perf_events: add support for per-cpu per-cgroup monitoring (v5)
Subsystems (2)
PATCH 1/2 perf_events: add support for per-cpu per-cgroup monitoring (v5)
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing PERF_FLAG_PID_CGROUP in the flags argument to the syscall.
For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
struct perf_event_attr attr;
int cgroup_fd, fd;
cgroup_fd = open("/cgroup/foo", O_RDONLY);
fd = perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP); close(cgroup_fd);
---
include/linux/cgroup.h +2 -0
@@ -627,6 +627,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_dir (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 +30 -0
@@ -454,6 +454,7 @@ enum perf_callchain_context {#define PERF_FLAG_FD_NO_GROUP (1U << 0)#define PERF_FLAG_FD_OUTPUT (1U << 1) +#define PERF_FLAG_PID_CGROUP (1U << 2)/* pid=cgroup id, per-cpu mode */ #ifdef __KERNEL__/*
@@ -461,6 +462,7 @@ enum perf_callchain_context {*/ #ifdef CONFIG_PERF_EVENTS +# include <linux/cgroup.h> # include <asm/perf_event.h> # include <asm/local64.h> #endif
@@ -702,6 +704,18 @@ struct swevent_hlist {#define PERF_ATTACH_GROUP 0x02#define PERF_ATTACH_TASK 0x04 +#ifdef CONFIG_CGROUPS +struct perf_cgroup_info { +u64 time; +u64 timestamp; +}; + +struct perf_cgroup { +struct cgroup_subsys_state css; +struct perf_cgroup_info *info; +}; +#endif +/** * struct perf_event - performance event kernel representation: */
@@ -815,6 +829,10 @@ struct perf_event {struct event_filter *filter;#endif +#ifdef CONFIG_CGROUPS +struct perf_cgroup *css; +#endif +#endif /* CONFIG_PERF_EVENTS */ };
@@ -868,6 +886,8 @@ struct perf_event_context {u64 generation;int pin_count;struct rcu_head rcu_head; + +int nr_cgroups;/* cgroup events present */ };/*
@@ -911,6 +931,12 @@ extern void __perf_event_task_sched_out(struct task_struct *task, struct task_stextern atomic_t perf_task_events; +#ifdef CONFIG_CGROUPS +extern void perf_cgroup_switch (struct task_struct *task, +struct task_struct *next); +DECLARE_PER_CPU (atomic_t, perf_cgroup_events); +#endif +static inline void perf_event_task_sched_in (struct task_struct *task) {COND_STMT (&perf_task_events,__perf_event_task_sched_in (task));
@@ -919,6 +945,10 @@ static inline void perf_event_task_sched_in(struct task_struct *task)static inline void perf_event_task_sched_out (struct task_struct *task,struct task_struct *next) { +#ifdef CONFIG_CGROUPS +atomic_t *cgroup_events = &__get_cpu_var (perf_cgroup_events); +COND_STMT (cgroup_events,perf_cgroup_switch (task, next)); +#endif COND_STMT (&perf_task_events,__perf_event_task_sched_out (task, next)); }
kernel/cgroup.c +23 -0
@@ -4790,6 +4790,29 @@ css_get_next(struct cgroup_subsys *ss, int id,return ret; } +/* +* get corresponding css from file open on cgroupfs directory +*/ +struct cgroup_subsys_state *cgroup_css_from_dir (struct file *f,int id) +{ +struct cgroup *cgrp; +struct inode *inode; +struct cgroup_subsys_state *css; + + inode = f->f_dentry->d_inode; +/* check in cgroup filesystem dir */ +if (inode->i_op != &cgroup_dir_inode_operations) +return ERR_PTR (-EBADF ); + +if (id <0 || id >=CGROUP_SUBSYS_COUNT ) +return ERR_PTR (-EINVAL ); + +/* get cgroup */ + cgrp =__d_cgrp (f->f_dentry); + css = cgrp->subsys[id]; +return css ? css :ERR_PTR (-ENOENT ); +} +#ifdef CONFIG_CGROUP_DEBUG static struct cgroup_subsys_state *debug_create (struct cgroup_subsys *ss,struct cgroup *cont)
kernel/exit.c +6 -5
@@ -985,6 +985,12 @@ NORET_TYPE void do_exit(long code)exit_fs (tsk);check_stack_usage ();exit_thread (); +/* +* Flush inherited counters to the parent - before the parent +* gets woken up by child-exit notifications. +* because of cgroup mode, must be called before cgroup_exit() +*/ +perf_event_exit_task (tsk);cgroup_exit (tsk,1 );if (group_dead)
@@ -998,11 +1004,6 @@ NORET_TYPE void do_exit(long code)* FIXME: do that only when needed, using sched_exit tracepoint */ flush_ptrace_hw_breakpoint (tsk); -/* -* Flush inherited counters to the parent - before the parent -* gets woken up by child-exit notifications. -*/ -perf_event_exit_task (tsk);exit_notify (tsk, group_dead);#ifdef CONFIG_NUMA
kernel/perf_event.c +512 -57
909 lines not on this page · raw message
Peter Zijlstra
maintainerinclude/linux/perf_event.h static inline void perf_event_task_sched_in(struct task_struct *task) · line 953
Quoted 10 lines · Stephane Eranian
include/linux/perf_event.h +4
-0@@ -919,6 +945,10 @@ static inline void perf_event_task_sched_in(struct task_struct *task)static inline void perf_event_task_sched_out (struct task_struct *task,struct task_struct *next) { +#ifdef CONFIG_CGROUPS +atomic_t *cgroup_events = &__get_cpu_var (perf_cgroup_events); +COND_STMT (cgroup_events,perf_cgroup_switch (task, next)); +#endif COND_STMT (&perf_task_events,__perf_event_task_sched_out (task, next)); }
I don't think that'll actually work, the jump label stuff needs a static address.
Why not simply: s/perf_task_events/perf_sched_events/ and increment it for cgroup events as well?
Quoted 16 lines · Peter Zijlstra
Quoted 10 lines · Stephane Eranian
(quoted diff) +0
-0@@ -919,6 +945,10 @@ static inline void perf_event_task_sched_in(struct task_struct *task)static inline
voidperf_event_task_sched_out(struct task_struct *task, struct task_struct *next){include/linux/perf_event.h +4
-0+#ifdef CONFIG_CGROUPS + atomic_t *cgroup_events = &__get_cpu_var(perf_cgroup_events); + COND_STMT(cgroup_events, perf_cgroup_switch(task, next)); +#endif
COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next)); }I don't think that'll actually work, the jump label stuff needs a static address.
I did not know that.
Quoted 3 lines
Why not simply: s/perf_task_events/perf_sched_events/ and increment it for cgroup events as well?
But you would need to demultiplex. that's not because perf_sched_events is set that you want BOTH perf_cgroup_switch() AND perf_event_task_sched_out(). Cgroup mode is per-cpu only.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Peter Zijlstra
maintainerQuoted 19 lines · Stephane Eranian
On Thu, Nov 25, 2010 at 12:20 PM, Peter Zijlstra <[email protected]> wrote:
On Thu, 2010-11-18 at 12:40 +0200, Stephane Eranian wrote: > @@ -919,6 +945,10 @@ static inline void perf_event_task_sched_in(struct task_struct *task) > static inline > void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next) > { > +#ifdef CONFIG_CGROUPS > + atomic_t *cgroup_events = &__get_cpu_var(perf_cgroup_events); > + COND_STMT(cgroup_events, perf_cgroup_switch(task, next)); > +#endif > COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next)); > } I don't think that'll actually work, the jump label stuff needs a static address.
Quoted 1 line
I did not know that.
Yeah, its unfortunate the fallback code doesn't mandate this :/
Quoted 6 lines
Why not simply: s/perf_task_events/perf_sched_events/ and increment it
for cgroup events as well?But you would need to demultiplex. that's not because
perf_sched_eventsis set that you want BOTHperf_cgroup_switch()ANDperf_event_task_sched_out().
The main purpose of the jump-label stuff is to optimize the function call and conditional into the perf code away, the moment we a function call we might as well do everything, at that point its only a single conditional.
Jump labels are supposed to work like (they don't actually work like this yet):
my_func:
asm-fooaddr_of_nop:
nop5after_nop:
more-asm-foo
iret
out_of_line:
do-special-foo
jmp after_nop
We then keep a section of tuples:
__jump_labels:
&perf_task_events,addr_of_nop
Then when we flip perf_task_events from 0 -> !0 we rewrite the nop5 at addr_of_nop to "jmp out_of_line" (5 bytes on x86, hence nop5), or the reverse on !0 -> 0.
So 1) we need the 'key' (&perf_task_events) to be a static address because the compiler needs to place the address in the special section -- otherwise we can never find the nop location again, this also means per-cpu variables don't make sense, there's only 1 copy of the text.
and 2) the moment we take the out-of-line branch we incur the icache hit and already set up a call, so optimizing away another conditional at the cost of an extra function call doesn't really make sense.
Quoted 64 lines · Peter Zijlstra
Quoted 16 lines · Stephane Eranian
On Thu, Nov 25, 2010 at 12:20 PM, Peter Zijlstra <[email protected]> wrote:
On Thu, 2010-11-18 at 12:40 +0200, Stephane Eranian wrote:
> @@ -919,6 +945,10 @@ static inline voidperf_event_task_sched_in(struct task_struct *task)> static inline
> voidperf_event_task_sched_out(struct task_struct *task, struct task_struct *next)> {
> +#ifdefCONFIG_CGROUPS
> +atomic_t*cgroup_events=&__get_cpu_var(perf_cgroup_events);
> +COND_STMT(cgroup_events, perf_cgroup_switch(task, next));
> +#endif
>COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next)); > }Quoted 4 lines
I don't think that'll actually work, the jump label stuff needs a static address.
I did not know that.
Yeah, its unfortunate the fallback code doesn't mandate this :/
Quoted 6 lines
Why not simply: s/perf_task_events/perf_sched_events/ and increment it
for cgroup events as well?But you would need to demultiplex. that's not because
perf_sched_eventsis set that you want BOTHperf_cgroup_switch()ANDperf_event_task_sched_out().The main purpose of the jump-label stuff is to optimize the function call and conditional into the perf code away, the moment we a function call we might as well do everything, at that point its only a single conditional.
Jump labels are supposed to work like (they don't actually work like this yet):
my_func:
asm-fooaddr_of_nop:
nop5after_nop:
more-asm-foo
iret
out_of_line:
do-special-foo
jmpafter_nopWe then keep a section of tuples:
__jump_labels:&perf_task_events,addr_of_nop
Then when we flip
perf_task_eventsfrom 0 -> !0 we rewrite the nop5 ataddr_of_nopto "jmpout_of_line" (5 bytes on x86, hence nop5), or the reverse on !0 -> 0.
Quoted 10 lines
So 1) we need the 'key' (
&perf_task_events) to be a static address because the compiler needs to place the address in the special section -- otherwise we can never find the nop location again, this also means per-cpu variables don't make sense, there's only 1 copy of the text.and 2) the moment we take the out-of-line branch we incur the icache hit and already set up a call, so optimizing away another conditional at the cost of an extra function call doesn't really make sense.
Ok, I understand. Thanks for the explanation.
So perf_sched_events would indicate that there may be some perf ctxsw work to do. It would set as soon as there is at least one event defined and not just a per-thread event.
BTW, I suspect, isn't there a bug with PERF_COUNT_SW_CONTEXT_SWITCHES not being updated
if you don't have at least one per-thread event. You need to hoist that perf_sw_event() into the header file before the COND().
Then, __perf_event_task_sched_out() would be modified to do some more checks.
__perf_event_task_sched_out(task, next)
{
int ctxn;
perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
for_each_task_context_nr(ctxn)
perf_event_context_sched_out(task, ctxn, next);
}void __perf_event_task_sched_out(struct task_struct *task,
struct task_struct *next)
{
int ctxn;
int cgroup_events;
perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
croup_events = &__get_cpu_var(perf_cgroup_events);
if (cgroup_events)
perf_cgroup_switch(task, next);
if (perf_task_events)
for_each_task_context_nr(ctxn)
perf_event_context_sched_out(task, ctxn, next);
}That implies you need to maintain:
- perf_sched_events: number of active events system-wide
- perf_task_events: number of per-thread events system-wide
- cgroup_events: per-cpu variable representing the number of cgroup
events on a CPU
Is that what you are thinking?
Peter Zijlstra
maintainerQuoted 77 lines · Stephane Eranian
Quoted 64 lines · Peter Zijlstra
Quoted 19 lines · Stephane Eranian
On Thu, Nov 25, 2010 at 12:20 PM, Peter Zijlstra <[email protected]> wrote:
On Thu, 2010-11-18 at 12:40 +0200, Stephane Eranian wrote: > @@ -919,6 +945,10 @@ static inline void perf_event_task_sched_in(struct task_struct *task) > static inline > void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next) > { > +#ifdef CONFIG_CGROUPS > + atomic_t *cgroup_events = &__get_cpu_var(perf_cgroup_events); > + COND_STMT(cgroup_events, perf_cgroup_switch(task, next)); > +#endif > COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next)); > } I don't think that'll actually work, the jump label stuff needs a static address.Quoted 1 line
I did not know that.
Yeah, its unfortunate the fallback code doesn't mandate this :/
Quoted 6 lines
Why not simply: s/perf_task_events/perf_sched_events/ and increment it
for cgroup events as well?But you would need to demultiplex. that's not because
perf_sched_eventsis set that you want BOTHperf_cgroup_switch()ANDperf_event_task_sched_out().The main purpose of the jump-label stuff is to optimize the function call and conditional into the perf code away, the moment we a function call we might as well do everything, at that point its only a single conditional.
Jump labels are supposed to work like (they don't actually work like this yet):
my_func:
asm-fooaddr_of_nop:
nop5after_nop:
more-asm-foo
iret
out_of_line:
do-special-foo
jmpafter_nopWe then keep a section of tuples:
__jump_labels:&perf_task_events,addr_of_nop
Then when we flip
perf_task_eventsfrom 0 -> !0 we rewrite the nop5 ataddr_of_nopto "jmpout_of_line" (5 bytes on x86, hence nop5), or the reverse on !0 -> 0.Quoted 10 lines
So 1) we need the 'key' (
&perf_task_events) to be a static address because the compiler needs to place the address in the special section -- otherwise we can never find the nop location again, this also means per-cpu variables don't make sense, there's only 1 copy of the text.and 2) the moment we take the out-of-line branch we incur the icache hit and already set up a call, so optimizing away another conditional at the cost of an extra function call doesn't really make sense.
Ok, I understand. Thanks for the explanation.
Quoted 8 lines
So
perf_sched_eventswould indicate that there may be some perf ctxsw work to do. It would set as soon as there is at least one event defined and not just a per-thread event.BTW, I suspect, isn't there a bug with
PERF_COUNT_SW_CONTEXT_SWITCHESnot being updated
if you don't have at least one per-thread event. You need to hoist thatperf_sw_event()into the header file before theCOND().
Ah, indeed, that needs fixing.
Quoted 7 lines
That implies you need to maintain:
-perf_sched_events: number of active events system-wide
-perf_task_events: number of per-thread events system-wide
-cgroup_events: per-cpu variable representing the number of cgroup
events on a CPUIs that what you are thinking?
Not sure you need the last two, once we have the jump label enabled and call into the perf context switch handler the rest are simple conditions on the current task state, no need to add yet more conditions to check those conditions.
Peter Zijlstra
maintainerQuoted 14 lines · Stephane Eranian
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing
PERF_FLAG_PID_CGROUPin the flags argument to the syscall.For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
Quoted 8 lines
struct
perf_event_attrattr;
intcgroup_fd, fd;
cgroup_fd=open("/cgroup/foo", O_RDONLY);
fd =perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP);close(cgroup_fd);Signed-off-by Stephane Eranian <[email protected]>
Could you please split this patch:
- pure code movement
- time accounting changes
- event_filter_match() stuff
- cgroup thing
Quoted 1 line
From a quick reading it doesn't look bad, but I want an ACK from the
cgroup people -- specifically if they're OK with the filedesc juggling thing, because I know the sysfs people objected to such tricks.
Also, it might make sense to add a CONFIG_PERF_CGROUP, even if you want it automagically set if CONFIG_PERF && CONFIG_CGROUP, its easier to find all related code if its under a single CONFIG_var.
Quoted 30 lines · Peter Zijlstra
Quoted 14 lines · Stephane Eranian
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing
PERF_FLAG_PID_CGROUPin the flags argument to the syscall.For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
Quoted 8 lines
struct
perf_event_attrattr;
intcgroup_fd, fd;
cgroup_fd=open("/cgroup/foo", O_RDONLY);
fd =perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP);close(cgroup_fd);Signed-off-by Stephane Eranian <[email protected]>Could you please split this patch:
- pure code movement
- time accounting changes
-event_filter_match()stuff
- cgroup thing
Quoted 4 lines
From a quick reading it doesn't look bad, but I want an ACK from the cgroup people -- specifically if they're OK with the filedesc juggling thing, because I know the sysfs people objected to such tricks.
Long long ago, a feature that used this trick was accepted, and that's cgroup taskstat.
You get an fd of a cgroup directory and send it to the kernel via netlink, and then you'll receive some statistics, such as how many tasks are running/interrupted in that cgroup.
Quoted 4 lines
Also, it might make sense to add a
CONFIG_PERF_CGROUP, even if you want it automagically set ifCONFIG_PERF&&CONFIG_CGROUP, its easier to find all related code if its under a singleCONFIG_var.
Quoted 36 lines · * [email protected] <[email protected]> [2010-11-26 09:50:24]:
Quoted 30 lines · Peter Zijlstra
Quoted 14 lines · Stephane Eranian
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing
PERF_FLAG_PID_CGROUPin the flags argument to the syscall.For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
Quoted 8 lines
struct
perf_event_attrattr;
intcgroup_fd, fd;
cgroup_fd=open("/cgroup/foo", O_RDONLY);
fd =perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP);close(cgroup_fd);Signed-off-by Stephane Eranian <[email protected]>Could you please split this patch:
- pure code movement
- time accounting changes
-event_filter_match()stuff
- cgroup thingQuoted 4 lines
From a quick reading it doesn't look bad, but I want an ACK from the cgroup people -- specifically if they're OK with the filedesc juggling thing, because I know the sysfs people objected to such tricks.
Quoted 7 lines
Long long ago, a feature that used this trick was accepted, and that's cgroup taskstat.
You get an fd of a cgroup directory and send it to the kernel via netlink, and then you'll receive some statistics, such as how many tasks are running/interrupted in that cgroup.
That is right, since cgroups don't have id's there is no easy way to identify them, looking them up by name and passing strings seemed an overkill.
Signature · 2 lines
Three Cheers, Balbir
Quoted 39 lines · Balbir Singh
Quoted 37 lines · * [email protected] <[email protected]> [2010-11-26 09:50:24]:
Quoted 29 lines · Peter Zijlstra
Quoted 14 lines · Stephane Eranian
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing
PERF_FLAG_PID_CGROUPin the flags argument to the syscall.For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
Quoted 8 lines
struct
perf_event_attrattr;
intcgroup_fd, fd;
cgroup_fd=open("/cgroup/foo", O_RDONLY);
fd =perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP);close(cgroup_fd);Signed-off-by Stephane Eranian <[email protected]>Could you please split this patch:
- pure code movement
- time accounting changes
-event_filter_match()stuff
- cgroup thingQuoted 4 lines
From a quick reading it doesn't look bad, but I want an ACK from the cgroup people -- specifically if they're OK with the filedesc juggling thing, because I know the sysfs people objected to such tricks.
Long long ago, a feature that used this trick was accepted, and that's cgroup taskstat.
Quoted 9 lines
Quoted 4 lines
You get an fd of a cgroup directory and send it to the kernel via netlink, and then you'll receive some statistics, such as how many tasks are running/interrupted in that cgroup.
That is right, since cgroups don't have id's there is no easy way to identify them, looking them up by name and passing strings seemed an overkill.
More information:
Another feature recently added (eventfd-based notifications) also uses fd to identify a cgroup.
Peter Zijlstra
maintainerQuoted 4 lines · Li Zefan
More information:
Another feature recently added (eventfd-based notifications) also uses fd to identify a cgroup.
Ok, anyway I guess this all means the cgroup people are fine with this ;-)
Peter Zijlstra
maintainerQuoted 33 lines · Balbir Singh
Quoted 31 lines · * [email protected] <[email protected]> [2010-11-26 09:50:24]:
Quoted 30 lines · Peter Zijlstra
Quoted 14 lines · Stephane Eranian
This kernel patch adds the ability to filter monitoring based on container groups (cgroups). This is for use in per-cpu mode only.
The cgroup to monitor is passed as a file descriptor in the pid argument to the syscall. The file descriptor must be opened to the cgroup name in the cgroup filesystem. For instance, if the cgroup name is foo and cgroupfs is mounted in /cgroup, then the file descriptor is opened to /cgroup/foo. Cgroup mode is activated by passing
PERF_FLAG_PID_CGROUPin the flags argument to the syscall.For instance to measure in cgroup foo on CPU1 assuming cgroupfs is mounted under /cgroup:
Quoted 8 lines
struct
perf_event_attrattr;
intcgroup_fd, fd;
cgroup_fd=open("/cgroup/foo", O_RDONLY);
fd =perf_event_open(&attr, cgroup_fd, 1, -1, PERF_FLAG_PID_CGROUP);close(cgroup_fd);Signed-off-by Stephane Eranian <[email protected]>Could you please split this patch:
- pure code movement
- time accounting changes
-event_filter_match()stuff
- cgroup thing
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
From a quick reading it doesn't look bad, but I want an ACK from the cgroup people -- specifically if they're OK with the filedesc juggling thing, because I know the sysfs people objected to such tricks.
Long long ago, a feature that used this trick was accepted, and that's cgroup taskstat.
egads, I knew I should have looked at that.. :/
Quoted 8 lines
Quoted 4 lines
You get an fd of a cgroup directory and send it to the kernel via netlink, and then you'll receive some statistics, such as how many tasks are running/interrupted in that cgroup.
That is right, since cgroups don't have id's there is no easy way to identify them, looking them up by name and passing strings seemed an overkill.
You could of course have added an ID instead ;-)