Commit 2ba2a305 authored by Martin Schwidefsky's avatar Martin Schwidefsky Committed by Thomas Gleixner

timekeeping: Add timekeeper read_clock helper functions

Add timekeeper_read_clock_ntp and timekeeper_read_clock_raw and use
them for getnstimeofday, ktime_get, ktime_get_ts and getrawmonotonic.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Acked-by: default avatarJohn Stultz <johnstul@us.ibm.com>
Cc: Daniel Walker <dwalker@fifo99.com>
LKML-Reference: <20090814134810.435105711@de.ibm.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 0a544198
...@@ -95,6 +95,40 @@ static void timekeeper_setup_internals(struct clocksource *clock) ...@@ -95,6 +95,40 @@ static void timekeeper_setup_internals(struct clocksource *clock)
timekeeper.mult = clock->mult; timekeeper.mult = clock->mult;
} }
/* Timekeeper helper functions. */
static inline s64 timekeeping_get_ns(void)
{
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* return delta convert to nanoseconds using ntp adjusted mult. */
return clocksource_cyc2ns(cycle_delta, timekeeper.mult,
timekeeper.shift);
}
static inline s64 timekeeping_get_ns_raw(void)
{
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* return delta convert to nanoseconds using ntp adjusted mult. */
return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
}
/* /*
* This read-write spinlock protects us from races in SMP while * This read-write spinlock protects us from races in SMP while
* playing with xtime. * playing with xtime.
...@@ -183,8 +217,6 @@ static void timekeeping_forward_now(void) ...@@ -183,8 +217,6 @@ static void timekeeping_forward_now(void)
*/ */
void getnstimeofday(struct timespec *ts) void getnstimeofday(struct timespec *ts)
{ {
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
unsigned long seq; unsigned long seq;
s64 nsecs; s64 nsecs;
...@@ -194,17 +226,7 @@ void getnstimeofday(struct timespec *ts) ...@@ -194,17 +226,7 @@ void getnstimeofday(struct timespec *ts)
seq = read_seqbegin(&xtime_lock); seq = read_seqbegin(&xtime_lock);
*ts = xtime; *ts = xtime;
nsecs = timekeeping_get_ns();
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* convert to nanoseconds: */
nsecs = clocksource_cyc2ns(cycle_delta, timekeeper.mult,
timekeeper.shift);
/* If arch requires, add in gettimeoffset() */ /* If arch requires, add in gettimeoffset() */
nsecs += arch_gettimeoffset(); nsecs += arch_gettimeoffset();
...@@ -218,8 +240,6 @@ EXPORT_SYMBOL(getnstimeofday); ...@@ -218,8 +240,6 @@ EXPORT_SYMBOL(getnstimeofday);
ktime_t ktime_get(void) ktime_t ktime_get(void)
{ {
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
unsigned int seq; unsigned int seq;
s64 secs, nsecs; s64 secs, nsecs;
...@@ -229,17 +249,7 @@ ktime_t ktime_get(void) ...@@ -229,17 +249,7 @@ ktime_t ktime_get(void)
seq = read_seqbegin(&xtime_lock); seq = read_seqbegin(&xtime_lock);
secs = xtime.tv_sec + wall_to_monotonic.tv_sec; secs = xtime.tv_sec + wall_to_monotonic.tv_sec;
nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec; nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec;
nsecs += timekeeping_get_ns();
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* convert to nanoseconds: */
nsecs += clocksource_cyc2ns(cycle_delta, timekeeper.mult,
timekeeper.shift);
} while (read_seqretry(&xtime_lock, seq)); } while (read_seqretry(&xtime_lock, seq));
/* /*
...@@ -260,8 +270,6 @@ EXPORT_SYMBOL_GPL(ktime_get); ...@@ -260,8 +270,6 @@ EXPORT_SYMBOL_GPL(ktime_get);
*/ */
void ktime_get_ts(struct timespec *ts) void ktime_get_ts(struct timespec *ts)
{ {
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
struct timespec tomono; struct timespec tomono;
unsigned int seq; unsigned int seq;
s64 nsecs; s64 nsecs;
...@@ -272,17 +280,7 @@ void ktime_get_ts(struct timespec *ts) ...@@ -272,17 +280,7 @@ void ktime_get_ts(struct timespec *ts)
seq = read_seqbegin(&xtime_lock); seq = read_seqbegin(&xtime_lock);
*ts = xtime; *ts = xtime;
tomono = wall_to_monotonic; tomono = wall_to_monotonic;
nsecs = timekeeping_get_ns();
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* convert to nanoseconds: */
nsecs = clocksource_cyc2ns(cycle_delta, timekeeper.mult,
timekeeper.shift);
} while (read_seqretry(&xtime_lock, seq)); } while (read_seqretry(&xtime_lock, seq));
...@@ -445,23 +443,10 @@ void getrawmonotonic(struct timespec *ts) ...@@ -445,23 +443,10 @@ void getrawmonotonic(struct timespec *ts)
{ {
unsigned long seq; unsigned long seq;
s64 nsecs; s64 nsecs;
cycle_t cycle_now, cycle_delta;
struct clocksource *clock;
do { do {
seq = read_seqbegin(&xtime_lock); seq = read_seqbegin(&xtime_lock);
nsecs = timekeeping_get_ns_raw();
/* read clocksource: */
clock = timekeeper.clock;
cycle_now = clock->read(clock);
/* calculate the delta since the last update_wall_time: */
cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
/* convert to nanoseconds: */
nsecs = clocksource_cyc2ns(cycle_delta, clock->mult,
clock->shift);
*ts = raw_time; *ts = raw_time;
} while (read_seqretry(&xtime_lock, seq)); } while (read_seqretry(&xtime_lock, seq));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment