[glibc] x86: Lower non-temporal copy threshold for Hygon

Adhemerval Zanella via Glibc-cvs <[email protected]> Mon, 18 May 2026 16:34:32 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=08e963f675d017ae8d64bd7191bcb2183201211c

commit 08e963f675d017ae8d64bd7191bcb2183201211c
Author: xiejiamei <[email protected]>
Date:   Sat May 9 14:23:09 2026 +0800

    x86: Lower non-temporal copy threshold for Hygon
    
    Benchmarks on Hygon processors show that the default non-temporal
    threshold is higher than ideal for large copy workloads. As a result,
    memcpy and memmove may continue to use the temporal copy path for
    longer than is beneficial, increasing cache pollution and reducing
    throughput for large copies.
    
    Lower the copy non-temporal threshold to 3/8 of the shared cache size
    per thread on Hygon. This allows the non-temporal copy path to be
    selected earlier while leaving the memset non-temporal threshold
    unchanged.
    
    Signed-off-by: xiejiamei <[email protected]>

Diff:
---
 sysdeps/x86/dl-cacheinfo.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h
index b6e17b0e32..84817a84fd 100644
--- a/sysdeps/x86/dl-cacheinfo.h
+++ b/sysdeps/x86/dl-cacheinfo.h
@@ -1244,6 +1244,13 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
   if (!CPU_FEATURES_ARCH_P (cpu_features, Avoid_Non_Temporal_Memset))
     memset_non_temporal_threshold = non_temporal_threshold;
 
+  /* Hygon benefits from entering the non-temporal copy path earlier.
+     Use 3/8 of the shared cache size per thread to reduce cache
+     pollution and improve throughput for large copies. Keep the memset
+     non-temporal threshold unchanged.  */
+  if (cpu_features->basic.kind == arch_kind_hygon)
+    non_temporal_threshold = shared_per_thread * 3 / 8;
+
   tunable_size = TUNABLE_GET (x86_non_temporal_threshold, long int, NULL);
   if (tunable_size > minimum_non_temporal_threshold
       && tunable_size <= maximum_non_temporal_threshold)