3 ms·
Aren't most modern CPUs tickless[1]? They effectively work the way you describe, the scheduler will sleep as long as possible instead of just "ticking" a NOP if
by simias 6y ago
Aren't most modern CPUs tickless[1]? They effectively work the way you describe, the scheduler will sleep as long as possible instead of just "ticking" a NOP if nothing is scheduled.
The problem is that what you describe is very hard to guarantee in a non-realtime OS. Modern CPUs are pretty damn fast, that's true, but they can't task switch on a dime. The delay between an IRQ being triggered and task being scheduled can vary pretty wildly, especially if the CPU is already under a heavy load.
You can still try your luck with nanosleep() and see how that treats you. It might work. It probably won't always work.
In general if you need to react so fast on some event you probably want to avoid polling at all costs. That's why most OSs are fine relaxing timer constraints for better overall performance. If you can't react on an external interrupt and you really need to be reactive busy-polling is still probably your best bet.
[1] https://en.wikipedia.org/wiki/Tickless_kernel https://en.wikipedia.org/wiki/Tickless_kernel