public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, paulus@samba.org,
	davem@davemloft.net, fweisbec@gmail.com,
	perfmon2-devel@lists.sf.net, eranian@gmail.com,
	robert.richter@amd.com, acme@redhat.com, lizf@cn.fujitsu.com
Subject: Re: [PATCH 4/5] perf_events: add cgroup support (v7)
Date: Thu, 06 Jan 2011 11:15:09 +0100	[thread overview]
Message-ID: <1294308909.2016.321.camel@laptop> (raw)
In-Reply-To: <AANLkTinGaHThAxO+0ObCtv+28W8bKULBEtV1KQ4Nax8H@mail.gmail.com>

On Wed, 2011-01-05 at 22:39 +0100, Stephane Eranian wrote:
> Peter,
> 
> On Wed, Jan 5, 2011 at 2:01 PM, Stephane Eranian <eranian@google.com> wrote:
> > On Wed, Jan 5, 2011 at 12:23 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> >> On Mon, 2011-01-03 at 18:20 +0200, Stephane Eranian wrote:
> >>> +void
> >>> +perf_cgroup_switch(struct task_struct *task, struct task_struct *next)
> >>> +{
> >>> +     struct perf_cgroup *cgrp_out = perf_cgroup_from_task(task);
> >>> +     struct perf_cgroup *cgrp_in = perf_cgroup_from_task(next);
> >>> +     struct perf_cpu_context *cpuctx;
> >>> +     struct pmu *pmu;
> >>> +     /*
> >>> +      * if task is DEAD, then css_out is irrelevant, it has
> >>> +      * been changed to init_cgrp in cgroup_exit() from do_exit().
> >>> +      * Furthermore, perf_cgroup_exit_task(), has scheduled out
> >>> +      * all css constrained events, only unconstrained events
> >>> +      * remain. Therefore we need to reschedule based on css_in.
> >>> +      */
> >>> +     if (task->state != TASK_DEAD && cgrp_out == cgrp_in)
> >>> +             return;
> >>
> >> I think that check is broken, TASK_DEAD is set way after calling
> >> cgroup_exit(), so if we get preempted in between there you'll still go
> >> funny.
> >>
> 
> I looked at this part again.
> 
> The original code checking for TASK_DEAD is correct.
> 
> The reason is simple, you're looking at perf_cgroup_switch() which is
> invoked as part of schedule() and NOT perf_event_task_exit() (called
> prior to cgroup_exit()).
> Thus, by the time you do the final schedule(), the task state has indeed
> been switched to TASK_DEAD.
> 
> I remember testing for this condition during the debug phase.

But, cgroup_exit() detaches the task from the cgroup, after which the
cgroup can disappear. Furthermore, we can schedule after cgroup_exit()
and before the explicit schedule() invocation.

Some of the exit functions (say proc_exit_connector) can block and cause
scheduling, and with PREEMPT=y we can get preempted.

This means you'll be context switching, and thus possibly calling
perf_cgroup_switch(), on a task who's cgroup is possibly destroyed.

So I'm not at all seeing how this is correct.

  reply	other threads:[~2011-01-06 10:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-03 16:20 [PATCH 4/5] perf_events: add cgroup support (v7) Stephane Eranian
2011-01-05  3:13 ` Li Zefan
2011-01-05  8:32   ` Stephane Eranian
2011-01-05 11:23 ` Peter Zijlstra
2011-01-05 13:01   ` Stephane Eranian
2011-01-05 21:39     ` Stephane Eranian
2011-01-06 10:15       ` Peter Zijlstra [this message]
2011-01-10 14:30         ` Stephane Eranian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1294308909.2016.321.camel@laptop \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eranian@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=perfmon2-devel@lists.sf.net \
    --cc=robert.richter@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox