mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor: aarch64: capture the guest counter for snapshot/restore
Unlike x86, ARM64 has no kvmclock support to sync guest time upon required. However, the guest reads the architected virtual timer (CNTVCT_EL0) directly which can be modified by the VMM to update the time after snapshot restore. Since the CNTVCT is in ticks, we also need to read CNTFRQ (via mrs due to lack of ONEREG interface) to compute the ticks from wall clock difference. Because the counter is a vCPU register, the capture must run with the vCPUs quiesced, so the VMM now captures the clock just after cpu_manager.pause() through the boot vCPU. This is behaviorally identical for x86, whose clock is VM-wide. There is no restore/advance yet, so aarch64 guests still resume behind real time until the following commit. Signed-off-by: Atish Patra <atishp@meta.com>
This commit is contained in:
committed by
Rob Bradford
parent
ad909a3d71
commit
69637dde69
@@ -7,6 +7,23 @@ pub mod regs;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Reads the architected counter frequency (`CNTFRQ_EL0`, Hz) from the host: KVM
|
||||
/// does not expose it through ONE_REG and the guest counter runs at host frequency.
|
||||
pub fn get_cntfrq() -> u64 {
|
||||
use std::arch::asm;
|
||||
let cntfrq: u64;
|
||||
// SAFETY: `mrs cntfrq_el0` only reads a read-only system register and
|
||||
// touches no memory (nomem, nostack, preserves_flags).
|
||||
unsafe {
|
||||
asm!(
|
||||
"mrs {}, cntfrq_el0",
|
||||
out(reg) cntfrq,
|
||||
options(nomem, nostack, preserves_flags),
|
||||
);
|
||||
}
|
||||
cntfrq
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct ExtendedReg {
|
||||
pub id: u64,
|
||||
|
||||
Reference in New Issue
Block a user