Skip to contentSkip to conversation

perf: sched map skips redundant lines with cpu filters

PATCH Applied Fernand Sieber 3 participants 5 messages Jun 14, 2024 – Jun 16, 2024 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: sched map skips redundant lines with cpu filters

perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines, which makes the output particlularly difficult to read on wide architectures.

Fix it by skipping printing for irrelevant CPUs.

Example snippet of output before fix:

*B0 1.461147 secs
B0
B0
B0
*G0 1.517139 secs

After fix:

*B0 1.461147 secs
*G0 1.517139 secs

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Alexander Shishkin <[email protected]>
---
 tools/perf/builtin-sched.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +6 -6
index 7422c930abaf..aa59f763ca46 100644
@@ -1594,8 +1594,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1622,6 +1620,11 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 		new_shortname = 1;
 	}
 
+	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
+		goto out;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1656,9 +1659,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			color_fprintf(stdout, color, "   ");
 	}
 
-	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
-		goto out;
-
 	timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
 	color_fprintf(stdout, color, "  %12s secs ", stimestamp);
 	if (new_shortname || tr->comm_changed || (verbose > 0 && thread__tid(sched_in))) {
@@ -1675,9 +1675,9 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 	if (sched->map.comp && new_cpu)
 		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-out:
 	color_fprintf(stdout, color, "\n");
 
+out:
 	thread__put(sched_in);
 
 	return 0;
Signature · 1 line
2.40.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 20 lines · Fernand Sieber

perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines, which makes the output particlularly difficult to read on wide architectures.

Fix it by skipping printing for irrelevant CPUs.

Example snippet of output before fix:

*B0 1.461147 secs
B0
B0
B0
*G0 1.517139 secs

After fix:

Quoted 8 lines

*B0 1.461147 secs
*G0 1.517139 secs

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Alexander Shishkin <[email protected]>

Thanks,
Namhyung

Quoted 54 lines
---
 tools/perf/builtin-sched.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +6 -7
index 7422c930abaf..aa59f763ca46 100644
@@ -1594,8 +1594,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
        sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-       printf("  ");
-
        new_shortname = 0;
        if (!tr->shortname[0]) {
                if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1622,6 +1620,11 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
                new_shortname = 1;
        }
 
+       if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
+               goto out;
+
+       printf("  ");
+
        for (i = 0; i < cpus_nr; i++) {
                struct perf_cpu cpu = {
                        .cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1656,9 +1659,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
                        color_fprintf(stdout, color, "   ");
        }
 
-       if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
-               goto out;
-
        timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
        color_fprintf(stdout, color, "  %12s secs ", stimestamp);
        if (new_shortname || tr->comm_changed || (verbose > 0 && thread__tid(sched_in))) {
@@ -1675,9 +1675,9 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
        if (sched->map.comp && new_cpu)
                color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-out:
        color_fprintf(stdout, color, "\n");
 
+out:
        thread__put(sched_in);
 
        return 0;
--

2.40.1

#2 lore raw
In reply to Fernand Sieber

Hi Fernand,

Quoted 17 lines · Fernand Sieber

perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines, which makes the output particlularly difficult to read on wide architectures.

Fix it by skipping printing for irrelevant CPUs.

Example snippet of output before fix:

*B0 1.461147 secs
B0
B0
B0
*G0 1.517139 secs

Quoted 4 lines

After fix:

*B0 1.461147 secs
*G0 1.517139 secs

Yes, this makes sense. The current implementation doesn't even print timestamp for the redundant lines as shown in the example below.

. *F0 708529.114889 secs F0 => schbench:278841
. F0
. F0
. *. 708529.114919 secs

It makes sense to remove them entirely since we can still infer the sched-out time for the selected CPUs implicitly.

Thanks and Regards
Madadi Vineeth Reddy

Quoted 56 lines
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Alexander Shishkin <[email protected]>
---
 tools/perf/builtin-sched.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +6 -6
index 7422c930abaf..aa59f763ca46 100644
@@ -1594,8 +1594,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1622,6 +1620,11 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 		new_shortname = 1;
 	}
 
+	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
+		goto out;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1656,9 +1659,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			color_fprintf(stdout, color, "   ");
 	}
 
-	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
-		goto out;
-
 	timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
 	color_fprintf(stdout, color, "  %12s secs ", stimestamp);
 	if (new_shortname || tr->comm_changed || (verbose > 0 && thread__tid(sched_in))) {
@@ -1675,9 +1675,9 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 	if (sched->map.comp && new_cpu)
 		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-out:
 	color_fprintf(stdout, color, "\n");
 
+out:
 	thread__put(sched_in);
 
 	return 0;
#3 lore raw
In reply to Fernand Sieber

Hi Fernand,

Quoted 17 lines · Fernand Sieber

perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines, which makes the output particlularly difficult to read on wide architectures.

Fix it by skipping printing for irrelevant CPUs.

Example snippet of output before fix:

*B0 1.461147 secs
B0
B0
B0
*G0 1.517139 secs

Quoted 4 lines

After fix:

*B0 1.461147 secs
*G0 1.517139 secs

Yes, this makes sense. The current implementation doesn't even print timestamp for the redundant lines as shown in the example below.

. *F0 708529.114889 secs F0 => schbench:278841
. F0
. F0
. *. 708529.114919 secs

It makes sense to remove them entirely since we can still infer the sched-out time for the selected CPUs implicitly.

Thanks and Regards
Madadi Vineeth Reddy

Quoted 56 lines
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Alexander Shishkin <[email protected]>
---
 tools/perf/builtin-sched.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/builtin-sched.c +6 -6
index 7422c930abaf..aa59f763ca46 100644
@@ -1594,8 +1594,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1622,6 +1620,11 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 		new_shortname = 1;
 	}
 
+	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
+		goto out;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1656,9 +1659,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			color_fprintf(stdout, color, "   ");
 	}
 
-	if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu))
-		goto out;
-
 	timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
 	color_fprintf(stdout, color, "  %12s secs ", stimestamp);
 	if (new_shortname || tr->comm_changed || (verbose > 0 && thread__tid(sched_in))) {
@@ -1675,9 +1675,9 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 	if (sched->map.comp && new_cpu)
 		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-out:
 	color_fprintf(stdout, color, "\n");
 
+out:
 	thread__put(sched_in);
 
 	return 0;
maintainer Applied
#4 lore raw
In reply to Fernand Sieber
Quoted 8 lines · Fernand Sieber

perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines, which makes the output particlularly difficult to read on wide architectures.

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung