1 From 8e36ad01ceb1257d05773b684dbe9358aecd3f71 Mon Sep 17 00:00:00 2001
2 From: Maynard Johnson <maynardj@us.ibm.com>
3 Date: Tue, 26 Feb 2013 13:41:27 -0600
4 Subject: [PATCH] Fix PPC64-specific libpfm usage so it doesn't break ppc32
7 The configure check to determine whether we should use libpfm or not
8 is intended only for the ppc64 architecture, but was incorrectly
9 hitting on the ppc32 architecture, too. Not only that, but it was using
10 'uname' which is not a good idea in cross-compile situtations.
12 Then, aside from that, we had several instances in the source code
14 #if (defined(__powerpc__) || defined(__powerpc64__))
15 which incorrectly included ppc32 architecutre also, when it was intended
16 for use as PPC64 architecture.
18 This patch fixes both errors.
20 Signed-off-by: Maynard Johnson <maynardj@us.ibm.com
22 configure.ac | 5 ++---
23 libperf_events/operf_utils.cpp | 4 ++--
24 libperf_events/operf_utils.h | 6 ++++++
25 pe_profiling/operf.cpp | 10 +++++-----
26 4 files changed, 15 insertions(+), 10 deletions(-)
28 diff --git a/configure.ac b/configure.ac
29 index a9b1ee4..a0da98c 100644
32 @@ -154,11 +154,10 @@ else
35 AC_DEFINE_UNQUOTED(HAVE_PERF_EVENTS, $HAVE_PERF_EVENTS, [Kernel support for perf_events exists])
38 if test "$HAVE_PERF_EVENTS" = "1"; then
41 - if test "$arch" = "ppc64" || test "$arch" = "ppc"; then
42 + if test "$host_cpu" = "powerpc64"; then
43 AC_CHECK_HEADER(perfmon/pfmlib.h,,[AC_MSG_ERROR([pfmlib.h not found; usually provided in papi devel package])])
44 AC_CHECK_LIB(pfm,pfm_get_os_event_encoding, HAVE_LIBPFM3='0'; HAVE_LIBPFM='1', [
45 AC_CHECK_LIB(pfm, pfm_get_event_name, HAVE_LIBPFM3='1'; HAVE_LIBPFM='1',
46 diff --git a/libperf_events/operf_utils.cpp b/libperf_events/operf_utils.cpp
47 index da964fd..a17200b 100644
48 --- a/libperf_events/operf_utils.cpp
49 +++ b/libperf_events/operf_utils.cpp
50 @@ -83,7 +83,7 @@ static event_t comm_event;
51 * the following method is to map the operf-record event value to a value that
52 * opreport can understand.
54 -#if (defined(__powerpc__) || defined(__powerpc64__))
59 @@ -716,7 +716,7 @@ static void __handle_sample_event(event_t * event, u64 sample_type)
60 } else if (event->header.misc == PERF_RECORD_MISC_USER) {
63 -#if (defined(__powerpc__) || defined(__powerpc64__))
65 else if (event->header.misc == PERF_RECORD_MISC_HYPERVISOR) {
66 #define MAX_HYPERVISOR_ADDRESS 0xfffffffULL
67 if (data.ip > MAX_HYPERVISOR_ADDRESS) {
68 diff --git a/libperf_events/operf_utils.h b/libperf_events/operf_utils.h
69 index 2df00b7..ddf05ed 100644
70 --- a/libperf_events/operf_utils.h
71 +++ b/libperf_events/operf_utils.h
72 @@ -45,6 +45,12 @@ extern bool throttled;
73 #define MMAP_WINDOW_SZ (32 * 1024 * 1024ULL)
76 +/* A macro to be used for ppc64 architecture-specific code. The '__powerpc__' macro
77 + * is defined for both ppc64 and ppc32 architectures, so we must further qualify by
78 + * including the 'HAVE_LIBPFM' macro, since that macro will be defined only for ppc64.
80 +#define PPC64_ARCH (HAVE_LIBPFM) && ((defined(__powerpc__) || defined(__powerpc64__)))
82 extern unsigned int op_nr_counters;
84 static inline size_t align_64bit(u64 x)
85 diff --git a/pe_profiling/operf.cpp b/pe_profiling/operf.cpp
86 index e7c2eab..e1190c2 100644
87 --- a/pe_profiling/operf.cpp
88 +++ b/pe_profiling/operf.cpp
89 @@ -1177,7 +1177,7 @@ static void _get_event_code(operf_event_t * event)
90 event->evt_code = config;
93 -#if (defined(__powerpc__) || defined(__powerpc64__))
95 /* All ppc64 events (except CYCLES) have a _GRP<n> suffix. This is
96 * because the legacy opcontrol profiler can only profile events in
97 * the same group (i.e., having the same _GRP<n> suffix). But operf
98 @@ -1287,7 +1287,7 @@ static void _process_events_list(void)
99 string full_cmd = cmd;
100 string event_spec = operf_options::evts[i];
102 -#if (defined(__powerpc__) || defined(__powerpc64__))
104 event_spec = _handle_powerpc_event_spec(event_spec);
107 @@ -1357,9 +1357,9 @@ static void _process_events_list(void)
108 _get_event_code(&event);
109 events.push_back(event);
111 -#if (defined(__powerpc__) || defined(__powerpc64__))
114 - /* This section of code is for architectures such as ppc[64] for which
115 + /* This section of code is soley for the ppc64 architecture for which
116 * the oprofile event code needs to be converted to the appropriate event
117 * code to pass to the perf_event_open syscall.
119 @@ -1404,7 +1404,7 @@ static void get_default_event(void)
120 _get_event_code(&dft_evt);
121 events.push_back(dft_evt);
123 -#if (defined(__powerpc__) || defined(__powerpc64__))
126 /* This section of code is for architectures such as ppc[64] for which
127 * the oprofile event code needs to be converted to the appropriate event