TS-1843: detect and link libhwloc on Ubuntu Fix the hwloc-enabled build on current and older Ubuntu releases. This requires explicitly testing for the HWLOC_OBJ_PU symbol, and using pkg-cofig to find the correct build options.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7e417c47 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7e417c47 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7e417c47 Branch: refs/heads/sphinx-docs Commit: 7e417c4712e36c9c38cf60b98783b24ad2a1c4f3 Parents: 54e9a1e Author: James Peach <[email protected]> Authored: Mon Apr 22 13:16:23 2013 -0700 Committer: James Peach <[email protected]> Committed: Mon Apr 29 09:15:56 2013 -0700 ---------------------------------------------------------------------- CHANGES | 4 ++- configure.ac | 32 +++++++++++++----------- iocore/cluster/ClusterHandlerBase.cc | 6 +---- iocore/eventsystem/UnixEventProcessor.cc | 8 +++++- lib/ts/Makefile.am | 13 +++++++++- lib/ts/ink_defs.cc | 27 ++++++++++++-------- proxy/Makefile.am | 3 +- 7 files changed, 58 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index dbb5fd0..b99556e 100644 --- a/CHANGES +++ b/CHANGES @@ -2,7 +2,9 @@ Changes with Apache Traffic Server 3.3.3 - *) [TS-1858] Fix redefinition of timersub on Solaris + *) [TS-1843] Detect and link libhwloc on Ubuntu. + + *) [TS-1858] Fix redefinition of timersub on Solaris. *) [TS-1861] Build fails with reclaimable freelist enabled. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 6e7549a..8d48401 100644 --- a/configure.ac +++ b/configure.ac @@ -1235,14 +1235,24 @@ AC_SUBST(use_linux_native_aio) # Check for hwloc library. # If we don't find it, disable checking for header. use_hwloc=0 -AS_IF([test "x$enable_hwloc" = "xyes"], - AC_CHECK_LIB([hwloc],[hwloc_topology_init], - [AC_SUBST([LIBHWLOC], ["-lhwloc"]) - use_hwloc=1 - ], - [enable_hwloc=no] + +AS_IF([test "x$enable_hwloc" = "xyes"], [ + AC_CHECK_HEADERS([hwloc.h], [], + [AC_MSG_WARN([hwloc.h header not found, try --disable-hwloc])], [] ) -) + + # Old versions of libhwloc don't have HWLOC_OBJ_PU. + AC_CHECK_DECL(HWLOC_OBJ_PU, + [AC_DEFINE(HAVE_HWLOC_OBJ_PU, 1, [Whether HWLOC_OBJ_PU is available])], [], + [#include <hwloc.h>] + ) + + # Use pkg-config, because some distros (*cough* Ubuntu) put hwloc in unusual places. + PKG_CHECK_MODULES([hwloc], [hwloc], [use_hwloc=yes], [use_hwloc=no]) + AC_SUBST([hwloc_CFLAGS]) + AC_SUBST([hwloc_LIBS]) +]) + AC_SUBST(use_hwloc) # @@ -1489,14 +1499,6 @@ if test "x${enable_posix_cap}" != "xno"; then ) fi -if test "x${enable_hwloc}" = "xyes"; then - AC_CHECK_HEADERS([hwloc.h], - [], - [AC_MSG_FAILURE([hwloc header not found. Try --disable-hwloc])], - [] - ) -fi - # Check for high-resolution timestamps in struct stat AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec]) AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec]) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/iocore/cluster/ClusterHandlerBase.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc index 19a9747..b245db6 100644 --- a/iocore/cluster/ClusterHandlerBase.cc +++ b/iocore/cluster/ClusterHandlerBase.cc @@ -1152,11 +1152,7 @@ failed: // Startup the periodic events to process entries in // external_incoming_control. -#if defined(freebsd) - int procs_online = 1; -#else - int procs_online = sysconf(_SC_NPROCESSORS_ONLN); -#endif + int procs_online = ink_number_of_processors(); int total_callbacks = min(procs_online, MAX_COMPLETION_CALLBACK_EVENTS); for (int n = 0; n < total_callbacks; ++n) { callout_cont[n] = NEW(new ClusterCalloutContinuation(this)); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/iocore/eventsystem/UnixEventProcessor.cc ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc index 1821809..8613cd3 100644 --- a/iocore/eventsystem/UnixEventProcessor.cc +++ b/iocore/eventsystem/UnixEventProcessor.cc @@ -169,7 +169,13 @@ EventProcessor::start(int n_event_threads) ink_cpuset_t cpuset; int socket = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_SOCKET); int cu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_CORE); - int pu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU); + int pu = cu; + + // Older versions of libhwloc (eg. Ubuntu 10.04) don't have pHWLOC_OBJ_PU. +#if HAVE_HWLOC_OBJ_PU + pu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU); +#endif + Debug("iocore_thread", "socket: %d core: %d logical processor: %d affinity: %d", socket, cu, pu, affinity); #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/lib/ts/Makefile.am ---------------------------------------------------------------------- diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am index 689df2f..2b6692d 100644 --- a/lib/ts/Makefile.am +++ b/lib/ts/Makefile.am @@ -25,7 +25,18 @@ AM_CPPFLAGS = -I$(top_srcdir)/lib lib_LTLIBRARIES = libtsutil.la libtsutil_la_LDFLAGS = -no-undefined -version-info @TS_LIBTOOL_VERSION@ -libtsutil_la_LIBADD = @LIBOBJS@ @LIBPCRE@ @LIBSSL@ @LIBTCL@ @LIBRESOLV@ @LIBRT@ @LIBSOCKET@ @LIBNSL@ @LIBCAP@ @LIBHWLOC@ -lc +libtsutil_la_LIBADD = \ + @hwloc_LIBS@ \ + @LIBOBJS@ \ + @LIBPCRE@ \ + @LIBSSL@ \ + @LIBTCL@ \ + @LIBRESOLV@ \ + @LIBRT@ \ + @LIBSOCKET@ \ + @LIBNSL@ \ + @LIBCAP@ \ + -lc libtsutil_la_SOURCES = \ Allocator.h \ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/lib/ts/ink_defs.cc ---------------------------------------------------------------------- diff --git a/lib/ts/ink_defs.cc b/lib/ts/ink_defs.cc index a327bbb..dc68183 100644 --- a/lib/ts/ink_defs.cc +++ b/lib/ts/ink_defs.cc @@ -119,17 +119,21 @@ int ink_number_of_processors() { #if TS_USE_HWLOC - int cu; - int pu; - cu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_CORE); - pu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU); - if (pu > cu) + int cu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_CORE); + +#if HAVE_HWLOC_OBJ_PU + int pu = hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU); + + if (pu > cu) { return cu + (pu - cu)/4; - else - return cu; -#else -#if defined(freebsd) + } +#endif + + return cu; + +#elif defined(freebsd) + int mib[2], n; mib[0] = CTL_HW; mib[1] = HW_NCPU; @@ -137,9 +141,10 @@ ink_number_of_processors() if (sysctl(mib, 2, &n, &len, NULL, 0) == -1) return 1; return n; + #else + return sysconf(_SC_NPROCESSORS_ONLN); // number of processing units (includes Hyper Threading) -#endif /* freebsd */ -#endif /* TS_HAVE_HWLOC_H */ +#endif } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7e417c47/proxy/Makefile.am ---------------------------------------------------------------------- diff --git a/proxy/Makefile.am b/proxy/Makefile.am index d68e6d8..3975db9 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -161,9 +161,10 @@ traffic_server_LDADD = \ $(top_builddir)/lib/records/librecprocess.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(which_libts) \ + @hwloc_LIBS@ \ @LIBTHREAD@ @LIBSOCKET@ @LIBNSL@ @LIBRESOLV@ @LIBRT@ \ @LIBPCRE@ @LIBSSL@ @LIBTCL@ @LIBDL@ \ - @LIBEXPAT@ @LIBDEMANGLE@ @LIBCAP@ @LIBHWLOC@ \ + @LIBEXPAT@ @LIBDEMANGLE@ @LIBCAP@ \ @LIBZ@ @LIBLZMA@ \ @LIBMLD@ @LIBEXC@ -lm @LIBPROFILER@ @LIBEXECINFO@
