lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230405170906.2510-2-kprateek.nayak@amd.com>
Date:   Wed, 5 Apr 2023 22:39:03 +0530
From:   K Prateek Nayak <kprateek.nayak@....com>
To:     <linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <acme@...nel.org>, <peterz@...radead.org>, <mingo@...hat.com>,
        <mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
        <jolsa@...nel.org>, <namhyung@...nel.org>
CC:     <ravi.bangoria@....com>, <sandipan.das@....com>,
        <ananth.narayan@....com>, <gautham.shenoy@....com>,
        <eranian@...gle.com>, <puwen@...on.cn>
Subject: [RFC PATCH v2 1/4] perf: Read cache instance ID when building cache topology

CPU cache level data currently stores cache level, type, line size,
associativity, sets, total cache size, and the CPUs sharing the cache.
Also read and store the cache instance ID from
"/sys/devices/system/cpu/cpuX/cache/indexY/id" in the cache level data
on kernels where the file exits. If the file does not exist, id will be
set to 0.

Suggested-by: Arnaldo Carvalho de Melo <acme@...nel.org> # Error Handling
Signed-off-by: K Prateek Nayak <kprateek.nayak@....com>
---
o v1->v2
  - Handle case where the cache instance ID might not be exposed so perf
    can continue to work on older kernels.
---
 tools/perf/util/env.h    |  1 +
 tools/perf/util/header.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index 4566c51f2fd9..d761bfae76af 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -17,6 +17,7 @@ struct cpu_topology_map {
 
 struct cpu_cache_level {
 	u32	level;
+	u32	id;
 	u32	line_size;
 	u32	sets;
 	u32	ways;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 404d816ca124..a938738f8775 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1131,6 +1131,9 @@ static bool cpu_cache_level__cmp(struct cpu_cache_level *a, struct cpu_cache_lev
 	if (a->level != b->level)
 		return false;
 
+	if (a->id != b->id)
+		return false;
+
 	if (a->line_size != b->line_size)
 		return false;
 
@@ -1157,6 +1160,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
 	char path[PATH_MAX], file[PATH_MAX];
 	struct stat st;
 	size_t len;
+	int ret;
 
 	scnprintf(path, PATH_MAX, "devices/system/cpu/cpu%d/cache/index%d/", cpu, level);
 	scnprintf(file, PATH_MAX, "%s/%s", sysfs__mountpoint(), path);
@@ -1168,6 +1172,16 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
 	if (sysfs__read_int(file, (int *) &cache->level))
 		return -1;
 
+	scnprintf(file, PATH_MAX, "%s/id", path);
+	ret = sysfs__read_int(file, (int *) &cache->id);
+
+	/*
+	 * Set cache->id to 0 if the read fails. This enables perf to
+	 * work on older kernels where the id may be missing.
+	 */
+	if (ret)
+		cache->id = 0;
+
 	scnprintf(file, PATH_MAX, "%s/coherency_line_size", path);
 	if (sysfs__read_int(file, (int *) &cache->line_size))
 		return -1;
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