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(-)
@@ -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
@@ -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