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

rcuwait: Support timeouts

The rcuwait utility provides an efficient and safe single
wait/wake mechanism. It is used in situations where queued
wait is the wrong semantics, and often too bulky. For example,
cases where the wait is already done under a lock.

In the past, rcuwait has been extended to support beyond only
uninterruptible sleep, and similarly, there are users that can
benefit for the addition of timeouts.

As such, tntroduce rcuwait_wait_event_timeout(), with semantics
equivalent to calls for queued wait counterparts.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Link: https://lore.kernel.org/r/20230523170927.20685-2-dave@stgolabs.net
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

authored by

Davidlohr Bueso and committed by
Dan Williams
f6239d3f a70fc4ed

+20 -3
+20 -3
include/linux/rcuwait.h
··· 49 49 50 50 extern void finish_rcuwait(struct rcuwait *w); 51 51 52 - #define rcuwait_wait_event(w, condition, state) \ 52 + #define ___rcuwait_wait_event(w, condition, state, ret, cmd) \ 53 53 ({ \ 54 - int __ret = 0; \ 54 + long __ret = ret; \ 55 55 prepare_to_rcuwait(w); \ 56 56 for (;;) { \ 57 57 /* \ ··· 67 67 break; \ 68 68 } \ 69 69 \ 70 - schedule(); \ 70 + cmd; \ 71 71 } \ 72 72 finish_rcuwait(w); \ 73 + __ret; \ 74 + }) 75 + 76 + #define rcuwait_wait_event(w, condition, state) \ 77 + ___rcuwait_wait_event(w, condition, state, 0, schedule()) 78 + 79 + #define __rcuwait_wait_event_timeout(w, condition, state, timeout) \ 80 + ___rcuwait_wait_event(w, ___wait_cond_timeout(condition), \ 81 + state, timeout, \ 82 + __ret = schedule_timeout(__ret)) 83 + 84 + #define rcuwait_wait_event_timeout(w, condition, state, timeout) \ 85 + ({ \ 86 + long __ret = timeout; \ 87 + if (!___wait_cond_timeout(condition)) \ 88 + __ret = __rcuwait_wait_event_timeout(w, condition, \ 89 + state, timeout); \ 73 90 __ret; \ 74 91 }) 75 92