diff options
| author | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2009-08-14 09:47:32 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2009-08-15 04:55:47 -0400 |
| commit | 23970e389e9cee43c4b41023935e1417271708b2 (patch) | |
| tree | d97d299cf74c44cf7ceb4c04c82dafc451fbbfbb | |
| parent | d4f587c67fc39e0030ddd718675e252e208da4d7 (diff) | |
timekeeping: Introduce read_boot_clock
Add the new function read_boot_clock to get the exact time the system
has been started. For architectures without support for exact boot
time a new weak function is added that returns 0. Use the exact boot
time to initialize wall_to_monotonic, or xtime if the read_boot_clock
returned 0.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Acked-by: John Stultz <johnstul@us.ibm.com>
Cc: Daniel Walker <dwalker@fifo99.com>
LKML-Reference: <20090814134811.296703241@de.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
| -rw-r--r-- | arch/s390/kernel/time.c | 17 | ||||
| -rw-r--r-- | include/linux/time.h | 1 | ||||
| -rw-r--r-- | kernel/time/timekeeping.c | 24 |
3 files changed, 28 insertions, 14 deletions
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c index a94ec48587b4..6bff1a1d9060 100644 --- a/arch/s390/kernel/time.c +++ b/arch/s390/kernel/time.c | |||
| @@ -187,6 +187,11 @@ void read_persistent_clock(struct timespec *ts) | |||
| 187 | tod_to_timeval(get_clock() - TOD_UNIX_EPOCH, ts); | 187 | tod_to_timeval(get_clock() - TOD_UNIX_EPOCH, ts); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | void read_boot_clock(struct timespec *ts) | ||
| 191 | { | ||
| 192 | tod_to_timeval(sched_clock_base_cc - TOD_UNIX_EPOCH, ts); | ||
| 193 | } | ||
| 194 | |||
| 190 | static cycle_t read_tod_clock(struct clocksource *cs) | 195 | static cycle_t read_tod_clock(struct clocksource *cs) |
| 191 | { | 196 | { |
| 192 | return get_clock(); | 197 | return get_clock(); |
| @@ -243,9 +248,6 @@ void update_vsyscall_tz(void) | |||
| 243 | */ | 248 | */ |
| 244 | void __init time_init(void) | 249 | void __init time_init(void) |
| 245 | { | 250 | { |
| 246 | struct timespec ts; | ||
| 247 | unsigned long flags; | ||
| 248 | |||
| 249 | /* Reset time synchronization interfaces. */ | 251 | /* Reset time synchronization interfaces. */ |
| 250 | etr_reset(); | 252 | etr_reset(); |
| 251 | stp_reset(); | 253 | stp_reset(); |
| @@ -261,15 +263,6 @@ void __init time_init(void) | |||
| 261 | if (clocksource_register(&clocksource_tod) != 0) | 263 | if (clocksource_register(&clocksource_tod) != 0) |
| 262 | panic("Could not register TOD clock source"); | 264 | panic("Could not register TOD clock source"); |
| 263 | 265 | ||
| 264 | /* | ||
| 265 | * Reset wall_to_monotonic to the initial timestamp created | ||
| 266 | * in head.S to get a precise value in /proc/uptime. | ||
| 267 | */ | ||
| 268 | write_seqlock_irqsave(&xtime_lock, flags); | ||
| 269 | tod_to_timeval(sched_clock_base_cc - TOD_UNIX_EPOCH, &ts); | ||
| 270 | set_normalized_timespec(&wall_to_monotonic, -ts.tv_sec, -ts.tv_nsec); | ||
| 271 | write_sequnlock_irqrestore(&xtime_lock, flags); | ||
| 272 | |||
| 273 | /* Enable TOD clock interrupts on the boot cpu. */ | 266 | /* Enable TOD clock interrupts on the boot cpu. */ |
| 274 | init_cpu_timer(); | 267 | init_cpu_timer(); |
| 275 | 268 | ||
diff --git a/include/linux/time.h b/include/linux/time.h index 53a3216f0d1b..f505988398e6 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
| @@ -102,6 +102,7 @@ extern struct timespec wall_to_monotonic; | |||
| 102 | extern seqlock_t xtime_lock; | 102 | extern seqlock_t xtime_lock; |
| 103 | 103 | ||
| 104 | extern void read_persistent_clock(struct timespec *ts); | 104 | extern void read_persistent_clock(struct timespec *ts); |
| 105 | extern void read_boot_clock(struct timespec *ts); | ||
| 105 | extern int update_persistent_clock(struct timespec now); | 106 | extern int update_persistent_clock(struct timespec now); |
| 106 | extern int no_sync_cmos_clock __read_mostly; | 107 | extern int no_sync_cmos_clock __read_mostly; |
| 107 | void timekeeping_init(void); | 108 | void timekeeping_init(void); |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index f1a21ce491e6..15e06defca55 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
| @@ -501,6 +501,21 @@ void __attribute__((weak)) read_persistent_clock(struct timespec *ts) | |||
| 501 | ts->tv_nsec = 0; | 501 | ts->tv_nsec = 0; |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | /** | ||
| 505 | * read_boot_clock - Return time of the system start. | ||
| 506 | * | ||
| 507 | * Weak dummy function for arches that do not yet support it. | ||
| 508 | * Function to read the exact time the system has been started. | ||
| 509 | * Returns a timespec with tv_sec=0 and tv_nsec=0 if unsupported. | ||
| 510 | * | ||
| 511 | * XXX - Do be sure to remove it once all arches implement it. | ||
| 512 | */ | ||
| 513 | void __attribute__((weak)) read_boot_clock(struct timespec *ts) | ||
| 514 | { | ||
| 515 | ts->tv_sec = 0; | ||
| 516 | ts->tv_nsec = 0; | ||
| 517 | } | ||
| 518 | |||
| 504 | /* | 519 | /* |
| 505 | * timekeeping_init - Initializes the clocksource and common timekeeping values | 520 | * timekeeping_init - Initializes the clocksource and common timekeeping values |
| 506 | */ | 521 | */ |
| @@ -508,9 +523,10 @@ void __init timekeeping_init(void) | |||
| 508 | { | 523 | { |
| 509 | struct clocksource *clock; | 524 | struct clocksource *clock; |
| 510 | unsigned long flags; | 525 | unsigned long flags; |
| 511 | struct timespec now; | 526 | struct timespec now, boot; |
| 512 | 527 | ||
| 513 | read_persistent_clock(&now); | 528 | read_persistent_clock(&now); |
| 529 | read_boot_clock(&boot); | ||
| 514 | 530 | ||
| 515 | write_seqlock_irqsave(&xtime_lock, flags); | 531 | write_seqlock_irqsave(&xtime_lock, flags); |
| 516 | 532 | ||
| @@ -525,8 +541,12 @@ void __init timekeeping_init(void) | |||
| 525 | xtime.tv_nsec = now.tv_nsec; | 541 | xtime.tv_nsec = now.tv_nsec; |
| 526 | raw_time.tv_sec = 0; | 542 | raw_time.tv_sec = 0; |
| 527 | raw_time.tv_nsec = 0; | 543 | raw_time.tv_nsec = 0; |
| 544 | if (boot.tv_sec == 0 && boot.tv_nsec == 0) { | ||
| 545 | boot.tv_sec = xtime.tv_sec; | ||
| 546 | boot.tv_nsec = xtime.tv_nsec; | ||
| 547 | } | ||
| 528 | set_normalized_timespec(&wall_to_monotonic, | 548 | set_normalized_timespec(&wall_to_monotonic, |
| 529 | -xtime.tv_sec, -xtime.tv_nsec); | 549 | -boot.tv_sec, -boot.tv_nsec); |
| 530 | update_xtime_cache(0); | 550 | update_xtime_cache(0); |
| 531 | total_sleep_time.tv_sec = 0; | 551 | total_sleep_time.tv_sec = 0; |
| 532 | total_sleep_time.tv_nsec = 0; | 552 | total_sleep_time.tv_nsec = 0; |
