tools build: Add test for sched_getcpu()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Mar 2017 15:55:49 +0000 (12:55 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Mar 2017 22:07:19 +0000 (19:07 -0300)
Instead of trying to go on adding more ifdef conditions, do a feature
test and define HAVE_SCHED_GETCPU_SUPPORT instead, then use it to
provide the prototype. No need to change the stub, as it is already a
__weak symbol.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-yge89er9g90sc0v6k0a0r5tr@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-all.c
tools/build/feature/test-sched_getcpu.c [new file with mode: 0644]
tools/perf/Makefile.config
tools/perf/util/cloexec.h
tools/perf/util/util.h

index e3fb5ecbdcb65cee24172baecbe7f87da959b640..523911f316ce5e65511962f0c13fe0032a06427a 100644 (file)
@@ -63,6 +63,7 @@ FEATURE_TESTS_BASIC :=                  \
         lzma                            \
         get_cpuid                       \
         bpf                             \
+        sched_getcpu                   \
         sdt
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
index b564a2eea03904636f41101dd485e441d2d4fe00..ab1e2bbc2e96f3f9ec6d25b149ff2eb4953eea1d 100644 (file)
@@ -48,7 +48,8 @@ FILES=                                          \
          test-get_cpuid.bin                     \
          test-sdt.bin                           \
          test-cxx.bin                           \
-         test-jvmti.bin
+         test-jvmti.bin                                \
+         test-sched_getcpu.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -91,6 +92,9 @@ $(OUTPUT)test-libelf.bin:
 $(OUTPUT)test-glibc.bin:
        $(BUILD)
 
+$(OUTPUT)test-sched_getcpu.bin:
+       $(BUILD)
+
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
index 699e43627397b5c3008cd74008016f4812550c77..cc6c7c01f4cadd5f8fe28ced947b9c80a2a0515d 100644 (file)
 # include "test-pthread-attr-setaffinity-np.c"
 #undef main
 
+#define main main_test_sched_getcpu
+# include "test-sched_getcpu.c"
+#undef main
+
 # if 0
 /*
  * Disable libbabeltrace check for test-all, because the requested
@@ -182,6 +186,7 @@ int main(int argc, char *argv[])
        main_test_get_cpuid();
        main_test_bpf();
        main_test_libcrypto();
+       main_test_sched_getcpu();
        main_test_sdt();
 
        return 0;
diff --git a/tools/build/feature/test-sched_getcpu.c b/tools/build/feature/test-sched_getcpu.c
new file mode 100644 (file)
index 0000000..c4a148d
--- /dev/null
@@ -0,0 +1,7 @@
+#define _GNU_SOURCE
+#include <sched.h>
+
+int main(void)
+{
+       return sched_getcpu();
+}
index 27c9fbca7bd9c79eb703ad2d37d4280f9d286cc4..2b656de99495378e12767af7305d0f583a450ddd 100644 (file)
@@ -317,6 +317,10 @@ ifdef NO_DWARF
   NO_LIBDW_DWARF_UNWIND := 1
 endif
 
+ifeq ($(feature-sched_getcpu), 1)
+  CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
+endif
+
 ifndef NO_LIBELF
   CFLAGS += -DHAVE_LIBELF_SUPPORT
   EXTLIBS += -lelf
index d0d465953d36e16c07038ea69182e71c44db0558..94a5a7d829d5ba32efe646f9c04729ab363ac593 100644 (file)
@@ -3,10 +3,4 @@
 
 unsigned long perf_event_open_cloexec_flag(void);
 
-#ifdef __GLIBC_PREREQ
-#if !__GLIBC_PREREQ(2, 6) && !defined(__UCLIBC__)
-int sched_getcpu(void) __THROW;
-#endif
-#endif
-
 #endif /* __PERF_CLOEXEC_H */
index c74708da857129356e2a308cd987dec34f371104..b2cfa47990dcc7bc3a95a8c7f3a7bae1d565a700 100644 (file)
@@ -355,8 +355,8 @@ void print_binary(unsigned char *data, size_t len,
                  size_t bytes_per_line, print_binary_t printer,
                  void *extra);
 
-#if !defined(__GLIBC__) && !defined(__ANDROID__)
-extern int sched_getcpu(void);
+#ifndef HAVE_SCHED_GETCPU_SUPPORT
+int sched_getcpu(void);
 #endif
 
 int is_printable_array(char *p, unsigned int len);