aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Gordeev <lasaine@lvk.cs.msu.su>2011-01-12 20:00:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 11:03:21 -0500
commite2c18e49a0d4f822ffc29fb4958943beb1ff08b7 (patch)
tree227dbb544277f7908fa1666ce21a15e6b2282ccb
parent025b40abe715d638e60516a657d354e8560c1a85 (diff)
pps: capture MONOTONIC_RAW timestamps as well
MONOTONIC_RAW clock timestamps are ideally suited for frequency calculation and also fit well into the original NTP hardpps design. Now phase and frequency can be adjusted separately: the former based on REALTIME clock and the latter based on MONOTONIC_RAW clock. A new function getnstime_raw_and_real is added to timekeeping subsystem to capture both timestamps at the same time and atomically. Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su> Acked-by: John Stultz <johnstul@us.ibm.com> Cc: Rodolfo Giometti <giometti@enneenne.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/pps_kernel.h14
-rw-r--r--include/linux/time.h2
-rw-r--r--kernel/time/timekeeping.c43
3 files changed, 59 insertions, 0 deletions
diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h
index 1aedf50088cf..94048547f29a 100644
--- a/include/linux/pps_kernel.h
+++ b/include/linux/pps_kernel.h
@@ -47,6 +47,9 @@ struct pps_source_info {
47}; 47};
48 48
49struct pps_event_time { 49struct pps_event_time {
50#ifdef CONFIG_NTP_PPS
51 struct timespec ts_raw;
52#endif /* CONFIG_NTP_PPS */
50 struct timespec ts_real; 53 struct timespec ts_real;
51}; 54};
52 55
@@ -97,10 +100,21 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
97 kt->nsec = ts.tv_nsec; 100 kt->nsec = ts.tv_nsec;
98} 101}
99 102
103#ifdef CONFIG_NTP_PPS
104
105static inline void pps_get_ts(struct pps_event_time *ts)
106{
107 getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
108}
109
110#else /* CONFIG_NTP_PPS */
111
100static inline void pps_get_ts(struct pps_event_time *ts) 112static inline void pps_get_ts(struct pps_event_time *ts)
101{ 113{
102 getnstimeofday(&ts->ts_real); 114 getnstimeofday(&ts->ts_real);
103} 115}
104 116
117#endif /* CONFIG_NTP_PPS */
118
105#endif /* LINUX_PPS_KERNEL_H */ 119#endif /* LINUX_PPS_KERNEL_H */
106 120
diff --git a/include/linux/time.h b/include/linux/time.h
index 9f15ac7ab92a..1e6d3b59238d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -158,6 +158,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);
158extern int do_getitimer(int which, struct itimerval *value); 158extern int do_getitimer(int which, struct itimerval *value);
159extern void getnstimeofday(struct timespec *tv); 159extern void getnstimeofday(struct timespec *tv);
160extern void getrawmonotonic(struct timespec *ts); 160extern void getrawmonotonic(struct timespec *ts);
161extern void getnstime_raw_and_real(struct timespec *ts_raw,
162 struct timespec *ts_real);
161extern void getboottime(struct timespec *ts); 163extern void getboottime(struct timespec *ts);
162extern void monotonic_to_bootbased(struct timespec *ts); 164extern void monotonic_to_bootbased(struct timespec *ts);
163 165
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5bb86da82003..5536aaf3ba36 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -288,6 +288,49 @@ void ktime_get_ts(struct timespec *ts)
288} 288}
289EXPORT_SYMBOL_GPL(ktime_get_ts); 289EXPORT_SYMBOL_GPL(ktime_get_ts);
290 290
291#ifdef CONFIG_NTP_PPS
292
293/**
294 * getnstime_raw_and_real - get day and raw monotonic time in timespec format
295 * @ts_raw: pointer to the timespec to be set to raw monotonic time
296 * @ts_real: pointer to the timespec to be set to the time of day
297 *
298 * This function reads both the time of day and raw monotonic time at the
299 * same time atomically and stores the resulting timestamps in timespec
300 * format.
301 */
302void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
303{
304 unsigned long seq;
305 s64 nsecs_raw, nsecs_real;
306
307 WARN_ON_ONCE(timekeeping_suspended);
308
309 do {
310 u32 arch_offset;
311
312 seq = read_seqbegin(&xtime_lock);
313
314 *ts_raw = raw_time;
315 *ts_real = xtime;
316
317 nsecs_raw = timekeeping_get_ns_raw();
318 nsecs_real = timekeeping_get_ns();
319
320 /* If arch requires, add in gettimeoffset() */
321 arch_offset = arch_gettimeoffset();
322 nsecs_raw += arch_offset;
323 nsecs_real += arch_offset;
324
325 } while (read_seqretry(&xtime_lock, seq));
326
327 timespec_add_ns(ts_raw, nsecs_raw);
328 timespec_add_ns(ts_real, nsecs_real);
329}
330EXPORT_SYMBOL(getnstime_raw_and_real);
331
332#endif /* CONFIG_NTP_PPS */
333
291/** 334/**
292 * do_gettimeofday - Returns the time of day in a timeval 335 * do_gettimeofday - Returns the time of day in a timeval
293 * @tv: pointer to the timeval to be set 336 * @tv: pointer to the timeval to be set