Skip to content

Commit

Permalink
autoconf: check for linux/perf_event.h
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Alex Wang <[email protected]>
  • Loading branch information
azhou-nicira committed Apr 16, 2015
1 parent 212c4d5 commit 9a6156b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/perf-counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions lib/perf-counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,16 +129,16 @@ 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) {}
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
Expand Down
4 changes: 4 additions & 0 deletions m4/openvswitch.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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])])
Expand Down

0 comments on commit 9a6156b

Please sign in to comment.