提交 e2c18e49 编写于 作者: A Alexander Gordeev 提交者: Linus Torvalds

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: NAlexander Gordeev <lasaine@lvk.cs.msu.su>
Acked-by: NJohn Stultz <johnstul@us.ibm.com>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 025b40ab
...@@ -47,6 +47,9 @@ struct pps_source_info { ...@@ -47,6 +47,9 @@ struct pps_source_info {
}; };
struct pps_event_time { struct pps_event_time {
#ifdef CONFIG_NTP_PPS
struct timespec ts_raw;
#endif /* CONFIG_NTP_PPS */
struct timespec ts_real; struct timespec ts_real;
}; };
...@@ -97,10 +100,21 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt, ...@@ -97,10 +100,21 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
kt->nsec = ts.tv_nsec; kt->nsec = ts.tv_nsec;
} }
#ifdef CONFIG_NTP_PPS
static inline void pps_get_ts(struct pps_event_time *ts)
{
getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
}
#else /* CONFIG_NTP_PPS */
static inline void pps_get_ts(struct pps_event_time *ts) static inline void pps_get_ts(struct pps_event_time *ts)
{ {
getnstimeofday(&ts->ts_real); getnstimeofday(&ts->ts_real);
} }
#endif /* CONFIG_NTP_PPS */
#endif /* LINUX_PPS_KERNEL_H */ #endif /* LINUX_PPS_KERNEL_H */
...@@ -158,6 +158,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds); ...@@ -158,6 +158,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);
extern int do_getitimer(int which, struct itimerval *value); extern int do_getitimer(int which, struct itimerval *value);
extern void getnstimeofday(struct timespec *tv); extern void getnstimeofday(struct timespec *tv);
extern void getrawmonotonic(struct timespec *ts); extern void getrawmonotonic(struct timespec *ts);
extern void getnstime_raw_and_real(struct timespec *ts_raw,
struct timespec *ts_real);
extern void getboottime(struct timespec *ts); extern void getboottime(struct timespec *ts);
extern void monotonic_to_bootbased(struct timespec *ts); extern void monotonic_to_bootbased(struct timespec *ts);
......
...@@ -288,6 +288,49 @@ void ktime_get_ts(struct timespec *ts) ...@@ -288,6 +288,49 @@ void ktime_get_ts(struct timespec *ts)
} }
EXPORT_SYMBOL_GPL(ktime_get_ts); EXPORT_SYMBOL_GPL(ktime_get_ts);
#ifdef CONFIG_NTP_PPS
/**
* getnstime_raw_and_real - get day and raw monotonic time in timespec format
* @ts_raw: pointer to the timespec to be set to raw monotonic time
* @ts_real: pointer to the timespec to be set to the time of day
*
* This function reads both the time of day and raw monotonic time at the
* same time atomically and stores the resulting timestamps in timespec
* format.
*/
void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
{
unsigned long seq;
s64 nsecs_raw, nsecs_real;
WARN_ON_ONCE(timekeeping_suspended);
do {
u32 arch_offset;
seq = read_seqbegin(&xtime_lock);
*ts_raw = raw_time;
*ts_real = xtime;
nsecs_raw = timekeeping_get_ns_raw();
nsecs_real = timekeeping_get_ns();
/* If arch requires, add in gettimeoffset() */
arch_offset = arch_gettimeoffset();
nsecs_raw += arch_offset;
nsecs_real += arch_offset;
} while (read_seqretry(&xtime_lock, seq));
timespec_add_ns(ts_raw, nsecs_raw);
timespec_add_ns(ts_real, nsecs_real);
}
EXPORT_SYMBOL(getnstime_raw_and_real);
#endif /* CONFIG_NTP_PPS */
/** /**
* do_gettimeofday - Returns the time of day in a timeval * do_gettimeofday - Returns the time of day in a timeval
* @tv: pointer to the timeval to be set * @tv: pointer to the timeval to be set
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册