autoconf: check for linux/perf_event.h
authorAndy Zhou <azhou@nicira.com>
Thu, 16 Apr 2015 19:52:09 +0000 (12:52 -0700)
committerAndy Zhou <azhou@nicira.com>
Thu, 16 Apr 2015 21:21:05 +0000 (14:21 -0700)
Older Linux prior to version 2.6.32 do not support user mode
performance events, They also don't have 'linux/perf_event.h' header
file. Add check for those older Linux to conditionally compile
perf-counter.c

Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
configure.ac
lib/perf-counter.c
lib/perf-counter.h
m4/openvswitch.m4

index 8d47eb9..d1b48ca 100644 (file)
@@ -111,6 +111,7 @@ OVS_CHECK_PKIDIR
 OVS_CHECK_RUNDIR
 OVS_CHECK_DBDIR
 OVS_CHECK_BACKTRACE
+OVS_CHECK_PERF_EVENT
 OVS_CHECK_VALGRIND
 OVS_CHECK_SOCKET_LIBS
 OVS_CHECK_XENSERVER_VERSION
index 4188f6b..a6c4965 100644 (file)
@@ -15,7 +15,9 @@
  */
 
 /* This implementation only applies to the Linux platform.  */
-#ifdef __linux__
+
+#include <config.h>
+#if defined(__linux__) && defined(HAVE_PERF_EVENT_H)
 
 #include <stddef.h>
 #include <sys/types.h>
@@ -24,7 +26,6 @@
 #include <sys/ioctl.h>
 #include <linux/perf_event.h>
 #include <asm/unistd.h>
-#include <config.h>
 #include "dynamic-string.h"
 #include "openvswitch/vlog.h"
 #include "perf-counter.h"
index c9abf72..9cdec5b 100644 (file)
@@ -94,7 +94,7 @@
  * will work just fine.
  */
 
-#ifdef __linux__
+#if defined(__linux__) && defined(HAVE_PERF_EVENT_H)
 struct perf_counter {
     const char *name;
     bool once;
@@ -129,8 +129,8 @@ char *perf_counters_to_string(void);
 
 #else
 
-#define PERF_FUNCTON_COUNT_BEGIN
-#define PERF_FUNCTON_COUNT_END
+#define PERF_FUNCTON_BEGIN
+#define PERF_FUNCTON_END
 
 static inline void perf_counters_init(void) {}
 static inline void perf_counters_destroy(void) {}
@@ -138,7 +138,7 @@ static inline void perf_counters_clear(void) {}
 static inline char *
 perf_counters_to_string(void)
 {
-    return xstrdup("Not Supported on this platform. Only available on Linux.");
+    return xstrdup("Not Supported on this platform. Only available on Linux (version >= 2.6.32)");
 }
 
 #endif
index ba3ed9b..8ace9ce 100644 (file)
@@ -243,6 +243,10 @@ AC_DEFUN([OVS_CHECK_BACKTRACE],
                   [AC_DEFINE([HAVE_BACKTRACE], [1],
                              [Define to 1 if you have backtrace(3).])])])
 
+dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
+AC_DEFUN([OVS_CHECK_PERF_EVENT],
+  [AC_CHECK_HEADERS([linux/perf_event.h])])
+
 dnl Checks for valgrind/valgrind.h.
 AC_DEFUN([OVS_CHECK_VALGRIND],
   [AC_CHECK_HEADERS([valgrind/valgrind.h])])