Skip to content

Commit 86bcdb5

Browse files
committed
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>
1 parent 59291f1 commit 86bcdb5

8 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ FEATURE_TESTS_BASIC := \
6464
get_cpuid \
6565
bpf \
6666
sched_getcpu \
67-
sdt
67+
sdt \
68+
setns
6869

6970
# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
7071
# of all feature tests

‎tools/build/feature/Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ FILES= \
4949
test-sdt.bin \
5050
test-cxx.bin \
5151
test-jvmti.bin \
52-
test-sched_getcpu.bin
52+
test-sched_getcpu.bin \
53+
test-setns.bin
5354

5455
FILES := $(addprefix $(OUTPUT),$(FILES))
5556

@@ -95,6 +96,9 @@ $(OUTPUT)test-glibc.bin:
9596
$(OUTPUT)test-sched_getcpu.bin:
9697
$(BUILD)
9798

99+
$(OUTPUT)test-setns.bin:
100+
$(BUILD)
101+
98102
DWARFLIBS := -ldw
99103
ifeq ($(findstring -static,${LDFLAGS}),-static)
100104
DWARFLIBS += -lelf -lebl -lz -llzma -lbz2

‎tools/build/feature/test-all.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
# include "test-sdt.c"
154154
#undef main
155155

156+
#define main main_test_setns
157+
# include "test-setns.c"
158+
#undef main
159+
156160
int main(int argc, char *argv[])
157161
{
158162
main_test_libpython();
@@ -188,6 +192,7 @@ int main(int argc, char *argv[])
188192
main_test_libcrypto();
189193
main_test_sched_getcpu();
190194
main_test_sdt();
195+
main_test_setns();
191196

192197
return 0;
193198
}

‎tools/build/feature/test-setns.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define _GNU_SOURCE
2+
#include <sched.h>
3+
4+
int main(void)
5+
{
6+
return setns(0, 0);
7+
}

‎tools/perf/Makefile.config‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ ifeq ($(feature-sched_getcpu), 1)
330330
CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
331331
endif
332332

333+
ifeq ($(feature-setns), 1)
334+
CFLAGS += -DHAVE_SETNS_SUPPORT
335+
$(call detected,CONFIG_SETNS)
336+
endif
337+
333338
ifndef NO_LIBELF
334339
CFLAGS += -DHAVE_LIBELF_SUPPORT
335340
EXTLIBS += -lelf

‎tools/perf/util/Build‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ ifndef CONFIG_LIBELF
104104
libperf-y += symbol-minimal.o
105105
endif
106106

107+
ifndef CONFIG_SETNS
108+
libperf-y += setns.o
109+
endif
110+
107111
libperf-$(CONFIG_DWARF) += probe-finder.o
108112
libperf-$(CONFIG_DWARF) += dwarf-aux.o
109113
libperf-$(CONFIG_DWARF) += dwarf-regs.o

‎tools/perf/util/setns.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

‎tools/perf/util/util.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ const char *perf_tip(const char *dirpath);
5858
int sched_getcpu(void);
5959
#endif
6060

61+
#ifndef HAVE_SETNS_SUPPORT
62+
int setns(int fd, int nstype);
63+
#endif
64+
6165
#endif /* GIT_COMPAT_UTIL_H */

0 commit comments

Comments
 (0)