diff --git a/include/tscore/ink_defs.h b/include/tscore/ink_defs.h index 35141368371..9407c525109 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 -#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 00000000000..fc9d7a7a68a --- /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 + +// 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 df8e27bea8f..9384ed7c6b4 100644 --- a/iocore/aio/AIO.cc +++ b/iocore/aio/AIO.cc @@ -25,7 +25,8 @@ * Async Disk IO operations. */ -#include +#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 e3dccef256d..bef0a8ea3b7 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 c3a30fe494c..ec860943d42 100644 --- a/iocore/eventsystem/UnixEventProcessor.cc +++ b/iocore/eventsystem/UnixEventProcessor.cc @@ -30,6 +30,7 @@ #include #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 9961bc00b8e..37e738adb21 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 #include "diags.i" diff --git a/src/traffic_layout/info.cc b/src/traffic_layout/info.cc index 68a39c9c751..a54a1b10f49 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 +#endif + #if HAVE_ZLIB_H #include #endif diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index f5f169ac3cd..84c95aa7da6 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 8b02bc17192..c4110a73170 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 b28ed35bcf0..e7c16519a51 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 - -// 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) { @@ -117,28 +91,6 @@ ink_sys_name_release(char *name, int namelen, char *release, int releaselen) #endif } -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() { diff --git a/src/tscore/ink_hw.cc b/src/tscore/ink_hw.cc new file mode 100644 index 00000000000..ba0264c6a97 --- /dev/null +++ b/src/tscore/ink_hw.cc @@ -0,0 +1,70 @@ +/** @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. + */ + +#include "tscore/ink_hw.h" +#include "tscore/ink_platform.h" + +#if TS_USE_HWLOC + +#include + +// 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; +} + +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 +} +#endif diff --git a/src/tscore/unit_tests/freelist_benchmark.cc b/src/tscore/unit_tests/freelist_benchmark.cc index d4e87004c82..161f89a2f61 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"