Skip to content

Commit 1aea29d

Browse files
committed
LoongArch: Fix shared cache size calculation
Current calculation of shared cache size is from the node (die) scope, but we hope 'lscpu' to show the shared cache size of the whole package for multi-die chips (e.g., Loongson-3C5000L, which contains 4 dies in one package). So fix it by multiplying nodes_per_package. Signed-off-by: Huacai Chen <[email protected]>
1 parent 317980e commit 1aea29d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/loongarch/kernel/cacheinfo.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*
55
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
66
*/
7-
#include <asm/cpu-info.h>
87
#include <linux/cacheinfo.h>
8+
#include <asm/bootinfo.h>
9+
#include <asm/cpu-info.h>
910

1011
/* Populates leaf and increments to next leaf */
1112
#define populate_cache(cache, leaf, c_level, c_type) \
@@ -17,6 +18,8 @@ do { \
1718
leaf->ways_of_associativity = c->cache.ways; \
1819
leaf->size = c->cache.linesz * c->cache.sets * \
1920
c->cache.ways; \
21+
if (leaf->level > 2) \
22+
leaf->size *= nodes_per_package; \
2023
leaf++; \
2124
} while (0)
2225

@@ -95,11 +98,15 @@ static void cache_cpumap_setup(unsigned int cpu)
9598

9699
int populate_cache_leaves(unsigned int cpu)
97100
{
98-
int level = 1;
101+
int level = 1, nodes_per_package = 1;
99102
struct cpuinfo_loongarch *c = &current_cpu_data;
100103
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
101104
struct cacheinfo *this_leaf = this_cpu_ci->info_list;
102105

106+
if (loongson_sysconf.nr_nodes > 1)
107+
nodes_per_package = loongson_sysconf.cores_per_package
108+
/ loongson_sysconf.cores_per_node;
109+
103110
if (c->icache.waysize) {
104111
populate_cache(dcache, this_leaf, level, CACHE_TYPE_DATA);
105112
populate_cache(icache, this_leaf, level++, CACHE_TYPE_INST);

0 commit comments

Comments
 (0)