Skip to main content

Module timers

Module timers 

Source
Expand description

An earliest-deadline-first timer queue.

One queue for a whole driver, not a task per timer. A busy proxy holds tens of thousands of live timers; spawning a task for each is how a stack acquires a scheduling problem nobody can profile.

The queue does not read the clock. now is an argument to TimerQueue::set and to TimerQueue::take_due, so a driver on virtual time — or a test asserting when a retransmission was scheduled rather than sleeping until it happens — uses the same queue the endpoint does. A queue that called Instant::now() internally would be unusable by either, which is what this one used to be.

It is generic over its key for the same reason: the endpoint keys on (TransactionKey, Timer), and nothing about earliest-deadline-first scheduling cares.

And it is generic over its instant, which is what makes the paragraph above true rather than merely intended. [tokio::time::Instant] has only two constructors — now(), which reads the machine clock, and from_std, which needs a std::time::Instant that has no zero either — so a discrete-event simulator on virtual time had no instant to hand in and could not build one. The type parameter defaults to [tokio::time::Instant], so TimerQueue<K> still names exactly what it always named and every existing caller is untouched.

Structs§

TimerQueue
Pending timers, earliest first.