]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
selftests/powerpc: Add cache_shape sniff test
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 6 Feb 2017 10:13:28 +0000 (21:13 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 20 Mar 2017 08:02:49 +0000 (19:02 +1100)
This is a very basic test of the new cache shape AUXV entries. All it
does at the moment is look for the entries and error out if we don't
find all the ones we expect. Primarily intended for folks bringing up a
new chip to check that the cache info is making it all the way to
userspace correctly.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
tools/testing/selftests/powerpc/Makefile
tools/testing/selftests/powerpc/cache_shape/.gitignore [new file with mode: 0644]
tools/testing/selftests/powerpc/cache_shape/Makefile [new file with mode: 0644]
tools/testing/selftests/powerpc/cache_shape/cache_shape.c [new file with mode: 0644]

index 1c5d0575802e47113b49b4b0facfd7bff47a6620..ca1a86f5d869fdc118d293491c867cd89b7dc6a4 100644 (file)
@@ -14,6 +14,7 @@ export CFLAGS
 
 SUB_DIRS = alignment           \
           benchmarks           \
+          cache_shape          \
           copyloops            \
           context_switch       \
           dscr                 \
diff --git a/tools/testing/selftests/powerpc/cache_shape/.gitignore b/tools/testing/selftests/powerpc/cache_shape/.gitignore
new file mode 100644 (file)
index 0000000..ec18484
--- /dev/null
@@ -0,0 +1 @@
+cache_shape
diff --git a/tools/testing/selftests/powerpc/cache_shape/Makefile b/tools/testing/selftests/powerpc/cache_shape/Makefile
new file mode 100644 (file)
index 0000000..b24485a
--- /dev/null
@@ -0,0 +1,10 @@
+TEST_PROGS := cache_shape
+
+all: $(TEST_PROGS)
+
+$(TEST_PROGS): ../harness.c ../utils.c
+
+include ../../lib.mk
+
+clean:
+       rm -f $(TEST_PROGS) *.o
diff --git a/tools/testing/selftests/powerpc/cache_shape/cache_shape.c b/tools/testing/selftests/powerpc/cache_shape/cache_shape.c
new file mode 100644 (file)
index 0000000..29ec07e
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2017, Michael Ellerman, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <link.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+#ifndef AT_L1I_CACHESIZE
+#define AT_L1I_CACHESIZE       40
+#define AT_L1I_CACHEGEOMETRY   41
+#define AT_L1D_CACHESIZE       42
+#define AT_L1D_CACHEGEOMETRY   43
+#define AT_L2_CACHESIZE                44
+#define AT_L2_CACHEGEOMETRY    45
+#define AT_L3_CACHESIZE                46
+#define AT_L3_CACHEGEOMETRY    47
+#endif
+
+static void print_size(const char *label, uint32_t val)
+{
+       printf("%s cache size: %#10x %10dB %10dK\n", label, val, val, val / 1024);
+}
+
+static void print_geo(const char *label, uint32_t val)
+{
+       uint16_t assoc;
+
+       printf("%s line size:  %#10x       ", label, val & 0xFFFF);
+
+       assoc = val >> 16;
+       if (assoc)
+               printf("%u-way", assoc);
+       else
+               printf("fully");
+
+       printf(" associative\n");
+}
+
+static int test_cache_shape()
+{
+       static char buffer[4096];
+       ElfW(auxv_t) *p;
+       int found;
+
+       FAIL_IF(read_auxv(buffer, sizeof(buffer)));
+
+       found = 0;
+
+       p = find_auxv_entry(AT_L1I_CACHESIZE, buffer);
+       if (p) {
+               found++;
+               print_size("L1I ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L1I_CACHEGEOMETRY, buffer);
+       if (p) {
+               found++;
+               print_geo("L1I ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L1D_CACHESIZE, buffer);
+       if (p) {
+               found++;
+               print_size("L1D ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L1D_CACHEGEOMETRY, buffer);
+       if (p) {
+               found++;
+               print_geo("L1D ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L2_CACHESIZE, buffer);
+       if (p) {
+               found++;
+               print_size("L2  ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L2_CACHEGEOMETRY, buffer);
+       if (p) {
+               found++;
+               print_geo("L2  ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L3_CACHESIZE, buffer);
+       if (p) {
+               found++;
+               print_size("L3  ", (uint32_t)p->a_un.a_val);
+       }
+
+       p = find_auxv_entry(AT_L3_CACHEGEOMETRY, buffer);
+       if (p) {
+               found++;
+               print_geo("L3  ", (uint32_t)p->a_un.a_val);
+       }
+
+       /* If we found none we're probably on a system where they don't exist */
+       SKIP_IF(found == 0);
+
+       /* But if we found any, we expect to find them all */
+       FAIL_IF(found != 8);
+
+       return 0;
+}
+
+int main(void)
+{
+       return test_harness(test_cache_shape, "cache_shape");
+}