perf stat: Fix wrong skipping for per-die aggregation
PATCH 1/1 perf stat: Fix wrong skipping for per-die aggregation
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported --per-die aggregation yet.
One issue is found in check_per_pkg() for uncore events running on AP system. On cascade Lake-AP, we have:
S0-D0
S0-D1
S1-D0
S1-D1
But in check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't check die_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not correct.
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read
1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read
1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read
1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read
2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read
2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read
2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read
2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read
3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read
3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read
3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read
3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read
4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read
4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read
4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read
4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read
5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read
5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read
5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read
5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_readFrom above output, we can see S0-D1 and S1-D1 don't report the interval values, they are continued to grow. That's because check_per_pkg() wrongly decides to use zero counts for S0-D1 and S1-D1.
So in check_per_pkg(), we should use a pair of die_id + socket_id to decide if this cpu counts needs to skip. Only considering socket_id is not enough.
Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001622560 S0-D0 1 1210176 Bytes llc_misses.mem_read
1.001622560 S0-D1 1 950208 Bytes llc_misses.mem_read
1.001622560 S1-D0 1 968704 Bytes llc_misses.mem_read
1.001622560 S1-D1 1 1113280 Bytes llc_misses.mem_read
2.004399430 S0-D0 1 1258560 Bytes llc_misses.mem_read
2.004399430 S0-D1 1 1011008 Bytes llc_misses.mem_read
2.004399430 S1-D0 1 1036544 Bytes llc_misses.mem_read
2.004399430 S1-D1 1 1237376 Bytes llc_misses.mem_read
3.006535657 S0-D0 1 1036608 Bytes llc_misses.mem_read
3.006535657 S0-D1 1 906560 Bytes llc_misses.mem_read
3.006535657 S1-D0 1 994112 Bytes llc_misses.mem_read
3.006535657 S1-D1 1 1025472 Bytes llc_misses.mem_read
4.008934402 S0-D0 1 1005120 Bytes llc_misses.mem_read
4.008934402 S0-D1 1 882368 Bytes llc_misses.mem_read
4.008934402 S1-D0 1 961408 Bytes llc_misses.mem_read
4.008934402 S1-D1 1 988352 Bytes llc_misses.mem_read
5.001605406 S0-D0 1 1930240 Bytes llc_misses.mem_read
5.001605406 S0-D1 1 1134272 Bytes llc_misses.mem_read
5.001605406 S1-D0 1 1531136 Bytes llc_misses.mem_read
5.001605406 S1-D1 1 2230848 Bytes llc_misses.mem_readOn no-die system, die_id is 0, this patch keeps original behavior unchanged.
--- tools/perf/util/cpumap.h | 2 ++ tools/perf/util/stat.c | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)
tools/perf/util/cpumap.h +2 -0
@@ -7,6 +7,8 @@#include <internal/cpumap.h> #include <perf/cpumap.h> +#define CPU_MAP_MAX_DIE 256 +struct perf_record_cpu_map_data ;struct perf_cpu_map *perf_cpu_map__empty_new (int nr);
tools/perf/util/stat.c +17 -4
@@ -282,9 +282,9 @@ static void zero_per_pkg(struct evsel *counter)static int check_per_pkg (struct evsel *counter,struct perf_counts_values *vals,int cpu,bool *skip) { -unsigned long *mask = counter->per_pkg_mask; +unsigned long *mask = counter->per_pkg_mask, *l;struct perf_cpu_map *cpus =evsel__cpus (counter); -int s; +int s, d; *skip = false;
@@ -295,7 +295,7 @@ static int check_per_pkg(struct evsel *counter,return 0 ;if (!mask) { - mask =zalloc (cpu__max_cpu ()); + mask =zalloc (cpu__max_cpu () *CPU_MAP_MAX_DIE );if (!mask)return -ENOMEM ;
@@ -317,7 +317,20 @@ static int check_per_pkg(struct evsel *counter,if (s <0 )return -1 ; - *skip =test_and_set_bit (s, mask) ==1 ; + d =cpu_map__get_die (cpus, cpu,NULL ); +if (d <0 ) +return -1 ; + +/* +* On multi-die system, die_id < 256. We use a pair +* of socket + die to identify the used bit. +* On no-die system, die_id is 0, l = &mask[0]. It doesn't +* change original "test_and_set_bit(s, mask)" behavior. +*/ + d &=0xff ; + l = &mask[d]; + + *skip =test_and_set_bit (s, l) ==1 ;return 0 ; }
Signature · 1 line
2.17.1
Quoted 124 lines · Jin Yao
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported --per-die aggregation yet.
One issue is found in
check_per_pkg()for uncore events running on AP system. On cascade Lake-AP, we have:S0-D0
S0-D1
S1-D0
S1-D1But in
check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't checkdie_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not correct.root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read 1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read 1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read 1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read 2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read 2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read 2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read 2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read 3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read 3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read 3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read 3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read 4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read 4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read 4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read 4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read 5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read 5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read 5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read 5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_readFrom above output, we can see S0-D1 and S1-D1 don't report the interval values, they are continued to grow. That's because
check_per_pkg()wrongly decides to use zero counts for S0-D1 and S1-D1.So in
check_per_pkg(), we should use a pair ofdie_id+socket_idto decide if this cpu counts needs to skip. Only consideringsocket_idis not enough.Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001622560 S0-D0 1 1210176 Bytes llc_misses.mem_read 1.001622560 S0-D1 1 950208 Bytes llc_misses.mem_read 1.001622560 S1-D0 1 968704 Bytes llc_misses.mem_read 1.001622560 S1-D1 1 1113280 Bytes llc_misses.mem_read 2.004399430 S0-D0 1 1258560 Bytes llc_misses.mem_read 2.004399430 S0-D1 1 1011008 Bytes llc_misses.mem_read 2.004399430 S1-D0 1 1036544 Bytes llc_misses.mem_read 2.004399430 S1-D1 1 1237376 Bytes llc_misses.mem_read 3.006535657 S0-D0 1 1036608 Bytes llc_misses.mem_read 3.006535657 S0-D1 1 906560 Bytes llc_misses.mem_read 3.006535657 S1-D0 1 994112 Bytes llc_misses.mem_read 3.006535657 S1-D1 1 1025472 Bytes llc_misses.mem_read 4.008934402 S0-D0 1 1005120 Bytes llc_misses.mem_read 4.008934402 S0-D1 1 882368 Bytes llc_misses.mem_read 4.008934402 S1-D0 1 961408 Bytes llc_misses.mem_read 4.008934402 S1-D1 1 988352 Bytes llc_misses.mem_read 5.001605406 S0-D0 1 1930240 Bytes llc_misses.mem_read 5.001605406 S0-D1 1 1134272 Bytes llc_misses.mem_read 5.001605406 S1-D0 1 1531136 Bytes llc_misses.mem_read 5.001605406 S1-D1 1 2230848 Bytes llc_misses.mem_readOn no-die system,
die_idis 0, this patch keeps original behavior unchanged.Reported-by Huang Ying <[email protected]>Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/cpumap.h | 2 ++ tools/perf/util/stat.c | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)tools/perf/util/cpumap.h +2
-0@@ -7,6 +7,8 @@#include <internal/cpumap.h> #include <perf/cpumap.h> +#define CPU_MAP_MAX_DIE 256 +struct perf_record_cpu_map_data ;struct perf_cpu_map *perf_cpu_map__empty_new (int nr);tools/perf/util/stat.c +5
-4@@ -282,9 +282,9 @@ static void zero_per_pkg(struct evsel *counter)static int check_per_pkg (struct evsel *counter,struct perf_counts_values *vals,int cpu,bool *skip) { -unsigned long *mask = counter->per_pkg_mask; +unsigned long *mask = counter->per_pkg_mask, *l;struct perf_cpu_map *cpus =evsel__cpus (counter); -int s; +int s, d; *skip = false;@@ -295,7 +295,7 @@ static int check_per_pkg(struct evsel *counter,return 0 ;if (!mask) { - mask =zalloc (cpu__max_cpu ()); + mask =zalloc (cpu__max_cpu () *CPU_MAP_MAX_DIE );if (!mask)return -ENOMEM ;@@ -317,7 +317,20 @@ static int check_per_pkg(struct evsel *counter,if (s <0 )return -1 ; - *skip =test_and_set_bit (s, mask) ==1 ; + d =cpu_map__get_die (cpus, cpu,NULL ); +if (d <0 )
tools/perf/util/stat.c static int check_per_pkg(struct evsel *counter, · line 331
Quoted 10 lines
tools/perf/util/stat.c +10
-0+return -1 ; + +/* +* On multi-die system, die_id < 256. We use a pair +* of socket + die to identify the used bit. +* On no-die system, die_id is 0, l = &mask[0]. It doesn't +* change original "test_and_set_bit(s, mask)" behavior. +*/ + d &=0xff ; + l = &mask[d];
James is fixing the aggregation, because we could get large socket numbers:
https://lore.kernel.org/lkml/[email protected]/
I think we should fix that in here as well
maybe just use hashmap (socket,die) -> bool ?
jirka
Quoted 8 lines
tools/perf/util/stat.c +2
-0+ + *skip =test_and_set_bit (s, l) ==1 ;return 0 ; }Signature · 1 line
2.17.1
Quoted 137 lines · Jiri Olsa
Quoted 124 lines · Jin Yao
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported --per-die aggregation yet.
One issue is found in
check_per_pkg()for uncore events running on AP system. On cascade Lake-AP, we have:S0-D0
S0-D1
S1-D0
S1-D1But in
check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't checkdie_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not correct.root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read 1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read 1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read 1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read 2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read 2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read 2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read 2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read 3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read 3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read 3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read 3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read 4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read 4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read 4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read 4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read 5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read 5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read 5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read 5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_readFrom above output, we can see S0-D1 and S1-D1 don't report the interval
values, they are continued to grow. That's becausecheck_per_pkg()wrongly decides to use zero counts for S0-D1 and S1-D1.So in
check_per_pkg(), we should use a pair ofdie_id+socket_idto decide if this cpu counts needs to skip. Only consideringsocket_idis not enough.Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001622560 S0-D0 1 1210176 Bytes llc_misses.mem_read 1.001622560 S0-D1 1 950208 Bytes llc_misses.mem_read 1.001622560 S1-D0 1 968704 Bytes llc_misses.mem_read 1.001622560 S1-D1 1 1113280 Bytes llc_misses.mem_read 2.004399430 S0-D0 1 1258560 Bytes llc_misses.mem_read 2.004399430 S0-D1 1 1011008 Bytes llc_misses.mem_read 2.004399430 S1-D0 1 1036544 Bytes llc_misses.mem_read 2.004399430 S1-D1 1 1237376 Bytes llc_misses.mem_read 3.006535657 S0-D0 1 1036608 Bytes llc_misses.mem_read 3.006535657 S0-D1 1 906560 Bytes llc_misses.mem_read 3.006535657 S1-D0 1 994112 Bytes llc_misses.mem_read 3.006535657 S1-D1 1 1025472 Bytes llc_misses.mem_read 4.008934402 S0-D0 1 1005120 Bytes llc_misses.mem_read 4.008934402 S0-D1 1 882368 Bytes llc_misses.mem_read 4.008934402 S1-D0 1 961408 Bytes llc_misses.mem_read 4.008934402 S1-D1 1 988352 Bytes llc_misses.mem_read 5.001605406 S0-D0 1 1930240 Bytes llc_misses.mem_read 5.001605406 S0-D1 1 1134272 Bytes llc_misses.mem_read 5.001605406 S1-D0 1 1531136 Bytes llc_misses.mem_read 5.001605406 S1-D1 1 2230848 Bytes llc_misses.mem_readOn no-die system,
die_idis 0, this patch keeps original behavior unchanged.Reported-by Huang Ying <[email protected]>Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/cpumap.h | 2 ++ tools/perf/util/stat.c | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)tools/perf/util/cpumap.h +2
-0@@ -7,6 +7,8 @@#include <internal/cpumap.h> #include <perf/cpumap.h> +#define CPU_MAP_MAX_DIE 256 +struct perf_record_cpu_map_data ;struct perf_cpu_map *perf_cpu_map__empty_new (int nr);tools/perf/util/stat.c +5
-4@@ -282,9 +282,9 @@ static void zero_per_pkg(struct evsel *counter)static int check_per_pkg (struct evsel *counter,struct perf_counts_values *vals,int cpu,bool *skip) { -unsigned long *mask = counter->per_pkg_mask; +unsigned long *mask = counter->per_pkg_mask, *l;struct perf_cpu_map *cpus =evsel__cpus (counter); -int s; +int s, d; *skip = false;@@ -295,7 +295,7 @@ static int check_per_pkg(struct evsel *counter,return 0 ;if (!mask) { - mask =zalloc (cpu__max_cpu ()); + mask =zalloc (cpu__max_cpu () *CPU_MAP_MAX_DIE );if (!mask)return -ENOMEM ;@@ -317,7 +317,20 @@ static int check_per_pkg(struct evsel *counter,if (s <0 )return -1 ; - *skip =test_and_set_bit (s, mask) ==1 ; + d =cpu_map__get_die (cpus, cpu,NULL ); +if (d <0 )tools/perf/util/stat.c static int check_per_pkg(struct evsel *counter, · line 331
Quoted 10 lines
tools/perf/util/stat.c +10
-0+return -1 ; + +/* +* On multi-die system, die_id < 256. We use a pair +* of socket + die to identify the used bit. +* On no-die system, die_id is 0, l = &mask[0]. It doesn't +* change original "test_and_set_bit(s, mask)" behavior. +*/ + d &=0xff ; + l = &mask[d];James is fixing the aggregation, because we could get large socket numbers:
Quoted 2 lines
https://lore.kernel.org/lkml/[email protected]/
James is using "struct cpu_aggr_map" to replace "struct perf_cpu_map", but do we also need to replace the "struct perf_cpu_map" in "struct perf_evsel"? Otherwise the evsel->cpus will be inconsistent, right?
struct perf_evsel {
...
struct perf_cpu_map *cpus;
struct perf_cpu_map *own_cpus;
...
};Quoted 1 line
I think we should fix that in here as well
Yes, we need to fix that in check_per_pkg() as well. As I said above, in check_per_pkg(),
struct perf_cpu_map *cpus = evsel__cpus(counter);
we should use "struct cpu_aggr_map" here.
Quoted 2 lines
maybe just use hashmap (socket,die) -> bool ?
Yes, hashmap should be better, saving more memory.
Thanks
Jin Yao
Quoted 11 lines
jirka
Quoted 8 lines
tools/perf/util/stat.c +2
-0+ + *skip =test_and_set_bit (s, l) ==1 ;return 0 ; }Signature · 1 line
2.17.1