@@ -117,8 +117,7 @@ static void *vcpu_worker(void *data)
117117 struct kvm_vm * vm = args -> vm ;
118118 int vcpu_id = args -> vcpu_id ;
119119 struct kvm_run * run ;
120- struct timespec start ;
121- struct timespec end ;
120+ struct timespec start , end , ts_diff ;
122121
123122 vcpu_args_set (vm , vcpu_id , 1 , vcpu_id );
124123 run = vcpu_state (vm , vcpu_id );
@@ -135,9 +134,9 @@ static void *vcpu_worker(void *data)
135134 }
136135
137136 clock_gettime (CLOCK_MONOTONIC , & end );
138- PER_VCPU_DEBUG ( "vCPU %d execution time: %lld.%.9lds\n" , vcpu_id ,
139- ( long long )( timespec_diff ( start , end ). tv_sec ) ,
140- timespec_diff ( start , end ) .tv_nsec );
137+ ts_diff = timespec_sub ( end , start );
138+ PER_VCPU_DEBUG ( "vCPU %d execution time: %ld.%.9lds\n" , vcpu_id ,
139+ ts_diff . tv_sec , ts_diff .tv_nsec );
141140
142141 return NULL ;
143142}
@@ -201,8 +200,8 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
201200
202201 clock_gettime (CLOCK_MONOTONIC , & end );
203202
204- PER_PAGE_DEBUG ("UFFDIO_COPY %d \t%lld ns\n" , tid ,
205- ( long long ) timespec_to_ns (timespec_diff ( start , end )));
203+ PER_PAGE_DEBUG ("UFFDIO_COPY %d \t%ld ns\n" , tid ,
204+ timespec_to_ns (timespec_sub ( end , start )));
206205 PER_PAGE_DEBUG ("Paged in %ld bytes at 0x%lx from thread %d\n" ,
207206 host_page_size , addr , tid );
208207
@@ -224,8 +223,7 @@ static void *uffd_handler_thread_fn(void *arg)
224223 int pipefd = uffd_args -> pipefd ;
225224 useconds_t delay = uffd_args -> delay ;
226225 int64_t pages = 0 ;
227- struct timespec start ;
228- struct timespec end ;
226+ struct timespec start , end , ts_diff ;
229227
230228 clock_gettime (CLOCK_MONOTONIC , & start );
231229 while (!quit_uffd_thread ) {
@@ -295,11 +293,10 @@ static void *uffd_handler_thread_fn(void *arg)
295293 }
296294
297295 clock_gettime (CLOCK_MONOTONIC , & end );
298- PER_VCPU_DEBUG ("userfaulted %ld pages over %lld.%.9lds. (%f/sec)\n" ,
299- pages , (long long )(timespec_diff (start , end ).tv_sec ),
300- timespec_diff (start , end ).tv_nsec , pages /
301- ((double )timespec_diff (start , end ).tv_sec +
302- (double )timespec_diff (start , end ).tv_nsec / 100000000.0 ));
296+ ts_diff = timespec_sub (end , start );
297+ PER_VCPU_DEBUG ("userfaulted %ld pages over %ld.%.9lds. (%f/sec)\n" ,
298+ pages , ts_diff .tv_sec , ts_diff .tv_nsec ,
299+ pages / ((double )ts_diff .tv_sec + (double )ts_diff .tv_nsec / 100000000.0 ));
303300
304301 return NULL ;
305302}
@@ -360,13 +357,12 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
360357 pthread_t * vcpu_threads ;
361358 pthread_t * uffd_handler_threads = NULL ;
362359 struct uffd_handler_args * uffd_args = NULL ;
360+ struct timespec start , end , ts_diff ;
363361 int * pipefds = NULL ;
364362 struct kvm_vm * vm ;
365363 uint64_t guest_num_pages ;
366364 int vcpu_id ;
367365 int r ;
368- struct timespec start ;
369- struct timespec end ;
370366
371367 vm = create_vm (mode , vcpus , vcpu_memory_bytes );
372368
@@ -514,12 +510,11 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
514510 }
515511 }
516512
517- pr_info ( "Total guest execution time: %lld.%.9lds\n" ,
518- ( long long )( timespec_diff ( start , end ). tv_sec ) ,
519- timespec_diff ( start , end ) .tv_nsec );
513+ ts_diff = timespec_sub ( end , start );
514+ pr_info ( "Total guest execution time: %ld.%.9lds\n" ,
515+ ts_diff . tv_sec , ts_diff .tv_nsec );
520516 pr_info ("Overall demand paging rate: %f pgs/sec\n" ,
521- guest_num_pages / ((double )timespec_diff (start , end ).tv_sec +
522- (double )timespec_diff (start , end ).tv_nsec / 100000000.0 ));
517+ guest_num_pages / ((double )ts_diff .tv_sec + (double )ts_diff .tv_nsec / 100000000.0 ));
523518
524519 ucall_uninit (vm );
525520 kvm_vm_free (vm );
0 commit comments