Lines Matching +full:calibration +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-only
29 #include <asm/intel-family.h>
57 struct cyc2ns_data data[2]; /* 0 + 2*16 = 32 */ member
70 __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) in cyc2ns_read_begin() argument
80 data->cyc2ns_offset = this_cpu_read(cyc2ns.data[idx].cyc2ns_offset); in cyc2ns_read_begin()
81 data->cyc2ns_mul = this_cpu_read(cyc2ns.data[idx].cyc2ns_mul); in cyc2ns_read_begin()
82 data->cyc2ns_shift = this_cpu_read(cyc2ns.data[idx].cyc2ns_shift); in cyc2ns_read_begin()
107 * cyc2ns_scale needs to be a 32-bit value so that 32-bit multiplication
108 * (64-bit result) can be used.
113 * -johnstul@us.ibm.com "math is hard, lets go shopping!"
118 struct cyc2ns_data data; in cycles_2_ns() local
121 cyc2ns_read_begin(&data); in cycles_2_ns()
123 ns = data.cyc2ns_offset; in cycles_2_ns()
124 ns += mul_u64_u32_shr(cyc, data.cyc2ns_mul, data.cyc2ns_shift); in cycles_2_ns()
134 struct cyc2ns_data data; in __set_cyc2ns_scale() local
144 clocks_calc_mult_shift(&data.cyc2ns_mul, &data.cyc2ns_shift, khz, in __set_cyc2ns_scale()
150 * conversion algorithm shifting a 32-bit value (now specifies a 64-bit in __set_cyc2ns_scale()
151 * value) - refer perf_event_mmap_page documentation in perf_event.h. in __set_cyc2ns_scale()
153 if (data.cyc2ns_shift == 32) { in __set_cyc2ns_scale()
154 data.cyc2ns_shift = 31; in __set_cyc2ns_scale()
155 data.cyc2ns_mul >>= 1; in __set_cyc2ns_scale()
158 data.cyc2ns_offset = ns_now - in __set_cyc2ns_scale()
159 mul_u64_u32_shr(tsc_now, data.cyc2ns_mul, data.cyc2ns_shift); in __set_cyc2ns_scale()
163 raw_write_seqcount_latch(&c2n->seq); in __set_cyc2ns_scale()
164 c2n->data[0] = data; in __set_cyc2ns_scale()
165 raw_write_seqcount_latch(&c2n->seq); in __set_cyc2ns_scale()
166 c2n->data[1] = data; in __set_cyc2ns_scale()
190 seqcount_latch_init(&c2n->seq); in cyc2ns_init_boot_cpu()
203 struct cyc2ns_data *data = c2n->data; in cyc2ns_init_secondary_cpus() local
207 seqcount_latch_init(&c2n->seq); in cyc2ns_init_secondary_cpus()
209 c2n->data[0] = data[0]; in cyc2ns_init_secondary_cpus()
210 c2n->data[1] = data[1]; in cyc2ns_init_secondary_cpus()
216 * Scheduler clock - returns current time in nanosec units.
237 return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ); in native_sched_clock()
330 if ((t2 - t1) < thresh) in tsc_read_refs()
345 hpet2 -= hpet1; in calc_hpet_ref()
365 pm2 -= pm1; in calc_pmtimer_ref()
428 delta = t2 - tsc; in pit_calibrate_tsc()
450 delta = t2 - t1; in pit_calibrate_tsc()
458 * non-virtualized hardware.
462 * - the PIT is running at roughly 1.19MHz
464 * - each IO is going to take about 1us on real hardware,
467 * update - anything else implies a unacceptably slow CPU
468 * or PIT for the fast calibration to work.
470 * - with 256 PIT ticks to read the value, we have 214us to
474 * - We're doing 2 reads per loop (LSB, MSB), and we expect
479 * - if the PIT is stuck, and we see *many* more reads, we
508 *deltap = get_cycles() - prev_tsc; in pit_expect_msb()
540 * Counter 2, mode 0 (one-shot), binary count in quick_pit_calibrate()
544 * final output frequency as a decrement-by-one), in quick_pit_calibrate()
557 * to do that is to just read back the 16-bit counter in quick_pit_calibrate()
564 if (!pit_expect_msb(0xff-i, &delta, &d2)) in quick_pit_calibrate()
567 delta -= tsc; in quick_pit_calibrate()
590 if (!pit_verify_msb(0xfe - i)) in quick_pit_calibrate()
595 pr_info("Fast TSC calibration failed\n"); in quick_pit_calibrate()
608 * kHz = ticks / time-in-seconds / 1000; in quick_pit_calibrate()
609 * kHz = (t2 - t1) / (I * 256 / PIT_TICK_RATE) / 1000 in quick_pit_calibrate()
610 * kHz = ((t2 - t1) * PIT_TICK_RATE) / (I * 256 * 1000) in quick_pit_calibrate()
614 pr_info("Fast TSC calibration using PIT\n"); in quick_pit_calibrate()
725 * Run 5 calibration loops to get the lowest frequency value in pit_hpet_ptimer_calibrate_cpu()
726 * (the best estimate). We use two different calibration modes in pit_hpet_ptimer_calibrate_cpu()
745 * calibration delay loop as we have to wait for a certain in pit_hpet_ptimer_calibrate_cpu()
760 * calibration, which will take at least 50ms, and in pit_hpet_ptimer_calibrate_cpu()
769 /* Pick the lowest PIT TSC calibration so far */ in pit_hpet_ptimer_calibrate_cpu()
780 tsc2 = (tsc2 - tsc1) * 1000000LL; in pit_hpet_ptimer_calibrate_cpu()
793 * If both calibration results are inside a 10% window in pit_hpet_ptimer_calibrate_cpu()
794 * then we can be sure, that the calibration in pit_hpet_ptimer_calibrate_cpu()
799 pr_info("PIT calibration matches %s. %d loops\n", in pit_hpet_ptimer_calibrate_cpu()
832 pr_warn("HPET/PMTIMER calibration failed\n"); in pit_hpet_ptimer_calibrate_cpu()
837 pr_info("using %s reference calibration\n", in pit_hpet_ptimer_calibrate_cpu()
843 /* We don't have an alternative source, use the PIT calibration value */ in pit_hpet_ptimer_calibrate_cpu()
845 pr_info("Using PIT calibration value\n"); in pit_hpet_ptimer_calibrate_cpu()
849 /* The alternative source failed, use the PIT calibration value */ in pit_hpet_ptimer_calibrate_cpu()
851 pr_warn("HPET/PMTIMER calibration failed. Using PIT calibration.\n"); in pit_hpet_ptimer_calibrate_cpu()
856 * The calibration values differ too much. In doubt, we use in pit_hpet_ptimer_calibrate_cpu()
860 pr_warn("PIT calibration deviates from %s: %lu %lu\n", in pit_hpet_ptimer_calibrate_cpu()
862 pr_info("Using PIT calibration value\n"); in pit_hpet_ptimer_calibrate_cpu()
867 * native_calibrate_cpu_early - can calibrate the cpu early in boot
885 * native_calibrate_cpu - calibrate the cpu
909 else if (abs(cpu_khz - tsc_khz) * 10 > tsc_khz) in recalibrate_cpu_khz()
951 * data fields. in tsc_restore_sched_clock_state()
954 this_cpu_write(cyc2ns.data[0].cyc2ns_offset, 0); in tsc_restore_sched_clock_state()
955 this_cpu_write(cyc2ns.data[1].cyc2ns_offset, 0); in tsc_restore_sched_clock_state()
957 offset = cyc2ns_suspend - sched_clock(); in tsc_restore_sched_clock_state()
960 per_cpu(cyc2ns.data[0].cyc2ns_offset, cpu) = offset; in tsc_restore_sched_clock_state()
961 per_cpu(cyc2ns.data[1].cyc2ns_offset, cpu) = offset; in tsc_restore_sched_clock_state()
984 void *data) in time_cpufreq_notifier() argument
986 struct cpufreq_freqs *freq = data; in time_cpufreq_notifier()
994 ref_freq = freq->old; in time_cpufreq_notifier()
999 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || in time_cpufreq_notifier()
1000 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) { in time_cpufreq_notifier()
1002 cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new); in time_cpufreq_notifier()
1004 tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new); in time_cpufreq_notifier()
1005 if (!(freq->flags & CPUFREQ_CONST_LOOPS)) in time_cpufreq_notifier()
1008 set_cyc2ns_scale(tsc_khz, freq->policy->cpu, rdtsc()); in time_cpufreq_notifier()
1048 * Don't enable ART in a VM, non-stop TSC and TSC_ADJUST required, in detect_art()
1079 * structure to avoid a nasty time-warp. This can be observed in a
1090 * checking the result of read_tsc() - cycle_last for being negative.
1129 .name = "tsc-early",
1198 /* Geode_LX - the OLPC CPU has a very reliable TSC */ in check_system_tsc_reliable()
1208 * - TSC running at constant frequency in check_system_tsc_reliable()
1209 * - TSC which does not stop in C-States in check_system_tsc_reliable()
1210 * - the TSC_ADJUST register which allows to detect even minimal in check_system_tsc_reliable()
1212 * - not more than two sockets. As the number of sockets cannot be in check_system_tsc_reliable()
1277 * convert_art_ns_to_tsc() - Convert ART in nanoseconds to TSC.
1281 * software requests a cross-timestamp, this function converts system timestamp
1289 * struct system_counterval_t - system counter value with the pointer to the
1318 * tsc_refine_calibration_work - Further refine tsc freq calibration
1319 * @work - ignored.
1324 * process while this longer calibration is done.
1326 * If there are any calibration anomalies (too many SMIs, etc),
1327 * or the refined calibration is off by 1% of the fast early
1328 * calibration, we throw out the new calibration and use the
1329 * early calibration.
1370 delta = tsc_stop - tsc_start; in tsc_refine_calibration_work()
1378 if (abs(tsc_khz - freq) > tsc_khz/100) in tsc_refine_calibration_work()
1382 pr_info("Refined TSC clocksource calibration: %lu.%03lu MHz\n", in tsc_refine_calibration_work()
1418 * the refined calibration and directly register it as a clocksource. in init_tsc_clocksource()
1450 /* We should not be here with non-native cpu calibration */ in determine_cpu_tsc_frequencies()
1456 * Trust non-zero tsc_khz as authoritative, in determine_cpu_tsc_frequencies()
1462 else if (abs(cpu_khz - tsc_khz) * 10 > tsc_khz) in determine_cpu_tsc_frequencies()
1503 /* Don't change UV TSC multi-chassis synchronization */ in tsc_early_init()
1559 * we can skip clock calibration if another cpu in the same socket has already
1561 * cpus in the socket - this should be a safe assumption.