Skip to content

Commit ad8dfef

Browse files
author
ndenoyelle
committed
add tool and tests for binding threads according to a set of locations
1 parent a1b0f2c commit ad8dfef

File tree

6 files changed

+1063
-1
lines changed

6 files changed

+1063
-1
lines changed

config/hwloc_internal.m4

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,34 @@ EOF
355355
AC_CHECK_FUNCS([clock_gettime])
356356
])
357357
358+
# Check for ptrace support
359+
hwloc_have_ptrace=1
360+
AC_CHECK_HEADERS([sys/ptrace.h],, [hwloc_have_ptrace=0])
361+
AC_CHECK_FUNCS([ptrace],, [hwloc_have_ptrace=0])
362+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
363+
#include "sys/ptrace.h"
364+
int main(void){
365+
return ptrace(PTRACE_SEIZE,
366+
-1,
367+
0,
368+
(void*)(PTRACE_O_TRACECLONE|PTRACE_O_TRACEFORK));
369+
}
370+
]])],, [hwloc_have_ptrace=0])
371+
AM_CONDITIONAL([HWLOC_HAVE_PTRACE],[test $hwloc_have_ptrace -eq 1])
372+
AC_DEFINE_UNQUOTED([HWLOC_HAVE_PTRACE], [$hwloc_have_ptrace], [Whether ptrace is present and supports PTRACE_SEIZE or not])
373+
374+
# Check if syscall gettid is available.
375+
hwloc_have_sys_gettid=1
376+
AC_CHECK_HEADERS([sys/syscall.h],, [hwloc_have_sys_gettid=0])
377+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
378+
#include "sys/syscall.h"
379+
#ifndef SYS_gettid
380+
#error "syscall SYS_gettid not found"
381+
#endif
382+
int main(void){ return syscall(SYS_gettid) > 0;}
383+
]])],,[hwloc_have_sys_gettid=0])
384+
AC_DEFINE_UNQUOTED([HWLOC_HAVE_SYS_GETTID], [$hwloc_have_sys_gettid], [Whether syscall header is present and SYS_gettid macro is defined or not])
385+
358386
# Only generate this if we're building the utilities
359387
# Even the netloc library Makefile is here because
360388
# we don't embed libnetloc yet, it's useless without tools
@@ -385,7 +413,11 @@ AC_DEFUN([HWLOC_SETUP_TESTS],[
385413
###
386414
EOF
387415
388-
AC_CHECK_LIB([pthread], [pthread_self], [hwloc_have_pthread=yes])
416+
# Check thread support.
417+
AC_CHECK_LIB([pthread], [pthread_self], [hwloc_have_pthread=1], [hwloc_have_pthread=0])
418+
AC_DEFINE_UNQUOTED([HWLOC_HAVE_PTHREAD], [$hwloc_have_pthread], [Whether we have the pthread library or not])
419+
AM_CONDITIONAL([HWLOC_HAVE_PTHREAD], [test $hwloc_have_pthread -eq 1]) AC_CHECK_LIB([pthread], [pthread_self], [hwloc_have_pthread=yes])
420+
AC_OPENMP
389421
390422
HWLOC_PKG_CHECK_MODULES([NUMA], [numa], [numa_available], [numa.h],
391423
[hwloc_have_linux_libnuma=yes],

utils/hwloc/Makefile.am

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,24 @@ endif HWLOC_HAVE_LINUX
169169

170170
distclean-local:
171171
rm -f $(nodist_man_MANS)
172+
173+
# Build hwloc-thread-bind
174+
if HWLOC_HAVE_PTRACE
175+
if HWLOC_HAVE_PTHREAD
176+
AM_LDFLAGS+=-lpthread
177+
endif #HWLOC_HAVE_PHREAD
178+
noinst_LTLIBRARIES+=libhwloc-thread-bind.la
179+
libhwloc_thread_bind_la_SOURCES=hwloc-thread-bind-utils.c hwloc-thread-bind.h
180+
LIBDADD=$(HWLOC_top_builddir)/hwloc/libhwloc.la
181+
182+
bin_PROGRAMS += hwloc-thread-bind
183+
hwloc_thread_bind_SOURCES = \
184+
hwloc-thread-bind.c \
185+
hwloc-thread-bind.h
186+
LDADD+=$(HWLOC_top_builddir)/hwloc/libhwloc.la
187+
LDADD+=libhwloc-thread-bind.la
188+
check_PROGRAMS=test-hwloc-thread-bind
189+
if !HWLOC_HAVE_MINGW32
190+
TESTS+=test-hwloc-thread-bind
191+
endif #!HWLOC_HAVE_MINGW32
192+
endif #HWLOC_HAVE_PTRACE

0 commit comments

Comments
 (0)