Skip to content

Commit

Permalink
tools build: Add test for setns()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Krister Johansen <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jul 19, 2017
1 parent 59291f1 commit 86bcdb5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tools/build/Makefile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ FEATURE_TESTS_BASIC := \
get_cpuid \
bpf \
sched_getcpu \
sdt
sdt \
setns

# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
# of all feature tests
Expand Down
6 changes: 5 additions & 1 deletion tools/build/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ FILES= \
test-sdt.bin \
test-cxx.bin \
test-jvmti.bin \
test-sched_getcpu.bin
test-sched_getcpu.bin \
test-setns.bin

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

Expand Down Expand Up @@ -95,6 +96,9 @@ $(OUTPUT)test-glibc.bin:
$(OUTPUT)test-sched_getcpu.bin:
$(BUILD)

$(OUTPUT)test-setns.bin:
$(BUILD)

DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
Expand Down
5 changes: 5 additions & 0 deletions tools/build/feature/test-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
# include "test-sdt.c"
#undef main

#define main main_test_setns
# include "test-setns.c"
#undef main

int main(int argc, char *argv[])
{
main_test_libpython();
Expand Down Expand Up @@ -188,6 +192,7 @@ int main(int argc, char *argv[])
main_test_libcrypto();
main_test_sched_getcpu();
main_test_sdt();
main_test_setns();

return 0;
}
7 changes: 7 additions & 0 deletions tools/build/feature/test-setns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define _GNU_SOURCE
#include <sched.h>

int main(void)
{
return setns(0, 0);
}
5 changes: 5 additions & 0 deletions tools/perf/Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ ifeq ($(feature-sched_getcpu), 1)
CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
endif

ifeq ($(feature-setns), 1)
CFLAGS += -DHAVE_SETNS_SUPPORT
$(call detected,CONFIG_SETNS)
endif

ifndef NO_LIBELF
CFLAGS += -DHAVE_LIBELF_SUPPORT
EXTLIBS += -lelf
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/Build
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ ifndef CONFIG_LIBELF
libperf-y += symbol-minimal.o
endif

ifndef CONFIG_SETNS
libperf-y += setns.o
endif

libperf-$(CONFIG_DWARF) += probe-finder.o
libperf-$(CONFIG_DWARF) += dwarf-aux.o
libperf-$(CONFIG_DWARF) += dwarf-regs.o
Expand Down
8 changes: 8 additions & 0 deletions tools/perf/util/setns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "util.h"
#include <unistd.h>
#include <sys/syscall.h>

int setns(int fd, int nstype)
{
return syscall(__NR_setns, fd, nstype);
}
4 changes: 4 additions & 0 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ const char *perf_tip(const char *dirpath);
int sched_getcpu(void);
#endif

#ifndef HAVE_SETNS_SUPPORT
int setns(int fd, int nstype);
#endif

#endif /* GIT_COMPAT_UTIL_H */

0 comments on commit 86bcdb5

Please sign in to comment.