From patchwork Mon Jan 9 13:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 40872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2162154wrt; Mon, 9 Jan 2023 05:42:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXtEJr1/Kz9t4WsCeR0DgMvwn/hx9sVxM7Ym+4JBVWMA3BZr6h5hZkVy1jwSRya54BEfTCFX X-Received: by 2002:a05:6a20:6aa8:b0:b3:87f8:8387 with SMTP id bi40-20020a056a206aa800b000b387f88387mr48345303pzb.50.1673271751589; Mon, 09 Jan 2023 05:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673271751; cv=none; d=google.com; s=arc-20160816; b=OYYIqEQddvXAFQ91zhGTCB1TQF/nZXx+G+i6KIwItchnwsv2Nmf70FvGtK3UE7Zxxw KF0dll7tAg3SG6RgTaqKEJJd1iE9aTDwdFspekDiiwld/Pqp4N92dg2XpWl0HKEkU9eZ P5BIMTz/mxaJ3zgEshiDdkuwy3ZDeiMz17EVymrP8ISFZA/XpPSHutfl0qClp4TgNvJ/ Qo5884FNCwwj5Yt222k3nxmU2QSRXkEHKWyWlunE1Kfsx81I+Ka1pg2BpoyYAYv/YjKD GPhdslXDwT2ZEkMKySt19RN1lEC9WvPPuslBWXT2h4Ux9IdhJxjH07PmCpPzLMlBO7fY PuMA== 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=A6dex5ykj17DwH3w2pApB0qEylWCN/cbwH7uv0L+wI0=; b=PNwIk8SY4gvBlFctr6rIOz4IIyCvVuJ3Ghub40e/ka51RDKmNm/6HVX6KGZe4Zeewc 6V8FlKrpOEdsHAWnaQaNsYwNUSWOL5AfLT5m715N2CVjh/aP9b5zaz4UKydcBSg0hVV1 Npra36G0DzxrH6xiXxiuBzXWSIF7Mt8J5Qy5HLBOEb3x6Os1QnUEJz+/2sDcnL9yyPGJ ks1VuzpdC4DFOzjVpywnBNFOkIvSKcOtt5OpW//SH1OZ0nbkczu+RJdH/r8M7a1Flrzv 9M62ryusM9dCC/XHQWaVeHB8L0/Iuzpk/yOR2rujUQiy1DseZuDDN/x0nu1tEu82yNXy kB3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y3u1cFb5; 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 r6-20020a635d06000000b004787836f4d6si8911238pgb.396.2023.01.09.05.42.19; Mon, 09 Jan 2023 05:42:31 -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=Y3u1cFb5; 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 S237211AbjAINfr (ORCPT + 99 others); Mon, 9 Jan 2023 08:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237060AbjAINe0 (ORCPT ); Mon, 9 Jan 2023 08:34:26 -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 722861EC65 for ; Mon, 9 Jan 2023 05:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673271217; 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=A6dex5ykj17DwH3w2pApB0qEylWCN/cbwH7uv0L+wI0=; b=Y3u1cFb5PF8ei9IE9Em3imoYQO2smeqeMPeFW09ejPK17BBzTPoTzqSXLpBnarnW0su77k TqkavTYSrbd1+eGQdGH6iXJ9qIcc/lIC810GI7F42HRdwAwGPbcCxyXZay0LaEBPUR9NYK vyl7NVHCiaoNnoJpXrI2OgMOZXhk6qk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-446-857qZRkRNAmGTjAEOm8Osw-1; Mon, 09 Jan 2023 08:33:32 -0500 X-MC-Unique: 857qZRkRNAmGTjAEOm8Osw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95152196EF88; Mon, 9 Jan 2023 13:33:31 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.33.36.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 252CF492C1B; Mon, 9 Jan 2023 13:33:30 +0000 (UTC) From: Valentin Schneider To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Tejun Heo , Peter Zijlstra , Frederic Weisbecker , Juri Lelli , Phil Auld , Marcelo Tosatti Subject: [PATCH v7 2/4] workqueue: Factorize unbind/rebind_workers() logic Date: Mon, 9 Jan 2023 13:33:14 +0000 Message-Id: <20230109133316.4026472-3-vschneid@redhat.com> In-Reply-To: <20230109133316.4026472-1-vschneid@redhat.com> References: <20230109133316.4026472-1-vschneid@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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?1754552599842520922?= X-GMAIL-MSGID: =?utf-8?q?1754552599842520922?= Later patches will reuse this code, move it into reusable functions. Signed-off-by: Valentin Schneider Reviewed-by: Lai Jiangshan --- kernel/workqueue.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 76ea87b0251ce..5e6897f0ef105 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);