DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Scott Mitchell" <scott.k.mitch1@gmail.com>
Cc: <dev@dpdk.org>, <stephen@networkplumber.org>
Subject: RE: [PATCH v11] net: optimize raw checksum computation
Date: Fri, 9 Jan 2026 16:58:04 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F6563C@smartserver.smartshare.dk> (raw)
In-Reply-To: <CAFn2buDULHpj-5m1TXEcp0xUfMpTA9dKqEuEC98UhDp4qW21og@mail.gmail.com>

> From: Scott Mitchell [mailto:scott.k.mitch1@gmail.com]
> Sent: Friday, 9 January 2026 16.27
> 
> On Fri, Jan 9, 2026 at 4:26 AM Morten Brørup <mb@smartsharesystems.com>
> wrote:
> >
> > > Changes in v8:
> > > - __rte_raw_cksum: use native pointer arithmetic instead of
> RTE_PTR_ADD
> > >   to avoid incorrect results with -O3 for UDP checksums. Also
> improves
> > >   performance due to less assembly generated with Clang.
> >
> > Personally, I also have observed GCC's optimizer behave as if it
> loses some contextual information when using RTE_PTR_ADD, and thus
> emitting less optimal code.
> > I didn't look further into it, and thus have no data or examples to
> back up the claim. Which is why I haven't started a discussion about
> discouraging the use of RTE_PTR_ADD.
> > In other words: I support this change.
> 
> Sounds good! I observed ~600 (dpdk ptr macros) vs ~500 (native c ptr
> operations) TSC cycles/block in cksum_perf_autotest.

That is a significant performance degradation caused by the RTE_PTR_ADD() macros. We really should look into that - some day. ;-)
Our application code base has RTE_CONST_PTR_ADD/SUB() for type consistency reasons (not for performance reasons). But I haven't gotten around to submitting them to the DPDK project yet.
I wonder if the implicit stripping of "const" when using the RTE_PTR_ADD() macros makes the difference, or if the difference stems from other optimizer context getting lost.

> 
> >
> > >       /* if length is odd, keeping it byte order independent */
> > > -     if (unlikely(len % 2)) {
> > > +     if (len & 1) {
> > >               uint16_t left = 0;
> > > -
> > >               memcpy(&left, end, 1);
> > >               sum += left;
> > >       }
> >
> > Changing "len % 2" to "len & 1" made sense for consistency in
> previous versions handling 32/16/8/4/2-byte chunks before this 1-byte
> chunk; now it makes no difference, so consider not changing this part
> at all.
> > Under all circumstances, don't remove the unlikely() for handling odd
> length in __rte_raw_cksum(). The vast majority of packets (and partial
> packets, e.g. headers) being checksummed are even length.
> >
> 
> Sounds good. I will restore the original.
> 
> The use case that motivated these changes was software interfaces
> (veth)
> with encapsulation requiring software checksum on inner IPv4 payloads,
> where lengths may be odd/even.

You might want to mention the use case in the cover letter or patch description.
Having a real use case often helps getting a patch accepted, especially for optimization patches.

> However, I agree that header checksums
> with even lengths are the more common case and unlikely() is
> appropriate.

In my experience (and based on statistics from our appliances deployed), internet traffic is dominated by "max size" (1500 byte or QUIC "safe max" somewhat below 1500 byte) packets and empty TCP ACK packets, which are even size.
So I also consider the unlikely()applicable to "real life" traffic on the internet.
Although it's not in the order of magnitude many people advocate should be a requirement for unlikely().


  reply	other threads:[~2026-01-09 15:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 23:05 scott.k.mitch1
2026-01-09  0:44 ` Scott Mitchell
2026-01-09  9:26 ` Morten Brørup
2026-01-09 15:27   ` Scott Mitchell
2026-01-09 15:58     ` Morten Brørup [this message]
2026-01-09 17:23       ` Scott Mitchell
2026-01-09 22:12     ` Morten Brørup
2026-01-10  4:19       ` Scott Mitchell
2026-01-09 18:28 ` Morten Brørup
2026-01-10  3:41   ` Scott Mitchell

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=98CBD80474FA8B44BF855DF32C47DC35F6563C@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    --cc=scott.k.mitch1@gmail.com \
    --cc=stephen@networkplumber.org \
    /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).