tools/perf: Fix aggr_printout to display cpu field irrespective of core value
PATCH 1/1 tools/perf: Fix aggr_printout to display cpu field irrespective of core value
perf stat includes option to specify aggr_mode to display per-socket, per-core, per-die, per-node counter details. Also there is option -A ( AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.
Each of the aggregate mode uses the information fetched from "/sys/devices/system/cpu/cpuX/topology" like core_id, physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details like physical_package_id is restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.
In case of displaying socket or die value, there is no check done in the "aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail like physical_package_id is restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.
Result for per-socket:
<<>>
perf stat -e branches --per-socket -a true
Performance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>
Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
47,146 instructions
45,226 instructions
43,354 instructions
45,184 instructions<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.
After the fix:
<<>>
perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".
--- tools/perf/util/stat-display.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/stat-display.c +2 -4
@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",
@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Signature · 1 line
2.31.1
Quoted 67 lines · Athira Rajeev
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructions<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions
Quoted 7 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Reported-by Disha Goel<[email protected]>Signed-off-by Athira Rajeev<[email protected]>
Quoted 33 lines
--- tools/perf/util/stat-display.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +2
-4@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 81 lines · Disha Goel
This Message Is From an External Sender
This message came from outside your organization.Quoted 72 lines · Athira Rajeev
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructions<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".
Quoted 6 lines
Quoted 5 lines
Reported-by: Disha Goel
<[email protected]>Signed-off-by: Athira Rajeev
<[email protected]>Tested-by Disha Goel <[email protected]>
Hi,
Looking for review comments for this change.
Thanks
Athira
Quoted 34 lines
Quoted 34 lines
--- tools/perf/util/stat-display.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +2
-4@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 8 lines · Athira Rajeev
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,
I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
Quoted 38 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructions
Quoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Quoted 14 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions
Quoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".
Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>--- tools/perf/util/stat-display.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0
tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else
This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in df936cadfb because there is no obvious justification for the change to .core in that commit.
Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 6 lines · James Clark
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.
Quoted 6 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
The cpu value is filled in this function:
Function : aggr_cpu_id__cpu
Code: util/cpumap.c
Quoted 47 lines
Quoted 39 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsQuoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.
Quoted 8 lines
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value.
For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries platform where the value is set to -1 )
./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock # 1.018 CPUs utilized S-1-D-1-C-1 1 2 context-switches # 1.879 K/sec S-1-D-1-C-1 1 0 cpu-migrations # 0.000 /sec
Here though the value is -1, we are displaying it. Where as in case of cpu, the first column will be empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
0.88 msec cpu-clock # 1.022 CPUs utilized
2 context-switches
0 cpu-migrations
No sure, whether there are scripts out there, which consume the current format and not displaying -1 may break it. That is why we tried with change to remove check for cpu, similar to other modes like socket, die, core etc.
Also perf code ie “aggr_cpu_id__empty” in util/cpumap.c initialises the values to -1 . I was checking to see where we are mapping -1 to “to not aggregate”. What I could find is AGGR_NONE ( which is for no-aggr ) has value as zero.
Reference: defined in util/stat.h
enum aggr_mode {
AGGR_NONE,
James, can you point me to reference for that meaning if I have missed anything.
Thanks
Athira
Quoted 65 lines
Quoted 15 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsQuoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 108 lines · Athira Rajeev
Quoted 6 lines · James Clark
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Quoted 6 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
The cpu value is filled in this function:
Function :
aggr_cpu_id__cpuCode: util/cpumap.cQuoted 47 lines
Quoted 39 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsQuoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.Quoted 8 lines
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value.
For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries platform where the value is set to -1 )./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock # 1.018 CPUs utilized S-1-D-1-C-1 1 2 context-switches # 1.879 K/sec S-1-D-1-C-1 1 0 cpu-migrations # 0.000 /secHere though the value is -1, we are displaying it. Where as in case of cpu, the first column will be empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
Quoted 8 lines
0.88 msec cpu-clock # 1.022 CPUs utilized
2 context-switches
0 cpu-migrationsNo sure, whether there are scripts out there, which consume the current format and not displaying -1 may break it. That is why we tried with change to remove check for cpu, similar to other modes like socket, die, core etc.
I wouldn't worry about that because there are json and CSV modes which are machine readable, and -1 is already not always displayed. If anything this change here is also likely to break parsing by adding -1 where it wasn't before.
Quoted 10 lines
Also perf code ie “aggr_cpu_id__empty” in
util/cpumap.cinitialises the values to -1 . I was checking to see where we are mapping -1 to “to not aggregate”. What I could find isAGGR_NONE( which is for no-aggr ) has value as zero.Reference: defined in
util/stat.henum
aggr_mode{
AGGR_NONE,
That enum is never written to any of the cpumap members, that defines the mode of how to fill the cpu map instead. 0 is a valid value, for example "CPU 0". -1 is used as a special case and shouldn't be displayed IMO.
Did you see my comment in the code below about the bad merge? Could that not be related to your issue?
Or the one about fixing it in the test instead? Or failing early if the topology can't be read?
I'm still not convinced that any of the modes where -1 is printed are even working properly so it might be best to fix that rather than just the printout.
Quoted 1 line
James, can you point me to reference for that meaning if I have missed anything.
It's here:
/** Identify where counts are aggregated, -1 implies not to aggregate. */ struct aggr_cpu_id {
Quoted 70 lines
Thanks
AthiraQuoted 65 lines
Quoted 15 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsQuoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Ian Rogers
reviewerQuoted 137 lines · James Clark
Quoted 108 lines · Athira Rajeev
Quoted 6 lines · James Clark
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Quoted 6 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
The cpu value is filled in this function:
Function :
aggr_cpu_id__cpuCode: util/cpumap.cQuoted 47 lines
Quoted 39 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsQuoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.Quoted 8 lines
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value.
For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries platform where the value is set to -1 )./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock # 1.018 CPUs utilized S-1-D-1-C-1 1 2 context-switches # 1.879 K/sec S-1-D-1-C-1 1 0 cpu-migrations # 0.000 /secHere though the value is -1, we are displaying it. Where as in case of cpu, the first column will be empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
Quoted 8 lines
0.88 msec cpu-clock # 1.022 CPUs utilized
2 context-switches
0 cpu-migrationsNo sure, whether there are scripts out there, which consume the current format and not displaying -1 may break it. That is why we tried with change to remove check for cpu, similar to other modes like socket, die, core etc.
I wouldn't worry about that because there are json and CSV modes which are machine readable, and -1 is already not always displayed. If anything this change here is also likely to break parsing by adding -1 where it wasn't before.
Quoted 10 lines
Also perf code ie “aggr_cpu_id__empty” in
util/cpumap.cinitialises the values to -1 . I was checking to see where we are mapping -1 to “to not aggregate”. What I could find isAGGR_NONE( which is for no-aggr ) has value as zero.Reference: defined in
util/stat.henum
aggr_mode{
AGGR_NONE,
Quoted 7 lines
That enum is never written to any of the cpumap members, that defines the mode of how to fill the cpu map instead. 0 is a valid value, for example "CPU 0". -1 is used as a special case and shouldn't be displayed IMO.
Did you see my comment in the code below about the bad merge? Could that not be related to your issue?
I'm suspicious of this too. In Claire's patch:
case AGGR_NONE:
- if (evsel->percore && !config->percore_show_thread) {
- fprintf(config->output, "S%d-D%d-C%*d%s",
- id.socket, - id.die, - config->csv_output ? 0 : -3, - id.core, config->csv_sep);
- } else if (id.cpu.cpu > -1) {
- fprintf(config->output, "CPU%*d%s",
- config->csv_output ? 0 : -7,
- id.cpu.cpu, config->csv_sep);
+ if (config->json_output) {
+ if (evsel->percore && !config->percore_show_thread) {
+ fprintf(config->output, "\"core\" :
\"S%d-D%d-C%d\"",
+ id.socket, + id.die, + id.core);
+ } else if (id.core > -1) {
+ fprintf(config->output, "\"cpu\" : \"%d\", ",
+ id.cpu.cpu);
+ }
+ } else {
+ if (evsel->percore && !config->percore_show_thread) {
+ fprintf(config->output, "S%d-D%d-C%*d%s",
+ id.socket, + id.die, + config->csv_output ? 0 : -3, + id.core, config->csv_sep);
+ } else if (id.core > -1) {
+ fprintf(config->output, "CPU%*d%s",
+ config->csv_output ? 0 : -7,
+ id.cpu.cpu, config->csv_sep);
+ }
}
break;The old code was using "id.cpu.cpu > -1" while the new code is "id.core > -1". The value printed is id.cpu.cpu and so testing id.core makes less sense to me. Going back to the original patch:
https://lore.kernel.org/lkml/[email protected]/
case AGGR_NONE:
- if (evsel->percore && !config->percore_show_thread) {
- fprintf(config->output, "S%d-D%d-C%*d%s",
- id.socket,
- id.die,
- config->csv_output ? 0 : -3,
- id.core, config->csv_sep);
+ if (config->json_output) {
+ if (evsel->percore && !config->percore_show_thread) {
+ fprintf(config->output, "\"core\" : \"S%d-D%d-C%d\"",
+ id.socket,
+ id.die,
+ id.core);
+ } else if (id.core > -1) {
+ fprintf(config->output, "\"cpu\" : \"%d\", ",
+ evsel__cpus(evsel)->map[id.core]);
+ }
+ } else {
+ if (evsel->percore && !config->percore_show_thread) {
+ fprintf(config->output, "S%d-D%d-C%*d%s",
+ id.socket,
+ id.die,
+ config->csv_output ? 0 : -3,
+ id.core, config->csv_sep);
} else if (id.core > -1) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7, evsel__cpus(evsel)->map[id.core], config->csv_sep);
- }
+ }
+ }
+
break;
So testing the id.core isn't a bad index makes sense. However, we changed from core to CPU here:
https://lore.kernel.org/all/[email protected]/
and that was because of:
https://lore.kernel.org/r/[email protected]
So I think the code needs to test CPU and not core. Whether that is addressing the Power test failures is another matter, as James said we may need a fix in the tests for that.
Thanks,
Ian
Quoted 84 lines
Or the one about fixing it in the test instead? Or failing early if the topology can't be read?
I'm still not convinced that any of the modes where -1 is printed are even working properly so it might be best to fix that rather than just the printout.
Quoted 1 line
James, can you point me to reference for that meaning if I have missed anything.
It's here:
/** Identify where counts are aggregated, -1 implies not to aggregate. */ struct
aggr_cpu_id{Quoted 70 lines
Thanks
AthiraQuoted 65 lines
Quoted 15 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsQuoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ian Rogers
reviewerQuoted 268 lines · atrajeev
Quoted 238 lines · Ian Rogers
Quoted 143 lines · James Clark
Quoted 108 lines · Athira Rajeev
Quoted 6 lines · James Clark
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Quoted 6 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
The cpu value is filled in this function:
Function :
aggr_cpu_id__cpuCode: util/cpumap.cQuoted 47 lines
Quoted 39 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsQuoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.Quoted 8 lines
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value.
For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries platform where the value is set to -1 )./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock # 1.018 CPUs utilized S-1-D-1-C-1 1 2 context-switches # 1.879 K/sec S-1-D-1-C-1 1 0 cpu-migrations # 0.000 /secHere though the value is -1, we are displaying it. Where as in case of cpu, the first column will be empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
Quoted 8 lines
0.88 msec cpu-clock # 1.022 CPUs utilized
2 context-switches
0 cpu-migrationsNo sure, whether there are scripts out there, which consume the current format and not displaying -1 may break it. That is why we tried with change to remove check for cpu, similar to other modes like socket, die, core etc.
I wouldn't worry about that because there are json and CSV modes which are machine readable, and -1 is already not always displayed. If anything this change here is also likely to break parsing by adding -1 where it wasn't before.
Quoted 10 lines
Also perf code ie “aggr_cpu_id__empty” in
util/cpumap.cinitialises the values to -1 . I was checking to see where we are mapping -1 to “to not aggregate”. What I could find isAGGR_NONE( which is for no-aggr ) has value as zero.Reference: defined in
util/stat.henum
aggr_mode{
AGGR_NONE,That enum is never written to any of the cpumap members, that defines the mode of how to fill the cpu map instead. 0 is a valid value, for example "CPU 0". -1 is used as a special case and shouldn't be displayed
IMO.Quoted 3 lines
Did you see my comment in the code below about the bad merge? Could that
not be related to your issue?I'm suspicious of this too. In Claire's patch:
case
AGGR_NONE:(quoted diff) +2
-10- if (evsel->percore && !config->percore_show_thread) { - fprintf(config->output, "S%d-D%d-C%*d%s", - id.socket, - id.die, - config->csv_output ? 0 : -3, - id.core, config->csv_sep); - } else if (id.cpu.cpu > -1) { - fprintf(config->output, "CPU%*d%s", - config->csv_output ? 0 : -7, - id.cpu.cpu, config->csv_sep); + if (config->json_output) { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output, "\"core\" :
\"S%d-D%d-C%d\"",(quoted diff) +5
-0+ id.socket, + id.die, + id.core); + } else if (id.core > -1) { + fprintf(config->output, "\"cpu\" :\"%d\", ",
(quoted diff) +4
-0+ id.cpu.cpu); + } + } else { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output,
"S%d-D%d-C%*d%s",(quoted diff) +9
-0+ id.socket, + id.die, + config->csv_output ? 0 : -3, + id.core, config->csv_sep); + } else if (id.core > -1) { + fprintf(config->output, "CPU%*d%s", + config->csv_output ? 0 : -7, + id.cpu.cpu, config->csv_sep); + } } break;The old code was using "id.cpu.cpu > -1" while the new code is "id.core > -1". The value printed is id.cpu.cpu and so testing id.core makes less sense to me. Going back to the original patch:
https://lore.kernel.org/lkml/[email protected]/
caseAGGR_NONE:
- if (evsel->percore&& !config->percore_show_thread) {
- fprintf(config->output, "S%d-D%d-C%*d%s",
- id.socket,
- id.die,
-config->csv_output? 0 : -3,
- id.core,config->csv_sep);
+ if (config->json_output) {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "\"core\" : \"S%d-D%d-C%d\"",
+ id.socket,
+ id.die,
+ id.core);
+ } else if (id.core > -1) {
+ fprintf(config->output, "\"cpu\" : \"%d\", ",
+ evsel__cpus(evsel)->map[id.core]);
+ }
+ } else {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "S%d-D%d-C%*d%s",
+ id.socket,
+ id.die,
+config->csv_output? 0 : -3,
+ id.core,config->csv_sep);
} else if (id.core > -1) { fprintf(config->output, "CPU%*d%s",config->csv_output? 0 : -7, evsel__cpus(evsel)->map[id.core],config->csv_sep);
- }
+ }
+ }
+
break;So testing the id.core isn't a bad index makes sense. However, we changed from core to CPU here:
https://lore.kernel.org/all/[email protected]/
and that was because of:
https://lore.kernel.org/r/[email protected]Quoted 4 lines
So I think the code needs to test CPU and not core. Whether that is addressing the Power test failures is another matter, as James said we may need a fix in the tests for that.
Hi Ian, James
Thanks for the reviews and suggestions.
After checking through the original commits for id.core vs cpu check, sharing patch below to test CPU and not core.
From
4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9Mon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutperf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "
aggr_printout" inutil/stat-display.cwhich is used to print the aggregates, has a check for cpu in case ofAGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commitdf936cadfb58("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".
Quoted 7 lines
The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
Signed-off-by Athira Rajeev <[email protected]>Suggested-by James Clark <[email protected]>Suggested-by Ian Rogers <[email protected]>
The change below works on my dual socket SkylakeX:
..
85: perf stat CSV output linter :
Ok
86: perf stat csv summary test : Ok
87: perf stat JSON output linter : Ok
..
I don't see anything else out of the ordinary.
Thanks,
Ian
Quoted 134 lines
--- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/stat-display.c +1
-1@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu);}tools/perf/util/stat-display.c +1
-1@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7,id.cpu.cpu, config->csv_sep);--
2.31.1Can you suggest or help to test this patch change.
To address the test failure, as James suggested, I will handle fix in testcases and post them
as a separate patch. Plan is to add a sanity check in the tests to see if the "physical_packagge_id" ( ie socket id ) in topology points to -1 and if so skip the test. Also in parallel, checking to see how we can handle the aggregation modes to work incase of "-1" value for socket or dieThanks
AthiraQuoted 89 lines
Thanks,
IanQuoted 86 lines
Or the one about fixing it in the test instead? Or failing early if the
topology can't be read?I'm still not convinced that any of the modes where -1 is printed are even working properly so it might be best to fix that rather than just the printout.
Quoted 1 line
James, can you point me to reference for that meaning if I have missed anything.
It's here:
/** Identify where counts are aggregated, -1 implies not to
aggregate. */
structaggr_cpu_id{Quoted 70 lines
Thanks
AthiraQuoted 65 lines
Quoted 15 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsQuoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 290 lines · Ian Rogers
Quoted 268 lines · atrajeev
Quoted 238 lines · Ian Rogers
Quoted 143 lines · James Clark
Quoted 108 lines · Athira Rajeev
Quoted 6 lines · James Clark
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Quoted 6 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than anything being read from the topology file.
The cpu value is filled in this function:
Function :
aggr_cpu_id__cpuCode: util/cpumap.cQuoted 47 lines
Quoted 39 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsQuoted 7 lines
<<>>
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.Quoted 8 lines
Why would you want to print -1 out? Seems like the if statement was a good one to me, otherwise the output looks a bit broken to users. Are the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier with a failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value.
For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries platform where the value is set to -1 )./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock # 1.018 CPUs utilized S-1-D-1-C-1 1 2 context-switches # 1.879 K/sec S-1-D-1-C-1 1 0 cpu-migrations # 0.000 /secHere though the value is -1, we are displaying it. Where as in case of cpu, the first column will be empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
Quoted 8 lines
0.88 msec cpu-clock # 1.022 CPUs utilized
2 context-switches
0 cpu-migrationsNo sure, whether there are scripts out there, which consume the current format and not displaying -1 may break it. That is why we tried with change to remove check for cpu, similar to other modes like socket, die, core etc.
I wouldn't worry about that because there are json and CSV modes which are machine readable, and -1 is already not always displayed. If anything this change here is also likely to break parsing by adding -1 where it wasn't before.
Quoted 10 lines
Also perf code ie “aggr_cpu_id__empty” in
util/cpumap.cinitialises the values to -1 . I was checking to see where we are mapping -1 to “to not aggregate”. What I could find isAGGR_NONE( which is for no-aggr ) has value as zero.Reference: defined in
util/stat.henum
aggr_mode{
AGGR_NONE,That enum is never written to any of the cpumap members, that defines the mode of how to fill the cpu map instead. 0 is a valid value, for example "CPU 0". -1 is used as a special case and shouldn't be displayed
IMO.Quoted 3 lines
Did you see my comment in the code below about the bad merge? Could that
not be related to your issue?I'm suspicious of this too. In Claire's patch:
case
AGGR_NONE:(quoted diff) +2
-10- if (evsel->percore && !config->percore_show_thread) { - fprintf(config->output, "S%d-D%d-C%*d%s", - id.socket, - id.die, - config->csv_output ? 0 : -3, - id.core, config->csv_sep); - } else if (id.cpu.cpu > -1) { - fprintf(config->output, "CPU%*d%s", - config->csv_output ? 0 : -7, - id.cpu.cpu, config->csv_sep); + if (config->json_output) { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output, "\"core\" :
\"S%d-D%d-C%d\"",(quoted diff) +5
-0+ id.socket, + id.die, + id.core); + } else if (id.core > -1) { + fprintf(config->output, "\"cpu\" :\"%d\", ",
(quoted diff) +4
-0+ id.cpu.cpu); + } + } else { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output,
"S%d-D%d-C%*d%s",(quoted diff) +9
-0+ id.socket, + id.die, + config->csv_output ? 0 : -3, + id.core, config->csv_sep); + } else if (id.core > -1) { + fprintf(config->output, "CPU%*d%s", + config->csv_output ? 0 : -7, + id.cpu.cpu, config->csv_sep); + } } break;The old code was using "id.cpu.cpu > -1" while the new code is "id.core > -1". The value printed is id.cpu.cpu and so testing id.core makes less sense to me. Going back to the original patch:
https://lore.kernel.org/lkml/[email protected]/
caseAGGR_NONE:
- if (evsel->percore&& !config->percore_show_thread) {
- fprintf(config->output, "S%d-D%d-C%*d%s",
- id.socket,
- id.die,
-config->csv_output? 0 : -3,
- id.core,config->csv_sep);
+ if (config->json_output) {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "\"core\" : \"S%d-D%d-C%d\"",
+ id.socket,
+ id.die,
+ id.core);
+ } else if (id.core > -1) {
+ fprintf(config->output, "\"cpu\" : \"%d\", ",
+ evsel__cpus(evsel)->map[id.core]);
+ }
+ } else {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "S%d-D%d-C%*d%s",
+ id.socket,
+ id.die,
+config->csv_output? 0 : -3,
+ id.core,config->csv_sep);
} else if (id.core > -1) { fprintf(config->output, "CPU%*d%s",config->csv_output? 0 : -7, evsel__cpus(evsel)->map[id.core],config->csv_sep);
- }
+ }
+ }
+
break;So testing the id.core isn't a bad index makes sense. However, we changed from core to CPU here:
https://lore.kernel.org/all/[email protected]/
and that was because of:
https://lore.kernel.org/r/[email protected]Quoted 4 lines
So I think the code needs to test CPU and not core. Whether that is addressing the Power test failures is another matter, as James said we may need a fix in the tests for that.
Hi Ian, James
Thanks for the reviews and suggestions.
After checking through the original commits for id.core vs cpu check, sharing patch below to test CPU and not core.
From
4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9Mon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutperf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "
aggr_printout" inutil/stat-display.cwhich is used to print the aggregates, has a check for cpu in case ofAGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commitdf936cadfb58("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".Quoted 7 lines
The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
Signed-off-by Athira Rajeev <[email protected]>Suggested-by James Clark <[email protected]>Suggested-by Ian Rogers <[email protected]>The change below works on my dual socket SkylakeX:
..
85: perf stat CSV output linter :
Ok
86: perf stat csv summary test : Ok
87: perf stat JSON output linter : Ok
..
I don't see anything else out of the ordinary.
Quoted 3 lines
Thanks,
Ian
Hi Ian,
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Arnaldo,
Please suggest if I have to send as separate patch for the cpu check fix patch pasted above:
"tools/perf: Fix cpu check to use id.cpu.cpu in aggr_printout”
Thanks
Athira
Quoted 134 lines
Quoted 134 lines
--- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/stat-display.c +1
-1@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu);}tools/perf/util/stat-display.c +1
-1@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7,id.cpu.cpu, config->csv_sep);--
2.31.1Can you suggest or help to test this patch change.
To address the test failure, as James suggested, I will handle fix in testcases and post them
as a separate patch. Plan is to add a sanity check in the tests to see if the "physical_packagge_id" ( ie socket id ) in topology points to -1 and if so skip the test. Also in parallel, checking to see how we can handle the aggregation modes to work incase of "-1" value for socket or dieThanks
AthiraQuoted 89 lines
Thanks,
IanQuoted 86 lines
Or the one about fixing it in the test instead? Or failing early if the
topology can't be read?I'm still not convinced that any of the modes where -1 is printed are even working properly so it might be best to fix that rather than just the printout.
Quoted 1 line
James, can you point me to reference for that meaning if I have missed anything.
It's here:
/** Identify where counts are aggregated, -1 implies not to
aggregate. */
structaggr_cpu_id{Quoted 70 lines
Thanks
AthiraQuoted 65 lines
Quoted 15 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsQuoted 4 lines
<<>>
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the lack of the CPU id?
Quoted 12 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/stat-display.c +0
-0tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config *config, · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1@@ -168,10 +168,9 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed by some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 19 lines
tools/perf/util/stat-display.c +1
-3fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); - } }else {if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s",@@ -179,11 +178,10 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Quoted 309 lines · Athira Rajeev
Quoted 5 lines · Ian Rogers
On Mon, Oct 3, 2022 at 7:03 AM atrajeev <[email protected]>
Quoted 11 lines · wrote:
Quoted 11 lines · Ian Rogers
Quoted 9 lines
Quoted 7 lines · James Clark
Quoted 3 lines · Athira Rajeev
Quoted 3 lines
On 28-Sep-2022, at 9:05 PM, James Clark <[email protected]>
Quoted 15 lines · wrote:
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Hi James,
Thanks for looking at the patch and sharing review comments.
Quoted 7 lines · Athira Rajeev
Quoted 6 lines
perf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each cpu along with "CPU" value in one field of the output.Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,I thought that this wouldn't apply to the cpu field because cpu is basically interchangeable as an index in cpumap, rather than
anything
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 1 line
being read from the topology file.
The cpu value is filled in this function:
Function :
aggr_cpu_id__cpuCode: util/cpumap.cQuoted 41 lines
Quoted 41 lines
physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, cpu etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
<<>>
perf stat -e branches --per-socket -a truePerformance counter stats for 'system wide':
S-1 32 416,851 branches
<<>>Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
<<>>
/bin/perfstat -e instructions -A -a truePerformance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructions<<>>
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
If the cpu id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.Why would you want to print -1 out? Seems like the if statement was
a
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
good one to me, otherwise the output looks a bit broken to users.
Are
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the other aggregation modes even working if -1 is set for socket and die? Maybe we need to not print -1 in those cases or exit earlier
with a
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
failure.
The -1 value has a specific internal meaning which is "to not aggregate". It doesn't mean "not set".
Currently, this check is done only for printing cpu value. For socket/die/core values, this check is not done. Pasting an example snippet from a powerpc system ( specifically from pseries
platform where
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
the value is set to -1 )
./perf stat --per-core -a -C 1 true
Performance counter stats for 'system wide':
S-1-D-1-C-1 1 1.06 msec cpu-clock
# 1.018 CPUs utilized
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
S-1-D-1-C-1 1 2 context-switches
# 1.879 K/secQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
S-1-D-1-C-1 1 0 cpu-migrations
# 0.000 /secQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here though the value is -1, we are displaying it. Where as in case
of cpu, the first column will be
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
empty since we do a check before printing.
Example:
./perf stat --per-core -A -C 1 true
Performance counter stats for 'CPU(s) 1':
0.88 msec cpu-clock # 1.022
CPUs utilized
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
2 context-switches
0 cpu-migrationsNo sure, whether there are scripts out there, which consume the
current format and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
not displaying -1 may break it. That is why we tried with change to
remove check for cpu, similar to
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
other modes like socket, die, core etc.
I wouldn't worry about that because there are json and CSV modes which are machine readable, and -1 is already not always displayed. If anything this change here is also likely to break parsing by adding -1 where it wasn't before.
Quoted 2 lines
Also perf code ie “aggr_cpu_id__empty” in
util/cpumap.cinitialisesthe
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
values to -1 . I was checking to see where we are mapping -1 to “to
not aggregate”.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
What I could find is
AGGR_NONE( which is for no-aggr ) has value aszero.
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 13 lines
Quoted 6 lines
Reference: defined in
util/stat.henum
aggr_mode{
AGGR_NONE,That enum is never written to any of the cpumap members, that defines the mode of how to fill the cpu map instead. 0 is a valid value, for example "CPU 0". -1 is used as a special case and shouldn't be displayed
IMO.Quoted 3 lines
Did you see my comment in the code below about the bad merge? Could that
not be related to your issue?I'm suspicious of this too. In Claire's patch:
case
AGGR_NONE:(quoted diff) +2
-10- if (evsel->percore && !config->percore_show_thread) { - fprintf(config->output, "S%d-D%d-C%*d%s", - id.socket, - id.die, - config->csv_output ? 0 : -3, - id.core, config->csv_sep); - } else if (id.cpu.cpu > -1) { - fprintf(config->output, "CPU%*d%s", - config->csv_output ? 0 : -7, - id.cpu.cpu, config->csv_sep); + if (config->json_output) { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output, "\"core\" :
\"S%d-D%d-C%d\"",(quoted diff) +5
-0+ id.socket, + id.die, + id.core); + } else if (id.core > -1) { + fprintf(config->output, "\"cpu\" :\"%d\", ",
(quoted diff) +4
-0+ id.cpu.cpu); + } + } else { + if (evsel->percore &&!config->percore_show_thread) {
+ fprintf(config->output,
"S%d-D%d-C%*d%s",(quoted diff) +9
-0+ id.socket, + id.die, + config->csv_output ? 0 : -3, + id.core, config->csv_sep); + } else if (id.core > -1) { + fprintf(config->output, "CPU%*d%s", + config->csv_output ? 0 : -7, + id.cpu.cpu, config->csv_sep); + } } break;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
The old code was using "id.cpu.cpu > -1" while the new code is "id.core > -1". The value printed is id.cpu.cpu and so testing id.core makes less sense to me. Going back to the original patch:
https://lore.kernel.org/lkml/[email protected]/
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
case
AGGR_NONE:
- if (evsel->percore&& !config->percore_show_thread) {
- fprintf(config->output, "S%d-D%d-C%*d%s",
- id.socket,
- id.die,
-config->csv_output? 0 : -3,
- id.core,config->csv_sep);
+ if (config->json_output) {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "\"core\" : \"S%d-D%d-C%d\"",
+ id.socket,
+ id.die,
+ id.core);
+ } else if (id.core > -1) {
+ fprintf(config->output, "\"cpu\" : \"%d\", ",
+ evsel__cpus(evsel)->map[id.core]);
+ }
+ } else {
+ if (evsel->percore&& !config->percore_show_thread) {
+ fprintf(config->output, "S%d-D%d-C%*d%s",
+ id.socket,
+ id.die,
+config->csv_output? 0 : -3,
+ id.core,config->csv_sep);
} else if (id.core > -1) { fprintf(config->output, "CPU%*d%s",config->csv_output? 0 : -7, evsel__cpus(evsel)->map[id.core],config->csv_sep);
- }
+ }
+ }
+
break;Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
So testing the id.core isn't a bad index makes sense. However, we changed from core to CPU here:
https://lore.kernel.org/all/[email protected]/
Quoted 48 lines
Quoted 31 lines
Quoted 7 lines
and that was because of:
https://lore.kernel.org/r/[email protected]So I think the code needs to test CPU and not core. Whether that is addressing the Power test failures is another matter, as James said we may need a fix in the tests for that.
Hi Ian, James
Thanks for the reviews and suggestions.
After checking through the original commits for id.core vs cpu check, sharing patch below to test CPU and not core.
From
4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9Mon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutperf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "
aggr_printout" inutil/stat-display.cwhich is used to print the aggregates, has a check for cpu in case ofAGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commitdf936cadfb58("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".Quoted 7 lines
The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
Signed-off-by Athira Rajeev <[email protected]>Suggested-by James Clark <[email protected]>Suggested-by Ian Rogers <[email protected]>The change below works on my dual socket SkylakeX:
..
85: perf stat CSV output linter :
Ok
86: perf stat csv summary test : Ok
87: perf stat JSON output linter : Ok
..
I don't see anything else out of the ordinary.
Quoted 7 lines
Quoted 3 lines
Thanks,
IanHi Ian,
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Yep.
Thanks,
Ian
Arnaldo,
Quoted 152 lines
Please suggest if I have to send as separate patch for the cpu check fix patch pasted above:
"tools/perf: Fix cpu check to use id.cpu.cpu in aggr_printout”Thanks
AthiraQuoted 4 lines
Quoted 4 lines
--- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 13 lines
tools/perf/util/stat-display.c static void aggr_printout(struct perf_stat_config · line 173
Quoted 13 lines
tools/perf/util/stat-display.c +1
-1@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "\"cpu\" :\"%d\", ",
Quoted 35 lines
Quoted 35 lines
tools/perf/util/stat-display.c +0
-0id.cpu.cpu);}tools/perf/util/stat-display.c +1
-1@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7,id.cpu.cpu, config->csv_sep);--
2.31.1Can you suggest or help to test this patch change.
To address the test failure, as James suggested, I will handle fix in testcases and post them
as a separate patch. Plan is to add a sanity check in the tests to see if the "physical_packagge_id" ( ie socket id ) in topology points to -1 and if so skip the test. Also in parallel, checking to see how we can handle the aggregation modes to work incase of "-1" value for socket or dieThanks
AthiraQuoted 7 lines
Thanks,
IanQuoted 4 lines
Or the one about fixing it in the test instead? Or failing early if the
topology can't be read?Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
I'm still not convinced that any of the modes where -1 is printed are even working properly so it might be best to fix that rather than just the printout.
Quoted 1 line
James, can you point me to reference for that meaning if I have
missed anything.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
It's here:
/** Identify where counts are aggregated, -1 implies not to
aggregate. */
structaggr_cpu_id{Quoted 21 lines
Thanks
AthiraQuoted 17 lines
Quoted 17 lines
After the fix:
<<>>
perf stat -e instructions -A -a truePerformance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions<<>>
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
This is caught while running "perf test" for
"stat+json_output.sh" and "stat+csv_output.sh".Is it possible to fix the issue by making the tests cope with the
lack
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
of the CPU id?
Review
Quoted 8 lines
Reported-by Disha Goel <[email protected]>Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/util/stat-display.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/tools/perf/util/stat-display.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
tools/perf/util/stat-display.c static void aggr_printout(struct
Quoted 4 lines
index
b82844cb0ce7..1b751a730271100644tools/perf/util/stat-display.c +0
-0@@ -168,10 +168,9 @@ static void aggr_printout(struct
perf_stat_config*config,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
tools/perf/util/stat-display.c static void aggr_printout(struct · line 171
Quoted 5 lines
tools/perf/util/stat-display.c +1
-1id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else This should have been "id.cpu.cpu > -1". Looks like it was changed
by
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
some kind of bad merge or rebase in
df936cadfbbecause there is no obvious justification for the change to .core in that commit.Quoted 1 line
tools/perf/util/stat-display.c +0
-0fprintf(config->output, "\"cpu\" :\"%d\", ",
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
tools/perf/util/stat-display.c static void aggr_printout(struct · line 175
Quoted 4 lines
tools/perf/util/stat-display.c +0
-1id.cpu.cpu); - } }else { if (evsel->percore &&!config->percore_show_thread) {
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
tools/perf/util/stat-display.c static void aggr_printout(struct · line 176
Quoted 1 line
tools/perf/util/stat-display.c +0
-0fprintf(config->output,"S%d-D%d-C%*d%s",
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
tools/perf/util/stat-display.c static void aggr_printout(struct
Quoted 1 line
tools/perf/util/stat-display.c +0
-0@@ -179,11 +178,10 @@ static void aggr_printout(struct
perf_stat_config*config,Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
tools/perf/util/stat-display.c +1
-2id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep); - } }break ;case AGGR_THREAD :
Arnaldo Carvalho de Melo
maintainerEm Tue, Oct 04, 2022 at 07:49:21AM -0700, Ian Rogers escreveu:
Quoted 9 lines
On Tue, Oct 4, 2022, 12:06 AM Athira Rajeev <[email protected]>
Quoted 1 line
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Yep.
Tested-by Ian Rogers <[email protected]>Thanks,
Ian
Em Tue, Oct 04, 2022 at 03:14:27PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 7 lines
Em Tue, Oct 04, 2022 at 07:49:21AM -0700, Ian Rogers escreveu:
Quoted 6 lines
On Tue, Oct 4, 2022, 12:06 AM Athira Rajeev <[email protected]>
Quoted 1 line
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Yep.
Tested-by Ian Rogers <[email protected]>
Thanks, applied.
- Arnaldo
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Tue, Oct 04, 2022 at 03:14:27PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 4 lines
Em Tue, Oct 04, 2022 at 07:49:21AM -0700, Ian Rogers escreveu:
Quoted 2 lines
On Tue, Oct 4, 2022, 12:06 AM Athira Rajeev <[email protected]>
Quoted 1 line
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Yep.
Tested-by Ian Rogers <[email protected]>Thanks, applied.
- Arnaldo
Hi Arnaldo,
Looks like you have taken change to remove id.core check:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/core&id=db83f447b323958cdc5fedcf2134effb2ec9a6fe
But the patch that has to go in is :
"[PATCH] tools/perf: Fix cpu check to use id.cpu.cpu in ggr_printout" which is tested by Ian and "pasted" by me in same mail thread.
Re-pasting here for reference:
From 4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9 Mon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH] tools/perf: Fix cpu check to use id.cpu.cpu in aggr_printout
perf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "aggr_printout" in util/stat-display.c which is used to print the aggregates, has a check for cpu in case of AGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commit df936cadfb58 ("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".
The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
---tools/perf/util/stat-display.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/stat-display.c +0 -0
@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config,
id.socket,
id.die,
id.core);
- } else if (id.core > -1) {
+ } else if (id.cpu.cpu > -1) {
fprintf(config->output, "\"cpu\" : \"%d\", ",
id.cpu.cpu);
}
@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config,
id.die,
config->csv_output ? 0 : -3,
id.core, config->csv_sep);
- } else if (id.core > -1) {
+ } else if (id.cpu.cpu > -1) {
fprintf(config->output, "CPU%*d%s",
config->csv_output ? 0 : -7,
id.cpu.cpu, config->csv_sep);Signature · 8 lines
2.31.1 If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ? Please revert https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/core&id=db83f447b323958cdc5fedcf2134effb2ec9a6fe Thanks Athira
Quoted 1 line
Arnaldo Carvalho de Melo
maintainerEm Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 83 lines
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Tue, Oct 04, 2022 at 03:14:27PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 4 lines
Em Tue, Oct 04, 2022 at 07:49:21AM -0700, Ian Rogers escreveu:
Quoted 2 lines
On Tue, Oct 4, 2022, 12:06 AM Athira Rajeev <[email protected]>
Quoted 1 line
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Yep.
Tested-by Ian Rogers <[email protected]>Thanks, applied.
- Arnaldo
Hi Arnaldo,
Looks like you have taken change to remove id.core check:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/core&id=db83f447b323958cdc5fedcf2134effb2ec9a6feBut the patch that has to go in is :
"[PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inggr_printout" which is tested by Ian and "pasted" by me in same mail thread.Re-pasting here for reference:
Quoted 1 line
From
4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9Mon Sep 17 00:00:00 2001From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutperf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "
aggr_printout" inutil/stat-display.cwhich is used to print the aggregates, has a check for cpu in case ofAGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commitdf936cadfb58("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
Signed-off-by Athira Rajeev <[email protected]>Suggested-by James Clark <[email protected]>Suggested-by Ian Rogers <[email protected]>---
tools/perf/util/stat-display.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 5 lines
2.31.1 If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ? Please revert https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/core&id=db83f447b323958cdc5fedcf2134effb2ec9a6fe
I'll do it, but in these cases just go ahead and resubmit with a v N+1 patchset, so that b4 can pick the newer version even if I point it to the previous version message-id.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 81 lines
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Tue, Oct 04, 2022 at 03:14:27PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 4 lines
Em Tue, Oct 04, 2022 at 07:49:21AM -0700, Ian Rogers escreveu:
Quoted 2 lines
On Tue, Oct 4, 2022, 12:06 AM Athira Rajeev <[email protected]>
Quoted 1 line
Thanks for helping with testing. Can I add your Tested-by for the patch ?
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Yep.
Tested-by Ian Rogers <[email protected]>Thanks, applied.
- Arnaldo
Hi Arnaldo,
Looks like you have taken change to remove id.core check:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=tmp.perf/core&id=db83f447b323958cdc5fedcf2134effb2ec9a6feBut the patch that has to go in is :
"[PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inggr_printout" which is tested by Ian and "pasted" by me in same mail thread.Re-pasting here for reference:
Quoted 1 line
From
4dd98d953940deb2f85176cb6b4ecbfd18dbdbf9Mon Sep 17 00:00:00 2001From: Athira Rajeev <[email protected]>
Date: Mon, 3 Oct 2022 15:47:27 +0530
Subject: [PATCH]tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutperf stat has options to aggregate the counts in different modes like per socket, per core etc. The function "
aggr_printout" inutil/stat-display.cwhich is used to print the aggregates, has a check for cpu in case ofAGGR_NONE. This check was originally using condition : "if (id.cpu.cpu > -1)". But this got changed after commitdf936cadfb58("perf stat: Add JSON output option"), which added option to output json format for different aggregation modes. After this commit, the check in "aggr_printout" is using "if (id.core > -1)".The old code was using "id.cpu.cpu > -1" while the new code is using "id.core > -1". But since the value printed is id.cpu.cpu, fix this check to use cpu and not core.
Signed-off-by Athira Rajeev <[email protected]>Suggested-by James Clark <[email protected]>Suggested-by Ian Rogers <[email protected]>---
tools/perf/util/stat-display.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 3 lines
2.31.1 If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ?
I'll have to do this by hand, tried pointing b4 to this message and it picked the old one, also tried to save the message and apply by hand, its mangled.
- Arnaldo
Quoted 5 lines
Thanks
AthiraQuoted 1 line
Signature · 1 line
- Arnaldo
Em Wed, Oct 05, 2022 at 09:28:52AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 20 lines
tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s",
Quoted 8 lines
Quoted 4 lines
tools/perf/util/stat-display.c +0
-0config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 1 line
If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ?I'll have to do this by hand, tried pointing b4 to this message and it picked the old one, also tried to save the message and apply by hand, its mangled.
This is what I have now, will force push later, please triple check :-)
- Arnaldo
From b7dd96f9211e4ddbd6fa080da8dec2eac98d3f2a Mon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Tue, 13 Sep 2022 17:27:17 +0530
Subject: [PATCH 1/1] perf stat: Fix aggr_printout to display CPU field
irrespective of core value
perf stat includes option to specify aggr_mode to display per-socket, per-core, per-die, per-node counter details. Also there is option -A ( AGGR_NONE, -no-aggr ), where the counter values are displayed for each CPU along with "CPU" value in one field of the output.
Each of the aggregate mode uses the information fetched from "/sys/devices/system/cpu/cpuX/topology" like core_id, physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, CPU etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details like physical_package_id is restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.
In case of displaying socket or die value, there is no check done in the "aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail like physical_package_id is restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.
Result for per-socket:
perf stat -e branches --per-socket -a true
Performance counter stats for 'system wide':
S-1 32 416,851 branches
Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
47,146 instructions
45,226 instructions
43,354 instructions
45,184 instructionsIf the CPU id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.
After the fix:
perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructions
This is caught while running "perf test" for "stat+json_output.sh" and "stat+csv_output.sh".
--- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/stat-display.c +2 -2
@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }
@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);
Signature · 1 line
2.37.3
Quoted 35 lines · Arnaldo Carvalho de Melo
Em Wed, Oct 05, 2022 at 09:28:52AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 20 lines
tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s",Quoted 8 lines
Quoted 4 lines
tools/perf/util/stat-display.c +0
-0config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 1 line
If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ?I'll have to do this by hand, tried pointing b4 to this message and it picked the old one, also tried to save the message and apply by hand, its mangled.
Quoted 1 line
This is what I have now, will force push later, please triple check :-)
Sorry for all the confusion Arnaldo. Hereafter, I will resubmit the patch to avoid this. In below patch which you shared, code change is correct. But commit message is different. So to avoid further confusion, I went ahead and posted a separate patch in the mailing list with:
subject: [PATCH] tools/perf: Fix cpu check to use id.cpu.cpu in aggr_printout Patch link: https://lore.kernel.org/lkml/[email protected]/T/#u
Please pick the separately send patch.
Thanks
Athira
Quoted 114 lines
- Arnaldo
From
b7dd96f9211e4ddbd6fa080da8dec2eac98d3f2aMon Sep 17 00:00:00 2001
From: Athira Rajeev <[email protected]>
Date: Tue, 13 Sep 2022 17:27:17 +0530
Subject: [PATCH 1/1] perf stat: Fixaggr_printoutto display CPU field irrespective of core valueperf stat includes option to specify
aggr_modeto display per-socket, per-core, per-die, per-node counter details. Also there is option -A (AGGR_NONE, -no-aggr ), where the counter values are displayed for each CPU along with "CPU" value in one field of the output.Each of the aggregate mode uses the information fetched from "
/sys/devices/system/cpu/cpuX/topology" likecore_id,physical_package_id. Utility functions in "cpumap.c" fetches this information and populates the socket id, core id, CPU etc. If the platform does not expose the topology information, these values will be set to -1. Example, in case of powerpc, details likephysical_package_idis restricted to be exposed in pSeries platform. So id.socket, id.core, id.cpu all will be set as -1.In case of displaying socket or die value, there is no check done in the "
aggr_printout" function to see if it points to valid socket id or die. But for displaying "cpu" value, there is a check for "if (id.core > -1)". In case of powerpc pSeries where detail likephysical_package_idis restricted to be exposed, id.core will be set to -1. Hence the column or field itself for CPU won't be displayed in the output.Result for per-socket:
perf stat -e branches --per-socket -a true
Performance counter stats for 'system wide':
S-1 32 416,851 branches
Here S has -1 in above result. But with -A option which also expects CPU in one column in the result, below is observed.
perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
47,146 instructions 45,226 instructions 43,354 instructions 45,184 instructionsIf the CPU id value is pointing to -1 also, it makes sense to display the column in the output to replicate the behaviour or to be in precedence with other aggr
options(like per-socket, per-core). Remove the check "id.core" so that CPU field gets displayed in the output.After the fix:
perf stat -e instructions -A -a true
Performance counter stats for 'system wide':
CPU-1 64,034 instructions CPU-1 68,941 instructions CPU-1 59,418 instructions CPU-1 70,478 instructions CPU-1 65,201 instructions CPU-1 63,704 instructionsThis is caught while running "perf test" for "
stat+json_output.sh" and "stat+csv_output.sh".Reported-by Disha Goel <[email protected]>Suggested-by Ian Rogers <[email protected]>Suggested-by James Clark <[email protected]>Signed-off-by Athira Jajeev <[email protected]>Tested-by Disha Goel <[email protected]>Tested-by Ian Rogers <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kajol Jain <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nageswara R Sastry <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>---
tools/perf/util/stat-display.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"CPU%*d%s" , config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 1 line
2.37.3
Arnaldo Carvalho de Melo
maintainerEm Thu, Oct 06, 2022 at 06:16:14PM +0530, Athira Rajeev escreveu:
Quoted 38 lines
Quoted 35 lines · Arnaldo Carvalho de Melo
Em Wed, Oct 05, 2022 at 09:28:52AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 20 lines
tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s",Quoted 8 lines
Quoted 4 lines
tools/perf/util/stat-display.c +0
-0config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 1 line
If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ?I'll have to do this by hand, tried pointing b4 to this message and it picked the old one, also tried to save the message and apply by hand, its mangled.
Quoted 1 line
This is what I have now, will force push later, please triple check :-)
Quoted 8 lines
Sorry for all the confusion Arnaldo. Hereafter, I will resubmit the patch to avoid this. In below patch which you shared, code change is correct. But commit message is different. So to avoid further confusion, I went ahead and posted a separate patch in the mailing list with:
subject: [PATCH]
tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutPatch link: https://lore.kernel.org/lkml/[email protected]/T/#uPlease pick the separately send patch.
Ok, will do.
- Arnaldo
Quoted 47 lines · Arnaldo Carvalho de Melo
Em Thu, Oct 06, 2022 at 06:16:14PM +0530, Athira Rajeev escreveu:
Quoted 42 lines
Quoted 35 lines · Arnaldo Carvalho de Melo
Em Wed, Oct 05, 2022 at 09:28:52AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 21 lines
Em Wed, Oct 05, 2022 at 10:23:39AM +0530, Athira Rajeev escreveu:
Quoted 20 lines
tools/perf/util/stat-display.c +2
-2@@ -168,7 +168,7 @@ static void aggr_printout(struct perf_stat_config *config, id.socket, id.die, id.core); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) {fprintf (config->output,"\"cpu\" : \"%d\", " , id.cpu.cpu); }@@ -179,7 +179,7 @@ static void aggr_printout(struct perf_stat_config *config, id.die, config->csv_output ?0 :-3 , id.core, config->csv_sep); - }else if (id.core >-1 ) { + }else if (id.cpu.cpu >-1 ) { fprintf(config->output, "CPU%*d%s",Quoted 8 lines
Quoted 4 lines
tools/perf/util/stat-display.c +0
-0config->csv_output ?0 :-7 , id.cpu.cpu, config->csv_sep);Signature · 1 line
If it is confusing, shall I send it as a separate patch along with Tested-by from Ian ?I'll have to do this by hand, tried pointing b4 to this message and it picked the old one, also tried to save the message and apply by hand, its mangled.
Quoted 1 line
This is what I have now, will force push later, please triple check :-)
Sorry for all the confusion Arnaldo. Hereafter, I will resubmit the patch to avoid this. In below patch which you shared, code change is correct. But commit message is different. So to avoid further confusion, I went ahead and posted a separate patch in the mailing list with:
Quoted 6 lines
Quoted 4 lines
subject: [PATCH]
tools/perf: Fix cpu check to use id.cpu.cpu inaggr_printoutPatch link: https://lore.kernel.org/lkml/[email protected]/T/#uPlease pick the separately send patch.
Ok, will do.
Thanks Arnaldo.
Quoted 2 lines
- Arnaldo