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