Re: [PATCH v7 19/21] timer: Implement the hierarchical pull model

From: Frederic Weisbecker
Date: Tue Jun 06 2023 - 16:11:47 EST


Le Wed, May 24, 2023 at 09:06:27AM +0200, Anna-Maria Behnsen a écrit :
> +u64 tmigr_cpu_deactivate(u64 nextexp)
> +{
> + struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
> + u64 ret;
> +
> + if (!is_tmigr_enabled() || !tmc->tmgroup || !tmc->online)
> + return nextexp;
> +
> + raw_spin_lock(&tmc->lock);
> +
> + /*
> + * CPU is already deactivated in timer migration
> + * hierarchy. tick_nohz_get_sleep_length() calls
> + * tick_nohz_next_event() and thereby timer idle path is
> + * executed once more. tmc->wakeup holds the first timer, when
> + * timer migration hierarchy is completely idle and remote
> + * expiry was done.

This can also hold the first timer in the hierarchy on nodes
having no true migrator, but still with upper nodes having potentially
a migrator, right??

> + * If there is no new next expiry value
> + * handed in which should be inserted into the timer migration
> + * hierarchy, wakeup value is returned.
> + */
> + if (tmc->idle) {
> + ret = tmc->wakeup;
> +
> + tmc->wakeup = KTIME_MAX;
> +
> + if (nextexp != KTIME_MAX) {

This seem to assume that tick_nohz_next_event() on the last idle CPU in an idle
hierarchy is always called right after a timer interrupt arriving on time
(ie: right after a call to tmigr_handle_remote()), but this can actually be called
after any interrupt. Can the following happen or am I overlooking something?

do_idle() {
// ===> <IRQ>
tmigr_handle_remote() {
// find some timer in the hierarchy
// expiring in 2 jiffies
tmc->wakeup = jiffies + 2
}
//<=== </IRQ>
tick_nohz_get_sleep_length() {
get_next_timer_interrupt() {
tmigr_cpu_deactivate() {
wakeup = tmc->wakeup
tmc->wakeup = KTIME_MAX
return wakeup // jiffies + 2
}
}
}
tick_nohz_idle_stop_tick() {
// SLEEP 2 jiffies
}

// ===> <IRQ>
// whatever IRQ that is not timer
// or a timer IRQ firing too early
//<=== </IRQ>

tick_nohz_get_sleep_length() {
get_next_timer_interrupt() {
tmigr_cpu_deactivate() {
wakeup = tmc->wakeup
tmc->wakeup = KTIME_MAX
return wakeup // KTIME_MAX
}
}
}
tick_nohz_idle_stop_tick() {
// SLEEP forever, misses the timer in 2 jiffies
}
}

Thanks.