Lines Matching full:cs

23 static noinline u64 cycles_to_nsec_safe(struct clocksource *cs, u64 start, u64 end)  in cycles_to_nsec_safe()  argument
25 u64 delta = clocksource_delta(end, start, cs->mask); in cycles_to_nsec_safe()
27 if (likely(delta < cs->max_cycles)) in cycles_to_nsec_safe()
28 return clocksource_cyc2ns(delta, cs->mult, cs->shift); in cycles_to_nsec_safe()
30 return mul_u64_u32_shr(delta, cs->mult, cs->shift); in cycles_to_nsec_safe()
123 * a lower bound for cs->uncertainty_margin values when registering clocks.
142 * Default for maximum permissible skew when cs->uncertainty_margin is
143 * not specified, and the lower bound even when cs->uncertainty_margin
145 * clocks with unspecifed cs->uncertainty_margin, so this macro is used
174 static void __clocksource_change_rating(struct clocksource *cs, int rating);
194 static void __clocksource_unstable(struct clocksource *cs) in __clocksource_unstable() argument
196 cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); in __clocksource_unstable()
197 cs->flags |= CLOCK_SOURCE_UNSTABLE; in __clocksource_unstable()
203 if (list_empty(&cs->list)) { in __clocksource_unstable()
204 cs->rating = 0; in __clocksource_unstable()
208 if (cs->mark_unstable) in __clocksource_unstable()
209 cs->mark_unstable(cs); in __clocksource_unstable()
218 * @cs: clocksource to be marked unstable
223 void clocksource_mark_unstable(struct clocksource *cs) in clocksource_mark_unstable() argument
228 if (!(cs->flags & CLOCK_SOURCE_UNSTABLE)) { in clocksource_mark_unstable()
229 if (!list_empty(&cs->list) && list_empty(&cs->wd_list)) in clocksource_mark_unstable()
230 list_add(&cs->wd_list, &watchdog_list); in clocksource_mark_unstable()
231 __clocksource_unstable(cs); in clocksource_mark_unstable()
245 static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow) in cs_watchdog_read() argument
256 *csnow = cs->read(cs); in cs_watchdog_read()
262 if (wd_delay <= md + cs->uncertainty_margin) { in cs_watchdog_read()
285 smp_processor_id(), cs->name, wd_delay, WATCHDOG_MAX_SKEW, wd_seq_delay, nretries, cs->name); in cs_watchdog_read()
292 cs->name, wd_delay); in cs_watchdog_read()
351 struct clocksource *cs = (struct clocksource *)csin; in clocksource_verify_one_cpu() local
353 csnow_mid = cs->read(cs); in clocksource_verify_one_cpu()
356 void clocksource_verify_percpu(struct clocksource *cs) in clocksource_verify_percpu() argument
373 pr_warn("Not enough CPUs to check clocksource '%s'.\n", cs->name); in clocksource_verify_percpu()
377 …pr_warn("Checking clocksource %s synchronization from CPU %d to CPUs %*pbl.\n", cs->name, testcpu,… in clocksource_verify_percpu()
381 csnow_begin = cs->read(cs); in clocksource_verify_percpu()
382 smp_call_function_single(cpu, clocksource_verify_one_cpu, cs, 1); in clocksource_verify_percpu()
383 csnow_end = cs->read(cs); in clocksource_verify_percpu()
384 delta = (s64)((csnow_mid - csnow_begin) & cs->mask); in clocksource_verify_percpu()
387 delta = (csnow_end - csnow_mid) & cs->mask; in clocksource_verify_percpu()
390 cs_nsec = cycles_to_nsec_safe(cs, csnow_begin, csnow_end); in clocksource_verify_percpu()
400 cpumask_pr_args(&cpus_ahead), testcpu, cs->name); in clocksource_verify_percpu()
403 cpumask_pr_args(&cpus_behind), testcpu, cs->name); in clocksource_verify_percpu()
406 testcpu, cs_nsec_min, cs_nsec_max, cs->name); in clocksource_verify_percpu()
412 struct clocksource *cs; in clocksource_reset_watchdog() local
414 list_for_each_entry(cs, &watchdog_list, wd_list) in clocksource_reset_watchdog()
415 cs->flags &= ~CLOCK_SOURCE_WATCHDOG; in clocksource_reset_watchdog()
424 struct clocksource *cs; in clocksource_watchdog() local
435 list_for_each_entry(cs, &watchdog_list, wd_list) { in clocksource_watchdog()
438 if (cs->flags & CLOCK_SOURCE_UNSTABLE) { in clocksource_watchdog()
444 read_ret = cs_watchdog_read(cs, &csnow, &wdnow); in clocksource_watchdog()
448 __clocksource_unstable(cs); in clocksource_watchdog()
462 * cs->last could keep unchanged for 5 minutes, reset in clocksource_watchdog()
471 if (!(cs->flags & CLOCK_SOURCE_WATCHDOG) || in clocksource_watchdog()
473 cs->flags |= CLOCK_SOURCE_WATCHDOG; in clocksource_watchdog()
474 cs->wd_last = wdnow; in clocksource_watchdog()
475 cs->cs_last = csnow; in clocksource_watchdog()
479 wd_nsec = cycles_to_nsec_safe(watchdog, cs->wd_last, wdnow); in clocksource_watchdog()
480 cs_nsec = cycles_to_nsec_safe(cs, cs->cs_last, csnow); in clocksource_watchdog()
481 wdlast = cs->wd_last; /* save these in case we print them */ in clocksource_watchdog()
482 cslast = cs->cs_last; in clocksource_watchdog()
483 cs->cs_last = csnow; in clocksource_watchdog()
484 cs->wd_last = wdnow; in clocksource_watchdog()
511 md = cs->uncertainty_margin + watchdog->uncertainty_margin; in clocksource_watchdog()
518 smp_processor_id(), cs->name); in clocksource_watchdog()
522 cs->name, cs_nsec, csnow, cslast, cs->mask); in clocksource_watchdog()
526 cs->name, cs_nsec - wd_nsec, cs_wd_msec, watchdog->name, wd_nsec, wd_msec); in clocksource_watchdog()
527 if (curr_clocksource == cs) in clocksource_watchdog()
528 pr_warn(" '%s' is current clocksource.\n", cs->name); in clocksource_watchdog()
530 … '%s' (not '%s') is current clocksource.\n", curr_clocksource->name, cs->name); in clocksource_watchdog()
533 __clocksource_unstable(cs); in clocksource_watchdog()
537 if (cs == curr_clocksource && cs->tick_stable) in clocksource_watchdog()
538 cs->tick_stable(cs); in clocksource_watchdog()
540 if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && in clocksource_watchdog()
541 (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) && in clocksource_watchdog()
544 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_watchdog()
561 if (cs != curr_clocksource) { in clocksource_watchdog()
562 cs->flags |= CLOCK_SOURCE_RESELECT; in clocksource_watchdog()
620 static void clocksource_enqueue_watchdog(struct clocksource *cs) in clocksource_enqueue_watchdog() argument
622 INIT_LIST_HEAD(&cs->wd_list); in clocksource_enqueue_watchdog()
624 if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { in clocksource_enqueue_watchdog()
625 /* cs is a clocksource to be watched. */ in clocksource_enqueue_watchdog()
626 list_add(&cs->wd_list, &watchdog_list); in clocksource_enqueue_watchdog()
627 cs->flags &= ~CLOCK_SOURCE_WATCHDOG; in clocksource_enqueue_watchdog()
629 /* cs is a watchdog. */ in clocksource_enqueue_watchdog()
630 if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) in clocksource_enqueue_watchdog()
631 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_enqueue_watchdog()
637 struct clocksource *cs, *old_wd; in clocksource_select_watchdog() local
646 list_for_each_entry(cs, &clocksource_list, list) { in clocksource_select_watchdog()
647 /* cs is a clocksource to be watched. */ in clocksource_select_watchdog()
648 if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) in clocksource_select_watchdog()
652 if (fallback && cs == old_wd) in clocksource_select_watchdog()
656 if (!watchdog || cs->rating > watchdog->rating) in clocksource_select_watchdog()
657 watchdog = cs; in clocksource_select_watchdog()
672 static void clocksource_dequeue_watchdog(struct clocksource *cs) in clocksource_dequeue_watchdog() argument
674 if (cs != watchdog) { in clocksource_dequeue_watchdog()
675 if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { in clocksource_dequeue_watchdog()
676 /* cs is a watched clocksource. */ in clocksource_dequeue_watchdog()
677 list_del_init(&cs->wd_list); in clocksource_dequeue_watchdog()
686 struct clocksource *cs, *tmp; in __clocksource_watchdog_kthread() local
697 list_for_each_entry_safe(cs, tmp, &watchdog_list, wd_list) { in __clocksource_watchdog_kthread()
698 if (cs->flags & CLOCK_SOURCE_UNSTABLE) { in __clocksource_watchdog_kthread()
699 list_del_init(&cs->wd_list); in __clocksource_watchdog_kthread()
700 __clocksource_change_rating(cs, 0); in __clocksource_watchdog_kthread()
703 if (cs->flags & CLOCK_SOURCE_RESELECT) { in __clocksource_watchdog_kthread()
704 cs->flags &= ~CLOCK_SOURCE_RESELECT; in __clocksource_watchdog_kthread()
724 static bool clocksource_is_watchdog(struct clocksource *cs) in clocksource_is_watchdog() argument
726 return cs == watchdog; in clocksource_is_watchdog()
731 static void clocksource_enqueue_watchdog(struct clocksource *cs) in clocksource_enqueue_watchdog() argument
733 if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) in clocksource_enqueue_watchdog()
734 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; in clocksource_enqueue_watchdog()
738 static inline void clocksource_dequeue_watchdog(struct clocksource *cs) { } in clocksource_dequeue_watchdog() argument
741 static bool clocksource_is_watchdog(struct clocksource *cs) { return false; } in clocksource_is_watchdog() argument
742 void clocksource_mark_unstable(struct clocksource *cs) { } in clocksource_mark_unstable() argument
749 static bool clocksource_is_suspend(struct clocksource *cs) in clocksource_is_suspend() argument
751 return cs == suspend_clocksource; in clocksource_is_suspend()
754 static void __clocksource_suspend_select(struct clocksource *cs) in __clocksource_suspend_select() argument
759 if (!(cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP)) in __clocksource_suspend_select()
767 if (cs->suspend || cs->resume) { in __clocksource_suspend_select()
769 cs->name); in __clocksource_suspend_select()
773 if (!suspend_clocksource || cs->rating > suspend_clocksource->rating) in __clocksource_suspend_select()
774 suspend_clocksource = cs; in __clocksource_suspend_select()
783 struct clocksource *cs, *old_suspend; in clocksource_suspend_select() local
789 list_for_each_entry(cs, &clocksource_list, list) { in clocksource_suspend_select()
791 if (fallback && cs == old_suspend) in clocksource_suspend_select()
794 __clocksource_suspend_select(cs); in clocksource_suspend_select()
800 * @cs: current clocksource from timekeeping
811 void clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles) in clocksource_start_suspend_timing() argument
821 if (clocksource_is_suspend(cs)) { in clocksource_start_suspend_timing()
837 * @cs: current clocksource from timekeeping
849 u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 cycle_now) in clocksource_stop_suspend_timing() argument
861 if (clocksource_is_suspend(cs)) in clocksource_stop_suspend_timing()
873 if (!clocksource_is_suspend(cs) && suspend_clocksource->disable) in clocksource_stop_suspend_timing()
884 struct clocksource *cs; in clocksource_suspend() local
886 list_for_each_entry_reverse(cs, &clocksource_list, list) in clocksource_suspend()
887 if (cs->suspend) in clocksource_suspend()
888 cs->suspend(cs); in clocksource_suspend()
896 struct clocksource *cs; in clocksource_resume() local
898 list_for_each_entry(cs, &clocksource_list, list) in clocksource_resume()
899 if (cs->resume) in clocksource_resume()
900 cs->resume(cs); in clocksource_resume()
919 * @cs: Pointer to clocksource
922 static u32 clocksource_max_adjustment(struct clocksource *cs) in clocksource_max_adjustment() argument
928 ret = (u64)cs->mult * 11; in clocksource_max_adjustment()
980 * @cs: Pointer to clocksource to be updated
983 static inline void clocksource_update_max_deferment(struct clocksource *cs) in clocksource_update_max_deferment() argument
985 cs->max_idle_ns = clocks_calc_max_nsecs(cs->mult, cs->shift, in clocksource_update_max_deferment()
986 cs->maxadj, cs->mask, in clocksource_update_max_deferment()
987 &cs->max_cycles); in clocksource_update_max_deferment()
992 struct clocksource *cs; in clocksource_find_best() local
1002 list_for_each_entry(cs, &clocksource_list, list) { in clocksource_find_best()
1003 if (skipcur && cs == curr_clocksource) in clocksource_find_best()
1005 if (oneshot && !(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES)) in clocksource_find_best()
1007 return cs; in clocksource_find_best()
1015 struct clocksource *best, *cs; in __clocksource_select() local
1026 list_for_each_entry(cs, &clocksource_list, list) { in __clocksource_select()
1027 if (skipcur && cs == curr_clocksource) in __clocksource_select()
1029 if (strcmp(cs->name, override_name) != 0) in __clocksource_select()
1036 if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && oneshot) { in __clocksource_select()
1038 if (cs->flags & CLOCK_SOURCE_UNSTABLE) { in __clocksource_select()
1040 cs->name); in __clocksource_select()
1048 cs->name); in __clocksource_select()
1052 best = cs; in __clocksource_select()
1106 static void clocksource_enqueue(struct clocksource *cs) in clocksource_enqueue() argument
1113 if (tmp->rating < cs->rating) in clocksource_enqueue()
1117 list_add(&cs->list, entry); in clocksource_enqueue()
1122 * @cs: clocksource to be registered
1132 void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq) in __clocksource_update_freq_scale() argument
1150 sec = cs->mask; in __clocksource_update_freq_scale()
1155 else if (sec > 600 && cs->mask > UINT_MAX) in __clocksource_update_freq_scale()
1158 clocks_calc_mult_shift(&cs->mult, &cs->shift, freq, in __clocksource_update_freq_scale()
1177 if (scale && freq && !cs->uncertainty_margin) { in __clocksource_update_freq_scale()
1178 cs->uncertainty_margin = NSEC_PER_SEC / (scale * freq); in __clocksource_update_freq_scale()
1179 if (cs->uncertainty_margin < 2 * WATCHDOG_MAX_SKEW) in __clocksource_update_freq_scale()
1180 cs->uncertainty_margin = 2 * WATCHDOG_MAX_SKEW; in __clocksource_update_freq_scale()
1181 } else if (!cs->uncertainty_margin) { in __clocksource_update_freq_scale()
1182 cs->uncertainty_margin = WATCHDOG_THRESHOLD; in __clocksource_update_freq_scale()
1184 WARN_ON_ONCE(cs->uncertainty_margin < 2 * WATCHDOG_MAX_SKEW); in __clocksource_update_freq_scale()
1190 cs->maxadj = clocksource_max_adjustment(cs); in __clocksource_update_freq_scale()
1191 while (freq && ((cs->mult + cs->maxadj < cs->mult) in __clocksource_update_freq_scale()
1192 || (cs->mult - cs->maxadj > cs->mult))) { in __clocksource_update_freq_scale()
1193 cs->mult >>= 1; in __clocksource_update_freq_scale()
1194 cs->shift--; in __clocksource_update_freq_scale()
1195 cs->maxadj = clocksource_max_adjustment(cs); in __clocksource_update_freq_scale()
1202 WARN_ONCE(cs->mult + cs->maxadj < cs->mult, in __clocksource_update_freq_scale()
1204 cs->name); in __clocksource_update_freq_scale()
1206 clocksource_update_max_deferment(cs); in __clocksource_update_freq_scale()
1209 cs->name, cs->mask, cs->max_cycles, cs->max_idle_ns); in __clocksource_update_freq_scale()
1215 * @cs: clocksource to be registered
1224 int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) in __clocksource_register_scale() argument
1228 clocksource_arch_init(cs); in __clocksource_register_scale()
1230 if (WARN_ON_ONCE((unsigned int)cs->id >= CSID_MAX)) in __clocksource_register_scale()
1231 cs->id = CSID_GENERIC; in __clocksource_register_scale()
1232 if (cs->vdso_clock_mode < 0 || in __clocksource_register_scale()
1233 cs->vdso_clock_mode >= VDSO_CLOCKMODE_MAX) { in __clocksource_register_scale()
1235 cs->name, cs->vdso_clock_mode); in __clocksource_register_scale()
1236 cs->vdso_clock_mode = VDSO_CLOCKMODE_NONE; in __clocksource_register_scale()
1240 __clocksource_update_freq_scale(cs, scale, freq); in __clocksource_register_scale()
1246 clocksource_enqueue(cs); in __clocksource_register_scale()
1247 clocksource_enqueue_watchdog(cs); in __clocksource_register_scale()
1252 __clocksource_suspend_select(cs); in __clocksource_register_scale()
1258 static void __clocksource_change_rating(struct clocksource *cs, int rating) in __clocksource_change_rating() argument
1260 list_del(&cs->list); in __clocksource_change_rating()
1261 cs->rating = rating; in __clocksource_change_rating()
1262 clocksource_enqueue(cs); in __clocksource_change_rating()
1267 * @cs: clocksource to be changed
1270 void clocksource_change_rating(struct clocksource *cs, int rating) in clocksource_change_rating() argument
1276 __clocksource_change_rating(cs, rating); in clocksource_change_rating()
1287 * Unbind clocksource @cs. Called with clocksource_mutex held
1289 static int clocksource_unbind(struct clocksource *cs) in clocksource_unbind() argument
1293 if (clocksource_is_watchdog(cs)) { in clocksource_unbind()
1296 if (clocksource_is_watchdog(cs)) in clocksource_unbind()
1300 if (cs == curr_clocksource) { in clocksource_unbind()
1303 if (curr_clocksource == cs) in clocksource_unbind()
1307 if (clocksource_is_suspend(cs)) { in clocksource_unbind()
1317 clocksource_dequeue_watchdog(cs); in clocksource_unbind()
1318 list_del_init(&cs->list); in clocksource_unbind()
1326 * @cs: clocksource to be unregistered
1328 int clocksource_unregister(struct clocksource *cs) in clocksource_unregister() argument
1333 if (!list_empty(&cs->list)) in clocksource_unregister()
1334 ret = clocksource_unbind(cs); in clocksource_unregister()
1420 struct clocksource *cs; in unbind_clocksource_store() local
1430 list_for_each_entry(cs, &clocksource_list, list) { in unbind_clocksource_store()
1431 if (strcmp(cs->name, name)) in unbind_clocksource_store()
1433 ret = clocksource_unbind(cs); in unbind_clocksource_store()