我的公司开发了一个管理程序,这个问题涉及到AMD的SVM(安全虚拟机)API的使用。
我想准确地跟踪在给定的时间段内,在客户操作系统中执行了多少条指令。AMD在其0x10h系列CPU(Phenom x2等)的实现过程中,在PerfEvtSel MSR(0xc0010000..3)中提供了所谓的“HO”和“GO”或“HostOnly”和“GuestOnly”位。系列0x10h的BKDG指示这些位是64位PerfEvtSel寄存器的40和41。但是,系列0x11h的BKDG没有声明HostOnly和GuestOnly位的存在!
我的代码是这样的:
reg_svm_pes_set_unit_mask(&pes, 0x00);
reg_svm_pes_set_usr(&pes, 1); // Count user mode cycles
reg_svm_pes_set_os(&pes, 1); // Count system cycles
reg_svm_pes_set_e(&pes, 0); // Level, not edge
reg_svm_pes_set_pc(&pes, 0);
reg_svm_pes_set_int(&pes, 1); // Trigger interrupt on overflow
reg_svm_pes_set_en(&pes, enabled);
reg_svm_pes_set_inv(&pes, 0); // No invert sense
reg_svm_pes_set_go(&pes, 1); // Count in the guest
reg_svm_pes_set_ho(&pes, 0); // And not in the host...
你必须相信我的话,每一个都是一个正确编写的内联函数,它在PMC寄存器中设置了适当的位,并且给定的代码成功地写入并可以读回MSR的第40位和第41位。我已经核实过了。
我的经验是,柜台对客人和主人都很重要。这使得仅仅对客人身上发生的事情很难做出准确的解释。
我的问题是:
-
HostOnly和GuestOnly位在家庭0x10h cpu上工作吗?
-
是否需要配置其他计算机状态才能正常工作?
-
有人见过这个CPU的功能吗?
-
-
有没有其他已知的方法可以让SVM实现在主机中关闭PMCs?