lkml.org 
[lkml]   [2021]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5] hrtimer: avoid retrigger_next_event IPI
Hi, all,

On Fri, Apr 16, 2021 at 01:00:23PM -0300, Marcelo Tosatti wrote:
>
> Setting the realtime clock triggers an IPI to all CPUs to reprogram
> the clock event device.
>
> However, only realtime and TAI clocks have their offsets updated
> (and therefore potentially require a reprogram).
>
> Instead of sending an IPI unconditionally, check each per CPU hrtimer base
> whether it has active timers in the CLOCK_REALTIME and CLOCK_TAI bases. If
> that's not the case, update the realtime and TAI base offsets remotely and
> skip the IPI. This ensures that any subsequently armed timers on
> CLOCK_REALTIME and CLOCK_TAI are evaluated with the correct offsets.
>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
> ---
>
> v5:
> - Add missing hrtimer_update_base (Peter Xu).
>
> v4:
> - Drop unused code (Thomas).
>
> v3:
> - Nicer changelog (Thomas).
> - Code style fixes (Thomas).
> - Compilation warning with CONFIG_HIGH_RES_TIMERS=n (Thomas).
> - Shrink preemption disabled section (Thomas).
>
> v2:
> - Only REALTIME and TAI bases are affected by offset-to-monotonic changes (Thomas).
> - Don't special case nohz_full CPUs (Thomas).
>
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index 5c9d968187ae..06fcc272e28d 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -871,6 +871,19 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram)
> tick_program_event(expires, 1);
> }
>
> +#define CLOCK_SET_BASES ((1U << HRTIMER_BASE_REALTIME) | \
> + (1U << HRTIMER_BASE_REALTIME_SOFT) | \
> + (1U << HRTIMER_BASE_TAI) | \
> + (1U << HRTIMER_BASE_TAI_SOFT))
> +
> +static bool need_reprogram_timer(struct hrtimer_cpu_base *cpu_base)
> +{
> + if (cpu_base->softirq_activated)
> + return true;

A pure question on whether this check is needed...

Here even if softirq_activated==1 (as softirq is going to happen), as long as
(cpu_base->active_bases & CLOCK_SET_BASES)==0, shouldn't it already mean that
"yes indeed clock was set, but no need to kick this cpu as no relevant timer"?
As that question seems to be orthogonal to whether a softirq is going to
trigger on that cpu.

Thanks,

> +
> + return (cpu_base->active_bases & CLOCK_SET_BASES) != 0;
> +}

--
Peter Xu

\
 
 \ /
  Last update: 2021-04-16 19:14    [W:0.075 / U:0.832 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site