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