public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeed@kernel.org>
To: Caleb Sander <csander@purestorage.com>
Cc: Parav Pandit <parav@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next 2/2] mlx5/core: deduplicate {mlx5_,}eq_update_ci()
Date: Wed, 6 Nov 2024 18:36:08 -0800	[thread overview]
Message-ID: <ZywnmDQIxzgV3uJe@x130> (raw)
In-Reply-To: <CADUfDZon6QbURp7TqB6dvE4Ewb_To2EDyUTQ=spNCorXDy0DbQ@mail.gmail.com>

On 06 Nov 15:44, Caleb Sander wrote:
>On Tue, Nov 5, 2024 at 9:44 PM Parav Pandit <parav@nvidia.com> wrote:
>>
>>
>> > From: Caleb Sander <csander@purestorage.com>
>> > Sent: Tuesday, November 5, 2024 9:36 PM
>> >
>> > On Mon, Nov 4, 2024 at 9:22 PM Parav Pandit <parav@nvidia.com> wrote:
>> > >
>> > >
>> > >
>> > > > From: Caleb Sander <csander@purestorage.com>
>> > > > Sent: Monday, November 4, 2024 3:49 AM
>> > > >
>> > > > On Sat, Nov 2, 2024 at 8:55 PM Parav Pandit <parav@nvidia.com> wrote:
>> > > > >
>> > > > >
>> > > > >
>> > > > > > From: Caleb Sander Mateos <csander@purestorage.com>
>> > > > > > Sent: Friday, November 1, 2024 9:17 AM
>> > > > > >
>> > > > > > The logic of eq_update_ci() is duplicated in mlx5_eq_update_ci().
>> > > > > > The only additional work done by mlx5_eq_update_ci() is to
>> > > > > > increment
>> > > > > > eq->cons_index. Call eq_update_ci() from mlx5_eq_update_ci() to
>> > > > > > eq->avoid
>> > > > > > the duplication.
>> > > > > >
>> > > > > > Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
>> > > > > > ---
>> > > > > >  drivers/net/ethernet/mellanox/mlx5/core/eq.c | 9 +--------
>> > > > > >  1 file changed, 1 insertion(+), 8 deletions(-)
>> > > > > >
>> > > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
>> > > > > > b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
>> > > > > > index 859dcf09b770..078029c81935 100644
>> > > > > > --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
>> > > > > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
>> > > > > > @@ -802,19 +802,12 @@ struct mlx5_eqe *mlx5_eq_get_eqe(struct
>> > > > > > mlx5_eq *eq, u32 cc)  }  EXPORT_SYMBOL(mlx5_eq_get_eqe);
>> > > > > >
>> > > > > >  void mlx5_eq_update_ci(struct mlx5_eq *eq, u32 cc, bool arm)  {
>> > > > > > -     __be32 __iomem *addr = eq->doorbell + (arm ? 0 : 2);
>> > > > > > -     u32 val;
>> > > > > > -
>> > > > > >       eq->cons_index += cc;
>> > > > > > -     val = (eq->cons_index & 0xffffff) | (eq->eqn << 24);
>> > > > > > -
>> > > > > > -     __raw_writel((__force u32)cpu_to_be32(val), addr);
>> > > > > > -     /* We still want ordering, just not swabbing, so add a barrier */
>> > > > > > -     wmb();
>> > > > > > +     eq_update_ci(eq, arm);
>> > > > > Long ago I had similar rework patches to get rid of
>> > > > > __raw_writel(), which I never got chance to push,
>> > > > >
>> > > > > Eq_update_ci() is using full memory barrier.
>> > > > > While mlx5_eq_update_ci() is using only write memory barrier.
>> > > > >
>> > > > > So it is not 100% deduplication by this patch.
>> > > > > Please have a pre-patch improving eq_update_ci() to use wmb().
>> > > > > Followed by this patch.
>> > > >
>> > > > Right, patch 1/2 in this series is changing eq_update_ci() to use
>> > > > writel() instead of __raw_writel() and avoid the memory barrier:
>> > > > https://lore.kernel.org/lkml/20241101034647.51590-1-
>> > > > csander@purestorage.com/
>> > > This patch has two bugs.
>> > > 1. writel() writes the MMIO space in LE order. EQ updates are in BE order.
>> > > So this will break on ppc64 BE.
>> >
>> > Okay, so this should be writel(cpu_to_le32(val), addr)?
>> >
>> That would break the x86 side because device should receive in BE format regardless of cpu endianness.
>> Above code will write in the LE format.
>>
>> So an API foo_writel() need which does
>> a. write memory barrier
>> b. write to MMIO space but without endineness conversion.
>
>Got it, thanks. writel(bswap_32(val, addr)) should work, then? I
>suppose it may introduce a second bswap on BE architectures, but
>that's probably worth it to avoid the memory barrier.
>

The existing mb() needs to be changed to wmb(), this will provide a more
efficient fence on most architectures.

I don't understand why you are still discussing the use of writel(), yes
it will work but you are introducing two unconditional swaps per doorbell
write.

Just replace the existing mb with wmb() in eq_update_ci()

And if you have time to write one extra patch, please reuse eq_update_ci() 
inside mlx5_eq_update_ci(). 

mlx5_eq_update_ci(eq, cc, arm) {
        eq->cons_index += cc;
        eq_update_ci(eq, arm);
}

So we won't have two different implementations of EQ doorbell ringing
anymore.

Thanks,
Saeed.


  reply	other threads:[~2024-11-07  2:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01  3:46 [PATCH net-next 1/2] mlx5/core: avoid memory barrier in eq_update_ci() Caleb Sander Mateos
2024-11-01  3:46 ` [PATCH net-next 2/2] mlx5/core: deduplicate {mlx5_,}eq_update_ci() Caleb Sander Mateos
2024-11-03  3:55   ` Parav Pandit
2024-11-03 22:18     ` Caleb Sander
2024-11-05  5:22       ` Parav Pandit
2024-11-05 16:06         ` Caleb Sander
2024-11-06  5:44           ` Parav Pandit
2024-11-06 23:44             ` Caleb Sander
2024-11-07  2:36               ` Saeed Mahameed [this message]
2024-11-07  2:43                 ` Parav Pandit
2024-11-07  4:45                 ` Caleb Sander
2024-11-07  5:14                   ` Saeed Mahameed
2024-11-07 18:30                     ` [PATCH net-next v2 1/2] mlx5/core: relax memory barrier in eq_update_ci() Caleb Sander Mateos
2024-11-07 18:30                       ` [PATCH net-next v2 2/2] mlx5/core: deduplicate {mlx5_,}eq_update_ci() Caleb Sander Mateos
2024-11-08 10:49                         ` Parav Pandit
2024-11-11 11:59                           ` Tariq Toukan
2024-11-08 10:46                       ` [PATCH net-next v2 1/2] mlx5/core: relax memory barrier in eq_update_ci() Parav Pandit
2024-11-11 11:59                         ` Tariq Toukan
2024-11-12  2:38                       ` Jakub Kicinski

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=ZywnmDQIxzgV3uJe@x130 \
    --to=saeed@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=csander@purestorage.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.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