perf stat: Metrics calculation fix
Jiri Olsa
reviewercover perf stat: Metrics calculation fix
hi,
I'm sending Andi's patch accompanied with changes requested by Ingo.
http://marc.info/?l=linux-kernel&m=139748629929175&w=2
I added simple bit calculated index array, while exclude_* bits might have more strict logic and ban some combinations, but I wanted to keep it simple and did not find better solution.
thanks,
jirka
---
Andi Kleen (1):
perf stat: Fix metrics calculation with event qualifiers
Jiri Olsa (5):
perf tools: Add 'I' event modifier for exclude_idle bit perf stat: Change metrics context calculation perf stat: Add metrics support for exclude_hv perf stat: Add metrics support for exclude_(host|guest) perf stat: Add metrics support for exclude_idle
tools/perf/Documentation/perf-list.txt | 1 + tools/perf/builtin-stat.c | 144 +++++++++++++++++++++++++++++++++++++++++------------------------ tools/perf/tests/parse-events.c | 40 ++++++++++++++++++ tools/perf/util/parse-events.c | 8 +++- tools/perf/util/parse-events.l | 2 +- 5 files changed, 141 insertions(+), 54 deletions(-)
Jiri Olsa
reviewerPATCH 1/6 perf tools: Add 'I' event modifier for exclude_idle bit
Adding 'I' event modifier to have complete set of modifiers for perf_event_attr:exclude_* bits.
Any event specified with 'I' modifier will have the perf_event_attr:exclude_idle bit set.
$ perf record -e cycles:I -vv ls 2>&1 | grep exclude_idle exclude_hv 0 exclude_idle 1
Adding automated tests.
--- tools/perf/Documentation/perf-list.txt | 1 + tools/perf/tests/parse-events.c | 40 ++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 8 ++++++- tools/perf/util/parse-events.l | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-list.txt +1 -0
@@ -26,6 +26,7 @@ counted. The following modifiers exist: u - user-space counting k - kernel counting h - hypervisor counting + I - non idle counting G - guest counting (in KVM guests) H - host counting (not in KVM guests) p - precise level
tools/perf/tests/parse-events.c +40 -0
@@ -295,6 +295,36 @@ static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)return test__checkevent_genhw (evlist); } +static int test__checkevent_exclude_idle_modifier (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel =perf_evlist__first (evlist); + +TEST_ASSERT_VAL ("wrong exclude idle" , evsel->attr.exclude_idle); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); + +return test__checkevent_symbolic_name (evlist); +} + +static int test__checkevent_exclude_idle_modifier_1 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel =perf_evlist__first (evlist); + +TEST_ASSERT_VAL ("wrong exclude idle" , evsel->attr.exclude_idle); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong exclude_user" , evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); + +return test__checkevent_symbolic_name (evlist); +} +static int test__checkevent_breakpoint_modifier (struct perf_evlist *evlist) {struct perf_evsel *evsel =perf_evlist__first (evlist);
@@ -1494,6 +1524,16 @@ static struct evlist_test test__events[] = { .id = 100, },#endif + { + .name = "instructions:I", + .check = test__checkevent_exclude_idle_modifier, + .id = 45, + }, + { + .name = "instructions:kIG", + .check = test__checkevent_exclude_idle_modifier_1, + .id = 46, + }, }; static struct evlist_test test__events_pmu[] = {
tools/perf/util/parse-events.c +7 -1
@@ -709,6 +709,7 @@ struct event_modifier {int eh;int eH;int eG; +int eI;int precise;int exclude_GH;int sample_read;
@@ -723,6 +724,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,int eh = evsel ? evsel->attr.exclude_hv :0 ;int eH = evsel ? evsel->attr.exclude_host :0 ;int eG = evsel ? evsel->attr.exclude_guest :0 ; +int eI = evsel ? evsel->attr.exclude_idle :0 ;int precise = evsel ? evsel->attr.precise_ip :0 ;int sample_read =0 ;int pinned = evsel ? evsel->attr.pinned :0 ;
@@ -753,6 +755,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,if (!exclude_GH) exclude_GH = eG = eH =1 ; eH =0 ; + }else if (*str =='I' ) { + eI =1 ; }else if (*str =='p' ) { precise++;/* use of precise requires exclude_guest */
@@ -786,6 +790,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, mod->eh = eh; mod->eH = eH; mod->eG = eG; + mod->eI = eI; mod->precise = precise; mod->exclude_GH = exclude_GH; mod->sample_read = sample_read;
@@ -803,7 +808,7 @@ static int check_modifier(char *str)char *p = str;/* The sizeof includes 0 byte as well. */ -if (strlen (str) > (sizeof ("ukhGHpppSD" ) -1 )) +if (strlen (str) > (sizeof ("ukhGHpppSDI" ) -1 ))return -1 ;while (*p) {
@@ -839,6 +844,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add) evsel->attr.precise_ip = mod.precise; evsel->attr.exclude_host = mod.eH; evsel->attr.exclude_guest = mod.eG; + evsel->attr.exclude_idle = mod.eI; evsel->exclude_GH = mod.exclude_GH; evsel->sample_read = mod.sample_read;
tools/perf/util/parse-events.l +1 -1
@@ -101,7 +101,7 @@ num_raw_hex [a-fA-F0-9]+ name [a-zA-Z_*?][a-zA-Z0-9_*?]* name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]* /* If you add a modifier you need to update check_modifier() */ -modifier_event [ukhpGHSD]+ +modifier_event [ukhpGHSDI]+ modifier_bp [rwx]{1,3} %%
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/6] perf tools: Add 'I' event modifier for exclude_idle bit
Em Tue, Apr 07, 2015 at 11:25:14PM +0200, Jiri Olsa escreveu:
Quoted 10 lines
Adding 'I' event modifier to have complete set of modifiers for perf_event_attr:exclude_* bits.
Any event specified with 'I' modifier will have the perf_event_attr:exclude_idle bit set.
$ perf record -e cycles:I -vv ls 2>&1 | grep exclude_idle exclude_hv 0 exclude_idle 1Adding automated tests.
Applied this one, waiting for an Ack from Andi, as you asked for,
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add 'I' event modifier for exclude_idle bit
In reply to Jiri Olsaperf tools: Add 'I' event modifier for exclude_idle bit
Commit-ID: a1e12da4796a4ddd0e911687a290eb396d1c64bf Gitweb: http://git.kernel.org/tip/a1e12da4796a4ddd0e911687a290eb396d1c64bf Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:14 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 8 Apr 2015 11:00:16 -0300
perf tools: Add 'I' event modifier for exclude_idle bit
Adding 'I' event modifier to have complete set of modifiers for perf_event_attr:exclude_* bits.
Any event specified with 'I' modifier will have the perf_event_attr:exclude_idle bit set.
$ perf record -e cycles:I -vv ls 2>&1 | grep exclude_idle exclude_hv 0 exclude_idle 1
Adding automated tests.
--- tools/perf/Documentation/perf-list.txt | 1 + tools/perf/tests/parse-events.c | 40 ++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 8 ++++++- tools/perf/util/parse-events.l | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-list.txt +1 -0
@@ -26,6 +26,7 @@ counted. The following modifiers exist: u - user-space counting k - kernel counting h - hypervisor counting + I - non idle counting G - guest counting (in KVM guests) H - host counting (not in KVM guests) p - precise level
tools/perf/tests/parse-events.c +40 -0
@@ -295,6 +295,36 @@ static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)return test__checkevent_genhw (evlist); } +static int test__checkevent_exclude_idle_modifier (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel =perf_evlist__first (evlist); + +TEST_ASSERT_VAL ("wrong exclude idle" , evsel->attr.exclude_idle); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); + +return test__checkevent_symbolic_name (evlist); +} + +static int test__checkevent_exclude_idle_modifier_1 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel =perf_evlist__first (evlist); + +TEST_ASSERT_VAL ("wrong exclude idle" , evsel->attr.exclude_idle); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong exclude_user" , evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); + +return test__checkevent_symbolic_name (evlist); +} +static int test__checkevent_breakpoint_modifier (struct perf_evlist *evlist) {struct perf_evsel *evsel =perf_evlist__first (evlist);
@@ -1494,6 +1524,16 @@ static struct evlist_test test__events[] = { .id = 100, },#endif + { + .name = "instructions:I", + .check = test__checkevent_exclude_idle_modifier, + .id = 45, + }, + { + .name = "instructions:kIG", + .check = test__checkevent_exclude_idle_modifier_1, + .id = 46, + }, }; static struct evlist_test test__events_pmu[] = {
tools/perf/util/parse-events.c +7 -1
@@ -709,6 +709,7 @@ struct event_modifier {int eh;int eH;int eG; +int eI;int precise;int exclude_GH;int sample_read;
@@ -723,6 +724,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,int eh = evsel ? evsel->attr.exclude_hv :0 ;int eH = evsel ? evsel->attr.exclude_host :0 ;int eG = evsel ? evsel->attr.exclude_guest :0 ; +int eI = evsel ? evsel->attr.exclude_idle :0 ;int precise = evsel ? evsel->attr.precise_ip :0 ;int sample_read =0 ;int pinned = evsel ? evsel->attr.pinned :0 ;
@@ -753,6 +755,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,if (!exclude_GH) exclude_GH = eG = eH =1 ; eH =0 ; + }else if (*str =='I' ) { + eI =1 ; }else if (*str =='p' ) { precise++;/* use of precise requires exclude_guest */
@@ -786,6 +790,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, mod->eh = eh; mod->eH = eH; mod->eG = eG; + mod->eI = eI; mod->precise = precise; mod->exclude_GH = exclude_GH; mod->sample_read = sample_read;
@@ -803,7 +808,7 @@ static int check_modifier(char *str)char *p = str;/* The sizeof includes 0 byte as well. */ -if (strlen (str) > (sizeof ("ukhGHpppSD" ) -1 )) +if (strlen (str) > (sizeof ("ukhGHpppSDI" ) -1 ))return -1 ;while (*p) {
@@ -839,6 +844,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add) evsel->attr.precise_ip = mod.precise; evsel->attr.exclude_host = mod.eH; evsel->attr.exclude_guest = mod.eG; + evsel->attr.exclude_idle = mod.eI; evsel->exclude_GH = mod.exclude_GH; evsel->sample_read = mod.sample_read;
tools/perf/util/parse-events.l +1 -1
@@ -101,7 +101,7 @@ num_raw_hex [a-fA-F0-9]+ name [a-zA-Z_*?][a-zA-Z0-9_*?]* name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]* /* If you add a modifier you need to update check_modifier() */ -modifier_event [ukhpGHSD]+ +modifier_event [ukhpGHSDI]+ modifier_bp [rwx]{1,3} %%
Jiri Olsa
reviewerPATCH 2/6 perf stat: Fix metrics calculation with event qualifiers
In reply to Jiri OlsaFrom: Andi Kleen <[email protected]>
Currently in perf IPC and other metrics cannot be directly shown separately for both user and kernel in a single run. The problem was that the metrics matching code did not check event qualifiers.
With this patch the following case works correctly.
% perf stat -e cycles:k,cycles:u,instructions:k,instructions:u true
Performance counter stats for 'true':
531,718 cycles:k
203,895 cycles:u
338,151 instructions:k # 0.64 insns per cycle
105,961 instructions:u # 0.52 insns per cycle0.002989739 seconds time elapsed
Previously it would misreport the ratios because they were matching the wrong value.
The patch is fairly big, but quite mechanic as it just adds context indexes everywhere.
--- tools/perf/builtin-stat.c | 129 +++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 52 deletions(-)
tools/perf/builtin-stat.c +77 -52
@@ -247,21 +247,35 @@ out_free:return -1 ; } +#define NUM_CTX 3 + +enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +static struct stats runtime_nsecs_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_back_stats[MAX_NR_CPUS ]; -static struct stats runtime_branches_stats[MAX_NR_CPUS ]; -static struct stats runtime_cacherefs_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_dcache_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_icache_stats[MAX_NR_CPUS ]; -static struct stats runtime_ll_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_in_tx_stats[MAX_NR_CPUS ]; +static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_front_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_back_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_branches_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cacherefs_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_dcache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_icache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_ll_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_itlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_dtlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cycles_in_tx_stats[NUM_CTX ][MAX_NR_CPUS ];static struct stats walltime_nsecs_stats; -static struct stats runtime_transaction_stats[MAX_NR_CPUS ]; -static struct stats runtime_elision_stats[MAX_NR_CPUS ]; +static struct stats runtime_transaction_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_elision_stats[NUM_CTX ][MAX_NR_CPUS ]; + +static int evsel_context (struct perf_evsel *evsel) +{ +if (evsel->attr.exclude_kernel) +return CTX_USER ; +if (evsel->attr.exclude_user) +return CTX_KERNEL ; +/* Handle hypervisor too? */ +return CTX_ALL ; +}static void perf_stat__reset_stats (struct perf_evlist *evlist) {
@@ -356,37 +370,39 @@ static struct perf_evsel *nth_evsel(int n)static void update_shadow_stats (struct perf_evsel *counter,u64 *count,int cpu) { +int ctx =evsel_context (counter); +if (perf_evsel__match (counter,SOFTWARE ,SW_TASK_CLOCK ))update_stats (&runtime_nsecs_stats[cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CPU_CYCLES )) -update_stats (&runtime_cycles_stats[cpu], count[0 ]); +update_stats (&runtime_cycles_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_CYCLES_IN_TX ))) -update_stats (&runtime_cycles_in_tx_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_TRANSACTION_START ))) -update_stats (&runtime_transaction_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_ELISION_START ))) -update_stats (&runtime_elision_stats[cpu], count[0 ]); +update_stats (&runtime_elision_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_FRONTEND )) -update_stats (&runtime_stalled_cycles_front_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_front_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_BACKEND )) -update_stats (&runtime_stalled_cycles_back_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_back_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_BRANCH_INSTRUCTIONS )) -update_stats (&runtime_branches_stats[cpu], count[0 ]); +update_stats (&runtime_branches_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CACHE_REFERENCES )) -update_stats (&runtime_cacherefs_stats[cpu], count[0 ]); +update_stats (&runtime_cacherefs_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1D )) -update_stats (&runtime_l1_dcache_stats[cpu], count[0 ]); +update_stats (&runtime_l1_dcache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1I )) -update_stats (&runtime_l1_icache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_LL )) -update_stats (&runtime_ll_cache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_DTLB )) -update_stats (&runtime_dtlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_dtlb_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_ITLB )) -update_stats (&runtime_itlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_itlb_cache_stats[ctx][cpu], count[0 ]); }static void zero_per_pkg (struct perf_evsel *counter)
@@ -908,8 +924,9 @@ static void print_stalled_cycles_frontend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -927,8 +944,9 @@ static void print_stalled_cycles_backend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -946,8 +964,9 @@ static void print_branch_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_branches_stats[cpu]); + total =avg_stats (&runtime_branches_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -965,8 +984,9 @@ static void print_l1_dcache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_dcache_stats[cpu]); + total =avg_stats (&runtime_l1_dcache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -984,8 +1004,9 @@ static void print_l1_icache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_icache_stats[cpu]); + total =avg_stats (&runtime_l1_icache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1003,8 +1024,9 @@ static void print_dtlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_dtlb_cache_stats[cpu]); + total =avg_stats (&runtime_dtlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1022,8 +1044,9 @@ static void print_itlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_itlb_cache_stats[cpu]); + total =avg_stats (&runtime_itlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1041,8 +1064,9 @@ static void print_ll_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_ll_cache_stats[cpu]); + total =avg_stats (&runtime_ll_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1060,6 +1084,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)double sc = evsel->scale;const char *fmt;int cpu =cpu_map__id_to_cpu (id); +int ctx =evsel_context (evsel);if (csv_output) { fmt = sc !=1.0 ?"%.2f%s" :"%.0f%s" ;
@@ -1091,15 +1116,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)return ;if (perf_evsel__match (evsel,HARDWARE ,HW_INSTRUCTIONS )) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) { ratio = avg / total;fprintf (output," # %5.2f insns per cycle " , ratio); }else {fprintf (output," " ); } - total =avg_stats (&runtime_stalled_cycles_front_stats[cpu]); - total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[cpu])); + total =avg_stats (&runtime_stalled_cycles_front_stats[ctx][cpu]); + total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[ctx][cpu]));if (total && avg) { ratio = total / avg;
@@ -1110,46 +1135,46 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (perf_evsel__match (evsel,HARDWARE ,HW_BRANCH_MISSES ) && - runtime_branches_stats[cpu].n !=0 ) { + runtime_branches_stats[ctx][cpu].n !=0 ) {print_branch_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1D | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_dcache_stats[cpu].n !=0 ) { + runtime_l1_dcache_stats[ctx][cpu].n !=0 ) {print_l1_dcache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1I | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_icache_stats[cpu].n !=0 ) { + runtime_l1_icache_stats[ctx][cpu].n !=0 ) {print_l1_icache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_DTLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_dtlb_cache_stats[cpu].n !=0 ) { + runtime_dtlb_cache_stats[ctx][cpu].n !=0 ) {print_dtlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_ITLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_itlb_cache_stats[cpu].n !=0 ) { + runtime_itlb_cache_stats[ctx][cpu].n !=0 ) {print_itlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_LL | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_ll_cache_stats[cpu].n !=0 ) { + runtime_ll_cache_stats[ctx][cpu].n !=0 ) {print_ll_cache_misses (cpu, evsel, avg); }else if (perf_evsel__match (evsel,HARDWARE ,HW_CACHE_MISSES ) && - runtime_cacherefs_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cacherefs_stats[cpu]); + runtime_cacherefs_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cacherefs_stats[ctx][cpu]);if (total) ratio = avg *100 / total;
@@ -1171,15 +1196,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total)fprintf (output," # %5.2f%% transactional cycles " ,100.0 * (avg / total)); }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX_CP ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); - total2 =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]); + total2 =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total2 < avg) total2 = avg;if (total)
@@ -1189,8 +1214,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_TRANSACTION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
@@ -1199,8 +1224,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_ELISION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
Signature · 1 line
1.9.3
Namhyung Kim
maintainerRe: [PATCH 2/6] perf stat: Fix metrics calculation with event qualifiers
Hi Jiri and Andi,
Quoted 17 lines · Jiri Olsa
From: Andi Kleen <[email protected]>
Currently in perf IPC and other metrics cannot be directly shown separately for both user and kernel in a single run. The problem was that the metrics matching code did not check event qualifiers.
With this patch the following case works correctly.
% perf stat -e cycles:k,cycles:u,instructions:k,instructions:u true
Performance counter stats for 'true':
531,718 cycles:k 203,895 cycles:u 338,151 instructions:k # 0.64 insns per cycle 105,961 instructions:u # 0.52 insns per cycle
Quoted 4 lines
0.002989739 seconds time elapsedPreviously it would misreport the ratios because they were matching the wrong value.
This patch reminds me of following change:
Quoted 1 line
From
a8ae843bf7cff7b68dc39b6f088c43669d140d00Mon Sep 17 00:00:00 2001
From: Namhyung Kim <[email protected]>
Date: Wed, 8 Apr 2015 21:56:12 +0900
Subject: [RFC] perf stat: Add -U/--user option
The -U/--user option is to control event modifier for all events easily. It has same effect as if adding 'u' modifier to every events.
An example follows:
$ perf stat -U true
Performance counter stats for 'true':
0.722461 task-clock:uH (msec) # 0.520 CPUs utilized
0 context-switches:uH # 0.000 K/sec
0 cpu-migrations:uH # 0.000 K/sec
41 page-faults:uH # 0.057 M/sec
145,341 cycles:uH # 0.201 GHz
517,317 stalled-cycles-frontend:uH # 355.93% frontend cycles idle
497,570 stalled-cycles-backend:uH # 342.35% backend cycles idle
98,846 instructions:uH # 0.68 insns per cycle # 5.23 stalled cycles per insn
19,552 branches:uH # 27.063 M/sec
<not counted> branch-misses:uH
0.001389613 seconds time elapsed
--- tools/perf/Documentation/perf-stat.txt | 5 ++++- tools/perf/builtin-stat.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-stat.txt +4 -1
@@ -151,9 +151,12 @@ filter out the startup phase of the program, which is often very different. -T:: --transaction:: - Print statistics of transactional execution if supported. +-U:: +--user:: +Collect events only in user mode execution + EXAMPLES --------
tools/perf/builtin-stat.c +11 -0
@@ -141,6 +141,7 @@ static unsigned int interval = 0;static unsigned int initial_delay =0 ;static unsigned int unit_width =4 ;/* strlen("unit") */ static bool forever = false; +static bool mod_user = false;static struct timespec ref_time;static struct cpu_map *aggr_map;static int (*aggr_get_id)(struct cpu_map *m,int cpu);
@@ -1809,6 +1810,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) "aggregate counts per physical processor core", AGGR_CORE),OPT_UINTEGER ('D' ,"delay" , &initial_delay,"ms to wait before starting measurement after program start" ), +OPT_BOOLEAN ('U' ,"user" , &mod_user,"Count event only in user mode" ),OPT_END () }; const char * const stat_usage[] = {
@@ -1913,6 +1915,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)if (add_default_attributes ()) goto out; +if (mod_user) { +struct perf_evsel *evsel; + +evlist__for_each (evsel_list, evsel) { + evsel->attr.exclude_kernel =1 ; + evsel->attr.exclude_hv =1 ; + } + } +target__validate (&target);if (perf_evlist__create_maps (evsel_list, &target) <0 ) {
Signature · 1 line
2.3.5
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/6] perf stat: Fix metrics calculation with event qualifiers
Em Wed, Apr 08, 2015 at 10:28:33PM +0900, Namhyung Kim escreveu:
Quoted 12 lines
Hi Jiri and Andi,
Quoted 10 lines · Jiri Olsa
From: Andi Kleen <[email protected]>
% perf stat -e cycles:k,cycles:u,instructions:k,instructions:u truePerformance counter stats for 'true':
531,718 cycles:k 203,895 cycles:u 338,151 instructions:k # 0.64 insns per cycle 105,961 instructions:u # 0.52 insns per cycle
Quoted 6 lines
Quoted 4 lines
0.002989739 seconds time elapsedPreviously it would misreport the ratios because they were matching the wrong value.
This patch reminds me of following change:
Yeah, useful, but do we have one for the kernel, hypervisor, guest, etc? Could we instead have a --cpumode u?k?g?H? combo, so that we could filter by that?
Applying this series, with your Ack, thanks!
- Arnaldo
Quoted 91 lines
Quoted 1 line
From
a8ae843bf7cff7b68dc39b6f088c43669d140d00Mon Sep 17 00:00:00 2001From: Namhyung Kim <[email protected]>
Date: Wed, 8 Apr 2015 21:56:12 +0900
Subject: [RFC] perf stat: Add -U/--user optionThe -U/--user option is to control event modifier for all events easily. It has same effect as if adding 'u' modifier to every events.
An example follows:
$ perf stat -U truePerformance counter stats for 'true':
0.722461 task-clock:uH (msec) # 0.520 CPUs utilized 0 context-switches:uH # 0.000 K/sec 0 cpu-migrations:uH # 0.000 K/sec 41 page-faults:uH # 0.057 M/sec 145,341 cycles:uH # 0.201 GHz 517,317 stalled-cycles-frontend:uH # 355.93% frontend cycles idle 497,570 stalled-cycles-backend:uH # 342.35% backend cycles idle 98,846 instructions:uH # 0.68 insns per cycle# 5.23 stalled cycles per insn
19,552 branches:uH # 27.063 M/sec
<not counted> branch-misses:uH0.001389613 seconds time elapsed
Cc Andi Kleen <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-stat.txt | 5 ++++- tools/perf/builtin-stat.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-stat.txt +4
-1@@ -151,9 +151,12 @@ filter out the startup phase of the program, which is often very different. -T:: --transaction:: - Print statistics of transactional execution if supported. +-U:: +--user:: +Collect events only in user mode execution + EXAMPLES --------tools/perf/builtin-stat.c +11
-0@@ -141,6 +141,7 @@ static unsigned int interval = 0;static unsigned int initial_delay =0 ;static unsigned int unit_width =4 ;/* strlen("unit") */ static bool forever = false; +static bool mod_user = false;static struct timespec ref_time;static struct cpu_map *aggr_map;static int (*aggr_get_id)(struct cpu_map *m,int cpu);@@ -1809,6 +1810,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) "aggregate counts per physical processor core", AGGR_CORE),OPT_UINTEGER ('D' ,"delay" , &initial_delay,"ms to wait before starting measurement after program start" ), +OPT_BOOLEAN ('U' ,"user" , &mod_user,"Count event only in user mode" ),OPT_END () }; const char * const stat_usage[] = {@@ -1913,6 +1915,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)if (add_default_attributes ()) goto out; +if (mod_user) { +struct perf_evsel *evsel; + +evlist__for_each (evsel_list, evsel) { + evsel->attr.exclude_kernel =1 ; + evsel->attr.exclude_hv =1 ; + } + } +target__validate (&target);if (perf_evlist__create_maps (evsel_list, &target) <0 ) {Signature · 1 line
2.3.5
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf stat: Fix metrics calculation with event qualifiers
In reply to Jiri Olsaperf stat: Fix metrics calculation with event qualifiers
Commit-ID: a0aa21e2281f89a197ad8e7bd8008f3b7b735dfc Gitweb: http://git.kernel.org/tip/a0aa21e2281f89a197ad8e7bd8008f3b7b735dfc Author: Andi Kleen <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:15 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:04 -0300
perf stat: Fix metrics calculation with event qualifiers
Currently in perf IPC and other metrics cannot be directly shown separately for both user and kernel in a single run. The problem was that the metrics matching code did not check event qualifiers.
With this patch the following case works correctly.
% perf stat -e cycles:k,cycles:u,instructions:k,instructions:u true
Performance counter stats for 'true':
531,718 cycles:k
203,895 cycles:u
338,151 instructions:k # 0.64 insns per cycle
105,961 instructions:u # 0.52 insns per cycle0.002989739 seconds time elapsed
Previously it would misreport the ratios because they were matching the wrong value.
The patch is fairly big, but quite mechanic as it just adds context indexes everywhere.
--- tools/perf/builtin-stat.c | 129 +++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 52 deletions(-)
tools/perf/builtin-stat.c +77 -52
@@ -247,21 +247,35 @@ out_free:return -1 ; } +#define NUM_CTX 3 + +enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +static struct stats runtime_nsecs_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_back_stats[MAX_NR_CPUS ]; -static struct stats runtime_branches_stats[MAX_NR_CPUS ]; -static struct stats runtime_cacherefs_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_dcache_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_icache_stats[MAX_NR_CPUS ]; -static struct stats runtime_ll_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_in_tx_stats[MAX_NR_CPUS ]; +static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_front_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_back_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_branches_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cacherefs_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_dcache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_icache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_ll_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_itlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_dtlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cycles_in_tx_stats[NUM_CTX ][MAX_NR_CPUS ];static struct stats walltime_nsecs_stats; -static struct stats runtime_transaction_stats[MAX_NR_CPUS ]; -static struct stats runtime_elision_stats[MAX_NR_CPUS ]; +static struct stats runtime_transaction_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_elision_stats[NUM_CTX ][MAX_NR_CPUS ]; + +static int evsel_context (struct perf_evsel *evsel) +{ +if (evsel->attr.exclude_kernel) +return CTX_USER ; +if (evsel->attr.exclude_user) +return CTX_KERNEL ; +/* Handle hypervisor too? */ +return CTX_ALL ; +}static void perf_stat__reset_stats (struct perf_evlist *evlist) {
@@ -356,37 +370,39 @@ static struct perf_evsel *nth_evsel(int n)static void update_shadow_stats (struct perf_evsel *counter,u64 *count,int cpu) { +int ctx =evsel_context (counter); +if (perf_evsel__match (counter,SOFTWARE ,SW_TASK_CLOCK ))update_stats (&runtime_nsecs_stats[cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CPU_CYCLES )) -update_stats (&runtime_cycles_stats[cpu], count[0 ]); +update_stats (&runtime_cycles_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_CYCLES_IN_TX ))) -update_stats (&runtime_cycles_in_tx_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_TRANSACTION_START ))) -update_stats (&runtime_transaction_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_ELISION_START ))) -update_stats (&runtime_elision_stats[cpu], count[0 ]); +update_stats (&runtime_elision_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_FRONTEND )) -update_stats (&runtime_stalled_cycles_front_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_front_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_BACKEND )) -update_stats (&runtime_stalled_cycles_back_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_back_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_BRANCH_INSTRUCTIONS )) -update_stats (&runtime_branches_stats[cpu], count[0 ]); +update_stats (&runtime_branches_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CACHE_REFERENCES )) -update_stats (&runtime_cacherefs_stats[cpu], count[0 ]); +update_stats (&runtime_cacherefs_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1D )) -update_stats (&runtime_l1_dcache_stats[cpu], count[0 ]); +update_stats (&runtime_l1_dcache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1I )) -update_stats (&runtime_l1_icache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_LL )) -update_stats (&runtime_ll_cache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_DTLB )) -update_stats (&runtime_dtlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_dtlb_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_ITLB )) -update_stats (&runtime_itlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_itlb_cache_stats[ctx][cpu], count[0 ]); }static void zero_per_pkg (struct perf_evsel *counter)
@@ -908,8 +924,9 @@ static void print_stalled_cycles_frontend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -927,8 +944,9 @@ static void print_stalled_cycles_backend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -946,8 +964,9 @@ static void print_branch_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_branches_stats[cpu]); + total =avg_stats (&runtime_branches_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -965,8 +984,9 @@ static void print_l1_dcache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_dcache_stats[cpu]); + total =avg_stats (&runtime_l1_dcache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -984,8 +1004,9 @@ static void print_l1_icache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_icache_stats[cpu]); + total =avg_stats (&runtime_l1_icache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1003,8 +1024,9 @@ static void print_dtlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_dtlb_cache_stats[cpu]); + total =avg_stats (&runtime_dtlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1022,8 +1044,9 @@ static void print_itlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_itlb_cache_stats[cpu]); + total =avg_stats (&runtime_itlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1041,8 +1064,9 @@ static void print_ll_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_ll_cache_stats[cpu]); + total =avg_stats (&runtime_ll_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1060,6 +1084,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)double sc = evsel->scale;const char *fmt;int cpu =cpu_map__id_to_cpu (id); +int ctx =evsel_context (evsel);if (csv_output) { fmt = sc !=1.0 ?"%.2f%s" :"%.0f%s" ;
@@ -1091,15 +1116,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)return ;if (perf_evsel__match (evsel,HARDWARE ,HW_INSTRUCTIONS )) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) { ratio = avg / total;fprintf (output," # %5.2f insns per cycle " , ratio); }else {fprintf (output," " ); } - total =avg_stats (&runtime_stalled_cycles_front_stats[cpu]); - total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[cpu])); + total =avg_stats (&runtime_stalled_cycles_front_stats[ctx][cpu]); + total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[ctx][cpu]));if (total && avg) { ratio = total / avg;
@@ -1110,46 +1135,46 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (perf_evsel__match (evsel,HARDWARE ,HW_BRANCH_MISSES ) && - runtime_branches_stats[cpu].n !=0 ) { + runtime_branches_stats[ctx][cpu].n !=0 ) {print_branch_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1D | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_dcache_stats[cpu].n !=0 ) { + runtime_l1_dcache_stats[ctx][cpu].n !=0 ) {print_l1_dcache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1I | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_icache_stats[cpu].n !=0 ) { + runtime_l1_icache_stats[ctx][cpu].n !=0 ) {print_l1_icache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_DTLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_dtlb_cache_stats[cpu].n !=0 ) { + runtime_dtlb_cache_stats[ctx][cpu].n !=0 ) {print_dtlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_ITLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_itlb_cache_stats[cpu].n !=0 ) { + runtime_itlb_cache_stats[ctx][cpu].n !=0 ) {print_itlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_LL | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_ll_cache_stats[cpu].n !=0 ) { + runtime_ll_cache_stats[ctx][cpu].n !=0 ) {print_ll_cache_misses (cpu, evsel, avg); }else if (perf_evsel__match (evsel,HARDWARE ,HW_CACHE_MISSES ) && - runtime_cacherefs_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cacherefs_stats[cpu]); + runtime_cacherefs_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cacherefs_stats[ctx][cpu]);if (total) ratio = avg *100 / total;
@@ -1171,15 +1196,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total)fprintf (output," # %5.2f%% transactional cycles " ,100.0 * (avg / total)); }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX_CP ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); - total2 =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]); + total2 =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total2 < avg) total2 = avg;if (total)
@@ -1189,8 +1214,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_TRANSACTION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
@@ -1199,8 +1224,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_ELISION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
Jiri Olsa
reviewerPATCH 3/6 perf stat: Change metrics context calculation
In reply to Jiri OlsaChanging metrics context calculation to allow more than 2 types of context.
Following patches will add support for the rest of the exclude_* bits so we need separate array element for all context combinations.
--- tools/perf/builtin-stat.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +11 -6
@@ -247,9 +247,13 @@ out_free:return -1 ; } -#define NUM_CTX 3 +enum { +CTX_BIT_USER =1 <<0 , +CTX_BIT_KERNEL =1 <<1 , +CTX_BIT_MAX =1 <<2 , +}; -enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +#define NUM_CTX CTX_BIT_MAXstatic struct stats runtime_nsecs_stats[MAX_NR_CPUS ];static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ];
@@ -269,12 +273,13 @@ static struct stats runtime_elision_stats[NUM_CTX][MAX_NR_CPUS];static int evsel_context (struct perf_evsel *evsel) { +int ctx =0 ; +if (evsel->attr.exclude_kernel) -return CTX_USER ; + ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) -return CTX_KERNEL ; -/* Handle hypervisor too? */ -return CTX_ALL ; + ctx |=CTX_BIT_USER ; +return ctx; }static void perf_stat__reset_stats (struct perf_evlist *evlist)
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Change metrics context calculation
perf stat: Change metrics context calculation
Commit-ID: 9f71b4f39d7c01cae9d80e938774ff6b0a9bfd80 Gitweb: http://git.kernel.org/tip/9f71b4f39d7c01cae9d80e938774ff6b0a9bfd80 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:16 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:05 -0300
perf stat: Change metrics context calculation
Changing metrics context calculation to allow more than 2 types of context.
Following patches will add support for the rest of the exclude_* bits so we need separate array element for all context combinations.
--- tools/perf/builtin-stat.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +11 -6
@@ -247,9 +247,13 @@ out_free:return -1 ; } -#define NUM_CTX 3 +enum { +CTX_BIT_USER =1 <<0 , +CTX_BIT_KERNEL =1 <<1 , +CTX_BIT_MAX =1 <<2 , +}; -enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +#define NUM_CTX CTX_BIT_MAXstatic struct stats runtime_nsecs_stats[MAX_NR_CPUS ];static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ];
@@ -269,12 +273,13 @@ static struct stats runtime_elision_stats[NUM_CTX][MAX_NR_CPUS];static int evsel_context (struct perf_evsel *evsel) { +int ctx =0 ; +if (evsel->attr.exclude_kernel) -return CTX_USER ; + ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) -return CTX_KERNEL ; -/* Handle hypervisor too? */ -return CTX_ALL ; + ctx |=CTX_BIT_USER ; +return ctx; }static void perf_stat__reset_stats (struct perf_evlist *evlist)
Jiri Olsa
reviewerPATCH 4/6 perf stat: Add metrics support for exclude_hv
In reply to Jiri OlsaSeparating metrics values for exclude_hv bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -250,7 +250,8 @@ out_free:enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 , -CTX_BIT_MAX =1 <<2 , +CTX_BIT_HV =1 <<2 , +CTX_BIT_MAX =1 <<3 , };#define NUM_CTX CTX_BIT_MAX
@@ -279,6 +280,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) ctx |=CTX_BIT_USER ; +if (evsel->attr.exclude_hv) + ctx |=CTX_BIT_HV ;return ctx; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Add metrics support for exclude_hv
perf stat: Add metrics support for exclude_hv
Commit-ID: afef2fbd1435050377f6487c43f2aa6edc37b30f Gitweb: http://git.kernel.org/tip/afef2fbd1435050377f6487c43f2aa6edc37b30f Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:17 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:05 -0300
perf stat: Add metrics support for exclude_hv
Separating metrics values for exclude_hv bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -250,7 +250,8 @@ out_free:enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 , -CTX_BIT_MAX =1 <<2 , +CTX_BIT_HV =1 <<2 , +CTX_BIT_MAX =1 <<3 , };#define NUM_CTX CTX_BIT_MAX
@@ -279,6 +280,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) ctx |=CTX_BIT_USER ; +if (evsel->attr.exclude_hv) + ctx |=CTX_BIT_HV ;return ctx; }
Jiri Olsa
reviewerPATCH 5/6 perf stat: Add metrics support for exclude_(host|guest)
In reply to Jiri OlsaSeparating metrics values for guest and host,
so we get proper values.
--- tools/perf/builtin-stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +5 -1
@@ -251,7 +251,8 @@ enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 , - CTX_BIT_MAX = 1 << 3, +CTX_BIT_HOST =1 <<3 , + CTX_BIT_MAX = 1 << 4, };#define NUM_CTX CTX_BIT_MAX
@@ -282,6 +283,9 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_USER ;if (evsel->attr.exclude_hv) ctx |=CTX_BIT_HV ; +if (evsel->attr.exclude_host) + ctx |=CTX_BIT_HOST ; +return ctx; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Add metrics support for exclude_( host|guest)
perf stat: Add metrics support for exclude_(host|guest)
Commit-ID: a2270d38a53aa88c67a72978fc8717e26c7f27d9 Gitweb: http://git.kernel.org/tip/a2270d38a53aa88c67a72978fc8717e26c7f27d9 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:18 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:05 -0300
perf stat: Add metrics support for exclude_(host|guest)
Separating metrics values for guest and host, so we get proper values.
--- tools/perf/builtin-stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +5 -1
@@ -251,7 +251,8 @@ enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 , - CTX_BIT_MAX = 1 << 3, +CTX_BIT_HOST =1 <<3 , + CTX_BIT_MAX = 1 << 4, };#define NUM_CTX CTX_BIT_MAX
@@ -282,6 +283,9 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_USER ;if (evsel->attr.exclude_hv) ctx |=CTX_BIT_HV ; +if (evsel->attr.exclude_host) + ctx |=CTX_BIT_HOST ; +return ctx; }
Jiri Olsa
reviewerPATCH 6/6 perf stat: Add metrics support for exclude_idle
In reply to Jiri OlsaSeparating metrics values for exclude_idle bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -252,7 +252,8 @@ enum {CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 ,CTX_BIT_HOST =1 <<3 , - CTX_BIT_MAX = 1 << 4, +CTX_BIT_IDLE =1 <<4 , + CTX_BIT_MAX = 1 << 5, };#define NUM_CTX CTX_BIT_MAX
@@ -285,6 +286,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_HV ;if (evsel->attr.exclude_host) ctx |=CTX_BIT_HOST ; +if (evsel->attr.exclude_idle) + ctx |=CTX_BIT_IDLE ;return ctx; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Add metrics support for exclude_idle
perf stat: Add metrics support for exclude_idle
Commit-ID: c4fa0d9c1e6aa360cfa2c36f7836a89da24a1b7a Gitweb: http://git.kernel.org/tip/c4fa0d9c1e6aa360cfa2c36f7836a89da24a1b7a Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 7 Apr 2015 23:25:19 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 29 Apr 2015 10:38:06 -0300
perf stat: Add metrics support for exclude_idle
Separating metrics values for exclude_idle bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -252,7 +252,8 @@ enum {CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 ,CTX_BIT_HOST =1 <<3 , - CTX_BIT_MAX = 1 << 4, +CTX_BIT_IDLE =1 <<4 , + CTX_BIT_MAX = 1 << 5, };#define NUM_CTX CTX_BIT_MAX
@@ -285,6 +286,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_HV ;if (evsel->attr.exclude_host) ctx |=CTX_BIT_HOST ; +if (evsel->attr.exclude_idle) + ctx |=CTX_BIT_IDLE ;return ctx; }
Quoted 7 lines · Jiri Olsa
hi,
I'm sending Andi's patch accompanied with changes requested by Ingo.
http://marc.info/?l=linux-kernel&m=139748629929175&w=2I added simple bit calculated index array, while exclude_* bits might have more strict logic and ban some combinations, but I wanted to keep it simple and did not find better solution.
available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/andi
Quoted 22 lines
thanks,
jirka---
Andi Kleen (1):
perf stat: Fix metrics calculation with event qualifiersJiri Olsa (5):
perf tools: Add 'I' event modifier forexclude_idlebit perf stat: Change metrics context calculation perf stat: Add metrics support forexclude_hvperf stat: Add metrics support forexclude_(host|guest)perf stat: Add metrics support forexclude_idletools/perf/Documentation/perf-list.txt | 1 + tools/perf/builtin-stat.c | 144 +++++++++++++++++++++++++++++++++++++++++------------------------ tools/perf/tests/parse-events.c | 40 ++++++++++++++++++ tools/perf/util/parse-events.c | 8 +++- tools/perf/util/parse-events.l | 2 +- 5 files changed, 141 insertions(+), 54 deletions(-)
Quoted 7 lines · Jiri Olsa
hi,
I'm sending Andi's patch accompanied with changes requested by Ingo.
http://marc.info/?l=linux-kernel&m=139748629929175&w=2I added simple bit calculated index array, while exclude_* bits might have more strict logic and ban some combinations, but I wanted to keep it simple and did not find better solution.
ping
jirka
Quoted 22 lines
thanks,
jirka---
Andi Kleen (1):
perf stat: Fix metrics calculation with event qualifiersJiri Olsa (5):
perf tools: Add 'I' event modifier forexclude_idlebit perf stat: Change metrics context calculation perf stat: Add metrics support forexclude_hvperf stat: Add metrics support forexclude_(host|guest)perf stat: Add metrics support forexclude_idletools/perf/Documentation/perf-list.txt | 1 + tools/perf/builtin-stat.c | 144 +++++++++++++++++++++++++++++++++++++++++------------------------ tools/perf/tests/parse-events.c | 40 ++++++++++++++++++ tools/perf/util/parse-events.c | 8 +++- tools/perf/util/parse-events.l | 2 +- 5 files changed, 141 insertions(+), 54 deletions(-)
Hi Jiri,
Quoted 7 lines · Jiri Olsa
hi,
I'm sending Andi's patch accompanied with changes requested by Ingo.
http://marc.info/?l=linux-kernel&m=139748629929175&w=2I added simple bit calculated index array, while exclude_* bits might have more strict logic and ban some combinations, but I wanted to keep it simple and did not find better solution.
For the series,
Thanks,
Namhyung