public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Pavel Begunkov <[email protected]>, [email protected]
Subject: Re: [PATCH 2/5] io_uring: serialize ctx->rings->sq_flags with cmpxchg()
Date: Sat, 23 Apr 2022 07:28:00 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 4/23/22 7:07 AM, Jens Axboe wrote:
> On 4/23/22 2:06 AM, Pavel Begunkov wrote:
>> On 4/22/22 22:42, Jens Axboe wrote:
>>> Rather than require ctx->completion_lock for ensuring that we don't
>>> clobber the flags, use try_cmpxchg() instead. This removes the need
>>> to grab the completion_lock, in preparation for needing to set or
>>> clear sq_flags when we don't know the status of this lock.
>>>
>>> Signed-off-by: Jens Axboe <[email protected]>
>>> ---
>>>   fs/io_uring.c | 54 ++++++++++++++++++++++++++++++---------------------
>>>   1 file changed, 32 insertions(+), 22 deletions(-)
>>>
>>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>>> index 626bf840bed2..38e58fe4963d 100644
>>> --- a/fs/io_uring.c
>>> +++ b/fs/io_uring.c
>>> @@ -1999,6 +1999,34 @@ static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx)
>>>           io_cqring_wake(ctx);
>>>   }
>>>   +static void io_ring_sq_flag_clear(struct io_ring_ctx *ctx, unsigned int flag)
>>> +{
>>> +    struct io_rings *rings = ctx->rings;
>>> +    unsigned int oldf, newf;
>>> +
>>> +    do {
>>> +        oldf = READ_ONCE(rings->sq_flags);
>>> +
>>> +        if (!(oldf & flag))
>>> +            break;
>>> +        newf = oldf & ~flag;
>>> +    } while (!try_cmpxchg(&rings->sq_flags, &oldf, newf));
>>> +}
>>> +
>>> +static void io_ring_sq_flag_set(struct io_ring_ctx *ctx, unsigned int flag)
>>> +{
>>> +    struct io_rings *rings = ctx->rings;
>>> +    unsigned int oldf, newf;
>>> +
>>> +    do {
>>> +        oldf = READ_ONCE(rings->sq_flags);
>>> +
>>> +        if (oldf & flag)
>>> +            break;
>>> +        newf = oldf | flag;
>>> +    } while (!try_cmpxchg(&rings->sq_flags, &oldf, newf));
>>> +}
>>
>> atomic and/or might be a better fit
> 
> That would indeed be great, but the type is fixed. Not sure if all archs
> end up with a plain int as the type?

Looks like it actually is defined generically, so this could work.

-- 
Jens Axboe


  reply	other threads:[~2022-04-23 13:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 21:42 [PATCHSET next 0/5] Add support for non-IPI task_work Jens Axboe
2022-04-22 21:42 ` [PATCH 1/5] task_work: allow TWA_SIGNAL without a rescheduling IPI Jens Axboe
2022-04-22 21:42 ` [PATCH 2/5] io_uring: serialize ctx->rings->sq_flags with cmpxchg() Jens Axboe
2022-04-23  8:06   ` Pavel Begunkov
2022-04-23 13:07     ` Jens Axboe
2022-04-23 13:28       ` Jens Axboe [this message]
2022-04-22 21:42 ` [PATCH 3/5] io-wq: use __set_notify_signal() to wake workers Jens Axboe
2022-04-22 21:42 ` [PATCH 4/5] io_uring: set task_work notify method at init time Jens Axboe
2022-04-22 21:42 ` [PATCH 5/5] io_uring: use TWA_SIGNAL_NO_IPI if IORING_SETUP_NO_RESCHED is used 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