2 * Copyright 2017, Michael Ellerman, IBM Corp.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
18 #include <sys/types.h>
24 #ifndef AT_L1I_CACHESIZE
25 #define AT_L1I_CACHESIZE 40
26 #define AT_L1I_CACHEGEOMETRY 41
27 #define AT_L1D_CACHESIZE 42
28 #define AT_L1D_CACHEGEOMETRY 43
29 #define AT_L2_CACHESIZE 44
30 #define AT_L2_CACHEGEOMETRY 45
31 #define AT_L3_CACHESIZE 46
32 #define AT_L3_CACHEGEOMETRY 47
35 static void print_size(const char *label, uint32_t val)
37 printf("%s cache size: %#10x %10dB %10dK\n", label, val, val, val / 1024);
40 static void print_geo(const char *label, uint32_t val)
44 printf("%s line size: %#10x ", label, val & 0xFFFF);
48 printf("%u-way", assoc);
52 printf(" associative\n");
55 static int test_cache_shape()
57 static char buffer[4096];
61 FAIL_IF(read_auxv(buffer, sizeof(buffer)));
65 p = find_auxv_entry(AT_L1I_CACHESIZE, buffer);
68 print_size("L1I ", (uint32_t)p->a_un.a_val);
71 p = find_auxv_entry(AT_L1I_CACHEGEOMETRY, buffer);
74 print_geo("L1I ", (uint32_t)p->a_un.a_val);
77 p = find_auxv_entry(AT_L1D_CACHESIZE, buffer);
80 print_size("L1D ", (uint32_t)p->a_un.a_val);
83 p = find_auxv_entry(AT_L1D_CACHEGEOMETRY, buffer);
86 print_geo("L1D ", (uint32_t)p->a_un.a_val);
89 p = find_auxv_entry(AT_L2_CACHESIZE, buffer);
92 print_size("L2 ", (uint32_t)p->a_un.a_val);
95 p = find_auxv_entry(AT_L2_CACHEGEOMETRY, buffer);
98 print_geo("L2 ", (uint32_t)p->a_un.a_val);
101 p = find_auxv_entry(AT_L3_CACHESIZE, buffer);
104 print_size("L3 ", (uint32_t)p->a_un.a_val);
107 p = find_auxv_entry(AT_L3_CACHEGEOMETRY, buffer);
110 print_geo("L3 ", (uint32_t)p->a_un.a_val);
113 /* If we found none we're probably on a system where they don't exist */
116 /* But if we found any, we expect to find them all */
124 return test_harness(test_cache_shape, "cache_shape");