VxWorks Learning Note - Real-Time Multitasking

xiaoxiao2021-04-10  559

VxWorks learning notes

§ Real-time Multitasking

1.Intuction

Real-time

A System IS Described As Being Deterministic if ITS Response Time Is Predictable. Deterministic response is the key to real-time performance.

Single task system

Disadvantages: 1) Each component cannot be performed according to different rates; 2) There is no priority; 3) Unable to seize; advantages: There is no overhead of task switching.

How VxWorks meets real-time requirements

Multi-task execution speed: 1) Lightweight task, context switching fast; 2) No determinism of overhead operations without system call: Priority-based sewage scheduling ensures high priority task response speed.

Task status

Ready Delay: Waiting for a mount of time to pass pend: waiting for an Object Event Pend & delay Suspend

Multi-tasking kernel

VxWorks Managing tasks is Wind kernal; use TCB tracking management tasks; TCB data structure definition: wind_tcb Get TCB pointer: Function tasktcb () for each Pend's Event, there is independent Queue

Context

Divided into two types: Synchronous, Asynchronous asynchronous Switch is the task caused by ISR to switch Synchronous needs to save the registers, so the speed is faster ISR's priority than task.

Priority scheduling

The preemptive scheduling is based on priority, high priority seizures low priority task re-scheduled time: 1) Kernal calls, 2) The high and low priority of Interrupts (EG System Clock Ticks) Priority depends on the requirements of the task timing, and Not the importance of mission

Round-Robin Scheduling

Act on the same priority tasks Round-robin scheduling is disabled by default To allow equal priority tasks to preempt each other, time slicing must be turned on:. KernelTimeSlice (ticks) -> clockRate = sysClkRateGet ()

Performance enhancements

All tasks reside in a common address space. 1) Makes intertask communication fast and easy. 2) Makes context switch faster (do not need to save and restore virtual address contexts). 3) A deviant task can corrupt other tasks. All tasks Run in supervisor (privileged) Mode. No system call overhead.

Multiitasking facilities

Message passing queues for intertask communication within a CPU Network routines for intertask communication between CPU's Semaphores to protect data which is shared by tasks Timers and other interrupts to trigger task execution I / O system facilities to read / write data to hardware devices2. Task basics

Mission composition

TCB Stack: Storage Automatic Variables and Functions Parameters

CREANG A TASK

Allocate Memory for the Stack and TCB from A Memory Pool. Initialize The Stack. Initialize The Tcb. Put Task Into Ready Queue. Newtid = Taskspawn ("Tmytask", 150, 0, 20000, Myroutine, Arg1, Arg2, 0, 0, 0, 0, 0, 0, 0, 0)

Task ID

A Task ID of Zero Refers To Task Making Call (Self). Related Functions: Taskidself, TaskidListGet, Taskidverify

Task name

Related functions: taskname, TaskNameToid

Task Priority

Timing Requirements Rather Than Hazy Ideas About Task Importance Should Govern Priorities Dynamically With: TaskPriorityget (TID, & Priority), TaskPrioritySet (TID, PRIORITY)

Task Stack

Fixed size after creation. The kernel reserves some space from the stack, making the stack space actually available slightly less than the stack space requested. Each byte in a task's stack is filled with 0xee when the task is created. The checkStack () function searches from the end of the stack for this value in order to find the maximum stack usage. VxSim targets add 8000 bytes to the requested stack size, to deal with simulated interrupts, which are handled on the stack of the current task.

Task Option

Taskoptionsget Taskoptionsset

Task Creation

During time critical code, task creation can be unacceptably time consuming. To reduce creation time, a task can be spawned with the VX_NO_STACK_FILL option bit set. Alternatively, spawn a task at system start-up which blocks immediately, and waits to be made ready When Needed.Task deletion

Related functions: taskdelete, exit

3. Task Control

RESTART

Related functions: Taskrestart is usually used for error recovery of a task to restart itself, is done by Task TRESTART

Suspend & resume

Related functions: tasksuspend, taskresume

DELAY

Related functions: taskdelay (ticks) delay 1/7 seconds: taskdelay (sysclkrateget () / 7) sysclkrateget: get the number of ticks per second of the system clock

Reentrant and Task Variables

Use only stack variables in applications. Protect the resource with a semaphore. Use task variables to make the variable private to a task. Task Variables cause a 32-bit value to be saved and restored on context switches, like a register.

Task hooks

User-defined code can be executed on every context switch, at task creation, or at ask deletion: taskSwitchHookAdd (), taskCreateHookAdd (), taskDeleteHookAdd () VxWorks uses a switch hook to implement task variables.

Task Information

-> TI

4. Use of error code

The global variable errno is used to save the error status of the current execution task; when the task context switch, Errno will save to the TCB of the task; the underlying function is set by errno according to the situation, the upper call function checks the value of the value of errno to determine the failure of the function call; error code Format: Module encoding (16BITS) error type (16bits); get description information by error code: shell command printRNO, function strrrror (); define user error code;

5. System task

Tusrroot Tlogtask Texctask Twdbtask

转载请注明原文地址:https://www.9cbs.com/read-133394.html

New Post(0)