Lines Matching +full:test +full:- +full:cpu
1 // SPDX-License-Identifier: GPL-2.0
8 * print a warning if not and turn off the TSC clock-source.
10 * The warp-check is point-to-point between two CPUs, the CPU
11 * initiating the bootup is the 'source CPU', the freshly booting
12 * CPU is the 'target CPU'.
14 * Only two CPUs may participate - they can enter in any order.
15 * ( The serial nature of the boot logic and the CPU hotplug lock
63 if (!resume && time_before(jiffies, adj->nextcheck)) in tsc_verify_tsc_adjust()
66 adj->nextcheck = jiffies + HZ; in tsc_verify_tsc_adjust()
69 if (adj->adjusted == curval) in tsc_verify_tsc_adjust()
73 wrmsrl(MSR_IA32_TSC_ADJUST, adj->adjusted); in tsc_verify_tsc_adjust()
75 if (!adj->warned || resume) { in tsc_verify_tsc_adjust()
76 pr_warn(FW_BUG "TSC ADJUST differs: CPU%u %lld --> %lld. Restoring\n", in tsc_verify_tsc_adjust()
77 smp_processor_id(), adj->adjusted, curval); in tsc_verify_tsc_adjust()
78 adj->warned = true; in tsc_verify_tsc_adjust()
123 unsigned int cpu, bool bootcpu) in tsc_sanitize_first_cpu() argument
126 * First online CPU in a package stores the boot value in the in tsc_sanitize_first_cpu()
131 * On the boot cpu we just force set the ADJUST value to 0 if it's in tsc_sanitize_first_cpu()
143 pr_warn(FW_BUG "TSC ADJUST: CPU%u: %lld force to 0\n", in tsc_sanitize_first_cpu()
144 cpu, bootval); in tsc_sanitize_first_cpu()
148 pr_info("TSC ADJUST: CPU%u: %lld NOT forced to 0\n", in tsc_sanitize_first_cpu()
149 cpu, bootval); in tsc_sanitize_first_cpu()
152 cur->adjusted = bootval; in tsc_sanitize_first_cpu()
169 cur->bootval = bootval; in tsc_store_and_check_tsc_adjust()
170 cur->nextcheck = jiffies + HZ; in tsc_store_and_check_tsc_adjust()
183 unsigned int refcpu, cpu = smp_processor_id(); in tsc_store_and_check_tsc_adjust() local
191 cur->bootval = bootval; in tsc_store_and_check_tsc_adjust()
192 cur->nextcheck = jiffies + HZ; in tsc_store_and_check_tsc_adjust()
193 cur->warned = false; in tsc_store_and_check_tsc_adjust()
196 * If a non-zero TSC value for socket 0 may be valid then the default in tsc_store_and_check_tsc_adjust()
200 cur->adjusted = bootval; in tsc_store_and_check_tsc_adjust()
203 * Check whether this CPU is the first in a package to come up. In in tsc_store_and_check_tsc_adjust()
207 * boot CPU topology_core_cpumask() might not be available yet. in tsc_store_and_check_tsc_adjust()
209 mask = topology_core_cpumask(cpu); in tsc_store_and_check_tsc_adjust()
210 refcpu = mask ? cpumask_any_but(mask, cpu) : nr_cpu_ids; in tsc_store_and_check_tsc_adjust()
223 if (bootval != ref->bootval) in tsc_store_and_check_tsc_adjust()
228 * value on this newly upcoming CPU differs from the adjustment in tsc_store_and_check_tsc_adjust()
229 * value of the already online CPU in this package, set it to that in tsc_store_and_check_tsc_adjust()
232 if (bootval != ref->adjusted) { in tsc_store_and_check_tsc_adjust()
233 cur->adjusted = ref->adjusted; in tsc_store_and_check_tsc_adjust()
234 wrmsrl(MSR_IA32_TSC_ADJUST, ref->adjusted); in tsc_store_and_check_tsc_adjust()
238 * test: in tsc_store_and_check_tsc_adjust()
253 * we want to have the fastest, inlined, non-debug version
254 * of a critical section, to be able to prove TSC time-warps:
264 * TSC-warp measurement loop running on both CPUs. This is not called
282 * another CPU) and update the previous TSC timestamp. in check_tsc_warp()
304 * we saw a time-warp of the TSC going backwards: in check_tsc_warp()
308 max_warp = max(max_warp, prev - now); in check_tsc_warp()
312 * one CPU should observe time going backwards. in check_tsc_warp()
321 WARN(!(now-start), in check_tsc_warp()
323 now-start, end-start); in check_tsc_warp()
328 * If the target CPU coming online doesn't have any of its core-siblings
329 * online, a timeout of 20msec will be used for the TSC-warp measurement
332 * have more and more logical-siblings in that socket).
335 * core-siblings, if the first logical CPU in a socket passed the sync test.
336 * But as the TSC is per-logical CPU and can potentially be modified wrongly
337 * by the bios, TSC sync test for smaller duration should be able
341 static inline unsigned int loop_timeout(int cpu) in loop_timeout() argument
343 return (cpumask_weight(topology_core_cpumask(cpu)) > 1) ? 2 : 20; in loop_timeout()
354 * The freshly booted CPU initiates this via an async SMP function call.
358 unsigned int cpu = (unsigned long)__cpu; in check_tsc_sync_source() local
362 * Set the maximum number of test runs to in check_tsc_sync_source()
363 * 1 if the CPU does not provide the TSC_ADJUST MSR in check_tsc_sync_source()
372 while (atomic_read(&start_count) != cpus - 1) in check_tsc_sync_source()
380 check_tsc_warp(loop_timeout(cpu)); in check_tsc_sync_source()
382 while (atomic_read(&stop_count) != cpus-1) in check_tsc_sync_source()
386 * If the test was successful set the number of runs to zero and in check_tsc_sync_source()
393 pr_debug("TSC synchronization [CPU#%d -> CPU#%u]: passed\n", in check_tsc_sync_source()
394 smp_processor_id(), cpu); in check_tsc_sync_source()
400 pr_warn("TSC synchronization [CPU#%d -> CPU#%u]:\n", in check_tsc_sync_source()
401 smp_processor_id(), cpu); in check_tsc_sync_source()
410 * Reset it - just in case we boot another CPU later: in check_tsc_sync_source()
436 unsigned int cpu = smp_processor_id(); in check_tsc_sync_target() local
446 * successful skip the test. in check_tsc_sync_target()
448 * The test is also skipped when the TSC is marked reliable. This in check_tsc_sync_target()
456 /* Kick the control CPU into the TSC synchronization function */ in check_tsc_sync_target()
458 (unsigned long *)(unsigned long)cpu, 0); in check_tsc_sync_target()
461 * Register this CPU's participation and wait for the in check_tsc_sync_target()
462 * source CPU to start the measurement: in check_tsc_sync_target()
468 cur_max_warp = check_tsc_warp(loop_timeout(cpu)); in check_tsc_sync_target()
481 * Wait for the source CPU to print stuff: in check_tsc_sync_target()
487 * Reset it for the next sync test: in check_tsc_sync_target()
492 * Check the number of remaining test runs. If not zero, the test in check_tsc_sync_target()
494 * test was either successful or failed terminally. in check_tsc_sync_target()
500 * If the warp value of this CPU is 0, then the other CPU in check_tsc_sync_target()
505 cur_max_warp = -gbl_max_warp; in check_tsc_sync_target()
512 * really depends on CPU, node distance and frequency. So in check_tsc_sync_target()
518 cur->adjusted += cur_max_warp; in check_tsc_sync_target()
520 pr_warn("TSC ADJUST compensate: CPU%u observed %lld warp. Adjust: %lld\n", in check_tsc_sync_target()
521 cpu, cur_max_warp, cur->adjusted); in check_tsc_sync_target()
523 wrmsrl(MSR_IA32_TSC_ADJUST, cur->adjusted); in check_tsc_sync_target()