Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build feature: Check if eventfd() is available

A new 'perf bench epoll' will use this, and to disable it for older
systems, add a feature test for this API.

This is just a simple program that if successfully compiled, means that
the feature is present, at least at the library level, in a build that
sets the output directory to /tmp/build/perf (using O=/tmp/build/perf),
we end up with:

$ ls -la /tmp/build/perf/feature/test-eventfd*
-rwxrwxr-x. 1 acme acme 8176 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.bin
-rw-rw-r--. 1 acme acme 588 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.d
-rw-rw-r--. 1 acme acme 0 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.make.output
$ ldd /tmp/build/perf/feature/test-eventfd.bin
linux-vdso.so.1 (0x00007fff3bf3f000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa984061000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa984417000)
$ grep eventfd -A 2 -B 2 /tmp/build/perf/FEATURE-DUMP
feature-dwarf=1
feature-dwarf_getlocations=1
feature-eventfd=1
feature-fortify-source=1
feature-sync-compare-and-swap=1
$

The main thing here is that in the end we'll have -DHAVE_EVENTFD in
CFLAGS, and then the 'perf bench' entry needing that API can be
selectively pruned.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-wkeldwob7dpx6jvtuzl8164k@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+23 -1
+1
tools/build/Makefile.feature
··· 31 31 backtrace \ 32 32 dwarf \ 33 33 dwarf_getlocations \ 34 + eventfd \ 34 35 fortify-source \ 35 36 sync-compare-and-swap \ 36 37 get_current_dir_name \
+4
tools/build/feature/Makefile
··· 5 5 test-bionic.bin \ 6 6 test-dwarf.bin \ 7 7 test-dwarf_getlocations.bin \ 8 + test-eventfd.bin \ 8 9 test-fortify-source.bin \ 9 10 test-sync-compare-and-swap.bin \ 10 11 test-get_current_dir_name.bin \ ··· 102 101 103 102 $(OUTPUT)test-libelf.bin: 104 103 $(BUILD) -lelf 104 + 105 + $(OUTPUT)test-eventfd.bin: 106 + $(BUILD) 105 107 106 108 $(OUTPUT)test-get_current_dir_name.bin: 107 109 $(BUILD)
+5
tools/build/feature/test-all.c
··· 50 50 # include "test-dwarf_getlocations.c" 51 51 #undef main 52 52 53 + #define main main_test_eventfd 54 + # include "test-eventfd.c" 55 + #undef main 56 + 53 57 #define main main_test_libelf_getphdrnum 54 58 # include "test-libelf-getphdrnum.c" 55 59 #undef main ··· 186 182 main_test_glibc(); 187 183 main_test_dwarf(); 188 184 main_test_dwarf_getlocations(); 185 + main_test_eventfd(); 189 186 main_test_libelf_getphdrnum(); 190 187 main_test_libelf_gelf_getnote(); 191 188 main_test_libelf_getshdrstrndx();
+9
tools/build/feature/test-eventfd.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 + 4 + #include <sys/eventfd.h> 5 + 6 + int main(void) 7 + { 8 + return eventfd(0, EFD_NONBLOCK); 9 + }
+4 -1
tools/perf/Makefile.config
··· 299 299 endif 300 300 endif 301 301 302 + ifeq ($(feature-eventfd), 1) 303 + CFLAGS += -DHAVE_EVENTFD 304 + endif 305 + 302 306 ifeq ($(feature-get_current_dir_name), 1) 303 307 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME 304 308 endif 305 - 306 309 307 310 ifdef NO_LIBELF 308 311 NO_DWARF := 1