Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3977995rdb; Wed, 30 Aug 2023 11:33:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsVXMiM5Y3WicjTGfvfglZht/1w4Io7Kxy36/WrFGPnLinoCkUjuv1k/ZXviS2QiG7BW4e X-Received: by 2002:aa7:c60a:0:b0:529:fa63:ef7d with SMTP id h10-20020aa7c60a000000b00529fa63ef7dmr2542053edq.7.1693420436899; Wed, 30 Aug 2023 11:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693420436; cv=none; d=google.com; s=arc-20160816; b=E5Y2l/+qJGY/KuQDFdDpHu4ODTNGM6VV++CWE1DkKDvoqL5cn9FP4YOvXxPZlNol6z +z9kg9evqLj7i6Id8QzWHwDZf5IFvciE74OJfpORQ/yMcCLtbnu+vGo4Hl3rHyNjL682 NtdRrdrUBv1ocNBNdAACR21tBKjceSo1LAworRHPkAW4ZTvel0dHIFlu2+05Zn/5dZoS iuKOscSdcSsPMWTZfdG9Rx0aUrorOmALFfvT1a8VY9X7SE1LdJRRXENQemws5gPlroGS Ldi4ffr8vTIVkS7Tc51x0fhMmRU5FWVjLWK/WmZtkfoSy+4/NtAOMxV9J5HoNUm1MSjQ oCyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:date:to:cc:from:subject:references :in-reply-to:content-transfer-encoding:mime-version:message-id :dkim-signature; bh=uuv01TEAA8j9PCkooSK7q4T1uZWBc75uJhsC8PFYm28=; fh=DKq+JW4ibZGHwE6Q6boniXpCY8wuxeztPuV0IAMXmm8=; b=NN6fj+BFYjjeg2smwRkaOiMfJv3caNl4lz8+Bsdxu94T4D6xORU767H1AGDyy4BbkR P+zrcX/ibFj0vMzwfb/oAOniGWFf16N6lX3+xcIC5pDhC1OhkJxJVARfJu+fIBjw7VRx acYJWzfZdP5ogRUkY98xwfUBmyGqzJP+fAA1ArNF4yeoSreQEQf+qeT6sRPpSd8KSblO dOMvPDIsD04OtCesZZ8H9Xbt+CY1Wo/GxRkVRWin795xSOnRfEgjEAD1ChYCdxe6pMCY tJrmN48Loa+CCIusi80Ib0LQKdof5dmzgxHSDODEQvneoHt4a5wcwsH1bFvncGMHKOKp Qabw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOUwFzvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020aa7dacc000000b0052322fbabf9si7943880eds.324.2023.08.30.11.33.29; Wed, 30 Aug 2023 11:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOUwFzvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236327AbjH2Vud (ORCPT + 99 others); Tue, 29 Aug 2023 17:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238557AbjH2Vu0 (ORCPT ); Tue, 29 Aug 2023 17:50:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8CA107; Tue, 29 Aug 2023 14:50:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 976216351E; Tue, 29 Aug 2023 21:50:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEEF4C433C8; Tue, 29 Aug 2023 21:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693345822; bh=U/l32QlMVAaPte5bD4QT0elttRsFrPc4ZIwaQ1O0ouY=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=bOUwFzvKtT45GrRxfuvHLwAW81f7eBzSXr9zZ6oaZcTfDGqYd9msBEzj0595LDRIE 36EDKxwgGRZjgYRD2aomvhojeEuoQA7qLFtavjRLMzce3wSS5+35vAtCu2rx27erN5 FHZ18oZuPweRMSCWGFJ7AUBbXJP0EKwbN+Z7tlexaQVV+BggiQkENQt3QA+5eCqj56 BRiH8spWV+dcUJScphSNeguYTDWG3vgDP6vhRA1JuU+9EMlyd1Y5HeFavpTRiCJ7UM FCiPJd27lBIEWE/5OpqdVwTgdGafWlkfu1SgS0oUnTyVA8Armq9WBcL55Jb/C+4Vr9 xyTAeqlSRVVsg== Message-ID: <6991631008bab403e957534d6d05360c.sboyd@kernel.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20230817225537.4053865-3-linux@roeck-us.net> References: <20230817225537.4053865-1-linux@roeck-us.net> <20230817225537.4053865-3-linux@roeck-us.net> Subject: Re: [PATCH v2 2/7] rtc: alarmtimer: Use maximum alarm time offset From: Stephen Boyd Cc: Alessandro Zummo , Benson Leung , Miquel Raynal , Thomas Gleixner , John Stultz , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Norris , Guenter Roeck To: Alexandre Belloni , Guenter Roeck Date: Tue, 29 Aug 2023 14:50:19 -0700 User-Agent: alot/0.10 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Guenter Roeck (2023-08-17 15:55:32) > Some userspace applications use timerfd_create() to request wakeups after > a long period of time. For example, a backup application may request a > wakeup once per week. This is perfectly fine as long as the system does > not try to suspend. However, if the system tries to suspend and the > system's RTC does not support the required alarm timeout, the suspend > operation will fail with an error such as >=20 > rtc_cmos 00:01: Alarms can be up to one day in the future > PM: dpm_run_callback(): platform_pm_suspend+0x0/0x4a returns -22 > alarmtimer alarmtimer.4.auto: platform_pm_suspend+0x0/0x4a returned -22 a= fter 117 usecs > PM: Device alarmtimer.4.auto failed to suspend: error -22 >=20 > This results in a refusal to suspend the system, causing substantial > battery drain on affected systems. >=20 > To fix the problem, use the maximum alarm time offset as reported by rtc > drivers to set the maximum alarm time. While this will result in brief > spurious wakeups from suspend, it is still much better than not suspending > at all. >=20 > Cc: Brian Norris > Signed-off-by: Guenter Roeck > --- > v2: Rename range_max_offset -> alarm_offset_max >=20 > kernel/time/alarmtimer.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) >=20 > diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c > index 8d9f13d847f0..895e3a6d6444 100644 > --- a/kernel/time/alarmtimer.c > +++ b/kernel/time/alarmtimer.c > @@ -290,6 +290,19 @@ static int alarmtimer_suspend(struct device *dev) > rtc_timer_cancel(rtc, &rtctimer); > rtc_read_time(rtc, &tm); > now =3D rtc_tm_to_ktime(tm); > + > + /* > + * If the RTC alarm timer only supports a limited time offset, set > + * the alarm time to the maximum supported value. > + * The system will wake up earlier than necessary and is expected > + * to go back to sleep if it has nothing to do. Does this assume that the kernel is configured for autosuspend (CONFIG_PM_AUTOSLEEP)? Maybe we should only do this when that config is enabled. If userspace is the one autosuspending, then I don't know what we do, or how the kernel knows it is OK. Maybe we need another alarmtimer clock id that will fail creation if the wakeup time is larger than what the rtc can be programmed for? Or maybe that new clock id can have this fixed behavior to wakeup early with the assumption that userspace will go back to sleep, and outdated userspace can use the original alarmtimer clock id if they don't care about suspend failing? I see another problem too. What do we do if an alarmtimer is created, the rtc device is unregistered, and then we enter suspend? It looks like alarmtimer_suspend() bails out early with no error, so suspend continues. That looks wrong. Presumably we should fail suspend entirely at that point because we'll never be able to wakeup to run the alarmtimer.