2011-04-14 02:07:50

by Shaohua Li

[permalink] [raw]
Subject: [patch v3 1/3] percpu_counter: change return value and add comments

the percpu_counter_*_positive() API in UP case doesn't check if return value is
positive. Add comments to explain why we don't.
Also if count < 0, returns 0 instead of 1 for *read_positive().

Signed-off-by: Shaohua Li <[email protected]>

---
include/linux/percpu_counter.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux/include/linux/percpu_counter.h
===================================================================
--- linux.orig/include/linux/percpu_counter.h 2011-04-13 16:09:22.000000000 +0800
+++ linux/include/linux/percpu_counter.h 2011-04-14 08:50:45.000000000 +0800
@@ -75,7 +75,7 @@ static inline s64 percpu_counter_read_po
barrier(); /* Prevent reloads of fbc->count */
if (ret >= 0)
return ret;
- return 1;
+ return 0;
}

static inline int percpu_counter_initialized(struct percpu_counter *fbc)
@@ -133,6 +133,10 @@ static inline s64 percpu_counter_read(st
return fbc->count;
}

+/*
+ * percpu_counter is intended to track positive number. In UP case, the number
+ * should never be negative.
+ */
static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
{
return fbc->count;


2011-04-14 02:32:47

by Eric Dumazet

[permalink] [raw]
Subject: Re: [patch v3 1/3] percpu_counter: change return value and add comments

Le jeudi 14 avril 2011 à 10:04 +0800, [email protected] a écrit :
> pièce jointe document texte brut (percpu-counter-positive.patch)
> the percpu_counter_*_positive() API in UP case doesn't check if return value is
> positive. Add comments to explain why we don't.
> Also if count < 0, returns 0 instead of 1 for *read_positive().
>
> Signed-off-by: Shaohua Li <[email protected]>
>
> ---
> include/linux/percpu_counter.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> Index: linux/include/linux/percpu_counter.h
> ===================================================================
> --- linux.orig/include/linux/percpu_counter.h 2011-04-13 16:09:22.000000000 +0800
> +++ linux/include/linux/percpu_counter.h 2011-04-14 08:50:45.000000000 +0800
> @@ -75,7 +75,7 @@ static inline s64 percpu_counter_read_po
> barrier(); /* Prevent reloads of fbc->count */
> if (ret >= 0)
> return ret;
> - return 1;
> + return 0;
> }
>
> static inline int percpu_counter_initialized(struct percpu_counter *fbc)
> @@ -133,6 +133,10 @@ static inline s64 percpu_counter_read(st
> return fbc->count;
> }
>
> +/*
> + * percpu_counter is intended to track positive number. In UP case, the number
> + * should never be negative.
> + */
> static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
> {
> return fbc->count;
>


Acked-by: Eric Dumazet <[email protected]>

2011-04-15 03:41:36

by Tejun Heo

[permalink] [raw]
Subject: Re: [patch v3 1/3] percpu_counter: change return value and add comments

On Thu, Apr 14, 2011 at 10:04:48AM +0800, [email protected] wrote:
> the percpu_counter_*_positive() API in UP case doesn't check if return value is
> positive. Add comments to explain why we don't.
> Also if count < 0, returns 0 instead of 1 for *read_positive().
>
> Signed-off-by: Shaohua Li <[email protected]>

Applied to percpu#for-2.6.40 w/ Eric's Acked-by added.

Thanks.

--
tejun