Reputation: 3088
As part of debugging our guest VM, we use rdtsc quite extensively to monitor the amount of time (ok, clock cycles) being used. The question was raised that this was expensive in itself as rdtsc yields a VM exit. I can think of no lower level means of finding out how much clock time or equivalent has elapsed. Is there any other solution ? Is this really expensive ?
Upvotes: 2
Views: 2466
Reputation: 314
It is not necessary for every rdtsc to result in VM Exit, atleast not on Intel CPU's. ASAIK, the Virtual Machine Control Structure(VMCS) has a bit which dictates whether every RDTSC should cause a VM-Exit. Check "Definitions of Primary Processor-Based VM-Execution Controls – BIT 12" (Table 21-6) of Intel Architecture Manual
There is a nifty script(vmxcap.py) which can be used to quickly dump this info. For example, on my machine where RDTSC does not incur VM-Exit, I get the below:
[root@XYZ ~]# ./vmxcap.py | grep -i rdtsc
RDTSC exiting no
Hope this helps.
Upvotes: 6