[RFC PATCH 1/4] perf: Read cache instance ID when building cache topology

K Prateek Nayak posted 4 patches 2 years, 10 months ago
There is a newer version of this series
[RFC PATCH 1/4] perf: Read cache instance ID when building cache topology
Posted by K Prateek Nayak 2 years, 10 months ago
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.
Use instance ID as well when comparing cache levels.

Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
 tools/perf/util/env.h    | 1 +
 tools/perf/util/header.c | 7 +++++++
 2 files changed, 8 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..5c3f5d260612 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;
 
@@ -1168,6 +1171,10 @@ 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);
+	if (sysfs__read_int(file, (int *) &cache->id))
+		return -1;
+
 	scnprintf(file, PATH_MAX, "%s/coherency_line_size", path);
 	if (sysfs__read_int(file, (int *) &cache->line_size))
 		return -1;
-- 
2.34.1
Re: [RFC PATCH 1/4] perf: Read cache instance ID when building cache topology
Posted by Arnaldo Carvalho de Melo 2 years, 10 months ago
Em Fri, Mar 31, 2023 at 10:21:14AM +0530, K Prateek Nayak escreveu:
> 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.
> Use instance ID as well when comparing cache levels.

And if a new perf tool is used in an older kernel without this new 'id'
file?

Please check if the file exists, if it doesn't don't fail, just
initialize with a zero, this way the latest perf will be usable in older
kernels.

- Arnaldo
 
> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
> ---
>  tools/perf/util/env.h    | 1 +
>  tools/perf/util/header.c | 7 +++++++
>  2 files changed, 8 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..5c3f5d260612 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;
>  
> @@ -1168,6 +1171,10 @@ 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);
> +	if (sysfs__read_int(file, (int *) &cache->id))
> +		return -1;
> +
>  	scnprintf(file, PATH_MAX, "%s/coherency_line_size", path);
>  	if (sysfs__read_int(file, (int *) &cache->line_size))
>  		return -1;
> -- 
> 2.34.1
> 

-- 

- Arnaldo
Re: [RFC PATCH 1/4] perf: Read cache instance ID when building cache topology
Posted by K Prateek Nayak 2 years, 10 months ago
Hello Arnaldo,

Thank you for taking a look at the series.

On 3/31/2023 5:24 PM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Mar 31, 2023 at 10:21:14AM +0530, K Prateek Nayak escreveu:
>> 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.
>> Use instance ID as well when comparing cache levels.
> 
> And if a new perf tool is used in an older kernel without this new 'id'
> file?
> 
> Please check if the file exists, if it doesn't don't fail, just
> initialize with a zero, this way the latest perf will be usable in older
> kernels.

That makes sense. I'll handle this case as you suggested in the next
version.

> 
> - Arnaldo
>  
>> [..snip..]
> 

 
--
Thanks and Regards,
Prateek