Skip to contentSkip to conversation

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

PATCH Superseded Thomas Richter 4 participants 5 messages Jun 25, 2018 perf events

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 4/4 perf stat: Add transaction flag (-T) support for s390

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 dependend json files. This requires a metric named "transaction" in the json files for the platform.

v2 --> v3:
Introduce new function metricgroup__has_metric() to check for the existance of a metric named 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]#

---
 tools/perf/builtin-stat.c     | 12 ++++++++++++
 tools/perf/util/metricgroup.c | 23 +++++++++++++++++++++++
 tools/perf/util/metricgroup.h |  1 +
 3 files changed, 36 insertions(+)
tools/perf/builtin-stat.c +12 -0
index a4f662a462c6..e309279e7b04 100644
@@ -2425,6 +2425,18 @@ static int add_default_attributes(void)
 	if (transaction_run) {
 		struct parse_events_error errinfo;
 
+		/* Handle -T as -M transaction. Once platform specific metrics
+		 * support has been added to the json files, all archictures
+		 * will use this approach. To determine transaction support
+		 * on an architecture test for such a metric name.
+		 */
+		if (metricgroup__has_metric("transaction")) {
+			struct option opt = { .value = &evsel_list };
+
+			return metricgroup__parse_groups(&opt, "transaction",
+							 &metric_events);
+		}
+
 		if (pmu_have_event("cpu", "cycles-ct") &&
 		    pmu_have_event("cpu", "el-start"))
 			err = parse_events(evsel_list, transaction_attrs,
tools/perf/util/metricgroup.c +23 -0
index 1ddc3d1d0147..90cff5226ecc 100644
@@ -490,3 +490,26 @@ int metricgroup__parse_groups(const struct option *opt,
 	metricgroup__free_egroups(&group_list);
 	return ret;
 }
+
+bool metricgroup__has_metric(const char *metric)
+{
+	struct pmu_events_map *map = perf_pmu__find_map(NULL);
+	struct pmu_event *pe;
+	int i;
+
+	if (!map)
+		return false;
+
+	for (i = 0; ; i++) {
+		pe = &map->table[i];
+
+		if (!pe->name && !pe->metric_group && !pe->metric_name)
+			break;
+		if (!pe->metric_expr)
+			continue;
+		if (match_metric(pe->metric_group, metric) ||
+		    match_metric(pe->metric_name, metric))
+			return true;
+	}
+	return false;
+}
tools/perf/util/metricgroup.h +1 -0
index 06854e125ee7..8a155dba0581 100644
@@ -28,4 +28,5 @@ int metricgroup__parse_groups(const struct option *opt,
 			struct rblist *metric_events);
 
 void metricgroup__print(bool metrics, bool groups, char *filter, bool raw);
+bool metricgroup__has_metric(const char *metric);
 #endif
Signature · 1 line
2.14.3
#1 lore raw

Em Mon, Jun 25, 2018 at 02:58:56PM +0200, Thomas Richter escreveu:

Quoted 5 lines

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 dependend json files. This requires a metric named "transaction" in the json files for the platform.

You forgot to CC Andi in this post, Andi, is everything ok now? May I have your reviewed-by or acked-by?

Thanks,

- Arnaldo

Quoted 103 lines

v2 --> v3:
Introduce new function metricgroup__has_metric() to check for the existance of a metric named 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]#

---
 tools/perf/builtin-stat.c     | 12 ++++++++++++
 tools/perf/util/metricgroup.c | 23 +++++++++++++++++++++++
 tools/perf/util/metricgroup.h |  1 +
 3 files changed, 36 insertions(+)
tools/perf/builtin-stat.c +12 -0
index a4f662a462c6..e309279e7b04 100644
@@ -2425,6 +2425,18 @@ static int add_default_attributes(void)
 	if (transaction_run) {
 		struct parse_events_error errinfo;
 
+		/* Handle -T as -M transaction. Once platform specific metrics
+		 * support has been added to the json files, all archictures
+		 * will use this approach. To determine transaction support
+		 * on an architecture test for such a metric name.
+		 */
+		if (metricgroup__has_metric("transaction")) {
+			struct option opt = { .value = &evsel_list };
+
+			return metricgroup__parse_groups(&opt, "transaction",
+							 &metric_events);
+		}
+
 		if (pmu_have_event("cpu", "cycles-ct") &&
 		    pmu_have_event("cpu", "el-start"))
 			err = parse_events(evsel_list, transaction_attrs,
tools/perf/util/metricgroup.c +23 -0
index 1ddc3d1d0147..90cff5226ecc 100644
@@ -490,3 +490,26 @@ int metricgroup__parse_groups(const struct option *opt,
 	metricgroup__free_egroups(&group_list);
 	return ret;
 }
+
+bool metricgroup__has_metric(const char *metric)
+{
+	struct pmu_events_map *map = perf_pmu__find_map(NULL);
+	struct pmu_event *pe;
+	int i;
+
+	if (!map)
+		return false;
+
+	for (i = 0; ; i++) {
+		pe = &map->table[i];
+
+		if (!pe->name && !pe->metric_group && !pe->metric_name)
+			break;
+		if (!pe->metric_expr)
+			continue;
+		if (match_metric(pe->metric_group, metric) ||
+		    match_metric(pe->metric_name, metric))
+			return true;
+	}
+	return false;
+}
tools/perf/util/metricgroup.h +1 -0
index 06854e125ee7..8a155dba0581 100644
@@ -28,4 +28,5 @@ int metricgroup__parse_groups(const struct option *opt,
 			struct rblist *metric_events);
 
 void metricgroup__print(bool metrics, bool groups, char *filter, bool raw);
+bool metricgroup__has_metric(const char *metric);
 #endif
Signature · 1 line
2.14.3
Acked-by
#2 lore raw
Quoted 10 lines
Quoted 10 lines
tools/perf/util/metricgroup.c +10 -0
+bool metricgroup__has_metric(const char *metric)
+{
+	struct pmu_events_map *map = perf_pmu__find_map(NULL);
+	struct pmu_event *pe;
+	int i;
+
+	if (!map)
+		return false;
+
+	for (i = 0; ; i++) {
Quoted 8 lines

tools/perf/util/metricgroup.c int metricgroup__parse_groups(const struct option *opt, · line 511

Quoted 8 lines
tools/perf/util/metricgroup.c +8 -0
+		pe = &map->table[i];
+
+		if (!pe->name && !pe->metric_group && !pe->metric_name)
+			break;
+		if (!pe->metric_expr)
+			continue;
+		if (match_metric(pe->metric_group, metric) ||
+		    match_metric(pe->metric_name, metric))

Why both the group and the metric?

I would just match the metric_name

Otherwise it's impossible to have a group called "transaction"

With that fixed it's ok for me.

-Andi

#3 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Mon, Jun 25, 2018 at 02:58:56PM +0200, Thomas Richter escreveu:

Quoted 5 lines

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 dependend json files. This requires a metric named "transaction" in the json files for the platform.

You forgot to CC Andi in this post, Andi, is everything ok now? May I have your reviewed-by or acked-by?

hu, I haven't got this one either.. will check

jirka

Quoted 108 lines

Thanks,

- Arnaldo

Quoted 103 lines

v2 --> v3:
Introduce new function metricgroup__has_metric() to check for the existance of a metric named 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]#

---
 tools/perf/builtin-stat.c     | 12 ++++++++++++
 tools/perf/util/metricgroup.c | 23 +++++++++++++++++++++++
 tools/perf/util/metricgroup.h |  1 +
 3 files changed, 36 insertions(+)
tools/perf/builtin-stat.c +12 -0
index a4f662a462c6..e309279e7b04 100644
@@ -2425,6 +2425,18 @@ static int add_default_attributes(void)
 	if (transaction_run) {
 		struct parse_events_error errinfo;
 
+		/* Handle -T as -M transaction. Once platform specific metrics
+		 * support has been added to the json files, all archictures
+		 * will use this approach. To determine transaction support
+		 * on an architecture test for such a metric name.
+		 */
+		if (metricgroup__has_metric("transaction")) {
+			struct option opt = { .value = &evsel_list };
+
+			return metricgroup__parse_groups(&opt, "transaction",
+							 &metric_events);
+		}
+
 		if (pmu_have_event("cpu", "cycles-ct") &&
 		    pmu_have_event("cpu", "el-start"))
 			err = parse_events(evsel_list, transaction_attrs,
tools/perf/util/metricgroup.c +23 -0
index 1ddc3d1d0147..90cff5226ecc 100644
@@ -490,3 +490,26 @@ int metricgroup__parse_groups(const struct option *opt,
 	metricgroup__free_egroups(&group_list);
 	return ret;
 }
+
+bool metricgroup__has_metric(const char *metric)
+{
+	struct pmu_events_map *map = perf_pmu__find_map(NULL);
+	struct pmu_event *pe;
+	int i;
+
+	if (!map)
+		return false;
+
+	for (i = 0; ; i++) {
+		pe = &map->table[i];
+
+		if (!pe->name && !pe->metric_group && !pe->metric_name)
+			break;
+		if (!pe->metric_expr)
+			continue;
+		if (match_metric(pe->metric_group, metric) ||
+		    match_metric(pe->metric_name, metric))
+			return true;
+	}
+	return false;
+}
tools/perf/util/metricgroup.h +1 -0
index 06854e125ee7..8a155dba0581 100644
@@ -28,4 +28,5 @@ int metricgroup__parse_groups(const struct option *opt,
 			struct rblist *metric_events);
 
 void metricgroup__print(bool metrics, bool groups, char *filter, bool raw);
+bool metricgroup__has_metric(const char *metric);
 #endif
Signature · 1 line
2.14.3
Acked-by on v3 4/4
#4 lore raw
In reply to Thomas Richter
Quoted 53 lines · Thomas Richter

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 dependend json files. This requires a metric named "transaction" in the json files for the platform.

v2 --> v3:
Introduce new function metricgroup__has_metric() to check for the existance of a metric named 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]#

---
 tools/perf/builtin-stat.c     | 12 ++++++++++++
 tools/perf/util/metricgroup.c | 23 +++++++++++++++++++++++
 tools/perf/util/metricgroup.h |  1 +
 3 files changed, 36 insertions(+)
tools/perf/builtin-stat.c +2 -0
index a4f662a462c6..e309279e7b04 100644
@@ -2425,6 +2425,18 @@ static int add_default_attributes(void)
 	if (transaction_run) {
 		struct parse_events_error errinfo;
 
+		/* Handle -T as -M transaction. Once platform specific metrics
+		 * support has been added to the json files, all archictures

tools/perf/builtin-stat.c static int add_default_attributes(void) · line 2439

Quoted 10 lines
tools/perf/builtin-stat.c +10 -0
+		 * will use this approach. To determine transaction support
+		 * on an architecture test for such a metric name.
+		 */
+		if (metricgroup__has_metric("transaction")) {
+			struct option opt = { .value = &evsel_list };
+
+			return metricgroup__parse_groups(&opt, "transaction",
+							 &metric_events);
+		}
+

this won't apply now.. needs rebase to current Arnaldo's perf/core

but other than that and with Andi's comment

thanks,
jirka