Hardware timers just fire an interrupt to indicate they've expired, they don't set arbitrary bits in memory to indicate expiration.robfinch wrote: ↑Mon Jul 14, 2025 6:16 pmYes, it is an O(n) search but I think it could be done extremely fast. 1024 timers could be represented by 32 32-bit timeout status flags. It is just a matter of searching 32 regs for a non-zero status indicating a timer timed out. It may also be possible to have hardware accelerate the bit search, so it would just be a loop for how many ever timers expired.So, to avoid an O(n) insert time, you want the ISR to do an O(n) search of outstanding timers looking for expired timers?
That is the job of your ISR.
What hardware are you targeting? I'm not aware of any platform with an arbitrary number of independent hardware timers.
Nor a platform that has an arbitrary number of interrupt lines.
More typically, the platform will provide A timer of some description. This may be all you get, or you may get a per-CPU timer instead of or as well, such as the timer built into the local APIC of each x86 core.
But hardware timers are a very limited resource, and have to be multiplexed to support an arbitrary number of software timers.
And that multiplexing requires some sort of queue on which timers sit waiting to expire.
And that queue should be sorted by expiration deadline, to make it quick and easy to bound the search to just those timers that have expired.