From: Jackie Liu <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] io_uring: add support for linked SQE timeouts
Date: Fri, 8 Nov 2019 09:24:20 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
> 2019年11月7日 10:05,Jens Axboe <[email protected]> 写道:
>
> While we have support for generic timeouts, we don't have a way to tie
> a timeout to a specific SQE. The generic timeouts simply trigger wakeups
> on the CQ ring.
>
> This adds support for IORING_OP_LINK_TIMEOUT. This command is only valid
> as a link to a previous command. The timeout specific can be either
> relative or absolute, following the same rules as IORING_OP_TIMEOUT. If
> the timeout triggers before the dependent command completes, it will
> attempt to cancel that command. Likewise, if the dependent command
> completes before the timeout triggers, it will cancel the timeout.
>
> Signed-off-by: Jens Axboe <[email protected]>
>
> ---
>
> Changes since v1:
> - Move required locking outside of io_req_link_next(), it's much
> cleaner this way and avoids sparse complaining.
> - Avoid 32-bit complaint on casting to pointer of different size
> - Fix IORING_TIMEOUT_ABS, used sqe->flags instead of timeout_flags
> - Rebase on top of current tree
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index c39d1c50a3be..e29ecc1b0218 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -329,6 +329,7 @@ struct io_kiocb {
> #define REQ_F_IO_DRAIN 16 /* drain existing IO first */
> #define REQ_F_IO_DRAINED 32 /* drain done */
> #define REQ_F_LINK 64 /* linked sqes */
> +#define REQ_F_LINK_TIMEOUT 128 /* has linked timeout */
> #define REQ_F_FAIL_LINK 256 /* fail rest of links */
> #define REQ_F_SHADOW_DRAIN 512 /* link-drain shadow req */
> #define REQ_F_TIMEOUT 1024 /* timeout request */
> @@ -371,6 +372,7 @@ static void io_wq_submit_work(struct io_wq_work **workptr);
> static void io_cqring_fill_event(struct io_ring_ctx *ctx, u64 ki_user_data,
> long res);
> static void __io_free_req(struct io_kiocb *req);
> +static void io_put_req(struct io_kiocb *req, struct io_kiocb **nxtptr);
>
> static struct kmem_cache *req_cachep;
>
> @@ -712,9 +714,28 @@ static void __io_free_req(struct io_kiocb *req)
> kmem_cache_free(req_cachep, req);
> }
>
> +static bool io_link_cancel_timeout(struct io_ring_ctx *ctx,
> + struct io_kiocb *req)
> +{
> + int ret;
> +
> + ret = hrtimer_try_to_cancel(&req->timeout.timer);
> + if (ret != -1) {
> + io_cqring_fill_event(ctx, req->user_data, -ECANCELED);
> + io_commit_cqring(ctx);
> + req->flags &= ~REQ_F_LINK;
> + __io_free_req(req);
> + return true;
> + }
> +
> + return false;
> +}
> +
> static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
> {
> + struct io_ring_ctx *ctx = req->ctx;
> struct io_kiocb *nxt;
> + bool wake_ev = false;
>
> /*
> * The list should never be empty when we are called here. But could
> @@ -722,7 +743,7 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
> * safe side.
> */
> nxt = list_first_entry_or_null(&req->link_list, struct io_kiocb, list);
> - if (nxt) {
> + while (nxt) {
> list_del(&nxt->list);
> if (!list_empty(&req->link_list)) {
> INIT_LIST_HEAD(&nxt->link_list);
> @@ -734,11 +755,23 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
> * If we're in async work, we can continue processing the chain
> * in this context instead of having to queue up new async work.
> */
> - if (nxtptr && current_work())
> + if (req->flags & REQ_F_LINK_TIMEOUT) {
> + wake_ev = io_link_cancel_timeout(ctx, nxt);
> +
> + /* we dropped this link, get next */
> + nxt = list_first_entry_or_null(&req->link_list,
> + struct io_kiocb, list);
> + } else if (nxtptr && current_work()) {
> *nxtptr = nxt;
> - else
> + nxt = NULL;
Use 'break' is more better? no need to set variables and compare.
> + } else {
> io_queue_async_work(req->ctx, nxt);
> + nxt = NULL;
> + }
> }
--
BR, Jackie Liu
next prev parent reply other threads:[~2019-11-08 1:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-07 2:05 [PATCH v2] io_uring: add support for linked SQE timeouts Jens Axboe
2019-11-08 1:24 ` Jackie Liu [this message]
2019-11-08 2:12 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox