Skip to content

Commit 49c692b

Browse files
namhyungacmel
authored andcommitted
perf offcpu: Accept allowed sample types only
As offcpu-time event is synthesized at the end, it could not get the all the sample info. Define OFFCPU_SAMPLE_TYPES for allowed ones and mask out others in evsel__config() to prevent parse errors. Because perf sample parsing assumes a specific ordering with the sample types, setting unsupported one would make it fail to read data like perf record -d/--data. Fixes: edc41a1 ("perf record: Enable off-cpu analysis with BPF") Signed-off-by: Namhyung Kim <[email protected]> Cc: Blake Jones <[email protected]> Cc: Hao Luo <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Milian Wolff <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d6838ec commit 49c692b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

tools/perf/util/bpf_off_cpu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ int off_cpu_write(struct perf_session *session)
265265

266266
sample_type = evsel->core.attr.sample_type;
267267

268+
if (sample_type & ~OFFCPU_SAMPLE_TYPES) {
269+
pr_err("not supported sample type: %llx\n",
270+
(unsigned long long)sample_type);
271+
return -1;
272+
}
273+
268274
if (sample_type & (PERF_SAMPLE_ID | PERF_SAMPLE_IDENTIFIER)) {
269275
if (evsel->core.id)
270276
sid = evsel->core.id[0];
@@ -319,7 +325,6 @@ int off_cpu_write(struct perf_session *session)
319325
}
320326
if (sample_type & PERF_SAMPLE_CGROUP)
321327
data.array[n++] = key.cgroup_id;
322-
/* TODO: handle more sample types */
323328

324329
size = n * sizeof(u64);
325330
data.hdr.size = size;

tools/perf/util/evsel.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "util.h"
4949
#include "hashmap.h"
5050
#include "pmu-hybrid.h"
51+
#include "off_cpu.h"
5152
#include "../perf-sys.h"
5253
#include "util/parse-branch-options.h"
5354
#include <internal/xyarray.h>
@@ -1102,6 +1103,11 @@ static void evsel__set_default_freq_period(struct record_opts *opts,
11021103
}
11031104
}
11041105

1106+
static bool evsel__is_offcpu_event(struct evsel *evsel)
1107+
{
1108+
return evsel__is_bpf_output(evsel) && !strcmp(evsel->name, OFFCPU_EVENT);
1109+
}
1110+
11051111
/*
11061112
* The enable_on_exec/disabled value strategy:
11071113
*
@@ -1366,6 +1372,9 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
13661372
*/
13671373
if (evsel__is_dummy_event(evsel))
13681374
evsel__reset_sample_bit(evsel, BRANCH_STACK);
1375+
1376+
if (evsel__is_offcpu_event(evsel))
1377+
evsel->core.attr.sample_type &= OFFCPU_SAMPLE_TYPES;
13691378
}
13701379

13711380
int evsel__set_filter(struct evsel *evsel, const char *filter)

tools/perf/util/off_cpu.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#ifndef PERF_UTIL_OFF_CPU_H
22
#define PERF_UTIL_OFF_CPU_H
33

4+
#include <linux/perf_event.h>
5+
46
struct evlist;
57
struct target;
68
struct perf_session;
79
struct record_opts;
810

911
#define OFFCPU_EVENT "offcpu-time"
1012

13+
#define OFFCPU_SAMPLE_TYPES (PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_IP | \
14+
PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
15+
PERF_SAMPLE_ID | PERF_SAMPLE_CPU | \
16+
PERF_SAMPLE_PERIOD | PERF_SAMPLE_CALLCHAIN | \
17+
PERF_SAMPLE_CGROUP)
18+
19+
1120
#ifdef HAVE_BPF_SKEL
1221
int off_cpu_prepare(struct evlist *evlist, struct target *target,
1322
struct record_opts *opts);

0 commit comments

Comments
 (0)