aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/percpu-refcount.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-09-24 13:31:50 -0400
committerTejun Heo <tj@kernel.org>2014-09-24 13:31:50 -0400
commit2aad2a86f6685c10360ec8a5a55eb9ab7059cb72 (patch)
tree85da25f36ba0c8158becdc8ba940201652cf30ce /include/linux/percpu-refcount.h
parentf47ad45784611297b699f3dffb6c7222b76afe64 (diff)
percpu_ref: add PERCPU_REF_INIT_* flags
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. Similarly, percpu_ref_switch_to_atomic/percpu() allow dynamic selection of operation mode; however, currently a newly initialized percpu_ref is always in percpu mode making it impossible to avoid the latency overhead of switching to atomic mode. This patch adds @flags to percpu_ref_init() and implements the following flags. * PERCPU_REF_INIT_ATOMIC : start ref in atomic mode * PERCPU_REF_INIT_DEAD : start ref killed and drained These flags should be able to serve the above two use cases. v2: target_core_tpg.c conversion was missing. Fixed. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Kent Overstreet <kmo@daterainc.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Christoph Hellwig <hch@infradead.org> Cc: Johannes Weiner <hannes@cmpxchg.org>
Diffstat (limited to 'include/linux/percpu-refcount.h')
-rw-r--r--include/linux/percpu-refcount.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index cd7e20f0fe47..b0293f268cd2 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -63,6 +63,21 @@ enum {
63 __PERCPU_REF_FLAG_BITS = 2, 63 __PERCPU_REF_FLAG_BITS = 2,
64}; 64};
65 65
66/* @flags for percpu_ref_init() */
67enum {
68 /*
69 * Start w/ ref == 1 in atomic mode. Can be switched to percpu
70 * operation using percpu_ref_switch_to_percpu().
71 */
72 PERCPU_REF_INIT_ATOMIC = 1 << 0,
73
74 /*
75 * Start dead w/ ref == 0 in atomic mode. Must be revived with
76 * percpu_ref_reinit() before used. Implies INIT_ATOMIC.
77 */
78 PERCPU_REF_INIT_DEAD = 1 << 1,
79};
80
66struct percpu_ref { 81struct percpu_ref {
67 atomic_long_t count; 82 atomic_long_t count;
68 /* 83 /*
@@ -76,7 +91,8 @@ struct percpu_ref {
76}; 91};
77 92
78int __must_check percpu_ref_init(struct percpu_ref *ref, 93int __must_check percpu_ref_init(struct percpu_ref *ref,
79 percpu_ref_func_t *release, gfp_t gfp); 94 percpu_ref_func_t *release, unsigned int flags,
95 gfp_t gfp);
80void percpu_ref_exit(struct percpu_ref *ref); 96void percpu_ref_exit(struct percpu_ref *ref);
81void percpu_ref_switch_to_atomic(struct percpu_ref *ref, 97void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
82 percpu_ref_func_t *confirm_switch); 98 percpu_ref_func_t *confirm_switch);