From patchwork Mon Oct 9 13:08:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 150085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1855202vqo; Mon, 9 Oct 2023 06:08:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyW76fGabKV8+1A2TrarvQYQoAQ2ybm3gpBDfxhVHd5eNNrbLckNLy/oJrYHtD+aQKpVUY X-Received: by 2002:a05:6a00:21cf:b0:68b:ff3b:e14a with SMTP id t15-20020a056a0021cf00b0068bff3be14amr18869409pfj.18.1696856907768; Mon, 09 Oct 2023 06:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696856907; cv=none; d=google.com; s=arc-20160816; b=WX0VtfOJI04EFcvm4sQMYQ3VTDLtrgVjK3/9uNt3HyX1iPWZCsNls09DJ8RhO6JUSz Qr3jqLtDbGri153D6kUHcB8cvGYOvlAaMap9LY37u2uhKVajNq2tPX2a5RiPJgnjaeUU wcxD0ckMdxWfu6COd3DKfB0RCoUZfHDHOqCEXw6Ss/7UAS/YhN3vN9qeIZCErctf1TQH sxTi/am2nRvLhYXZhwAQ7sHB7hJ4yXMk+C9Z1xFQ25uv9nITrmFBVuC4RnNOdsRo1U6u MTkwnH+tNApaXaXkn9BeX8wklyaTaFTUuTPKUW1HB13TgMtmyXehLdc49W/P/ZC+aPHC D0DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=seh42BDMFxD1CDYwbST4vPKqH1J5AcIjG1O+fVobOmk=; fh=5KFREh6EnW3D5ZqTm52xhXa+uelqugPYOe3JF5mTvrw=; b=bnyR47AGcbtCfGOcBdHe1Jc3WtaFkqOqhSyHGdHWcyx9yDLaFJI+pxgHcvEWqs21iG wDZF/cXzHCqziH1to/0wnAKv1aFf4kQpSKVB+3AtP6l3DpDgmn6oQm8xVsa3mRZ/t436 4Dt6X1xbV2iHiRE0h29EuiYjaZU3MHZeU5ICHNZRXXSJR2xdKSHI5dNZpQNFo/PfKBS5 EKrts+kd8OTSsX3bkSfA+dYYMPdRRlZnSJ8AnKsEgocse8UNI0nA90Ra+RaRr/toBp3m zNz4Id4MTbJv98qwnw9BU3WoDrYnNEEXwGB1gLZSxgMN5IdLsmNX7/qieLOXBDohVGYW rBxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dv7KQlWG; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j65-20020a638b44000000b005898cf1c687si7363405pge.144.2023.10.09.06.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 06:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dv7KQlWG; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1D79F804B87E; Mon, 9 Oct 2023 06:08:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376710AbjJINIL (ORCPT + 18 others); Mon, 9 Oct 2023 09:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376704AbjJINIJ (ORCPT ); Mon, 9 Oct 2023 09:08:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCB3D9C; Mon, 9 Oct 2023 06:08:07 -0700 (PDT) Date: Mon, 09 Oct 2023 13:08:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696856886; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=seh42BDMFxD1CDYwbST4vPKqH1J5AcIjG1O+fVobOmk=; b=dv7KQlWGXTDXxc3gduFYbnEbHREUCKB+Vp9CY+5KXjfU8Wc7AFg2NKOMgfFcZGeNLiOPGc nfFEVMaIEIHTK69fzD5N1Z0q867lDahQITgD1CEMia5L88ERLIKIrN2PQYph40VNS9orPL MjWtoNrGgRgfVEpV00izxbObvzyXp+Fl+8T01j9A/6akYcRg79+0QilGAvYy5mIhdc7svF opDcP3kKFyyudPbHz0wgija3P0sdvrZRsL5F17qfEvoKYvP/3fIGzIhNjm5eeCzqlQpXPq LFPG9IxsdUdgnPqY0hEyU8VdRio1kqPAwm4oo7aqYZF4X7oA3gLA4JZlps7YDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696856886; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=seh42BDMFxD1CDYwbST4vPKqH1J5AcIjG1O+fVobOmk=; b=fHNXxFNfN90n2MnXXjaEkm3Eq3H3bl4VWaYXu0nU0IFhdwcbBP7qpsD22Vg+PtIsI/SpNY fRtQFnwPqjFpBpAA== From: "tip-bot2 for Guenter Roeck" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] alarmtimer: Use maximum alarm time for suspend Cc: Guenter Roeck , Thomas Gleixner , John Stultz , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230915152238.1144706-3-linux@roeck-us.net> References: <20230915152238.1144706-3-linux@roeck-us.net> MIME-Version: 1.0 Message-ID: <169685688566.3135.9313648193477749393.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 06:08:20 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779283428586173665 X-GMAIL-MSGID: 1779283428586173665 The following commit has been merged into the timers/core branch of tip: Commit-ID: 8ceea12d183cf29f28072dede218a04eda2a789c Gitweb: https://git.kernel.org/tip/8ceea12d183cf29f28072dede218a04eda2a789c Author: Guenter Roeck AuthorDate: Fri, 15 Sep 2023 08:22:38 -07:00 Committer: Thomas Gleixner CommitterDate: Mon, 09 Oct 2023 15:03:28 +02:00 alarmtimer: Use maximum alarm time for suspend 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 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 after 117 usecs PM: Device alarmtimer.4.auto failed to suspend: error -22 This results in a refusal to suspend the system, causing substantial battery drain on affected systems. To fix the problem, use the maximum alarm time offset as reported by RTC drivers to set the maximum alarm time. While this may result in early wakeups from suspend, it is still much better than not suspending at all. Standardize system behavior if the requested alarm timeout is larger than the alarm timeout supported by the rtc chip. Currently, in this situation, the RTC driver will do one of the following: - It may return an error. - It may limit the alarm timeout to the maximum supported by the rtc chip. - It may mask the timeout by the maximum alarm timeout supported by the RTC chip (i.e. a requested timeout of 1 day + 1 minute may result in a 1 minute timeout). With this in place, if the RTC driver reports the maximum alarm timeout supported by the RTC chip, the system will always limit the alarm timeout to the maximum supported by the RTC chip. Signed-off-by: Guenter Roeck Signed-off-by: Thomas Gleixner Acked-by: John Stultz Link: https://lore.kernel.org/r/20230915152238.1144706-3-linux@roeck-us.net --- kernel/time/alarmtimer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 8d9f13d..4657cb8 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -290,6 +290,17 @@ static int alarmtimer_suspend(struct device *dev) rtc_timer_cancel(rtc, &rtctimer); rtc_read_time(rtc, &tm); now = 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 may wake up earlier (possibly much earlier) than expected + * when the alarmtimer runs. This is the best the kernel can do if + * the alarmtimer exceeds the time that the rtc device can be programmed + * for. + */ + min = rtc_bound_alarmtime(rtc, min); + now = ktime_add(now, min); /* Set alarm, if in the past reject suspend briefly to handle */