Skip to content

Commit f6239d3

Browse files
Davidlohr Buesodjbw
authored andcommitted
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>
1 parent a70fc4e commit f6239d3

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

include/linux/rcuwait.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ static inline void prepare_to_rcuwait(struct rcuwait *w)
4949

5050
extern void finish_rcuwait(struct rcuwait *w);
5151

52-
#define rcuwait_wait_event(w, condition, state) \
52+
#define ___rcuwait_wait_event(w, condition, state, ret, cmd) \
5353
({ \
54-
int __ret = 0; \
54+
long __ret = ret; \
5555
prepare_to_rcuwait(w); \
5656
for (;;) { \
5757
/* \
@@ -67,10 +67,27 @@ extern void finish_rcuwait(struct rcuwait *w);
6767
break; \
6868
} \
6969
\
70-
schedule(); \
70+
cmd; \
7171
} \
7272
finish_rcuwait(w); \
7373
__ret; \
7474
})
7575

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); \
90+
__ret; \
91+
})
92+
7693
#endif /* _LINUX_RCUWAIT_H_ */

0 commit comments

Comments
 (0)