Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2223147pxu; Fri, 18 Dec 2020 08:13:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjMjVt/xdAYY5DuGcmq7P2PnCs/Cc2nGz0b9oHgtSSSqzwL2Aj60wex/mWzE4JWFKsoTAy X-Received: by 2002:aa7:d99a:: with SMTP id u26mr5248774eds.32.1608308035117; Fri, 18 Dec 2020 08:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608308035; cv=none; d=google.com; s=arc-20160816; b=g/ORSwT8gvG+crCUgyueWjMWU3vryLcZIAn1sbHAD/YtZCTMck1/5p5uAuS89BuBsH 1iiOX+VEXsLgQSwxVy9JIRi3KoLLO/aIN2zhkJAf7/bWSJxu+4kMEqbfCbtXHAlpW9y7 guM8Ybukpvu5Dsy/9YBj7+0QpBNsD/JyBF0PhCaG5G/uYWPUGR3KrtZRQMp5joTvI4C3 pcwiySfCziSu/lba9Pu/hy7hM7lmbcDbIKrFMIau9KZRI+hFyTjoJAE1OU18BRFymQYp h4E7DLauFssyIsPN3gfMcEzl4bdzDYYvw7LDoWGm999t7GbPdrz/21WGhYHoPyTdoSvF B/wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D5N7Urez2Ap/i5iB6KY/YtR+1zUuju8vDKp6VV6ij/s=; b=elobbsSI2+JgZDZCali3fw1b677r6wxxvXJnSylJqodX/Ou12J8OY+5RL+kfCLoPo/ vx3acLtwKRiP28UGTaTneiSmbtU6Qk52Ap/VazEp2xFqXnspxJmu2BbxjJfVHMy4m7CO gJR5UzAaD+lQxneDiQYcuB/JvxYLvBKpW90r1dninBOoYEbfFjztpIFzXnpS9puUt7zK FLxzVc5K9vgRXxgH5gUWd42YcH8hlNT+xVOW5ZlkmINW/lfcSJ1JTkDX3RONXcy9Vsy5 KgO6q7x2MY/Vbg2qgJrksK1EJOfls16Nscu1/koio039jT+E+s2iEPNoWysFkNmQM+Yk AvCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=odh4ZXWX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh18si5017826ejb.374.2020.12.18.08.13.32; Fri, 18 Dec 2020 08:13:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=odh4ZXWX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730794AbgLRQLE (ORCPT + 99 others); Fri, 18 Dec 2020 11:11:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbgLRQLE (ORCPT ); Fri, 18 Dec 2020 11:11:04 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F8FC06138C for ; Fri, 18 Dec 2020 08:10:24 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id f14so1530010pju.4 for ; Fri, 18 Dec 2020 08:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D5N7Urez2Ap/i5iB6KY/YtR+1zUuju8vDKp6VV6ij/s=; b=odh4ZXWX/CcH04zRRW2dbx5K9qJBjnB3zaicenSq1CUz2UwSHRJycc/HC9O5ybFyDa QmA7wgEL6k0puHixugVLCx5oa1PAFP4OJ6gVrQQV+KNFyxtSn0YU0ASAibzl0FmPB1uf 5HgPY0bp+x8l8DgICl9BGOGR6GviYqq19QVWp743hSSW5Af2H29yuOVaFk/r8vPp7yCZ LYiRYSmVBvmWF8Tou2bRmaBShgDXQcUFI+f08+CbXXv6iyQstNw//suwwyj8bs3KYlyq k1mYYD9yWDOSIW7LR21edgfdS0xP49qSa1t4AByW4gDBmLsNrZz/Z9d/k8MqwmnkJlsz duRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D5N7Urez2Ap/i5iB6KY/YtR+1zUuju8vDKp6VV6ij/s=; b=Vqhz65Je5xHKTZa7cXAURsQh2wEdnvEk0yGOAdm/pRIZuiIbIT6Nx+15Uwo49wYJLL Qse9Hj8/WqTrxTrUeOc3YH09Ld2kxbj3H2JpOAzKZQUUftMOU/SUvmtY386X5BVI7RKn 5fq3imeo20/awvEs850natt9xp3xTOEiun0FsUWRj8z9mnK0hTPJYONKAwD233s/ZNFj XoOwjVZI/E00Np52ElIbcEKQvvAu0OxArzkGU5cs6kxQZuP3AvGv1ViCQGKJbyFvHcWA VGF/Ns9MGHNvTubZ/QEuX3KK2y7GX7EfVLmsqef6Eq2x8pOsJbCaTUOr+ri1Uu8BjKHA wNNA== X-Gm-Message-State: AOAM532PTmJFLfsdgxCtfoXvdnb1NMvQeZIsVscb7r2XrnjpdweSn+6v lkk0m2KvSQ+L5CDXGrk9SpHN+SvRRl4= X-Received: by 2002:a17:90b:228b:: with SMTP id kx11mr5139393pjb.122.1608307823308; Fri, 18 Dec 2020 08:10:23 -0800 (PST) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id a31sm9621196pgb.93.2020.12.18.08.10.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Dec 2020 08:10:22 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Valentin Schneider , Peter Zijlstra , Qian Cai , Vincent Donnefort , Lai Jiangshan , Tejun Heo , Lai Jiangshan Subject: [PATCH -tip V2 09/10] workqueue: reorganize workqueue_offline_cpu() unbind_workers() Date: Sat, 19 Dec 2020 01:09:18 +0800 Message-Id: <20201218170919.2950-10-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20201218170919.2950-1-jiangshanlai@gmail.com> References: <20201218170919.2950-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan Just move around the code, no functionality changed. Only wq_pool_attach_mutex protected region becomes a little larger. It prepares for later patch protecting wq_online_cpumask in wq_pool_attach_mutex. Acked-by: Tejun Heo Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 90 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index dc891b5c0868..65270729454c 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4904,61 +4904,57 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task) * cpu comes back online. */ -static void unbind_workers(int cpu) +static void unbind_workers(struct worker_pool *pool) { - struct worker_pool *pool; struct worker *worker; - for_each_cpu_worker_pool(pool, cpu) { - mutex_lock(&wq_pool_attach_mutex); - raw_spin_lock_irq(&pool->lock); + lockdep_assert_held(&wq_pool_attach_mutex); - /* - * We've blocked all attach/detach operations. Make all workers - * unbound and set DISASSOCIATED. Before this, all workers - * except for the ones which are still executing works from - * before the last CPU down must be on the cpu. After - * this, they may become diasporas. - */ - for_each_pool_worker(worker, pool) - worker->flags |= WORKER_UNBOUND; + raw_spin_lock_irq(&pool->lock); - pool->flags |= POOL_DISASSOCIATED; + /* + * We've blocked all attach/detach operations. Make all workers + * unbound and set DISASSOCIATED. Before this, all workers + * except for the ones which are still executing works from + * before the last CPU down must be on the cpu. After + * this, they may become diasporas. + */ + for_each_pool_worker(worker, pool) + worker->flags |= WORKER_UNBOUND; - raw_spin_unlock_irq(&pool->lock); + pool->flags |= POOL_DISASSOCIATED; - for_each_pool_worker(worker, pool) - WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); + raw_spin_unlock_irq(&pool->lock); - mutex_unlock(&wq_pool_attach_mutex); + for_each_pool_worker(worker, pool) + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); - /* - * Call schedule() so that we cross rq->lock and thus can - * guarantee sched callbacks see the %WORKER_UNBOUND flag. - * This is necessary as scheduler callbacks may be invoked - * from other cpus. - */ - schedule(); + /* + * Call schedule() so that we cross rq->lock and thus can + * guarantee sched callbacks see the %WORKER_UNBOUND flag. + * This is necessary as scheduler callbacks may be invoked + * from other cpus. + */ + schedule(); - /* - * Sched callbacks are disabled now. Zap nr_running. - * After this, nr_running stays zero and need_more_worker() - * and keep_working() are always true as long as the - * worklist is not empty. This pool now behaves as an - * unbound (in terms of concurrency management) pool which - * are served by workers tied to the pool. - */ - atomic_set(&pool->nr_running, 0); + /* + * Sched callbacks are disabled now. Zap nr_running. + * After this, nr_running stays zero and need_more_worker() + * and keep_working() are always true as long as the + * worklist is not empty. This pool now behaves as an + * unbound (in terms of concurrency management) pool which + * are served by workers tied to the pool. + */ + atomic_set(&pool->nr_running, 0); - /* - * With concurrency management just turned off, a busy - * worker blocking could lead to lengthy stalls. Kick off - * unbound chain execution of currently pending work items. - */ - raw_spin_lock_irq(&pool->lock); - wake_up_worker(pool); - raw_spin_unlock_irq(&pool->lock); - } + /* + * With concurrency management just turned off, a busy + * worker blocking could lead to lengthy stalls. Kick off + * unbound chain execution of currently pending work items. + */ + raw_spin_lock_irq(&pool->lock); + wake_up_worker(pool); + raw_spin_unlock_irq(&pool->lock); } /** @@ -5121,7 +5117,11 @@ int workqueue_offline_cpu(unsigned int cpu) if (WARN_ON(cpu != smp_processor_id())) return -1; - unbind_workers(cpu); + for_each_cpu_worker_pool(pool, cpu) { + mutex_lock(&wq_pool_attach_mutex); + unbind_workers(pool); + mutex_unlock(&wq_pool_attach_mutex); + } mutex_lock(&wq_pool_mutex); cpumask_clear_cpu(cpu, wq_online_cpumask); -- 2.19.1.6.gb485710b