I. Task Switching
In the operating system, when a task needs to be switched from one task to another, it must be saved to the stack of the current task (the current task site mainly refers to the CPU-related registers ), then, reply to the site of the new task and execute the new task. This is called context switch or task switch.
Context switching brings a certain burden to the system. The more CPU registers, the heavier the burden. The switching time depends on the number of registers that need to be switched.
In μC/OS-ⅲ, task switching is a part related to the processor that needs to be transplanted. This part of code is stored in several special files: OS _cpu.h, OS _cpu_c.c, and OS _cpu_a.asm.
In μC/OS-ⅲ, task switching has two functions: task-level switching function --- osctxsw () and interruption-level switching function --- osintctxsw (). The two functions have the same functions. The difference is that the interrupt-level task switching function is called only by the interrupt scheduler, therefore, on-site storage has been performed before the call (on-site storage is required when the interruption occurs). Therefore, you only need to reply to the on-site storage of the new task without switching the task level. The task switching principle book is very clear and will not be detailed here. For details, see section 8.1 and section 8.2 p111 of this book.
Ii. Task Scheduling
μC/OS-ⅲ adopts the deprivation scheduling algorithm to always execute tasks with the highest priority in the ready state.
μC/OS-ⅲ allows multiple tasks with the same priority. These tasks use the time slice scheduling algorithm (that is, tasks with the same priority, each task runs for a fixed period of time ).
When a program calls certain μC/OS-ⅲ service functions, the scheduler starts. These time points are also called scheduling points.
μC/OS-ⅲ has two schedulers: osintexit () is called when the service interrupt program ends by using ossched () in the task-level code (). The difference between osintexit () Is that osintexit () processes interrupt nesting during execution and calls interrupt-level task switching during Task Switching. ossched () does not process interrupt nesting, use Task-level task switchover.
Task Switching and scheduling in the μC/OS-ⅲ System