From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <tj@kernel.org>, <jiangshanlai@gmail.com>, <corbet@lwn.net>
Cc: <paulmck@kernel.org>, <rdunlap@infradead.org>,
<peterz@infradead.org>, <yanjiewtw@gmail.com>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<ke.wang@unisoc.com>, <xuewen.yan94@gmail.com>
Subject: [PATCH] workqueue: Control the frequency of intensive warning through cmdline
Date: Mon, 19 Feb 2024 15:46:34 +0800 [thread overview]
Message-ID: <20240219074634.2039-1-xuewen.yan@unisoc.com> (raw)
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 <xuewen.yan@unisoc.com>
---
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 */
--
2.25.1
next reply other threads:[~2024-02-19 7:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 7:46 Xuewen Yan [this message]
2024-02-19 16:00 ` Randy Dunlap
2024-02-20 16:46 ` Tejun Heo
2024-02-21 2:01 ` Xuewen Yan
2024-02-21 5:44 ` Tejun Heo
2024-02-21 11:00 ` Xuewen Yan
2024-02-21 17:44 ` Tejun Heo
2024-02-22 1:52 ` Xuewen Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240219074634.2039-1-xuewen.yan@unisoc.com \
--to=xuewen.yan@unisoc.com \
--cc=corbet@lwn.net \
--cc=jiangshanlai@gmail.com \
--cc=ke.wang@unisoc.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=tj@kernel.org \
--cc=xuewen.yan94@gmail.com \
--cc=yanjiewtw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®