linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yong Zhang <yong.zhang0@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	David Howells <dhowells@redhat.com>, Ingo Molnar <mingo@elte.hu>,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] schedule: simplify the reacquire_kernel_lock() logic
Date: Wed, 19 May 2010 21:11:55 +0800	[thread overview]
Message-ID: <20100519131155.GB2216@zhy> (raw)
In-Reply-To: <20100519125711.GA30199@redhat.com>

On Wed, May 19, 2010 at 02:57:11PM +0200, Oleg Nesterov wrote:
> - Contrary to what 6d558c3a says, there is no need to reload
>   prev = rq->curr after the context switch. You always schedule
>   back to where you came from, prev must be equal to current
>   even if cpu/rq was changed.
> 
> - This also means reacquire_kernel_lock() can use prev instead
>   of current.
> 
> - No need to reassign switch_count if reacquire_kernel_lock()
>   reports need_resched(), we can just move the initial assignment
>   down, under the "need_resched_nonpreemptible:" label.
> 
> - Try to update the comment after context_switch().
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

This make it more clear now. Thank you Oleg.

Acked-by: Yong Zhang <yong.zhang0@gmail.com>

> ---
> 
>  kernel/sched.c |   13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> --- 34-rc1/kernel/sched.c~SCHEDULE_PREV_EQ_TO_CURRENT	2010-05-18 23:32:50.000000000 +0200
> +++ 34-rc1/kernel/sched.c	2010-05-19 14:32:57.000000000 +0200
> @@ -3679,7 +3679,6 @@ need_resched:
>  	rq = cpu_rq(cpu);
>  	rcu_sched_qs(cpu);
>  	prev = rq->curr;
> -	switch_count = &prev->nivcsw;
>  
>  	release_kernel_lock(prev);
>  need_resched_nonpreemptible:
> @@ -3693,6 +3692,7 @@ need_resched_nonpreemptible:
>  	update_rq_clock(rq);
>  	clear_tsk_need_resched(prev);
>  
> +	switch_count = &prev->nivcsw;
>  	if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
>  		if (unlikely(signal_pending_state(prev->state, prev)))
>  			prev->state = TASK_RUNNING;
> @@ -3719,8 +3719,10 @@ need_resched_nonpreemptible:
>  
>  		context_switch(rq, prev, next); /* unlocks the rq */
>  		/*
> -		 * the context switch might have flipped the stack from under
> -		 * us, hence refresh the local variables.
> +		 * The context switch have flipped the stack from under us
> +		 * and restored the local variables which were saved when
> +		 * this task called schedule() in the past. prev == current
> +		 * is still correct, but it can be moved to another cpu/rq.
>  		 */
>  		cpu = smp_processor_id();
>  		rq = cpu_rq(cpu);
> @@ -3729,11 +3731,8 @@ need_resched_nonpreemptible:
>  
>  	post_schedule(rq);
>  
> -	if (unlikely(reacquire_kernel_lock(current) < 0)) {
> -		prev = rq->curr;
> -		switch_count = &prev->nivcsw;
> +	if (unlikely(reacquire_kernel_lock(prev)))
>  		goto need_resched_nonpreemptible;
> -	}
>  
>  	preempt_enable_no_resched();
>  	if (need_resched())

  parent reply	other threads:[~2010-05-19 13:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18 16:45 [PATCH 1/3] Reduce get_current() to the asm-generic implementation where possible David Howells
2010-05-18 16:45 ` [PATCH 2/3] Mark the 'current' pointer register read-only when such a thing exists David Howells
2010-05-18 21:05   ` David Miller
2010-05-18 16:45 ` [PATCH 3/3] Make get_current() __attribute__((const)) David Howells
2010-05-18 21:22   ` schedule() && prev/current (Was: [PATCH 3/3] Make get_current() __attribute__((const))) Oleg Nesterov
2010-05-19  6:21     ` Peter Zijlstra
2010-05-19 10:27       ` Oleg Nesterov
2010-05-19 10:37         ` Peter Zijlstra
2010-05-19 12:57           ` [PATCH] schedule: simplify the reacquire_kernel_lock() logic Oleg Nesterov
2010-05-19 12:57             ` Oleg Nesterov
2010-05-19 13:11             ` Yong Zhang [this message]
2010-05-19 13:07         ` schedule() && prev/current (Was: [PATCH 3/3] Make get_current() __attribute__((const))) Yong Zhang
2010-05-19 13:07           ` Yong Zhang
2010-05-18 17:39 ` [PATCH 1/3] Reduce get_current() to the asm-generic implementation where possible Kyle McMartin
2010-05-18 19:47 ` Jamie Lokier
2010-05-19  6:21   ` Nick Piggin
2010-05-19 11:02     ` Oleg Nesterov
2010-05-21 10:13 ` David Howells

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=20100519131155.GB2216@zhy \
    --to=yong.zhang0@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).