Re: [PATCH 4/5] perf_events: add cgroup support (v6)

Previous thread: [PATCH 3/5] perf_events: add perf_event_time() (v6) by Stephane Eranian on Tuesday, November 30, 2010 - 10:20 am. (1 message)

Next thread: [PATCH 5/5] perf_events: add cgroup support to perf tool (v6) by Stephane Eranian on Tuesday, November 30, 2010 - 10:20 am. (1 message)
From: Stephane Eranian
Date: Tuesday, November 30, 2010 - 10:20 am

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);

Signed-off-by: Stephane Eranian <eranian@google.com>
---

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index ed4ba11..5449b61 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -626,6 +626,7 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 /* Get id and depth of css */
 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 */
 
diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h
index ccefff0..c93ea28 100644
--- a/include/linux/cgroup_subsys.h
+++ b/include/linux/cgroup_subsys.h
@@ -65,4 +65,8 @@ SUBSYS(net_cls)
 SUBSYS(blkio)
 #endif
 
+#ifdef CONFIG_PERF_CGROUPS
+SUBSYS(perf)
+#endif
+
 /* */
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index cbf04cc..a3a9732 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -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, ...
From: Peter Zijlstra
Date: Wednesday, December 1, 2010 - 7:00 am

Since this paradigm was already in use it surprises me you have to add

That wants to be:
/*
 * text goes here




Most callers seem to already check for !cgrp, make that all and avoid

Do you leak a preemption count here? No matching put_cpu_ptr().

Since we're in the middle of a context switch, preemption is already
disabled and it might be best to use this_cpu_ptr() instead of


So I guess the difference is that we want perf_cgroup_event_css_time()
even when !active?

I'm afraid all this time accounting stuff is going to make my head

Ah, I guess this is why you're still using atomics, since another cpu
can install the counters on the target cpu,. ok I guess that makes




Hrm,. that isn't particularly pretty,.. why do we have to do this in
perf_event_alloc()? Can't we do this in the syscall after
perf_event_alloc() returns?
--

From: Stephane Eranian
Date: Wednesday, December 8, 2010 - 5:15 pm

Well, I could not find one. If anybody knows of one, I'll be able to
The difference is in the way time_enabled in accounted for in cgroup mode.
time_enabled represent the time the event is enabled AND the monitored
threads were active of the monitored CPU. Thus it is independent of the
state of the context. A context may have cgroup and non-cgroup events

Done.

Will be posting an updated version soon.
I also realized, I need to check how cgroup is handled for the SW events.
--

Previous thread: [PATCH 3/5] perf_events: add perf_event_time() (v6) by Stephane Eranian on Tuesday, November 30, 2010 - 10:20 am. (1 message)

Next thread: [PATCH 5/5] perf_events: add cgroup support to perf tool (v6) by Stephane Eranian on Tuesday, November 30, 2010 - 10:20 am. (1 message)