All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Stultz <jstultz@google.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Michael <michael@mipisi.de>,
	Michael Trimarchi <michael@amarulasolutions.com>,
	kernel-team@android.com
Subject: [RFC][PATCH 2/2] time: alarmtimer: Use TASK_FREEZABLE to cleanup freezer handling
Date: Sat, 11 Feb 2023 06:45:27 +0000	[thread overview]
Message-ID: <20230211064527.3481754-2-jstultz@google.com> (raw)
In-Reply-To: <20230211064527.3481754-1-jstultz@google.com>

Instead of trying to handle the freezer waking up tasks from
schedule() in nanosleep on alarmtimers explicitly, use
TASK_FREEZABLE which marks the task freezable when it goes
to schedule, which prevents the signal wakeup.

This allows for the freezer handling to be removed, simplifying
the code.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael <michael@mipisi.de>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Cc: kernel-team@android.com
Originally-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/alpine.DEB.2.21.1909021247250.3955@nanos.tec.linutronix.de/
[jstultz: Forward ported to 6.2-rc and split out from a separate
          fix.]
Signed-off-by: John Stultz <jstultz@google.com>
---
 kernel/time/alarmtimer.c | 53 ++--------------------------------------
 1 file changed, 2 insertions(+), 51 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index f7b2128f64e2..15ecde8fcc1b 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -49,14 +49,6 @@ static struct alarm_base {
 	clockid_t		base_clockid;
 } alarm_bases[ALARM_NUMTYPE];
 
-#if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS)
-/* freezer information to handle clock_nanosleep triggered wakeups */
-static enum alarmtimer_type freezer_alarmtype;
-static ktime_t freezer_expires;
-static ktime_t freezer_delta;
-static DEFINE_SPINLOCK(freezer_delta_lock);
-#endif
-
 #ifdef CONFIG_RTC_CLASS
 /* rtc timer and device for setting alarm wakeups at suspend */
 static struct rtc_timer		rtctimer;
@@ -241,19 +233,12 @@ EXPORT_SYMBOL_GPL(alarm_expires_remaining);
  */
 static int alarmtimer_suspend(struct device *dev)
 {
-	ktime_t min, now, expires;
+	ktime_t now, expires, min = KTIME_MAX;
 	int i, ret, type;
 	struct rtc_device *rtc;
 	unsigned long flags;
 	struct rtc_time tm;
 
-	spin_lock_irqsave(&freezer_delta_lock, flags);
-	min = freezer_delta;
-	expires = freezer_expires;
-	type = freezer_alarmtype;
-	freezer_delta = KTIME_MAX;
-	spin_unlock_irqrestore(&freezer_delta_lock, flags);
-
 	rtc = alarmtimer_get_rtcdev();
 	/* If we have no rtcdev, just return */
 	if (!rtc)
@@ -480,38 +465,6 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
 EXPORT_SYMBOL_GPL(alarm_forward_now);
 
 #ifdef CONFIG_POSIX_TIMERS
-
-static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
-{
-	struct alarm_base *base;
-	unsigned long flags;
-	ktime_t delta;
-
-	switch(type) {
-	case ALARM_REALTIME:
-		base = &alarm_bases[ALARM_REALTIME];
-		type = ALARM_REALTIME_FREEZER;
-		break;
-	case ALARM_BOOTTIME:
-		base = &alarm_bases[ALARM_BOOTTIME];
-		type = ALARM_BOOTTIME_FREEZER;
-		break;
-	default:
-		WARN_ONCE(1, "Invalid alarm type: %d\n", type);
-		return;
-	}
-
-	delta = ktime_sub(absexp, base->get_ktime());
-
-	spin_lock_irqsave(&freezer_delta_lock, flags);
-	if (delta < freezer_delta) {
-		freezer_delta = delta;
-		freezer_expires = absexp;
-		freezer_alarmtype = type;
-	}
-	spin_unlock_irqrestore(&freezer_delta_lock, flags);
-}
-
 /**
  * clock2alarm - helper that converts from clockid to alarmtypes
  * @clockid: clockid.
@@ -750,7 +703,7 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
 	struct restart_block *restart;
 	alarm->data = (void *)current;
 	do {
-		set_current_state(TASK_INTERRUPTIBLE);
+		set_current_state(TASK_INTERRUPTIBLE | TASK_FREEZABLE);
 		alarm_start(alarm, absexp);
 		if (likely(alarm->data))
 			schedule();
@@ -765,8 +718,6 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
 	if (!alarm->data)
 		return 0;
 
-	if (freezing(current))
-		alarmtimer_freezerset(absexp, type);
 	restart = &current->restart_block;
 	if (restart->nanosleep.type != TT_NONE) {
 		struct timespec64 rmt;
-- 
2.39.1.581.gbfd45094c4-goog


  reply	other threads:[~2023-02-11  6:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-11  6:45 [RFC][PATCH 1/2] time: alarmtimer: Fix erroneous case of using 0 as an "invalid" initialization value John Stultz
2023-02-11  6:45 ` John Stultz [this message]
2023-02-15  8:22   ` [RFC][PATCH 2/2] time: alarmtimer: Use TASK_FREEZABLE to cleanup freezer handling Michael Nazzareno Trimarchi
2023-02-15 13:52     ` Thomas Gleixner
2023-02-18 14:56   ` Michael Nazzareno Trimarchi
2023-02-20  7:23     ` Thomas Gleixner
2023-02-20  8:23       ` Michael Nazzareno Trimarchi
2023-02-20 11:47         ` Michael Nazzareno Trimarchi
2023-02-20 17:48           ` Thomas Gleixner
2023-02-20 18:11             ` Michael Nazzareno Trimarchi
2023-02-20 21:18               ` Thomas Gleixner
2023-02-20 21:32                 ` Michael Nazzareno Trimarchi
2023-02-21  0:12                   ` Thomas Gleixner
2023-02-21  7:10                     ` Michael Nazzareno Trimarchi
2023-02-24 10:02                       ` Michael Nazzareno Trimarchi
2023-02-24 10:32                         ` Michael Nazzareno Trimarchi
2023-02-24 11:57                           ` Michael Nazzareno Trimarchi
2023-02-28  0:03                 ` John Stultz
2023-02-28  4:06                   ` John Stultz
2023-03-01 22:11                     ` Thomas Gleixner
2023-03-02  0:47                       ` John Stultz
2023-03-02  9:34                         ` Michael Nazzareno Trimarchi
2023-03-02 15:00                         ` Rafael J. Wysocki
2023-03-15 20:12                           ` Michael Nazzareno Trimarchi
2023-03-02 14:54                       ` Rafael J. Wysocki
2023-03-02 14:56                         ` Rafael J. Wysocki
2023-03-02 14:32                 ` Rafael J. Wysocki
2023-03-02 22:21                   ` Thomas Gleixner
2023-03-02 22:58                     ` Thomas Gleixner
2024-06-27  7:46                       ` Michael Nazzareno Trimarchi
2024-07-13 10:47                         ` Thomas Gleixner
2024-07-15  8:20                           ` Michael Nazzareno Trimarchi
2023-02-21 11:50   ` Michael Nazzareno Trimarchi
2024-01-11  8:28   ` Michael Nazzareno Trimarchi
2023-02-18 14:51 ` [RFC][PATCH 1/2] time: alarmtimer: Fix erroneous case of using 0 as an "invalid" initialization value Michael Nazzareno Trimarchi

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=20230211064527.3481754-2-jstultz@google.com \
    --to=jstultz@google.com \
    --cc=arnd@arndb.de \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@amarulasolutions.com \
    --cc=michael@mipisi.de \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.