Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
4f2abe91 3cb17cce

+17
+6
tools/perf/builtin-record.c
··· 2714 2714 rec->no_buildid = true; 2715 2715 } 2716 2716 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 + 2717 2723 if (rec->opts.kcore) 2718 2724 rec->data.is_dir = true; 2719 2725
+10
tools/perf/util/perf_api_probe.c
··· 103 103 evsel->core.attr.build_id = 1; 104 104 } 105 105 106 + static void perf_probe_cgroup(struct evsel *evsel) 107 + { 108 + evsel->core.attr.cgroup = 1; 109 + } 110 + 106 111 bool perf_can_sample_identifier(void) 107 112 { 108 113 return perf_probe_api(perf_probe_sample_identifier); ··· 186 181 bool perf_can_record_build_id(void) 187 182 { 188 183 return perf_probe_api(perf_probe_build_id); 184 + } 185 + 186 + bool perf_can_record_cgroup(void) 187 + { 188 + return perf_probe_api(perf_probe_cgroup); 189 189 }
+1
tools/perf/util/perf_api_probe.h
··· 12 12 bool perf_can_record_text_poke_events(void); 13 13 bool perf_can_sample_identifier(void); 14 14 bool perf_can_record_build_id(void); 15 + bool perf_can_record_cgroup(void); 15 16 16 17 #endif // __PERF_API_PROBE_H