Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14440510rwd; Sat, 24 Jun 2023 20:22:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NKtTzPxAjFmpEjDMi7/Ra5ku7F2f8Kun+UnfQsg8W94MBRvAZOEN2C+6DsY24NfdD4Qe/ X-Received: by 2002:a05:6808:bd0:b0:39e:bfe9:6391 with SMTP id o16-20020a0568080bd000b0039ebfe96391mr29928702oik.1.1687663369170; Sat, 24 Jun 2023 20:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687663369; cv=none; d=google.com; s=arc-20160816; b=XHfcIvujahhKZkotlm3IohJQ2OrdfgmZ40Ww+2TqBkqsjlx6K/w/qDhr4z9MrGQ42w zODsU6gwojepOes9+js6K8qSw4sLyrf2+t/qIMxLOZ+t0y0nk20iapwlQmuyT3bQLAAS p6nqq7n62zx+AIWYeRTB2hgx0fi+eIpAdf5SWhC2lpwGxkvqL1y+wi283q1hWNV/iaVh pB1ZH9UfMxikZCP6Fi/Lx4N/PGvk7oUHpAE+gSBpgjNNMXndHrQ0TlEdVXwXfq88+muk 2wJgjIB+E50b0Hw0jM18tBHUTkefh+SpKWdVJrUqGoqKBsaemkSIo8BbVwhB2AqEPmdQ ZRlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:mail-followup-to:message-id:subject:cc:to:from:date; bh=/uj3PJkD03ApOV6g5GkqUDtEQvoUZiE5jmHq3l5YbBU=; fh=QhBF3umRvOHYh/KQn5VVg9273/o8qlDPcEMKxp8Vz1Q=; b=b9Hy4NY9iXdsceexuIWEFCb6rVFwZtL7eQGN+RNfl4z88e6B6C1+Ex+tvRSYTRAIma DxhvsI3mqN/ICrX2/Ky5MkxrF5vu2GS/yh1g7Jhqv7rOphGJhUj6XKWDRsvdHYtfjxAs MlmcWS+RZQILiN+2TYwzq1TJ9M966PazZQXkOrM2R8a46+zlrcVYEWjhfZQKo5EgtWhu 6rXc8/5uxHyEuqvDC/0rVIbOmvLnas7VEI1uiM+NaI2q5MbN9O2A5u7lIcwq59CmsrHa KMqirjvamrN4Ouxkzl/7gOOkpc4CDGhW/mEgD/qRuQ5AGH7ELllQqiOPgZ6oZfTBYZt/ cpEA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a170903245000b001b55c029108si2513404pls.363.2023.06.24.20.22.37; Sat, 24 Jun 2023 20:22:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbjFYDPX (ORCPT + 99 others); Sat, 24 Jun 2023 23:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbjFYDPM (ORCPT ); Sat, 24 Jun 2023 23:15:12 -0400 Received: from mx6.didiglobal.com (mx6.didiglobal.com [111.202.70.123]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 9586DE70 for ; Sat, 24 Jun 2023 20:15:10 -0700 (PDT) Received: from mail.didiglobal.com (unknown [10.79.65.12]) by mx6.didiglobal.com (Maildata Gateway V2.8) with ESMTPS id 70FE211002112F; Sun, 25 Jun 2023 11:15:08 +0800 (CST) Received: from didi-ThinkCentre-M930t-N000 (10.79.64.101) by ZJY02-ACTMBX-02.didichuxing.com (10.79.65.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Sun, 25 Jun 2023 11:15:08 +0800 Date: Sun, 25 Jun 2023 11:15:02 +0800 X-MD-Sfrom: tiozhang@didiglobal.com X-MD-SrcIP: 10.79.65.12 From: tiozhang To: , CC: , , , , , Subject: [PATCH v3] workqueue: add cmdline parameter `workqueue_unbound_cpus` to further constrain wq_unbound_cpumask at boot time Message-ID: <20230625031502.GA22708@didi-ThinkCentre-M930t-N000> Mail-Followup-To: tj@kernel.org, rdunlap@infradead.org, linux-kernel@vger.kernel.org, jiangshanlai@gmail.com, zyhtheonly@gmail.com, zyhtheonly@yeah.net, zwp10758@gmail.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230623073033.GA6584@didi-ThinkCentre-M930t-N000> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.79.64.101] X-ClientProxiedBy: ZJY01-PUBMBX-01.didichuxing.com (10.79.64.32) To ZJY02-ACTMBX-02.didichuxing.com (10.79.65.12) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Motivation of doing this is to better improve boot times for devices when we want to prevent our workqueue works from running on some specific CPUs, e,g, some CPUs are busy with interrupts. Signed-off-by: tiozhang --- .../admin-guide/kernel-parameters.txt | 8 +++++++ kernel/workqueue.c | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a465d5242774..7f2fe8c60d5c 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6780,6 +6780,14 @@ disables both lockup detectors. Default is 10 seconds. + workqueue_unbound_cpus= + [KNL,SMP] + Format: + Specify to constrain one or some CPUs to use in + unbound workqueues. + By default, all online CPUs are available for + unbound workqueues. + workqueue.watchdog_thresh= If CONFIG_WQ_WATCHDOG is configured, workqueue can warn stall conditions and dump internal state to diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7cd5f5e7e0a1..c247725b0873 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -329,6 +329,9 @@ static bool workqueue_freezing; /* PL: have wqs started freezing? */ /* PL: allowable cpus for unbound wqs and work items */ static cpumask_var_t wq_unbound_cpumask; +/* for further constrain wq_unbound_cpumask by cmdline parameter*/ +static cpumask_var_t wq_cmdline_cpumask; + /* CPU where unbound work was last round robin scheduled from this CPU */ static DEFINE_PER_CPU(int, wq_rr_cpu_last); @@ -6006,6 +6009,10 @@ void __init workqueue_init_early(void) cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_WQ)); cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN)); + if (!cpumask_empty(wq_cmdline_cpumask)) + cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, wq_cmdline_cpumask); + free_bootmem_cpumask_var(wq_cmdline_cpumask); + pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC); /* initialize CPU pools */ @@ -6129,3 +6136,20 @@ void __init workqueue_init(void) */ void __warn_flushing_systemwide_wq(void) { } EXPORT_SYMBOL(__warn_flushing_systemwide_wq); + +static int __init workqueue_unbound_cpus_setup(char *str) +{ + cpumask_var_t cpumask; + + alloc_bootmem_cpumask_var(&wq_cmdline_cpumask); + alloc_bootmem_cpumask_var(&cpumask); + if (cpulist_parse(str, cpumask) < 0) + pr_warn("workqueue_unbound_cpus: incorrect CPU range\n"); + else + cpumask_copy(wq_cmdline_cpumask, cpumask); + + free_bootmem_cpumask_var(cpumask); + + return 0; +} +__setup("workqueue_unbound_cpus=", workqueue_unbound_cpus_setup); -- 2.17.1