Skip to content

Commit

Permalink
lib: percpu_counter_init_irq
Browse files Browse the repository at this point in the history
provide a way to tell lockdep about percpu_counters that are supposed to be
used from irq safe contexts.

Signed-off-by: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Peter Zijlstra authored and Linus Torvalds committed Oct 17, 2007
1 parent 833f407 commit dc62a30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/linux/percpu_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
}
Expand Down
12 changes: 12 additions & 0 deletions lib/percpu_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit dc62a30

Please sign in to comment.