From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796105597; b=vpZb5Tv5Nc1ZnFX8WIZntRaVv96oNyN/oId0VDxXs/Nb/Pkcc7/rNPdc5gdjVdYuXrVl Xe/YLGEmfv8ARtN7crO/oAvaP8AvmtMjh2bW9rc6Wm2tt1Z8FY2wxEDd3kmf8O/IwqpVZ ePEIjEPLbPcB6oLVZPQ2gfFVCgWMDSDiKm9g8yfSJu8PJJ7WSvtggH9J+bBwcL4uKwbTr y6wNHbt/I9svUyVANVZwmjUZjCY0B+MOeviUTsIHF9i4WYYt5Ea0nw3ZZ0gPm3dB8vMFp Hdw3uXYrFKSJE/UKaKUiZpjkbCUfpoWrnQoeuFAzH3ETjWNEunHcywuKgNp9wzdk10g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796105597; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=8lbBDgbCVvoDP/MoxhbCmvXt2FSh8zUb9R9zmBLgWWs=; b=kq2eV8CkzNM7j+he556yFg333aeppj5BrWrbNnRaPrezbzcb3M2/pcJ4D3vt7QC7iFTP FXxwX9pNngo1xU8AWvtxlSOG1or3sVXEDHUDr5Oq7CVFIJLOD9Rw2plVic7nvHIL1OcGv qEkVJz/gug3qNOljv2y6vGyC9f1ZOP3yftP5SZ6FLULDH7YUfUDSx4Zz0KMECpa4cz+W2 W3paYEqMntM/xwvlnbNVvpd3zQBhKnQzukAtkzwMx3+lO6W7EEHID1fHfevDpGIuq86Pt WLYsVIRC8lmPTa9ro0DWvKI4/DlqkwuR1UJS79dEVLX6vHWWGmvZ12EHe5ATOkOt5bg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LmPhhRXo; arc=none smtp.remote-ip=74.125.82.71 Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29606606A320 for ; Tue, 1 Dec 2026 06:13:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29606606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LmPhhRXo Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-1b5bbedcdafso1715016c88.1 for ; Mon, 30 Nov 2026 22:13:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796105596; x=1796710396; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8lbBDgbCVvoDP/MoxhbCmvXt2FSh8zUb9R9zmBLgWWs=; b=LmPhhRXo7PksQEPHfRQOpw6oElgd5Knu7DAi0ERDN136ActCiPZEtY6lhpVHuDm+Gc C4sjzvhGtaF0RCM3DSHfC1G/CupcgPqs68Y1PHNclvJW7GKsVS18hVF/X8ExLTD7eGLS 0aAXTNQPve1RisDn+BX8yRe1wlJXuFR4qOymjjgWd5rQota+bYvimxa92GJDdnnY4rH3 /7lACRORKwqQBU/A2xL+3KM4AMUTnWzSZdOUHJMk2A5ZdpgV772nNAhe+099jxQwdfxm ZXE9VaFu9s1lRRIoZfn29Qjwjht1rvJfpNPIH4LsnTMpE3BIT8PLimpgKpxmCXyuocKt RlNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796105596; x=1796710396; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8lbBDgbCVvoDP/MoxhbCmvXt2FSh8zUb9R9zmBLgWWs=; b=fw85fcQ3nEMCJgux3UfuV92f1dkYz1Kzt0e34XFatvlMwQcAlrhPG7xMGQk1VntkYd EQ0SZLlKGPh+m5P/T3xM+tfksl5qgy9s48DdWHFfehLXk9xy16A34qx6/LfNDyGy/9Wh O1cBcA79QrRqxTpNWsEcS20GAyiZRiINe28UnktZO1X4aJT0RI9razyzYLn22ntaD0HM hzqn3TkWy3NQgMP/cpN2FTElkI0SjBr7iWpNbHL2NmTlviWvI0IxrOeDboQhJ77YC3g6 39DQavhj1K8o9ydb14ysUrap8H6oQfGjqpaKg5Lt2O1geC4ei/7CPGRjerw2caRH25Th skZg== X-Forwarded-Encrypted: i=1; AL+hErE9Ihj8j5Kx9RlcgoABCjkiwdI468zB2vx7pQa/tyZGBxwhrGW/N50tcFwHvRvHMtTLI9+TcWcZJWTQCME=@vger.kernel.org X-Gm-Message-State: APuU4Z+gzIEgIXqAr1id2p9Rm0+7XTVqZ25iACp5Ev4/qTFkITY/ju7c 3XO8dCubUG72clXekM3N2iNQaz6dtDUKe1nOVPe82AQnRPdcugI3Worym+21RJgrIs2hSRFCbMa KC9m/BQAwuvyBrw== X-Received: from dlbvs8.prod.google.com ([2002:a05:7022:3f08:b0:1b0:166c:6a91]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1587:b0:168:3243:c911 with SMTP id a92af1059eb24-1b556903a3bmr42759420c88.37.1796105595900; Mon, 30 Nov 2026 22:13:15 -0800 (PST) Date: Mon, 30 Nov 2026 22:13:04 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261201061304.2825419-6-wusamuel@google.com> Subject: [PATCH 0/4] alarmtimer: Reject suspend earlier when alarm is imminent From: Samuel Wu To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar Cc: linux-pm@vger.kernel.org, rafael@kernel.org, Samuel Wu , kernel-team@android.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" alarmtimer_suspend() aborts suspend with -EBUSY when the next alarm is due in less than 2 seconds, and holds a wakeup source for a fixed 2 seconds. This is suboptimal: - The check runs quite late in the suspend sequence. An abort means kernel spent time doing work it now has to undo. - The fixed 2 second timeout has no relation to the time at which the alarm is due. This patchseries addresses both problems: - 1/4: Hold wakeup source with grace period (100ms) after alarm is due. - 2/4: Move the lookup of soonest alarm into helper function - 3/4: Add a PM notifier (earlier in suspend sequence) to do an imminent alarm check. This is the same idea as [1], but without the sysfs node. - 4/4: Add alarm check in resume path, to handle wakeups that are earlier than the actual alarm, since RTC has up to 1s error compared to an alarm on hrtimer With patch 3, the time spent on a suspend attempt that is aborted by an imminent alarm drops from: - ~220 ms to ~20 ms on Pixel 9 (v7.3) - ~90 ms to ~0.1 ms on Pixel Watch (v6.12) With patch 4, aborted suspend attempts due to alarmtimer are noticeably lower. [1]: https://lore.kernel.org/lkml/20240214092902.1908443-1-pranavpp@google.com/ Samuel Wu (4): alarmtimer: Bound wakeup source timeout on suspend abort alarmtimer: Extract alarmtimer_get_next_delta() helper alarmtimer: Reject imminent-alarm suspend in PM_SUSPEND_PREPARE alarmtimer: Hold wakeup source on resume for imminent alarms kernel/time/alarmtimer.c | 124 ++++++++++++++++++++++++++++++--------- 1 file changed, 97 insertions(+), 27 deletions(-) -- 2.56.1.911.g883d8bcb20-goog