Skip to content

Commit cbf2186

Browse files
James Morsegregkh
authored andcommitted
arm64: cacheinfo: Provide helper to compress MPIDR value into u32
Filesystems like resctrl use the cache-id exposed via sysfs to identify groups of CPUs. The value is also used for PCIe cache steering tags. On DT platforms cache-id is not something that is described in the device-tree, but instead generated from the smallest MPIDR of the CPUs associated with that cache. The cache-id exposed to user-space has historically been 32 bits. MPIDR values may be larger than 32 bits. MPIDR only has 32 bits worth of affinity data, but the aff3 field lives above 32bits. The corresponding lower bits are masked out by MPIDR_HWID_BITMASK and contain an SMT flag and Uni-Processor flag. Swizzzle the aff3 field into the bottom 32 bits and using that. In case more affinity fields are added in the future, the upper RES0 area should be checked. Returning a value greater than 32 bits from this helper will cause the caller to give up on allocating cache-ids. Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Link: https://lore.kernel.org/r/20250711182743.30141-4-james.morse@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9a697ef commit cbf2186

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

arch/arm64/include/asm/cache.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ int cache_line_size(void);
8787

8888
#define dma_get_cache_alignment cache_line_size
8989

90+
/* Compress a u64 MPIDR value into 32 bits. */
91+
static inline u64 arch_compact_of_hwid(u64 id)
92+
{
93+
u64 aff3 = MPIDR_AFFINITY_LEVEL(id, 3);
94+
95+
/*
96+
* These bits are expected to be RES0. If not, return a value with
97+
* the upper 32 bits set to force the caller to give up on 32 bit
98+
* cache ids.
99+
*/
100+
if (FIELD_GET(GENMASK_ULL(63, 40), id))
101+
return id;
102+
103+
return (aff3 << 24) | FIELD_GET(GENMASK_ULL(23, 0), id);
104+
}
105+
#define arch_compact_of_hwid arch_compact_of_hwid
106+
90107
/*
91108
* Read the effective value of CTR_EL0.
92109
*

0 commit comments

Comments
 (0)