On Tue, Nov 15, 2022, Colton Lewis wrote: > Print summary stats of the memory latency distribution in > nanoseconds. For every iteration, this prints the minimum, the > maximum, and the 50th, 90th, and 99th percentiles. > > Stats are calculated by sorting the samples taken from all vcpus and > picking from the index corresponding with each percentile. > > The conversion to nanoseconds needs the frequency of the Intel > timestamp counter, which is estimated by reading the counter before > and after sleeping for 1 second. This is not a pretty trick, but it > also exists in vmx_nested_tsc_scaling_test.c This test shouldn't need to guesstimate the frequency, just use a VM-scoped KVM_GET_TSC_KHZ, which will provide KVM's default TSC frequency, i.e. the host frequency. For hardware with a constant TSC, which is everything modern, that will be as accurate as we can get. For hardware without a constant TSC, well, buy new hardware :-) vmx_nested_tsc_scaling_test.c does the weird sleep() behavior because it's trying to validate that the guest TSC counts at the correct rate, i.e. it is validating KVM_GET_TSC_KHZ to some extent, and so obviously doesn't fully trust its result. For tests that just want to measure time, there's no reason not to trust KVM.