1

I am trying to measure the cycle count of an instruction in a VM -- my code looks like this:

start = rdtscp();
//complex_sequence_of_instructions
end = rtdscp();
//complex_sequence_of_instructions took end-time cycles

To the best of my knowledge, using rdtscp in a VM does not provide an accurate cycle count, however. I launch my VM like this:

qemu-system-x86_64 -enable-kvm -cpu EPYC-v4 [...]

on a zen3 AMD CPU (without SEV enabled). Is there any way I can configure kvm to no trap the rdtscp instruction and get an accurate timestamp measurement?

  • `//Increasing i took end-time cycles` - RDTSC and RDTSCP have significant overhead compared to executing one instruction. That's not a meaningful microbenchmark even on bare metal. Also, a single time in cycles isn't very meaningful for something as short as incrementing an integer; you need to measure throughput separately from latency. See [How many CPU cycles are needed for each assembly instruction?](https://stackoverflow.com/q/692718) – Peter Cordes Mar 03 '23 at 13:47
  • Thanks @PeterCordes -- I should have picked another instruction for illustration. I am actually benchmarking a more complex sequence of instructions -- edited the post – cryptobeginner Mar 03 '23 at 15:24

0 Answers0