hrtimer: watchdog: support hrtimer suspend when CPU suspend
cover hrtimer: watchdog: support hrtimer suspend when CPU suspend
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 either, such as watchdog hrtimer. The maximum suspend time of the CPU is 4s if enable lockup detector, which is unacceptable on some products, and in fact, watchdog timer can suspend when the cpu suspend.
This is a patch for comments, I'm not sure if there any ill-considerations. If this feature is really needed, I will continue to develop.
Wang Qing (2):
hrtimer: support hrtimer suspend when CPU suspend
watchdog: support watchdog hrtimer suspend when CPU suspend
include/linux/hrtimer.h | 3 +++ kernel/time/hrtimer.c | 4 +++- kernel/time/tick-sched.c | 7 +++++++ kernel/watchdog.c | 3 ++-
Signature · 1 line
2.7.4
RFC PATCH 1/2 hrtimer: support hrtimer suspend when CPU suspend
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.
--- include/linux/hrtimer.h | 3 +++ kernel/time/hrtimer.c | 4 +++- kernel/time/tick-sched.c | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-)
include/linux/hrtimer.h +3 -0
@@ -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; };/**
kernel/time/hrtimer.c +3 -1
@@ -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); }
kernel/time/tick-sched.c +7 -0
@@ -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 *
Signature · 1 line
2.7.4
Re: [PATCH RFC 1/2] hrtimer: support hrtimer suspend when CPU suspend
kernel/time/hrtimer.c static ktime_t __hrtimer_next_event_base(struct hrtimer_cpu_base *cpu_base, · line 517
Quoted 12 lines · Wang Qing
/**
kernel/time/hrtimer.c +2
-1@@ -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)) {
Aside of being indented in unreadable ways, how is this supposed to be correct? If the first expiring timer is excluded what prevents the next one from being marked to stop in suspend or the other way round.
What's wrong with just canceling the offending timer before going into suspend and rearming it on resume instead of adding a half baken magic case for timers?
Thanks,
tglx
RFC PATCH 2/2 watchdog: support watchdog hrtimer suspend when CPU suspend
In reply to Wang Qingthe 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.
--- kernel/watchdog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/watchdog.c +2 -1
@@ -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 );
Signature · 1 line
2.7.4