summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2019-06-16 22:14:17 -0700
committernickjsanders <nick.j.sanders@gmail.com>2022-12-19 10:40:46 -0800
commit099e350edce88bd978ee0b4b5e06f58149776dec (patch)
treea1c9c39d0ab6514f61ff8f9b542137aea755a69d
parent8070b63792990bd1de317762ed275dc7a0eea7a1 (diff)
stressapptest: Implement reading sysfs and use it if sysconf
sysconf params like _SC_LEVEL1_DCACHE_LINESIZE are not universally implemented, therefore check for them being available, if not there then read the sysfs directly to get the value Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rw-r--r--src/sat.cc40
-rw-r--r--src/sat.h3
2 files changed, 38 insertions, 5 deletions
diff --git a/src/sat.cc b/src/sat.cc
index a0e4eb9..d2ac6a7 100644
--- a/src/sat.cc
+++ b/src/sat.cc
@@ -1484,15 +1484,47 @@ int Sat::CpuCount() {
return sysconf(_SC_NPROCESSORS_CONF);
}
+int Sat::ReadInt(const char *filename, int *value) {
+ char line[64];
+ int fd = open(filename, O_RDONLY), err = -1;
+
+ if (fd < 0)
+ return -1;
+ if (read(fd, line, sizeof(line)) > 0) {
+ *value = atoi(line);
+ err = 0;
+ }
+
+ close(fd);
+ return err;
+}
+
// Return the worst case (largest) cache line size of the various levels of
// cache actually prsent in the machine.
int Sat::CacheLineSize() {
- int max_linesize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
- int linesize = sysconf(_SC_LEVEL2_CACHE_LINESIZE);
+ int max_linesize, linesize;
+#ifdef _SC_LEVEL1_DCACHE_LINESIZE
+ max_linesize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+#else
+ ReadInt("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", &max_linesize);
+#endif
+#ifdef _SC_LEVEL2_DCACHE_LINESIZE
+ linesize = sysconf(_SC_LEVEL2_DCACHE_LINESIZE);
+#else
+ ReadInt("/sys/devices/system/cpu/cpu0/cache/index1/coherency_line_size", &linesize);
+#endif
if (linesize > max_linesize) max_linesize = linesize;
- linesize = sysconf(_SC_LEVEL3_CACHE_LINESIZE);
+#ifdef _SC_LEVEL3_DCACHE_LINESIZE
+ linesize = sysconf(_SC_LEVEL3_DCACHE_LINESIZE);
+#else
+ ReadInt("/sys/devices/system/cpu/cpu0/cache/index2/coherency_line_size", &linesize);
+#endif
if (linesize > max_linesize) max_linesize = linesize;
- linesize = sysconf(_SC_LEVEL4_CACHE_LINESIZE);
+#ifdef _SC_LEVEL4_DCACHE_LINESIZE
+ linesize = sysconf(_SC_LEVEL4_DCACHE_LINESIZE);
+#else
+ ReadInt("/sys/devices/system/cpu/cpu0/cache/index3/coherency_line_size", &linesize);
+#endif
if (linesize > max_linesize) max_linesize = linesize;
return max_linesize;
}
diff --git a/src/sat.h b/src/sat.h
index 6af90a2..9347ec6 100644
--- a/src/sat.h
+++ b/src/sat.h
@@ -137,7 +137,8 @@ class Sat {
int CpuCount();
// Return the worst-case (largest) cache line size of the system.
int CacheLineSize();
-
+ // Read int values from kernel file system e.g. sysfs
+ int ReadInt(const char *filename, int *value);
// Collect error counts from threads.
int64 GetTotalErrorCount();