Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

percpu-refcount: support synchronous switch to atomic mode.

percpu_ref_switch_to_atomic_sync() schedules the switch to atomic mode, then
waits for it to complete.

Also export percpu_ref_switch_to_* so they can be used from modules.

This will be used in md/raid to count the number of pending write
requests to an array.
We occasionally need to check if the count is zero, but most often
we don't care.
We always want updates to the counter to be fast, as in some cases
we count every 4K page.

Signed-off-by: NeilBrown <neilb@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Shaohua Li <shli@fb.com>

authored by

NeilBrown and committed by
Shaohua Li
210f7cdc 55cc39f3

+18
+1
include/linux/percpu-refcount.h
··· 99 99 void percpu_ref_exit(struct percpu_ref *ref); 100 100 void percpu_ref_switch_to_atomic(struct percpu_ref *ref, 101 101 percpu_ref_func_t *confirm_switch); 102 + void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref); 102 103 void percpu_ref_switch_to_percpu(struct percpu_ref *ref); 103 104 void percpu_ref_kill_and_confirm(struct percpu_ref *ref, 104 105 percpu_ref_func_t *confirm_kill);
+17
lib/percpu-refcount.c
··· 260 260 261 261 spin_unlock_irqrestore(&percpu_ref_switch_lock, flags); 262 262 } 263 + EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic); 264 + 265 + /** 266 + * percpu_ref_switch_to_atomic_sync - switch a percpu_ref to atomic mode 267 + * @ref: percpu_ref to switch to atomic mode 268 + * 269 + * Schedule switching the ref to atomic mode, and wait for the 270 + * switch to complete. Caller must ensure that no other thread 271 + * will switch back to percpu mode. 272 + */ 273 + void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref) 274 + { 275 + percpu_ref_switch_to_atomic(ref, NULL); 276 + wait_event(percpu_ref_switch_waitq, !ref->confirm_switch); 277 + } 278 + EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic_sync); 263 279 264 280 /** 265 281 * percpu_ref_switch_to_percpu - switch a percpu_ref to percpu mode ··· 306 290 307 291 spin_unlock_irqrestore(&percpu_ref_switch_lock, flags); 308 292 } 293 + EXPORT_SYMBOL_GPL(percpu_ref_switch_to_percpu); 309 294 310 295 /** 311 296 * percpu_ref_kill_and_confirm - drop the initial ref and schedule confirmation