Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Add test for setns()

And provide an alternative implementation to keep perf building on older
distros as we're about to add initial support for namespaces.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-bqdwijunhjlvps1ardykhw1i@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+40 -2
+2 -1
tools/build/Makefile.feature
··· 64 64 get_cpuid \ 65 65 bpf \ 66 66 sched_getcpu \ 67 - sdt 67 + sdt \ 68 + setns 68 69 69 70 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list 70 71 # of all feature tests
+5 -1
tools/build/feature/Makefile
··· 49 49 test-sdt.bin \ 50 50 test-cxx.bin \ 51 51 test-jvmti.bin \ 52 - test-sched_getcpu.bin 52 + test-sched_getcpu.bin \ 53 + test-setns.bin 53 54 54 55 FILES := $(addprefix $(OUTPUT),$(FILES)) 55 56 ··· 94 93 $(BUILD) 95 94 96 95 $(OUTPUT)test-sched_getcpu.bin: 96 + $(BUILD) 97 + 98 + $(OUTPUT)test-setns.bin: 97 99 $(BUILD) 98 100 99 101 DWARFLIBS := -ldw
+5
tools/build/feature/test-all.c
··· 153 153 # include "test-sdt.c" 154 154 #undef main 155 155 156 + #define main main_test_setns 157 + # include "test-setns.c" 158 + #undef main 159 + 156 160 int main(int argc, char *argv[]) 157 161 { 158 162 main_test_libpython(); ··· 192 188 main_test_libcrypto(); 193 189 main_test_sched_getcpu(); 194 190 main_test_sdt(); 191 + main_test_setns(); 195 192 196 193 return 0; 197 194 }
+7
tools/build/feature/test-setns.c
··· 1 + #define _GNU_SOURCE 2 + #include <sched.h> 3 + 4 + int main(void) 5 + { 6 + return setns(0, 0); 7 + }
+5
tools/perf/Makefile.config
··· 330 330 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT 331 331 endif 332 332 333 + ifeq ($(feature-setns), 1) 334 + CFLAGS += -DHAVE_SETNS_SUPPORT 335 + $(call detected,CONFIG_SETNS) 336 + endif 337 + 333 338 ifndef NO_LIBELF 334 339 CFLAGS += -DHAVE_LIBELF_SUPPORT 335 340 EXTLIBS += -lelf
+4
tools/perf/util/Build
··· 104 104 libperf-y += symbol-minimal.o 105 105 endif 106 106 107 + ifndef CONFIG_SETNS 108 + libperf-y += setns.o 109 + endif 110 + 107 111 libperf-$(CONFIG_DWARF) += probe-finder.o 108 112 libperf-$(CONFIG_DWARF) += dwarf-aux.o 109 113 libperf-$(CONFIG_DWARF) += dwarf-regs.o
+8
tools/perf/util/setns.c
··· 1 + #include "util.h" 2 + #include <unistd.h> 3 + #include <sys/syscall.h> 4 + 5 + int setns(int fd, int nstype) 6 + { 7 + return syscall(__NR_setns, fd, nstype); 8 + }
+4
tools/perf/util/util.h
··· 58 58 int sched_getcpu(void); 59 59 #endif 60 60 61 + #ifndef HAVE_SETNS_SUPPORT 62 + int setns(int fd, int nstype); 63 + #endif 64 + 61 65 #endif /* GIT_COMPAT_UTIL_H */