46 | | The RUNNING thread can explicitly ask to be descheduled, when blocked on a shared resource. Before descheduling, the thread should release all kernel locks. |
47 | | But the scheduling policy being preemptive, the RUNNING thread can hold one (or several) kernel lock(s) when receiving a TICK interrupt. |
| 48 | The RUNNING thread can explicitly ask to be descheduled, when blocked on a shared resource. Before descheduling, the thread should release all taken kernel busy locks. But the scheduling policy being preemptive, the RUNNING thread can hold one (or several) kernel lock(s) when receiving a TICK interrupt. Therefore, the |
| 49 | busylock_acquire() function disables IRQs before it takes the lock, and the busylock_release() function restore IRQs only after it releases the lock. |
49 | | In this situation, ALMOS-MKH implements the following delayed context switch mechanism: |
50 | | 1. The RUNNING thread holding locks continues execution, but the THREAD_FLAG_SCHED is set in the running thread descriptor. |
51 | | 2. All kernel functions used to release kernel locks check this THREAD_FLAG_SCHED. When this flag is set, and the last lock is released by the calling thread, the sched_yield() is immediately executed. |
52 | | |
53 | | More generally, ALMOS-MKH supports descheduling of an USER thread that is currently in kernel mode - as a result of a syscall. In other words, syscalls can be interrupted by interrupts signaling the completion of an I/O operations, or by the TICK interrupt, requiring a context switch. |
| 51 | On the other hand, ALMOS-MKH supports descheduling of an USER thread that is currently in kernel mode - as a result of a syscall. In other words, some syscalls (not all) can be interrupted by interrupts signaling the completion of an I/O operations, or by the TICK interrupt, requiring a context switch. |