Skip to content

Commit c3422be

Browse files
paulmckIngo Molnar
authored andcommitted
rcu: Simplify rcu_read_unlock_special() quiescent-state accounting
The earlier approach required two scheduling-clock ticks to note an preemptable-RCU quiescent state in the situation in which the scheduling-clock interrupt is unlucky enough to always interrupt an RCU read-side critical section. With this change, the quiescent state is instead noted by the outermost rcu_read_unlock() immediately following the first scheduling-clock tick, or, alternatively, by the first subsequent context switch. Therefore, this change also speeds up grace periods. Suggested-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: laijs@cn.fujitsu.com Cc: dipankar@in.ibm.com Cc: akpm@linux-foundation.org Cc: mathieu.desnoyers@polymtl.ca Cc: dvhltc@us.ibm.com Cc: niv@us.ibm.com Cc: peterz@infradead.org Cc: rostedt@goodmis.org Cc: Valdis.Kletnieks@vt.edu LKML-Reference: <12528585111945-git-send-email-> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent b0e165c commit c3422be

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

include/linux/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,6 @@ extern cputime_t task_gtime(struct task_struct *p);
17401740

17411741
#define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */
17421742
#define RCU_READ_UNLOCK_NEED_QS (1 << 1) /* RCU core needs CPU response. */
1743-
#define RCU_READ_UNLOCK_GOT_QS (1 << 2) /* CPU has responded to RCU core. */
17441743

17451744
static inline void rcu_copy_process(struct task_struct *p)
17461745
{

kernel/rcutree.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,23 @@ static void __cpuinit rcu_init_percpu_data(int cpu, struct rcu_state *rsp,
107107
*/
108108
void rcu_sched_qs(int cpu)
109109
{
110-
unsigned long flags;
111110
struct rcu_data *rdp;
112111

113-
local_irq_save(flags);
114112
rdp = &per_cpu(rcu_sched_data, cpu);
115-
rdp->passed_quiesc = 1;
116113
rdp->passed_quiesc_completed = rdp->completed;
117-
rcu_preempt_qs(cpu);
118-
local_irq_restore(flags);
114+
barrier();
115+
rdp->passed_quiesc = 1;
116+
rcu_preempt_note_context_switch(cpu);
119117
}
120118

121119
void rcu_bh_qs(int cpu)
122120
{
123-
unsigned long flags;
124121
struct rcu_data *rdp;
125122

126-
local_irq_save(flags);
127123
rdp = &per_cpu(rcu_bh_data, cpu);
128-
rdp->passed_quiesc = 1;
129124
rdp->passed_quiesc_completed = rdp->completed;
130-
local_irq_restore(flags);
125+
barrier();
126+
rdp->passed_quiesc = 1;
131127
}
132128

133129
#ifdef CONFIG_NO_HZ
@@ -615,6 +611,7 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
615611

616612
/* Advance to a new grace period and initialize state. */
617613
rsp->gpnum++;
614+
WARN_ON_ONCE(rsp->signaled == RCU_GP_INIT);
618615
rsp->signaled = RCU_GP_INIT; /* Hold off force_quiescent_state. */
619616
rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
620617
record_gp_stall_check_time(rsp);

kernel/rcutree_plugin.h

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,42 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed);
6464
* not in a quiescent state. There might be any number of tasks blocked
6565
* while in an RCU read-side critical section.
6666
*/
67-
static void rcu_preempt_qs_record(int cpu)
67+
static void rcu_preempt_qs(int cpu)
6868
{
6969
struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
70-
rdp->passed_quiesc = 1;
7170
rdp->passed_quiesc_completed = rdp->completed;
71+
barrier();
72+
rdp->passed_quiesc = 1;
7273
}
7374

7475
/*
75-
* We have entered the scheduler or are between softirqs in ksoftirqd.
76-
* If we are in an RCU read-side critical section, we need to reflect
77-
* that in the state of the rcu_node structure corresponding to this CPU.
78-
* Caller must disable hardirqs.
76+
* We have entered the scheduler, and the current task might soon be
77+
* context-switched away from. If this task is in an RCU read-side
78+
* critical section, we will no longer be able to rely on the CPU to
79+
* record that fact, so we enqueue the task on the appropriate entry
80+
* of the blocked_tasks[] array. The task will dequeue itself when
81+
* it exits the outermost enclosing RCU read-side critical section.
82+
* Therefore, the current grace period cannot be permitted to complete
83+
* until the blocked_tasks[] entry indexed by the low-order bit of
84+
* rnp->gpnum empties.
85+
*
86+
* Caller must disable preemption.
7987
*/
80-
static void rcu_preempt_qs(int cpu)
88+
static void rcu_preempt_note_context_switch(int cpu)
8189
{
8290
struct task_struct *t = current;
91+
unsigned long flags;
8392
int phase;
8493
struct rcu_data *rdp;
8594
struct rcu_node *rnp;
8695

8796
if (t->rcu_read_lock_nesting &&
8897
(t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
89-
WARN_ON_ONCE(cpu != smp_processor_id());
9098

9199
/* Possibly blocking in an RCU read-side critical section. */
92100
rdp = rcu_preempt_state.rda[cpu];
93101
rnp = rdp->mynode;
94-
spin_lock(&rnp->lock);
102+
spin_lock_irqsave(&rnp->lock, flags);
95103
t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
96104
t->rcu_blocked_node = rnp;
97105

@@ -112,7 +120,7 @@ static void rcu_preempt_qs(int cpu)
112120
phase = !(rnp->qsmask & rdp->grpmask) ^ (rnp->gpnum & 0x1);
113121
list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]);
114122
smp_mb(); /* Ensure later ctxt swtch seen after above. */
115-
spin_unlock(&rnp->lock);
123+
spin_unlock_irqrestore(&rnp->lock, flags);
116124
}
117125

118126
/*
@@ -124,9 +132,8 @@ static void rcu_preempt_qs(int cpu)
124132
* grace period, then the fact that the task has been enqueued
125133
* means that we continue to block the current grace period.
126134
*/
127-
rcu_preempt_qs_record(cpu);
128-
t->rcu_read_unlock_special &= ~(RCU_READ_UNLOCK_NEED_QS |
129-
RCU_READ_UNLOCK_GOT_QS);
135+
rcu_preempt_qs(cpu);
136+
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
130137
}
131138

