lib: percpu_counter_init_irq
authorPeter Zijlstra <a.p.zijlstra@chello.nl>
Wed, 17 Oct 2007 06:25:46 +0000 (23:25 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 17 Oct 2007 15:42:44 +0000 (08:42 -0700)
provide a way to tell lockdep about percpu_counters that are supposed to be
used from irq safe contexts.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/percpu_counter.h
lib/percpu_counter.c

index f7ecd38d7e9c074f3065838c452eb6015ee7619e..9007ccdfc1127cfe73db03e31dd82a843f8f4fa8 100644 (file)
@@ -31,6 +31,7 @@ struct percpu_counter {
 #endif
 
 int percpu_counter_init(struct percpu_counter *fbc, s64 amount);
+int percpu_counter_init_irq(struct percpu_counter *fbc, s64 amount);
 void percpu_counter_destroy(struct percpu_counter *fbc);
 void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
 void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch);
@@ -84,6 +85,8 @@ static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
        return 0;
 }
 
+#define percpu_counter_init_irq percpu_counter_init
+
 static inline void percpu_counter_destroy(struct percpu_counter *fbc)
 {
 }
index 3a59d84b2d1e14ef96c4ef6f51e939cdc88e574c..9659eabffc319c5235669a87687949d270536b4e 100644 (file)
@@ -68,6 +68,8 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
 }
 EXPORT_SYMBOL(__percpu_counter_sum);
 
+static struct lock_class_key percpu_counter_irqsafe;
+
 int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
 {
        spin_lock_init(&fbc->lock);
@@ -84,6 +86,16 @@ int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
 }
 EXPORT_SYMBOL(percpu_counter_init);
 
+int percpu_counter_init_irq(struct percpu_counter *fbc, s64 amount)
+{
+       int err;
+
+       err = percpu_counter_init(fbc, amount);
+       if (!err)
+               lockdep_set_class(&fbc->lock, &percpu_counter_irqsafe);
+       return err;
+}
+
 void percpu_counter_destroy(struct percpu_counter *fbc)
 {
        if (!fbc->counters)