Basic Principles of RTOS: multi-task and scheduling-How freertos works

Source: Internet
Author: User

How freertos works-Basic Principles of RTOS: multi-task and Scheduling

Author: Gavin Lee Source: upsdn.net updated on: 2006-04-12

Basic Principles of RTOS
Multi-task
Scheduling
Context switching
Real-time application
Real-Time Scheduling

This section provides an overview of the real-time and multi-task concepts. You must understand these concepts before reading the next section.

Multi-task)

In an operating system, the kernel [Kernel]Is the core component. A linux-like operating system uses a kernel that allows concurrent user (simultaneously) access to the computer. It seems that multiple users (apparently) can execute multiple programs in parallel (concurrently.

Under the control of the operating system, each program being executed is a task [task]. If an operating system can execute multiple tasks in this way, it is called a multi-task [multitasking].

The use of multi-task operating systems simplifies the design of applications:
1. the operating system's multi-task and inter-task communication mechanism allows complex applications to be divided into a series of smaller and more manageable tasks.
2. Partitioning makes software testing easier. Work Breakdown within teams also facilitates code reuse.
3. Complex timing and order details can be deleted from application code. (Because) This is the responsibility of the operating system.

Multi-task vs concurrency

A traditional conventional processor can only execute one task at a time. However, through fast task switching, a multitasking operating system can make it look like an appear task is executed in parallel. This can be described below (depicted ). It shows the Execution Mode of the three tasks related to (with respect to) time. The task name is marked in color and written on the left side. The time increases from left to right, and the colored lines show that the task is being executed at a special time. The figure above demonstrates the Parallel Execution Mode perceived by the user. The figure below shows the actual multi-task execution mode.

---- All available tasks seem to be being executed, but only one task is actually being executed at any time.

 

Scheduling

Sched is the part in the kernel that determines which task should be executed at a specific time. The kernel can suspend (suspend)/resume (resume) A task many times during the life time of the task.

Scheduling Policy is an algorithm used by the scheduler to determine the task execution time. A (non-real-time) multi-user system policy is likely to allocate (allow) a "fair" (fair) processor time slice (proportion of processor time) to each task ). The policies used in real-time and embedded systems will be described later.

In addition to being unintentionally suspended by the RTOS kernel, a task can also suspend itself. If a task wants to delay a fixed period of time (that is, sleep), or wait (that is, block) for a resource to be available (such as a serial port ), or wait for an event to appear (such as a key press ). A blocked or sleep task cannot be executed and no processing time is assigned to it.

Number mentioned in:
1) Task 1 is running
2) Task 1 is suspended in the kernel.
3) Resume Task 2
4) Task 2 is being executed. for exclusive access, it locks a processor peripheral.
5) Task 2 is suspended in the kernel.
6) Restore task3
7) task3 tries to access the same processor peripherals and finds that it is locked. task3 cannot continue, so he suspends himself.
8) kernel Recovery Task 1
.............
9) Next (the next time), Task 2 is executed at 9. It completes access to the processor peripherals, so it is unlocked
10) then, Task 3 will be executed at 10 points. It finds that it can now access the processor peripherals, so it starts to execute until it is suspended by the kernel.

 

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.