From patchwork Thu Nov 3 03:09:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binglei Wang X-Patchwork-Id: 14616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp291826wru; Wed, 2 Nov 2022 20:24:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6t3kcg2Xb//lpUOYIF89dSairZFmSlOhVIYf5FDvULFesKSxqJj9DSBmTtyYys+71C8ory X-Received: by 2002:a63:fe58:0:b0:46f:dc58:b23c with SMTP id x24-20020a63fe58000000b0046fdc58b23cmr12811205pgj.205.1667445888416; Wed, 02 Nov 2022 20:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667445888; cv=none; d=google.com; s=arc-20160816; b=GJqEybK5DRhbfELg5Ol3ZzmTew57yuzGAsaIJFNXSObDpg8zKiuMYgEsuFtU8ragAD EtIX0ircfUCerV3fdGr3D/sm4jdRI/xkxw2zcbhQ81P2fPDhhCxpeWs9kRU+Ut5dmo3h hy9FO1gbRsBOfPpmnl0ET585IVhwEgoivzkwjSrna4Q5d/sAdKYD6GrVQDMmcEBUetq6 l1qje1RStHi/te2++vTzmXAJQrphZ+KDAXyAC4dkU8rtW/jz0+qByTBtOEreBJgnrmMp aHGA6L+5BEBFusAKVIghV0i2TnxbkQ2izXppGWbFza7KuS3gvGhgdcZFrbhdLXZZzwYQ uRaA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=BdWhTXBxXiysd2poPDnV59IYfoHF6Yvsi7EDbvrcVKE=; b=Rj/MRxWFGIoQyKU3MqDWrHXoqCy1c6jZsCl2rLonVFbz46iq15Hfb7FNVJKhBZ/LrO ayZjVntvB96/pJUcsJLmP+ZLxCjhiAUAgO1gDBD800f2JUxWzaK9eo36QrYHv2O+Y9kF qj9gPtHXmk8XdqYti7N1JKsVdadd8XXEmilc7UoJokCBE9GkStf3ked1Qt5FXXCT7Q0p JmTCd/zosJlAoanWD6UyzRR73x2qCt1gQ4Z1ku8QWV21gnXrcinawzMG7PSDrdSt33fW XAcL0pQJTNCIVCMc6IN7jH9k6AjvtlvxETr/qC958/i7bx+TJsLd08OcF6M3Iq0huTve BokQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gYbvK43L; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a17090aa88400b002130053cad7si4030534pjq.7.2022.11.02.20.24.35; Wed, 02 Nov 2022 20:24:48 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=gYbvK43L; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbiKCDKC (ORCPT + 99 others); Wed, 2 Nov 2022 23:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbiKCDJr (ORCPT ); Wed, 2 Nov 2022 23:09:47 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AB0D14009 for ; Wed, 2 Nov 2022 20:09:41 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id y4so702215plb.2 for ; Wed, 02 Nov 2022 20:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BdWhTXBxXiysd2poPDnV59IYfoHF6Yvsi7EDbvrcVKE=; b=gYbvK43L1DZqFx+ncvrgw/oZ6CiqmHTE5VXqD3ed95nY7yH3kULTt25HQtXLklnJaB tgtwTvK906H+5ij8UMm2GcH5+gE1/axheql6d5qiYQXIUI7OkBd8aDXwPJ3pGNo+SzKI 6vjBAhPqgRSNZaaaGYlpjeAnJ8RLRoB4rW6cUWEjufDq7lP2SB2uv/PcMP5NoCcti8cU 94Wh1hJUdzBwdlUhPD50yHQArO9HJG77bepaWCd04enO5PUAu6rsZV2giYlMWRg8s6RA PqbBmJ/bS4WQhFMgbyQboPxkvbpdkk/R/IeAv+lUTDBo8t/cdpyfmQVROOJyAgRYZjDP 7DQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BdWhTXBxXiysd2poPDnV59IYfoHF6Yvsi7EDbvrcVKE=; b=8SVFoAyNH4U1g2mn1pj55onNRCfywUUOCeR6vBKOLDvMougJjmQxST31vSrAtGd8XQ 4mybaj45YKuq45tpDQern1+CW5JfuME9ShU1kC2vA8KcCjBK1g4tKf/Hs5odTag5W4i8 cDxJ2X/1Bdo8MXKCrYphNV85TQuFW+9j0aC4XfqjQiRLMgkuRjWW5Sv27eQp/kzVCdyp zR+GXWwtAUyt4BBpVxnxkX48Q7Z1MKU9ih+GizDI7wZ8mRGi61NPIlYIon4H/6zSknLt Wg2E9pwo/DCFkBnZY8WCxqafQ2d7nNmvw6YK7FOjXDxhYXpoSdWxXRIsGuxmSCUjBrwc WlFA== X-Gm-Message-State: ACrzQf2Q+gTGUctNjgrsg85zh7fN65JrnxPlOMr9s97F1bcj3k4nUALz bjLvIntSQCnLpbMuAshSS19PllrNb/LBlA== X-Received: by 2002:a17:90b:3886:b0:213:5ccc:973b with SMTP id mu6-20020a17090b388600b002135ccc973bmr45301295pjb.193.1667444980508; Wed, 02 Nov 2022 20:09:40 -0700 (PDT) Received: from localhost.localdomain (l3b2w1.cn. [159.138.1.25]) by smtp.gmail.com with ESMTPSA id q1-20020a17090a7a8100b0020d67a726easm2177563pjf.10.2022.11.02.20.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 20:09:40 -0700 (PDT) From: Binglei Wang X-Google-Original-From: Binglei Wang To: tj@kernel.org, jiangshanlai@gmail.com Cc: linux-kernel@vger.kernel.org, Binglei Wang Subject: [PATCH] workqueue: make workers threads stick to HK_TYPE_KTHREAD cpumask Date: Thu, 3 Nov 2022 11:09:33 +0800 Message-Id: <20221103030933.840989-1-l3b2w1@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_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?1748443739621326278?= X-GMAIL-MSGID: =?utf-8?q?1748443739621326278?= From: Binglei Wang When new worker thread created, set its affinity to HK_TYPE_KTHREAD cpumask. When hotplug cpu online, rebind workers's affinity to HK_TYPE_KTHREAD cpumask. Make workers threads stick to HK_TYPE_KTHREAD cpumask all the time. Signed-off-by: Binglei Wang --- kernel/workqueue.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7cd5f5e7e..77b303f5e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1928,6 +1928,7 @@ static struct worker *create_worker(struct worker_pool *pool) struct worker *worker; int id; char id_buf[16]; + const struct cupmask *cpumask = NULL; /* ID is needed to determine kthread name */ id = ida_alloc(&pool->worker_ida, GFP_KERNEL); @@ -1952,7 +1953,10 @@ static struct worker *create_worker(struct worker_pool *pool) goto fail; set_user_nice(worker->task, pool->attrs->nice); - kthread_bind_mask(worker->task, pool->attrs->cpumask); + + if (housekeeping_enabled(HK_TYPE_KTHREAD)) + cpumask = housekeeping_cpumask(HK_TYPE_KTHREAD); + kthread_bind_mask(worker->task, cpumask ? cpumask : pool->attrs->cpumask); /* successful, attach the worker to the pool */ worker_attach_to_pool(worker, pool); @@ -5027,20 +5031,26 @@ static void unbind_workers(int cpu) static void rebind_workers(struct worker_pool *pool) { struct worker *worker; + const struct cpumask *cpumask = NULL; lockdep_assert_held(&wq_pool_attach_mutex); + if (housekeeping_enabled(HK_TYPE_KTHREAD)) + cpumask = housekeeping_cpumask(HK_TYPE_KTHREAD); + /* * Restore CPU affinity of all workers. As all idle workers should * be on the run-queue of the associated CPU before any local * wake-ups for concurrency management happen, restore CPU affinity * of all workers first and then clear UNBOUND. As we're called * from CPU_ONLINE, the following shouldn't fail. + * + * Also consider the housekeeping HK_TYPE_KTHREAD cpumask. */ 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); + cpumask ? cpumask : pool->attrs->cpumask) < 0); } raw_spin_lock_irq(&pool->lock);