This is an automated email from the ASF dual-hosted git repository.

rrm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 08d3506  Move hwloc-based functions into it's own header/compilation 
unit (#8711)
08d3506 is described below

commit 08d350601fbbbd062de743412601c8adb67df978
Author: Randall Meyer <r...@apache.org>
AuthorDate: Sat Mar 5 19:35:39 2022 -0800

    Move hwloc-based functions into it's own header/compilation unit (#8711)
    
    Reduces everything needing to include hwloc.h
---
 include/tscore/ink_defs.h                   | 10 ----
 include/tscore/ink_hw.h                     | 33 ++++++++++++
 iocore/aio/AIO.cc                           |  3 +-
 iocore/aio/test_AIO.cc                      |  1 +
 iocore/eventsystem/UnixEventProcessor.cc    |  1 +
 iocore/net/test_I_Net.cc                    |  3 ++
 src/traffic_layout/info.cc                  |  4 ++
 src/traffic_server/traffic_server.cc        |  1 +
 src/tscore/Makefile.am                      |  1 +
 src/tscore/ink_defs.cc                      | 48 -----------------
 src/tscore/{ink_defs.cc => ink_hw.cc}       | 81 +----------------------------
 src/tscore/unit_tests/freelist_benchmark.cc |  1 +
 12 files changed, 49 insertions(+), 138 deletions(-)

diff --git a/include/tscore/ink_defs.h b/include/tscore/ink_defs.h
index 3514136..9407c52 100644
--- a/include/tscore/ink_defs.h
+++ b/include/tscore/ink_defs.h
@@ -100,10 +100,6 @@ countof(const T (&)[N])
 #define unlikely(x) __builtin_expect(!!(x), 0)
 #endif
 
-#if TS_USE_HWLOC
-#include <hwloc.h>
-#endif
-
 #if defined(MAP_NORESERVE)
 #define MAP_SHARED_MAP_NORESERVE (MAP_SHARED | MAP_NORESERVE)
 #else
@@ -119,7 +115,6 @@ extern int on;
 /* Functions
  */
 int ink_sys_name_release(char *name, int namelen, char *release, int 
releaselen);
-int ink_number_of_processors();
 int ink_login_name_max();
 
 #ifdef __cplusplus
@@ -136,8 +131,3 @@ ROUNDUP(ArithmeticV value, ArithmeticM m)
   return value;
 }
 #endif
-
-#if TS_USE_HWLOC
-// Get the hardware topology
-hwloc_topology_t ink_get_topology();
-#endif
diff --git a/include/tscore/ink_hw.h b/include/tscore/ink_hw.h
new file mode 100644
index 0000000..fc9d7a7
--- /dev/null
+++ b/include/tscore/ink_hw.h
@@ -0,0 +1,33 @@
+/** @file
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include "tscore/ink_config.h"
+
+#if TS_USE_HWLOC
+#include <hwloc.h>
+
+// Get the hardware topology
+hwloc_topology_t ink_get_topology();
+#endif
+
+int ink_number_of_processors();
diff --git a/iocore/aio/AIO.cc b/iocore/aio/AIO.cc
index df8e27b..9384ed7 100644
--- a/iocore/aio/AIO.cc
+++ b/iocore/aio/AIO.cc
@@ -25,7 +25,8 @@
  * Async Disk IO operations.
  */
 
-#include <tscore/TSSystemState.h>
+#include "tscore/TSSystemState.h"
+#include "tscore/ink_hw.h"
 
 #include "P_AIO.h"
 
diff --git a/iocore/aio/test_AIO.cc b/iocore/aio/test_AIO.cc
index e3dccef..bef0a8e 100644
--- a/iocore/aio/test_AIO.cc
+++ b/iocore/aio/test_AIO.cc
@@ -23,6 +23,7 @@
 
 #include "P_AIO.h"
 #include "InkAPIInternal.h"
