Re: [PATCH 14/16] perf kvm: reuse some code of perf_kvm__timerfd_create()

Ingo Molnar
2013-09-12T13:08:55Z

btw., I tried to build perf on a really old distro that has no timerfd.h,
and got:

builtin-kvm.c:22:25: error: sys/timerfd.h: No such file or directory
cc1: warnings being treated as errors
builtin-kvm.c: In function ‘perf_kvm__timerfd_create’:
builtin-kvm.c:967: warning: implicit declaration of function ‘timerfd_create’
builtin-kvm.c:967: warning: nested extern declaration of ‘timerfd_create’
builtin-kvm.c:967: error: ‘TFD_NONBLOCK’ undeclared (first use in this function)
builtin-kvm.c:967: error: (Each undeclared identifier is reported only once
builtin-kvm.c:967: error: for each function it appears in.)
builtin-kvm.c:978: warning: implicit declaration of function ‘timerfd_settime’
builtin-kvm.c:978: warning: nested extern declaration of ‘timerfd_settime’
make: *** [builtin-kvm.o] Error 1
make: *** Waiting for unfinished jobs....

The quick patch below made it build - but it's incomplete, I have not
filled in the config/* details to generate HAVE_TIMERFD, I only made
builtin-kvm.o build.

Thanks,

Ingo

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 935d522..5cae8f2 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -19,7 +19,22 @@
#include "util/top.h"

#include <sys/prctl.h>
-#include <sys/timerfd.h>
+#ifdef HAVE_TIMERFD
+# include <sys/timerfd.h>
+#else
+# define TFD_NONBLOCK -1
+static int timerfd_create(clockid_t __clock_id __maybe_unused, int __flags __maybe_unused)
+{
+ return -1;
+}
+static int timerfd_settime(int __ufd __maybe_unused, int __flags __maybe_unused,
+ const struct itimerspec *__utmr __maybe_unused,
+ struct itimerspec *__otmr __maybe_unused)
+{
+ return -1;
+}
+
+#endif

#include <termios.h>
#include <semaphore.h>