From patchwork Tue Jun 21 23:52:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 2148 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 07A9623F08 for ; Tue, 21 Jun 2011 23:53:15 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id CA35AA188A0 for ; Tue, 21 Jun 2011 23:53:14 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 7so364962vxd.11 for ; Tue, 21 Jun 2011 16:53:14 -0700 (PDT) Received: by 10.52.95.194 with SMTP id dm2mr37925vdb.47.1308700394621; Tue, 21 Jun 2011 16:53:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs105223vdc; Tue, 21 Jun 2011 16:53:14 -0700 (PDT) Received: by 10.91.87.5 with SMTP id p5mr120811agl.102.1308700393879; Tue, 21 Jun 2011 16:53:13 -0700 (PDT) Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx.google.com with ESMTPS id el7si11695icb.84.2011.06.21.16.53.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Jun 2011 16:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.154 as permitted sender) client-ip=32.97.110.154; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.154 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e36.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p5LNl7dY017849; Tue, 21 Jun 2011 17:47:07 -0600 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5LNr5SP175988; Tue, 21 Jun 2011 17:53:05 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5LNr4Yx001605; Tue, 21 Jun 2011 17:53:05 -0600 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p5LNr4pl001577; Tue, 21 Jun 2011 17:53:04 -0600 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 0B3841E750F; Tue, 21 Jun 2011 16:53:04 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , =?UTF-8?q?Toralf=20F=C3=B6rster?= , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 2/2] alarmtimers: Return -ENOTSUPP if no RTC device is present Date: Tue, 21 Jun 2011 16:52:53 -0700 Message-Id: <1308700373-18415-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1308700373-18415-1-git-send-email-john.stultz@linaro.org> References: <1308700373-18415-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 Toralf Förster and Richard Weinberger noted that if there is no RTC device, the alarm timers core prints out an annoying "ALARM timers will not wake from suspend" message. This warning has been removed in a previous patch, however the issue still remains: The original idea was to support alarm timers even if there was no rtc device, as long as the system didn't go into suspend. However, after further consideration, communicating to the application that alarmtimers are not fully functional seems like the better solution. So this patch makes it so we return -ENOTSUPP to any posix _ALARM clockid calls if there is no backing RTC device on the system. Further this changes the behavior where when there is no rtc device we will check for one on clock_getres, clock_gettime, timer_create, and timer_nsleep instead of on suspend. CC: Toralf Förster CC: Richard Weinberger CC: Thomas Gleixner Reported-by: Toralf Förster Reported by: Richard Weinberger Signed-off-by: John Stultz --- kernel/time/alarmtimer.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 98ecf4e..59f369f 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -107,6 +107,9 @@ static struct rtc_device *alarmtimer_get_rtcdev(void) return ret; } +#else +#define alarmtimer_get_rtcdev() (0) +#define rtcdev (0) #endif @@ -231,7 +234,7 @@ static int alarmtimer_suspend(struct device *dev) freezer_delta = ktime_set(0, 0); spin_unlock_irqrestore(&freezer_delta_lock, flags); - rtc = alarmtimer_get_rtcdev(); + rtc = rtcdev; /* If we have no rtcdev, just return */ if (!rtc) return 0; @@ -381,6 +384,9 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp) { clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid; + if (!alarmtimer_get_rtcdev()) + return -ENOTSUPP; + return hrtimer_get_res(baseid, tp); } @@ -395,6 +401,9 @@ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp) { struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)]; + if (!alarmtimer_get_rtcdev()) + return -ENOTSUPP; + *tp = ktime_to_timespec(base->gettime()); return 0; } @@ -410,6 +419,9 @@ static int alarm_timer_create(struct k_itimer *new_timer) enum alarmtimer_type type; struct alarm_base *base; + if (!alarmtimer_get_rtcdev()) + return -ENOTSUPP; + if (!capable(CAP_WAKE_ALARM)) return -EPERM; @@ -444,6 +456,9 @@ static void alarm_timer_get(struct k_itimer *timr, */ static int alarm_timer_del(struct k_itimer *timr) { + if (!rtcdev) + return -ENOTSUPP; + alarm_cancel(&timr->it.alarmtimer); return 0; } @@ -461,6 +476,9 @@ static int alarm_timer_set(struct k_itimer *timr, int flags, struct itimerspec *new_setting, struct itimerspec *old_setting) { + if (!rtcdev) + return -ENOTSUPP; + /* Save old values */ old_setting->it_interval = ktime_to_timespec(timr->it.alarmtimer.period); @@ -600,6 +618,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, int ret = 0; struct restart_block *restart; + if (!alarmtimer_get_rtcdev()) + return -ENOTSUPP; + if (!capable(CAP_WAKE_ALARM)) return -EPERM;