Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752116AbdDMLLj (ORCPT ); Thu, 13 Apr 2017 07:11:39 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:33972 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750952AbdDMLLg (ORCPT ); Thu, 13 Apr 2017 07:11:36 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="17705081" Subject: Re: [patch 02/13] workqueue: Provide work_on_cpu_safe() To: Thomas Gleixner , LKML References: <20170412200726.941336635@linutronix.de> <20170412201042.262610721@linutronix.de> CC: Peter Zijlstra , Ingo Molnar , Sebastian Siewior , Benjamin Herrenschmidt , "David S. Miller" , Fenghua Yu , Herbert Xu , Lai Jiangshan , Len Brown , Michael Ellerman , "Rafael J. Wysocki" , Tejun Heo , Tony Luck , Viresh Kumar From: Dou Liyang Message-ID: Date: Thu, 13 Apr 2017 19:11:32 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170412201042.262610721@linutronix.de> Content-Type: text/plain; charset="iso-8859-15"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: 9768C47CE221.ACBD2 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.fnst@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2160 Lines: 76 At 04/13/2017 04:07 AM, Thomas Gleixner wrote: > work_on_cpu() is not protected against CPU hotplug. For code which requires > to be either executed on an online CPU or to fail if the CPU is not > available the callsite would have to protect against CPU hotplug. > > Provide a function which does get/put_online_cpus() around the call to > work_on_cpu() and fails the call with -ENODEV if the target CPU is not > online. > > Preparatory patch to convert several racy task affinity manipulations. > > Signed-off-by: Thomas Gleixner > Cc: Tejun Heo > Cc: Lai Jiangshan > --- > include/linux/workqueue.h | 5 +++++ > kernel/workqueue.c | 23 +++++++++++++++++++++++ > 2 files changed, 28 insertions(+) > > --- a/include/linux/workqueue.h > +++ b/include/linux/workqueue.h > @@ -608,8 +608,13 @@ static inline long work_on_cpu(int cpu, > { > return fn(arg); > } > +static inline long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg) > +{ > + return fn(arg); > +} > #else > long work_on_cpu(int cpu, long (*fn)(void *), void *arg); > +long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg); > #endif /* CONFIG_SMP */ > > #ifdef CONFIG_FREEZER > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -4735,6 +4735,29 @@ long work_on_cpu(int cpu, long (*fn)(voi > return wfc.ret; > } > EXPORT_SYMBOL_GPL(work_on_cpu); > + > +/** There is an extra '*' :) Thanks, Liyang > + * work_on_cpu_safe - run a function in thread context on a particular cpu > + * @cpu: the cpu to run on > + * @fn: the function to run > + * @arg: the function argument > + * > + * Disables CPU hotplug and calls work_on_cpu(). The caller must not hold > + * any locks which would prevent @fn from completing. > + * > + * Return: The value @fn returns. > + */ > +long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg) > +{ > + long ret = -ENODEV; > + > + get_online_cpus(); > + if (cpu_online(cpu)) > + ret = work_on_cpu(cpu, fn, arg); > + put_online_cpus(); > + return ret; > +} > +EXPORT_SYMBOL_GPL(work_on_cpu_safe); > #endif /* CONFIG_SMP */ > > #ifdef CONFIG_FREEZER