1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2017, Michael Ellerman, IBM Corp.
14 #include <sys/types.h>
20 #ifndef AT_L1I_CACHESIZE
21 #define AT_L1I_CACHESIZE 40
22 #define AT_L1I_CACHEGEOMETRY 41
23 #define AT_L1D_CACHESIZE 42
24 #define AT_L1D_CACHEGEOMETRY 43
25 #define AT_L2_CACHESIZE 44
26 #define AT_L2_CACHEGEOMETRY 45
27 #define AT_L3_CACHESIZE 46
28 #define AT_L3_CACHEGEOMETRY 47
31 static void print_size(const char *label
, uint32_t val
)
33 printf("%s cache size: %#10x %10dB %10dK\n", label
, val
, val
, val
/ 1024);
36 static void print_geo(const char *label
, uint32_t val
)
40 printf("%s line size: %#10x ", label
, val
& 0xFFFF);
44 printf("%u-way", assoc
);
48 printf(" associative\n");
51 static int test_cache_shape()
53 static char buffer
[4096];
57 FAIL_IF(read_auxv(buffer
, sizeof(buffer
)));
61 p
= find_auxv_entry(AT_L1I_CACHESIZE
, buffer
);
64 print_size("L1I ", (uint32_t)p
->a_un
.a_val
);
67 p
= find_auxv_entry(AT_L1I_CACHEGEOMETRY
, buffer
);
70 print_geo("L1I ", (uint32_t)p
->a_un
.a_val
);
73 p
= find_auxv_entry(AT_L1D_CACHESIZE
, buffer
);
76 print_size("L1D ", (uint32_t)p
->a_un
.a_val
);
79 p
= find_auxv_entry(AT_L1D_CACHEGEOMETRY
, buffer
);
82 print_geo("L1D ", (uint32_t)p
->a_un
.a_val
);
85 p
= find_auxv_entry(AT_L2_CACHESIZE
, buffer
);
88 print_size("L2 ", (uint32_t)p
->a_un
.a_val
);
91 p
= find_auxv_entry(AT_L2_CACHEGEOMETRY
, buffer
);
94 print_geo("L2 ", (uint32_t)p
->a_un
.a_val
);
97 p
= find_auxv_entry(AT_L3_CACHESIZE
, buffer
);
100 print_size("L3 ", (uint32_t)p
->a_un
.a_val
);
103 p
= find_auxv_entry(AT_L3_CACHEGEOMETRY
, buffer
);
106 print_geo("L3 ", (uint32_t)p
->a_un
.a_val
);
109 /* If we found none we're probably on a system where they don't exist */
112 /* But if we found any, we expect to find them all */
120 return test_harness(test_cache_shape
, "cache_shape");