diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-18 16:15:29 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-18 22:14:08 -0400 |
| commit | 86bcdb5a43997bb02ba25a76482c7bfc652ba45b (patch) | |
| tree | 60737d10e15be7e8dbff4d7da4ba1f80f72ea5e0 | |
| parent | 59291f19824200b5a9046b79d37f02fb415335b0 (diff) | |
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>
| -rw-r--r-- | tools/build/Makefile.feature | 3 | ||||
| -rw-r--r-- | tools/build/feature/Makefile | 6 | ||||
| -rw-r--r-- | tools/build/feature/test-all.c | 5 | ||||
| -rw-r--r-- | tools/build/feature/test-setns.c | 7 | ||||
| -rw-r--r-- | tools/perf/Makefile.config | 5 | ||||
| -rw-r--r-- | tools/perf/util/Build | 4 | ||||
| -rw-r--r-- | tools/perf/util/setns.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/util.h | 4 |
8 files changed, 40 insertions, 2 deletions
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 523911f316ce..c71a05b9c984 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature | |||
| @@ -64,7 +64,8 @@ FEATURE_TESTS_BASIC := \ | |||
| 64 | get_cpuid \ | 64 | get_cpuid \ |
| 65 | bpf \ | 65 | bpf \ |
| 66 | sched_getcpu \ | 66 | sched_getcpu \ |
| 67 | sdt | 67 | sdt \ |
| 68 | setns | ||
| 68 | 69 | ||
| 69 | # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list | 70 | # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list |
| 70 | # of all feature tests | 71 | # of all feature tests |
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index e35e4e5ad192..ee2546ddf028 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile | |||
| @@ -49,7 +49,8 @@ FILES= \ | |||
| 49 | test-sdt.bin \ | 49 | test-sdt.bin \ |
| 50 | test-cxx.bin \ | 50 | test-cxx.bin \ |
| 51 | test-jvmti.bin \ | 51 | test-jvmti.bin \ |
| 52 | test-sched_getcpu.bin | 52 | test-sched_getcpu.bin \ |
| 53 | test-setns.bin | ||
| 53 | 54 | ||
| 54 | FILES := $(addprefix $(OUTPUT),$(FILES)) | 55 | FILES := $(addprefix $(OUTPUT),$(FILES)) |
| 55 | 56 | ||
| @@ -95,6 +96,9 @@ $(OUTPUT)test-glibc.bin: | |||
| 95 | $(OUTPUT)test-sched_getcpu.bin: | 96 | $(OUTPUT)test-sched_getcpu.bin: |
| 96 | $(BUILD) | 97 | $(BUILD) |
| 97 | 98 | ||
| 99 | $(OUTPUT)test-setns.bin: | ||
| 100 | $(BUILD) | ||
| 101 | |||
| 98 | DWARFLIBS := -ldw | 102 | DWARFLIBS := -ldw |
| 99 | ifeq ($(findstring -static,${LDFLAGS}),-static) | 103 | ifeq ($(findstring -static,${LDFLAGS}),-static) |
| 100 | DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 | 104 | DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 |
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index cc6c7c01f4ca..b5cfc6445771 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c | |||
| @@ -153,6 +153,10 @@ | |||
| 153 | # include "test-sdt.c" | 153 | # include "test-sdt.c" |
| 154 | #undef main | 154 | #undef main |
| 155 | 155 | ||
| 156 | #define main main_test_setns | ||
| 157 | # include "test-setns.c" | ||
| 158 | #undef main | ||
| 159 | |||
| 156 | int main(int argc, char *argv[]) | 160 | int main(int argc, char *argv[]) |
| 157 | { | 161 | { |
| 158 | main_test_libpython(); | 162 | main_test_libpython(); |
| @@ -188,6 +192,7 @@ int main(int argc, char *argv[]) | |||
| 188 | main_test_libcrypto(); | 192 | main_test_libcrypto(); |
| 189 | main_test_sched_getcpu(); | 193 | main_test_sched_getcpu(); |
| 190 | main_test_sdt(); | 194 | main_test_sdt(); |
| 195 | main_test_setns(); | ||
| 191 | 196 | ||
| 192 | return 0; | 197 | return 0; |
| 193 | } | 198 | } |
diff --git a/tools/build/feature/test-setns.c b/tools/build/feature/test-setns.c new file mode 100644 index 000000000000..1f714d2a658b --- /dev/null +++ b/tools/build/feature/test-setns.c | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sched.h> | ||
| 3 | |||
| 4 | int main(void) | ||
| 5 | { | ||
| 6 | return setns(0, 0); | ||
| 7 | } | ||
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index bdf0e87f9b29..37d203c4cd1f 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config | |||
| @@ -330,6 +330,11 @@ ifeq ($(feature-sched_getcpu), 1) | |||
| 330 | CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT | 330 | CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT |
| 331 | endif | 331 | endif |
| 332 | 332 | ||
| 333 | ifeq ($(feature-setns), 1) | ||
| 334 | CFLAGS += -DHAVE_SETNS_SUPPORT | ||
| 335 | $(call detected,CONFIG_SETNS) | ||
| 336 | endif | ||
| 337 | |||
| 333 | ifndef NO_LIBELF | 338 | ifndef NO_LIBELF |
| 334 | CFLAGS += -DHAVE_LIBELF_SUPPORT | 339 | CFLAGS += -DHAVE_LIBELF_SUPPORT |
| 335 | EXTLIBS += -lelf | 340 | EXTLIBS += -lelf |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 79dea95a7f68..7580fe4d5d30 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
| @@ -104,6 +104,10 @@ ifndef CONFIG_LIBELF | |||
| 104 | libperf-y += symbol-minimal.o | 104 | libperf-y += symbol-minimal.o |
| 105 | endif | 105 | endif |
| 106 | 106 | ||
| 107 | ifndef CONFIG_SETNS | ||
| 108 | libperf-y += setns.o | ||
| 109 | endif | ||
| 110 | |||
| 107 | libperf-$(CONFIG_DWARF) += probe-finder.o | 111 | libperf-$(CONFIG_DWARF) += probe-finder.o |
| 108 | libperf-$(CONFIG_DWARF) += dwarf-aux.o | 112 | libperf-$(CONFIG_DWARF) += dwarf-aux.o |
| 109 | libperf-$(CONFIG_DWARF) += dwarf-regs.o | 113 | libperf-$(CONFIG_DWARF) += dwarf-regs.o |
diff --git a/tools/perf/util/setns.c b/tools/perf/util/setns.c new file mode 100644 index 000000000000..ce8fc290fce8 --- /dev/null +++ b/tools/perf/util/setns.c | |||
| @@ -0,0 +1,8 @@ | |||
| 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 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 2c9e58a45310..1e5fe1d9ec32 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
| @@ -58,4 +58,8 @@ const char *perf_tip(const char *dirpath); | |||
| 58 | int sched_getcpu(void); | 58 | int sched_getcpu(void); |
| 59 | #endif | 59 | #endif |
| 60 | 60 | ||
| 61 | #ifndef HAVE_SETNS_SUPPORT | ||
| 62 | int setns(int fd, int nstype); | ||
| 63 | #endif | ||
| 64 | |||
| 61 | #endif /* GIT_COMPAT_UTIL_H */ | 65 | #endif /* GIT_COMPAT_UTIL_H */ |
