Skip to content

Commit 20175d5

Browse files
committed
selftests: kvm: move get_run_delay() into lib/test_util
get_run_delay() is defined static in xen_shinfo_test and steal_time test. Move it to lib and remove code duplication. Signed-off-by: Shuah Khan <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 3a4f0cc commit 20175d5

File tree

4 files changed

+16
-30
lines changed

4 files changed

+16
-30
lines changed

tools/testing/selftests/kvm/include/test_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
102102
size_t get_backing_src_pagesz(uint32_t i);
103103
void backing_src_help(void);
104104
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
105+
long get_run_delay(void);
105106

106107
/*
107108
* Whether or not the given source type is shared memory (as opposed to

tools/testing/selftests/kvm/lib/test_util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdlib.h>
1212
#include <time.h>
1313
#include <sys/stat.h>
14+
#include <sys/syscall.h>
1415
#include <linux/mman.h>
1516
#include "linux/kernel.h"
1617

@@ -303,3 +304,17 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
303304
TEST_FAIL("Unknown backing src type: %s", type_name);
304305
return -1;
305306
}
307+
308+
long get_run_delay(void)
309+
{
310+
char path[64];
311+
long val[2];
312+
FILE *fp;
313+
314+
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
315+
fp = fopen(path, "r");
316+
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
317+
fclose(fp);
318+
319+
return val[1];
320+
}

tools/testing/selftests/kvm/steal_time.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <sched.h>
1111
#include <pthread.h>
1212
#include <linux/kernel.h>
13-
#include <sys/syscall.h>
1413
#include <asm/kvm.h>
1514
#include <asm/kvm_para.h>
1615

@@ -217,20 +216,6 @@ static void steal_time_dump(struct kvm_vm *vm, uint32_t vcpuid)
217216

218217
#endif
219218

220-
static long get_run_delay(void)
221-
{
222-
char path[64];
223-
long val[2];
224-
FILE *fp;
225-
226-
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
227-
fp = fopen(path, "r");
228-
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
229-
fclose(fp);
230-
231-
return val[1];
232-
}
233-
234219
static void *do_steal_time(void *arg)
235220
{
236221
struct timespec ts, stop;

tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <stdint.h>
1515
#include <time.h>
1616
#include <sched.h>
17-
#include <sys/syscall.h>
1817

1918
#define VCPU_ID 5
2019

@@ -98,20 +97,6 @@ static void guest_code(void)
9897
GUEST_DONE();
9998
}
10099

101-
static long get_run_delay(void)
102-
{
103-
char path[64];
104-
long val[2];
105-
FILE *fp;
106-
107-
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
108-
fp = fopen(path, "r");
109-
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
110-
fclose(fp);
111-
112-
return val[1];
113-
}
114-
115100
static int cmp_timespec(struct timespec *a, struct timespec *b)
116101
{
117102
if (a->tv_sec > b->tv_sec)

0 commit comments

Comments
 (0)