X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=lib%2Fpercpu_counter.c;h=ec9048e74f448ce3a79522aef9ac5f4c4b350737;hb=dcded10f6dce10411b16134ce9cc87bfdf75c13f;hp=aeaa6d7344475518a3b73b3a7062106e77cadcea;hpb=33dbe6114047496a5b6fee0941c52dad41250043;p=~andy%2Flinux diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index aeaa6d73444..ec9048e74f4 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c @@ -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();