lkml.org 
[lkml]   [2023]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v7 4/4] workqueue: Unbind kworkers before sending them to exit()
Hello,

The series generally looks good to me. Just one thing.

On Mon, Jan 09, 2023 at 01:33:16PM +0000, Valentin Schneider wrote:
> @@ -3658,13 +3702,24 @@ static void put_unbound_pool(struct worker_pool *pool)
> TASK_UNINTERRUPTIBLE);
> pool->flags |= POOL_MANAGER_ACTIVE;
>
> + /*
> + * We need to hold wq_pool_attach_mutex() while destroying the workers,
> + * but we can't grab it in rcuwait_wait_event() as it can clobber
> + * current's task state. We can drop pool->lock here as we've set
> + * POOL_MANAGER_ACTIVE, no one else can steal our manager position.
> + */
> + raw_spin_unlock_irq(&pool->lock);
> + mutex_lock(&wq_pool_attach_mutex);
> + raw_spin_lock_irq(&pool->lock);

The original pattern was a bit weird to begin with and this makes it quite
worse. Let's do something more straight forward like:

while (true) {
rcuwait_wait_event(&manager_wait,
!(pool->flags & POOL_MANAGER_ACTIVE),
TASK_UNINTERRUPTIBLE);
mutex_lock(&wq_pool_attach_mutex);
raw_spin_lock_irq(&pool->lock);
if (!(pool->flags & POOL_MANAGER_ACTIVE)) {
pool->flags |= POOL_MANAGER_ACTIVE;
break;
}
raw_spin_unlock_irq(&pool->lock);
mutex_unlock(&wq_pool_attach_mutex);
}
Thanks.

--
tejun

\
 
 \ /
  Last update: 2023-03-26 23:35    [W:0.072 / U:0.340 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site