提交 43f55452 编写于 作者: H Huacai Chen 提交者: Hongchen Zhang

LoongArch: Fix shared cache size calculation

mainline inclusion
from mainline-v5.19
commit 1aea29d7
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB
CVE: NA

--------------------------------

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: NHuacai Chen <chenhuacai@loongson.cn>
上级 672bc047
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
* *
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/ */
#include <asm/cpu-info.h>
#include <linux/cacheinfo.h> #include <linux/cacheinfo.h>
#include <asm/bootinfo.h>
#include <asm/cpu-info.h>
/* Populates leaf and increments to next leaf */ /* Populates leaf and increments to next leaf */
#define populate_cache(cache, leaf, c_level, c_type) \ #define populate_cache(cache, leaf, c_level, c_type) \
...@@ -17,6 +18,8 @@ do { \ ...@@ -17,6 +18,8 @@ do { \
leaf->ways_of_associativity = c->cache.ways; \ leaf->ways_of_associativity = c->cache.ways; \
leaf->size = c->cache.linesz * c->cache.sets * \ leaf->size = c->cache.linesz * c->cache.sets * \
c->cache.ways; \ c->cache.ways; \
if (leaf->level > 2) \
leaf->size *= nodes_per_package; \
leaf++; \ leaf++; \
} while (0) } while (0)
...@@ -95,11 +98,15 @@ static void cache_cpumap_setup(unsigned int cpu) ...@@ -95,11 +98,15 @@ static void cache_cpumap_setup(unsigned int cpu)
int populate_cache_leaves(unsigned int cpu) int populate_cache_leaves(unsigned int cpu)
{ {
int level = 1; int level = 1, nodes_per_package = 1;
struct cpuinfo_loongarch *c = &current_cpu_data; struct cpuinfo_loongarch *c = &current_cpu_data;
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
struct cacheinfo *this_leaf = this_cpu_ci->info_list; struct cacheinfo *this_leaf = this_cpu_ci->info_list;
if (loongson_sysconf.nr_nodes > 1)
nodes_per_package = loongson_sysconf.cores_per_package
/ loongson_sysconf.cores_per_node;
if (c->icache.waysize) { if (c->icache.waysize) {
populate_cache(dcache, this_leaf, level, CACHE_TYPE_DATA); populate_cache(dcache, this_leaf, level, CACHE_TYPE_DATA);
populate_cache(icache, this_leaf, level++, CACHE_TYPE_INST); populate_cache(icache, this_leaf, level++, CACHE_TYPE_INST);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册