lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1336056962-10465-3-git-send-email-gilad@benyossef.com>
Date:	Thu,  3 May 2012 17:55:58 +0300
From:	Gilad Ben-Yossef <gilad@...yossef.com>
To:	linux-kernel@...r.kernel.org
Cc:	Gilad Ben-Yossef <gilad@...yossef.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Tejun Heo <tj@...nel.org>, John Stultz <johnstul@...ibm.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
	Mel Gorman <mel@....ul.ie>, Mike Frysinger <vapier@...too.org>,
	David Rientjes <rientjes@...gle.com>,
	Hugh Dickins <hughd@...gle.com>,
	Minchan Kim <minchan.kim@...il.com>,
	Konstantin Khlebnikov <khlebnikov@...nvz.org>,
	Christoph Lameter <cl@...ux.com>,
	Chris Metcalf <cmetcalf@...era.com>,
	Hakan Akkan <hakanakkan@...il.com>,
	Max Krasnyansky <maxk@...lcomm.com>,
	Frederic Weisbecker <fweisbec@...il.com>, linux-mm@...ck.org
Subject: [PATCH v1 2/6] workqueue: introduce schedule_on_each_cpu_mask

Introduce schedule_on_each_cpu_mask function to schedule a work
item on each online CPU which is included in the mask provided.

Then re-implement schedule_on_each_cpu on top of the new function.

This function should be prefered to schedule_on_each_cpu in
any case where some of the CPUs, especially on a big multi-core
system, might not have actual work to perform in order to save
needless wakeups and schedules.

Signed-off-by: Gilad Ben-Yossef <gilad@...yossef.com>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Tejun Heo <tj@...nel.org>
CC: John Stultz <johnstul@...ibm.com>
CC: Andrew Morton <akpm@...ux-foundation.org>
CC: KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>
CC: Mel Gorman <mel@....ul.ie>
CC: Mike Frysinger <vapier@...too.org>
CC: David Rientjes <rientjes@...gle.com>
CC: Hugh Dickins <hughd@...gle.com>
CC: Minchan Kim <minchan.kim@...il.com>
CC: Konstantin Khlebnikov <khlebnikov@...nvz.org>
CC: Christoph Lameter <cl@...ux.com>
CC: Chris Metcalf <cmetcalf@...era.com>
CC: Hakan Akkan <hakanakkan@...il.com>
CC: Max Krasnyansky <maxk@...lcomm.com>
CC: Frederic Weisbecker <fweisbec@...il.com>
CC: linux-kernel@...r.kernel.org
CC: linux-mm@...ck.org
---
 include/linux/workqueue.h |    2 ++
 kernel/workqueue.c        |   36 ++++++++++++++++++++++++++++--------
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index af15545..20da95a 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -383,6 +383,8 @@ extern int schedule_delayed_work(struct delayed_work *work, unsigned long delay)
 extern int schedule_delayed_work_on(int cpu, struct delayed_work *work,
 					unsigned long delay);
 extern int schedule_on_each_cpu(work_func_t func);
+extern int schedule_on_each_cpu_mask(work_func_t func,
+					const struct cpumask *mask);
 extern int keventd_up(void);
 
 int execute_in_process_context(work_func_t fn, struct execute_work *);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 5abf42f..1c9782b 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2787,43 +2787,63 @@ int schedule_delayed_work_on(int cpu,
 EXPORT_SYMBOL(schedule_delayed_work_on);
 
 /**
- * schedule_on_each_cpu - execute a function synchronously on each online CPU
+ * schedule_on_each_cpu_mask - execute a function synchronously on each
+ * online CPU which is specified in the supplied cpumask
  * @func: the function to call
+ * @mask: the cpu mask
  *
- * 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.
+ * schedule_on_each_cpu_mask() executes @func on each online CPU which
+ * is part of the @mask using the * system workqueue and blocks until
+ * all CPUs have completed
+ * schedule_on_each_cpu_mask() is very slow.
  *
  * RETURNS:
  * 0 on success, -errno on failure.
  */
-int schedule_on_each_cpu(work_func_t func)
+int schedule_on_each_cpu_mask(work_func_t func, const struct cpumask *mask)
 {
 	int cpu;
 	struct work_struct __percpu *works;
 
 	works = alloc_percpu(struct work_struct);
-	if (!works)
+	if (unlikely(!works))
 		return -ENOMEM;
 
 	get_online_cpus();
 
-	for_each_online_cpu(cpu) {
+	for_each_cpu_and(cpu, mask, cpu_online_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_and(cpu, mask, cpu_online_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)
+{
+	return schedule_on_each_cpu_mask(func, cpu_online_mask);
+}
+
+/**
  * flush_scheduled_work - ensure that any scheduled work has run to completion.
  *
  * Forces execution of the kernel-global workqueue and blocks until its
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