+#include "tscore/ink_hw.h"
 #include "tscore/I_Layout.h"
 #include "tscore/TSSystemState.h"
 #include "tscore/Random.h"
diff --git a/iocore/eventsystem/UnixEventProcessor.cc 
b/iocore/eventsystem/UnixEventProcessor.cc
index c3a30fe..ec86094 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -30,6 +30,7 @@
 #include <hwloc.h>
 #endif
 #include "tscore/ink_defs.h"
+#include "tscore/ink_hw.h"
 #include "tscore/hugepages.h"
 
 /// Global singleton.
diff --git a/iocore/net/test_I_Net.cc b/iocore/net/test_I_Net.cc
index 9961bc0..37e738a 100644
--- a/iocore/net/test_I_Net.cc
+++ b/iocore/net/test_I_Net.cc
@@ -22,6 +22,9 @@
  */
 
 #include "P_Net.h"
+
+#include "tscore/ink_hw.h"
+
 #include <netdb.h>
 
 #include "diags.i"
diff --git a/src/traffic_layout/info.cc b/src/traffic_layout/info.cc
index 68a39c9..a54a1b1 100644
--- a/src/traffic_layout/info.cc
+++ b/src/traffic_layout/info.cc
@@ -30,6 +30,10 @@
 #include "RecordsConfig.h"
 #include "info.h"
 
+#if TS_USE_HWLOC
+#include <hwloc.h>
+#endif
+
 #if HAVE_ZLIB_H
 #include <zlib.h>
 #endif
diff --git a/src/traffic_server/traffic_server.cc 
b/src/traffic_server/traffic_server.cc
index f5f169a..84c95aa 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -33,6 +33,7 @@
 #include "tscore/ink_platform.h"
 #include "tscore/ink_sys_control.h"
 #include "tscore/ink_args.h"
+#include "tscore/ink_hw.h"
 #include "tscore/ink_lockfile.h"
 #include "tscore/ink_stack_trace.h"
 #include "tscore/ink_syslog.h"
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index 8b02bc1..c4110a7 100644
--- a/src/tscore/Makefile.am
+++ b/src/tscore/Makefile.am
@@ -79,6 +79,7 @@ libtscore_la_SOURCES = \
        ink_error.cc \
        ink_file.cc \
        ink_hrtime.cc \
+       ink_hw.cc \
        ink_inet.cc \
        ink_memory.cc \
        ink_mutex.cc \
diff --git a/src/tscore/ink_defs.cc b/src/tscore/ink_defs.cc
index b28ed35..e7c1651 100644
--- a/src/tscore/ink_defs.cc
+++ b/src/tscore/ink_defs.cc
@@ -41,32 +41,6 @@
 int off = 0;
 int on  = 1;
 
-#if TS_USE_HWLOC
-
-#include <hwloc.h>
-
-// Little helper to initialize the hwloc topology, once.
-static hwloc_topology_t
-setup_hwloc()
-{
-  hwloc_topology_t topology;
-
-  hwloc_topology_init(&topology);
-  hwloc_topology_load(topology);
-
-  return topology;
-}
-
-// Get the topology
-hwloc_topology_t
-ink_get_topology()
-{
-  static hwloc_topology_t topology = setup_hwloc();
-  return topology;
-}
-
-#endif
-
 int
 ink_sys_name_release(char *name, int namelen, char *release, int releaselen)
 {
@@ -118,28 +92,6 @@ ink_sys_name_release(char *name, int namelen, char 
*release, int releaselen)
 }
 
 int
