Task Switching and scheduling in the μC/OS-ⅲ System

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.