This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: memcpy performance regressions 2.19 -> 2.24(5)


Sorry for misinterpreting.  Here is the full patch.

On Thu, May 25, 2017 at 3:03 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 25, 2017 at 2:57 PM, Erich Elsen <eriche@google.com> wrote:
>> It looks like you already added the non_temporal_threshold as part of
>> the cpu_features tunables?  Here's a small patch that allows the
>
> No, I didn't.  I only added cache info to CPU features.
>
>> cpu_features struct to be passed in.  This is useful if you need to be
>> able to call init_cacheinfo with cpu_features other than the global
>> ones.
>
> I need to see the complete working patch.
>
>>
>>
>> On Thu, May 25, 2017 at 2:23 PM, Erich Elsen <eriche@google.com> wrote:
>>> Ok, will do.
>>>
>>> On Wed, May 24, 2017 at 2:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Mon, May 22, 2017 at 8:19 PM, Erich Elsen <eriche@google.com> wrote:
>>>>> Here is the patch that slightly refactors how init_cacheinfo is called.
>>>>>
>>>>
>>>> Please take a look at hjl/tunables/master branch.  You can add
>>>> non_temporal_threshold support on top of it.
>>>>
>>>>
>>>> --
>>>> H.J.
>
>
>
> --
> H.J.
From bdbc243d9da3f5d59dc495970ef9572e7c446e94 Mon Sep 17 00:00:00 2001
From: Erich Elsen <eriche@google.com>
Date: Fri, 26 May 2017 17:28:06 -0700
Subject: [PATCH 1/1] add tunables for x86 cache info

---
 sysdeps/x86/cacheinfo.c      | 60 +++++++++++++++++++++++++++++++++++++++++---
 sysdeps/x86/dl-tunables.list | 15 +++++++++++
 2 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
index a46dd4dc30..ac98a951b0 100644
--- a/sysdeps/x86/cacheinfo.c
+++ b/sysdeps/x86/cacheinfo.c
@@ -25,6 +25,15 @@
 #include <cpuid.h>
 #include <init-arch.h>
 
+#if HAVE_TUNABLES
+# define TUNABLE_NAMESPACE x86
+# include <elf/dl-tunables.h>
+#else
+# include <string.h>
+# include <stdlib.h>
+extern char **_environ;
+#endif
+
 static const struct intel_02_cache_info
 {
   unsigned char idx;
@@ -482,9 +491,9 @@ int __x86_prefetchw attribute_hidden;
 #endif
 
 
-static void
-__attribute__((constructor))
-init_cacheinfo (void)
+void
+attribute_hidden
+init_cacheinfo_impl (const struct cpu_features* cpu_features)
 {
   /* Find out what brand of processor.  */
   unsigned int eax;
@@ -496,7 +505,6 @@ init_cacheinfo (void)
   long int shared = -1;
   unsigned int level;
   unsigned int threads = 0;
-  const struct cpu_features *cpu_features = __get_cpu_features ();
   int max_cpuid = cpu_features->max_cpuid;
 
   if (cpu_features->kind == arch_kind_intel)
@@ -787,4 +795,48 @@ intel_bug_no_cache_info:
        : __x86_shared_cache_size * 6);
 }
 
+static void
+update_cpufeature_cache_info(struct cpu_features* cpu_features)
+{
+#if HAVE_TUNABLES
+  TUNABLE_SET_VAL (non_temporal_threshold,
+                   &(cpu_features->cache.non_temporal_threshold));
+  TUNABLE_SET_VAL (data_size,
+                   &(cpu_features->cache.data_size));
+  TUNABLE_SET_VAL (shared_size,
+                   &(cpu_features->cache.shared_size));
+#else
+  if (__glibc_likely (_environ != NULL)
+      && !__builtin_expect (__libc_enable_secure, 0))
+    {
+      char **runp = _environ;
+      char *envline;
+
+      while (*runp != NULL)
+	{
+	  envline = *runp;
+	  if (!DEFAULT_MEMCMP (envline, "GLIBC_NON_TEMPORAL_THRESHOLD=", 29))
+	    cpu_features->cache.non_temporal_threshold = atoi (&envline[29]);
+	  else if (!DEFAULT_MEMCMP (envline, "GLIBC_DATA_SIZE=", 16))
+	    cpu_features->cache.data_size = atoi (&envline[16]);
+	  else if (!DEFAULT_MEMCMP (envline, "GLIBC_SHARED_SIZE=", 18))
+	    cpu_features->cache.shared_size = atoi (&envline[18]);
+
+	  runp++;
+	}
+    }
+#endif
+}
+
+static void
+__attribute__((constructor))
+init_cacheinfo (void)
+{
+  const struct cpu_features *cpu_features_const = __get_cpu_features ();
+  struct cpu_features cpu_features = *cpu_features_const;
+
+  update_cpufeature_cache_info (&cpu_features);
+
+  init_cacheinfo_impl (&cpu_features);
+}
 #endif
diff --git a/sysdeps/x86/dl-tunables.list b/sysdeps/x86/dl-tunables.list
index 0c9acc085c..136e455bcf 100644
--- a/sysdeps/x86/dl-tunables.list
+++ b/sysdeps/x86/dl-tunables.list
@@ -5,5 +5,20 @@ glibc {
       env_alias: GLIBC_IFUNC
       security_level: SXID_IGNORE
     }
+    non_temporal_threshold {
+      type: SIZE_T
+      env_alias: GLIBC_NON_TEMPORAL_THRESHOLD
+      security_level: SXID_IGNORE
+    }
+    data_size {
+      type: SIZE_T
+      env_alias: GLIBC_DATA_SIZE
+      security_level: SXID_IGNORE
+    }
+    shared_size {
+      type: SIZE_T
+      env_alias: GLIBC_SHARED_SIZE
+      security_level: SXID_IGNORE
+    }
   }
 }
-- 
2.13.0.219.gdb65acc882-goog


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]