public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Rowand <frank.rowand@am.sony.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Chris Mason <chris.mason@oracle.com>,
	"Rowand, Frank" <Frank_Rowand@sonyusa.com>,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	Mike Galbraith <efault@gmx.de>, Oleg Nesterov <oleg@redhat.com>,
	Paul Turner <pjt@google.com>, Jens Axboe <axboe@kernel.dk>,
	Yong Zhang <yong.zhang0@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 20/22] sched: Move the second half of ttwu() to the remote cpu
Date: Thu, 10 Mar 2011 17:44:50 -0800	[thread overview]
Message-ID: <4D797E92.20408@am.sony.com> (raw)
In-Reply-To: <20110302174121.709471743@chello.nl>

On 03/02/11 09:38, Peter Zijlstra wrote:
> Now that we've removed the rq->lock requirement from the first part of
> ttwu() and can compute placement without holding any rq->lock, ensure
> we execute the second half of ttwu() on the actual cpu we want the
> task to run on.
> 
> This avoids having to take rq->lock and doing the task enqueue
> remotely, saving lots on cacheline transfers.
> 
> As measured using: http://oss.oracle.com/~mason/sembench.c
> 
> $ echo 4096 32000 64 128 > /proc/sys/kernel/sem
> $ ./sembench -t 2048 -w 1900 -o 0
> 
> unpatched: run time 30 seconds 537953 worker burns per second
> patched:   run time 30 seconds 847526 worker burns per second
> 
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> LKML-Reference: <new-submission>
> ---
>  include/linux/sched.h   |    4 +--
>  kernel/sched.c          |   56 ++++++++++++++++++++++++++++++++++++++++++++++++
>  kernel/sched_features.h |    2 +
>  3 files changed, 60 insertions(+), 2 deletions(-)
> 
> Index: linux-2.6/include/linux/sched.h
> ===================================================================
> --- linux-2.6.orig/include/linux/sched.h
> +++ linux-2.6/include/linux/sched.h
> @@ -1202,6 +1201,7 @@ struct task_struct {
>  	int lock_depth;		/* BKL lock depth */
>  
>  #ifdef CONFIG_SMP
> +	struct task_struct *wake_entry;
>  	int on_cpu;
>  #endif
>  	int on_rq;
> @@ -2185,7 +2185,7 @@ extern void set_task_comm(struct task_st
>  extern char *get_task_comm(char *to, struct task_struct *tsk);
>  
>  #ifdef CONFIG_SMP
> -static inline void scheduler_ipi(void) { }
> +void scheduler_ipi(void);
>  extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
>  #else
>  static inline unsigned long wait_task_inactive(struct task_struct *p,
> Index: linux-2.6/kernel/sched.c
> ===================================================================
> --- linux-2.6.orig/kernel/sched.c
> +++ linux-2.6/kernel/sched.c
> @@ -557,6 +557,10 @@ struct rq {
>  	unsigned int ttwu_count;
>  	unsigned int ttwu_local;
>  #endif
> +
> +#ifdef CONFIG_SMP
> +	struct task_struct *wake_list;
> +#endif
>  };
>  
>  static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
> @@ -2511,10 +2515,61 @@ static int ttwu_remote(struct task_struc
>  	return ret;
>  }
>  
> +#ifdef CONFIG_SMP
> +void sched_ttwu_pending(void)
> +{

sched_ttwu_pending() is now only used in sched.c, so can be static
(in the previous patch version is was called from other files).

> +	struct rq *rq = this_rq();
> +	struct task_struct *list = xchg(&rq->wake_list, NULL);
> +
> +	if (!list)
> +		return;
> +
> +	raw_spin_lock(&rq->lock);
> +
> +	while (list) {
> +		struct task_struct *p = list;
> +		list = list->wake_entry;
> +		ttwu_do_activate(rq, p, 0);
> +	}
> +
> +	raw_spin_unlock(&rq->lock);
> +}
> +
> +void scheduler_ipi(void)
> +{
> +	sched_ttwu_pending();
> +}
> +
> +static void ttwu_queue_remote(struct task_struct *p, int cpu)
> +{
> +	struct rq *rq = cpu_rq(cpu);
> +	struct task_struct *next = rq->wake_list;
> +
> +	for (;;) {
> +		struct task_struct *old = next;
> +
> +		p->wake_entry = next;
> +		next = cmpxchg(&rq->wake_list, old, p);
> +		if (next == old)
> +			break;
> +	}
> +
> +	if (!next)
> +		smp_send_reschedule(cpu);
> +}
> +#endif
> +
>  static void ttwu_queue(struct task_struct *p, int cpu)
>  {
>  	struct rq *rq = cpu_rq(cpu);
>  
> +#ifdef CONFIG_SMP
> +	if (!sched_feat(TTWU_FORCE_REMOTE) && cpu != smp_processor_id()) {
> +		ttwu_queue_remote(p, cpu);
> +		return;
> +	}
> +#endif
> +
>  	raw_spin_lock(&rq->lock);
>  	ttwu_do_activate(rq, p, 0);
>  	raw_spin_unlock(&rq->lock);
> @@ -6287,6 +6342,7 @@ migration_call(struct notifier_block *nf
>  
>  #ifdef CONFIG_HOTPLUG_CPU
>  	case CPU_DYING:

Should pi_lock be locked here, so that additional wake ups can not
be put on the wake list in the window after sched_ttwu_pending()
completes, and before set_rq_offline(rq) is called?  If so, then
of course unlock pi_lock after the matching
"raw_spin_unlock_irqrestore(&rq->lock, flags);"

> +		sched_ttwu_pending();
>  		/* Update our root-domain */
>  		raw_spin_lock_irqsave(&rq->lock, flags);
>  		if (rq->rd) {
> Index: linux-2.6/kernel/sched_features.h
> ===================================================================
> --- linux-2.6.orig/kernel/sched_features.h
> +++ linux-2.6/kernel/sched_features.h
> @@ -64,3 +64,5 @@ SCHED_FEAT(OWNER_SPIN, 1)
>   * Decrement CPU power based on irq activity
>   */
>  SCHED_FEAT(NONIRQ_POWER, 1)
> +
> +SCHED_FEAT(TTWU_FORCE_REMOTE, 0)
> 
> 
> 
> .
> 



  reply	other threads:[~2011-03-11  1:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02 17:38 [PATCH 00/22] sched: Reduce runqueue lock contention -v5 Peter Zijlstra
2011-03-02 17:38 ` [PATCH 01/22] sched: Provide scheduler_ipi() callback in response to smp_send_reschedule() Peter Zijlstra
2011-03-11  1:36   ` Frank Rowand
2011-03-16  8:30     ` Peter Zijlstra
2011-03-11 15:07   ` [01/22] " Milton Miller
2011-03-11 15:27     ` Peter Zijlstra
2011-03-15  3:59       ` Milton Miller
2011-03-15  9:13         ` Peter Zijlstra
2011-03-02 17:38 ` [PATCH 02/22] sched: Always provide p->on_cpu Peter Zijlstra
2011-03-02 17:38 ` [PATCH 03/22] mutex: Use p->on_cpu for the adaptive spin Peter Zijlstra
2011-03-02 17:38 ` [PATCH 04/22] sched: Change the ttwu success details Peter Zijlstra
2011-03-02 17:38 ` [PATCH 05/22] sched: Clean up ttwu stats Peter Zijlstra
2011-03-02 17:38 ` [PATCH 06/22] sched: Provide p->on_rq Peter Zijlstra
2011-03-02 17:38 ` [PATCH 07/22] sched: Serialize p->cpus_allowed and ttwu() using p->pi_lock Peter Zijlstra
2011-03-02 17:38 ` [PATCH 08/22] sched: Drop the rq argument to sched_class::select_task_rq() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 09/22] sched: Remove rq argument to sched_class::task_waking() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 10/22] sched: Deal with non-atomic min_vruntime reads on 32bits Peter Zijlstra
2011-03-02 17:38 ` [PATCH 11/22] sched: Delay task_contributes_to_load() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 12/22] sched: Also serialize ttwu_local() with p->pi_lock Peter Zijlstra
2011-03-02 17:38 ` [PATCH 13/22] sched: Add p->pi_lock to task_rq_lock() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 14/22] sched: Drop rq->lock from first part of wake_up_new_task() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 15/22] sched: Drop rq->lock from sched_exec() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 16/22] sched: Remove rq->lock from the first half of ttwu() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 17/22] sched: Remove rq argument from ttwu_stat() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 18/22] sched: Rename ttwu_post_activation Peter Zijlstra
2011-03-02 17:38 ` [PATCH 19/22] sched: Restructure ttwu some more Peter Zijlstra
2011-03-02 17:38 ` [PATCH 20/22] sched: Move the second half of ttwu() to the remote cpu Peter Zijlstra
2011-03-11  1:44   ` Frank Rowand [this message]
2011-03-16  8:32     ` Peter Zijlstra
2011-03-02 17:38 ` [PATCH 21/22] sched: Remove need_migrate_task() Peter Zijlstra
2011-03-02 17:38 ` [PATCH 22/22] sched: Remove TASK_WAKING Peter Zijlstra
2011-03-11  1:49   ` Frank Rowand
2011-03-16  9:53     ` Peter Zijlstra
2011-03-11  1:51 ` [PATCH 00/22] sched: Reduce runqueue lock contention -v5 Frank Rowand

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=4D797E92.20408@am.sony.com \
    --to=frank.rowand@am.sony.com \
    --cc=Frank_Rowand@sonyusa.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=axboe@kernel.dk \
    --cc=chris.mason@oracle.com \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=pjt@google.com \
    --cc=tglx@linutronix.de \
    --cc=yong.zhang0@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