Skip to content

Commit 5b61adb

Browse files
olsajiriacmel
authored andcommitted
perf evsel: Probe for precise_ip with simple attr
Currently we probe for precise_ip with user specified perf_event_attr, which might fail because of unsupported kernel features, which would get disabled during the open time anyway. Switching the probe to take place on simple hw cycles, so the following record sets proper precise_ip: # perf record -e cycles:P ls # perf evlist -v cycles:P: size: 112, ... precise_ip: 3, ... Signed-off-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jonas Rabenstein <[email protected]> Cc: Nageswara R Sastry <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 90a86bd commit 5b61adb

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

tools/perf/util/evlist.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,33 @@ void perf_evlist__set_leader(struct perf_evlist *evlist)
230230
}
231231
}
232232

233-
void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
233+
void perf_event_attr__set_max_precise_ip(struct perf_event_attr *pattr)
234234
{
235-
attr->precise_ip = 3;
235+
struct perf_event_attr attr = {
236+
.type = PERF_TYPE_HARDWARE,
237+
.config = PERF_COUNT_HW_CPU_CYCLES,
238+
.exclude_kernel = 1,
239+
.precise_ip = 3,
240+
};
236241

237-
while (attr->precise_ip != 0) {
238-
int fd = sys_perf_event_open(attr, 0, -1, -1, 0);
242+
event_attr_init(&attr);
243+
244+
/*
245+
* Unnamed union member, not supported as struct member named
246+
* initializer in older compilers such as gcc 4.4.7
247+
*/
248+
attr.sample_period = 1;
249+
250+
while (attr.precise_ip != 0) {
251+
int fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
239252
if (fd != -1) {
240253
close(fd);
241254
break;
242255
}
243-
--attr->precise_ip;
256+
--attr.precise_ip;
244257
}
258+
259+
pattr->precise_ip = attr.precise_ip;
245260
}
246261

247262
int __perf_evlist__add_default(struct perf_evlist *evlist, bool precise)

tools/perf/util/evsel.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,12 @@ struct perf_evsel *perf_evsel__new_cycles(bool precise)
294294

295295
if (!precise)
296296
goto new_event;
297-
/*
298-
* Unnamed union member, not supported as struct member named
299-
* initializer in older compilers such as gcc 4.4.7
300-
*
301-
* Just for probing the precise_ip:
302-
*/
303-
attr.sample_period = 1;
304297

305298
perf_event_attr__set_max_precise_ip(&attr);
306299
/*
307300
* Now let the usual logic to set up the perf_event_attr defaults
308301
* to kick in when we return and before perf_evsel__open() is called.
309302
*/
310-
attr.sample_period = 0;
311303
new_event:
312304
evsel = perf_evsel__new(&attr);
313305
if (evsel == NULL)

0 commit comments

Comments
 (0)