132139
/*
@@ -162,7 +169,7 @@ static void rcu_read_unlock_special(struct task_struct *t)
162169
special = t->rcu_read_unlock_special;
163170
if (special & RCU_READ_UNLOCK_NEED_QS) {
164171
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
165-
t->rcu_read_unlock_special |= RCU_READ_UNLOCK_GOT_QS;
172+
rcu_preempt_qs(smp_processor_id());
166173
}
167174

168175
/* Hardware IRQ handlers cannot block. */
@@ -199,9 +206,7 @@ static void rcu_read_unlock_special(struct task_struct *t)
199206
*/
200207
if (!empty && rnp->qsmask == 0 &&
201208
list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1])) {
202-
t->rcu_read_unlock_special &=
203-
~(RCU_READ_UNLOCK_NEED_QS |
204-
RCU_READ_UNLOCK_GOT_QS);
209+
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
205210
if (rnp->parent == NULL) {
206211
/* Only one rcu_node in the tree. */
207212
cpu_quiet_msk_finish(&rcu_preempt_state, flags);
@@ -352,19 +357,12 @@ static void rcu_preempt_check_callbacks(int cpu)
352357
struct task_struct *t = current;
353358

354359
if (t->rcu_read_lock_nesting == 0) {
355-
t->rcu_read_unlock_special &=
356-
~(RCU_READ_UNLOCK_NEED_QS | RCU_READ_UNLOCK_GOT_QS);
357-
rcu_preempt_qs_record(cpu);
360+
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
361+
rcu_preempt_qs(cpu);
358362
return;
359363
}
360364
if (per_cpu(rcu_preempt_data, cpu).qs_pending) {
361-
if (t->rcu_read_unlock_special & RCU_READ_UNLOCK_GOT_QS) {
362-
rcu_preempt_qs_record(cpu);
363-
t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_GOT_QS;
364-
} else if (!(t->rcu_read_unlock_special &
365-
RCU_READ_UNLOCK_NEED_QS)) {
366-
t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
367-
}
365+
t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
368366
}
369367
}
370368

@@ -451,7 +449,7 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed);
451449
* Because preemptable RCU does not exist, we never have to check for
452450
* CPUs being in quiescent states.
453451
*/
454-
static void rcu_preempt_qs(int cpu)
452+
static void rcu_preempt_note_context_switch(int cpu)
455453
{
456454
}
457455

0 commit comments

Comments
 (0)