Skip to contentSkip to conversation

perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups

PATCH Superseded Athira Rajeev 3 participants 4 messages Oct 15, 2021 – Oct 21, 2021 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf/core: Avoid calling perf_mux_hrtimer_restart multiple times when scheduling event groups

Perf uses multiplexing if there are more events to be scheduled than the available counters. With multiplexing, event groups will be rotated at specified interval of time which is set using "hrtimer". During event scheduling, if any of the event group fails to schedule, multiplexing gets enabled by setting "rotate_necessary" for that event context and starting the hrtimer by calling "perf_mux_hrtimer_restart".

Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart" multiple times if already rotate_necessary is set for that context. Even though "perf_mux_hrtimer_restart" will just return if hrtimer is already active, this could avoid the overhead of calling this function multiple times if there are many event groups. Patch adds the check to avoid calling perf_mux_hrtimer_restart() for each event group on every schedule.

---
Changelog:
From v1 -> v2:
- Rebased on top of latest kernel source.

 kernel/events/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/events/core.c +4 -2
index f23ca260307f..9e1a06646ad0 100644
@@ -3753,8 +3753,10 @@ static int merge_sched_in(struct perf_event *event, void *data)
 			perf_cgroup_event_disable(event, ctx);
 			perf_event_set_state(event, PERF_EVENT_STATE_ERROR);
 		} else {
-			ctx->rotate_necessary = 1;
-			perf_mux_hrtimer_restart(cpuctx);
+			if (!ctx->rotate_necessary) {
+				ctx->rotate_necessary = 1;
+				perf_mux_hrtimer_restart(cpuctx);
+			}
 			group_update_userpage(event);
 		}
 	}
Signature · 1 line
2.27.0
Acked-by on v2 1/1
#1 lore raw
Quoted 19 lines · Athira Rajeev

Perf uses multiplexing if there are more events to be scheduled than the available counters. With multiplexing, event groups will be rotated at specified interval of time which is set using "hrtimer". During event scheduling, if any of the event group fails to schedule, multiplexing gets enabled by setting "rotate_necessary" for that event context and starting the hrtimer by calling "perf_mux_hrtimer_restart".

Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart" multiple times if already rotate_necessary is set for that context. Even though "perf_mux_hrtimer_restart" will just return if hrtimer is already active, this could avoid the overhead of calling this function multiple times if there are many event groups. Patch adds the check to avoid calling perf_mux_hrtimer_restart() for each event group on every schedule.

Quoted 1 line
maintainer
#2 lore raw
Quoted 19 lines · Song Liu
Quoted 19 lines · Athira Rajeev

Perf uses multiplexing if there are more events to be scheduled than the available counters. With multiplexing, event groups will be rotated at specified interval of time which is set using "hrtimer". During event scheduling, if any of the event group fails to schedule, multiplexing gets enabled by setting "rotate_necessary" for that event context and starting the hrtimer by calling "perf_mux_hrtimer_restart".

Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart" multiple times if already rotate_necessary is set for that context. Even though "perf_mux_hrtimer_restart" will just return if hrtimer is already active, this could avoid the overhead of calling this function multiple times if there are many event groups. Patch adds the check to avoid calling perf_mux_hrtimer_restart() for each event group on every schedule.

Quoted 3 lines
Quoted 1 line

Thanks!

#3 lore raw
Quoted 24 lines · Peter Zijlstra
Quoted 19 lines · Song Liu
Quoted 19 lines · Athira Rajeev

Perf uses multiplexing if there are more events to be scheduled than the available counters. With multiplexing, event groups will be rotated at specified interval of time which is set using "hrtimer". During event scheduling, if any of the event group fails to schedule, multiplexing gets enabled by setting "rotate_necessary" for that event context and starting the hrtimer by calling "perf_mux_hrtimer_restart".

Patch adds an optimisation to avoid calling "perf_mux_hrtimer_restart" multiple times if already rotate_necessary is set for that context. Even though "perf_mux_hrtimer_restart" will just return if hrtimer is already active, this could avoid the overhead of calling this function multiple times if there are many event groups. Patch adds the check to avoid calling perf_mux_hrtimer_restart() for each event group on every schedule.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Thanks!

Thanks for checking the patch.

Hi Peterz,
Should I resend this patch with Acked-by or can you consider pulling it, if the patch looks fine to you.

Thanks
Athira.