From: Simon Horman <horms@kernel.org>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: "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>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Jose E. Marchesi" <jose.marchesi@oracle.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
"Jason Baron" <jbaron@akamai.com>,
"Casey Schaufler" <casey@schaufler-ca.com>,
"Nathan Chancellor" <nathan@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 4/4] xsk: add helper to get &xdp_desc's DMA and meta pointer in one go
Date: Mon, 10 Feb 2025 21:06:45 +0000 [thread overview]
Message-ID: <20250210210645.GE554665@kernel.org> (raw)
In-Reply-To: <6d247107-5a9a-4ac7-8364-2619fce0c310@intel.com>
On Mon, Feb 10, 2025 at 05:00:36PM +0100, Alexander Lobakin wrote:
> From: Simon Horman <horms@kernel.org>
> Date: Sun, 9 Feb 2025 11:03:44 +0000
>
> > On Thu, Feb 06, 2025 at 07:26:29PM +0100, Alexander Lobakin wrote:
> >> Currently, when your driver supports XSk Tx metadata and you want to
> >> send an XSk frame, you need to do the following:
> >>
> >> * call external xsk_buff_raw_get_dma();
> >> * call inline xsk_buff_get_metadata(), which calls external
> >> xsk_buff_raw_get_data() and then do some inline checks.
> >>
> >> This effectively means that the following piece:
> >>
> >> addr = pool->unaligned ? xp_unaligned_add_offset_to_addr(addr) : addr;
> >>
> >> is done twice per frame, plus you have 2 external calls per frame, plus
> >> this:
> >>
> >> meta = pool->addrs + addr - pool->tx_metadata_len;
> >> if (unlikely(!xsk_buff_valid_tx_metadata(meta)))
> >>
> >> is always inlined, even if there's no meta or it's invalid.
> >>
> >> Add xsk_buff_raw_get_ctx() (xp_raw_get_ctx() to be precise) to do that
> >> in one go. It returns a small structure with 2 fields: DMA address,
> >> filled unconditionally, and metadata pointer, non-NULL only if it's
> >> present and valid. The address correction is performed only once and
> >> you also have only 1 external call per XSk frame, which does all the
> >> calculations and checks outside of your hotpath. You only need to
> >> check `if (ctx.meta)` for the metadata presence.
> >> To not copy any existing code, derive address correction and getting
> >> virtual and DMA address into small helpers. bloat-o-meter reports no
> >> object code changes for the existing functionality.
> >>
> >> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
> >
> > Hi Alexander,
> >
> > I think that this patch needs to be accompanied by at least one
> > patch that uses xsk_buff_raw_get_ctx() in a driver.
>
> This mini-series is the final part of my Chapter III, which was all
> about prereqs in order to add libeth_xdp and then XDP for idpf.
> This helper will be used in the next series (Chapter IV) I'll send once
> this lands.
Understood. If it's going to be used in chapter IV then, given
that we've made it to chapter II, that is fine by me.
> > Also, as this seems to be an optimisation, some performance data would
> > be nice too.
>
> -1 Kb of object code which has an unrolled-by-8 loop which used this
> function each iteration. I don't remember the perf numbers since it was
> a year ago and since then I've been using this helper only, but it was
> something around a couple procent (which is several hundred Kpps when it
> comes to XSk).
Thanks. It might be worth including some of that information in the commit
message, but I don't feel strongly about it.
>
> >
> > Which brings me to my last point. I'd always understood that
> > returning a struct was discouraged due to performance implications.
>
> Rather stack usage, not perf implications. Compound returns are used
> heavily throughout the kernel code when sizeof(result) <= 16 bytes.
> Here it's also 16 bytes. Just the same as one __u128. Plus this function
> doesn't recurse, so the stack won't blow up.
Also understood. It seems my assumptions were somewhat wrong.
So I have no objections to this approach.
> > Perhaps that information is out of date, doesn't apply because
> > the returned struct is so small in this case, or just plain wrong.
> > But I'd appreciate it if you could add some colour to this.
>
> Moreover, the function is global, not inline, so passing a pointer here
> instead of returning a struct may even behave worse in this case.
>
> (and we'll save basically only 8 bytes on the stack, which I don't
> believe is worth it).
>
> Thanks,
> Olek
>
next prev parent reply other threads:[~2025-02-10 21:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 18:26 [PATCH net-next 0/4] xsk: the lost bits from Chapter III Alexander Lobakin
2025-02-06 18:26 ` [PATCH net-next 1/4] unroll: add generic loop unroll helpers Alexander Lobakin
2025-02-09 11:07 ` Simon Horman
2025-02-10 12:28 ` Maciej Fijalkowski
2025-02-10 15:49 ` Alexander Lobakin
2025-02-10 21:08 ` Simon Horman
2025-02-11 1:56 ` Jakub Kicinski
2025-02-06 18:26 ` [PATCH net-next 2/4] i40e: use generic unrolled_count() macro Alexander Lobakin
2025-02-10 12:30 ` Maciej Fijalkowski
2025-02-10 22:28 ` David Laight
2025-02-06 18:26 ` [PATCH net-next 3/4] ice: " Alexander Lobakin
2025-02-10 12:31 ` Maciej Fijalkowski
2025-02-06 18:26 ` [PATCH net-next 4/4] xsk: add helper to get &xdp_desc's DMA and meta pointer in one go Alexander Lobakin
2025-02-09 11:03 ` Simon Horman
2025-02-10 16:00 ` Alexander Lobakin
2025-02-10 21:06 ` Simon Horman [this message]
2025-02-11 2:00 ` [PATCH net-next 0/4] xsk: the lost bits from Chapter III patchwork-bot+netdevbpf
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=20250210210645.GE554665@kernel.org \
--to=horms@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=casey@schaufler-ca.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jbaron@akamai.com \
--cc=john.fastabend@gmail.com \
--cc=jose.marchesi@oracle.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=toke@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).