Lines Matching +full:clock +full:- +full:accuracy
38 tc->cc = cc; in timecounter_init()
39 tc->cycle_last = cc->read(cc); in timecounter_init()
40 tc->nsec = start_tstamp; in timecounter_init()
45 * timecounter_read_delta - get nanoseconds since last call of this function
61 cycle_now = tc->cc->read(tc->cc); in timecounter_read_delta()
64 cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask; in timecounter_read_delta()
67 ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta); in timecounter_read_delta()
70 tc->cycle_last = cycle_now; in timecounter_read_delta()
81 nsec += tc->nsec; in timecounter_read()
82 tc->nsec = nsec; in timecounter_read()
91 u64 cycle_delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask; in timecounter_cyc2time()
96 * than tc->cycle_last, detect when it is too far in the in timecounter_cyc2time()
99 if (cycle_delta > tc->cc->mask / 2) { in timecounter_cyc2time()
100 cycle_delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask; in timecounter_cyc2time()
101 nsec = tc->nsec - cyclecounter_cyc2ns(tc->cc, cycle_delta); in timecounter_cyc2time()
103 nsec = cyclecounter_cyc2ns(tc->cc, cycle_delta) + tc->nsec; in timecounter_cyc2time()
111 * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
121 * @to and @from are frequency values in HZ. For clock sources @to is
122 * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock
130 * reduce the conversion accuracy by chosing smaller mult and shift
146 sftacc--; in clocks_calc_mult_shift()
151 * accuracy and fits the maxsec conversion range: in clocks_calc_mult_shift()
153 for (sft = 32; sft > 0; sft--) { in clocks_calc_mult_shift()
164 /*[Clocksource internal variables]---------
172 * Name of the user-specified clocksource.
204 * watchdog_list will find the unstable clock again. in clocksource_watchdog_work()
211 cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); in __clocksource_unstable()
212 cs->flags |= CLOCK_SOURCE_UNSTABLE; in __clocksource_unstable()
220 cs->name, delta); in clocksource_unstable()
225 * clocksource_mark_unstable - mark clocksource unstable via watchdog
238 if (!(cs->flags & CLOCK_SOURCE_UNSTABLE)) { in clocksource_mark_unstable()
239 if (list_empty(&cs->wd_list)) in clocksource_mark_unstable()
240 list_add(&cs->wd_list, &watchdog_list); in clocksource_mark_unstable()
262 if (cs->flags & CLOCK_SOURCE_UNSTABLE) { in clocksource_watchdog()
269 csnow = cs->read(cs); in clocksource_watchdog()
270 wdnow = watchdog->read(watchdog); in clocksource_watchdog()
274 if (!(cs->flags & CLOCK_SOURCE_WATCHDOG) || in clocksource_watchdog()
276 cs->flags |= CLOCK_SOURCE_WATCHDOG; in clocksource_watchdog()
277 cs->wd_last = wdnow; in clocksource_watchdog()
278 cs->cs_last = csnow; in clocksource_watchdog()
282 wd_nsec = clocksource_cyc2ns((wdnow - cs->wd_last) & watchdog->mask, in clocksource_watchdog()
283 watchdog->mult, watchdog->shift); in clocksource_watchdog()
285 cs_nsec = clocksource_cyc2ns((csnow - cs->cs_last) & in clocksource_watchdog()
286 cs->mask, cs->mult, cs->shift); in clocksource_watchdog()
287 cs->cs_last = csnow; in clocksource_watchdog()
288 cs->wd_last = wdnow; in clocksource_watchdog()
294 if ((abs(cs_nsec - wd_nsec) > WATCHDOG_THRESHOLD)) { in clocksource_watchdog()
295 clocksource_unstable(cs, cs_nsec - wd_nsec); in clocksource_watchdog()
299 if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && in clocksource_watchdog()
300 (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) && in clocksource_watchdog()
301 (watchdog->flags & CLOCK_SOURCE_IS_CONTINUOUS)) { in clocksource_watchdog()
302 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_watchdog()
304 * We just marked the clocksource as highres-capable, in clocksource_watchdog()
306 * transition into high-res mode: in clocksource_watchdog()
356 cs->flags &= ~CLOCK_SOURCE_WATCHDOG; in clocksource_reset_watchdog()
369 if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { in clocksource_enqueue_watchdog()
371 list_add(&cs->wd_list, &watchdog_list); in clocksource_enqueue_watchdog()
372 cs->flags &= ~CLOCK_SOURCE_WATCHDOG; in clocksource_enqueue_watchdog()
375 if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) in clocksource_enqueue_watchdog()
376 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_enqueue_watchdog()
378 if (!watchdog || cs->rating > watchdog->rating) { in clocksource_enqueue_watchdog()
395 if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { in clocksource_dequeue_watchdog()
397 list_del_init(&cs->wd_list); in clocksource_dequeue_watchdog()
404 if (tmp == cs || tmp->flags & CLOCK_SOURCE_MUST_VERIFY) in clocksource_dequeue_watchdog()
406 if (!watchdog || tmp->rating > watchdog->rating) in clocksource_dequeue_watchdog()
410 cs->flags &= ~CLOCK_SOURCE_WATCHDOG; in clocksource_dequeue_watchdog()
425 if (cs->flags & CLOCK_SOURCE_UNSTABLE) { in clocksource_watchdog_kthread()
426 list_del_init(&cs->wd_list); in clocksource_watchdog_kthread()
427 list_add(&cs->wd_list, &unstable); in clocksource_watchdog_kthread()
435 list_del_init(&cs->wd_list); in clocksource_watchdog_kthread()
446 if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) in clocksource_enqueue_watchdog()
447 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_enqueue_watchdog()
457 * clocksource_suspend - suspend the clocksource(s)
464 if (cs->suspend) in clocksource_suspend()
465 cs->suspend(cs); in clocksource_suspend()
469 * clocksource_resume - resume the clocksource(s)
476 if (cs->resume) in clocksource_resume()
477 cs->resume(cs); in clocksource_resume()
483 * clocksource_touch_watchdog - Update watchdog
495 * clocksource_max_adjustment- Returns max adjustment amount
505 ret = (u64)cs->mult * 11; in clocksource_max_adjustment()
511 * clocksource_max_deferment - Returns max time the clocksource can be deferred
521 * cyc2ns function without overflowing a 64-bit signed result. The in clocksource_max_deferment()
522 * maximum number of cycles is equal to ULLONG_MAX/(cs->mult+cs->maxadj) in clocksource_max_deferment()
524 * max_cycles < (2^63)/(cs->mult + cs->maxadj) in clocksource_max_deferment()
525 * max_cycles < 2^(log2((2^63)/(cs->mult + cs->maxadj))) in clocksource_max_deferment()
526 * max_cycles < 2^(log2(2^63) - log2(cs->mult + cs->maxadj)) in clocksource_max_deferment()
527 * max_cycles < 2^(63 - log2(cs->mult + cs->maxadj)) in clocksource_max_deferment()
528 * max_cycles < 1 << (63 - log2(cs->mult + cs->maxadj)) in clocksource_max_deferment()
533 max_cycles = 1ULL << (63 - (ilog2(cs->mult + cs->maxadj) + 1)); in clocksource_max_deferment()
537 * determined by the minimum of max_cycles and cs->mask. in clocksource_max_deferment()
541 max_cycles = min_t(u64, max_cycles, (u64) cs->mask); in clocksource_max_deferment()
542 max_nsecs = clocksource_cyc2ns(max_cycles, cs->mult - cs->maxadj, in clocksource_max_deferment()
543 cs->shift); in clocksource_max_deferment()
551 return max_nsecs - (max_nsecs >> 3); in clocksource_max_deferment()
557 * clocksource_select - Select the best clocksource available
574 if (strcmp(cs->name, override_name) != 0) in clocksource_select()
577 * Check to make sure we don't switch to a non-highres in clocksource_select()
581 if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && in clocksource_select()
586 "HRT/NOHZ mode\n", cs->name); in clocksource_select()
594 printk(KERN_INFO "Switching to clocksource %s\n", best->name); in clocksource_select()
607 * clocksource_done_booting - Called near the end of core bootup
622 * Run the watchdog first to eliminate unstable clock sources in clocksource_done_booting()
643 if (tmp->rating >= cs->rating) in clocksource_enqueue()
644 entry = &tmp->list; in clocksource_enqueue()
645 list_add(&cs->list, entry); in clocksource_enqueue()
649 * __clocksource_updatefreq_scale - Used update clocksource with new freq
654 * This should only be called from the clocksource->enable() method.
672 sec = (cs->mask - (cs->mask >> 3)); in __clocksource_updatefreq_scale()
677 else if (sec > 600 && cs->mask > UINT_MAX) in __clocksource_updatefreq_scale()
680 clocks_calc_mult_shift(&cs->mult, &cs->shift, freq, in __clocksource_updatefreq_scale()
688 cs->maxadj = clocksource_max_adjustment(cs); in __clocksource_updatefreq_scale()
689 while ((cs->mult + cs->maxadj < cs->mult) in __clocksource_updatefreq_scale()
690 || (cs->mult - cs->maxadj > cs->mult)) { in __clocksource_updatefreq_scale()
691 cs->mult >>= 1; in __clocksource_updatefreq_scale()
692 cs->shift--; in __clocksource_updatefreq_scale()
693 cs->maxadj = clocksource_max_adjustment(cs); in __clocksource_updatefreq_scale()
696 cs->max_idle_ns = clocksource_max_deferment(cs); in __clocksource_updatefreq_scale()
701 * __clocksource_register_scale - Used to install new clocksources
706 * Returns -EBUSY if registration fails, zero otherwise.
729 * clocksource_register - Used to install new clocksources
732 * Returns -EBUSY if registration fails, zero otherwise.
737 cs->maxadj = clocksource_max_adjustment(cs); in clocksource_register()
738 WARN_ONCE(cs->mult + cs->maxadj < cs->mult, in clocksource_register()
740 cs->name); in clocksource_register()
743 cs->max_idle_ns = clocksource_max_deferment(cs); in clocksource_register()
756 list_del(&cs->list); in __clocksource_change_rating()
757 cs->rating = rating; in __clocksource_change_rating()
763 * clocksource_change_rating - Change the rating of a registered clocksource
776 * clocksource_unregister - remove a registered clocksource
783 list_del(&cs->list); in clocksource_unregister()
791 * sysfs_show_current_clocksources - sysfs interface for current clocksource
805 count = snprintf(buf, PAGE_SIZE, "%s\n", curr_clocksource->name); in sysfs_show_current_clocksources()
812 * sysfs_override_clocksource - interface for manually overriding clocksource
829 return -EINVAL; in sysfs_override_clocksource()
832 if (buf[count-1] == '\n') in sysfs_override_clocksource()
833 count--; in sysfs_override_clocksource()
848 * sysfs_show_available_clocksources - sysfs interface for listing clocksource
866 * Don't show non-HRES clocksource if the tick code is in sysfs_show_available_clocksources()
870 (src->flags & CLOCK_SOURCE_VALID_FOR_HRES)) in sysfs_show_available_clocksources()
872 max((ssize_t)PAGE_SIZE - count, (ssize_t)0), in sysfs_show_available_clocksources()
873 "%s ", src->name); in sysfs_show_available_clocksources()
878 max((ssize_t)PAGE_SIZE - count, (ssize_t)0), "\n"); in sysfs_show_available_clocksources()
923 * boot_override_clocksource - boot clock override
941 * boot_override_clock - Compatibility layer for deprecated boot option
944 * DEPRECATED! Takes a clock= boot argument and uses it
950 printk("Warning: clock=pmtmr is deprecated. " in boot_override_clock()
954 printk("Warning! clock= boot option is deprecated. " in boot_override_clock()
959 __setup("clock=", boot_override_clock);