[LTP] [PATCH 4/7] KVM: Add async communication helper functions

Cyril Hrubis chrubis@suse.cz
Tue May 23 14:13:42 CEST 2023


Hi!
> +int tst_kvm_wait_guest(struct tst_kvm_instance *inst, int timeout)
> +{
> +	volatile struct tst_kvm_result *result = inst->result;
> +	int32_t res;
> +	time_t start = time(NULL);
> +
> +	while ((res = result->result) != KVM_TSYNC) {
> +		if (res == KVM_TEXIT)
> +			return res;
> +
> +		if (timeout >= 0 && start + timeout <= time(NULL))
> +			return -1;

Can we please avoid using wall clock time for timeouts? That is broken
by desing, since the time is continually adjusted by ntp daemon these
days and can jump back and forth...

This should be really:

	struct timespec start

	tst_clock_gettime(CLOCK_MONOTONIC, &start);

	while (...) {
		struct timespec now;

		tst_clock_gettime(CLOCK_MONOTONIC, &now);

		if (tst_timespec_diff_ms(now, start) >= timeout_ms)
			return -1;

> +		usleep(1000);
> +	}
> +
> +	return 0;
> +}

The rest looks good.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list