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