Skip to content

Commit f7b8eb8

Browse files
committed
rcu: Consolidate expedited grace period machinery
The functions synchronize_rcu_expedited() and synchronize_sched_expedited() have nearly identical code. This commit therefore consolidates this code into a new _synchronize_rcu_expedited() function. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 29b4817 commit f7b8eb8

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

kernel/rcu/tree_exp.h

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,33 @@ static void rcu_exp_wait_wake(struct rcu_state *rsp, unsigned long s)
516516
mutex_unlock(&rsp->exp_wake_mutex);
517517
}
518518

519+
/*
520+
* Given an rcu_state pointer and a smp_call_function() handler, kick
521+
* off the specified flavor of expedited grace period.
522+
*/
523+
static void _synchronize_rcu_expedited(struct rcu_state *rsp,
524+
smp_call_func_t func)
525+
{
526+
unsigned long s;
527+
528+
/* If expedited grace periods are prohibited, fall back to normal. */
529+
if (rcu_gp_is_normal()) {
530+
wait_rcu_gp(rsp->call);
531+
return;
532+
}
533+
534+
/* Take a snapshot of the sequence number. */
535+
s = rcu_exp_gp_seq_snap(rsp);
536+
if (exp_funnel_lock(rsp, s))
537+
return; /* Someone else did our work for us. */
538+
539+
/* Initialize the rcu_node tree in preparation for the wait. */
540+
sync_rcu_exp_select_cpus(rsp, func);
541+
542+
/* Wait and clean up, including waking everyone. */
543+
rcu_exp_wait_wake(rsp, s);
544+
}
545+
519546
/**
520547
* synchronize_sched_expedited - Brute-force RCU-sched grace period
521548
*
@@ -534,29 +561,13 @@ static void rcu_exp_wait_wake(struct rcu_state *rsp, unsigned long s)
534561
*/
535562
void synchronize_sched_expedited(void)
536563
{
537-
unsigned long s;
538564
struct rcu_state *rsp = &rcu_sched_state;
539565

540566
/* If only one CPU, this is automatically a grace period. */
541567
if (rcu_blocking_is_gp())
542568
return;
543569

544-
/* If expedited grace periods are prohibited, fall back to normal. */
545-
if (rcu_gp_is_normal()) {
546-
wait_rcu_gp(call_rcu_sched);
547-
return;
548-
}
549-
550-
/* Take a snapshot of the sequence number. */
551-
s = rcu_exp_gp_seq_snap(rsp);
552-
if (exp_funnel_lock(rsp, s))
553-
return; /* Someone else did our work for us. */
554-
555-
/* Initialize the rcu_node tree in preparation for the wait. */
556-
sync_rcu_exp_select_cpus(rsp, sync_sched_exp_handler);
557-
558-
/* Wait and clean up, including waking everyone. */
559-
rcu_exp_wait_wake(rsp, s);
570+
_synchronize_rcu_expedited(rsp, sync_sched_exp_handler);
560571
}
561572
EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
562573

@@ -620,23 +631,8 @@ static void sync_rcu_exp_handler(void *info)
620631
void synchronize_rcu_expedited(void)
621632
{
622633
struct rcu_state *rsp = rcu_state_p;
623-
unsigned long s;
624634

625-
/* If expedited grace periods are prohibited, fall back to normal. */
626-
if (rcu_gp_is_normal()) {
627-
wait_rcu_gp(call_rcu);
628-
return;
629-
}
630-
631-
s = rcu_exp_gp_seq_snap(rsp);
632-
if (exp_funnel_lock(rsp, s))
633-
return; /* Someone else did our work for us. */
634-
635-
/* Initialize the rcu_node tree in preparation for the wait. */
636-
sync_rcu_exp_select_cpus(rsp, sync_rcu_exp_handler);
637-
638-
/* Wait for ->blkd_tasks lists to drain, then wake everyone up. */
639-
rcu_exp_wait_wake(rsp, s);
635+
_synchronize_rcu_expedited(rsp, sync_rcu_exp_handler);
640636
}
641637
EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
642638

0 commit comments

Comments
 (0)