From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933238Ab3HGXfY (ORCPT ); Wed, 7 Aug 2013 19:35:24 -0400 Received: from usmamail.tilera.com ([12.216.194.151]:36609 "EHLO USMAMAIL.TILERA.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757520Ab3HGXfW (ORCPT ); Wed, 7 Aug 2013 19:35:22 -0400 Message-ID: <201308072335.r77NZJPA022490@farm-0012.internal.tilera.com> In-Reply-To: <5202CEAA.9040204@linux.vnet.ibm.com> References: <5202CEAA.9040204@linux.vnet.ibm.com> From: Chris Metcalf Date: Wed, 7 Aug 2013 16:49:44 -0400 Subject: [PATCH v4 1/2] workqueue: add new schedule_on_cpu_mask() API To: , , Tejun Heo , Thomas Gleixner , Frederic Weisbecker , Cody P Schafer MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This primitive allows scheduling work to run on a particular set of cpus described by a "struct cpumask". This can be useful, for example, if you have a per-cpu variable that requires code execution only if the per-cpu variable has a certain value (for example, is a non-empty list). Signed-off-by: Chris Metcalf --- v4: don't lose possible -ENOMEM in schedule_on_each_cpu() (Note: no change to the mm/swap.c commit) v3: split commit into two, one for workqueue and one for mm, though both should probably be taken through -mm. include/linux/workqueue.h | 3 +++ kernel/workqueue.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index a0ed78a..71a3fe7 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -13,6 +13,8 @@ #include #include +struct cpumask; + struct workqueue_struct; struct work_struct; @@ -470,6 +472,7 @@ extern void flush_workqueue(struct workqueue_struct *wq); extern void drain_workqueue(struct workqueue_struct *wq); extern void flush_scheduled_work(void); +extern int schedule_on_cpu_mask(work_func_t func, const struct cpumask *mask); extern int schedule_on_each_cpu(work_func_t func); int execute_in_process_context(work_func_t fn, struct execute_work *); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f02c4a4..1dacb09 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2962,17 +2962,18 @@ bool cancel_delayed_work_sync(struct delayed_work *dwork) EXPORT_SYMBOL(cancel_delayed_work_sync); /** - * schedule_on_each_cpu - execute a function synchronously on each online CPU + * schedule_on_cpu_mask - execute a function synchronously on each listed CPU * @func: the function to call + * @mask: the cpumask to invoke the function on * - * schedule_on_each_cpu() executes @func on each online CPU using the + * schedule_on_cpu_mask() executes @func on each listed CPU using the * system workqueue and blocks until all CPUs have completed. - * schedule_on_each_cpu() is very slow. + * schedule_on_cpu_mask() is very slow. * * RETURNS: * 0 on success, -errno on failure. */ -int schedule_on_each_cpu(work_func_t func) +int schedule_on_cpu_mask(work_func_t func, const struct cpumask *mask) { int cpu; struct work_struct __percpu *works; @@ -2981,24 +2982,41 @@ int schedule_on_each_cpu(work_func_t func) if (!works) return -ENOMEM; - get_online_cpus(); - - for_each_online_cpu(cpu) { + for_each_cpu(cpu, mask) { struct work_struct *work = per_cpu_ptr(works, cpu); INIT_WORK(work, func); schedule_work_on(cpu, work); } - for_each_online_cpu(cpu) + for_each_cpu(cpu, mask) flush_work(per_cpu_ptr(works, cpu)); - put_online_cpus(); free_percpu(works); return 0; } /** + * schedule_on_each_cpu - execute a function synchronously on each online CPU + * @func: the function to call + * + * schedule_on_each_cpu() executes @func on each online CPU using the + * system workqueue and blocks until all CPUs have completed. + * schedule_on_each_cpu() is very slow. + * + * RETURNS: + * 0 on success, -errno on failure. + */ +int schedule_on_each_cpu(work_func_t func) +{ + int ret; + get_online_cpus(); + ret = schedule_on_cpu_mask(func, cpu_online_mask); + put_online_cpus(); + return ret; +} + +/** * flush_scheduled_work - ensure that any scheduled work has run to completion. * * Forces execution of the kernel-global workqueue and blocks until its -- 1.8.3.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx186.postini.com [74.125.245.186]) by kanga.kvack.org (Postfix) with SMTP id ED17F6B0032 for ; Wed, 7 Aug 2013 19:35:22 -0400 (EDT) Message-ID: <201308072335.r77NZJPA022490@farm-0012.internal.tilera.com> In-Reply-To: <5202CEAA.9040204@linux.vnet.ibm.com> References: <5202CEAA.9040204@linux.vnet.ibm.com> From: Chris Metcalf Date: Wed, 7 Aug 2013 16:49:44 -0400 Subject: [PATCH v4 1/2] workqueue: add new schedule_on_cpu_mask() API MIME-Version: 1.0 Content-Type: text/plain Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Tejun Heo , Thomas Gleixner , Frederic Weisbecker , Cody P Schafer This primitive allows scheduling work to run on a particular set of cpus described by a "struct cpumask". This can be useful, for example, if you have a per-cpu variable that requires code execution only if the per-cpu variable has a certain value (for example, is a non-empty list). Signed-off-by: Chris Metcalf --- v4: don't lose possible -ENOMEM in schedule_on_each_cpu() (Note: no change to the mm/swap.c commit) v3: split commit into two, one for workqueue and one for mm, though both should probably be taken through -mm. include/linux/workqueue.h | 3 +++ kernel/workqueue.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index a0ed78a..71a3fe7 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -13,6 +13,8 @@ #include #include +struct cpumask; + struct workqueue_struct; struct work_struct; @@ -470,6 +472,7 @@ extern void flush_workqueue(struct workqueue_struct *wq); extern void drain_workqueue(struct workqueue_struct *wq); extern void flush_scheduled_work(void); +extern int schedule_on_cpu_mask(work_func_t func, const struct cpumask *mask); extern int schedule_on_each_cpu(work_func_t func); int execute_in_process_context(work_func_t fn, struct execute_work *); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f02c4a4..1dacb09 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2962,17 +2962,18 @@ bool cancel_delayed_work_sync(struct delayed_work *dwork) EXPORT_SYMBOL(cancel_delayed_work_sync); /** - * schedule_on_each_cpu - execute a function synchronously on each online CPU + * schedule_on_cpu_mask - execute a function synchronously on each listed CPU * @func: the function to call + * @mask: the cpumask to invoke the function on * - * schedule_on_each_cpu() executes @func on each online CPU using the + * schedule_on_cpu_mask() executes @func on each listed CPU using the * system workqueue and blocks until all CPUs have completed. - * schedule_on_each_cpu() is very slow. + * schedule_on_cpu_mask() is very slow. * * RETURNS: * 0 on success, -errno on failure. */ -int schedule_on_each_cpu(work_func_t func) +int schedule_on_cpu_mask(work_func_t func, const struct cpumask *mask) { int cpu; struct work_struct __percpu *works; @@ -2981,24 +2982,41 @@ int schedule_on_each_cpu(work_func_t func) if (!works) return -ENOMEM; - get_online_cpus(); - - for_each_online_cpu(cpu) { + for_each_cpu(cpu, mask) { struct work_struct *work = per_cpu_ptr(works, cpu); INIT_WORK(work, func); schedule_work_on(cpu, work); } - for_each_online_cpu(cpu) + for_each_cpu(cpu, mask) flush_work(per_cpu_ptr(works, cpu)); - put_online_cpus(); free_percpu(works); return 0; } /** + * schedule_on_each_cpu - execute a function synchronously on each online CPU + * @func: the function to call + * + * schedule_on_each_cpu() executes @func on each online CPU using the + * system workqueue and blocks until all CPUs have completed. + * schedule_on_each_cpu() is very slow. + * + * RETURNS: + * 0 on success, -errno on failure. + */ +int schedule_on_each_cpu(work_func_t func) +{ + int ret; + get_online_cpus(); + ret = schedule_on_cpu_mask(func, cpu_online_mask); + put_online_cpus(); + return ret; +} + +/** * flush_scheduled_work - ensure that any scheduled work has run to completion. * * Forces execution of the kernel-global workqueue and blocks until its -- 1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org