Skip to content

Commit 4f2abe9

Browse files
namhyungacmel
authored andcommitted
perf record: Move probing cgroup sampling support
I found that checking cgroup sampling support using the missing features doesn't work on old kernels. Because it added both attr.cgroup bit and PERF_SAMPLE_CGROUP bit, it needs to check whichever comes first (usually the actual event, not dummy). But it only checks the attr.cgroup bit which is set only in the dummy event so cannot detect failtures due the sample bits. Also we don't ignore the missing feature and retry, it'd be better checking it with the API probing logic. Committer notes: Extracted the minimal part to check using the new cgroup API probe routine, the part that removes the cgroup member can be left for further discussion. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20210527182835.1634339-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3cb17cc commit 4f2abe9

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

tools/perf/builtin-record.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,12 @@ int cmd_record(int argc, const char **argv)
27142714
rec->no_buildid = true;
27152715
}
27162716

2717+
if (rec->opts.record_cgroup && !perf_can_record_cgroup()) {
2718+
pr_err("Kernel has no cgroup sampling support.\n");
2719+
err = -EINVAL;
2720+
goto out_opts;
2721+
}
2722+
27172723
if (rec->opts.kcore)
27182724
rec->data.is_dir = true;
27192725

tools/perf/util/perf_api_probe.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ static void perf_probe_build_id(struct evsel *evsel)
103103
evsel->core.attr.build_id = 1;
104104
}
105105

106+
static void perf_probe_cgroup(struct evsel *evsel)
107+
{
108+
evsel->core.attr.cgroup = 1;
109+
}
110+
106111
bool perf_can_sample_identifier(void)
107112
{
108113
return perf_probe_api(perf_probe_sample_identifier);
@@ -182,3 +187,8 @@ bool perf_can_record_build_id(void)
182187
{
183188
return perf_probe_api(perf_probe_build_id);
184189
}
190+
191+
bool perf_can_record_cgroup(void)
192+
{
193+
return perf_probe_api(perf_probe_cgroup);
194+
}

tools/perf/util/perf_api_probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ bool perf_can_record_switch_events(void);
1212
bool perf_can_record_text_poke_events(void);
1313
bool perf_can_sample_identifier(void);
1414
bool perf_can_record_build_id(void);
15+
bool perf_can_record_cgroup(void);
1516

1617
#endif // __PERF_API_PROBE_H

0 commit comments

Comments
 (0)