Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15463601rwb; Mon, 28 Nov 2022 11:54:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5a5SaFzr1z4OLxp2YMAlFj7fnSe4zrVR9J/4kcaI42bNR8oqDx6IA/iFH0jEsUlZ4ohrhI X-Received: by 2002:a17:906:aac8:b0:7ae:df97:a033 with SMTP id kt8-20020a170906aac800b007aedf97a033mr28855176ejb.344.1669665264286; Mon, 28 Nov 2022 11:54:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669665264; cv=none; d=google.com; s=arc-20160816; b=SoEG/v7HlKpLxyqmjCWSDux34j2DSnVUH8rSPLCF+d0Mc6Ecv5cwkRkpONuuYzm/Cc 6ZvwZD2d+k8GRAXPn3ibyrOxXAjCX3I0ty9wvupMJM7SmYZV7YMRej2Y7FaCLIELglC3 R2yPTANYg5p4c3o8TAqt3WMwKUcRKVcv7/8d7wIJu/PssYX4w0kKBzgGW3k70/1e4fqh 6545ycaBi5u+ZYsQEYc/xT76JWHs0YIMLJWp9wDYl61bNkT2IDhpk4qb+nJKT0QW+6ok vyZT7PWFHNP6p/oNqI0QNTYBzyHipamePeLQTyV1HD8VthMBnPPlUALbxOxTOx1kcEyF FPIA== 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=x7PrwIbephFHwqEggFcsacqm2RtHRnvmk92NJMOeOz6Fmx8GvPzO45eFY8E3JRWGpc h7ePuKeqf28L7KlGl+61Kdf910eZJjKF1HEo7F2nxBbJlrTQF0aKTl4hYJ0tDVvajHtq r4Ow/BvClwJm9n0DqGZpCWJaAXouRlC9nkanuXz/k1aDd9o8wHS+checTMQRRroAtAm1 CY/LUTdgrSZ0Zs0cdrvWk0J1XkFf5JovueVamCa4TjV+65UeolN3BC71atkDYt+1Kp7P O7pvhLdJWuQhUT/ip2Dw5xlCVRtZxyfKs2Q0jZPvQ3wQwGMDuJHvlII7/rG4rurXoKne kL2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+9mBmb5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di16-20020a170906731000b007a835c56b70si10215877ejc.267.2022.11.28.11.54.03; Mon, 28 Nov 2022 11:54:24 -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=G+9mBmb5; 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 S233142AbiK1Sfr (ORCPT + 84 others); Mon, 28 Nov 2022 13:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233210AbiK1Sf0 (ORCPT ); Mon, 28 Nov 2022 13:35:26 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C36E91A05F for ; Mon, 28 Nov 2022 10:32:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669660361; 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=G+9mBmb5pfor3M4bss4cZGDh0i/yqjTKww4jtI/P6ox4fazIr3Zf4Alg1bMFQv4OPEQGPi vV2l3iUjsxfkNL2cyg9xqRVPk/B0QEsP4ktMXrp1tZNXePVozcC1KiTswa+ebcJghWLFwf qrgaFvUkPqUSMAoCV7XliHvQJizBULQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-241--wTU94U4M8KlY8lonqT2Pw-1; Mon, 28 Nov 2022 13:32:19 -0500 X-MC-Unique: -wTU94U4M8KlY8lonqT2Pw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9160A2999B36; Mon, 28 Nov 2022 18:31:20 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.33.37.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 836C02166B2E; Mon, 28 Nov 2022 18:31:19 +0000 (UTC) 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 v6 2/4] workqueue: Factorize unbind/rebind_workers() logic Date: Mon, 28 Nov 2022 18:31:07 +0000 Message-Id: <20221128183109.446754-3-vschneid@redhat.com> In-Reply-To: <20221128183109.446754-1-vschneid@redhat.com> References: <20221128183109.446754-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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 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); -- 2.31.1