hawkw / mycelium

🍄 an alleged 'operating system'
https://mycelium.elizas.website
MIT License
548 stars 20 forks source link

fix maitake timer inaccuracy #474

Closed hawkw closed 8 months ago

hawkw commented 10 months ago
hawkw commented 10 months ago

(the way you say rdtsc on RISC-V is mcycle IIRC)

hawkw commented 10 months ago

when creating a Sleep, do the following:

  • immediately take now() (call that t0)
  • when the wheel lock has been acquired, take now() again (t1)
  • subtract the time elapsed between t0 and t1 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).