Skip to contentSkip to conversation

percpu_counter: __this_cpu_write doesn't need to be protected by spinlock

PATCH New Fan Du 1 participant 1 message Jul 1, 2013

Subsystems (2)
lore
Share & tools
lore

Fan Du

author
#0 lore raw

PATCH 1/1 percpu_counter: __this_cpu_write doesn't need to be protected by spinlock

__this_cpu_write doesn't need to be protected by spinlock, AS we are doing per cpu write with preempt disabled. And another reason to remove __this_cpu_write outside of spinlock: __percpu_counter_sum is not a accurate counter.

---
 lib/percpu_counter.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/percpu_counter.c +1 -1
index ba6085d..1fc23a3 100644
@@ -80,8 +80,8 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
 	if (count >= batch || count <= -batch) {
 		raw_spin_lock(&fbc->lock);
 		fbc->count += count;
-		__this_cpu_write(*fbc->counters, 0);
 		raw_spin_unlock(&fbc->lock);
+		__this_cpu_write(*fbc->counters, 0);
 	} else {
 		__this_cpu_write(*fbc->counters, count);
 	}
Signature · 1 line
1.7.1