public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Kirill Tkhai <ktkhai@parallels.com>
Cc: Kirill Tkhai <tkhai@yandex.ru>,
	linux-kernel@vger.kernel.org, nicolas.pitre@linaro.org,
	pjt@google.com, oleg@redhat.com, rostedt@goodmis.org,
	umgwanakikbuti@gmail.com, tim.c.chen@linux.intel.com,
	mingo@kernel.org
Subject: Re: [PATCH v2 2/5] sched: Teach scheduler to understand ONRQ_MIGRATING state
Date: Tue, 29 Jul 2014 14:38:25 +0200	[thread overview]
Message-ID: <20140729123825.GB3935@laptop> (raw)
In-Reply-To: <1406627582.3600.9.camel@tkhai>

On Tue, Jul 29, 2014 at 01:53:02PM +0400, Kirill Tkhai wrote:
> From: Kirill Tkhai <ktkhai@parallels.com>
> 
>     sched: Teach scheduler to understand ONRQ_MIGRATING state
>     
>     This is new on_rq state for the cases when task is migrating
>     from one src_rq to another dst_rq, and there is no necessity
>     to have both RQs locked at the same time.
>     
>     We will use the state this way:
>     
>     	raw_spin_lock(&src_rq->lock);
>     	dequeue_task(src_rq, p, 0);
>     	p->on_rq = ONRQ_MIGRATING;
>     	set_task_cpu(p, dst_cpu);
>     	raw_spin_unlock(&src_rq->lock);
>     
>     	raw_spin_lock(&dst_rq->lock);
>     	p->on_rq = ONRQ_QUEUED;
>     	enqueue_task(dst_rq, p, 0);
>     	raw_spin_unlock(&dst_rq->lock);
>     
>     The profit is that double_rq_lock() is not needed now,
>     and this may reduce the latencies in some situations.

You forgot to explain how the spinning on task_migrated() is bounded and
thus doesn't make your beginning and end contradict itself.

>     Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 26aa7bc..00d7bcc 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -333,7 +333,8 @@ static inline struct rq *__task_rq_lock(struct task_struct *p)
>  	for (;;) {
>  		rq = task_rq(p);
>  		raw_spin_lock(&rq->lock);
> -		if (likely(rq == task_rq(p)))
> +		if (likely(rq == task_rq(p) &&
> +			   !task_migrating(p)))
>  			return rq;
>  		raw_spin_unlock(&rq->lock);
>  	}

I would prefer an extra spin-loop like so, that avoids us spinning on
the rq-lock, which serves no purpose.

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2676866b4394..1e65a0bdbbc3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -331,9 +331,12 @@ static inline struct rq *__task_rq_lock(struct task_struct *p)
 	lockdep_assert_held(&p->pi_lock);
 
 	for (;;) {
+		while (task_migrating(p))
+			cpu_relax();
+
 		rq = task_rq(p);
 		raw_spin_lock(&rq->lock);
-		if (likely(rq == task_rq(p)))
+		if (likely(rq == task_rq(p) && !task_migrating(p)))
 			return rq;
 		raw_spin_unlock(&rq->lock);
 	}

> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index e5a9b6d..f6773d7 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -17,6 +17,7 @@ struct rq;
>  
>  /* .on_rq states of struct task_struct: */

The 'normal' way to write that is: task_struct::on_rq

>  #define ONRQ_QUEUED	1
> +#define ONRQ_MIGRATING	2
>  
>  extern __read_mostly int scheduler_running;
>  

  reply	other threads:[~2014-07-29 12:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26 14:58 [PATCH v2 0/5] sched: Add on_rq states and remove several double rq locks Kirill Tkhai
2014-07-26 14:59 ` [PATCH v2 1/5] sched: Wrapper for checking task_struct's .on_rq Kirill Tkhai
2014-07-26 14:59 ` [PATCH v2 2/5] sched: Teach scheduler to understand ONRQ_MIGRATING state Kirill Tkhai
2014-07-28  8:01   ` Peter Zijlstra
2014-07-28  9:05     ` Kirill Tkhai
2014-07-29  9:53       ` Kirill Tkhai
2014-07-29 12:38         ` Peter Zijlstra [this message]
2014-07-29 16:19         ` Oleg Nesterov
2014-07-30  8:04           ` Kirill Tkhai
2014-07-30 14:41             ` Oleg Nesterov
2014-07-30 21:25               ` Kirill Tkhai
2014-07-26 14:59 ` [PATCH v2 3/5] sched: Remove double_rq_lock() from __migrate_task() Kirill Tkhai
2014-07-26 14:59 ` [PATCH v2 4/5] sched/fair: Remove double_lock_balance() from active_load_balance_cpu_stop() Kirill Tkhai
2014-07-26 14:59 ` [PATCH v2 5/5] sched/fair: Remove double_lock_balance() from load_balance() Kirill Tkhai
2014-07-29 12:57   ` Peter Zijlstra
2014-07-26 19:39 ` [PATCH v2 0/5] sched: Add on_rq states and remove several double rq locks Oleg Nesterov
2014-07-27 21:26   ` Kirill Tkhai
2014-07-28 13:19     ` Oleg Nesterov

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=20140729123825.GB3935@laptop \
    --to=peterz@infradead.org \
    --cc=ktkhai@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=oleg@redhat.com \
    --cc=pjt@google.com \
    --cc=rostedt@goodmis.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=tkhai@yandex.ru \
    --cc=umgwanakikbuti@gmail.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