提交 09223371 编写于 作者: S Shaohua Li 提交者: Paul E. McKenney

rcu: Use softirq to address performance regression

Commit a26ac245(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: NShaohua Li <shaohua.li@intel.com>
Tested-by: N"Alex,Shi" <alex.shi@intel.com>
Signed-off-by: NPaul E. McKenney <paulmck@linux.vnet.ibm.com>
上级 9a432736
...@@ -843,6 +843,7 @@ Provides counts of softirq handlers serviced since boot time, for each cpu. ...@@ -843,6 +843,7 @@ Provides counts of softirq handlers serviced since boot time, for each cpu.
TASKLET: 0 0 0 290 TASKLET: 0 0 0 290
SCHED: 27035 26983 26971 26746 SCHED: 27035 26983 26971 26746
HRTIMER: 0 0 0 0 HRTIMER: 0 0 0 0
RCU: 1678 1769 2178 2250
1.3 IDE devices in /proc/ide 1.3 IDE devices in /proc/ide
......
...@@ -414,6 +414,7 @@ enum ...@@ -414,6 +414,7 @@ enum
TASKLET_SOFTIRQ, TASKLET_SOFTIRQ,
SCHED_SOFTIRQ, SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ, HRTIMER_SOFTIRQ,
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
NR_SOFTIRQS NR_SOFTIRQS
}; };
......
...@@ -20,7 +20,8 @@ struct softirq_action; ...@@ -20,7 +20,8 @@ struct softirq_action;
softirq_name(BLOCK_IOPOLL), \ softirq_name(BLOCK_IOPOLL), \
softirq_name(TASKLET), \ softirq_name(TASKLET), \
softirq_name(SCHED), \ softirq_name(SCHED), \
softirq_name(HRTIMER)) softirq_name(HRTIMER), \
softirq_name(RCU))
/** /**
* irq_handler_entry - called immediately before the irq action handler * irq_handler_entry - called immediately before the irq action handler
......
...@@ -100,6 +100,7 @@ static char rcu_kthreads_spawnable; ...@@ -100,6 +100,7 @@ static char rcu_kthreads_spawnable;
static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu); static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
static void invoke_rcu_cpu_kthread(void); static void invoke_rcu_cpu_kthread(void);
static void __invoke_rcu_cpu_kthread(void);
#define RCU_KTHREAD_PRIO 1 /* RT priority for per-CPU kthreads. */ #define RCU_KTHREAD_PRIO 1 /* RT priority for per-CPU kthreads. */
...@@ -1442,13 +1443,21 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) ...@@ -1442,13 +1443,21 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
} }
/* If there are callbacks ready, invoke them. */ /* If there are callbacks ready, invoke them. */
rcu_do_batch(rsp, rdp); if (cpu_has_callbacks_ready_to_invoke(rdp))
__invoke_rcu_cpu_kthread();
}
static void rcu_kthread_do_work(void)
{
rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data));
rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
rcu_preempt_do_callbacks();
} }
/* /*
* Do softirq processing for the current CPU. * Do softirq processing for the current CPU.
*/ */
static void rcu_process_callbacks(void) static void rcu_process_callbacks(struct softirq_action *unused)
{ {
__rcu_process_callbacks(&rcu_sched_state, __rcu_process_callbacks(&rcu_sched_state,
&__get_cpu_var(rcu_sched_data)); &__get_cpu_var(rcu_sched_data));
...@@ -1465,7 +1474,7 @@ static void rcu_process_callbacks(void) ...@@ -1465,7 +1474,7 @@ static void rcu_process_callbacks(void)
* the current CPU with interrupts disabled, the rcu_cpu_kthread_task * the current CPU with interrupts disabled, the rcu_cpu_kthread_task
* cannot disappear out from under us. * cannot disappear out from under us.
*/ */
static void invoke_rcu_cpu_kthread(void) static void __invoke_rcu_cpu_kthread(void)
{ {
unsigned long flags; unsigned long flags;
...@@ -1479,6 +1488,11 @@ static void invoke_rcu_cpu_kthread(void) ...@@ -1479,6 +1488,11 @@ static void invoke_rcu_cpu_kthread(void)
local_irq_restore(flags); local_irq_restore(flags);
} }
static void invoke_rcu_cpu_kthread(void)
{
raise_softirq(RCU_SOFTIRQ);
}
/* /*
* Wake up the specified per-rcu_node-structure kthread. * Wake up the specified per-rcu_node-structure kthread.
* Because the per-rcu_node kthreads are immortal, we don't need * Because the per-rcu_node kthreads are immortal, we don't need
...@@ -1613,7 +1627,7 @@ static int rcu_cpu_kthread(void *arg) ...@@ -1613,7 +1627,7 @@ static int rcu_cpu_kthread(void *arg)
*workp = 0; *workp = 0;
local_irq_restore(flags); local_irq_restore(flags);
if (work) if (work)
rcu_process_callbacks(); rcu_kthread_do_work();
local_bh_enable(); local_bh_enable();
if (*workp != 0) if (*workp != 0)
spincnt++; spincnt++;
...@@ -2387,6 +2401,7 @@ void __init rcu_init(void) ...@@ -2387,6 +2401,7 @@ void __init rcu_init(void)
rcu_init_one(&rcu_sched_state, &rcu_sched_data); rcu_init_one(&rcu_sched_state, &rcu_sched_data);
rcu_init_one(&rcu_bh_state, &rcu_bh_data); rcu_init_one(&rcu_bh_state, &rcu_bh_data);
__rcu_init_preempt(); __rcu_init_preempt();
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
/* /*
* We don't need protection against CPU-hotplug here because * We don't need protection against CPU-hotplug here because
......
...@@ -439,6 +439,7 @@ static void rcu_preempt_offline_cpu(int cpu); ...@@ -439,6 +439,7 @@ static void rcu_preempt_offline_cpu(int cpu);
#endif /* #ifdef CONFIG_HOTPLUG_CPU */ #endif /* #ifdef CONFIG_HOTPLUG_CPU */
static void rcu_preempt_check_callbacks(int cpu); static void rcu_preempt_check_callbacks(int cpu);
static void rcu_preempt_process_callbacks(void); static void rcu_preempt_process_callbacks(void);
static void rcu_preempt_do_callbacks(void);
void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_TREE_PREEMPT_RCU) #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_TREE_PREEMPT_RCU)
static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp); static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp);
......
...@@ -602,6 +602,11 @@ static void rcu_preempt_process_callbacks(void) ...@@ -602,6 +602,11 @@ static void rcu_preempt_process_callbacks(void)
&__get_cpu_var(rcu_preempt_data)); &__get_cpu_var(rcu_preempt_data));
} }
static void rcu_preempt_do_callbacks(void)
{
rcu_do_batch(&rcu_preempt_state, &__get_cpu_var(rcu_preempt_data));
}
/* /*
* Queue a preemptible-RCU callback for invocation after a grace period. * Queue a preemptible-RCU callback for invocation after a grace period.
*/ */
...@@ -997,6 +1002,10 @@ static void rcu_preempt_process_callbacks(void) ...@@ -997,6 +1002,10 @@ static void rcu_preempt_process_callbacks(void)
{ {
} }
static void rcu_preempt_do_callbacks(void)
{
}
/* /*
* Wait for an rcu-preempt grace period, but make it happen quickly. * Wait for an rcu-preempt grace period, but make it happen quickly.
* But because preemptible RCU does not exist, map to rcu-sched. * But because preemptible RCU does not exist, map to rcu-sched.
......
...@@ -58,7 +58,7 @@ DEFINE_PER_CPU(struct task_struct *, ksoftirqd); ...@@ -58,7 +58,7 @@ DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
char *softirq_to_name[NR_SOFTIRQS] = { char *softirq_to_name[NR_SOFTIRQS] = {
"HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL", "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
"TASKLET", "SCHED", "HRTIMER" "TASKLET", "SCHED", "HRTIMER", "RCU"
}; };
/* /*
......
...@@ -2187,6 +2187,7 @@ static const struct flag flags[] = { ...@@ -2187,6 +2187,7 @@ static const struct flag flags[] = {
{ "TASKLET_SOFTIRQ", 6 }, { "TASKLET_SOFTIRQ", 6 },
{ "SCHED_SOFTIRQ", 7 }, { "SCHED_SOFTIRQ", 7 },
{ "HRTIMER_SOFTIRQ", 8 }, { "HRTIMER_SOFTIRQ", 8 },
{ "RCU_SOFTIRQ", 9 },
{ "HRTIMER_NORESTART", 0 }, { "HRTIMER_NORESTART", 0 },
{ "HRTIMER_RESTART", 1 }, { "HRTIMER_RESTART", 1 },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册