From patchwork Thu Aug 9 07:37:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todd Poynor X-Patchwork-Id: 1299131 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id BA98EDFF7B for ; Thu, 9 Aug 2012 07:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755942Ab2HIHhj (ORCPT ); Thu, 9 Aug 2012 03:37:39 -0400 Received: from mail-wi0-f202.google.com ([209.85.212.202]:60822 "EHLO mail-wi0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754749Ab2HIHhh (ORCPT ); Thu, 9 Aug 2012 03:37:37 -0400 Received: by wibhr14 with SMTP id hr14so4089wib.1 for ; Thu, 09 Aug 2012 00:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=QQ8Y7OlDAcqswBi6TkAeptiQqX3pu+MS1e1ZyBB9RrU=; b=kJp7I2YDM5KqYXjxH44hUC4uD1P4YQqXZe8ljc69D7cvayl8WAMsB/AZ00SVkUydyG N6F14hK0NeVO/SuJJuMhv3jYo/Yg0wpT0y90wklHAJ2k+3IjW+FHAgglVX2LvnzRyQBY aL42vevEBE682IsNgW8+6plvAGaDv+r7vTxpyojD2BGokOOguilEmlQ7NKseB/Pjm5D+ jMyuuI0E6+osAZcjQ8V9f3253VA4/yG/U+x1RwC2upRF0FAqKXlMNCJvFpPH4HXFtXgU EN8wwsmYwvja7xKokQqhAgdHXyRjVLDF4UlhZ5DViHFsnHGjumhIS6wB0V6jjlPWh7b/ L70g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=QQ8Y7OlDAcqswBi6TkAeptiQqX3pu+MS1e1ZyBB9RrU=; b=UsOgCufT3ryDZ+h1TtQxf7NignhywDqLBsk9idxkCmtnAXgUey1qpTJz+6ZKsvDJ22 oIJ6Gp3YwrSjbmu4EQ7NGbJT+w1Yld+cxKY/BnAZdDBMFYIAMEIEVGMfjXE44GShQ4oU Wq6ssCpBjaMbrS+JsYxqkLJZDhAtn9Vyg/W7slfy9CgDWxcb+QmzpvqoMiUrCrVOPHDh szIFDsc+19LcegjXaBeUZfN7KHOkf58lp9mfiL5rKa9ekoEAEliPObH1YAKQycpp+K2P 8BasumdPRl4U4aq8GwdiwHwUy5x8c2nFzAzSHtoDlp6xb45XwA2SfeLvQlhq6tVnY7bZ RSmQ== Received: by 10.14.179.72 with SMTP id g48mr17691745eem.2.1344497855861; Thu, 09 Aug 2012 00:37:35 -0700 (PDT) Received: by 10.14.179.72 with SMTP id g48mr17691738eem.2.1344497855793; Thu, 09 Aug 2012 00:37:35 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id d5si643680eep.0.2012.08.09.00.37.35 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 09 Aug 2012 00:37:35 -0700 (PDT) Received: from toddpoynor2.mtv.corp.google.com (toddpoynor2.mtv.corp.google.com [172.18.104.48]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 96E4120004E; Thu, 9 Aug 2012 00:37:35 -0700 (PDT) Received: by toddpoynor2.mtv.corp.google.com (Postfix, from userid 115684) id DEE21142C06; Thu, 9 Aug 2012 00:37:34 -0700 (PDT) From: Todd Poynor To: John Stultz Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, arve@android.com, Todd Poynor Subject: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend Date: Thu, 9 Aug 2012 00:37:27 -0700 Message-Id: <1344497847-7161-1-git-send-email-toddpoynor@google.com> X-Mailer: git-send-email 1.7.7.3 X-Gm-Message-State: ALoCoQmtFaBXTk2DgWcv6f3BOYiiUwuANHGYFjnFd2HX8VT48uv35DO8Zv2Nf74HagC/UouVLIqFpZZu6XSpzWLDUrAx3G7P7ohHSSre3G3741AvjQmTa9HqYw8hUeMtJTTaEqOtT8wXri2mvFZzvWPhpvMsYLO9lXP5MwwMAyZ9AoIH3UUY9yGZavHxamC4hUZRjwEf79pn Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org alarmtimer suspend return -EBUSY if the next alarm will fire in less than 2 seconds. This allows one RTC seconds tick to occur subsequent to this check before the alarm wakeup time is set, ensuring the wakeup time is still in the future (assuming the RTC does not tick one more second prior to setting the alarm). If suspend is rejected due to an imminent alarm, hold a wakeup source for 2 seconds to process the alarm prior to reattempting suspend. If setting the alarm incurs an -ETIME for an alarm set in the past, or any other problem setting the alarm, abort suspend and hold a wakelock for 1 second while the alarm is allowed to be serviced or other hopefully transient conditions preventing the alarm clear up. Signed-off-by: Todd Poynor --- kernel/time/alarmtimer.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index aa27d39..f979d85 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -46,6 +46,8 @@ static struct alarm_base { static ktime_t freezer_delta; static DEFINE_SPINLOCK(freezer_delta_lock); +static struct wakeup_source *ws; + #ifdef CONFIG_RTC_CLASS /* rtc timer and device for setting alarm wakeups at suspend */ static struct rtc_timer rtctimer; @@ -250,6 +252,7 @@ static int alarmtimer_suspend(struct device *dev) unsigned long flags; struct rtc_device *rtc; int i; + int ret; spin_lock_irqsave(&freezer_delta_lock, flags); min = freezer_delta; @@ -279,8 +282,10 @@ static int alarmtimer_suspend(struct device *dev) if (min.tv64 == 0) return 0; - /* XXX - Should we enforce a minimum sleep time? */ - WARN_ON(min.tv64 < NSEC_PER_SEC); + if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) { + __pm_wakeup_event(ws, 2 * MSEC_PER_SEC); + return -EBUSY; + } /* Setup an rtc timer to fire that far in the future */ rtc_timer_cancel(rtc, &rtctimer); @@ -288,9 +293,11 @@ static int alarmtimer_suspend(struct device *dev) now = rtc_tm_to_ktime(tm); now = ktime_add(now, min); - rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0)); - - return 0; + /* Set alarm, if in the past reject suspend briefly to handle */ + ret = rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0)); + if (ret < 0) + __pm_wakeup_event(ws, 1 * MSEC_PER_SEC); + return ret; } #else static int alarmtimer_suspend(struct device *dev) @@ -821,6 +828,7 @@ static int __init alarmtimer_init(void) error = PTR_ERR(pdev); goto out_drv; } + ws = wakeup_source_register("alarmtimer"); return 0; out_drv: