Skip to content

Commit fb50c09

Browse files
olsajiriacmel
authored andcommitted
perf tools: Fix crash on synthesizing the unit
Adam reported a record command crash for simple session like: $ perf record -e cpu-clock ls with following backtrace: Program received signal SIGSEGV, Segmentation fault. 3543 ev = event_update_event__new(size + 1, PERF_EVENT_UPDATE__UNIT, evsel->id[0]); (gdb) bt #0 perf_event__synthesize_event_update_unit #1 0x000000000051e469 in perf_event__synthesize_extra_attr #2 0x00000000004445cb in record__synthesize #3 0x0000000000444bc5 in __cmd_record ... We synthesize an update event that needs to touch the evsel id array, which is not defined at that time. Fix this by forcing the id allocation for events with their unit defined. Reflecting possible read_format ID bit in the attr tests. Reported-by: Yongxin Liu <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Cc: Adam Lee <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201477 Fixes: bfd8f72 ("perf record: Synthesize unit/scale/... in event update") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4d47d64 commit fb50c09

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

tools/perf/tests/attr/base-record

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ size=112
99
config=0
1010
sample_period=*
1111
sample_type=263
12-
read_format=0
12+
read_format=0|4
1313
disabled=1
1414
inherit=1
1515
pinned=0

tools/perf/util/evsel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
10921092
attr->exclude_user = 1;
10931093
}
10941094

1095-
if (evsel->own_cpus)
1095+
if (evsel->own_cpus || evsel->unit)
10961096
evsel->attr.read_format |= PERF_FORMAT_ID;
10971097

10981098
/*

0 commit comments

Comments
 (0)