From patchwork Mon Nov 28 18:31:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 26917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5873649wrr; Mon, 28 Nov 2022 10:44:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf56grwQCZSO8+so8XclPribBn3OXhQzW8fEFFlx2Qz37ou8/OUOAq7f8iFMA6/MuLveC/LY X-Received: by 2002:a17:906:2c5b:b0:7ae:180f:e6e with SMTP id f27-20020a1709062c5b00b007ae180f0e6emr27759542ejh.498.1669661070027; Mon, 28 Nov 2022 10:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669661070; cv=none; d=google.com; s=arc-20160816; b=KLvvAofF7o+oLPyNPU0MfiCvaa6XnJNKZUB72PiLA01g4I5DKBjkOuzIK8Skw0TbcS DvO8egoDVrR4IiQL/FDM9DyHf/5Py1Wkf03Ko0R6cDDGFIm9/UZG0pQdKYI76JbI/czL xglxKf6Mfa77k90uym5XtRXuWDc2Pn/7RiLWjVnse/mHAJO6Q+chf9G7qxl1UUzaD4Zg xS9FbdOT0EEz8r1r6m7FQGFXYd/9V9CYkL8EZZhf40iTJLIgWWZziyfGUk9rYNMjInHG 5C42cQXN8URfoTGwYPfu8lDeAo6tEVQfK8LM1HGXVzy7pGNio+9pE37jMEaPSTY4xyBY dFZw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402278700b00463f8aad371si11963535ede.239.2022.11.28.10.44.00; Mon, 28 Nov 2022 10:44:30 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750766526340562513?= X-GMAIL-MSGID: =?utf-8?q?1750766526340562513?= 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);