QuarkContainer / Quark

A secure container runtime with CRI/OCI interface
Apache License 2.0
324 stars 49 forks source link

KVM: KVM_GET_TSC_KHZ fails #1276

Open shrik3 opened 5 months ago

shrik3 commented 5 months ago

I don't know if it's only me but strace on quark (x86) repeatedly shows:

[pid 490389] ioctl(19, KVM_GET_TSC_KHZ, 0) = 2591999
[pid 490389] read(12, 0x7752b2fe71c8, 8) = -1 EAGAIN (Resource temporarily unavailable)

the vcpu constantly polls KVM_GET_TSC_KHZ, which always fails.

4.56 KVM_GET_TSC_KHZ
Capability: KVM_CAP_GET_TSC_KHZ
Architectures: x86
Type: vcpu ioctl
Parameters: none
Returns: virtual tsc-khz on success, negative value on error
Returns the tsc frequency of the guest. The unit of the return value is
KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
error.

Perhaps we turn off this kvm capability, if we don't use it.

shrik3 commented 5 months ago

image

shrik3 commented 5 months ago

CC. @QuarkContainer

The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. Processor’s support for invariant TSC is indicated by CPUID.80000007H:EDX[8]. The invariant TSC will run at a constant rate in all ACPI P-, C-. and T-states. This is the architectural behavior moving forward. On processors with invariant TSC support, the OS may use the TSC for wall clock timer services (instead of ACPI or HPET timers). TSC reads are much more efficient and do not incur the overhead associated with a ring transition or access to a platform resource.

In newer (x86) processors the TSC increments at a constant rate, in which case perhaps there is not need to calibrate the system clock per CPU frequency if using the rdtsc instruction.

reference: Intel SDM section 17.17.1 Invariant TSC