From: David Laight <david.laight.linux@gmail.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: torvalds@linux-foundation.org, mingo@redhat.com, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] x86: prevent gcc from emitting rep movsq/stosq for inlined ops
Date: Wed, 2 Apr 2025 23:29:17 +0100 [thread overview]
Message-ID: <20250402232917.6978ffa3@pumpkin> (raw)
In-Reply-To: <xmzxiwno5q3ordgia55wyqtjqbefxpami5wevwltcto52fehbv@ul44rsesp4kw>
On Wed, 2 Apr 2025 15:42:40 +0200
Mateusz Guzik <mjguzik@gmail.com> wrote:
> Not a real submission yet as I would like results from other people.
>
> tl;dr when benchmarking compilation of a hello-world program I'm getting
> a 1.7% increase in throughput on Sapphire Rapids when convincing the
> compiler to only use regular stores for inlined memset and memcpy
>
> Note this uarch does have FSRM and still benefits from not using it for
> some cases.
>
> I am not in position to bench this on other CPUs, would be nice if
> someone did it on AMD.
I did some benchmarking of 'rep movsb' on a zen 5.
Test is: mfence; rdpmc; mfence; test_code; mfence; rdpmc; mfence.
For large copies you get 64 bytes/clock.
Short copies (less than 128 bytes) are usually very cheap - maybe 5 clocks
But it then jumps to 38 clocks.
And the 'elephant in the room' is when (dest - src) % 4096 is between 1 and 63.
In that case short copies jump to 55 clocks.
Otherwise alignment doesn't make much difference.
If those values are right you want to use 'rep movsb' for short copies,
but probably not for ones between 128 and 256 bytes!
I might need to run with an inner loop.
The overhead for an empty test (an asm block with "nop" instead of "rep movsb")
is 180 clocks (and subtracted from the above clock counts).
But I've used the same scheme for 'normal' instructions (testing ipcsum)
and got sane results.
David
next prev parent reply other threads:[~2025-04-02 22:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 13:42 [RFC PATCH] x86: prevent gcc from emitting rep movsq/stosq for inlined ops Mateusz Guzik
2025-04-02 16:21 ` Linus Torvalds
2025-04-02 16:27 ` Mateusz Guzik
2025-04-02 18:17 ` Andrew Cooper
2025-04-02 18:22 ` Peter Zijlstra
2025-04-02 18:29 ` Linus Torvalds
2025-04-02 18:40 ` Andrew Cooper
2025-04-02 18:56 ` Linus Torvalds
2025-04-02 23:39 ` Mateusz Guzik
2025-04-13 10:27 ` Mateusz Guzik
2025-04-13 18:20 ` David Laight
2025-04-13 18:58 ` Mateusz Guzik
2025-04-02 22:29 ` David Laight [this message]
2025-04-02 23:15 ` Mateusz Guzik
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=20250402232917.6978ffa3@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mjguzik@gmail.com \
--cc=torvalds@linux-foundation.org \
--cc=x86@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.