diff options
Diffstat (limited to 'kernel/time/clocksource.c')
| -rw-r--r-- | kernel/time/clocksource.c | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index b79f39bda7e1..4892352f0e49 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c | |||
| @@ -34,82 +34,6 @@ | |||
| 34 | #include "tick-internal.h" | 34 | #include "tick-internal.h" |
| 35 | #include "timekeeping_internal.h" | 35 | #include "timekeeping_internal.h" |
| 36 | 36 | ||
| 37 | void timecounter_init(struct timecounter *tc, | ||
| 38 | const struct cyclecounter *cc, | ||
| 39 | u64 start_tstamp) | ||
| 40 | { | ||
| 41 | tc->cc = cc; | ||
| 42 | tc->cycle_last = cc->read(cc); | ||
| 43 | tc->nsec = start_tstamp; | ||
| 44 | } | ||
| 45 | EXPORT_SYMBOL_GPL(timecounter_init); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * timecounter_read_delta - get nanoseconds since last call of this function | ||
| 49 | * @tc: Pointer to time counter | ||
| 50 | * | ||
| 51 | * When the underlying cycle counter runs over, this will be handled | ||
| 52 | * correctly as long as it does not run over more than once between | ||
| 53 | * calls. | ||
| 54 | * | ||
| 55 | * The first call to this function for a new time counter initializes | ||
| 56 | * the time tracking and returns an undefined result. | ||
| 57 | */ | ||
| 58 | static u64 timecounter_read_delta(struct timecounter *tc) | ||
| 59 | { | ||
| 60 | cycle_t cycle_now, cycle_delta; | ||
| 61 | u64 ns_offset; | ||
| 62 | |||
| 63 | /* read cycle counter: */ | ||
| 64 | cycle_now = tc->cc->read(tc->cc); | ||
| 65 | |||
| 66 | /* calculate the delta since the last timecounter_read_delta(): */ | ||
| 67 | cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask; | ||
| 68 | |||
| 69 | /* convert to nanoseconds: */ | ||
| 70 | ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta); | ||
| 71 | |||
| 72 | /* update time stamp of timecounter_read_delta() call: */ | ||
| 73 | tc->cycle_last = cycle_now; | ||
| 74 | |||
| 75 | return ns_offset; | ||
| 76 | } | ||
| 77 | |||
| 78 | u64 timecounter_read(struct timecounter *tc) | ||
| 79 | { | ||
| 80 | u64 nsec; | ||
| 81 | |||
| 82 | /* increment time by nanoseconds since last call */ | ||
| 83 | nsec = timecounter_read_delta(tc); | ||
| 84 | nsec += tc->nsec; | ||
| 85 | tc->nsec = nsec; | ||
| 86 | |||
| 87 | return nsec; | ||
| 88 | } | ||
| 89 | EXPORT_SYMBOL_GPL(timecounter_read); | ||
| 90 | |||
| 91 | u64 timecounter_cyc2time(struct timecounter *tc, | ||
| 92 | cycle_t cycle_tstamp) | ||
| 93 | { | ||
| 94 | u64 cycle_delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask; | ||
| 95 | u64 nsec; | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Instead of always treating cycle_tstamp as more recent | ||
| 99 | * than tc->cycle_last, detect when it is too far in the | ||
| 100 | * future and treat it as old time stamp instead. | ||
| 101 | */ | ||
| 102 | if (cycle_delta > tc->cc->mask / 2) { | ||
| 103 | cycle_delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask; | ||
| 104 | nsec = tc->nsec - cyclecounter_cyc2ns(tc->cc, cycle_delta); | ||
| 105 | } else { | ||
| 106 | nsec = cyclecounter_cyc2ns(tc->cc, cycle_delta) + tc->nsec; | ||
| 107 | } | ||
| 108 | |||
| 109 | return nsec; | ||
| 110 | } | ||
| 111 | EXPORT_SYMBOL_GPL(timecounter_cyc2time); | ||
| 112 | |||
| 113 | /** | 37 | /** |
| 114 | * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks | 38 | * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks |
| 115 | * @mult: pointer to mult variable | 39 | * @mult: pointer to mult variable |
