ITIMER_VIRTUAL implementation seems wrong?

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Thu, 18 Sep 2025 15:23:14 UTC
Hi,

Paul Floyd has been trying to diagnose a hang they see in the valgrind
test suite under VirutalBox.  The test[0] is fairly simple and uses the
process virtual timer; just running it outside of Valgrind, you'll maybe
note that the runtime varies pretty wildly from real hardware to virtualized
environments.

I've only done a ~10 minute review on the virtual timer implementation,
but it doesn't seem quite right?  AFAICT, we only decrement from the
virtual timer if we managed to catch a hardclock while still executing
in usermode.

That seems like it would leave us open to shenanigans like this, because
they're effectively racing syscalls against timer interrupts and getting
quite unlucky, accumulating a pretty large error in the process.   This
probably isn't how the virtual timer is supposed to work, right?  It seems
like time from syscall <-> syscall and interrupt <-> syscall should still
be measured all the same.

Thanks,

Kyle Evans

[0] https://sourceware.org/git/?p=valgrind.git;a=blob_plain;f=none/tests/freebsd/bug452274.c;hb=HEAD