perf_events: add support for per-cpu per-cgroup monitoring (v2)
Subsystems (2)
RFC PATCH 1/2 perf_events: add support for per-cpu per-cgroup monitoring (v2)
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The patch adds perf_event_attr.cgroup, a boolean, to activate this new mode. The cgroup is designated by passing in perf_event_attr.cgroup_fd, an opened file descriptor to the <mnt>/<cgroup>/perf_event.perf file.
This is the second version of this patch. It corrects the way time_enabled is accounted for. In cgroup mode, time_enabled reflects the time the cgroup was active, i.e., threads from the cgroup executed on the monitored CPU. This is a more useful metric than just wall-clock. The meaning of time_enabled without cgroup is unaffected.
--
include/linux/cgroup.h +2 -0
@@ -618,6 +618,8 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,unsigned short css_id (struct cgroup_subsys_state *css);unsigned short css_depth (struct cgroup_subsys_state *css); +struct cgroup_subsys_state *cgroup_css_from_file (struct file *f,int id); +#else /* !CONFIG_CGROUPS */ static inline int cgroup_init_early (void ) {return 0 ; }
include/linux/cgroup_subsys.h +4 -0
@@ -65,4 +65,8 @@ SUBSYS(net_cls) SUBSYS(blkio)#endif +#ifdef CONFIG_PERF_EVENTS +SUBSYS(perf) +#endif +/* */
include/linux/perf_event.h +20 -2
@@ -215,8 +215,9 @@ struct perf_event_attr {*/ precise_ip : 2, /* skid constraint */ mmap_data : 1, /* non-exec mmap data */ + cgroup : 1, /* cgroup aggregation */ - __reserved_1 : 46; + __reserved_1 : 45;union {__u32 wakeup_events;/* wakeup every n events */
@@ -226,6 +227,8 @@ struct perf_event_attr {__u32 bp_type;__u64 bp_addr;__u64 bp_len; + +int cgroup_fd; };/*
@@ -463,6 +466,7 @@ enum perf_callchain_context {#ifdef CONFIG_PERF_EVENTS # include <asm/perf_event.h> # include <asm/local64.h> +# include <linux/cgroup.h> #endif struct perf_guest_info_callbacks {
@@ -657,6 +661,16 @@ struct swevent_hlist {#define PERF_ATTACH_CONTEXT 0x01#define PERF_ATTACH_GROUP 0x02 +#ifdef CONFIG_CGROUPS +struct perf_cgroup { +struct cgroup_subsys_state css; +struct { +u64 time; +u64 timestamp; + } times[NR_CPUS ]____cacheline_aligned_in_smp ; +}; +#endif +/** * struct perf_event - performance event kernel representation: */
@@ -759,7 +773,9 @@ struct perf_event {struct ftrace_event_call *tp_event;struct event_filter *filter;#endif - +#ifdef CONFIG_CGROUPS +struct perf_cgroup *css; +#endif #endif /* CONFIG_PERF_EVENTS */ };
@@ -806,6 +822,8 @@ struct perf_event_context {u64 generation;int pin_count;struct rcu_head rcu_head; + +int nr_cgroups; };/*
kernel/cgroup.c +17 -0
@@ -4722,6 +4722,23 @@ css_get_next(struct cgroup_subsys *ss, int id,return ret; } +struct cgroup_subsys_state *cgroup_css_from_file (struct file *f,int id) +{ +struct cgroup *cgrp; + +/* check in cgroup filesystem */ +if (f->f_op != &cgroup_seqfile_operations) +return ERR_PTR (-EBADF ); + +if (id <0 || id >=CGROUP_SUBSYS_COUNT ) +return ERR_PTR (-EINVAL ); + +/* get cgroup */ + cgrp =__d_cgrp (f->f_dentry->d_parent); + +return cgrp->subsys[id]; +} +#ifdef CONFIG_CGROUP_DEBUG static struct cgroup_subsys_state *debug_create (struct cgroup_subsys *ss,struct cgroup *cont)
kernel/perf_event.c +428 -107
826 lines not on this page · raw message
Peter Zijlstra
maintainerQuoted 1 line · Stephane Eranian
+ } times[NR_CPUS]
____cacheline_aligned_in_smp;
That's fail! NR_CPUS can be like 4k for distro configs.
Use proper per-cpu allocations.
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Stephane Eranian
+ } times[NR_CPUS]
____cacheline_aligned_in_smp;That's fail!
NR_CPUScan be like 4k for distro configs.
How do you do this on struct that are dynamically allocated? The number of css is dynamic.
Quoted 2 lines
Use proper per-cpu allocations.
Peter Zijlstra
maintainerQuoted 8 lines · stephane eranian
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Stephane Eranian
+ } times[NR_CPUS]
____cacheline_aligned_in_smp;That's fail!
NR_CPUScan be like 4k for distro configs.How do you do this on struct that are dynamically allocated? The number of css is dynamic.
alloc_percpu()?
Quoted 12 lines · Peter Zijlstra
Quoted 8 lines · stephane eranian
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Stephane Eranian
+ } times[NR_CPUS]
____cacheline_aligned_in_smp;That's fail!
NR_CPUScan be like 4k for distro configs.How do you do this on struct that are dynamically allocated? The number of css is dynamic.
alloc_percpu()?
Ok, I will look into this. Thanks.
Clearly we can kmalloc() the array. But it would be nicer to have one struct allocated per-cpu (avoid the cacheline_aligned_in_smp stuff).