Trap and Emulate RDTSC Instructions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all,
For an academic project we need to trap and emulate each RDTSC
instruction executed in a virtual machine. (Our main aim is to
calculate how many rdtsc instructions are executed in a virtual
machine.) Currently we can intercept each of them. But we have a
problem to give the correct tsc values (values are not stable). So we
don't want to mess up the rdtsc reads. We just need to count rdtscs.
Our current approach looks like this.

static int handle_rdtsc(struct kvm_vcpu *vcpu)
{
counter += 1;
vcpu->arch.regs[VCPU_REGS_RAX] = (rdtsc() - VM_EXIT_COS) & -1u;
vcpu->arch.regs[VCPU_REGS_RDX] = ((rdtsc() -  VM_EXIT_COST) >> 32) & -1u;
return skip_emulated_instruction(vcpu);

}

VM_EXIT_COST calculated by how many clock cycles are executed during
host to guest transition (for RDTSC exits only). Can KVM handle these
operations built-in or do you have any idea how we can achieve this?

Thanks a lot.



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux