076f82
commit 6e008c884dad5a25f91085c68d044bb5e2d63761
076f82
Author: Noah Goldstein <goldstein.w.n@gmail.com>
076f82
Date:   Tue Jun 14 13:50:11 2022 -0700
076f82
076f82
    x86: Fix misordered logic for setting `rep_movsb_stop_threshold`
076f82
    
076f82
    Move the setting of `rep_movsb_stop_threshold` to after the tunables
076f82
    have been collected so that the `rep_movsb_stop_threshold` (which
076f82
    is used to redirect control flow to the non_temporal case) will
076f82
    use any user value for `non_temporal_threshold` (set using
076f82
    glibc.cpu.x86_non_temporal_threshold)
076f82
    
076f82
    (cherry picked from commit 035591551400cfc810b07244a015c9411e8bff7c)
076f82
076f82
diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h
076f82
index 2e43e67e4f4037d3..560bf260e8fbd7bf 100644
076f82
--- a/sysdeps/x86/dl-cacheinfo.h
076f82
+++ b/sysdeps/x86/dl-cacheinfo.h
076f82
@@ -898,18 +898,6 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
076f82
   if (CPU_FEATURE_USABLE_P (cpu_features, FSRM))
076f82
     rep_movsb_threshold = 2112;
076f82
 
076f82
-  unsigned long int rep_movsb_stop_threshold;
076f82
-  /* ERMS feature is implemented from AMD Zen3 architecture and it is
076f82
-     performing poorly for data above L2 cache size. Henceforth, adding
076f82
-     an upper bound threshold parameter to limit the usage of Enhanced
076f82
-     REP MOVSB operations and setting its value to L2 cache size.  */
076f82
-  if (cpu_features->basic.kind == arch_kind_amd)
076f82
-    rep_movsb_stop_threshold = core;
076f82
-  /* Setting the upper bound of ERMS to the computed value of
076f82
-     non-temporal threshold for architectures other than AMD.  */
076f82
-  else
076f82
-    rep_movsb_stop_threshold = non_temporal_threshold;
076f82
-
076f82
   /* The default threshold to use Enhanced REP STOSB.  */
076f82
   unsigned long int rep_stosb_threshold = 2048;
076f82
 
076f82
@@ -951,6 +939,18 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
076f82
 			   SIZE_MAX);
076f82
 #endif
076f82
 
076f82
+  unsigned long int rep_movsb_stop_threshold;
076f82
+  /* ERMS feature is implemented from AMD Zen3 architecture and it is
076f82
+     performing poorly for data above L2 cache size. Henceforth, adding
076f82
+     an upper bound threshold parameter to limit the usage of Enhanced
076f82
+     REP MOVSB operations and setting its value to L2 cache size.  */
076f82
+  if (cpu_features->basic.kind == arch_kind_amd)
076f82
+    rep_movsb_stop_threshold = core;
076f82
+  /* Setting the upper bound of ERMS to the computed value of
076f82
+     non-temporal threshold for architectures other than AMD.  */
076f82
+  else
076f82
+    rep_movsb_stop_threshold = non_temporal_threshold;
076f82
+
076f82
   cpu_features->data_cache_size = data;
076f82
   cpu_features->shared_cache_size = shared;
076f82
   cpu_features->non_temporal_threshold = non_temporal_threshold;