Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6171237rwp; Mon, 17 Jul 2023 16:37:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlHE+EGTC7IkBQfzUC0cZM0GFFFAvRV0pNF43GGKotoyLN+ysvr4Iv33LffJ2z342IIzGpxC X-Received: by 2002:a05:6830:186:b0:6b9:ae94:c664 with SMTP id q6-20020a056830018600b006b9ae94c664mr12635655ota.13.1689637052459; Mon, 17 Jul 2023 16:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689637052; cv=none; d=google.com; s=arc-20160816; b=Dy7TDNKqjeHCiPP2rUnbvWbgB4rcGJc2zQv7U7/FvIYfyD0cgUAsXVNL6zq4wPfO53 gwe4GfnmPCFQWwmuc7d8IjPFXMER7LM9kOMjaOo+7kmLJP49WYTBaO4sYHdt+80CQ7Jy UINo/nAayAwZrg8eHU8Wiur6AQj6LnZvFC6UB0XiQ+6b71w06H3Ll3Mq2qBACproH1gS A0zAbfA2yl2w2iGqe+Ocy1Y1NvGp1D+8IjEIG1g11T7OVEvb4W1FJxbCwpKqscfuv9S4 UXEIt8TXEIuSw0slmNCmUs1mO5Pz/8VslN56LsA1cT7YQf6eC8MVQ/rOGWBdxiQPymnf pjJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=PjdXTr3dzdMnu6+stW9Y5PEi63LoYA7/O+Nyj8BgZrY=; fh=1062CBwmznJ6TpeOMkZDhFlQxf7M4P+YWC1Z/nYpPbk=; b=FwNutwJ5i0CQhUtSQkGmzZyxrQS+Fv3zTnYoCpBQhQA8cKEFYwHImjOsT/1B5gXXle L0+MJcU4vNHi8k1AC83CgZ06+fhfp44uJgBG/lM+UdM4S1RMjDqYx4PRmIVoTx5tq5JI +vs3PPJTgtG/027I6Kl/Q3dhwPlbUGml9ofvJVrqjjXsDTQby+E/PnsrTp0kGNWRTnRK 9LZVFP1Zu31A7v3RKbtF4QOs+V0v/P3FYq57+otFV8Pc3c2MaxLoVu17ZLf0uxAteTkz WUkgcWhWEFQzc/XC8T56Og1cG8HxKLAD8PaoIVeQeeI2dL9ju6KVsgDDZrjR2f47XvvW y6Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DXaD1vRP; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 62-20020a630041000000b005573b42d9e3si512386pga.593.2023.07.17.16.37.20; Mon, 17 Jul 2023 16:37:32 -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=20221208 header.b=DXaD1vRP; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbjGQXFh (ORCPT + 99 others); Mon, 17 Jul 2023 19:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbjGQXFf (ORCPT ); Mon, 17 Jul 2023 19:05:35 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563AA170A; Mon, 17 Jul 2023 16:04:47 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-3459baa237bso32105315ab.3; Mon, 17 Jul 2023 16:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689635007; x=1692227007; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=PjdXTr3dzdMnu6+stW9Y5PEi63LoYA7/O+Nyj8BgZrY=; b=DXaD1vRPgFSnKmXn3XmG3556H/iN7AORkeSIiv52gtXqrSsva4y99v678W83plsKQd Sb2RzUfAyqCwSAZXeTyPSTPVhft5cksYPgmlzFxPtaVsXr5qxjkvMhG/pbHf0f5Z50aS h9GVaj7R2fjtsiyItodMYi2N+0lWvihW95Yh1xyg3f7uUHAUyazn/6vxom75h3hyS49M aLO1zkjumLSNbljkXUZ1tYdZnJUSGtbH6lbZ/WdbgQyAalJGZBSmguuL4aRnR0VkTQfA MypCw40Sse8dM7MJ11W8RLcgEnNMiagL13pXMPaU1M+MYaMVjRDZvWqM2XKdb/0HVNLA OHpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689635007; x=1692227007; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PjdXTr3dzdMnu6+stW9Y5PEi63LoYA7/O+Nyj8BgZrY=; b=Z7n7lzoXYvBT8hCuzrQASx0hG8HTGb9DGHccm88ehjGh06T9Bu69MviUaVyk16M4sc vu4IyW8tW5UmrGumqrN8KAdiWqEvGe8F2885N8/Q8YmH+KNMYTxDuJO3Q1D4s2PRR26o 1ly73thmitkNId63hcStYYHWaIqg/LLradphCKaLWXpH40WLVJRg/01wN0j1syRV3rxv O9EWRprGV939k9wtnF4LH5KtQjehuyDjUeCat3xvvfjKBVZUOqmMx6YrAcyUdsFdCgLo h+qHCOW20sHg9vnxroV8W+4fGoRH2FMoMt/L1jhS7f7dC2/vyxXYKJJgUX0eh0QB0Gqe YpmQ== X-Gm-Message-State: ABy/qLY08tPpSixf7wqxm5/UlPcb50dIt7iLDivYpMaTsp37rOnwi3kV LPkWLStK4lgUom5I4g2Ztqg= X-Received: by 2002:a05:6e02:1b07:b0:346:189a:1b74 with SMTP id i7-20020a056e021b0700b00346189a1b74mr1436604ilv.0.1689635007204; Mon, 17 Jul 2023 16:03:27 -0700 (PDT) Received: from localhost (dhcp-72-235-13-41.hawaiiantel.net. [72.235.13.41]) by smtp.gmail.com with ESMTPSA id w5-20020a92d605000000b0034628814e66sm254216ilm.40.2023.07.17.16.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 16:03:26 -0700 (PDT) Sender: Tejun Heo Date: Mon, 17 Jul 2023 13:03:25 -1000 From: Tejun Heo To: Geert Uytterhoeven Cc: Lai Jiangshan , "torvalds@linux-foundation.org" , Peter Zijlstra , Linux Kernel Mailing List , kernel-team@meta.com, Linux PM list , DRI Development , linux-rtc@vger.kernel.org, linux-riscv , netdev , Linux Fbdev development list , Linux MMC List , "open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers)" , Linux-Renesas Subject: Re: Consider switching to WQ_UNBOUND messages (was: Re: [PATCH v2 6/7] workqueue: Report work funcs that trigger automatic CPU_INTENSIVE mechanism) Message-ID: References: <20230511181931.869812-1-tj@kernel.org> <20230511181931.869812-7-tj@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hello, Geert. Can you please the following patch and see how many reports you get? Looking back at your reports, I think some of them probably should be converted to UNBOUND but we should have a better idea with the adjusted threshold. Thanks. From 8555cbd4b22e5f85eb2bdcb84fd1d1f519a0a0d3 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 17 Jul 2023 12:50:02 -1000 Subject: [PATCH] workqueue: Scale up wq_cpu_intensive_thresh_us if BogoMIPS is below 1000 wq_cpu_intensive_thresh_us is used to detect CPU-hogging per-cpu work items. Once detected, they're excluded from concurrency management to prevent them from blocking other per-cpu work items. If CONFIG_WQ_CPU_INTENSIVE_REPORT is enabled, repeat offenders are also reported so that the code can be updated. The default threshold is 10ms which is long enough to do fair bit of work on modern CPUs while short enough to be usually not noticeable. This unfortunately leads to a lot of, arguable spurious, detections on very slow CPUs. Using the same threshold across CPUs whose performance levels may be apart by multiple levels of magnitude doesn't make whole lot of sense. This patch scales up wq_cpu_intensive_thresh_us upto 1 second when BogoMIPS is below 1000. This is obviously very inaccurate but it doesn't have to be accurate to be useful. The mechanism is still useful when the threshold is fully scaled up and the benefits of reports are usually shared with everyone regardless of who's reporting, so as long as there are sufficient number of fast machines reporting, we don't lose much. Some (or is it all?) ARM CPUs systemtically report significantly lower BogoMIPS. While this doesn't break anything, given how widespread ARM CPUs are, it's at least a missed opportunity and it probably would be a good idea to teach workqueue about it. Signed-off-by: Tejun Heo Cc: Geert Uytterhoeven --- kernel/workqueue.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 02a8f402eeb5..0d7a3d29762f 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "workqueue_internal.h" @@ -338,8 +339,10 @@ static cpumask_var_t *wq_numa_possible_cpumask; * Per-cpu work items which run for longer than the following threshold are * automatically considered CPU intensive and excluded from concurrency * management to prevent them from noticeably delaying other per-cpu work items. + * ULONG_MAX indicates that the user hasn't overridden it with a boot parameter. + * The actual value is initialized in wq_cpu_intensive_thresh_init(). */ -static unsigned long wq_cpu_intensive_thresh_us = 10000; +static unsigned long wq_cpu_intensive_thresh_us = ULONG_MAX; module_param_named(cpu_intensive_thresh_us, wq_cpu_intensive_thresh_us, ulong, 0644); static bool wq_disable_numa; @@ -6513,6 +6516,42 @@ void __init workqueue_init_early(void) !system_freezable_power_efficient_wq); } +static void __init wq_cpu_intensive_thresh_init(void) +{ + unsigned long thresh; + unsigned long mips; + + /* if the user set it to a specific value, keep it */ + if (wq_cpu_intensive_thresh_us != ULONG_MAX) + return; + + /* + * The default of 10ms is derived from the fact that most modern (as of + * 2023) processors can do a lot in 10ms and that it's just below what + * most consider human-perceivable. However, the kernel also runs on a + * lot slower CPUs including microcontrollers where the threshold is way + * too low. + * + * Let's scale up the threshold upto 1 second if BogoMips is below 1000. + * This is by no means accurate but it doesn't have to be. The mechanism + * is still useful even when the threshold is fully scaled up. Also, as + * the reports would usually be applicable to everyone, some machines + * operating on longer thresholds won't significantly diminish their + * usefulness. + */ + thresh = 10 * USEC_PER_MSEC; + + /* see init/calibrate.c for lpj -> BogoMIPS calculation */ + mips = max_t(unsigned long, loops_per_jiffy / 500000 * HZ, 1); + if (mips < 1000) + thresh = min_t(unsigned long, thresh * 1000 / mips, USEC_PER_SEC); + + pr_debug("wq_cpu_intensive_thresh: lpj=%lu mips=%lu thresh_us=%lu\n", + loops_per_jiffy, mips, thresh); + + wq_cpu_intensive_thresh_us = thresh; +} + /** * workqueue_init - bring workqueue subsystem fully online * @@ -6528,6 +6567,8 @@ void __init workqueue_init(void) struct worker_pool *pool; int cpu, bkt; + wq_cpu_intensive_thresh_init(); + /* * It'd be simpler to initialize NUMA in workqueue_init_early() but * CPU to node mapping may not be available that early on some -- 2.41.0