Skip to content

Commit 9e8d42a

Browse files
Sebastian Andrzej Siewiordennisszhou
authored andcommitted
percpu-refcount: Use normal instead of RCU-sched"
This is a revert of commit a424445 ("percpu-refcount: use RCU-sched insted of normal RCU") which claims the only reason for using RCU-sched is "rcu_read_[un]lock() … are slightly more expensive than preempt_disable/enable()" and "As the RCU critical sections are extremely short, using sched-RCU shouldn't have any latency implications." The problem with using RCU-sched here is that it disables preemption and the release callback (called from percpu_ref_put_many()) must not acquire any sleeping locks like spinlock_t. This breaks PREEMPT_RT because some of the users acquire spinlock_t locks in their callbacks. Using rcu_read_lock() on PREEMPTION=n kernels is not any different compared to rcu_read_lock_sched(). On PREEMPTION=y kernels there are already performance issues due to additional preemption points. Looking at the code, the rcu_read_lock() is just an increment and unlock is almost just a decrement unless there is something special to do. Both are functions while disabling preemption is inlined. Doing a small benchmark, the minimal amount of time required was mostly the same. The average time required was higher due to the higher MAX value (which could be preemption). With DEBUG_PREEMPT=y it is rcu_read_lock_sched() that takes a little longer due to the additional debug code. Convert back to normal RCU. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Dennis Zhou <[email protected]>
1 parent 825dbc6 commit 9e8d42a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/linux/percpu-refcount.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr)
186186
{
187187
unsigned long __percpu *percpu_count;
188188

189-
rcu_read_lock_sched();
189+
rcu_read_lock();
190190

191191
if (__ref_is_percpu(ref, &percpu_count))
192192
this_cpu_add(*percpu_count, nr);
193193
else
194194
atomic_long_add(nr, &ref->count);
195195

196-
rcu_read_unlock_sched();
196+
rcu_read_unlock();
197197
}
198198

199199
/**
@@ -223,7 +223,7 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref)
223223
unsigned long __percpu *percpu_count;
224224
bool ret;
225225

226-
rcu_read_lock_sched();
226+
rcu_read_lock();
227227

228228
if (__ref_is_percpu(ref, &percpu_count)) {
229229
this_cpu_inc(*percpu_count);
@@ -232,7 +232,7 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref)
232232
ret = atomic_long_inc_not_zero(&ref->count);
233233
}
234234

235-
rcu_read_unlock_sched();
235+
rcu_read_unlock();
236236

237237
return ret;
238238
}
@@ -257,7 +257,7 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref)
257257
unsigned long __percpu *percpu_count;
258258
bool ret = false;
259259

260-
rcu_read_lock_sched();
260+
rcu_read_lock();
261261

262262
if (__ref_is_percpu(ref, &percpu_count)) {
263263
this_cpu_inc(*percpu_count);
@@ -266,7 +266,7 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref)
266266
ret = atomic_long_inc_not_zero(&ref->count);
267267
}
268268

269-
rcu_read_unlock_sched();
269+
rcu_read_unlock();
270270

271271
return ret;
272272
}
@@ -285,14 +285,14 @@ static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr)
285285
{
286286
unsigned long __percpu *percpu_count;
287287

288-
rcu_read_lock_sched();
288+
rcu_read_lock();
289289

290290
if (__ref_is_percpu(ref, &percpu_count))
291291
this_cpu_sub(*percpu_count, nr);
292292
else if (unlikely(atomic_long_sub_and_test(nr, &ref->count)))
293293
ref->release(ref);
294294

295-
rcu_read_unlock_sched();
295+
rcu_read_unlock();
296296
}
297297

298298
/**

0 commit comments

Comments
 (0)