Re: PSA: Clock drift and pkgin
Johnny Billquist <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.kernel |
|---|---|
| Message-ID | <[email protected]> |
On 2023-12-23 14:35, Mouse wrote:
>>>> } else if (sec <= (LONG_MAX / 1000000))
>>>> ticks = (((sec * 1000000) + (unsigned long)usec + (tick - 1))
>>>> / tick) + 1;
>>> The delay is always rounded up to the resolution of the clock, so
>>> waiting for 1 microsecond waits at least 10ms.
>
> But it is increased by 1 tick when it is an exact multiple of the clock
> resolution, too. For sleeps, that makes some sense. For timer
> reloads, it doesn't.
I would probably agree that for timer reloads it should not do that
rounding up when the interval is evenly divisible. It is a very
different case than a sleep. For the reload we know that this happens at
a specific time.
> I could of course be wrong about that code being responsible, but
> reading realtimerexpire() makes me think not; it uses tshzto, which
> calls tstohz, which calls tvtohz, which is where the code quoted above
> comes from. Maybe realtimerexpire should be using other code?
Agreed.
>> Two options are to increase HZ on the host as suggested, or halve HZ
>> on the guest.
>
> I suppose actually fixing the bug isn't an option?
>
> I don't know whether that would mean using different code for timer
> reloads and sleeps or what. But 1.4T is demonstration-by-example that
> it is entirely possible to get this right, even in a tickful system.
> (I don't know whether 1.4T sleeps may be slightly too short; I haven't
> tested that. But, even if so, fixing that should not involve breaking
> timer reloads.)
A tickless system do not fundamentally change anything either. You can't
go below the resolution of a timer, and sleeps are supposed to be
sleeping for *at least* the given time, but it could be more.
But in this case, we end up where the expected, and reasonable behaviour
would be to get alarms/interrupts at the specified frequency, because it
is the resolution of the clock, but we are in fact rounding it up to the
double amount of time between alarms/interrupts. Not what I think anyone
would have expected.
Johnny
--
Johnny Billquist || "I'm on a bus
|| on a psychedelic trip
email: [email protected] || Reading murder books
pdp is alive! || tryin' to stay hip" - B. Idol