aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2016-02-09 17:59:38 -0500
committerTejun Heo <tj@kernel.org>2016-02-09 17:59:38 -0500
commitf303fccb82928790ec58eea82722bd5c54d300b3 (patch)
tree20030c728af441a4efa01c2612be4883bd431115
parentef557180447fa9a7a0affd3abb21ecceb4b5e125 (diff)
workqueue: implement "workqueue.debug_force_rr_cpu" debug feature
Workqueue used to guarantee local execution for work items queued without explicit target CPU. The guarantee is gone now which can break some usages in subtle ways. To flush out those cases, this patch implements a debug feature which forces round-robin CPU selection for all such work items. The debug feature defaults to off and can be enabled with a kernel parameter. The default can be flipped with a debug config option. If you hit this commit during bisection, please refer to 041bd12e272c ("Revert "workqueue: make sure delayed work run in local cpu"") for more information and ping me. Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r--Documentation/kernel-parameters.txt11
-rw-r--r--kernel/workqueue.c23
-rw-r--r--lib/Kconfig.debug15
3 files changed, 47 insertions, 2 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 87d40a72f6a1..cda2ead39093 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -4230,6 +4230,17 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
4230 The default value of this parameter is determined by 4230 The default value of this parameter is determined by
4231 the config option CONFIG_WQ_POWER_EFFICIENT_DEFAULT. 4231 the config option CONFIG_WQ_POWER_EFFICIENT_DEFAULT.
4232 4232
4233 workqueue.debug_force_rr_cpu
4234 Workqueue used to implicitly guarantee that work
4235 items queued without explicit CPU specified are put
4236 on the local CPU. This guarantee is no longer true
4237 and while local CPU is still preferred work items
4238 may be put on foreign CPUs. This debug option
4239 forces round-robin CPU selection to flush out
4240 usages which depend on the now broken guarantee.
4241 When enabled, memory and cache locality will be
4242 impacted.
4243
4233 x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of 4244 x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
4234 default x2apic cluster mode on platforms 4245 default x2apic cluster mode on platforms
4235 supporting x2apic. 4246 supporting x2apic.
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 054774605d2f..51d77e7c0989 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -307,6 +307,18 @@ static cpumask_var_t wq_unbound_cpumask;
307/* CPU where unbound work was last round robin scheduled from this CPU */ 307/* CPU where unbound work was last round robin scheduled from this CPU */
308static DEFINE_PER_CPU(int, wq_rr_cpu_last); 308static DEFINE_PER_CPU(int, wq_rr_cpu_last);
309 309
310/*
311 * Local execution of unbound work items is no longer guaranteed. The
312 * following always forces round-robin CPU selection on unbound work items
313 * to uncover usages which depend on it.
314 */
315#ifdef CONFIG_DEBUG_WQ_FORCE_RR_CPU
316static bool wq_debug_force_rr_cpu = true;
317#else
318static bool wq_debug_force_rr_cpu = false;
319#endif
320module_param_named(debug_force_rr_cpu, wq_debug_force_rr_cpu, bool, 0644);
321
310/* the per-cpu worker pools */ 322/* the per-cpu worker pools */
311static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS], 323static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
312 cpu_worker_pools); 324 cpu_worker_pools);
@@ -1309,10 +1321,17 @@ static bool is_chained_work(struct workqueue_struct *wq)
1309 */ 1321 */
1310static int wq_select_unbound_cpu(int cpu) 1322static int wq_select_unbound_cpu(int cpu)
1311{ 1323{
1324 static bool printed_dbg_warning;
1312 int new_cpu; 1325 int new_cpu;
1313 1326
1314 if (cpumask_test_cpu(cpu, wq_unbound_cpumask)) 1327 if (likely(!wq_debug_force_rr_cpu)) {
1315 return cpu; 1328 if (cpumask_test_cpu(cpu, wq_unbound_cpumask))
1329 return cpu;
1330 } else if (!printed_dbg_warning) {
1331 pr_warn("workqueue: round-robin CPU selection forced, expect performance impact\n");
1332 printed_dbg_warning = true;
1333 }
1334
1316 if (cpumask_empty(wq_unbound_cpumask)) 1335 if (cpumask_empty(wq_unbound_cpumask))
1317 return cpu; 1336 return cpu;
1318 1337
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ecb9e75614bf..8bfd1aca7a3d 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1400,6 +1400,21 @@ config RCU_EQS_DEBUG
1400 1400
1401endmenu # "RCU Debugging" 1401endmenu # "RCU Debugging"
1402 1402
1403config DEBUG_WQ_FORCE_RR_CPU
1404 bool "Force round-robin CPU selection for unbound work items"
1405 depends on DEBUG_KERNEL
1406 default n
1407 help
1408 Workqueue used to implicitly guarantee that work items queued
1409 without explicit CPU specified are put on the local CPU. This
1410 guarantee is no longer true and while local CPU is still
1411 preferred work items may be put on foreign CPUs. Kernel
1412 parameter "workqueue.debug_force_rr_cpu" is added to force
1413 round-robin CPU selection to flush out usages which depend on the
1414 now broken guarantee. This config option enables the debug
1415 feature by default. When enabled, memory and cache locality will
1416 be impacted.
1417
1403config DEBUG_BLOCK_EXT_DEVT 1418config DEBUG_BLOCK_EXT_DEVT
1404 bool "Force extended block device numbers and spread them" 1419 bool "Force extended block device numbers and spread them"
1405 depends on DEBUG_KERNEL 1420 depends on DEBUG_KERNEL