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