1.1. Task Management
Task is a image of code running, from the perspective of the system, the task is the minimum run unit of the competitive system resource. Tasks can be used or waited for system resources such as CPU, I / O devices, and memory spaces, and independent of other tasks, run with them concurrently (so). VxWorks cores can quickly share the vast majority of resources of the system, and there are independent contexts to control individual threads.
1.1.1. Task structure
Multi-task design can interrupt the task being executed, and respond to the internal and external events in the determined time. The VxWorks real-time kernel WIND provides a basic multitasking environment. From the surface, multiple tasks are executing simultaneously, in fact, the system kernel makes them alternately run according to a scheduling policy. The system scheduler uses the data structure of the task control block to manage task scheduling functions. Task Control Blocks are used to describe a task, and each task is associated with a TCB. The TCB includes the current state of the task, priority, event or resource, start address of the task code, the initial stack pointer, etc. This information is used when the scheduler is initially activated while the task is initially activated.
In addition, TCB is also used to store "context" of the task. The context of the task is all the information you want to save when the task in an execution is stopped. When the task is re-executed, you must recover the context. Typically, the context is the current state of the computer, that is, the content of each register. Like the content to be saved in the event of an interrupt. When a task switch occurs, the context of the currently running task is stored in the TCB, and the context of the task to be executed is removed from its TCB, and in each register. Thus, the task is executed, the starting point of the execution is the position where it is aborted before running.
In VxWorks, the memory address space is not part of the task context. All code runs in the same address space. If each task requires the respective memory space, you need to choose from VxVMI support.
1.1.2. Task status and state migration
One task of the real-time system can have a variety of states, and the most basic state has four:
Ready: Task only waiting for the system to assign CPU resources;
Suspend state: The task needs to be blocked by certain resources that cannot be utilized;
Sleep state: If the system does not need a task job, this task is in a sleep state;
Delay state: State when the task is delayed;
When the system function is operated on a task, the task migrates from one state to another. Tasks in any state can be deleted.
State migration call
Ready-state ----> Suspended Semtake () / msgqRecEive ()
Ready-state ----> Delayed state Taskdelay ()
Ready-state ----> Sleeping Taskspend ()
Suspend state ----> Ready Semgive () / msgqsend ()
Suspend state ----> Tembspend ()
Delay state ----> Ready expired delay
Delay state ----> sleep state taskspend ()
Sleep state ----> Ready TaskResume () / taskactivate ()
Sleep state ----> Suspended TaskResume ()
Sleep state ----> Delayed state TaskResume ()
1.1.3. Task Scheduling Strategy
Multi-tasking scheduling must be used to assign CPUs to read state tasks with a scheduling algorithm. The Wind kernel adopts priority-based preemptive scheduling as its default policy, and it also provides a rotation adjustment method. Based on priority preemptive scheduling, it has many advantages. This scheduling method specifies a different priority for each task. The highest priority task that is not in a suspension or dormant state will run. When the higher priority task is entered into runtime, the system kernel immediately saves the context of the current task, switching to a higher priority task.
Multi-tasking scheduling must be used to assign CPUs to read state tasks with a scheduling algorithm. The Wind kernel adopts priority-based preemptive scheduling as its default policy, and it also provides a rotation adjustment method.
Based on priority preemptive scheduling, it has many advantages. This scheduling method specifies a different priority for each task. The highest priority task that is not in a suspension or dormant state will run. When the higher priority task is entered into runtime, the system kernel immediately saves the context of the current task, switching to a higher priority task.
The WIND core division priority is 256 (0 ~ 255). Priority 0 is the highest priority, and the priority 255 is the lowest. When the task is created, the system allocates task priority based on the given value. However, priority can also be dynamic, which can be changed by user using the system when running, but cannot be changed by the operating system at runtime.
The rotation schedule is assigned to each of the same priority tasks in the read state. The length of the time sheet can be specified by the system call kernelTimeSlice () via the input parameter value. Obviously, each task has a runtime counter, and the task is running every time. 1. After a task uses the time slice, the task switch is performed, stop executing the currently running task, put it into the tail of the queue, set zero the runtime counter, and starts the next task in the ready queue. This task is saved when the runtime is a higher priority task, and the runtime counter of this task is saved until the task is run next time.
1.1.4. Grab the prohibition
The Wind kernel can work and fail by calling tasklock () and task () to make the scheduler work and invalid. When a task calls tasklock () makes the scheduler fail, there is no priority-based preemption when the task is running. However, if the task is blocked or suspended, the scheduler takes the highest priority task run from the ready queue. When setting the preemptive task is released, the seizure is prohibited when the runtime is started again. This seizures disabled to prevent the task from switching, but does not work on interrupt processing.
1.1.5. Abnormally handling
The error of the program code and the data, such as illegal commands, bus, or address errors, zero-free, etc. VxWorks exception handle package, generally will cause an abnormal task to sleep, save the status value of the task in an abnormal error. The kernel and other tasks continue to be executed. Users can view the current task status with the Tornado development tool to determine the sleeping task.
1.1.6. Task Management
Task Management of the VxWorks kernel provides a function of dynamically created, deleting, and control tasks, and the specific implementation is called by the following system:
TasksPawn () creates (generated and activated) new tasks
Taskinit () initializes a new task
Taskactivate () activates an initialized task
TaskName () gets the task name by the task ID number
TaskNameToid () gets the task ID number by the task name
TaskPriorityGet () Get the priority of the task
Taskissuspended () checks if the task is suspended
TaskisreadY () checks if the task is ready to run
Tasktcb () gets a pointer to a task control block
TaskDelete () Abort the specified task and free memory (only task stack and control block) Tasksafe () protection is called task
Taskspend () Suspension a task
TaskResume () Restore a task
Taskrestart () restarts a task
TaskDelay () delays a task