Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Add transaction flag (-T) support for s390

The 'perf stat' command line flag -T to display transaction counters is
currently supported for x86 only.

Add support for s390. It is based on the metrics flag -M transaction
using the architecture dependent JSON files. This requires a metric
named "transaction" in the JSON files for the platform.

Introduce a new function metricgroup__has_metric() to check for the
existence of a metric_name transaction.

As suggested by Andi Kleen, this is the new approach to support
transactions counters. Other architectures will follow.

Output before:

[root@p23lp27 perf]# ./perf stat -T -- sleep 1
Cannot set up transaction events
[root@p23lp27 perf]#

Output after:

[root@s35lp76 perf]# ./perf stat -T -- ~/mytesttx 1 >/tmp/111

Performance counter stats for '/root/mytesttx 1':

1 tx_c_tend # 13.0 transaction
1 tx_nc_tend
11 tx_nc_tabort
0 tx_c_tabort_special
0 tx_c_tabort_no_special

0.001070109 seconds time elapsed

[root@s35lp76 perf]#

Suggested-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Link: http://lkml.kernel.org/r/20180626071701.58190-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Thomas Richter and committed by
Arnaldo Carvalho de Melo
742d92ff 83eb383e

+35
+12
tools/perf/builtin-stat.c
··· 2449 2449 return 0; 2450 2450 2451 2451 if (transaction_run) { 2452 + /* Handle -T as -M transaction. Once platform specific metrics 2453 + * support has been added to the json files, all archictures 2454 + * will use this approach. To determine transaction support 2455 + * on an architecture test for such a metric name. 2456 + */ 2457 + if (metricgroup__has_metric("transaction")) { 2458 + struct option opt = { .value = &evsel_list }; 2459 + 2460 + return metricgroup__parse_groups(&opt, "transaction", 2461 + &metric_events); 2462 + } 2463 + 2452 2464 if (pmu_have_event("cpu", "cycles-ct") && 2453 2465 pmu_have_event("cpu", "el-start")) 2454 2466 err = parse_events(evsel_list, transaction_attrs,
+22
tools/perf/util/metricgroup.c
··· 490 490 metricgroup__free_egroups(&group_list); 491 491 return ret; 492 492 } 493 + 494 + bool metricgroup__has_metric(const char *metric) 495 + { 496 + struct pmu_events_map *map = perf_pmu__find_map(NULL); 497 + struct pmu_event *pe; 498 + int i; 499 + 500 + if (!map) 501 + return false; 502 + 503 + for (i = 0; ; i++) { 504 + pe = &map->table[i]; 505 + 506 + if (!pe->name && !pe->metric_group && !pe->metric_name) 507 + break; 508 + if (!pe->metric_expr) 509 + continue; 510 + if (match_metric(pe->metric_name, metric)) 511 + return true; 512 + } 513 + return false; 514 + }
+1
tools/perf/util/metricgroup.h
··· 28 28 struct rblist *metric_events); 29 29 30 30 void metricgroup__print(bool metrics, bool groups, char *filter, bool raw); 31 + bool metricgroup__has_metric(const char *metric); 31 32 #endif