[PATCH 05/11] perf stat: Check existence of frontend/backed stalled cycles

From: Arnaldo Carvalho de Melo
Date: Mon Feb 29 2016 - 14:24:22 EST


From: Andi Kleen <ak@xxxxxxxxxxxxxxx>

Only put the frontend/backend stalled cycles into the default perf stat
events when the CPU actually supports them.

This avoids empty columns with --metric-only on newer Intel CPUs.

Committer note:

Before:

$ perf stat ls
a.patch

Performance counter stats for 'ls':

0.822067 task-clock (msec) # 0.873 CPUs utilized (82.26%)
0 context-switches # 0.000 K/sec (82.26%)
0 cpu-migrations # 0.000 K/sec (82.26%)
125 page-faults # 0.152 M/sec (82.26%)
2,516,127 cycles # 3.061 GHz (82.84%)
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
2,430,467 instructions # 0.97 insn per cycle (82.84%)
486,235 branches # 591.479 M/sec (82.84%)
18,389 branch-misses # 3.78% of all branches (82.84%)

0.000941536 seconds time elapsed
$

After:

$ perf stat ls
a.patch

Performance counter stats for 'ls':

0.824919 task-clock (msec) # 0.893 CPUs utilized (85.47%)
0 context-switches # 0.000 K/sec (85.47%)
0 cpu-migrations # 0.000 K/sec (85.47%)
124 page-faults # 0.150 M/sec (85.47%)
2521790 cycles # 3.057 GHz (86.15%)
2364913 instructions # 0.94 insn per cycle (86.15%)
471970 branches # 572.141 M/sec (86.15%)
16935 branch-misses # 3.59% of all branches (86.15%)

0.000923397 seconds time elapsed
$

Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Tested-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/1456532881-26621-2-git-send-email-andi@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/builtin-stat.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 8c0bc0fe5179..24f222dd2a8a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1441,7 +1441,7 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
*/
static int add_default_attributes(void)
{
- struct perf_event_attr default_attrs[] = {
+ struct perf_event_attr default_attrs0[] = {

{ .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
{ .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES },
@@ -1449,8 +1449,14 @@ static int add_default_attributes(void)
{ .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS },

{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES },
+};
+ struct perf_event_attr frontend_attrs[] = {
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND },
+};
+ struct perf_event_attr backend_attrs[] = {
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND },
+};
+ struct perf_event_attr default_attrs1[] = {
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS },
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES },
@@ -1567,7 +1573,19 @@ static int add_default_attributes(void)
}

if (!evsel_list->nr_entries) {
- if (perf_evlist__add_default_attrs(evsel_list, default_attrs) < 0)
+ if (perf_evlist__add_default_attrs(evsel_list, default_attrs0) < 0)
+ return -1;
+ if (pmu_have_event("cpu", "stalled-cycles-frontend")) {
+ if (perf_evlist__add_default_attrs(evsel_list,
+ frontend_attrs) < 0)
+ return -1;
+ }
+ if (pmu_have_event("cpu", "stalled-cycles-backend")) {
+ if (perf_evlist__add_default_attrs(evsel_list,
+ backend_attrs) < 0)
+ return -1;
+ }
+ if (perf_evlist__add_default_attrs(evsel_list, default_attrs1) < 0)
return -1;
}

--
2.5.0