Re: [RFC PATCH v3 08/15] perf workqueue: add queue_work and flush_workqueue functions

From: Namhyung Kim
Date: Tue Aug 24 2021 - 15:40:56 EST


On Fri, Aug 20, 2021 at 3:54 AM Riccardo Mancini <rickyman7@xxxxxxxxx> wrote:
>
> This patch adds functions to queue and wait work_structs, and
> related tests.
>
> When a new work item is added, the workqueue first checks if there
> are threads to wake up. If so, it wakes it up with the given work item,
> otherwise it will pick the next round-robin thread and queue the work
> item to its queue. A thread which completes its queue will go to sleep.
>
> The round-robin mechanism is implemented through the next_worker
> attibute which will point to the next worker to be chosen for queueing.
> When work is assigned to that worker or when the worker goes to sleep,
> the pointer is moved to the next worker in the busy_list, if any.
> When a worker is woken up, it is added in the busy list just before the
> next_worker, so that it will be chosen as last (it's just been assigned
> a work item).

Do we really need this? I think some of the complexity comes
because of this. Can we simply put the works in a list in wq
and workers take it out with a lock? Then the kernel will
distribute the works among the threads for us.

Maybe we can get rid of worker->lock too..

Thanks,
Namhyung