From: Kent Overstreet <koverstreet@google.com>
To: tj@kernel.org
Cc: linux-kernel@vger.kernel.org, Kent Overstreet <koverstreet@google.com>
Subject: [PATCH] percpu-refcount: Don't use silly cmpxchg()
Date: Mon, 3 Jun 2013 16:02:29 -0700 [thread overview]
Message-ID: <1370300549-2177-1-git-send-email-koverstreet@google.com> (raw)
In-Reply-To: <1370039205-14071-1-git-send-email-koverstreet@google.com>
The cmpxcgh() was just to ensure the debug check didn't race, which was
a bit excessive. The caller is supposed to do the appropriate
synchronization, which means percpu_ref_kill() can just do a simple
store.
Signed-off-by: Kent Overstreet <koverstreet@google.com>
---
lib/percpu-refcount.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index e65820a..04be7ea 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -107,22 +107,11 @@ static void percpu_ref_kill_rcu(struct rcu_head *rcu)
*/
void percpu_ref_kill(struct percpu_ref *ref)
{
- unsigned __percpu *pcpu_count, *old, *new;
+ WARN_ONCE(REF_STATUS(ref->pcpu_count) == PCPU_REF_DEAD,
+ "percpu_ref_kill() called more than once!\n");
- pcpu_count = ACCESS_ONCE(ref->pcpu_count);
-
- do {
- if (REF_STATUS(pcpu_count) == PCPU_REF_DEAD) {
- WARN(1, "percpu_ref_kill() called more than once!\n");
- return;
- }
-
- old = pcpu_count;
- new = (unsigned __percpu *)
- (((unsigned long) pcpu_count)|PCPU_REF_DEAD);
-
- pcpu_count = cmpxchg(&ref->pcpu_count, old, new);
- } while (pcpu_count != old);
+ ref->pcpu_count = (unsigned __percpu *)
+ (((unsigned long) ref->pcpu_count)|PCPU_REF_DEAD);
call_rcu(&ref->rcu, percpu_ref_kill_rcu);
}
--
1.8.2.1
next prev parent reply other threads:[~2013-06-03 23:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 22:26 [PATCH] Generic percpu refcounting Kent Overstreet
2013-06-03 22:39 ` Tejun Heo
2013-06-03 23:02 ` Kent Overstreet [this message]
2013-06-03 23:09 ` [PATCH] percpu-refcount: Don't use silly cmpxchg() Tejun Heo
2013-06-05 7:35 ` [PATCH] Generic percpu refcounting Rusty Russell
2013-06-05 7:44 ` 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=1370300549-2177-1-git-send-email-koverstreet@google.com \
--to=koverstreet@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.