I'm reading about RTOS and there is a concept, regarding the implementation of a scheduler, that I don't understand.
One way of designing real-time software tasking is dividing the execution in time slots. This implies that, if a task T
starts executing but it can't finish its work within the defined time slot, the RTOS must save the state of T
, interrupt it and re-queue it for later execution.
Let's say that the implementation of a task is merely a procedure that the RTOS calls. My question is:
How can you implement the interrupting mechanism? I mean, if the RTOS starts executing a user procedure, it won't be able to check whether or not the task is out-of-time untile the procedure returns, nor it won't be able to interrupt it if necessary, right?
As far as I understand, there must be a mechanism through which the RTOS can do actions between the execution of each user task's instructions. I guess this is achieved trough the tick interruption, does this mean that the RTOS must perform this kind of operations (re-scheduling, interrupting tasks, save their state, etc.) in the tick interruption handler?
Any preemptive scheduler, not just so-called RTOSes, has the ability to stop the "normal" execution stream of userland code. The source for interruptions is not necessarily a "tick" timer but also any other external source which the system was designed and configured to accept. External in this sense means outside the CPU instruction execution, however fine grained you want to see this distinction. Even the cache/memory subsystem is "outside" in some (most) modern operating systems to facilitate loading from disk after a page miss e.g.
IMHO this question is way too broad and should be moved to a more apt stackexchange site.