From patchwork Tue Nov 22 19:29:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 24529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2404910wrr; Tue, 22 Nov 2022 11:40:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7k5bBRjHEtaym9KevuFO5eoqUX+F6/bLAudzSARLS0PSuoHQABftvvi01p2MMYk1STVRwQ X-Received: by 2002:aa7:c145:0:b0:469:400a:3f8e with SMTP id r5-20020aa7c145000000b00469400a3f8emr9047602edp.108.1669146001507; Tue, 22 Nov 2022 11:40:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669146001; cv=none; d=google.com; s=arc-20160816; b=k4GlAK4S2yPoVAbzG0wF5IPHnfZ7O6lXX3u2wraQjPu/IdlzUtVTMTcRy5xnqctnxK s+1/k/qXzbA1EctZneYkqbqiu8De8w+jsKAY/hfi7dZcbopLnxQ8Md+KDkuVsfQy73SH H3EQu4TSwHABYLEXFiUydrt03sbPE3yMV5NjMZ2InVV912tCGk6PLfnX7cz+/L/WFRR4 BGq/B/hopIDLjziQIgpFuc7vkiE/5e9u7aqN/wEpwrI4Mkbx80pofUT5R9g+xcANaVgd hkuXFnlUrJhHPb3HPz/cvj8A3c8OvmqyA8Tb7aLSUX28IhzuBttOpiA4NJH51k6zs3UI kfdw== 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=eQtqTu7JRNjFnV6o8lHrVhZyrgiyx0mHVqwoCilAwG0=; b=0fA/SK8uF+4WddPpa/zAkhdVNVR8ka27hC6MhSQhWi/IvsSNlY0HrqG7FjL/Zt81A6 zGfgZCQi0C+4Nuq8CNSqTQgFoRCnl+26Q9QIjnf0XXAG/F+QOjoYH5oFxn0Bmfplid6q SCNJroBre5P9WShZNkBXbjJhLyvK4FbPcTWeVe3NzMg2ktbGoZIrzcGFLGh+Coi2wpnn nimlNBmEI/DzHxPCRTY8fCmk9C/nUDMzqbexPxmw1uW4UISgl7Xt/3EM8v9+D9uMPBhP xEEVFyJq2avhST0ZOl4u9lt8Q/7Gtxz0QFbeKtX7assrlHM3IgdkHvEBm0nzNT2hcB4E RhQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cHfYR5FI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz3-20020a1709072ce300b007b29a6b7bd2si12579200ejc.662.2022.11.22.11.39.34; Tue, 22 Nov 2022 11:40:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cHfYR5FI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234828AbiKVTbY (ORCPT + 99 others); Tue, 22 Nov 2022 14:31:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbiKVTbK (ORCPT ); Tue, 22 Nov 2022 14:31:10 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471CC92B42 for ; Tue, 22 Nov 2022 11:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669145409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eQtqTu7JRNjFnV6o8lHrVhZyrgiyx0mHVqwoCilAwG0=; b=cHfYR5FI7gs5KBa6wABcFhvST4XH2TkGe23cXdLSkO9pwTnjUWPOaEF53H7CpTH6AeHVSe 0b7udjKznrEPwTz9cGSXiwUYH2BqO8eL5EEfj4W4TGKCqUAzM14iyavvetXGnAauNwzCQV puRlq1gEnBTpfFeLEqGMlGc54s8IxmQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-668-xi6gbFknMy63a4Nqet-pkw-1; Tue, 22 Nov 2022 14:30:08 -0500 X-MC-Unique: xi6gbFknMy63a4Nqet-pkw-1 Received: by mail-wm1-f70.google.com with SMTP id q12-20020a1ce90c000000b003d00f3fe1e7so3324197wmc.4 for ; Tue, 22 Nov 2022 11:30:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eQtqTu7JRNjFnV6o8lHrVhZyrgiyx0mHVqwoCilAwG0=; b=SvHyq3eXfvSOdqegQmBFaCzDlYTYSNyKAVikb84E23LpwpoV1qdHXRGWYNWbHpmb8y DcTnkXlwasOfXGWGwBpASd2HHolMYsmcOkxmW5/j6pPpFFglycJ0KxlGCcpo2ke53R8N /OPcSvRdHhzkUjOfy+F4qFRgKqKGhtzoiq8CYDa5gOJmg0ebEslvF4KWuO1loAForNzG S8EzAVoxgGBNUi9JWoNVUsCTbTNjyi9M83+TR4GTq07RdPOUaS78Ly/ajE8ryzbWK1gS 8vZy9W3wTZwHmrpLNmhOo4nZkNFq1Bsp2F0Ui0UaZIWPmPaFmw6OU1zUC/3UvTlE1yWP SZhA== X-Gm-Message-State: ANoB5pljov2ALT0Jv5J1ZjRyPYi48TaGG0FYs8IpV7ftK1uSdQ8hnI4V CiP2Y/mjoJXL6qPDxEvoVAdkQva+e/05/+BZ6ztoTnmHCnNjgQxtuVpVz2w3CZ/jVowTmXDzHEy CXU9LobQGecrfT9TowMcZkAy9trp8Fp73O3v5Z8KVDG94aT0hXZZFxUl1CY9WEpyZIV/1pjRm6w WW X-Received: by 2002:a05:600c:3ba1:b0:3d0:47c:9ff5 with SMTP id n33-20020a05600c3ba100b003d0047c9ff5mr10845525wms.121.1669145406535; Tue, 22 Nov 2022 11:30:06 -0800 (PST) X-Received: by 2002:a05:600c:3ba1:b0:3d0:47c:9ff5 with SMTP id n33-20020a05600c3ba100b003d0047c9ff5mr10845499wms.121.1669145406296; Tue, 22 Nov 2022 11:30:06 -0800 (PST) Received: from vschneid.remote.csb ([154.57.232.159]) by smtp.gmail.com with ESMTPSA id r14-20020adff10e000000b002366553eca7sm4173682wro.83.2022.11.22.11.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 11:30:05 -0800 (PST) From: Valentin Schneider To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Peter Zijlstra , Frederic Weisbecker , Juri Lelli , Phil Auld , Marcelo Tosatti Subject: [PATCH v5 2/5] workqueue: Factorize unbind/rebind_workers() logic Date: Tue, 22 Nov 2022 19:29:34 +0000 Message-Id: <20221122192937.2386494-3-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221122192937.2386494-1-vschneid@redhat.com> References: <20221122192937.2386494-1-vschneid@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750226437758922372?= X-GMAIL-MSGID: =?utf-8?q?1750226437758922372?= Later patches will reuse this code, move it into reusable functions. Signed-off-by: Valentin Schneider --- kernel/workqueue.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 8e21c352c1558..8185a42848c50 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1972,6 +1972,23 @@ static struct worker *create_worker(struct worker_pool *pool) return NULL; } +static void unbind_worker(struct worker *worker) +{ + lockdep_assert_held(&wq_pool_attach_mutex); + + kthread_set_per_cpu(worker->task, -1); + if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask)) + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0); + else + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); +} + +static void rebind_worker(struct worker *worker, struct worker_pool *pool) +{ + kthread_set_per_cpu(worker->task, pool->cpu); + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask) < 0); +} + /** * destroy_worker - destroy a workqueue worker * @worker: worker to be destroyed @@ -5008,13 +5025,8 @@ static void unbind_workers(int cpu) raw_spin_unlock_irq(&pool->lock); - for_each_pool_worker(worker, pool) { - kthread_set_per_cpu(worker->task, -1); - if (cpumask_intersects(wq_unbound_cpumask, cpu_active_mask)) - WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, wq_unbound_cpumask) < 0); - else - WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); - } + for_each_pool_worker(worker, pool) + unbind_worker(worker); mutex_unlock(&wq_pool_attach_mutex); } @@ -5039,11 +5051,8 @@ static void rebind_workers(struct worker_pool *pool) * of all workers first and then clear UNBOUND. As we're called * from CPU_ONLINE, the following shouldn't fail. */ - for_each_pool_worker(worker, pool) { - kthread_set_per_cpu(worker->task, pool->cpu); - WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, - pool->attrs->cpumask) < 0); - } + for_each_pool_worker(worker, pool) + rebind_worker(worker, pool); raw_spin_lock_irq(&pool->lock);