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