static void kvm_clock_test(void *data) { struct test_info *hv_test_info = (struct test_info *)data; long i, check = hv_test_info->check; for (i = 0; i < hv_test_info->loops; i++){ cycle_t t0, t1; long long delta; if (check == 0) { kvm_clock_read(); continue; } spin_lock(&hv_test_info->lock); t1 = kvm_clock_read(); t0 = hv_test_info->last; hv_test_info->last = kvm_clock_read(); spin_unlock(&hv_test_info->lock); delta = t1 - t0; if (delta < 0) { spin_lock(&hv_test_info->lock); ++hv_test_info->warps; if (delta < hv_test_info->worst){ hv_test_info->worst = delta; printf("Worst warp %lld %\n", hv_test_info->worst); } spin_unlock(&hv_test_info->lock); } if (delta == 0) ++hv_test_info->stalls; if (!((unsigned long)i & 31)) asm volatile("rep; nop"); } atomic_dec(&hv_test_info->ncpus); }
static void wallclock_test(void *data) { int *p_err = data; long ksec, offset; struct timespec ts; kvm_get_wallclock(&ts); ksec = ts.tv_sec; offset = ksec - sec; printf("Raw nanoseconds value from kvmclock: %" PRIu64 " (cpu %d)\n", kvm_clock_read(), smp_id()); printf("Seconds get from kvmclock: %ld (cpu %d, offset: %ld)\n", ksec, smp_id(), offset); if (offset > threshold || offset < -threshold) { printf("offset too large!\n"); (*p_err)++; } }