public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-kernel@vger.kernel.org, pjt@google.com,
	paul.mckenney@linaro.org, tglx@linutronix.de,
	suresh.b.siddha@intel.com, venki@google.com, mingo@redhat.com,
	peterz@infradead.org, robin.randhawa@arm.com,
	Steve.Bannister@arm.com, Arvind.Chauhan@arm.com,
	amit.kucheria@linaro.org, vincent.guittot@linaro.org,
	linaro-dev@lists.linaro.org, patches@linaro.org
Subject: Re: [PATCH 3/3] workqueue: Schedule work on non-idle cpu instead of current one
Date: Tue, 25 Sep 2012 10:56:57 -0700	[thread overview]
Message-ID: <20120925175657.GB16296@google.com> (raw)
In-Reply-To: <3232b3192e2e373cc4aaf43359d454c5ad53cddb.1348568074.git.viresh.kumar@linaro.org>

Hello,

On Tue, Sep 25, 2012 at 04:06:08PM +0530, Viresh Kumar wrote:
> +config MIGRATE_WQ
> +	bool "(EXPERIMENTAL) Migrate Workqueues to non-idle cpu"
> +	depends on SMP && EXPERIMENTAL
> +	help
> +	  Workqueues queues work on current cpu, if the caller haven't passed a
> +	  preferred cpu. This may wake up an idle CPU, which is actually not
> +	  required. This work can be processed by any CPU and so we must select
> +	  a non-idle CPU here.  This patch adds in support in workqueue
> +	  framework to get preferred CPU details from the scheduler, instead of
> +	  using current CPU.

I don't think it's a good idea to make behavior like this a config
option.  The behavior difference is subtle and may induce incorrect
behavior.

> +/* This enables migration of a work to a non-IDLE cpu instead of current cpu */
> +#ifdef CONFIG_MIGRATE_WQ
> +static int wq_select_cpu(void)
> +{
> +	return sched_select_cpu(SD_NUMA, -1);
> +}
> +#else
> +#define wq_select_cpu()		smp_processor_id()
> +#endif
> +
>  /* Serializes the accesses to the list of workqueues. */
>  static DEFINE_SPINLOCK(workqueue_lock);
>  static LIST_HEAD(workqueues);
> @@ -995,7 +1005,7 @@ static void __queue_work(unsigned int cpu, struct workqueue_struct *wq,
>  		struct global_cwq *last_gcwq;
>  
>  		if (unlikely(cpu == WORK_CPU_UNBOUND))
> -			cpu = raw_smp_processor_id();
> +			cpu = wq_select_cpu();
>  
>  		/*
>  		 * It's multi cpu.  If @wq is non-reentrant and @work
> @@ -1066,8 +1076,9 @@ int queue_work(struct workqueue_struct *wq, struct work_struct *work)
>  {
>  	int ret;
>  
> -	ret = queue_work_on(get_cpu(), wq, work);
> -	put_cpu();
> +	preempt_disable();
> +	ret = queue_work_on(wq_select_cpu(), wq, work);
> +	preempt_enable();

First of all, I'm not entirely sure this is safe.  queue_work() used
to *guarantee* that the work item would execute on the local CPU.  I
don't think there are many which depend on that but I'd be surprised
if this doesn't lead to some subtle problems somewhere.  It might not
be realistic to audit all users and we might have to just let it
happen and watch for the fallouts.  Dunno, still wanna see some level
of auditing.

Also, I'm wondering why this is necessary at all for workqueues.  For
schedule/queue_work(), you pretty much know the current cpu is not
idle.  For delayed workqueue, sure but for immediate scheduling, why?

Thanks.

-- 
tejun

  parent reply	other threads:[~2012-09-25 17:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-25 10:36 [PATCH 0/3] Create sched_select_cpu() and use it in workqueues Viresh Kumar
2012-09-25 10:36 ` [PATCH 1/3] sched: Create sched_select_cpu() to give preferred CPU for power saving Viresh Kumar
2012-09-25 10:52   ` Peter Zijlstra
2012-09-25 10:36 ` [PATCH 2/3] workqueue: create __flush_delayed_work to avoid duplicating code Viresh Kumar
2012-09-25 17:47   ` Tejun Heo
2012-09-26  4:22     ` Viresh Kumar
2012-09-25 10:36 ` [PATCH 3/3] workqueue: Schedule work on non-idle cpu instead of current one Viresh Kumar
2012-09-25 11:22   ` Peter Zijlstra
2012-09-25 11:30     ` Viresh Kumar
2012-09-25 11:38       ` Vincent Guittot
2012-09-25 11:40       ` Peter Zijlstra
2012-09-25 11:46         ` Peter Zijlstra
2012-09-25 17:56   ` Tejun Heo [this message]
2012-09-26 11:21     ` Viresh Kumar
2012-09-25 11:20 ` [PATCH 0/3] Create sched_select_cpu() and use it in workqueues Viresh Kumar

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=20120925175657.GB16296@google.com \
    --to=tj@kernel.org \
    --cc=Arvind.Chauhan@arm.com \
    --cc=Steve.Bannister@arm.com \
    --cc=amit.kucheria@linaro.org \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=patches@linaro.org \
    --cc=paul.mckenney@linaro.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=robin.randhawa@arm.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=tglx@linutronix.de \
    --cc=venki@google.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.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