diff options
| author | Matt Helsley <matthltc@us.ibm.com> | 2005-12-12 03:37:09 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-12-12 11:57:42 -0500 |
| commit | 64123fd42c7a1e4ebf6acd2399c98caddc7e0c26 (patch) | |
| tree | d6b1794fa33287d145a44ab55bc2e2ef65ebf248 /kernel/time.c | |
| parent | 894ec8707ced240b96dc45944790fb35d9a6b03c (diff) | |
[PATCH] Add getnstimestamp function
There are several functions that might seem appropriate for a timestamp:
get_cycles()
current_kernel_time()
do_gettimeofday()
<read jiffies/jiffies_64>
Each has problems with combinations of SMP-safety, low resolution, and
monotonicity. This patch adds a new function that returns a monotonic SMP-safe
timestamp with nanosecond resolution where available.
Changes:
Split timestamp into separate patch
Moved to kernel/time.c
Renamed to getnstimestamp
Fixed unintended-pointer-arithmetic bug
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/time.c')
| -rw-r--r-- | kernel/time.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/kernel/time.c b/kernel/time.c index 245d595a13..b94bfa8c03 100644 --- a/kernel/time.c +++ b/kernel/time.c | |||
| @@ -561,6 +561,28 @@ void getnstimeofday(struct timespec *tv) | |||
| 561 | EXPORT_SYMBOL_GPL(getnstimeofday); | 561 | EXPORT_SYMBOL_GPL(getnstimeofday); |
| 562 | #endif | 562 | #endif |
| 563 | 563 | ||
| 564 | void getnstimestamp(struct timespec *ts) | ||
| 565 | { | ||
| 566 | unsigned int seq; | ||
| 567 | struct timespec wall2mono; | ||
| 568 | |||
| 569 | /* synchronize with settimeofday() changes */ | ||
| 570 | do { | ||
| 571 | seq = read_seqbegin(&xtime_lock); | ||
| 572 | getnstimeofday(ts); | ||
| 573 | wall2mono = wall_to_monotonic; | ||
| 574 | } while(unlikely(read_seqretry(&xtime_lock, seq))); | ||
| 575 | |||
| 576 | /* adjust to monotonicaly-increasing values */ | ||
| 577 | ts->tv_sec += wall2mono.tv_sec; | ||
| 578 | ts->tv_nsec += wall2mono.tv_nsec; | ||
| 579 | while (unlikely(ts->tv_nsec >= NSEC_PER_SEC)) { | ||
| 580 | ts->tv_nsec -= NSEC_PER_SEC; | ||
| 581 | ts->tv_sec++; | ||
| 582 | } | ||
| 583 | } | ||
| 584 | EXPORT_SYMBOL_GPL(getnstimestamp); | ||
| 585 | |||
| 564 | #if (BITS_PER_LONG < 64) | 586 | #if (BITS_PER_LONG < 64) |
| 565 | u64 get_jiffies_64(void) | 587 | u64 get_jiffies_64(void) |
| 566 | { | 588 | { |
