Blame SOURCES/0004-Read-L1-data-cache-size-from-sysconf-if-possible.patch

698a2e
From a45cebf11522b3112fba3d682224a232ae5e2e98 Mon Sep 17 00:00:00 2001
698a2e
From: Andreas Arnez <arnez@linux.ibm.com>
698a2e
Date: Wed, 12 Dec 2018 19:44:32 +0100
698a2e
Subject: [PATCH 4/8] Read L1 data cache size from sysconf if possible
698a2e
698a2e
The probing of the L1 data cache size is sometimes not reliable.  This can
698a2e
cause the tuning to yield varying, sub-obtimal results.  But on Linux the
698a2e
L1 data cache size can usually be retrieved with sysconf instead, which is
698a2e
faster and more reliable.  Do this whenever possible.
698a2e
---
698a2e
 tune/sysinfo/L1CacheSize.c | 12 +++++++++++-
698a2e
 1 file changed, 11 insertions(+), 1 deletion(-)
698a2e
698a2e
diff --git a/tune/sysinfo/L1CacheSize.c b/tune/sysinfo/L1CacheSize.c
698a2e
index e62a273..dffa76e 100644
698a2e
--- a/tune/sysinfo/L1CacheSize.c
698a2e
+++ b/tune/sysinfo/L1CacheSize.c
698a2e
@@ -30,6 +30,7 @@
698a2e
 
698a2e
 #include <stdio.h>
698a2e
 #include <stdlib.h>
698a2e
+#include <unistd.h>
698a2e
 
698a2e
 #define REPS 4096
698a2e
 
698a2e
@@ -276,7 +277,16 @@ int main(int nargs, char *args[])
698a2e
       exit(-1);
698a2e
    }
698a2e
    if (nargs > 1) MaxSize = atoi(args[1]);
698a2e
-   L1Size = GetL1Size(MaxSize, 1.08);
698a2e
+
698a2e
+#ifdef _SC_LEVEL1_DCACHE_SIZE
698a2e
+   {
698a2e
+      long res = sysconf(_SC_LEVEL1_DCACHE_SIZE);
698a2e
+      L1Size = res > 0 ? (int) (res / 1024) : 0;
698a2e
+   }
698a2e
+#endif
698a2e
+
698a2e
+   if (!L1Size)
698a2e
+      L1Size = GetL1Size(MaxSize, 1.08);
698a2e
    if (!L1Size)
698a2e
       L1Size = GetL1Size(MaxSize, 1.08);
698a2e
    if (!L1Size)
698a2e
-- 
698a2e
2.23.0
698a2e