Re: [PATCH 3/3] thermal/powerclamp: use PF_IDLE in injection kthread

From: Peter Zijlstra
Date: Mon Nov 14 2016 - 10:12:15 EST


On Wed, Nov 09, 2016 at 11:05:12AM -0800, Jacob Pan wrote:
> +static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *hrtimer)
> +{
> + set_tsk_need_resched(current);

So drivers really should not use this, which is why I had that in
play_idle().

> + return HRTIMER_NORESTART;
> +}
> +
> static void clamp_idle_injection_func(struct kthread_work *work)
> {
> struct powerclamp_worker_data *w_data;
> - unsigned long target_jiffies;
> + unsigned long end_time;
> + unsigned int duration_ms;
>
> w_data = container_of(work, struct powerclamp_worker_data,
> idle_injection_work.work);
>
> + hrtimer_init(&w_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
> + w_data->timer.function = idle_inject_timer_fn;
> +
> /*
> * only elected controlling cpu can collect stats and update
> * control parameters.
> @@ -453,31 +459,17 @@ static void clamp_idle_injection_func(struct kthread_work *work)
> if (should_skip)
> goto balance;
>
> + end_time = jiffies + w_data->duration_jiffies;
> + duration_ms = jiffies_to_msecs(w_data->duration_jiffies);
> + hrtimer_start(&w_data->timer, ms_to_ktime(duration_ms),
> + HRTIMER_MODE_REL_PINNED);
> +
> + cpuidle_use_deepest_state(true);
> + while (time_after(end_time, jiffies))
> + play_idle();

Why that loop?

> + cpuidle_use_deepest_state(false);

> +
> + hrtimer_cancel(&w_data->timer);