本文介绍了KVM如何虚拟化性能计数器(PMC)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Intel平台上使用 KVM-QEMU .我想知道如何在 KVM 中将 PMC/PMU 虚拟化?

I am using KVM-QEMU in Intel platform.And I am wondering how is the PMC/PMU being virtualized in KVM?

我对vPMC的理解如下.

My understanding of vPMC is as follows.

由于PMU是共享的物理资源,因此管理程序应在VMExit/VMEnter期间上下文保存/恢复PMC配置和计数器.

Since PMU is a shared physical resource, so hypervisor shall context save/restore PMC configurations and counters during VMExit/VMEnter.

但是在测试中,我感到困惑.

But in my testing, I got confused.

 (In my host Linux, the MSR of IA32_PERF_FIXed_CTRL is set to 0xb0)

首先,在启动的VM中,

First of all, in a launched VM,

I 'wrmsr IA32_PERF_FIXed_CTRL 0x0b',以在VM中启用FIXed_CTR0.然后,我在VMExit上记录了IA32_PERF_FIXed_CTRL的MSR,发现FIXed_CTR0未启用.

I 'wrmsr IA32_PERF_FIXed_CTRL 0x0b', to enable FIXed_CTR0 in VM.Then, I logged the MSR of IA32_PERF_FIXed_CTRL at VMExit, and found FIXed_CTR0 is not enabled.

我认为这是因为发生VMExit时,它已经在主机上下文中,因此IA32_PERF_FIXed_CTRL的MSR是主机之一,而不是主机.

I think it is because when VMExit happens, it is already in the host context, so the MSR of IA32_PERF_FIXed_CTRL is the one of host, not the host.

但是问题是,VM的MSR在哪里保存在主机中,以及在VMEnter期间何时何地将VM的MSR还原到CPU上?

But the question is where is that MSR for the VM being saved in host, and when and where the VM's MSR is being restored to CPU during VMEnter???

希望我的问题很清楚.

谢谢

推荐答案

KVM实现了虚拟PMU,该虚拟PMU利用Linux的perf子系统进行核心PMU操作.它不会将主机PMU直接暴露给来宾.

KVM implements a virtual PMU that utilizes Linux's perf subsystem for core PMU operations. It does not expose the host PMU directly to the guest.

当您执行wrmsr IA32_PERF_FIXed_CTRL 0x0b时,您未在写入硬件MSR(特定于模型的寄存器),KVM将捕获MSR写入并对其虚拟PMU的表示形式进行更新.在x86.c中查找kvm_set_msr_common(),这最终将调用pmu_intel.c中的intel_pmu_set_msr(),这具有真正的魔力.还要查看struct kvm_pmu(),它是KVM对PMU的表示.

When you do wrmsr IA32_PERF_FIXed_CTRL 0x0b, you are not writing to the hardware MSR (Model-specific register), KVM traps the MSR write and makes an update in its representation of the virtual PMU. Look for kvm_set_msr_common() in x86.c, this will ultimately call intel_pmu_set_msr() in pmu_intel.c that does the real magic. Also look at struct kvm_pmu() which is KVM's representation of the PMU.

不需要像典型的VMCS字段那样还原MSR,因为KVM将来宾特定的PMU设置保存在每个vCPU(struct kvm_vcpu)的struct kvm_pmu()中.

The MSR doesn't need to be restored like typical VMCS fields because KVM saves guest specific PMU settings in struct kvm_pmu() per vCPU (struct kvm_vcpu).

这篇关于KVM如何虚拟化性能计数器(PMC)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 10:25