Skip to content

Commit f38628b

Browse files
namhyungIngo Molnar
authored andcommitted
perf/core: Reduce PMU access to adjust sample freq
In perf_adjust_freq_unthr_context(), it first starts the event and then stop unnecessarily to adjust the sampling frequency if the event is throttled. For a throttled non-frequency event, it doesn't have a freq so no need to adjust. Just starting the event would be ok. For a frequency event, whether it's throttled or not, it needs to stop before adjusting the frequency. That means it should not start the even if it was throttled. I tried to skip calling the stop callback, but it didn't work well since the event count might not be up to date. It should call the stop callback with PERF_EF_UPDATE anyway. However not calling start would prevent unnecessary MSR accesses (which can be costly) for already stopped events as stop state is saved in the hw config. Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Reviewed-by: Kan Liang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0259bf6 commit f38628b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/events/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4146,7 +4146,8 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list)
41464146
if (hwc->interrupts == MAX_INTERRUPTS) {
41474147
hwc->interrupts = 0;
41484148
perf_log_throttle(event, 1);
4149-
event->pmu->start(event, 0);
4149+
if (!event->attr.freq || !event->attr.sample_freq)
4150+
event->pmu->start(event, 0);
41504151
}
41514152

41524153
if (!event->attr.freq || !event->attr.sample_freq)

0 commit comments

Comments
 (0)