Re: [PATCH v4 08/10] KVM: selftests: Time guest demand paging

Andrew Jones
2020-01-24T10:21:16Z

On Thu, Jan 23, 2020 at 10:04:34AM -0800, Ben Gardon wrote:
> In order to quantify demand paging performance, time guest execution
> during demand paging.
>
> Signed-off-by: Ben Gardon <bgardon@google.com>
> ---
> .../selftests/kvm/demand_paging_test.c | 68 +++++++++++++++++++
> 1 file changed, 68 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index 2002032df32cc..0dc5d04718678 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -32,6 +32,12 @@
>
> #define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
>
> +#ifdef PRINT_PER_PAGE_UPDATES
> +#define PER_PAGE_DEBUG(...) DEBUG(__VA_ARGS__)
> +#else
> +#define PER_PAGE_DEBUG(...)
> +#endif
> +
> #ifdef PRINT_PER_VCPU_UPDATES
> #define PER_VCPU_DEBUG(...) DEBUG(__VA_ARGS__)
> #else
> @@ -64,6 +70,26 @@ static uint64_t guest_test_phys_mem;
> */
> static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
>
> +int64_t to_ns(struct timespec ts)
> +{
> + return (int64_t)ts.tv_nsec + 1000000000LL * (int64_t)ts.tv_sec;
> +}
> +
> +struct timespec diff(struct timespec start, struct timespec end)
> +{
> + struct timespec temp;
> +
> + if ((end.tv_nsec-start.tv_nsec) < 0) {

spaces around the '-' would be nice

> + temp.tv_sec = end.tv_sec - start.tv_sec - 1;
> + temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
> + } else {
> + temp.tv_sec = end.tv_sec - start.tv_sec;
> + temp.tv_nsec = end.tv_nsec - start.tv_nsec;
> + }
> +
> + return temp;
> +}

Could probably add these new time utilities to the new test_util.c

Thanks,
drew