Skip to content

Commit f032a45

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
locking, percpu_counter: Annotate ::lock as raw
The percpu_counter::lock can be taken in atomic context and therefore cannot be preempted on -rt - annotate it. In mainline this change documents the low level nature of the lock - otherwise there's no functional difference. Lockdep and Sparse checking will work as usual. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent ec48460 commit f032a45

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎include/linux/percpu_counter.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifdef CONFIG_SMP
1717

1818
struct percpu_counter {
19-
spinlock_t lock;
19+
raw_spinlock_t lock;
2020
s64 count;
2121
#ifdef CONFIG_HOTPLUG_CPU
2222
struct list_head list; /* All percpu_counters are on a list */

‎lib/percpu_counter.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
5959
{
6060
int cpu;
6161

62-
spin_lock(&fbc->lock);
62+
raw_spin_lock(&fbc->lock);
6363
for_each_possible_cpu(cpu) {
6464
s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
6565
*pcount = 0;
6666
}
6767
fbc->count = amount;
68-
spin_unlock(&fbc->lock);
68+
raw_spin_unlock(&fbc->lock);
6969
}
7070
EXPORT_SYMBOL(percpu_counter_set);
7171

@@ -76,10 +76,10 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
7676
preempt_disable();
7777
count = __this_cpu_read(*fbc->counters) + amount;
7878
if (count >= batch || count <= -batch) {
79-
spin_lock(&fbc->lock);
79+
raw_spin_lock(&fbc->lock);
8080
fbc->count += count;
8181
__this_cpu_write(*fbc->counters, 0);
82-
spin_unlock(&fbc->lock);
82+
raw_spin_unlock(&fbc->lock);
8383
} else {
8484
__this_cpu_write(*fbc->counters, count);
8585
}
@@ -96,21 +96,21 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
9696
s64 ret;
9797
int cpu;
9898

99-
spin_lock(&fbc->lock);
99+
raw_spin_lock(&fbc->lock);
100100
ret = fbc->count;
101101
for_each_online_cpu(cpu) {
102102
s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
103103
ret += *pcount;
104104
}
105-
spin_unlock(&fbc->lock);
105+
raw_spin_unlock(&fbc->lock);
106106
return ret;
107107
}
108108
EXPORT_SYMBOL(__percpu_counter_sum);
109109

110110
int __percpu_counter_init(struct percpu_counter *fbc, s64 amount,
111111
struct lock_class_key *key)
112112
{
113-
spin_lock_init(&fbc->lock);
113+
raw_spin_lock_init(&fbc->lock);
114114
lockdep_set_class(&fbc->lock, key);
115115
fbc->count = amount;
116116
fbc->counters = alloc_percpu(s32);
@@ -173,11 +173,11 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
173173
s32 *pcount;
174174
unsigned long flags;
175175

176-
spin_lock_irqsave(&fbc->lock, flags);
176+
raw_spin_lock_irqsave(&fbc->lock, flags);
177177
pcount = per_cpu_ptr(fbc->counters, cpu);
178178
fbc->count += *pcount;
179179
*pcount = 0;
180-
spin_unlock_irqrestore(&fbc->lock, flags);
180+
raw_spin_unlock_irqrestore(&fbc->lock, flags);
181181
}
182182
mutex_unlock(&percpu_counters_lock);
183183
#endif

0 commit comments

Comments
 (0)