| 1 | | Dans cette section nous spécifions l'ordonnanceur d'ALMOS-MKH. Ce dernier est par cœur et a pour rôle de gérer les états des threads. TODO |
| | 1 | In this section, we describe the scheduling mechanisms used by ALMOS-MKH. |
| | 2 | |
| | 3 | == A. Threads List == |
| | 4 | |
| | 5 | There are two lists of threads in ALMOS-MKH: a list of ''user'' threads and a list of ''kernel'' |
| | 6 | threads. |
| | 7 | |
| | 8 | == B. Context Switches == |
| | 9 | |
| | 10 | ALMOS-MKH supports switching context among threads only when they do not hold any kernel locks. |
| | 11 | |
| | 12 | Context switches have two causes: |
| | 13 | * The currently-executing thread explicitly asks to be rescheduled. When such a thing happens, |
| | 14 | it is guaranteed that the current thread does not hold any kernel locks. |
| | 15 | * A rescheduling interrupt (such as a tick) was received and it is decided that another thread |
| | 16 | needs to execute. The mechanism to ensure that the currently-executing thread does not hold |
| | 17 | any kernel locks is more complex, and described below. |
| | 18 | |
| | 19 | When a rescheduling interrupt is received, the interrupt routine that is called gives a look |
| | 20 | at the currently-executing thread. If this thread does not hold any kernel locks, the rescheduling |
| | 21 | is performed right away. Otherwise, the interrupt routine adds a flag in the thread's structure, |
| | 22 | to indicate that a rescheduling is necessary. The interrupt routine then returns to the original |
| | 23 | context. |
| | 24 | |
| | 25 | The thread keeps executing, and at some point, will release its last lock. When this last release |
| | 26 | is performed, the thread will give a look at the rescheduling flag in its structure. If this flag |
| | 27 | is set, the thread performs the rescheduling itself: this behavior is the same as if it was the |
| | 28 | thread that had asked to be rescheduled in the first place. In this scenario, it is therefore |
| | 29 | guaranteed that no kernel locks are held. |
| | 30 | |
| | 31 | == C. Kernel Mode Preemption == |
| | 32 | |
| | 33 | ALMOS-MKH supports descheduling a userland thread that is currently in kernel mode - as a result |
| | 34 | of a syscall for example. |