summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch')
-rw-r--r--meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch208
1 files changed, 208 insertions, 0 deletions
diff --git a/meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch b/meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch
new file mode 100644
index 0000000000..d19948a4f8
--- /dev/null
+++ b/meta/recipes-kernel/oprofile/oprofile/0001-Allow-ppc64-events-to-be-specified-with-or-without-_.patch
@@ -0,0 +1,208 @@
1Upstream-Status: Accepted
2
3From 36028035555297695f52e856f21920012fd64f79 Mon Sep 17 00:00:00 2001
4From: Maynard Johnson <maynardj@us.ibm.com>
5Date: Fri, 11 Jan 2013 13:29:57 -0600
6Subject: [PATCH] Allow ppc64 events to be specified with or without _GRP<n>
7 suffix
8
9All events for IBM PowerPC server processors (except CYCLES) have
10a _GRP<n> suffix. This is because the legacy opcontrol profiler
11can only profile events in the same group (i.e., having the same
12_GRP<n> suffix). But operf has no such restriction because it
13can multiplex events; thus, so we should allow the user to pass
14event names without the _GRP<n> suffix.
15
16Signed-off-by: Maynard Johnson <maynardj@us.ibm.com>
17---
18 doc/operf.1.in | 6 +++
19 doc/oprofile.xml | 12 +++++-
20 pe_profiling/operf.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++++
21 utils/ophelp.c | 4 ++
22 4 files changed, 127 insertions(+), 2 deletions(-)
23
24diff --git a/doc/operf.1.in b/doc/operf.1.in
25index b109324..03027ca 100644
26--- a/doc/operf.1.in
27+++ b/doc/operf.1.in
28@@ -110,6 +110,12 @@ be specified using the symbolic name. If no unit mask is specified, 0x0 will be
29 used as the default.
30 .P
31 .RS
32+On IBM PowerPC systems, events may be specified with or without the
33+.I _GRP<n>
34+suffix. If no group number suffix is given, one will be automatically
35+assigned; thus, OProfile post-processing tools will always show real event
36+names that include the group number suffix.
37+.P
38 When no event specification is given, the default event for the running
39 processor type will be used for profiling.
40 Use
41diff --git a/doc/oprofile.xml b/doc/oprofile.xml
42index 0ae2b0b..0f74726 100644
43--- a/doc/oprofile.xml
44+++ b/doc/oprofile.xml
45@@ -1106,10 +1106,18 @@ shown by the output of <command>ophelp</command>. Unit masks with "extra:" para
46 specified using the symbolic name.
47 </para>
48 <note><para>
49-When using legacy mode <command>opcontrol</command> on PowerPC platforms, all events specified must be in the same group;
50+When using legacy mode <command>opcontrol</command> on IBM PowerPC platforms, all events specified must be in the same group;
51 i.e., the group number appended to the event name (e.g. <constant>&lt;<emphasis>some-event-name</emphasis>&gt;_GRP9
52 </constant>) must be the same.
53-</para></note>
54+</para>
55+<para>
56+When profiling with <command>operf</command> on IBM PowerPC platforms, the above restriction
57+regarding the same group number does not apply, and events may be
58+specified with or without the group number suffix. If no group number suffix is given, one will be automatically
59+assigned; thus, OProfile post-processing tools will always show real event
60+names that include the group number suffix.
61+</para>
62+</note>
63 <para>
64 If OProfile is using timer-interrupt mode, there is no event configuration possible.
65 </para>
66diff --git a/pe_profiling/operf.cpp b/pe_profiling/operf.cpp
67index 4416b29..a776e71 100644
68--- a/pe_profiling/operf.cpp
69+++ b/pe_profiling/operf.cpp
70@@ -1146,6 +1146,108 @@ static void _get_event_code(operf_event_t * event)
71 event->evt_code = config;
72 }
73
74+#if (defined(__powerpc__) || defined(__powerpc64__))
75+/* All ppc64 events (except CYCLES) have a _GRP<n> suffix. This is
76+ * because the legacy opcontrol profiler can only profile events in
77+ * the same group (i.e., having the same _GRP<n> suffix). But operf
78+ * can multiplex events, so we should allow the user to pass event
79+ * names without the _GRP<n> suffix.
80+ *
81+ * If event name is not CYCLES or does not have a _GRP<n> suffix,
82+ * we'll call ophelp and scan the list of events, searching for one
83+ * that matches up to the _GRP<n> suffix. If we don't find a match,
84+ * then we'll exit with the expected error message for invalid event name.
85+ */
86+static string _handle_powerpc_event_spec(string event_spec)
87+{
88+ FILE * fp;
89+ char line[MAX_INPUT];
90+ size_t grp_pos;
91+ string evt, retval, err_msg;
92+ size_t evt_name_len;
93+ bool first_non_cyc_evt_found = false;
94+ bool event_found = false;
95+ char event_name[OP_MAX_EVT_NAME_LEN], event_spec_str[OP_MAX_EVT_NAME_LEN + 20], * count_str;
96+ string cmd = OP_BINDIR;
97+ cmd += "/ophelp";
98+
99+ strncpy(event_spec_str, event_spec.c_str(), event_spec.length() + 1);
100+
101+ strncpy(event_name, strtok(event_spec_str, ":"), OP_MAX_EVT_NAME_LEN);
102+ count_str = strtok(NULL, ":");
103+ if (!count_str) {
104+ err_msg = "Invalid count for event ";
105+ goto out;
106+ }
107+
108+ if (!strcmp("CYCLES", event_name)) {
109+ event_found = true;
110+ goto out;
111+ }
112+
113+ evt = event_name;
114+ // Need to make sure the event name truly has a _GRP<n> suffix.
115+ grp_pos = evt.rfind("_GRP");
116+ if ((grp_pos != string::npos) && ((evt = evt.substr(grp_pos, string::npos))).length() > 4) {
117+ unsigned long value;
118+ char * end;
119+ value = strtoul(evt.substr(4, string::npos).c_str(), &end, 0);
120+ if (end && (*end == '\0')) {
121+ // Valid group number found after _GRP, so we can skip to the end.
122+ event_found = true;
123+ goto out;
124+ }
125+ }
126+
127+ // If we get here, it implies the user passed a non-CYCLES event without a GRP suffix.
128+ // Lets try to find a valid suffix for it.
129+ fp = popen(cmd.c_str(), "r");
130+ if (fp == NULL) {
131+ cerr << "Unable to execute ophelp to get info for event "
132+ << event_spec << endl;
133+ exit(EXIT_FAILURE);
134+ }
135+ evt_name_len = strlen(event_name);
136+ err_msg = "Cannot find event ";
137+ while (fgets(line, MAX_INPUT, fp)) {
138+ if (!first_non_cyc_evt_found) {
139+ if (!strncmp(line, "PM_", 3))
140+ first_non_cyc_evt_found = true;
141+ else
142+ continue;
143+ }
144+ if (line[0] == ' ' || line[0] == '\t')
145+ continue;
146+ if (!strncmp(line, event_name, evt_name_len)) {
147+ // Found a potential match. Check if it's a perfect match.
148+ string save_event_name = event_name;
149+ size_t full_evt_len = index(line, ':') - line;
150+ memset(event_name, '\0', OP_MAX_EVT_NAME_LEN);
151+ strncpy(event_name, line, full_evt_len);
152+ string candidate = event_name;
153+ if (candidate.rfind("_GRP") == evt_name_len) {
154+ event_found = true;
155+ break;
156+ } else {
157+ memset(event_name, '\0', OP_MAX_EVT_NAME_LEN);
158+ strncpy(event_name, save_event_name.c_str(), evt_name_len);
159+ }
160+ }
161+ }
162+ pclose(fp);
163+
164+out:
165+ if (!event_found) {
166+ cerr << err_msg << event_name << endl;
167+ cerr << "Error retrieving info for event "
168+ << event_spec << endl;
169+ exit(EXIT_FAILURE);
170+ }
171+ retval = event_name;
172+ return retval + ":" + count_str;
173+}
174+#endif
175+
176 static void _process_events_list(void)
177 {
178 string cmd = OP_BINDIR;
179@@ -1154,6 +1256,11 @@ static void _process_events_list(void)
180 FILE * fp;
181 string full_cmd = cmd;
182 string event_spec = operf_options::evts[i];
183+
184+#if (defined(__powerpc__) || defined(__powerpc64__))
185+ event_spec = _handle_powerpc_event_spec(event_spec);
186+#endif
187+
188 if (operf_options::callgraph) {
189 full_cmd += " --callgraph=1 ";
190 }
191diff --git a/utils/ophelp.c b/utils/ophelp.c
192index 53a5dde..63895c8 100644
193--- a/utils/ophelp.c
194+++ b/utils/ophelp.c
195@@ -652,6 +652,10 @@ int main(int argc, char const * argv[])
196 case CPU_PPC64_POWER7:
197 case CPU_PPC64_IBM_COMPAT_V1:
198 event_doc =
199+ "When using operf, events may be specified without a '_GRP<n>' suffix.\n"
200+ "If _GRP<n> (i.e., group number) is not specified, one will be automatically\n"
201+ "selected for use by the profiler. OProfile post-processing tools will\n"
202+ "always show real event names that include the group number suffix.\n\n"
203 "Documentation for IBM POWER7 can be obtained at:\n"
204 "http://www.power.org/events/Power7/\n"
205 "No public performance monitoring doc available for older processors.\n";
206--
2071.7.9.7
208