From patchwork Thu Jan 12 16:14:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 42524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3971893wrt; Thu, 12 Jan 2023 08:20:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgtzFJN7uuZMzJ8kVysSnv7Qvqg3DEOEE0nW1YGChOlOrUPyXtzWQebpZ4QiDRhzfMH3Ix X-Received: by 2002:a17:906:9d8e:b0:84d:3921:11e2 with SMTP id fq14-20020a1709069d8e00b0084d392111e2mr14792147ejc.58.1673540415042; Thu, 12 Jan 2023 08:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673540415; cv=none; d=google.com; s=arc-20160816; b=bhAObRVasU90x8K+Twt0zEzhb/91muzyK3lE/XcB8JPVWlUEFJezIO3aDT6xGofYpl Ercc5VSmKt/cCE57ySrwFNDm1VAKYsHgwp2t5S2CnxsWhDbkHk36oY+nV3QELoheqfUf dqDY+E5rXQlw4qdIyjqiokhtDWK1uz9PcUCq4Bdkw1+FRKAHcH1PbgJzoD1XTSjBqISp +Z26EKrTN13+OUZd3cHLAAXHuphwjcwcL94VKRlL3A1wndqeTTLcXiqGTZ+OEN9+CK7+ DEvMkv2wGY5BJAAP/MSdUEs7UR0cmG70JOpBwpaJMiDF0wbwNKVrOkmdVa+s9h95gv5I sYcw== 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=zPiGmU6DNFNZ+RfljYKmRUIGOvwc1vvkVax8OHGXpH1uYhnr6XpPKUofoWXyxXbDX0 a9We0ESdg+0Sd4T+IMU/acCmA10OrPyEAPYfrSEczbDORm8NcxaXGabxn6IJ1meZ/y9X K+A9J3hFzqCkrjzSwpOV48pg/GIhWdw1KjO7aBLe/+65N2/08/u3dPaDLeNl360GQd+b O5gGJZ/ayH6iL94TIWITpNgiOAcirtWAJxYAeyEb9YzI3wMdb9v3Q0nTNYNKLCUzFI/k b9Cr5CMNiQZd29flTFk8h+pDNjBf2z910uFRmFa+2FfkpAaZ9bulJU3GCUWkWPviVcm6 ydJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FkWgXD+w; 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 ga42-20020a1709070c2a00b007ae2b7df929si19560463ejc.72.2023.01.12.08.19.50; Thu, 12 Jan 2023 08:20:15 -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=FkWgXD+w; 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 S229800AbjALQT3 (ORCPT + 99 others); Thu, 12 Jan 2023 11:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237426AbjALQSt (ORCPT ); Thu, 12 Jan 2023 11:18:49 -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 C522A2F78E for ; Thu, 12 Jan 2023 08:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673540092; 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=FkWgXD+wY8r2JXZd1pVhkSgfc5Hr5L7CGmC6oz7MvlhrnK3V7CV2EPk6DWx6R2tz//dkBy X0mIeDXmgSsFGpo1vH9yKM1xmEfi6Q+UR4sKslM4fb2CFPuiuKdN4Gv2pMyiAT1UYTLSC4 ukzoRHtiwWWqNb6oYlVCGyq5iyCgFw0= 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-70-wztmrNb3Pd2gBmKPflTHOQ-1; Thu, 12 Jan 2023 11:14:40 -0500 X-MC-Unique: wztmrNb3Pd2gBmKPflTHOQ-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 49434101A521; Thu, 12 Jan 2023 16:14:40 +0000 (UTC) Received: from vschneid.remote.csb (unknown [10.33.36.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E7642166B26; Thu, 12 Jan 2023 16:14:39 +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 v8 2/5] workqueue: Factorize unbind/rebind_workers() logic Date: Thu, 12 Jan 2023 16:14:28 +0000 Message-Id: <20230112161431.860196-3-vschneid@redhat.com> In-Reply-To: <20230112161431.860196-1-vschneid@redhat.com> References: <20230112161431.860196-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?1754834314456605353?= X-GMAIL-MSGID: =?utf-8?q?1754834314456605353?= 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);