* [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait
@ 2019-10-29 3:16 Jackie Liu
2019-11-01 2:14 ` Bob Liu
2019-11-01 14:37 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Jackie Liu @ 2019-10-29 3:16 UTC (permalink / raw)
To: axboe; +Cc: liuyun01, linux-block
We didn't use -ERESTARTSYS to tell the application layer to restart the
system call, but instead return -EINTR. we can set -EINTR directly when
wakeup by the signal, which can help us save an assignment operation and
comparison operation.
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
fs/io_uring.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a30c4f6..63eee7e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2878,7 +2878,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
.to_wait = min_events,
};
struct io_rings *rings = ctx->rings;
- int ret;
+ int ret = 0;
if (io_cqring_events(rings) >= min_events)
return 0;
@@ -2896,7 +2896,6 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
return ret;
}
- ret = 0;
iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts);
do {
prepare_to_wait_exclusive(&ctx->wait, &iowq.wq,
@@ -2905,15 +2904,13 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
break;
schedule();
if (signal_pending(current)) {
- ret = -ERESTARTSYS;
+ ret = -EINTR;
break;
}
} while (1);
finish_wait(&ctx->wait, &iowq.wq);
- restore_saved_sigmask_unless(ret == -ERESTARTSYS);
- if (ret == -ERESTARTSYS)
- ret = -EINTR;
+ restore_saved_sigmask_unless(ret == -EINTR);
return READ_ONCE(rings->cq.head) == READ_ONCE(rings->cq.tail) ? ret : 0;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait
2019-10-29 3:16 [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait Jackie Liu
@ 2019-11-01 2:14 ` Bob Liu
2019-11-01 14:37 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Bob Liu @ 2019-11-01 2:14 UTC (permalink / raw)
To: Jackie Liu, axboe; +Cc: linux-block
On 10/29/19 11:16 AM, Jackie Liu wrote:
> We didn't use -ERESTARTSYS to tell the application layer to restart the
> system call, but instead return -EINTR. we can set -EINTR directly when
> wakeup by the signal, which can help us save an assignment operation and
> comparison operation.
>
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Looks good to me.
Reviewed-by: Bob Liu <bob.liu@oracle.com>
> ---
> fs/io_uring.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index a30c4f6..63eee7e 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -2878,7 +2878,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
> .to_wait = min_events,
> };
> struct io_rings *rings = ctx->rings;
> - int ret;
> + int ret = 0;
>
> if (io_cqring_events(rings) >= min_events)
> return 0;
> @@ -2896,7 +2896,6 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
> return ret;
> }
>
> - ret = 0;
> iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts);
> do {
> prepare_to_wait_exclusive(&ctx->wait, &iowq.wq,
> @@ -2905,15 +2904,13 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
> break;
> schedule();
> if (signal_pending(current)) {
> - ret = -ERESTARTSYS;
> + ret = -EINTR;
> break;
> }
> } while (1);
> finish_wait(&ctx->wait, &iowq.wq);
>
> - restore_saved_sigmask_unless(ret == -ERESTARTSYS);
> - if (ret == -ERESTARTSYS)
> - ret = -EINTR;
> + restore_saved_sigmask_unless(ret == -EINTR);
>
> return READ_ONCE(rings->cq.head) == READ_ONCE(rings->cq.tail) ? ret : 0;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait
2019-10-29 3:16 [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait Jackie Liu
2019-11-01 2:14 ` Bob Liu
@ 2019-11-01 14:37 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-11-01 14:37 UTC (permalink / raw)
To: Jackie Liu; +Cc: linux-block
On 10/28/19 9:16 PM, Jackie Liu wrote:
> We didn't use -ERESTARTSYS to tell the application layer to restart the
> system call, but instead return -EINTR. we can set -EINTR directly when
> wakeup by the signal, which can help us save an assignment operation and
> comparison operation.
Looks good - patch looks like it's against 5.3 though, I've queued it up
for 5.4 with a bit of mangling.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-01 14:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29 3:16 [PATCH] io_uring: set -EINTR directly when a signal wakes up in io_cqring_wait Jackie Liu
2019-11-01 2:14 ` Bob Liu
2019-11-01 14:37 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).