Skip to contentSkip to conversation

perf parse-events: Move slots only with topdown

PATCH Applied Ian Rogers 3 participants 3 messages Mar 21, 2022 – Mar 22, 2022 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf parse-events: Move slots only with topdown

If slots isn't with a topdown event then moving it is unnecessary. For example {instructions, slots} is re-ordered:

$ perf stat -e '{instructions,slots}' -a sleep 1

Performance counter stats for 'system wide':

       936,600,825      slots
       144,440,968      instructions

       1.006061423 seconds time elapsed

Which can break tools expecting the command line order to match the printed order. It is necessary to move the slots event first when it appears with topdown events. Add extra checking so that the slots event is only moved in the case of there being a topdown event like:

$ perf stat -e '{instructions,slots,topdown-fe-bound}' -a sleep 1

Performance counter stats for 'system wide':

        2427568570      slots
         300927614      instructions
         551021649      topdown-fe-bound
       1.001771803 seconds time elapsed
Fixes 94dbfd6781a0 ("perf parse-events: Architecture specific leader override")
---
 tools/perf/arch/x86/util/evlist.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
tools/perf/arch/x86/util/evlist.c +14 -4
index 8d9b55959256..cfc208d71f00 100644
@@ -20,17 +20,27 @@ int arch_evlist__add_default_attrs(struct evlist *evlist)
 
 struct evsel *arch_evlist__leader(struct list_head *list)
 {
-	struct evsel *evsel, *first;
+	struct evsel *evsel, *first, *slots = NULL;
+	bool has_topdown = false;
 
 	first = list_first_entry(list, struct evsel, core.node);
 
 	if (!pmu_have_event("cpu", "slots"))
 		return first;
 
+	/* If there is a slots event and a topdown event then the slots event comes first. */
 	__evlist__for_each_entry(list, evsel) {
-		if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") &&
-			evsel->name && strcasestr(evsel->name, "slots"))
-			return evsel;
+		if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") && evsel->name) {
+			if (strcasestr(evsel->name, "slots")) {
+				slots = evsel;
+				if (slots == first)
+					return first;
+			}
+			if (!strncasecmp(evsel->name, "topdown", 7))
+				has_topdown = true;
+			if (slots && has_topdown)
+				return slots;
+		}
 	}
 	return first;
 }
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 25 lines · Ian Rogers

If slots isn't with a topdown event then moving it is unnecessary. For example {instructions, slots} is re-ordered:

$ perf stat -e '{instructions,slots}' -a sleep 1

Performance counter stats for 'system wide':

        936,600,825      slots
        144,440,968      instructions

        1.006061423 seconds time elapsed

Which can break tools expecting the command line order to match the printed order. It is necessary to move the slots event first when it appears with topdown events. Add extra checking so that the slots event is only moved in the case of there being a topdown event like:

$ perf stat -e '{instructions,slots,topdown-fe-bound}' -a sleep 1

Performance counter stats for 'system wide':

         2427568570      slots
          300927614      instructions
          551021649      topdown-fe-bound
Quoted 5 lines
        1.001771803 seconds time elapsed
Fixes 94dbfd6781a0 ("perf parse-events: Architecture specific leader override")

Thanks Ian. The patch works well.

Thanks,
Kan

Quoted 40 lines
---
  tools/perf/arch/x86/util/evlist.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
tools/perf/arch/x86/util/evlist.c +14 -4
index 8d9b55959256..cfc208d71f00 100644
@@ -20,17 +20,27 @@ int arch_evlist__add_default_attrs(struct evlist *evlist)
 
  struct evsel *arch_evlist__leader(struct list_head *list)
  {
-	struct evsel *evsel, *first;
+	struct evsel *evsel, *first, *slots = NULL;
+	bool has_topdown = false;
 
  	first = list_first_entry(list, struct evsel, core.node);
 
  	if (!pmu_have_event("cpu", "slots"))
  		return first;
 
+	/* If there is a slots event and a topdown event then the slots event comes first. */
  	__evlist__for_each_entry(list, evsel) {
-		if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") &&
-			evsel->name && strcasestr(evsel->name, "slots"))
-			return evsel;
+		if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") && evsel->name) {
+			if (strcasestr(evsel->name, "slots")) {
+				slots = evsel;
+				if (slots == first)
+					return first;
+			}
+			if (!strncasecmp(evsel->name, "topdown", 7))
+				has_topdown = true;
+			if (slots && has_topdown)
+				return slots;
+		}
  	}
  	return first;
  }
maintainer Applied
#2 lore raw

Em Tue, Mar 22, 2022 at 07:48:48AM -0400, Liang, Kan escreveu:

Quoted 28 lines · Ian Rogers
Quoted 27 lines

If slots isn't with a topdown event then moving it is unnecessary. For example {instructions, slots} is re-ordered:

$ perf stat -e '{instructions,slots}' -a sleep 1

Performance counter stats for 'system wide':

        936,600,825      slots
        144,440,968      instructions

        1.006061423 seconds time elapsed

Which can break tools expecting the command line order to match the printed order. It is necessary to move the slots event first when it appears with topdown events. Add extra checking so that the slots event is only moved in the case of there being a topdown event like:

$ perf stat -e '{instructions,slots,topdown-fe-bound}' -a sleep 1

Performance counter stats for 'system wide':

         2427568570      slots
          300927614      instructions
          551021649      topdown-fe-bound
        1.001771803 seconds time elapsed
Quoted 7 lines
Quoted 3 lines
Fixes 94dbfd6781a0 ("perf parse-events: Architecture specific leader override")

Thanks Ian. The patch works well.

Thanks, applied.

- Arnaldo