* [PATCH RFC 1/2] hrtimer: support hrtimer suspend when CPU suspend
2021-06-22 9:06 [PATCH RFC 0/2] hrtimer: watchdog: support hrtimer suspend when CPU suspend Wang Qing
@ 2021-06-22 9:06 ` Wang Qing
2021-08-10 14:58 ` Thomas Gleixner
2021-06-22 9:06 ` [PATCH RFC 2/2] watchdog: support watchdog " Wang Qing
1 sibling, 1 reply; 4+ messages in thread
From: Wang Qing @ 2021-06-22 9:06 UTC (permalink / raw)
To: Thomas Gleixner, Frederic Weisbecker, Ingo Molnar, Andrew Morton,
Petr Mladek, Wang Qing, Santosh Sivaraj, Peter Zijlstra (Intel),
linux-kernel, Tejun Heo
When the CPU suspend, in order to achieve a more power-saving effect,
it is hoped that the CPU sleeps as long as possible, but the timer is an
important reason for the CPU to wake up.
In some cases, when the CPU suspend, the timer doesn’t have to work.
Here provides a hrtimer mechanism that supports suspend.
Signed-off-by: Wang Qing <wangqing@vivo.com>
---
include/linux/hrtimer.h | 3 +++
kernel/time/hrtimer.c | 4 +++-
kernel/time/tick-sched.c | 7 +++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index bb5e7b0..bd0a4e6
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -42,6 +42,7 @@ enum hrtimer_mode {
HRTIMER_MODE_PINNED = 0x02,
HRTIMER_MODE_SOFT = 0x04,
HRTIMER_MODE_HARD = 0x08,
+ HRTIMER_MODE_SUSPEND = 0x08,
HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED,
HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED,
@@ -112,6 +113,7 @@ enum hrtimer_restart {
* @is_soft: Set if hrtimer will be expired in soft interrupt context.
* @is_hard: Set if hrtimer will be expired in hard interrupt context
* even on RT.
+ * @is_suspend: Set if hrtimer will be suspend when CPU suspend
*
* The hrtimer structure must be initialized by hrtimer_init()
*/
@@ -124,6 +126,7 @@ struct hrtimer {
u8 is_rel;
u8 is_soft;
u8 is_hard;
+ u8 is_suspend;
};
/**
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 4a66725..db34c9d
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -513,7 +513,8 @@ static ktime_t __hrtimer_next_event_base(struct hrtimer_cpu_base *cpu_base,
next = timerqueue_getnext(&base->active);
timer = container_of(next, struct hrtimer, node);
- if (timer == exclude) {
+ if ((timer == exclude) ||
+ (tick_nohz_tick_inidle() && timer->is_suspend)) {
/* Get to the next timer in the queue. */
next = timerqueue_iterate_next(next);
if (!next)
@@ -1422,6 +1423,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
base += hrtimer_clockid_to_base(clock_id);
timer->is_soft = softtimer;
timer->is_hard = !!(mode & HRTIMER_MODE_HARD);
+ timer->is_suspend = !!(mode & HRTIMER_MODE_SUSPEND);
timer->base = &cpu_base->clock_base[base];
timerqueue_init(&timer->node);
}
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 828b091..c886758
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -562,6 +562,13 @@ bool tick_nohz_tick_stopped_cpu(int cpu)
return ts->tick_stopped;
}
+bool tick_nohz_tick_inidle(void)
+{
+ struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
+
+ return ts->inidle;
+}
+
/**
* tick_nohz_update_jiffies - update jiffies when idle was interrupted
*
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH RFC 2/2] watchdog: support watchdog hrtimer suspend when CPU suspend
2021-06-22 9:06 [PATCH RFC 0/2] hrtimer: watchdog: support hrtimer suspend when CPU suspend Wang Qing
2021-06-22 9:06 ` [PATCH RFC 1/2] hrtimer: " Wang Qing
@ 2021-06-22 9:06 ` Wang Qing
1 sibling, 0 replies; 4+ messages in thread
From: Wang Qing @ 2021-06-22 9:06 UTC (permalink / raw)
To: Thomas Gleixner, Frederic Weisbecker, Ingo Molnar, Andrew Morton,
Petr Mladek, Wang Qing, Santosh Sivaraj, Peter Zijlstra (Intel),
linux-kernel
the watchdog hrtimer doesn’t have to work while CPU is suspend. Otherwise
the maximum suspend time of the CPU is 4s if enable lockup detector,
which is unacceptable on some products.
Signed-off-by: Wang Qing <wangqing@vivo.com>
---
kernel/watchdog.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 7c39790..f68591f
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -455,7 +455,8 @@ static void watchdog_enable(unsigned int cpu)
* Start the timer first to prevent the NMI watchdog triggering
* before the timer has a chance to fire.
*/
- hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
+ hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD
+ | HRTIMER_MODE_SUSPEND);
hrtimer->function = watchdog_timer_fn;
hrtimer_start(hrtimer, ns_to_ktime(sample_period),
HRTIMER_MODE_REL_PINNED_HARD);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread