All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Eric Dumazet' <edumazet@google.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, netdev <netdev@vger.kernel.org>
Subject: RE: [PATCH net-next 2/2] net: optimize skb_postpull_rcsum()
Date: Thu, 25 Nov 2021 14:29:14 +0000	[thread overview]
Message-ID: <58ea0edf987e47ea9795b03e70f58d9a@AcuMS.aculab.com> (raw)
In-Reply-To: <CANn89i+HmN3DbfAtH+Uq_pBWYHXp5ioH8LyhGRAiHZhRLbs1nw@mail.gmail.com>

There is another optimisation you can do that removes a conditional
from the end of the checksum generation.

The 'adc' sum is reduced to 16 bits leaving a value [1..0xffff].
This is then inverted to get the checksum, but the range is
then [0..0xfffe].
So 0 then has to be converted to 0xffff.

If you add 1 to thw inut checksum one of the csum_partial() calls
the adc sum is one too big, so the inverted value is one too small.
Adding 1 to the inverted value fixes this and leaves a checksum
in the correct range.

Potentially the invert+increment can be done as a negate prior
to the final masking with 0xffff.
(Which the compiler may well sort out for you.)

You do need to know 'early' that the checksum is going to get
inverted - or too many places might add in the extra 'one'.

On 64bit systems the 'input checksum' to csum_partial() can
(almost certainly) be made a long - with a proviso that the
value must not exceed 2**56 because the function might want
to add a partial word to it.

I'm also not sure how well any of this runs on mips-like cpu
that don't have a carry flag (I think this includes riscV).
On 64bit cpu it may be best to add 32bit values to 64bit registers.

With 2 memory read ports it is even possibly that an x86 cpu
can do 8 bytes/clock by adding 32 bit values to two registers.
However the reads would have to be aligned and arranged to
avoid cache bank conflicts.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2021-11-25 14:31 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 20:24 [PATCH net-next 0/2] net: small csum optimizations Eric Dumazet
2021-11-24 20:24 ` [PATCH net-next 1/2] gro: optimize skb_gro_postpull_rcsum() Eric Dumazet
2021-11-24 20:24 ` [PATCH net-next 2/2] net: optimize skb_postpull_rcsum() Eric Dumazet
2021-11-25  9:41   ` David Laight
2021-11-25 13:32     ` Eric Dumazet
2021-11-25 14:29       ` David Laight [this message]
2021-12-02 13:10   ` Vladimir Oltean
2021-12-02 14:51     ` Eric Dumazet
2021-12-02 16:29       ` Vladimir Oltean
2021-12-02 19:32         ` Eric Dumazet
2021-12-02 20:37           ` Eric Dumazet
2021-12-02 21:07             ` Vladimir Oltean
2021-12-02 20:40           ` Vladimir Oltean
2021-12-02 20:58             ` Vladimir Oltean
2021-12-02 20:58             ` David Laight
2021-12-02 21:40               ` Vladimir Oltean
2021-12-03 14:51                 ` David Laight
2021-12-03 14:57                 ` David Laight
2021-12-03 16:14                   ` Vladimir Oltean
2021-12-03 16:30                     ` Eric Dumazet
2021-12-03 16:47                       ` David Laight
2021-12-03 16:58                         ` Eric Dumazet
2021-12-03 17:41                           ` David Laight
2021-12-02 15:06     ` David Laight
2021-12-02 15:22       ` Eric Dumazet
2021-11-26  5:20 ` [PATCH net-next 0/2] net: small csum optimizations 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=58ea0edf987e47ea9795b03e70f58d9a@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.