Skip to contentSkip to conversation

aio: simplify read_events()

PATCH New Oleg Nesterov 1 participant 1 message Jun 7, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aio: simplify read_events()

Change wait_event_hrtimeout() to not call __wait_event_hrtimeout() if timeout == 0, this matches other _timeout() helpers in wait.h.

This allows to simplify its only user, read_events(), it no longer needs to optimize the "until == 0" case by hand.

Note: this patch doesn't use ___wait_cond_timeout because _hrtimeout() also differs in that it returns 0 if succeeds and -ETIME on timeout. Perhaps we should change this to make it fully compatible with other helpers.

---
 fs/aio.c             | 9 +++------
 include/linux/wait.h | 4 ++--
 2 files changed, 5 insertions(+), 8 deletions(-)
fs/aio.c +3 -6
index 5bdbef0..2bb3f2e 100644
@@ -1289,12 +1289,9 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr,
 	 * the ringbuffer empty. So in practice we should be ok, but it's
 	 * something to be aware of when touching this code.
 	 */
-	if (until == 0)
-		aio_read_events(ctx, min_nr, nr, event, &ret);
-	else
-		wait_event_interruptible_hrtimeout(ctx->wait,
-				aio_read_events(ctx, min_nr, nr, event, &ret),
-				until);
+	wait_event_interruptible_hrtimeout(ctx->wait,
+			aio_read_events(ctx, min_nr, nr, event, &ret),
+			until);
 	return ret;
 }
 
include/linux/wait.h +2 -2
index b6f77cf..ddb9596 100644
@@ -527,7 +527,7 @@ do {										\
 ({										\
 	int __ret = 0;								\
 	might_sleep();								\
-	if (!(condition))							\
+	if (!(condition) && (timeout))						\
 		__ret = __wait_event_hrtimeout(wq_head, condition, timeout,	\
 					       TASK_UNINTERRUPTIBLE);		\
 	__ret;									\
@@ -553,7 +553,7 @@ do {										\
 ({										\
 	long __ret = 0;								\
 	might_sleep();								\
-	if (!(condition))							\
+	if (!(condition) && (timeout))						\
 		__ret = __wait_event_hrtimeout(wq, condition, timeout,		\
 					       TASK_INTERRUPTIBLE);		\
 	__ret;									\
Signature · 1 line
2.5.0