sysconf(): implement cache queries.
This is a bit disappointing. I'd not implemented this in the past
because it wasn't available on all platforms, and -- although the
riscv64 implementation was just a cool optimization -- I thought that
the /sys stuff was actually portable, until I ran it on arm64 hardware.
So here we have getauxval() for riscv64, /sys for x86-64, and our best
guess based on ctr_el0 for arm64.
Bug: http://b/294034962
Test: ran tests on the host, an arm64 device, and riscv64 host and qemu
Change-Id: I420b69b976d30668d4d2ac548c4229e2a4eafb20
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 4c21627..b639a4e 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1166,6 +1166,26 @@
VERIFY_SYSCONF_UNKNOWN(666);
}
+static void show_cache(const char* name, long size, long assoc, long line_size) {
+ printf("%s cache size: %ld bytes, line size %ld bytes, ", name, size, line_size);
+ if (assoc == 0) {
+ printf("fully");
+ } else {
+ printf("%ld-way", assoc);
+ }
+ printf(" associative\n");
+}
+
+TEST(UNISTD_TEST, sysconf_cache) {
+ // It's not obvious we can _test_ any of these, but we can at least
+ // show the output for humans to inspect.
+ show_cache("L1D", sysconf(_SC_LEVEL1_DCACHE_SIZE), sysconf(_SC_LEVEL1_DCACHE_ASSOC), sysconf(_SC_LEVEL1_DCACHE_LINESIZE));
+ show_cache("L1I", sysconf(_SC_LEVEL1_ICACHE_SIZE), sysconf(_SC_LEVEL1_ICACHE_ASSOC), sysconf(_SC_LEVEL1_ICACHE_LINESIZE));
+ show_cache("L2", sysconf(_SC_LEVEL2_CACHE_SIZE), sysconf(_SC_LEVEL2_CACHE_ASSOC), sysconf(_SC_LEVEL2_CACHE_LINESIZE));
+ show_cache("L3", sysconf(_SC_LEVEL3_CACHE_SIZE), sysconf(_SC_LEVEL3_CACHE_ASSOC), sysconf(_SC_LEVEL3_CACHE_LINESIZE));
+ show_cache("L4", sysconf(_SC_LEVEL4_CACHE_SIZE), sysconf(_SC_LEVEL4_CACHE_ASSOC), sysconf(_SC_LEVEL4_CACHE_LINESIZE));
+}
+
TEST(UNISTD_TEST, dup2_same) {
// POSIX says of dup2:
// If fildes2 is already a valid open file descriptor ...