Skip to contentSkip to conversation

rcu: eliminate rcu_data.last_qsctr

PATCH In review Oleg Nesterov 3 participants 4 messages Nov 28, 2004 – Jan 5, 2005 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu: eliminate rcu_data.last_qsctr

last_qsctr is used in rcu_check_quiescent_state() exclusively. We can reset qsctr at the start of the grace period, and then just test qsctr against 0.

On top of the 'rcu: eliminate rcu_ctrlblk.lock', see
http://marc.theaimsgroup.com/?l=linux-kernel&m=110156786721526

include/linux/rcupdate.h renamed from include/linux/rcupdate.h~ +0 -2
@@ -88,8 +88,6 @@ struct rcu_data {
 	/* 1) quiescent state handling : */
 	long		quiescbatch;     /* Batch # for grace period */
 	long		qsctr;		 /* User-mode/idle loop etc. */
-	long            last_qsctr;	 /* value of qsctr at beginning */
-					 /* of rcu grace period */
 	int		qs_pending;	 /* core waits for quiesc state */
 
 	/* 2) batch handling */
kernel/rcupdate.c renamed from kernel/rcupdate.c~ +3 -8
@@ -215,9 +215,9 @@ static void rcu_check_quiescent_state(st
 			struct rcu_state *rsp, struct rcu_data *rdp)
 {
 	if (rdp->quiescbatch != rcp->cur) {
-		/* new grace period: record qsctr value. */
+		/* new grace period: reset qsctr value. */
 		rdp->qs_pending = 1;
-		rdp->last_qsctr = rdp->qsctr;
+		rdp->qsctr = 0;
 		rdp->quiescbatch = rcp->cur;
 		return;
 	}
@@ -229,12 +229,7 @@ static void rcu_check_quiescent_state(st
 	if (!rdp->qs_pending)
 		return;
 
-	/* 
-	 * Races with local timer interrupt - in the worst case
-	 * we may miss one quiescent state of that CPU. That is
-	 * tolerable. So no need to disable interrupts.
-	 */
-	if (rdp->qsctr == rdp->last_qsctr)
+	if (rdp->qsctr == 0)
 		return;
 	rdp->qs_pending = 0;
#1 lore raw
Quoted 11 lines · Oleg Nesterov

last_qsctr is used in rcu_check_quiescent_state() exclusively. We can reset qsctr at the start of the grace period, and then just test qsctr against 0.

On top of the 'rcu: eliminate rcu_ctrlblk.lock', see
http://marc.theaimsgroup.com/?l=linux-kernel&m=110156786721526

Compile and boot tested with 2.6.10-rc2 on a 2-cpu system.

#2 lore raw
In reply to Oleg Nesterov
Quoted 6 lines · Oleg Nesterov

last_qsctr is used in rcu_check_quiescent_state() exclusively. We can reset qsctr at the start of the grace period, and then just test qsctr against 0.

It seems the patch got lost, I've updated it a bit and resent it to Andrew.

But: I think there is the potential for an even larger cleanup, although this would be more a rewrite:
Get rid of rcu_check_quiescent_state and instead use something like this in rcu_qsctr_inc:

static inline void rcu_qsctr_inc(int cpu)

{
       struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
       if (rdp->quiescbatch != rcp->cur) {
            /* a new grace period is running. And we are at a quiescent
             * point, so complete it
             */
            spin_lock(&rsp->lock);
            rdp->quiescbatch = rcp->cur;
            cpu_quiet(rdp->cpu, rcp, rsp);
           spin_unlock(&rsp->lock);
    }
}

It's just an idea, it needs testing on big systems - does reading from the global rcp from every schedule call cause any problems? The cache line is virtually read-only, so it shouldn't cause trashing, but who knows?

--
Manfred

#3 lore raw
Quoted 29 lines · Manfred Spraul
Quoted 6 lines · Oleg Nesterov

last_qsctr is used in rcu_check_quiescent_state() exclusively. We can reset qsctr at the start of the grace period, and then just test qsctr against 0.

It seems the patch got lost, I've updated it a bit and resent it to Andrew.

But: I think there is the potential for an even larger cleanup, although this would be more a rewrite:
Get rid of rcu_check_quiescent_state and instead use something like this in rcu_qsctr_inc:

static inline void rcu_qsctr_inc(int cpu)

{
       struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
       if (rdp->quiescbatch != rcp->cur) {
            /* a new grace period is running. And we are at a quiescent
             * point, so complete it
             */
            spin_lock(&rsp->lock);
            rdp->quiescbatch = rcp->cur;
            cpu_quiet(rdp->cpu, rcp, rsp);
           spin_unlock(&rsp->lock);
    }
}
Quoted 3 lines

It's just an idea, it needs testing on big systems - does reading from the global rcp from every schedule call cause any problems? The cache line is virtually read-only, so it shouldn't cause trashing, but who knows?

Hello, Manfred,

The main concern I have with this is not cache thrashing of rcp->cur, but shrinking the grace periods on large systems, which can result in extra overhead per callback, since the shorter grace periods will tend to have fewer callbacks. We saw this problem on some of the early RCU-infrastructure patches.

Another approach would be to conditionally compile the two versions, though that might make the code more complex.

Thanx, Paul