Re: [PATCH 2/9] perf/core: Add PERF_SAMPLE_CGROUP feature
From: Peter Zijlstra
Date: Fri Dec 20 2019 - 04:36:29 EST
On Fri, Dec 20, 2019 at 01:32:46PM +0900, Namhyung Kim wrote:
> The PERF_SAMPLE_CGROUP bit is to save (perf_event) cgroup information
> in the sample. It will add a 64-bit id to identify current cgroup and
> it's the file handle in the cgroup file system. Userspace should use
> this information with PERF_RECORD_CGROUP event to match which cgroup
> it belongs.
>
> I put it before PERF_SAMPLE_AUX for simplicity since it just needs a
> 64-bit word. But if we want bigger samples, I can work on that
> direction too.
>
> Cc: Tejun Heo <tj@xxxxxxxxxx>
> Cc: Li Zefan <lizefan@xxxxxxxxxx>
> Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> ---
> @@ -6895,6 +6901,18 @@ void perf_prepare_sample(struct perf_event_header *header,
> if (sample_type & PERF_SAMPLE_PHYS_ADDR)
> data->phys_addr = perf_virt_to_phys(data->addr);
>
> + if (sample_type & PERF_SAMPLE_CGROUP) {
> + u64 cgrp_id = 0;
> +#ifdef CONFIG_CGROUP_PERF
> + struct cgroup *cgrp;
> +
> + /* protected by RCU */
> + cgrp = task_css_check(current, perf_event_cgrp_id, 1)->cgroup;
> + cgrp_id = cgroup_id(cgrp);
> +#endif
> + data->cgroup = cgrp_id;
> + }
Would it make more sense to refuse SAMPLE_CGROUP if !CGROUP_PERF?