Skip to content

Commit 98a5f36

Browse files
ozbenhmpe
authored andcommitted
powerpc: Add new cache geometry aux vectors
This adds AUX vectors for the L1I,D, L2 and L3 cache levels providing for each cache level the size of the cache in bytes and the geometry (line size and number of ways). We chose to not use the existing alpha/sh definition which packs all the information in a single entry per cache level as it is too restricted to represent some of the geometries used on POWER. Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 608b421 commit 98a5f36

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

arch/powerpc/include/asm/cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct ppc_cache_info {
3838
u32 log_block_size;
3939
u32 blocks_per_page;
4040
u32 sets;
41+
u32 assoc;
4142
};
4243

4344
struct ppc64_caches {

arch/powerpc/include/asm/elf.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
136136

137137
#endif /* CONFIG_SPU_BASE */
138138

139+
#ifdef CONFIG_PPC64
140+
141+
#define get_cache_geometry(level) \
142+
(ppc64_caches.level.assoc << 16 | ppc64_caches.level.line_size)
143+
144+
#define ARCH_DLINFO_CACHE_GEOMETRY \
145+
NEW_AUX_ENT(AT_L1I_CACHESIZE, ppc64_caches.l1i.size); \
146+
NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, get_cache_geometry(l1i)); \
147+
NEW_AUX_ENT(AT_L1D_CACHESIZE, ppc64_caches.l1i.size); \
148+
NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, get_cache_geometry(l1i)); \
149+
NEW_AUX_ENT(AT_L2_CACHESIZE, ppc64_caches.l2.size); \
150+
NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, get_cache_geometry(l2)); \
151+
NEW_AUX_ENT(AT_L3_CACHESIZE, ppc64_caches.l3.size); \
152+
NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, get_cache_geometry(l3))
153+
154+
#else
155+
#define ARCH_DLINFO_CACHE_GEOMETRY
156+
#endif
157+
139158
/*
140159
* The requirements here are:
141160
* - keep the final alignment of sp (sp & 0xf)
@@ -156,6 +175,7 @@ do { \
156175
NEW_AUX_ENT(AT_ICACHEBSIZE, icache_bsize); \
157176
NEW_AUX_ENT(AT_UCACHEBSIZE, ucache_bsize); \
158177
VDSO_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso_base); \
178+
ARCH_DLINFO_CACHE_GEOMETRY; \
159179
} while (0)
160180

161181
#endif /* _ASM_POWERPC_ELF_H */

arch/powerpc/include/uapi/asm/auxvec.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@
1616
*/
1717
#define AT_SYSINFO_EHDR 33
1818

19-
#define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
19+
/*
20+
* AT_*CACHEBSIZE above represent the cache *block* size which is
21+
* the size that is affected by the cache management instructions.
22+
*
23+
* It doesn't nececssarily matches the cache *line* size which is
24+
* more of a performance tuning hint. Additionally the latter can
25+
* be different for the different cache levels.
26+
*
27+
* The set of entries below represent more extensive information
28+
* about the caches, in the form of two entry per cache type,
29+
* one entry containing the cache size in bytes, and the other
30+
* containing the cache line size in bytes in the bottom 16 bits
31+
* and the cache associativity in the next 16 bits.
32+
*
33+
* The associativity is such that if N is the 16-bit value, the
34+
* cache is N way set associative. A value if 0xffff means fully
35+
* associative, a value of 1 means directly mapped.
36+
*
37+
* For all these fields, a value of 0 means that the information
38+
* is not known.
39+
*/
40+
41+
#define AT_L1I_CACHESIZE 40
42+
#define AT_L1I_CACHEGEOMETRY 41
43+
#define AT_L1D_CACHESIZE 42
44+
#define AT_L1D_CACHEGEOMETRY 43
45+
#define AT_L2_CACHESIZE 44
46+
#define AT_L2_CACHEGEOMETRY 45
47+
#define AT_L3_CACHESIZE 46
48+
#define AT_L3_CACHEGEOMETRY 47
49+
50+
#define AT_VECTOR_SIZE_ARCH 14 /* entries in ARCH_DLINFO */
2051

2152
#endif

arch/powerpc/kernel/setup_64.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ static void init_cache_info(struct ppc_cache_info *info, u32 size, u32 lsize,
411411
info->block_size = bsize;
412412
info->log_block_size = __ilog2(bsize);
413413
info->blocks_per_page = PAGE_SIZE / bsize;
414+
415+
if (sets == 0)
416+
info->assoc = 0xffff;
417+
else
418+
info->assoc = size / (sets * lsize);
414419
}
415420

416421
static bool __init parse_cache_info(struct device_node *np,

0 commit comments

Comments
 (0)