-ink_number_of_processors()
-{
-#if TS_USE_HWLOC
-#if HAVE_HWLOC_OBJ_PU
-  return hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU);
-#else
-  return hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_CORE);
-#endif
-#elif defined(freebsd)
-  int mib[2], n;
-  mib[0]     = CTL_HW;
-  mib[1]     = HW_NCPU;
-  size_t len = sizeof(n);
-  if (sysctl(mib, 2, &n, &len, nullptr, 0) == -1)
-    return 1;
-  return n;
-#else
-  return sysconf(_SC_NPROCESSORS_ONLN); // number of processing units 
(includes Hyper Threading)
-#endif
-}
-
-int
 ink_login_name_max()
 {
   long value = sysconf(_SC_LOGIN_NAME_MAX);
diff --git a/src/tscore/ink_defs.cc b/src/tscore/ink_hw.cc
similarity index 55%
copy from src/tscore/ink_defs.cc
copy to src/tscore/ink_hw.cc
index b28ed35..ba0264c 100644
--- a/src/tscore/ink_defs.cc
+++ b/src/tscore/ink_hw.cc
@@ -1,7 +1,5 @@
 /** @file
 
-  A brief file description
-
   @section license License
 
   Licensed to the Apache Software Foundation (ASF) under one
@@ -21,26 +19,9 @@
   limitations under the License.
  */
 
-/****************************************************************************
-
-  ink_defs.h
-  Some small general interest definitions
-
- ****************************************************************************/
-
+#include "tscore/ink_hw.h"
 #include "tscore/ink_platform.h"
 
-#if defined(linux) || defined(freebsd) || defined(darwin)
-#include <sys/types.h>
-#include <sys/param.h>
-#endif
-#if defined(linux)
-#include <sys/utsname.h>
-#endif
-
-int off = 0;
-int on  = 1;
-
 #if TS_USE_HWLOC
 
 #include <hwloc.h>
@@ -65,58 +46,6 @@ ink_get_topology()
   return topology;
 }
 
-#endif
-
-int
-ink_sys_name_release(char *name, int namelen, char *release, int releaselen)
-{
-  *name    = 0;
-  *release = 0;
-#if defined(freebsd) || defined(darwin)
-  int mib[2];
-  size_t len = namelen;
-  mib[0]     = CTL_KERN;
-  mib[1]     = KERN_OSTYPE;
-
-  if (sysctl(mib, 2, name, &len, nullptr, 0) == -1)
-    return -1;
-
-  len    = releaselen;
-  mib[0] = CTL_KERN;
-  mib[1] = KERN_OSRELEASE;
-
-  if (sysctl(mib, 2, release, &len, nullptr, 0) == -1)
-    return -1;
-
-  return 0;
-#elif defined(linux)
-  struct utsname buf;
-  int n;
-
-  if (uname(&buf)) {
-    return -1;
-  }
-
-  n = strlen(buf.sysname);
-  if (namelen <= n) {
-    n = namelen - 1;
-  }
-  memcpy(name, buf.sysname, n);
-  name[n] = 0;
-
-  n = strlen(buf.release);
-  if (releaselen <= n) {
-    n = releaselen - 1;
-  }
-  memcpy(release, buf.release, n);
-  release[n] = 0;
-
-  return 0;
-#else
-  return -1;
-#endif
-}
-
 int
 ink_number_of_processors()
 {
@@ -138,10 +67,4 @@ ink_number_of_processors()
   return sysconf(_SC_NPROCESSORS_ONLN); // number of processing units 
(includes Hyper Threading)
 #endif
 }
-
-int
-ink_login_name_max()
-{
-  long value = sysconf(_SC_LOGIN_NAME_MAX);
-  return value <= 0 ? _POSIX_LOGIN_NAME_MAX : value;
-}
+#endif
diff --git a/src/tscore/unit_tests/freelist_benchmark.cc 
b/src/tscore/unit_tests/freelist_benchmark.cc
index d4e8700..161f89a 100644
--- a/src/tscore/unit_tests/freelist_benchmark.cc
+++ b/src/tscore/unit_tests/freelist_benchmark.cc
@@ -24,6 +24,7 @@
 
 #include "catch.hpp"
 
+#include "tscore/ink_hw.h"
 #include "tscore/ink_thread.h"
 #include "tscore/ink_memory.h"
 #include "tscore/ink_queue.h"

Reply via email to