From patchwork Tue Jun 14 02:04:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 1885 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.47.109) by localhost6.localdomain6 with IMAP4-SSL; 14 Jun 2011 16:46:21 -0000 Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs36072vdc; Mon, 13 Jun 2011 19:05:02 -0700 (PDT) Received: by 10.100.50.27 with SMTP id x27mr5926510anx.16.1308017101675; Mon, 13 Jun 2011 19:05:01 -0700 (PDT) Received: from e9.ny.us.ibm.com (e9.ny.us.ibm.com [32.97.182.139]) by mx.google.com with ESMTPS id z2si11494069anj.10.2011.06.13.19.04.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 13 Jun 2011 19:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.139 as permitted sender) client-ip=32.97.182.139; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.139 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p5E1YJNA025711; Mon, 13 Jun 2011 21:34:19 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5E24ulX435126; Mon, 13 Jun 2011 22:04:56 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5E24thi031500; Mon, 13 Jun 2011 23:04:56 -0300 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p5E24sWt031487; Mon, 13 Jun 2011 23:04:55 -0300 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id CA5E61E750E; Mon, 13 Jun 2011 19:04:53 -0700 (PDT) From: John Stultz To: linux-kernel Cc: John Stultz , =?UTF-8?q?Toralf=20F=C3=B6rster?= , Peter Zijlstra , Thomas Gleixner Subject: [RFC][PATCH] alarmtimers: Return -ENOTSUPP if no RTC device is present Date: Mon, 13 Jun 2011 19:04:48 -0700 Message-Id: <1308017088-8233-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 MIME-Version: 1.0 Thomas, all: I wanted to send this out for initial feedback, but I think it would be good to get this in for the final 3.0 release. Let me know your thoughts here. thanks -john 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. 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. 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 | 32 ++++++++++++++++++++------------ 1 files changed, 20 insertions(+), 12 deletions(-) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 2d96624..aee3e53 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -46,6 +46,8 @@ static struct alarm_base { /* rtc timer and device for setting alarm wakeups at suspend */ static struct rtc_timer rtctimer; static struct rtc_device *rtcdev; +#else +#define rtcdev 0 #endif /* freezer delta & lock used to handle clock_nanosleep triggered wakeups */ @@ -322,6 +324,8 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp) { clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid; + if (!rtcdev) + return -ENOTSUPP; return hrtimer_get_res(baseid, tp); } @@ -336,6 +340,9 @@ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp) { struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)]; + if (!rtcdev) + return -ENOTSUPP; + *tp = ktime_to_timespec(base->gettime()); return 0; } @@ -351,6 +358,9 @@ static int alarm_timer_create(struct k_itimer *new_timer) enum alarmtimer_type type; struct alarm_base *base; + if (!rtcdev) + return -ENOTSUPP; + if (!capable(CAP_WAKE_ALARM)) return -EPERM; @@ -385,6 +395,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; } @@ -402,6 +415,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); @@ -541,6 +557,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, int ret = 0; struct restart_block *restart; + if (!rtcdev) + return -ENOTSUPP; + if (!capable(CAP_WAKE_ALARM)) return -EPERM; @@ -683,20 +702,9 @@ static int __init alarmtimer_init_late(void) */ put_device(dev); } - if (!rtcdev) { - printk(KERN_WARNING "No RTC device found, ALARM timers will" - " not wake from suspend"); - } rtc_timer_init(&rtctimer, NULL, NULL); return 0; } -#else -static int __init alarmtimer_init_late(void) -{ - printk(KERN_WARNING "Kernel not built with RTC support, ALARM timers" - " will not wake from suspend"); - return 0; -} -#endif late_initcall(alarmtimer_init_late); +#endif