Skip to content

Commit

Permalink
perf tools: Provide stub for missing pthread_attr_setaffinity_np
Browse files Browse the repository at this point in the history
uClibc Linuxthreads.old doesn't support the pthread_attr_setaffinity_np()
functioo:

   ----------------->8-----------------------
  CC       bench/futex-hash.o
  CC       bench/futex-wake.o
bench/futex-hash.c: In function 'bench_futex_hash':
bench/futex-hash.c:161:3: error: implicit declaration of function
'pthread_attr_setaffinity_np' [-Werror=implicit-function-declaration]
   ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t),
&cpu);
   ^
bench/futex-hash.c:161:3: error: nested extern declaration of
'pthread_attr_setaffinity_np' [-Werror=nested-externs]
   ----------------->8-----------------------

So introduce a test to check that and if not available provide a stub.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1421156604-30603-6-git-send-email-vgupta@synopsys.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Vineet Gupta authored and Arnaldo Carvalho de Melo committed Jan 28, 2015
1 parent 8d9cbd8 commit 459a3df
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/perf/bench/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wak
val, opflags);
}

#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
#include <pthread.h>
static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr,
size_t cpusetsize,
cpu_set_t *cpuset)
{
attr = attr;
cpusetsize = cpusetsize;
cpuset = cpuset;
return 0;
}
#endif

#endif /* _FUTEX_H */
6 changes: 6 additions & 0 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ CORE_FEATURE_TESTS = \
libpython-version \
libslang \
libunwind \
pthread-attr-setaffinity-np \
stackprotector-all \
timerfd \
libdw-dwarf-unwind \
Expand Down Expand Up @@ -226,6 +227,7 @@ VF_FEATURE_TESTS = \
libelf-getphdrnum \
libelf-mmap \
libpython-version \
pthread-attr-setaffinity-np \
stackprotector-all \
timerfd \
libunwind-debug-frame \
Expand Down Expand Up @@ -301,6 +303,10 @@ ifeq ($(feature-sync-compare-and-swap), 1)
CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
endif

ifeq ($(feature-pthread-attr-setaffinity-np), 1)
CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
endif

ifndef NO_BIONIC
$(call feature_check,bionic)
ifeq ($(feature-bionic), 1)
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/config/feature-checks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ FILES= \
test-libslang.bin \
test-libunwind.bin \
test-libunwind-debug-frame.bin \
test-pthread-attr-setaffinity-np.bin \
test-stackprotector-all.bin \
test-timerfd.bin \
test-libdw-dwarf-unwind.bin \
Expand All @@ -47,6 +48,9 @@ test-all.bin:
test-hello.bin:
$(BUILD)

test-pthread-attr-setaffinity-np.bin:
$(BUILD) -Werror -lpthread

test-stackprotector-all.bin:
$(BUILD) -Werror -fstack-protector-all

Expand Down
5 changes: 5 additions & 0 deletions tools/perf/config/feature-checks/test-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
# include "test-zlib.c"
#undef main

#define main main_test_pthread_attr_setaffinity_np
# include "test-pthread_attr_setaffinity_np.c"
#undef main

int main(int argc, char *argv[])
{
main_test_libpython();
Expand All @@ -121,6 +125,7 @@ int main(int argc, char *argv[])
main_test_libdw_dwarf_unwind();
main_test_sync_compare_and_swap(argc, argv);
main_test_zlib();
main_test_pthread_attr_setaffinity_np();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdint.h>
#include <pthread.h>

int main(void)
{
int ret = 0;
pthread_attr_t thread_attr;

pthread_attr_init(&thread_attr);
/* don't care abt exact args, just the API itself in libpthread */
ret = pthread_attr_setaffinity_np(&thread_attr, 0, NULL);

return ret;
}

0 comments on commit 459a3df

Please sign in to comment.