perf tools: Add file-handle feature test
authorNamhyung Kim <namhyung@kernel.org>
Thu, 2 Apr 2020 01:52:49 +0000 (10:52 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Apr 2020 12:37:55 +0000 (09:37 -0300)
The file handle (FHANDLE) support is configurable so some systems might not
have it.  So add a config feature item to check it on build time so that we
don't add the cgroup tracking feature based on that.

Committer notes:

Had to make the test use the same construct as its later use in
synthetic-events.c, in the next patch in this series. i.e. make it be:

struct {
struct file_handle fh;
uint64_t cgroup_id;
} handle;

To cope with:

    CC       /tmp/build/perf/util/cloexec.o
  util/synthetic-events.c:428:22: error: field 'fh' with   CC       /tmp/build/perf/util/call-path.o
  variable sized type 'struct file_handle' not at the end of a struct or class is a GNU
        extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                  struct file_handle fh;
                                     ^
  1 error generated.

Deal with this at some point, i.e. investigate if the right thing is to
remove that -Wgnu-variable-sized-type-not-at-end from our CFLAGS, for
now do the test the same way as it is used looks more sensible.

Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20200402015249.3800462-1-namhyung@kernel.org
[ split from a larger patch, removed blank line at EOF ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-file-handle.c [new file with mode: 0644]
tools/perf/Makefile.config

index 574c2e0b9d2054cab20f2cf570e9968d0eb84200..3e0c019ef2971bb598795a553482568968416372 100644 (file)
@@ -72,7 +72,8 @@ FEATURE_TESTS_BASIC :=                  \
         setns                          \
         libaio                         \
         libzstd                                \
-        disassembler-four-args
+        disassembler-four-args         \
+        file-handle
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
 # of all feature tests
index 7ac0d8088565ba203f36e4b22b111747eea63157..621f528f782232a1068a409c53d119c6c254ef92 100644 (file)
@@ -67,7 +67,8 @@ FILES=                                          \
          test-llvm.bin                         \
          test-llvm-version.bin                 \
          test-libaio.bin                       \
-         test-libzstd.bin
+         test-libzstd.bin                      \
+         test-file-handle.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -321,6 +322,9 @@ $(OUTPUT)test-libaio.bin:
 $(OUTPUT)test-libzstd.bin:
        $(BUILD) -lzstd
 
+$(OUTPUT)test-file-handle.bin:
+       $(BUILD)
+
 ###############################
 
 clean:
diff --git a/tools/build/feature/test-file-handle.c b/tools/build/feature/test-file-handle.c
new file mode 100644 (file)
index 0000000..4d3b03b
--- /dev/null
@@ -0,0 +1,17 @@
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <inttypes.h>
+
+int main(void)
+{
+       struct {
+               struct file_handle fh;
+               uint64_t cgroup_id;
+       } handle;
+       int mount_id;
+
+       name_to_handle_at(AT_FDCWD, "/", &handle.fh, &mount_id, 0);
+       return 0;
+}
index 80e55e796be9cbf3d9e9cac86ee3d0b7770e51c7..eb95c0c0a16934ddaff69f2ff815657ca5f0b0a8 100644 (file)
@@ -348,6 +348,10 @@ ifeq ($(feature-gettid), 1)
   CFLAGS += -DHAVE_GETTID
 endif
 
+ifeq ($(feature-file-handle), 1)
+  CFLAGS += -DHAVE_FILE_HANDLE
+endif
+
 ifdef NO_LIBELF
   NO_DWARF := 1
   NO_DEMANGLE := 1