brintos

brintos / linux-shallow public Read only

0
0
Text · 4.2 KiB · 1760432 Raw
83 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3Clocks and Timers4=================5 6arm647-----8On arm64, Hyper-V virtualizes the ARMv8 architectural system counter9and timer. Guest VMs use this virtualized hardware as the Linux10clocksource and clockevents via the standard arm_arch_timer.c11driver, just as they would on bare metal. Linux vDSO support for the12architectural system counter is functional in guest VMs on Hyper-V.13While Hyper-V also provides a synthetic system clock and four synthetic14per-CPU timers as described in the TLFS, they are not used by the15Linux kernel in a Hyper-V guest on arm64.  However, older versions16of Hyper-V for arm64 only partially virtualize the ARMv817architectural timer, such that the timer does not generate18interrupts in the VM. Because of this limitation, running current19Linux kernel versions on these older Hyper-V versions requires an20out-of-tree patch to use the Hyper-V synthetic clocks/timers instead.21 22x86/x6423-------24On x86/x64, Hyper-V provides guest VMs with a synthetic system clock25and four synthetic per-CPU timers as described in the TLFS. Hyper-V26also provides access to the virtualized TSC via the RDTSC and27related instructions. These TSC instructions do not trap to28the hypervisor and so provide excellent performance in a VM.29Hyper-V performs TSC calibration, and provides the TSC frequency30to the guest VM via a synthetic MSR.  Hyper-V initialization code31in Linux reads this MSR to get the frequency, so it skips TSC32calibration and sets tsc_reliable. Hyper-V provides virtualized33versions of the PIT (in Hyper-V  Generation 1 VMs only), local34APIC timer, and RTC. Hyper-V does not provide a virtualized HPET in35guest VMs.36 37The Hyper-V synthetic system clock can be read via a synthetic MSR,38but this access traps to the hypervisor. As a faster alternative,39the guest can configure a memory page to be shared between the guest40and the hypervisor.  Hyper-V populates this memory page with a4164-bit scale value and offset value. To read the synthetic clock42value, the guest reads the TSC and then applies the scale and offset43as described in the Hyper-V TLFS. The resulting value advances44at a constant 10 MHz frequency. In the case of a live migration45to a host with a different TSC frequency, Hyper-V adjusts the46scale and offset values in the shared page so that the 10 MHz47frequency is maintained.48 49Starting with Windows Server 2022 Hyper-V, Hyper-V uses hardware50support for TSC frequency scaling to enable live migration of VMs51across Hyper-V hosts where the TSC frequency may be different.52When a Linux guest detects that this Hyper-V functionality is53available, it prefers to use Linux's standard TSC-based clocksource.54Otherwise, it uses the clocksource for the Hyper-V synthetic system55clock implemented via the shared page (identified as56"hyperv_clocksource_tsc_page").57 58The Hyper-V synthetic system clock is available to user space via59vDSO, and gettimeofday() and related system calls can execute60entirely in user space.  The vDSO is implemented by mapping the61shared page with scale and offset values into user space.  User62space code performs the same algorithm of reading the TSC and63applying the scale and offset to get the constant 10 MHz clock.64 65Linux clockevents are based on Hyper-V synthetic timer 0 (stimer0).66While Hyper-V offers 4 synthetic timers for each CPU, Linux only uses67timer 0. In older versions of Hyper-V, an interrupt from stimer068results in a VMBus control message that is demultiplexed by69vmbus_isr() as described in the Documentation/virt/hyperv/vmbus.rst70documentation. In newer versions of Hyper-V, stimer0 interrupts can71be mapped to an architectural interrupt, which is referred to as72"Direct Mode". Linux prefers to use Direct Mode when available. Since73x86/x64 doesn't support per-CPU interrupts, Direct Mode statically74allocates an x86 interrupt vector (HYPERV_STIMER0_VECTOR) across all CPUs75and explicitly codes it to call the stimer0 interrupt handler. Hence76interrupts from stimer0 are recorded on the "HVS" line in /proc/interrupts77rather than being associated with a Linux IRQ. Clockevents based on the78virtualized PIT and local APIC timer also work, but Hyper-V stimer079is preferred.80 81The driver for the Hyper-V synthetic system clock and timers is82drivers/clocksource/hyperv_timer.c.83