The function cpu__max_cpu returns the possible number of CPUs as defined
in the sysfs and can be used as an alternative for MAX_NR_CPUS in
write_cache. MAX_CACHES is replaced by cpu__max_cpu() * MAX_CACHE_LVL.

Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: Arnaldo Carvalho de Melo <a...@kernel.org>
Cc: Alexander Shishkin <alexander.shish...@linux.intel.com>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.ander...@hpe.com>
Signed-off-by: Kyle Meyer <kyle.me...@hpe.com>
---
 tools/perf/util/header.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1f2965a07bef..881a586fab41 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1121,16 +1121,17 @@ static int build_caches(struct cpu_cache_level 
caches[], u32 size, u32 *cntp)
        return 0;
 }
 
-#define MAX_CACHES (MAX_NR_CPUS * 4)
+#define MAX_CACHE_LVL 4
 
 static int write_cache(struct feat_fd *ff,
                       struct evlist *evlist __maybe_unused)
 {
-       struct cpu_cache_level caches[MAX_CACHES];
+       u32 max_caches = cpu__max_cpu() * MAX_CACHE_LVL;
+       struct cpu_cache_level caches[max_caches];
        u32 cnt = 0, i, version = 1;
        int ret;
 
-       ret = build_caches(caches, MAX_CACHES, &cnt);
+       ret = build_caches(caches, max_caches, &cnt);
        if (ret)
                goto out;
 
-- 
2.12.3

Reply via email to