Skip to contentSkip to conversation

perf pmu-events: Don't lower case MetricExpr

RFC PATCH In review Ian Rogers 2 participants 6 messages Nov 26, 2021 – Jan 12, 2022 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

RFC PATCH 1/1 perf pmu-events: Don't lower case MetricExpr

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

This patch is on top of:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/pmu-events/jevents.c | 2 --
 tools/perf/util/expr.c          | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/pmu-events/jevents.c +0 -2
index 2e7c4153875b..1a57c3f81dd4 100644
@@ -672,8 +672,6 @@ static int json_events(const char *fn,
 				addfield(map, &je.metric_constraint, "", "", val);
 			} else if (json_streq(map, field, "MetricExpr")) {
 				addfield(map, &je.metric_expr, "", "", val);
-				for (s = je.metric_expr; *s; s++)
-					*s = tolower(*s);
 			} else if (json_streq(map, field, "ArchStdEvent")) {
 				addfield(map, &arch_std, "", "", val);
 				for (s = arch_std; *s; s++)
tools/perf/util/expr.c +1 -1
index cdbab4f959fe..5cd6b9ff2489 100644
@@ -397,7 +397,7 @@ double expr__get_literal(const char *literal)
 	static struct cpu_topology *topology;
 	double result = NAN;
 
-	if (!strcmp("#smt_on", literal)) {
+	if (!strcasecmp("#smt_on", literal)) {
 		result =  smt_on() > 0 ? 1.0 : 0.0;
 		goto out;
 	}
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
author reviewer
#1 lore raw
Quoted 6 lines · Ian Rogers

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

Ping.

Thanks,
Ian

Quoted 38 lines

This patch is on top of:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/pmu-events/jevents.c | 2 --
 tools/perf/util/expr.c          | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/pmu-events/jevents.c +0 -2
index 2e7c4153875b..1a57c3f81dd4 100644
@@ -672,8 +672,6 @@ static int json_events(const char *fn,
                                addfield(map, &je.metric_constraint, "", "", val);
                        } else if (json_streq(map, field, "MetricExpr")) {
                                addfield(map, &je.metric_expr, "", "", val);
-                               for (s = je.metric_expr; *s; s++)
-                                       *s = tolower(*s);
                        } else if (json_streq(map, field, "ArchStdEvent")) {
                                addfield(map, &arch_std, "", "", val);
                                for (s = arch_std; *s; s++)
tools/perf/util/expr.c +1 -2
index cdbab4f959fe..5cd6b9ff2489 100644
@@ -397,7 +397,7 @@ double expr__get_literal(const char *literal)
        static struct cpu_topology *topology;
        double result = NAN;
 
-       if (!strcmp("#smt_on", literal)) {
+       if (!strcasecmp("#smt_on", literal)) {
                result =  smt_on() > 0 ? 1.0 : 0.0;
                goto out;
        }
--

2.34.0.rc2.393.gf8c9666880-goog

#2 lore raw

Em Wed, Jan 12, 2022 at 09:22:51AM -0800, Ian Rogers escreveu:

Quoted 9 lines · Ian Rogers
Quoted 6 lines

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

Ping.

I tried applying [email protected] on top of your perf_cpu series, it failed, will check.

BTW, I got the two other patches in that series:

⬢[acme@toolbox perf]$ git log --oneline -2
6dd8646939a770e4 (HEAD -> perf/core) perf tools: Probe non-deprecated sysfs path 1st 0ce05781f4905fcf perf tools: Fix SMT fallback with large core counts ⬢[acme@toolbox perf]$

- Arnaldo

Quoted 41 lines

Thanks,
Ian

Quoted 38 lines

This patch is on top of:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/pmu-events/jevents.c | 2 --
 tools/perf/util/expr.c          | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/pmu-events/jevents.c +0 -2
index 2e7c4153875b..1a57c3f81dd4 100644
@@ -672,8 +672,6 @@ static int json_events(const char *fn,
                                addfield(map, &je.metric_constraint, "", "", val);
                        } else if (json_streq(map, field, "MetricExpr")) {
                                addfield(map, &je.metric_expr, "", "", val);
-                               for (s = je.metric_expr; *s; s++)
-                                       *s = tolower(*s);
                        } else if (json_streq(map, field, "ArchStdEvent")) {
                                addfield(map, &arch_std, "", "", val);
                                for (s = arch_std; *s; s++)
tools/perf/util/expr.c +1 -2
index cdbab4f959fe..5cd6b9ff2489 100644
@@ -397,7 +397,7 @@ double expr__get_literal(const char *literal)
        static struct cpu_topology *topology;
        double result = NAN;
 
-       if (!strcmp("#smt_on", literal)) {
+       if (!strcasecmp("#smt_on", literal)) {
                result =  smt_on() > 0 ? 1.0 : 0.0;
                goto out;
        }
--

2.34.0.rc2.393.gf8c9666880-goog

Signature · 1 line
- Arnaldo
#3 lore raw

Em Wed, Jan 12, 2022 at 02:45:07PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 14 lines

Em Wed, Jan 12, 2022 at 09:22:51AM -0800, Ian Rogers escreveu:

Quoted 9 lines · Ian Rogers
Quoted 6 lines

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

Ping.

I tried applying [email protected] on top of your perf_cpu series, it failed, will check.

Quoted 6 lines

BTW, I got the two other patches in that series:

⬢[acme@toolbox perf]$ git log --oneline -2
6dd8646939a770e4 (HEAD -> perf/core) perf tools: Probe non-deprecated sysfs path 1st 0ce05781f4905fcf perf tools: Fix SMT fallback with large core counts ⬢[acme@toolbox perf]$

It was due to that cpu__max_present_cpu().cpu;

Fixed, applied.

- Arnaldo

tools/perf/util/expr.c +25 -12
index e808738493e219fd..c94fb9bef919f5cb 100644
@@ -405,12 +405,17 @@ double expr_id_data__source_count(const struct expr_id_data *data)
 double expr__get_literal(const char *literal)
 {
 	static struct cpu_topology *topology;
+	double result = NAN;
 
-	if (!strcmp("#smt_on", literal))
-		return smt_on() > 0 ? 1.0 : 0.0;
+	if (!strcmp("#smt_on", literal)) {
+		result = smt_on() > 0 ? 1.0 : 0.0;
+		goto out;
+	}
 
-	if (!strcmp("#num_cpus", literal))
-		return cpu__max_present_cpu().cpu;
+	if (!strcmp("#num_cpus", literal)) {
+		result = cpu__max_present_cpu().cpu;
+		goto out;
+	}
 
 	/*
 	 * Assume that topology strings are consistent, such as CPUs "0-1"
@@ -422,16 +427,24 @@ double expr__get_literal(const char *literal)
 		topology = cpu_topology__new();
 		if (!topology) {
 			pr_err("Error creating CPU topology");
-			return NAN;
+			goto out;
 		}
 	}
-	if (!strcmp("#num_packages", literal))
-		return topology->package_cpus_lists;
-	if (!strcmp("#num_dies", literal))
-		return topology->die_cpus_lists;
-	if (!strcmp("#num_cores", literal))
-		return topology->core_cpus_lists;
+	if (!strcmp("#num_packages", literal)) {
+		result = topology->package_cpus_lists;
+		goto out;
+	}
+	if (!strcmp("#num_dies", literal)) {
+		result = topology->die_cpus_lists;
+		goto out;
+	}
+	if (!strcmp("#num_cores", literal)) {
+		result = topology->core_cpus_lists;
+		goto out;
+	}
 
 	pr_err("Unrecognized literal '%s'", literal);
-	return NAN;
+out:
+	pr_debug2("literal: %s = %f\n", literal, result);
+	return result;
 }
#4 lore raw
In reply to Arnaldo Carvalho de Melo

Em Wed, Jan 12, 2022 at 02:45:07PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 14 lines

Em Wed, Jan 12, 2022 at 09:22:51AM -0800, Ian Rogers escreveu:

Quoted 9 lines · Ian Rogers
Quoted 6 lines

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

Ping.

I tried applying [email protected] on top of your perf_cpu series, it failed, will check.

Quoted 6 lines

BTW, I got the two other patches in that series:

⬢[acme@toolbox perf]$ git log --oneline -2
6dd8646939a770e4 (HEAD -> perf/core) perf tools: Probe non-deprecated sysfs path 1st 0ce05781f4905fcf perf tools: Fix SMT fallback with large core counts ⬢[acme@toolbox perf]$

Ok, I have that one now on, but could Andi or somebody else that works more frequently with that code provide an Acked-by or Reviewed-by?

- Arnaldo

Quoted 47 lines

- Arnaldo

Quoted 41 lines

Thanks,
Ian

Quoted 38 lines

This patch is on top of:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/pmu-events/jevents.c | 2 --
 tools/perf/util/expr.c          | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/pmu-events/jevents.c +0 -2
index 2e7c4153875b..1a57c3f81dd4 100644
@@ -672,8 +672,6 @@ static int json_events(const char *fn,
                                addfield(map, &je.metric_constraint, "", "", val);
                        } else if (json_streq(map, field, "MetricExpr")) {
                                addfield(map, &je.metric_expr, "", "", val);
-                               for (s = je.metric_expr; *s; s++)
-                                       *s = tolower(*s);
                        } else if (json_streq(map, field, "ArchStdEvent")) {
                                addfield(map, &arch_std, "", "", val);
                                for (s = arch_std; *s; s++)
tools/perf/util/expr.c +1 -2
index cdbab4f959fe..5cd6b9ff2489 100644
@@ -397,7 +397,7 @@ double expr__get_literal(const char *literal)
        static struct cpu_topology *topology;
        double result = NAN;
 
-       if (!strcmp("#smt_on", literal)) {
+       if (!strcasecmp("#smt_on", literal)) {
                result =  smt_on() > 0 ? 1.0 : 0.0;
                goto out;
        }
--

2.34.0.rc2.393.gf8c9666880-goog

Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
maintainer Acked-by Jiri Olsa
#5 lore raw

Em Wed, Jan 12, 2022 at 02:53:42PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 17 lines

Em Wed, Jan 12, 2022 at 02:45:07PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 16 lines

Em Wed, Jan 12, 2022 at 09:22:51AM -0800, Ian Rogers escreveu:

Quoted 9 lines · Ian Rogers
Quoted 6 lines

This patch changes MetricExpr to be written out in the same case. This enables events in metrics to use modifiers like 'G' which currently yield parse errors when made lower case. To keep tests passing the literal #smt_on is compared in a non-case sensitive way - #SMT_on is present in at least SkylakeX metrics.

Ping.

I tried applying [email protected] on top of your perf_cpu series, it failed, will check.

BTW, I got the two other patches in that series:

Quoted 7 lines
Quoted 4 lines

⬢[acme@toolbox perf]$ git log --oneline -2
6dd8646939a770e4 (HEAD -> perf/core) perf tools: Probe non-deprecated sysfs path 1st 0ce05781f4905fcf perf tools: Fix SMT fallback with large core counts ⬢[acme@toolbox perf]$

Ok, I have that one now on, but could Andi or somebody else that works more frequently with that code provide an Acked-by or Reviewed-by?

Its there since since MetricExpr was introduced:

commit 00636c3b48e8acac2acd2601274c6eab4ecf8201

Author: Andi Kleen <[email protected]>
Date:   Mon Mar 20 13:17:07 2017 -0700

perf pmu: Support MetricExpr header in JSON event list

Add support for parsing the MetricExpr header in the JSON event lists and storing them in the alias structure.

Used in the next patch.

v2: Change DividedBy to MetricExpr
v3: Really catch all uses of DividedBy

-----------------------------

There is no explanation as to why it should be lowercased, and Ian's reason not to lowercase it is valid, not to lose information, so I'll apply the patch, please holler if there is some other subtlety I'm missing...

- Arnaldo

Quoted 46 lines
Quoted 42 lines
Quoted 38 lines
Quoted 38 lines

This patch is on top of:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/pmu-events/jevents.c | 2 --
 tools/perf/util/expr.c          | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/pmu-events/jevents.c +0 -2
index 2e7c4153875b..1a57c3f81dd4 100644
@@ -672,8 +672,6 @@ static int json_events(const char *fn,
                                addfield(map, &je.metric_constraint, "", "", val);
                        } else if (json_streq(map, field, "MetricExpr")) {
                                addfield(map, &je.metric_expr, "", "", val);
-                               for (s = je.metric_expr; *s; s++)
-                                       *s = tolower(*s);
                        } else if (json_streq(map, field, "ArchStdEvent")) {
                                addfield(map, &arch_std, "", "", val);
                                for (s = arch_std; *s; s++)
tools/perf/util/expr.c +1 -2
index cdbab4f959fe..5cd6b9ff2489 100644
@@ -397,7 +397,7 @@ double expr__get_literal(const char *literal)
        static struct cpu_topology *topology;
        double result = NAN;
 
-       if (!strcmp("#smt_on", literal)) {
+       if (!strcasecmp("#smt_on", literal)) {
                result =  smt_on() > 0 ? 1.0 : 0.0;
                goto out;
        }
--

2.34.0.rc2.393.gf8c9666880-goog

Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo