From: Heiner Kallweit <hkallweit1@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
pabeni@redhat.com, Alexander Duyck <alexander.duyck@gmail.com>
Subject: Re: [PATCH net-next 1/3] net: provide macros for commonly copied lockless queue stop/wake code
Date: Sat, 1 Apr 2023 22:41:55 +0200 [thread overview]
Message-ID: <4ba26f4a-4bdb-1852-7406-6f6f723986ad@gmail.com> (raw)
In-Reply-To: <20230401115854.371a5b4c@kernel.org>
On 01.04.2023 20:58, Jakub Kicinski wrote:
> On Sat, 1 Apr 2023 17:18:12 +0200 Heiner Kallweit wrote:
>>> +#define __netif_tx_queue_maybe_wake(txq, get_desc, start_thrs, down_cond) \
>>> + ({ \
>>> + int _res; \
>>> + \
>>> + _res = -1; \
>>
>> One more question: Don't we need a read memory barrier here to ensure
>> get_desc is up-to-date?
>
> CC: Alex, maybe I should not be posting after 10pm, with the missing v2
> and sparse CC list.. :|
>
> I was thinking about this too yesterday. AFAICT this implementation
> could indeed result in waking even tho the queue is full on non-x86.
> That's why the drivers have an extra check at the start of .xmit? :(
>
> I *think* that the right ordering would be:
>
> WRITE cons
> mb() # A
> READ stopped
> rmb() # C
> READ prod, cons
>
> And on the producer side (existing):
>
> WRITE prod
> READ prod, cons
> mb() # B
> WRITE stopped
> READ prod, cons
>
> But I'm slightly afraid to change it, it's been working for over
> a decade :D
>
> One neat thing that I noticed, which we could potentially exploit
> if we were to touch this code is that BQL already has a smp_mb()
> on the consumer side. So on any kernel config and driver which support
> BQL we can use that instead of adding another barrier at #A.
>
To me it seems ixgbe relies on this BQL-related barrier in
netdev_tx_completed_queue, maybe unintentionally.
I wonder whether we should move the smp_mb() from __netif_tx_queue_try_wake
to __netif_tx_queue_maybe_wake, before accessing get_desc.
Answer may depend on whether there's any use case where drivers would
call the "try" version directly, instead of the "may" version.
And, just thinking out loud, maybe add a flag to the macro to disable
the smp_mb() call, for cases where the driver has the required barrier
already. Setting this flag may look like this.
bool disable_barrier_in_may_wake = IS_ENABLED(CONFIG_BQL);
However this is quite some effort just to avoid a duplicated barrier.
> It would actually be a neat optimization because right now, AFAICT,
> completion will fire the # A -like barrier almost every time.
>
>>> + if (likely(get_desc > start_thrs)) \
>>> + _res = __netif_tx_queue_try_wake(txq, get_desc, \
>>> + start_thrs, \
>>> + down_cond); \
>>> + _res; \
>>> + })
next prev parent reply other threads:[~2023-04-01 20:42 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-01 5:12 [PATCH net-next 0/3] net: provide macros for commonly copied lockless queue stop/wake code Jakub Kicinski
2023-04-01 5:12 ` [PATCH net-next 1/3] " Jakub Kicinski
2023-04-01 15:04 ` Heiner Kallweit
2023-04-01 18:03 ` Jakub Kicinski
2023-04-01 15:18 ` Heiner Kallweit
2023-04-01 18:58 ` Jakub Kicinski
2023-04-01 20:41 ` Heiner Kallweit [this message]
2023-04-03 15:18 ` Alexander Duyck
2023-04-03 15:56 ` Jakub Kicinski
2023-04-03 18:11 ` Alexander Duyck
2023-04-03 19:03 ` Jakub Kicinski
2023-04-03 20:27 ` Alexander Duyck
2023-04-05 22:20 ` Paul E. McKenney
2023-04-06 5:15 ` Herbert Xu
2023-04-06 14:17 ` Paul E. McKenney
2023-04-06 14:46 ` Jakub Kicinski
2023-04-06 15:45 ` Paul E. McKenney
2023-04-06 15:56 ` Jakub Kicinski
2023-04-06 16:25 ` Paul E. McKenney
2023-04-07 0:58 ` Herbert Xu
2023-04-07 1:03 ` Jakub Kicinski
2023-04-07 1:14 ` Herbert Xu
2023-04-07 1:21 ` Jakub Kicinski
2023-04-04 6:39 ` Herbert Xu
2023-04-04 22:36 ` Jakub Kicinski
2023-04-01 5:12 ` [PATCH net-next 2/3] ixgbe: use new queue try_stop/try_wake macros Jakub Kicinski
2023-04-01 5:12 ` [PATCH net-next 3/3] bnxt: " Jakub Kicinski
2023-04-01 18:35 ` Michael Chan
-- strict thread matches above, loose matches on Subject: below --
2023-03-22 23:30 [PATCH net-next 1/3] net: provide macros for commonly copied lockless queue stop/wake code Jakub Kicinski
2023-03-23 0:35 ` Andrew Lunn
2023-03-23 1:04 ` Jakub Kicinski
2023-03-23 21:02 ` Andrew Lunn
2023-03-23 22:46 ` Jakub Kicinski
2023-03-23 3:05 ` Yunsheng Lin
2023-03-23 3:27 ` Jakub Kicinski
2023-03-23 4:53 ` Pavan Chebbi
2023-03-23 5:08 ` Jakub Kicinski
2023-03-23 16:05 ` Alexander H Duyck
2023-03-24 3:09 ` Jakub Kicinski
2023-03-24 15:45 ` Alexander Duyck
2023-03-24 21:28 ` Jakub Kicinski
2023-03-26 21:23 ` Alexander Duyck
2023-03-29 0:56 ` Jakub Kicinski
2023-03-30 14:56 ` Paolo Abeni
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=4ba26f4a-4bdb-1852-7406-6f6f723986ad@gmail.com \
--to=hkallweit1@gmail.com \
--cc=alexander.duyck@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 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).