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=1796105598; b=ozyJdzNyrLgp1bREu5tjX7j9PjPyrvYIuGFlKefSQBZAYVEbtAOqPeeFubOBhd9q4xxh ztEx4KNunnKB0J0NFoiOE050DxcPBDmgUhRcgGSpM8dLvspuxOLVj1k01ctqNlcCCJTUP Md407DNdUV7iuESxJbwdyMG45OwlnCJFnQDTZOI6CunE1vfOQuvLT5XnZ1suwy5sXYYJl 8yKs5UpQZqMgo8rhtXIiEkq381R2oal5VpUJ0BnYpoM2RhyMiKqYjjJy8SvKIyFXbCVwd nN1mqr5ddpPTMHElBMUQfx6zDexS3IQqFdqdT8ML9/GDjVp0Fs0g2q20ZIRNObJOYww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796105598; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=8lbBDgbCVvoDP/MoxhbCmvXt2FSh8zUb9R9zmBLgWWs=; b=i7BPLrOD8RBUOobGmE/R1TnoOxOgMX1ksTzd2/YuHpTDM551mG2EcPVR0ykh/9J0nwGt j7ivxBl4yj6PT/m7IUdR4kmPkDoZ55YHUQGmPADHLeJXjdZsZZOIFk2ETk5UvISwE0GFd grtLz9ssqLYVVzl3Oex4xr0RBcX9qTFqvHyosNCFiGnUJsKUCd4p8c6b7gde41hFUeOpe Q87S74Pn8ElcLfJVw8zaDYzGBGJfLCAMqArZNSpZ/+rG8728g7xywnEsZCOa8wHaHDHei cvKqj1akZ/bWplR0o25k90tgzOK/lsi3DQxtmClD8gBcjtzlah5RNXRf/VJoIuBRmLw== 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 296CB606A325 for ; Tue, 1 Dec 2026 06:13:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 296CB606A325 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-1b5bbedcdafso1715010c88.1 for ; Mon, 30 Nov 2026 22:13:16 -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=eI+EZK7arZJEmo9qo6U5bQTRFK+97y+XDotM+BPpJ2qm+7RIik7eh0umtK/RhJmzKP I9JKvT20fLCbRcMVIb27N5sy6MfIhM7731/nKZGfTmzEeZVOukwsZzTCVtZKwocj1c6L vJa2wPJpXNpSYX6fFzV/tApRyDs3s4YVvntrZi0vyk3twryBbwjw9zy6nXtFcO0NrpBD 1rEyPYWtRhGI7Uro7FoziS4tyQ0OnBZZ3nwp8pAcy/DcjS+hUp32aHCUYdBFkD+aMdkH nJP1ZhhEsQNqNssfzmT1OJwlIbCmhdZ0Pf1s5pfK3X7crgIRLi/mhPjexDWwPQSNx8GS Dhaw== X-Gm-Message-State: APuU4Z+LIVOb35hJQQjCyG8EFGgkGeSm+fx8jIa3W0BlUnzLdm1bBbde QrJ0/N0tB8cUmuziZH4tOwupbfrRIU06yN53zPb+iriLuK6XlsU0aD26gQiuJ4H4MrdQQ9g2kp+ YPXb9x2LX3QQNlg== 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-pm@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