public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Paul Turner <pjt@google.com>
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: Re: sched: race between deactivate and switch sched_info accounting?
Date: Sat, 10 Oct 2009 08:37:40 +0200	[thread overview]
Message-ID: <1255156660.7866.4.camel@twins> (raw)
In-Reply-To: <alpine.DEB.2.00.0910091849070.22548@kitami.corp.google.com>

On Fri, 2009-10-09 at 19:40 -0700, Paul Turner wrote:

This looks very funny, I would expect that whoever does activate() on
that task to do the sched_info*() muck?

The below patch looks very asymmetric in that regard.

> It's possible for our previously de-activated task to be re-activated by a 
> remote cpu during lock balancing.  We have to account for this manually 
> since prev == next, yet the task just went through dequeue accounting.
> 
>  Signed-off-by: Paul Turner <pjt@google.com>
> ---
>  kernel/sched.c |   15 ++++++++++++---
>  1 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched.c b/kernel/sched.c
> index ee61f45..6445d9d 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -5381,7 +5381,7 @@ asmlinkage void __sched schedule(void)
>  	struct task_struct *prev, *next;
>  	unsigned long *switch_count;
>  	struct rq *rq;
> -	int cpu;
> +	int cpu, deactivated_prev = 0;
>  
>  need_resched:
>  	preempt_disable();
> @@ -5406,8 +5406,10 @@ need_resched_nonpreemptible:
>  	if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
>  		if (unlikely(signal_pending_state(prev->state, prev)))
>  			prev->state = TASK_RUNNING;
> -		else
> +		else {
>  			deactivate_task(rq, prev, 1);
> +			deactivated_prev = 1;
> +		}
>  		switch_count = &prev->nvcsw;
>  	}
>  
> @@ -5434,8 +5436,15 @@ need_resched_nonpreemptible:
>  		 */
>  		cpu = smp_processor_id();
>  		rq = cpu_rq(cpu);
> -	} else
> +	} else {
> +		/*
> +		 * account for our previous task being re-activated by a
> +		 * remote cpu.
> +		 */
> +		if (unlikely(deactivated_prev))
> +			sched_info_switch(prev, prev);
>  		spin_unlock_irq(&rq->lock);
> +	}
>  
>  	post_schedule(rq);
>  

  reply	other threads:[~2009-10-10  6:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-10  2:40 sched: race between deactivate and switch sched_info accounting? Paul Turner
2009-10-10  6:37 ` Peter Zijlstra [this message]
2009-10-12 21:20   ` Paul Turner

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=1255156660.7866.4.camel@twins \
    --to=peterz@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pjt@google.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