Re: [PATCH v5 4/5] workqueue: Convert the idle_timer to a timer + work_struct

From: Tejun Heo
Date: Tue Nov 22 2022 - 15:24:02 EST


Hello,

On Tue, Nov 22, 2022 at 07:29:36PM +0000, Valentin Schneider wrote:
> @@ -2039,12 +2060,48 @@ static void idle_worker_timeout(struct timer_list *t)
> worker = list_entry(pool->idle_list.prev, struct worker, entry);
> expires = worker->last_active + IDLE_WORKER_TIMEOUT;
>
> + /* All remaining entries will be younger than this */
> if (time_before(jiffies, expires)) {
> - mod_timer(&pool->idle_timer, expires);
> + if (!cull_cnt)
> + mod_timer(&pool->idle_timer, expires);
> break;
> }
>
> + /*
> + * Mark the idle worker ripe for culling.
> + * If a preempted idle worker gets to run before the idle cull
> + * handles it, it will just pop itself out of that list and
> + * continue as normal.
> + */
> + list_move(&worker->entry, &pool->idle_cull_list);
> + }
> + raw_spin_unlock_irq(&pool->lock);
> +
> + if (cull_cnt)
> + queue_work(system_unbound_wq, &pool->idle_cull_work);
> +}

So, you mentioned this explicitly in the cover letter but I think I'd prefer
if the timer were simpler and all logic were in the work item. It just needs
to pick at the first worker and compare the expiration once, right? If that
bothers you, we can make workers keep track of the oldest idle's timestamp
in, say, wq->first_idle_at as the workers go idle and busy and then the
timer can simply look at the value and decide to schedule the work item or
not.

Thanks.

--
tejun