mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: retrieve timebase-frequency from KVM instead of hardcoding
The RISC-V device tree's timebase-frequency was hardcoded to 10 MHz (0x989680). Actual hardware uses different frequencies. Read the timebase frequency from KVM_GET_ONE_REG via KVM_REG_RISCV_TIMER (offset 0, kvm_riscv_timer.frequency), thread it through the VMM to arch to FDT layers, and fall back to the 10 MHz default when KVM returns no value. Signed-off-by: Meng Zhuo <mengzhuo@iscas.ac.cn>
This commit is contained in:
@@ -642,6 +642,11 @@ impl Vcpu {
|
||||
self.vcpu.run()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
pub fn get_timebase_frequency(&self) -> result::Result<u64, hypervisor::HypervisorCpuError> {
|
||||
self.vcpu.get_timebase_frequency()
|
||||
}
|
||||
|
||||
#[cfg(feature = "sev_snp")]
|
||||
pub fn set_sev_control_register(&self, vmsa_pfn: u64) -> Result<()> {
|
||||
self.vcpu
|
||||
|
||||
@@ -1988,6 +1988,16 @@ impl Vm {
|
||||
|
||||
// TODO: PMU support for riscv64 is scheduled to next stage.
|
||||
|
||||
let timebase_frequency = self
|
||||
.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.vcpus()
|
||||
.first()
|
||||
.and_then(|vcpu| vcpu.lock().unwrap().get_timebase_frequency().ok())
|
||||
.map(|f| f as u32)
|
||||
.unwrap_or(0x989680);
|
||||
|
||||
arch::configure_system(
|
||||
&mem,
|
||||
cmdline.as_cstring().unwrap().to_str().unwrap(),
|
||||
@@ -1996,6 +2006,7 @@ impl Vm {
|
||||
&initramfs_config,
|
||||
&pci_space_info,
|
||||
&vaia,
|
||||
timebase_frequency,
|
||||
)
|
||||
.map_err(Error::ConfigureSystem)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user