mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shaohua Li <shaohua.li@intel.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>, cl@linux.com, tj@kernel.org
Subject: [PATCH 1/4]percpu_counter: make API return consistent value
Date: Tue, 12 Apr 2011 16:03:57 +0800	[thread overview]
Message-ID: <1302595437.3981.127.camel@sli10-conroe> (raw)

the percpu_counter_*_positive() API SMP and !SMP aren't consistent. From
the API name, we should return a non-negative value for them.
Also if count < 0, returns 0 instead of 1 for *read_positive().

Signed-off-by: Shaohua Li <shaohua.li@intel.com>

---
 include/linux/percpu_counter.h |   52 ++++++++++++++++-------------------------
 1 file changed, 21 insertions(+), 31 deletions(-)

Index: linux/include/linux/percpu_counter.h
===================================================================
--- linux.orig/include/linux/percpu_counter.h	2011-04-12 15:48:42.000000000 +0800
+++ linux/include/linux/percpu_counter.h	2011-04-12 15:48:44.000000000 +0800
@@ -47,12 +47,6 @@ static inline void percpu_counter_add(st
 	__percpu_counter_add(fbc, amount, percpu_counter_batch);
 }
 
-static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
-{
-	s64 ret = __percpu_counter_sum(fbc);
-	return ret < 0 ? 0 : ret;
-}
-
 static inline s64 percpu_counter_sum(struct percpu_counter *fbc)
 {
 	return __percpu_counter_sum(fbc);
@@ -63,21 +57,6 @@ static inline s64 percpu_counter_read(st
 	return fbc->count;
 }
 
-/*
- * It is possible for the percpu_counter_read() to return a small negative
- * number for some counter which should never be negative.
- *
- */
-static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
-{
-	s64 ret = fbc->count;
-
-	barrier();		/* Prevent reloads of fbc->count */
-	if (ret >= 0)
-		return ret;
-	return 1;
-}
-
 static inline int percpu_counter_initialized(struct percpu_counter *fbc)
 {
 	return (fbc->counters != NULL);
@@ -133,16 +112,6 @@ static inline s64 percpu_counter_read(st
 	return fbc->count;
 }
 
-static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
-{
-	return fbc->count;
-}
-
-static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
-{
-	return percpu_counter_read_positive(fbc);
-}
-
 static inline s64 percpu_counter_sum(struct percpu_counter *fbc)
 {
 	return percpu_counter_read(fbc);
@@ -170,4 +139,25 @@ static inline void percpu_counter_sub(st
 	percpu_counter_add(fbc, -amount);
 }
 
+/*
+ * It is possible for the percpu_counter_read() to return a small negative
+ * number for some counter which should never be negative.
+ *
+ */
+static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
+{
+	s64 ret = percpu_counter_read(fbc);
+
+	barrier();		/* Prevent reloads of fbc->count */
+	if (ret >= 0)
+		return ret;
+	return 0;
+}
+
+static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
+{
+	s64 ret = percpu_counter_sum(fbc);
+	return ret < 0 ? 0 : ret;
+}
+
 #endif /* _LINUX_PERCPU_COUNTER_H */



             reply	other threads:[~2011-04-12  8:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12  8:03 Shaohua Li [this message]
2011-04-12 18:49 ` Tejun Heo
2011-04-13  1:24   ` Shaohua Li
2011-04-13  3:08     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302595437.3981.127.camel@sli10-conroe \
    --to=shaohua.li@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®