From: Stephen Hemminger <stephen@networkplumber.org>
To: scott.k.mitch1@gmail.com
Cc: dev@dpdk.org, mb@smartsharesystems.com
Subject: Re: [PATCH v9] net: optimize raw checksum computation
Date: Thu, 8 Jan 2026 21:39:16 -0800 [thread overview]
Message-ID: <20260108213916.618cb75a@phoenix.local> (raw)
In-Reply-To: <20260108214713.52987-1-scott.k.mitch1@gmail.com>
On Thu, 8 Jan 2026 16:47:13 -0500
scott.k.mitch1@gmail.com wrote:
> diff --git a/lib/net/rte_ip6.h b/lib/net/rte_ip6.h
> index d1abf1f5d5..8a7e5e4b8a 100644
> --- a/lib/net/rte_ip6.h
> +++ b/lib/net/rte_ip6.h
> @@ -560,19 +560,18 @@ rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
> static inline uint16_t
> rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
> {
> - uint32_t sum;
> struct {
> rte_be32_t len; /* L4 length. */
> rte_be32_t proto; /* L4 protocol - top 3 bytes must be zero */
> - } psd_hdr;
> -
> - psd_hdr.proto = (uint32_t)(ipv6_hdr->proto << 24);
> - if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
> - psd_hdr.len = 0;
> - else
> - psd_hdr.len = ipv6_hdr->payload_len;
> + } psd_hdr = {
> + .len = (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
> + ? (rte_be32_t)0
> + : ipv6_hdr->payload_len,
> + .proto = (uint32_t)(ipv6_hdr->proto << 24)
> + };
> + RTE_SUPPRESS_UNINITIALIZED_WARNING(psd_hdr);
>
> - sum = __rte_raw_cksum(&ipv6_hdr->src_addr,
> + uint32_t sum = __rte_raw_cksum(&ipv6_hdr->src_addr,
> sizeof(ipv6_hdr->src_addr) + sizeof(ipv6_hdr->dst_addr),
> 0);
> sum = __rte_raw_cksum(&psd_hdr, sizeof(psd_hdr), sum);
> --
Seems like this could be unrolled as well.
static inline uint16_t
rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
{
union {
struct {
struct rte_ipv6_addr src_addr; /* 16 bytes */
struct rte_ipv6_addr dst_addr; /* 16 bytes */
rte_be32_t len; /* 4 bytes */
rte_be32_t proto; /* 4 bytes */
} psd;
uint16_t u16[20];
} hdr = {
.psd = {
.src_addr = ipv6_hdr->src_addr,
.dst_addr = ipv6_hdr->dst_addr,
.proto = (uint32_t)(ipv6_hdr->proto << 24),
}
};
uint32_t sum;
if (!(ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)))
hdr.psd.len = ipv6_hdr->payload_len;
/* Unrolled sum of 20 uint16_t words:
* [0-7]: src_addr
* [8-15]: dst_addr
* [16-17]: len
* [18-19]: proto (3 zero bytes + next header)
*/
sum = hdr.u16[0] + hdr.u16[1] + hdr.u16[2] + hdr.u16[3] +
hdr.u16[4] + hdr.u16[5] + hdr.u16[6] + hdr.u16[7] +
hdr.u16[8] + hdr.u16[9] + hdr.u16[10] + hdr.u16[11] +
hdr.u16[12] + hdr.u16[13] + hdr.u16[14] + hdr.u16[15] +
hdr.u16[16] + hdr.u16[17] + hdr.u16[18] + hdr.u16[19];
sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16);
return (uint16_t)sum;
}
next prev parent reply other threads:[~2026-01-09 5:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 21:47 scott.k.mitch1
2026-01-09 5:34 ` Stephen Hemminger
2026-01-09 5:36 ` Stephen Hemminger
2026-01-09 5:39 ` Stephen Hemminger [this message]
2026-01-09 17:50 ` Scott Mitchell
2026-01-10 3:46 ` 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=20260108213916.618cb75a@phoenix.local \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=scott.k.mitch1@gmail.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).