From patchwork Wed Jun 20 22:46:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9513 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 B585B23E1B for ; Wed, 20 Jun 2012 22:46:17 +0000 (UTC) Received: from mail-yw0-f50.google.com (mail-yw0-f50.google.com [209.85.213.50]) by fiordland.canonical.com (Postfix) with ESMTP id 63FE0A18472 for ; Wed, 20 Jun 2012 22:46:17 +0000 (UTC) Received: by yhjj63 with SMTP id j63so7267300yhj.37 for ; Wed, 20 Jun 2012 15:46:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :subject:date:message-id:x-mailer:x-content-scanned:x-cbid :x-gm-message-state; bh=l3rNs+aUZ/DgdukNJGh9tJozzoGwnjtsUO47A6jGda0=; b=gCvmxcJGeTLDewGRFX+B7xf6G6S8WEsL8KYCYr24ujndsEa+DA/QCSMzVhigZlFkw4 vrJaIbYlHJJlVq6Qwrq1WKIsu/RsDVTDMi2xo/rGdgRoXY2yabaAG9UAZKUloZkl1T/9 CNggAngQpR2p71KqthJmNHTDkQzekZTWD9B19J+RaUZzwp6gmcjfbI7E31BHLIKLLOM+ C36zLApiGj+WDnXtrcT4LyhrsqyUU5S7LCu9Loa/0NVubDfj6B8pMvK0uxSzHkMYr18L nUOJ5YqX+mJ4B37FK4hhKqY2LVwdQlcdO0rjYvXw7Ynxsm20zgyTOpJ/h2QUxxge84n/ RWoQ== Received: by 10.50.46.232 with SMTP id y8mr5968525igm.57.1340232376373; Wed, 20 Jun 2012 15:46:16 -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.231.24.148 with SMTP id v20csp204048ibb; Wed, 20 Jun 2012 15:46:15 -0700 (PDT) Received: by 10.236.183.227 with SMTP id q63mr29376759yhm.114.1340232374841; Wed, 20 Jun 2012 15:46:14 -0700 (PDT) Received: from e35.co.us.ibm.com (e35.co.us.ibm.com. [32.97.110.153]) by mx.google.com with ESMTPS id d42si933270yhl.154.2012.06.20.15.46.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Jun 2012 15:46:14 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.110.153 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.110.153; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.110.153 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Jun 2012 16:46:13 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 20 Jun 2012 16:46:12 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id D5CD33E4004C; Wed, 20 Jun 2012 22:46:10 +0000 (WET) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5KMkAvZ173264; Wed, 20 Jun 2012 16:46:10 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5KMkAlB014153; Wed, 20 Jun 2012 16:46:10 -0600 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q5KMk91G014055; Wed, 20 Jun 2012 16:46:10 -0600 From: John Stultz To: john.stultz@linaro.org Subject: [PATCH] [RFC] time: Add CLOCK_TAI clockid Date: Wed, 20 Jun 2012 18:46:05 -0400 Message-Id: <1340232365-5986-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12062022-6148-0000-0000-000006E712BC X-Gm-Message-State: ALoCoQmZOkpqmypoye/wh78MwiDY2y2BEDZbontr5/c16DoZxIgcPe6J00M9SHoeqsLWgytpumUK This add a CLOCK_TAI clockid and the needed accessors. Signed-off-by: John Stultz --- include/linux/time.h | 7 +++---- kernel/posix-timers.c | 10 ++++++++++ kernel/time/timekeeping.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/linux/time.h b/include/linux/time.h index 2d98ae8..5ef3862 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -170,6 +170,7 @@ extern u64 timekeeping_max_deferment(void); extern int timekeeping_inject_offset(struct timespec *ts); extern u32 timekeeping_get_tai_offset(void); extern void timekeeping_set_tai_offset(u32 tai_offset); +extern void timekeeping_clocktai(struct timespec *ts); struct tms; extern void do_sys_times(struct tms *); @@ -298,11 +299,9 @@ struct itimerval { #define CLOCK_BOOTTIME 7 #define CLOCK_REALTIME_ALARM 8 #define CLOCK_BOOTTIME_ALARM 9 +#define CLOCK_SGI_CYCLE 10 /* Hardware specific */ +#define CLOCK_TAI 11 -/* - * The IDs of various hardware clocks: - */ -#define CLOCK_SGI_CYCLE 10 #define MAX_CLOCKS 16 #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) #define CLOCKS_MONO CLOCK_MONOTONIC diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index 69185ae..d6d146c 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c @@ -221,6 +221,11 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp) return 0; } +static int posix_get_tai(clockid_t which_clock, struct timespec *tp) +{ + timekeeping_clocktai(tp); + return 0; +} /* * Initialize everything, well, just everything in Posix clocks/timers ;) @@ -261,6 +266,10 @@ static __init int init_posix_timers(void) .clock_getres = posix_get_coarse_res, .clock_get = posix_get_monotonic_coarse, }; + struct k_clock clock_tai = { + .clock_getres = hrtimer_get_res, + .clock_get = posix_get_tai, + }; struct k_clock clock_boottime = { .clock_getres = hrtimer_get_res, .clock_get = posix_get_boottime, @@ -278,6 +287,7 @@ static __init int init_posix_timers(void) posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime); + posix_timers_register_clock(CLOCK_TAI, &clock_tai); posix_timers_cache = kmem_cache_create("posix_timers_cache", sizeof (struct k_itimer), 0, SLAB_PANIC, diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 0ea2be4..807a479 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -341,6 +341,37 @@ void ktime_get_ts(struct timespec *ts) } EXPORT_SYMBOL_GPL(ktime_get_ts); + +/** + * timekeeping_clocktai - Returns the TAI time of day in a timespec + * @ts: pointer to the timespec to be set + * + * Returns the time of day in a timespec. + */ +void timekeeping_clocktai(struct timespec *ts) +{ + unsigned long seq; + s64 nsecs; + + WARN_ON(timekeeping_suspended); + + do { + seq = read_seqbegin(&timekeeper.lock); + + *ts = timekeeper.xtime; + nsecs = timekeeping_get_ns(); + + /* If arch requires, add in gettimeoffset() */ + nsecs += arch_gettimeoffset(); + ts->tv_sec += timekeeper.tai_offset; + + } while (read_seqretry(&timekeeper.lock, seq)); + + timespec_add_ns(ts, nsecs); +} +EXPORT_SYMBOL(timekeeping_clocktai); + + #ifdef CONFIG_NTP_PPS /**