From: Tejun Heo <tj@kernel.org>
To: cl@linux-foundation.org, kmo@daterainc.com
Cc: linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 2/3] percpu-refcount: implement percpu_ref_set_killed()
Date: Mon, 8 Sep 2014 11:12:21 +0900 [thread overview]
Message-ID: <1410142342-8185-3-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1410142342-8185-1-git-send-email-tj@kernel.org>
With the recent addition of percpu_ref_reinit(), percpu_ref now can be
used as a persistent switch which can be turned on and off repeatedly
where turning off maps to killing the ref and waiting for it to drain;
however, there currently isn't a way to initialize a percpu_ref in its
off (killed and drained) state, which can be inconvenient for certain
persistent switch use cases.
This patch adds percpu_ref_set_killed() which forces the percpu_ref
into its killed and drained state. The caller is responsible for
ensuring that no one else is using the ref. This can be used to force
the percpu_ref into its off state after initialization.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Kent Overstreet <kmo@daterainc.com>
---
include/linux/percpu-refcount.h | 1 +
lib/percpu-refcount.c | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index ee83251..97a7d2a 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -69,6 +69,7 @@ struct percpu_ref {
int __must_check percpu_ref_init(struct percpu_ref *ref,
percpu_ref_func_t *release, gfp_t gfp);
void percpu_ref_reinit(struct percpu_ref *ref);
+void percpu_ref_set_killed(struct percpu_ref *ref);
void percpu_ref_exit(struct percpu_ref *ref);
void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
percpu_ref_func_t *confirm_kill);
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 70d28c9..a6768f6 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -98,6 +98,20 @@ void percpu_ref_reinit(struct percpu_ref *ref)
EXPORT_SYMBOL_GPL(percpu_ref_reinit);
/**
+ * percpu_ref_set_killed - force a percpu refcount to the killed state
+ * @ref: percpu_ref to set killed for
+ *
+ * Set @ref's state to killed. This function doesn't care about the
+ * current state or in-progress operations on @ref and the caller is
+ * responsible for ensuring that @ref isn't being used by anyone else.
+ */
+void percpu_ref_set_killed(struct percpu_ref *ref)
+{
+ ref->pcpu_count_ptr |= PCPU_REF_DEAD;
+ atomic_set(&ref->count, 0);
+}
+
+/**
* percpu_ref_exit - undo percpu_ref_init()
* @ref: percpu_ref to exit
*
--
1.9.3
next prev parent reply other threads:[~2014-09-08 2:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-08 2:12 [PATCHSET percpu/for-3.18] percpu-refcount: several improvements Tejun Heo
2014-09-08 2:12 ` [PATCH 1/3] percpu-refcount: improve WARN messages Tejun Heo
2014-09-08 2:12 ` Tejun Heo [this message]
2014-09-20 5:26 ` [PATCH 2/3] percpu-refcount: implement percpu_ref_set_killed() Tejun Heo
2014-09-08 2:12 ` [PATCH 3/3] percpu-refcount: make percpu_ref based on longs instead of ints Tejun Heo
2014-09-20 5:26 ` Tejun Heo
2014-09-20 5:31 ` [PATCH v2 " 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=1410142342-8185-3-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=cl@linux-foundation.org \
--cc=kmo@daterainc.com \
--cc=linux-kernel@vger.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
Powered by JetHome