From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935329AbdGTIuF (ORCPT ); Thu, 20 Jul 2017 04:50:05 -0400 Received: from terminus.zytor.com ([65.50.211.136]:41755 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934375AbdGTIuA (ORCPT ); Thu, 20 Jul 2017 04:50:00 -0400 Date: Thu, 20 Jul 2017 01:47:46 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: namhyung@kernel.org, acme@redhat.com, adrian.hunter@intel.com, tglx@linutronix.de, wangnan0@huawei.com, mingo@kernel.org, linux-kernel@vger.kernel.org, kjlx@templeofstupid.com, dsahern@gmail.com, jolsa@kernel.org, hpa@zytor.com Reply-To: namhyung@kernel.org, acme@redhat.com, adrian.hunter@intel.com, tglx@linutronix.de, wangnan0@huawei.com, mingo@kernel.org, linux-kernel@vger.kernel.org, kjlx@templeofstupid.com, dsahern@gmail.com, hpa@zytor.com, jolsa@kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] tools build: Add test for setns() Git-Commit-ID: 86bcdb5a43997bb02ba25a76482c7bfc652ba45b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 86bcdb5a43997bb02ba25a76482c7bfc652ba45b Gitweb: http://git.kernel.org/tip/86bcdb5a43997bb02ba25a76482c7bfc652ba45b Author: Arnaldo Carvalho de Melo AuthorDate: Tue, 18 Jul 2017 17:15:29 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 18 Jul 2017 23:14:08 -0300 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 Cc: David Ahern Cc: Jiri Olsa Cc: Krister Johansen Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-bqdwijunhjlvps1ardykhw1i@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Makefile.feature | 3 ++- tools/build/feature/Makefile | 6 +++++- tools/build/feature/test-all.c | 5 +++++ tools/build/feature/{test-sched_getcpu.c => test-setns.c} | 4 +--- tools/perf/Makefile.config | 5 +++++ tools/perf/util/Build | 4 ++++ tools/perf/util/setns.c | 8 ++++++++ tools/perf/util/util.h | 4 ++++ 8 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 523911f..c71a05b 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -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 diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index e35e4e5..ee2546d 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -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)) @@ -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 diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index cc6c7c0..b5cfc64 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -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(); @@ -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; } diff --git a/tools/build/feature/test-sched_getcpu.c b/tools/build/feature/test-setns.c similarity index 53% copy from tools/build/feature/test-sched_getcpu.c copy to tools/build/feature/test-setns.c index 9c6b4cb..1f714d2 100644 --- a/tools/build/feature/test-sched_getcpu.c +++ b/tools/build/feature/test-setns.c @@ -1,9 +1,7 @@ -#ifndef _GNU_SOURCE #define _GNU_SOURCE -#endif #include int main(void) { - return sched_getcpu(); + return setns(0, 0); } diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index bdf0e87..37d203c 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -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 diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 79dea95..7580fe4 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -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 diff --git a/tools/perf/util/setns.c b/tools/perf/util/setns.c new file mode 100644 index 0000000..ce8fc29 --- /dev/null +++ b/tools/perf/util/setns.c @@ -0,0 +1,8 @@ +#include "util.h" +#include +#include + +int setns(int fd, int nstype) +{ + return syscall(__NR_setns, fd, nstype); +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 2c9e58a..1e5fe1d 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -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 */