Lines Matching +full:fixed +full:- +full:factor +full:- +full:clock
27 struct clocksource *clock; member
31 /* Number of clock cycles in one NTP interval. */
33 /* Number of clock shifted nano seconds in one NTP interval. */
40 /* Clock shifted nano seconds remainder not stored in xtime.tv_nsec. */
45 /* Shift conversion between clock shifted nano seconds and
48 /* NTP adjusted clock multiplier */
55 * timekeeper_setup_internals - Set up internals to use clocksource clock.
57 * @clock: Pointer to clocksource.
59 * Calculates a fixed cycle/nsec interval for a given clocksource/adjustment
64 static void timekeeper_setup_internals(struct clocksource *clock) in timekeeper_setup_internals() argument
69 timekeeper.clock = clock; in timekeeper_setup_internals()
70 clock->cycle_last = clock->read(clock); in timekeeper_setup_internals()
72 /* Do the ns -> cycle conversion first, using original mult */ in timekeeper_setup_internals()
74 tmp <<= clock->shift; in timekeeper_setup_internals()
76 tmp += clock->mult/2; in timekeeper_setup_internals()
77 do_div(tmp, clock->mult); in timekeeper_setup_internals()
84 /* Go back from cycles -> shifted ns */ in timekeeper_setup_internals()
85 timekeeper.xtime_interval = (u64) interval * clock->mult; in timekeeper_setup_internals()
86 timekeeper.xtime_remainder = ntpinterval - timekeeper.xtime_interval; in timekeeper_setup_internals()
88 ((u64) interval * clock->mult) >> clock->shift; in timekeeper_setup_internals()
91 timekeeper.shift = clock->shift; in timekeeper_setup_internals()
94 timekeeper.ntp_error_shift = NTP_SCALE_SHIFT - clock->shift; in timekeeper_setup_internals()
99 * to counteract clock drifting. in timekeeper_setup_internals()
101 timekeeper.mult = clock->mult; in timekeeper_setup_internals()
108 struct clocksource *clock; in timekeeping_get_ns() local
111 clock = timekeeper.clock; in timekeeping_get_ns()
112 cycle_now = clock->read(clock); in timekeeping_get_ns()
115 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; in timekeeping_get_ns()
125 struct clocksource *clock; in timekeeping_get_ns_raw() local
128 clock = timekeeper.clock; in timekeeping_get_ns_raw()
129 cycle_now = clock->read(clock); in timekeeping_get_ns_raw()
132 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; in timekeeping_get_ns_raw()
135 return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); in timekeeping_get_ns_raw()
139 * This read-write spinlock protects us from races in SMP while
157 * - wall_to_monotonic is no longer the boot time, getboottime must be
165 * The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock.
176 wall_to_monotonic.tv_sec -= leapsecond; in timekeeping_leap_insert()
177 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, in timekeeping_leap_insert()
182 * timekeeping_forward_now - update clock to the current time
184 * Forward the current clock to update its state since the last call to
185 * update_wall_time(). This is useful before significant clock changes,
191 struct clocksource *clock; in timekeeping_forward_now() local
194 clock = timekeeper.clock; in timekeeping_forward_now()
195 cycle_now = clock->read(clock); in timekeeping_forward_now()
196 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; in timekeeping_forward_now()
197 clock->cycle_last = cycle_now; in timekeeping_forward_now()
207 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); in timekeeping_forward_now()
212 * getnstimeofday - Returns the time of day in a timespec
258 * 32-bit architectures without CONFIG_KTIME_SCALAR. in ktime_get()
265 * ktime_get_ts - get the monotonic clock in timespec format
268 * The function calculates the monotonic clock from the realtime
269 * clock and the wall_to_monotonic offset and stores the result
290 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec, in ktime_get_ts()
291 ts->tv_nsec + tomono.tv_nsec + nsecs); in ktime_get_ts()
298 * getnstime_raw_and_real - get day and raw monotonic time in timespec format
339 * do_gettimeofday - Returns the time of day in a timeval
349 tv->tv_sec = now.tv_sec; in do_gettimeofday()
350 tv->tv_usec = now.tv_nsec/1000; in do_gettimeofday()
355 * do_settimeofday - Sets the time of day
365 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) in do_settimeofday()
366 return -EINVAL; in do_settimeofday()
372 ts_delta.tv_sec = tv->tv_sec - xtime.tv_sec; in do_settimeofday()
373 ts_delta.tv_nsec = tv->tv_nsec - xtime.tv_nsec; in do_settimeofday()
381 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, in do_settimeofday()
396 * timekeeping_inject_offset - Adds or subtracts from the current time.
405 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) in timekeeping_inject_offset()
406 return -EINVAL; in timekeeping_inject_offset()
418 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, in timekeeping_inject_offset()
431 * change_clocksource - Swaps clocksources if a new one is available
442 if (!new->enable || new->enable(new) == 0) { in change_clocksource()
443 old = timekeeper.clock; in change_clocksource()
445 if (old->disable) in change_clocksource()
446 old->disable(old); in change_clocksource()
452 * timekeeping_notify - Install a new clock source
453 * @clock: pointer to the clock source
455 * This function is called from clocksource.c after a new, better clock
458 void timekeeping_notify(struct clocksource *clock) in timekeeping_notify() argument
460 if (timekeeper.clock == clock) in timekeeping_notify()
462 stop_machine(change_clocksource, clock, NULL); in timekeeping_notify()
467 * ktime_get_real - get the real (wall-) time in ktime_t format
482 * getrawmonotonic - Returns the raw monotonic time in a timespec
485 * Returns the raw monotonic time (completely un-modified by ntp)
505 * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres
515 ret = timekeeper.clock->flags & CLOCK_SOURCE_VALID_FOR_HRES; in timekeeping_valid_for_hres()
523 * timekeeping_max_deferment - Returns max time the clocksource can be deferred
530 return timekeeper.clock->max_idle_ns; in timekeeping_max_deferment()
534 * read_persistent_clock - Return time from the persistent clock.
537 * Reads the time from the battery backed persistent clock.
540 * XXX - Do be sure to remove it once all arches implement it.
544 ts->tv_sec = 0; in read_persistent_clock()
545 ts->tv_nsec = 0; in read_persistent_clock()
549 * read_boot_clock - Return time of the system start.
555 * XXX - Do be sure to remove it once all arches implement it.
559 ts->tv_sec = 0; in read_boot_clock()
560 ts->tv_nsec = 0; in read_boot_clock()
564 * timekeeping_init - Initializes the clocksource and common timekeeping values
568 struct clocksource *clock; in timekeeping_init() local
579 clock = clocksource_default_clock(); in timekeeping_init()
580 if (clock->enable) in timekeeping_init()
581 clock->enable(clock); in timekeeping_init()
582 timekeeper_setup_internals(clock); in timekeeping_init()
593 -boot.tv_sec, -boot.tv_nsec); in timekeeping_init()
603 * __timekeeping_inject_sleeptime - Internal function to add sleep interval
624 * timekeeping_inject_sleeptime - Adds suspend interval to timeekeeping values
628 * because their RTC/persistent clock is only accessible when irqs are enabled.
638 /* Make sure we don't set the clock twice */ in timekeeping_inject_sleeptime()
650 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, in timekeeping_inject_sleeptime()
661 * timekeeping_resume - Resumes the generic timekeeping subsystem.
682 /* re-base the last cycle value */ in timekeeping_resume()
683 timekeeper.clock->cycle_last = timekeeper.clock->read(timekeeper.clock); in timekeeping_resume()
769 error2 = timekeeper.ntp_error >> (NTP_SCALE_SHIFT + 22 - 2 * SHIFT_HZ); in timekeeping_bigadjust()
779 tick_error -= timekeeper.xtime_interval >> 1; in timekeeping_bigadjust()
780 error = ((error - tick_error) >> look_ahead) + tick_error; in timekeeping_bigadjust()
786 error = -error; in timekeeping_bigadjust()
787 *interval = -*interval; in timekeeping_bigadjust()
788 *offset = -*offset; in timekeeping_bigadjust()
789 mult = -1; in timekeeping_bigadjust()
801 * this is optimized for the most common adjustments of -1,0,1,
813 * First we shift it down from NTP_SHIFT to clocksource->shifted nsecs. in timekeeping_adjust()
822 error = timekeeper.ntp_error >> (timekeeper.ntp_error_shift - 1); in timekeeping_adjust()
832 * XXX - In update_wall_time, we round up to the next in timekeeping_adjust()
845 } else if (error < -interval) { in timekeeping_adjust()
848 if (likely(error >= -interval)) { in timekeeping_adjust()
849 adj = -1; in timekeeping_adjust()
850 interval = -interval; in timekeeping_adjust()
851 offset = -offset; in timekeeping_adjust()
857 WARN_ONCE(timekeeper.clock->maxadj && in timekeeping_adjust()
858 (timekeeper.mult + adj > timekeeper.clock->mult + in timekeeping_adjust()
859 timekeeper.clock->maxadj), in timekeeping_adjust()
861 timekeeper.clock->name, (long)timekeeper.mult + adj, in timekeeping_adjust()
862 (long)timekeeper.clock->mult + in timekeeping_adjust()
863 timekeeper.clock->maxadj); in timekeeping_adjust()
883 * So offset stores the non-accumulated cycles. Thus the current in timekeeping_adjust()
886 * Now, even though we're adjusting the clock frequency, we have in timekeeping_adjust()
907 * xtime_nsec_2 = xtime_nsec_1 - offset in timekeeping_adjust()
909 * xtime_nsec -= offset in timekeeping_adjust()
911 * XXX - TODO: Doc ntp_error calculation. in timekeeping_adjust()
915 timekeeper.xtime_nsec -= offset; in timekeeping_adjust()
916 timekeeper.ntp_error -= (interval - offset) << in timekeeping_adjust()
922 * logarithmic_accumulation - shifted accumulation of cycles
940 offset -= timekeeper.cycle_interval << shift; in logarithmic_accumulation()
941 timekeeper.clock->cycle_last += timekeeper.cycle_interval << shift; in logarithmic_accumulation()
945 timekeeper.xtime_nsec -= nsecps; in logarithmic_accumulation()
960 /* Accumulate error between NTP and clock interval */ in logarithmic_accumulation()
962 timekeeper.ntp_error -= in logarithmic_accumulation()
971 * update_wall_time - Uses the current clocksource to increment the wall time
977 struct clocksource *clock; in update_wall_time() local
985 clock = timekeeper.clock; in update_wall_time()
990 offset = (clock->read(clock) - clock->cycle_last) & clock->mask; in update_wall_time()
1002 shift = ilog2(offset) - ilog2(timekeeper.cycle_interval); in update_wall_time()
1005 maxshift = (8*sizeof(tick_length) - (ilog2(tick_length)+1)) - 1; in update_wall_time()
1010 shift--; in update_wall_time()
1013 /* correct the clock when NTP error is too big */ in update_wall_time()
1021 * its possible the required corrective factor to xtime_nsec could in update_wall_time()
1033 s64 neg = -(s64)timekeeper.xtime_nsec; in update_wall_time()
1044 timekeeper.xtime_nsec -= (s64) xtime.tv_nsec << timekeeper.shift; in update_wall_time()
1053 xtime.tv_nsec -= NSEC_PER_SEC; in update_wall_time()
1059 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, in update_wall_time()
1064 * getboottime - Return the real time of system boot.
1067 * Returns the wall-time of boot in a timespec.
1071 * basically means that however wrong your real time clock is at boot time,
1081 set_normalized_timespec(ts, -boottime.tv_sec, -boottime.tv_nsec); in getboottime()
1087 * get_monotonic_boottime - Returns monotonic time since boot
1112 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec, in get_monotonic_boottime()
1113 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs); in get_monotonic_boottime()
1118 * ktime_get_boottime - Returns monotonic time since boot in a ktime
1135 * monotonic_to_bootbased - Convert the monotonic time to boot based.
1188 * The 64-bit jiffies value is not atomic - you MUST NOT read it
1200 * get_xtime_and_monotonic_and_sleep_offset() - get xtime, wall_to_monotonic,
1220 * ktime_get_monotonic_offset() - get wall_to_monotonic in ktime_t format
1235 * xtime_update() - advances the timekeeping infrastructure