qemu kvm:如何获取性能监视中断? [英] qemu kvm: how to get permformance monitoring interrupt?
问题描述
我在OS内核中编写了一些函数,以在指令计数器溢出时发出性能监视中断(PMI).它在我的机器(Intel酷睿i5)上运行良好.但是当我使用
I write some function in my OS kernel to issue the performance monitoring interrupt (PMI) on instructions counter overflow. It works well on my machine (Intel core i5). But when I run it on qemu using
qemu-system-x86_64 -enable-kvm -cpu host -m 256 -serial mon:stdio -cdrom var/run/hypervisor.iso
qemu-system-x86_64 -enable-kvm -cpu host -m 256 -serial mon:stdio -cdrom var/run/hypervisor.iso
该中断不会触发. 有什么我想念的吗? 是否需要任何特殊配置才能在Qemu上触发PMI? 我记得指令计数在qemu中很好用. msr注册以激活PMI
the interrupt does never fire. Is there anything I am missing? Does it require any special configuration to get the PMI fired on qemu? I recall that instruction counting works well in qemu. msr registers to activate PMI
Msr::write(Msr::MSR_PERF_GLOBAL_CTRL, 0x700000003);
Msr::write(Msr::MSR_PERF_FIXED_CTRL, 0xa);
Msr::write(Msr::IA32_PERFEVTSEL0, 0x004100c5);
为PMI编写0x1000指令
Program the PMI for 0x1000 instructions
Msr::write(Msr::IA32_PERF_GLOBAL_OVF_CTRL, 1ull << 32);
Msr::write(Msr::MSR_PERF_FIXED_CTR0, 0xFFFFEFFF | 0xFFFF00000000);
推荐答案
从讨论中此处,您可以看到kvm仅在写入PERF_FIXED_CTR_CTRL(0x38d)时才更新虚拟计数器.
From the discussion here, you can read that kvm updates the virtual counter only when you write into PERF_FIXED_CTR_CTRL (0x38d).
因此,要获得pmi,最好在设置计数器值之后,将该寄存器设置在最后一个位置.
So, to get the pmi, you better set this register at last position, after setting the counter value of course.
为了完整起见,必须按以下顺序发布说明:
For the sake of completeness, instructions must be issued in this order:
; set counter value.
mov edx, 0xffff
mov eax, 0xffff0000
mov ecx, 0x309
wrmsr
; set counting mode
xor edx, edx
mov eax, 0xa
mov ecx, 0x38d
wrmsr
这篇关于qemu kvm:如何获取性能监视中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!