Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp7520577pxu; Fri, 25 Dec 2020 17:55:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJynEzduwnXzOs2C8MbPfKM2UrkYZ+ZBarhSOBfhpzhC8g9C8UMjDio/T7H4JMs8TThVN2lD X-Received: by 2002:a50:d2d2:: with SMTP id q18mr33333889edg.346.1608947714709; Fri, 25 Dec 2020 17:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608947714; cv=none; d=google.com; s=arc-20160816; b=Wiaz7yy0QIFkwdt3rK0WmKNCRwXTjxQxokiEUWmXIXI8v+MJ7FdaElk2QdfoLdxsBP q7/BhHa5KwFVkNbwE8fwBVmdpBZTERe/4eJv873GNJ+vEQJGYOr3aAgT4E6FscyjgWiT nuVWWchLD6K9bjMJL452/K35KwKjnuSF/HdnhzjdjaKNV0WlsD3W2oCxp4fzIdVSS0BZ YkTMPPRQTN0XzgcpTY8HfwjFcG3wBtrRMr7p9tymQ+ePhxFtp5hRalMH2xtkdqlE5rqF Df58YtuskQ9hPkXzQlTOuvrJFeejRDJ51nYvMjgWEagH+Qwn8WHwkWsNVcAAn3OcV03L Msag== 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=15jkmCKfS1m1xn/sVulof+I5g/Kt2DoKoW3K5fEsg+k=; b=SxEKpQXdrpxLLETLU3Xor4sTInI1SentjsE0gGiGZq9gtNQA2oFQZeiqhTM1XSsD3K DuDT2sblzt5TJuLKvSEz8f+f//hj3dlIuYkjW+d8ignwbTyLGF8D/6C0fJu2qx2iKIy9 yibnGhLbocBg+1Anjd1JWFb/yS7IGdEz4tfV4rvqr7eT0H5T23vZedowxf4QjEWaeBvy ccgZuUsMBNxNnpTncenGW63CDXTODwMkD0TN1sfsyCDei15NvRCags+6o8WCcaiV+/Iy 3VMyhFjwMjZlUT3iWazsikuRTODd5hbs6TUD9b/S+uIwUEbNmDjvaOnCXZ85TG0zXVa0 Q/rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NBjF8BHM; 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 d9si10080507eds.129.2020.12.25.17.54.52; Fri, 25 Dec 2020 17:55:14 -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=NBjF8BHM; 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 S1729317AbgLZBwL (ORCPT + 99 others); Fri, 25 Dec 2020 20:52:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726164AbgLZBwK (ORCPT ); Fri, 25 Dec 2020 20:52:10 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FDF5C061757 for ; Fri, 25 Dec 2020 17:51:30 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id lb18so2941853pjb.5 for ; Fri, 25 Dec 2020 17:51:30 -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=15jkmCKfS1m1xn/sVulof+I5g/Kt2DoKoW3K5fEsg+k=; b=NBjF8BHM+XJaHT/icVvQv4624yNhoUYFSZXU80vzuWpYJeIU+B32d1AsyV5/PCM24I W9ykA6Ah5qiURQTRSVCfmrxeNl16DJxxXsEoVoQgmD8mYFcGFwj5bztSe7yRRJ771Nfi 4eU1QJgIRoHIHI7AP6nWcYDn9ljqRL+4vMqT+fHjqRbXQG7JxHAnAB8eEz6a2MKrupez Qe+KmrW2rZ8POJhXMj/O/K7TxxGcbSGS+KPAzeL2OiijjvoIO8scBBja3Gef/wLuBbna a40eSZ9rHwQw4UZe1mmz3dvi2rSAJ5eEEG30aShm9j71BRgsHA5Bt8AR5DPEuv/kna5G 5d/w== 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=15jkmCKfS1m1xn/sVulof+I5g/Kt2DoKoW3K5fEsg+k=; b=p/oPjZZ0tIUgfDUWlZEqXltBd/HqZB9ehTjLpiqTLow7UpQWp6kNUF+wlrJ60TO3G5 dX3Eka0ZTEfGT5ozPRJS2ar/pWv84ufnatryzQWswM0sWCUu7w3m6ICNsCy49xwvb7WY P4DTX9y3smFOumMxKz+jvgT8rAeIWkCuc9OnTQnD9Ecc2HZsw8sqUcwWId95eZ2pfr3u cMPWzRWu1HoiI7ZkjwOM0rtS/dSa32obbLgHDDPaAHbXvMj896af1w8/YY0v2jHOO3Ir NYJMgfisKIfaLoQXCRHtsDix9PiibF4aAVpczV7psze5DzpaWWazKmRnQeS63RnPf8Df m2OA== X-Gm-Message-State: AOAM532zGmgy5aIOYZfGGvOGa7YJxEta9ah9qyJCLACZxsjrTTNYnGoK ptXqYuOGJ8PiNyrsUpOVzak4V9VgV8M= X-Received: by 2002:a17:902:7c04:b029:db:e44d:9366 with SMTP id x4-20020a1709027c04b02900dbe44d9366mr35219811pll.51.1608947489551; Fri, 25 Dec 2020 17:51:29 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id o11sm6313909pjs.36.2020.12.25.17.51.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Dec 2020 17:51:29 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Valentin Schneider , Peter Zijlstra , Qian Cai , Vincent Donnefort , Dexuan Cui , Lai Jiangshan , Tejun Heo , Lai Jiangshan Subject: [PATCH -tip V3 7/8] workqueue: reorganize workqueue_offline_cpu() unbind_workers() Date: Sat, 26 Dec 2020 10:51:15 +0800 Message-Id: <20201226025117.2770-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20201226025117.2770-1-jiangshanlai@gmail.com> References: <20201226025117.2770-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 94545e6feda5..dd32398edf55 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4896,61 +4896,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); } /** @@ -5122,7 +5118,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