[PATCH 2/2] x86: Enable ERMS memset for AMD Zen5/Zen6 servers
Sajan Karumanchi
sajan.karumanchi@gmail.com
Fri Nov 13 12:43:36 GMT 2026
Following the ERMS enablement for memcpy/memmove on AMD Zen5+ servers,
microcode improvements also make REP STOSB outperform vectorized memset
for buffers 32KB and larger.
Extend the Zen5+ server ERMS tuning to memset by lowering the default
rep_stosb_threshold from SIZE_MAX to 32KB when Prefer_Server_ERMS is set.
In addition, enable Avoid_Non_Temporal_Memset on these server models so
large memsets remain on ERMS, which edges out non-temporal stores.
Performance improvements:
- Range: [32KB, SIZE_MAX]
- Improvement: 9% to 43%
Co-authored-by: Sundari Swathy Meena H <sundari.swathymeenah@amd.com>
Reviewed-by: Ganesh Gopalasubramanian <Ganesh.Gopalasubramanian@amd.com>
---
sysdeps/x86/cpu-features.c | 9 +++++++--
sysdeps/x86/dl-cacheinfo.h | 13 ++++++++++---
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index bdd8ddb9ab..ac191ae7a5 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -1069,8 +1069,13 @@ disable_tsx:
|| (model >= 0x90 && model <= 0x9B)
|| (model >= 0xA0 && model <= 0xAB)
|| (model >= 0xC0 && model <= 0xCF))
- cpu_features->preferred[index_arch_Prefer_Server_ERMS]
- |= bit_arch_Prefer_Server_ERMS;
+ {
+ cpu_features->preferred[index_arch_Prefer_Server_ERMS]
+ |= bit_arch_Prefer_Server_ERMS;
+ /* Avoid non-temporal stores for memset on these models. */
+ cpu_features->preferred[index_arch_Avoid_Non_Temporal_Memset]
+ |= bit_arch_Avoid_Non_Temporal_Memset;
+ }
}
if (CPU_FEATURE_USABLE_P (cpu_features, AVX))
diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h
index 3fd7c77bc1..8a470421b5 100644
--- a/sysdeps/x86/dl-cacheinfo.h
+++ b/sysdeps/x86/dl-cacheinfo.h
@@ -1325,9 +1325,16 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
long int, NULL);
if (cpu_features->basic.kind == arch_kind_amd
&& !TUNABLE_IS_INITIALIZED (x86_rep_stosb_threshold))
- /* For AMD Zen3+ architecture, the performance of the vectorized loop is
- slightly better than ERMS. */
- rep_stosb_threshold = SIZE_MAX;
+ {
+ /* Setting erms:rep-stosb lower bound threshold to 32KB
+ for AMD Zen5+ server-class models. */
+ if (CPU_FEATURES_ARCH_P (cpu_features, Prefer_Server_ERMS))
+ rep_stosb_threshold = 32 * 1024;
+ else
+ /* For AMD Zen3+ architecture, the performance of the vectorized
+ loop is slightly better than ERMS. */
+ rep_stosb_threshold = SIZE_MAX;
+ }
/*
For memset, the non-temporal implementation is only accessed through the
--
2.34.1
More information about the Libc-alpha
mailing list