Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207229
b: refs/heads/master
c: 27f5e0f
h: refs/heads/master
i:
  207227: ea76ec1
v: v3
  • Loading branch information
Tim Chen authored and Linus Torvalds committed Aug 10, 2010
1 parent 7e49c4d commit f74ba0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4e60c86bd9e5a7110ed28874d0b6592186550ae8
refs/heads/master: 27f5e0f694fd0600274a76854636c0749e3bb1f6
11 changes: 11 additions & 0 deletions trunk/include/linux/percpu_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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);
s64 __percpu_counter_sum(struct percpu_counter *fbc);
int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs);

static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
{
Expand Down Expand Up @@ -98,6 +99,16 @@ static inline void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
fbc->count = amount;
}

static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
{
if (fbc->count > rhs)
return 1;
else if (fbc->count < rhs)
return -1;
else
return 0;
}

static inline void
percpu_counter_add(struct percpu_counter *fbc, s64 amount)
{
Expand Down
27 changes: 27 additions & 0 deletions trunk/lib/percpu_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
return NOTIFY_OK;
}

/*
* Compare counter against given value.
* Return 1 if greater, 0 if equal and -1 if less
*/
int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
{
s64 count;

count = percpu_counter_read(fbc);
/* Check to see if rough count will be sufficient for comparison */
if (abs(count - rhs) > (percpu_counter_batch*num_online_cpus())) {
if (count > rhs)
return 1;
else
return -1;
}
/* Need to use precise count */
count = percpu_counter_sum(fbc);
if (count > rhs)
return 1;
else if (count < rhs)
return -1;
else
return 0;
}
EXPORT_SYMBOL(percpu_counter_compare);

static int __init percpu_counter_startup(void)
{
compute_batch_value();
Expand Down

0 comments on commit f74ba0b

Please sign in to comment.