All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: William Dauchy <wdauchy@gmail.com>
Cc: io-uring@vger.kernel.org
Subject: Re: io_uring_peek_cqe and EAGAIN
Date: Thu, 23 Apr 2020 09:05:50 -0600	[thread overview]
Message-ID: <fc04aedf-a417-de72-9ee4-6aa1dbf18226@kernel.dk> (raw)
In-Reply-To: <CAJ75kXY1VLoqab4quz8RykbFrbXNJVBSAf7jv4t+u0_OquE1cQ@mail.gmail.com>

On 4/23/20 8:42 AM, William Dauchy wrote:
> Hello Jens,
> 
> Thank you for your answer on this newbie question :)
> 
> On Wed, Apr 22, 2020 at 10:57 PM Jens Axboe <axboe@kernel.dk> wrote:
>> I don't think the change is correct. That's not saying that the original
>> code is necessarily correct, though! Basically there are two cases there:
>>
>> 1) We haven't gotten a completion yet, we'll wait for it.
>> 2) We already found at least one completion. We don't want
>>    to _wait_ for more, but we can peek and see if there are more.
>>
>> Hence we don't want to turn case 2 into a loop, we should just
>> continue.
> 
> ok so in fact I think I understand that my usage is incorrect:
> 1- if I'm in the case of being able to do other things while waiting
> for data available using `io_uring_peek_cqe`, I should use it and come
> back later when getting a -EAGAIN.
> 2- it is useless to do a loop on `io_uring_peek_cqe` because in that
> case, I should simply do a `io_uring_wait_cqe`
> 
> is that correct?

Right, you rarely want to busy loop on io_uring_peek_cqe(), the normal
use case would be to use io_uring_wait_cqe() if you need to wait for a
completion to become available.

>> How is it currently failing for you?
> 
> While trying to open/read/close multiple files, I first thought that,
> because I had one successful `io_uring_wait_cqe`, I could then loop on
> `io_uring_peek_cqe` and get all my data. I now realise my assumption
> was completely wrong and this example was just written that way to
> show two different possibilities of getting results.

Ah ok, yes that sounds like a misunderstanding. Events are posted as
they become available, availability of one does not mean that everything
has completed.

-- 
Jens Axboe


  reply	other threads:[~2020-04-23 15:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20 16:27 io_uring_peek_cqe and EAGAIN William Dauchy
2020-04-22 20:57 ` Jens Axboe
2020-04-23 14:42   ` William Dauchy
2020-04-23 15:05     ` Jens Axboe [this message]
2020-04-23 15:12       ` William Dauchy

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 \
    --in-reply-to=fc04aedf-a417-de72-9ee4-6aa1dbf18226@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=wdauchy@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.