Re: [PATCH] perf_event: fix slow and broken cgroup context switchcode

From: Peter Zijlstra
Date: Thu Aug 25 2011 - 10:26:33 EST


On Thu, 2011-08-25 at 15:58 +0200, Stephane Eranian wrote:
> +static inline void perf_cgroup_sched_out(struct task_struct *task,
> + struct task_struct *next)
> {
> + struct perf_cgroup *cgrp1;
> + struct perf_cgroup *cgrp2 = NULL;
> +
> + /*
> + * we come here when we know perf_cgroup_events > 0
> + */
> + cgrp1 = perf_cgroup_from_task(task);
> +
> + /*
> + * next is NULL when called from perf_event_enable_on_exec()
> + * that will systematically cause a cgroup_switch()
> + */
> + if (next)
> + cgrp2 = perf_cgroup_from_task(next);
> +
> + /*
> + * only schedule out current cgroup events if we know
> + * that we are switching to a different cgroup. Otherwise,
> + * do no touch the cgroup events.
> + */
> + if (cgrp1 != cgrp2)
> + perf_cgroup_switch(task, PERF_CGROUP_SWOUT);
> }
>
> +static inline void perf_cgroup_sched_in(struct task_struct *prev,
> + struct task_struct *task)
> {
> + struct perf_cgroup *cgrp1;
> + struct perf_cgroup *cgrp2 = NULL;
> +
> + /*
> + * we come here when we know perf_cgroup_events > 0
> + */
> + cgrp1 = perf_cgroup_from_task(task);
> +
> + /* prev can never be NULL */
> + cgrp2 = perf_cgroup_from_task(prev);
> +
> + /*
> + * only need to schedule in cgroup events if we are changing
> + * cgroup during ctxsw. Cgroup events were not scheduled
> + * out of ctxsw out if that was not the case.
> + */
> + if (cgrp1 != cgrp2)
> + perf_cgroup_switch(task, PERF_CGROUP_SWIN);
> }

OK, looks sane enough, queued the patch, thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/