diff options
author | Shaohua Li <shaohua.li@intel.com> | 2011-06-14 01:26:25 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2011-06-14 18:25:39 -0400 |
commit | 09223371deac67d08ca0b70bd18787920284c967 (patch) | |
tree | 0ad0354a93ac209c8cfd2b79d03d0462aa3c5c58 /kernel/rcutree.c | |
parent | 9a432736904d386cda28b987b38ba14dae960ecc (diff) |
rcu: Use softirq to address performance regression
Commit a26ac2455ffcf3(rcu: move TREE_RCU from softirq to kthread)
introduced performance regression. In an AIM7 test, this commit degraded
performance by about 40%.
The commit runs rcu callbacks in a kthread instead of softirq. We observed
high rate of context switch which is caused by this. Out test system has
64 CPUs and HZ is 1000, so we saw more than 64k context switch per second
which is caused by RCU's per-CPU kthread. A trace showed that most of
the time the RCU per-CPU kthread doesn't actually handle any callbacks,
but instead just does a very small amount of work handling grace periods.
This means that RCU's per-CPU kthreads are making the scheduler do quite
a bit of work in order to allow a very small amount of RCU-related
processing to be done.
Alex Shi's analysis determined that this slowdown is due to lock
contention within the scheduler. Unfortunately, as Peter Zijlstra points
out, the scheduler's real-time semantics require global action, which
means that this contention is inherent in real-time scheduling. (Yes,
perhaps someone will come up with a workaround -- otherwise, -rt is not
going to do well on large SMP systems -- but this patch will work around
this issue in the meantime. And "the meantime" might well be forever.)
This patch therefore re-introduces softirq processing to RCU, but only
for core RCU work. RCU callbacks are still executed in kthread context,
so that only a small amount of RCU work runs in softirq context in the
common case. This should minimize ksoftirqd execution, allowing us to
skip boosting of ksoftirqd for CONFIG_RCU_BOOST=y kernels.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Tested-by: "Alex,Shi" <alex.shi@intel.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'kernel/rcutree.c')
-rw-r--r-- | kernel/rcutree.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 0a8ec5b2e208..ae5c9ea68662 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
@@ -100,6 +100,7 @@ static char rcu_kthreads_spawnable; | |||
100 | 100 | ||
101 | static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu); | 101 | static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu); |
102 | static void invoke_rcu_cpu_kthread(void); | 102 | static void invoke_rcu_cpu_kthread(void); |
103 | static void __invoke_rcu_cpu_kthread(void); | ||
103 | 104 | ||
104 | #define RCU_KTHREAD_PRIO 1 /* RT priority for per-CPU kthreads. */ | 105 | #define RCU_KTHREAD_PRIO 1 /* RT priority for per-CPU kthreads. */ |
105 | 106 | ||
@@ -1442,13 +1443,21 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1442 | } | 1443 | } |
1443 | 1444 | ||
1444 | /* If there are callbacks ready, invoke them. */ | 1445 | /* If there are callbacks ready, invoke them. */ |
1445 | rcu_do_batch(rsp, rdp); | 1446 | if (cpu_has_callbacks_ready_to_invoke(rdp)) |
1447 | __invoke_rcu_cpu_kthread(); | ||
1448 | } | ||
1449 | |||
1450 | static void rcu_kthread_do_work(void) | ||
1451 | { | ||
1452 | rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data)); | ||
1453 | rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); | ||
1454 | rcu_preempt_do_callbacks(); | ||
1446 | } | 1455 | } |
1447 | 1456 | ||
1448 | /* | 1457 | /* |
1449 | * Do softirq processing for the current CPU. | 1458 | * Do softirq processing for the current CPU. |
1450 | */ | 1459 | */ |
1451 | static void rcu_process_callbacks(void) | 1460 | static void rcu_process_callbacks(struct softirq_action *unused) |
1452 | { | 1461 | { |
1453 | __rcu_process_callbacks(&rcu_sched_state, | 1462 | __rcu_process_callbacks(&rcu_sched_state, |
1454 | &__get_cpu_var(rcu_sched_data)); | 1463 | &__get_cpu_var(rcu_sched_data)); |
@@ -1465,7 +1474,7 @@ static void rcu_process_callbacks(void) | |||
1465 | * the current CPU with interrupts disabled, the rcu_cpu_kthread_task | 1474 | * the current CPU with interrupts disabled, the rcu_cpu_kthread_task |
1466 | * cannot disappear out from under us. | 1475 | * cannot disappear out from under us. |
1467 | */ | 1476 | */ |
1468 | static void invoke_rcu_cpu_kthread(void) | 1477 | static void __invoke_rcu_cpu_kthread(void) |
1469 | { | 1478 | { |
1470 | unsigned long flags; | 1479 | unsigned long flags; |
1471 | 1480 | ||
@@ -1479,6 +1488,11 @@ static void invoke_rcu_cpu_kthread(void) | |||
1479 | local_irq_restore(flags); | 1488 | local_irq_restore(flags); |
1480 | } | 1489 | } |
1481 | 1490 | ||
1491 | static void invoke_rcu_cpu_kthread(void) | ||
1492 | { | ||
1493 | raise_softirq(RCU_SOFTIRQ); | ||
1494 | } | ||
1495 | |||
1482 | /* | 1496 | /* |
1483 | * Wake up the specified per-rcu_node-structure kthread. | 1497 | * Wake up the specified per-rcu_node-structure kthread. |
1484 | * Because the per-rcu_node kthreads are immortal, we don't need | 1498 | * Because the per-rcu_node kthreads are immortal, we don't need |
@@ -1613,7 +1627,7 @@ static int rcu_cpu_kthread(void *arg) | |||
1613 | *workp = 0; | 1627 | *workp = 0; |
1614 | local_irq_restore(flags); | 1628 | local_irq_restore(flags); |
1615 | if (work) | 1629 | if (work) |
1616 | rcu_process_callbacks(); | 1630 | rcu_kthread_do_work(); |
1617 | local_bh_enable(); | 1631 | local_bh_enable(); |
1618 | if (*workp != 0) | 1632 | if (*workp != 0) |
1619 | spincnt++; | 1633 | spincnt++; |
@@ -2387,6 +2401,7 @@ void __init rcu_init(void) | |||
2387 | rcu_init_one(&rcu_sched_state, &rcu_sched_data); | 2401 | rcu_init_one(&rcu_sched_state, &rcu_sched_data); |
2388 | rcu_init_one(&rcu_bh_state, &rcu_bh_data); | 2402 | rcu_init_one(&rcu_bh_state, &rcu_bh_data); |
2389 | __rcu_init_preempt(); | 2403 | __rcu_init_preempt(); |
2404 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
2390 | 2405 | ||
2391 | /* | 2406 | /* |
2392 | * We don't need protection against CPU-hotplug here because | 2407 | * We don't need protection against CPU-hotplug here because |