fix maitake timer inaccuracy
Closed this issue · 2 comments
hawkw commented
- have a
now: Fn() -> u64
that doesrdtsc
or however it is you say “rdtsc” in ARM/RISC-V/etc- or, really, probably a trait since you might want to have a “stupid
Now
” impl that’s anAtomicU64
that only gets bumped when advancing the wheel (so you can still have the current thing, basically)
- or, really, probably a trait since you might want to have a “stupid
- have a
Timer::now()
/global free fnnow()
that does now- probably returning an instant newtype
- so that user code can use the wheel’s time as a time source for other stuff
- when creating a
Sleep
, do the following:- immediately take
now()
(call thatt0
) - when the wheel lock has been acquired, take
now()
again (t1
) - subtract the time elapsed between
t0
andt1
from the sleep’s total duration when adding it to the wheel - while we’re still holding the wheel lock after inserting the sleep, turn the wheel to
t1
- immediately take
hawkw commented
(the way you say rdtsc
on RISC-V is mcycle
IIRC)
hawkw commented
when creating a
Sleep
, do the following:
- immediately take
now()
(call thatt0
)- when the wheel lock has been acquired, take
now()
again (t1
)- subtract the time elapsed between
t0
andt1
from the sleep’s total duration when adding it to the wheel
it turns out i was kinda wrong about this part; as a Sleep
's deadline is already calculated immediately upon the sleep's creation, rather than after we get the wheel lock. so, inaccuracy is primarily just due to the fact that time "doesn't advance" while ticking the scheduler, in the current design, and not due to wheel lock delays.
- while we’re still holding the wheel lock after inserting the sleep, turn the wheel to
t1
we should still do this part, though (and i haven't done it yet).