Whenever a process has to be preempted, Linux sets a flag in the task structure of the currently running process. When control reaches one of the safe points (eg. return from a system call), the schedule() function is called to determine the next process to be scheduled and to context switch to that process. The schedule() function has been changed to support the resource container framework.
The schedule() routine updates the CPU usage of the current resource container by adding to it the CPU usage of the currently running process. Then it checks whether any process has become runnable in any higher class than that of the current container. If there is any, the highest class runnable resource container is the next resource container to be scheduled. Otherwise the current container is scheduled.
Once the next resource container is found, the class specific scheduler function of that container is called to decide on the next task to be run. This function need not necessarily return a task in its own scheduler binding since it could allocate the CPU to a child container and call its scheduler function, or its CPU time allotted could have expired by this time, in which case it calls the scheduler function of the parent to give back the control of the CPU (subsection 2.3).
If the class specific scheduler function of the next resource container to run returns NULL, then scheduling restarts from the root container.
After finding out which task to schedule next, the container to which this task is bound is saved. If the next task to be scheduled is not the currently running one, a context switch is effected.