mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Qing <wangqing@vivo.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Petr Mladek <pmladek@suse.com>, Wang Qing <wangqing@vivo.com>,
	Santosh Sivaraj <santosh@fossix.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH RFC 1/2] hrtimer: support hrtimer suspend when CPU suspend
Date: Tue, 22 Jun 2021 17:06:46 +0800	[thread overview]
Message-ID: <1624352816-26450-2-git-send-email-wangqing@vivo.com> (raw)
In-Reply-To: <1624352816-26450-1-git-send-email-wangqing@vivo.com>

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


  reply	other threads:[~2021-06-22  9:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22  9:06 [PATCH RFC 0/2] hrtimer: watchdog: " Wang Qing
2021-06-22  9:06 ` Wang Qing [this message]
2021-08-10 14:58   ` [PATCH RFC 1/2] hrtimer: " Thomas Gleixner
2021-06-22  9:06 ` [PATCH RFC 2/2] watchdog: support watchdog " Wang Qing

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=1624352816-26450-2-git-send-email-wangqing@vivo.com \
    --to=wangqing@vivo.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=santosh@fossix.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    /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®