From: tiozhang <tiozhang@didiglobal.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Jonathan Corbet <corbet@lwn.net>,
"Steven Rostedt (Google)" <rostedt@goodmis.org>,
<linux-kernel@vger.kernel.org>, <zyhtheonly@gmail.com>,
<zyhtheonly@yeah.net>, <tiozhang@didiglobal.com>
Subject: [PATCH] hrtimer: add cmdline parameter retry_threshold to config retry times in interrupt handler routine
Date: Wed, 31 Jan 2024 18:41:52 +0800 [thread overview]
Message-ID: <20240131104152.GA19461@didi-ThinkCentre-M930t-N000> (raw)
Motivation of doing this is to give user a config option to reduce time
cost in hrtimer irq when influenced by some time consuming hrtimer
callbacks running in irq context.
E.g, if we tune this parameter to 1, we dont retry anymore to prevent
occasionally consecutive time consuming callbacks running in a single
interrupt.
Signed-off-by: tiozhang <tiozhang@didiglobal.com>
---
Documentation/admin-guide/kernel-parameters.txt | 5 +++++
kernel/time/hrtimer.c | 17 +++++++++++++++--
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a1457995fd41..29fcb1c43863 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1737,6 +1737,11 @@
hpet_mmap= [X86, HPET_MMAP] Allow userspace to mmap HPET
registers. Default set by CONFIG_HPET_MMAP_DEFAULT.
+ hrtimer.retry_threshold=
+ [KNL] Number of retry times when expired timer found
+ in hrtimer interrupt handle routine. Default 3.
+ Format: <int> (must be <= 3)
+
hugepages= [HW] Number of HugeTLB pages to allocate at boot.
If this follows hugepagesz (below), it specifies
the number of pages of hugepagesz to be allocated.
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 238262e4aba7..d3c17aa6cc13 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -144,6 +144,8 @@ static struct hrtimer_cpu_base migration_cpu_base = {
#define migration_base migration_cpu_base.clock_base[0]
+static int retry_threshold = 3;
+
static inline bool is_migration_base(struct hrtimer_clock_base *base)
{
return base == &migration_base;
@@ -1836,7 +1838,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
* - being scheduled away when running in a VM
*
* We need to prevent that we loop forever in the hrtimer
- * interrupt routine. We give it 3 attempts to avoid
+ * interrupt routine. We give it at most 3 attempts to avoid
* overreacting on some spurious event.
*
* Acquire base lock for updating the offsets and retrieving
@@ -1845,7 +1847,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
raw_spin_lock_irqsave(&cpu_base->lock, flags);
now = hrtimer_update_base(cpu_base);
cpu_base->nr_retries++;
- if (++retries < 3)
+ if (++retries < retry_threshold)
goto retry;
/*
* Give the system a chance to do something else than looping
@@ -2398,3 +2400,14 @@ int __sched schedule_hrtimeout(ktime_t *expires,
return schedule_hrtimeout_range(expires, 0, mode);
}
EXPORT_SYMBOL_GPL(schedule_hrtimeout);
+
+static int __init hrtimer_retry_threshold_setup(char *str)
+{
+ if (kstrtoint(str, 0, &retry_threshold) || retry_threshold > 3) {
+ retry_threshold = 3;
+ pr_warn("hrtimer.retry_threshold: bad given value, using default as 3\n");
+ }
+
+ return 1;
+}
+__setup("hrtimer.retry_threshold=", hrtimer_retry_threshold_setup);
--
2.17.1
next reply other threads:[~2024-01-31 10:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 10:41 tiozhang [this message]
2024-02-07 10:09 ` Thomas Gleixner
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=20240131104152.GA19461@didi-ThinkCentre-M930t-N000 \
--to=tiozhang@didiglobal.com \
--cc=corbet@lwn.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=zyhtheonly@gmail.com \
--cc=zyhtheonly@yeah.net \
/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®