From patchwork Mon Feb 19 07:46:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 202928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1135401dyc; Sun, 18 Feb 2024 23:50:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW9scjN3vZzxOE/ipR+jWjo0pUh1VnFvxAQpEg1FSs/JQ9I1HE+Rs9k+OV9jxic53HvVd35crJyUSErS8Q3hFC7AthKwA== X-Google-Smtp-Source: AGHT+IEIbK3SpSNBsZisvQmOCdJTif3qrkdzndQefFMHgSF+aKYPzd63auyHhmbZXVfgKHEFF6J6 X-Received: by 2002:a05:6a20:94cd:b0:19e:9a65:75eb with SMTP id ht13-20020a056a2094cd00b0019e9a6575ebmr13371915pzb.40.1708329032788; Sun, 18 Feb 2024 23:50:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708329032; cv=pass; d=google.com; s=arc-20160816; b=04+aM/SRyiTZcM4O0InSa3/OtCplFlRjj76w9NaYA0slByQoLKsb0HC2kB44r1M/m4 5GaxhMj9hM7rHgV3RFPPNR1YMmvWgVhph9CQW7g9ZyFfjr8v5ArfmxM+t9L79hmLqgSA KvDhg1iLFuZraDqIzn48egAREKQj//VAjbT2LleNKiydRoXyy6QZcr+12xCBQC0QW3WK cyiZibwq/MVB7FjNpW0uywYXenSMLIzSXkv0WeVmyh4xTZYDpAVSRDOAscsFDotBeqNv 96hrSFUtDqrAwP7LPURsBIl35c87u7XQnrTLFUwbyMnG60YFHpZfkb3+1nBGJPCdRYCG WeBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=HmUBUYnwRXUz+cqS4o8wKZ8a4/w/9GlOtCg9l6u0EUI=; fh=N6RAMI0ruAim3xnwX2ahKfId4ps63+t8EKOdEeAFYA0=; b=pw08irucPD7o3TIxipyI6cFIfcjWGusaOxBB5ae/uOCNEGsW1YJbMrGmVfsWwatr2c Yv6aaHdg9D5Pg0FWylE+9xAjoHEDGabVeqGevWVqynPQzyh2e+5SG0vwlpDtHA9ptRlf wB/cEZxRFucmhjzeQMbyBNIwfa6jiPR3GwyFwMAHpCgEnWN6i91Pcq07MVWAefvmh6Jr plrorO8uQDzRS7+DwHocPHvn1bMBc5+YQlqKrLZKU7r881w0Om2s7fzfODMqNTqB6x7F /iiJTY76qv8FN7zpFVy01At13FZ+MbxVeIX/KIKLBXSIdVIWbyUIshDwMQzJEDU0WFwx IvEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-70865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70865-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nn12-20020a17090b38cc00b002992dcfc30dsi4137083pjb.40.2024.02.18.23.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:50:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-70865-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70865-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5738C2835B0 for ; Mon, 19 Feb 2024 07:50:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD89B2374C; Mon, 19 Feb 2024 07:47:47 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2AE420DF4 for ; Mon, 19 Feb 2024 07:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328866; cv=none; b=h0nRIHJWV5lck8olfzplnQCSH0iEvkv2b8KfzVjSbyatB2Nhk379aI4E7nytJat0bW1RMJEGFfQjyEHNjj0USzFDhyqQS9VHH3nYiUerxe9lLG2tbsriTrCVFIak0fGwVNDBpajNTI/8HsJrd8S4gkLgNNYAo/FZGIEqKrF2HbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328866; c=relaxed/simple; bh=ewsDsPkbeobOE48ZRHp1eMRBk4DRcJdny5eRpEC1R6E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=V/LS9qSsHGj2joBhy3CximfAYwYUWu2sC7bvv58GsRrbkc5l/AUBpwvRVOIb8pkXre4ejv8D3UIFZlmgs34e3lbTtFg10lOGaKrfmKH1XlgCH0jzw1U+oZZs325gL9hBGHrqWHjo+qasn+26uVH9ow4vI+Lp2QEwUm6RRMJBWjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 41J7kfiO037258; Mon, 19 Feb 2024 15:46:41 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TdZNL0c0lz2KCvlD; Mon, 19 Feb 2024 15:46:10 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 19 Feb 2024 15:46:39 +0800 From: Xuewen Yan To: , , CC: , , , , , , , Subject: [PATCH] workqueue: Control the frequency of intensive warning through cmdline Date: Mon, 19 Feb 2024 15:46:34 +0800 Message-ID: <20240219074634.2039-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 41J7kfiO037258 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791312824139850867 X-GMAIL-MSGID: 1791312824139850867 When CONFIG_WQ_CPU_INTENSIVE_REPORT is set, the kernel will report the work functions which violate the intensive_threshold_us repeatedly. And now, only when the violate times exceed 4 and is a power of 2, the kernel warning could be triggered. However, sometimes we want to print the warning every time when the work executed too long. Because sometimes, even if a long work execution time occurs only once, it may cause other work to be delayed for a long time. In order to freely control the frequency of printing, a boot argument is added so that the user can control the warning to be printed only after a certain number of work timeouts. Default, it would print warning every 4 times. Signed-off-by: Xuewen Yan --- Documentation/admin-guide/kernel-parameters.txt | 9 +++++++++ kernel/workqueue.c | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 31b3a25680d0..599fc59fcf70 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -7225,6 +7225,15 @@ threshold repeatedly. They are likely good candidates for using WQ_UNBOUND workqueues instead. + workqueue.cpu_intensive_warning_per_count= + If CONFIG_WQ_CPU_INTENSIVE_REPORT is set, the kernel + will report the work functions which violate the + intensive_threshold_us repeatedly. In order to prevent + the kernel log from being printed too frequently. + Control the frequency. + + Default, it will print one warning per 4 times. + workqueue.power_efficient Per-cpu workqueues are generally preferred because they show better performance thanks to cache diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7b482a26d741..8e8cccf5329a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -359,6 +359,10 @@ static const char *wq_affn_names[WQ_AFFN_NR_TYPES] = { */ static unsigned long wq_cpu_intensive_thresh_us = ULONG_MAX; module_param_named(cpu_intensive_thresh_us, wq_cpu_intensive_thresh_us, ulong, 0644); +#ifdef CONFIG_WQ_CPU_INTENSIVE_REPORT +static unsigned int wq_cpu_intensive_warning_per_count = 4; +module_param_named(cpu_intensive_warning_per_count, wq_cpu_intensive_warning_per_count, uint, 0644); +#endif /* see the comment above the definition of WQ_POWER_EFFICIENT */ static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT); @@ -1202,7 +1206,7 @@ static void wq_cpu_intensive_report(work_func_t func) * exponentially. */ cnt = atomic64_inc_return_relaxed(&ent->cnt); - if (cnt >= 4 && is_power_of_2(cnt)) + if (wq_cpu_intensive_warning_per_count && !(cnt % wq_cpu_intensive_warning_per_count)) printk_deferred(KERN_WARNING "workqueue: %ps hogged CPU for >%luus %llu times, consider switching to WQ_UNBOUND\n", ent->func, wq_cpu_intensive_thresh_us, atomic64_read(&ent->cnt)); @@ -1231,10 +1235,12 @@ static void wq_cpu_intensive_report(work_func_t func) ent = &wci_ents[wci_nr_ents++]; ent->func = func; - atomic64_set(&ent->cnt, 1); + atomic64_set(&ent->cnt, 0); hash_add_rcu(wci_hash, &ent->hash_node, (unsigned long)func); raw_spin_unlock(&wci_lock); + + goto restart; } #else /* CONFIG_WQ_CPU_INTENSIVE_REPORT */