mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00

In order to quantify demand paging performance, time guest execution during demand paging. Signed-off-by: Ben Gardon <bgardon@google.com> [Move timespec-diff to test_util.h] Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
71 lines
1.3 KiB
C
71 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* tools/testing/selftests/kvm/lib/test_util.c
|
|
*
|
|
* Copyright (C) 2020, Google LLC.
|
|
*/
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <limits.h>
|
|
#include "test_util.h"
|
|
|
|
/*
|
|
* Parses "[0-9]+[kmgt]?".
|
|
*/
|
|
size_t parse_size(const char *size)
|
|
{
|
|
size_t base;
|
|
char *scale;
|
|
int shift = 0;
|
|
|
|
TEST_ASSERT(size && isdigit(size[0]), "Need at least one digit in '%s'", size);
|
|
|
|
base = strtoull(size, &scale, 0);
|
|
|
|
TEST_ASSERT(base != ULLONG_MAX, "Overflow parsing size!");
|
|
|
|
switch (tolower(*scale)) {
|
|
case 't':
|
|
shift = 40;
|
|
break;
|
|
case 'g':
|
|
shift = 30;
|
|
break;
|
|
case 'm':
|
|
shift = 20;
|
|
break;
|
|
case 'k':
|
|
shift = 10;
|
|
break;
|
|
case 'b':
|
|
case '\0':
|
|
shift = 0;
|
|
break;
|
|
default:
|
|
TEST_ASSERT(false, "Unknown size letter %c", *scale);
|
|
}
|
|
|
|
TEST_ASSERT((base << shift) >> shift == base, "Overflow scaling size!");
|
|
|
|
return base << shift;
|
|
}
|
|
|
|
int64_t timespec_to_ns(struct timespec ts)
|
|
{
|
|
return (int64_t)ts.tv_nsec + 1000000000LL * (int64_t)ts.tv_sec;
|
|
}
|
|
|
|
struct timespec timespec_diff(struct timespec start, struct timespec end)
|
|
{
|
|
struct timespec temp;
|
|
|
|
if ((end.tv_nsec - start.tv_nsec) < 0) {
|
|
temp.tv_sec = end.tv_sec - start.tv_sec - 1;
|
|
temp.tv_nsec = 1000000000LL + 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;
|
|
}
|