VxWorks学习笔记-Real-Time Multitasking

原创 2006年06月25日 11:46:00

VxWorks 学习笔记

§ Real-Time Multitasking



  • A system is described as being deterministic if its response time is predictable.

  • Deterministic response is the key to real-time performance.


  • 缺点:1)各个构件无法按照不同的速率执行;2)没有优先级;3)无法抢占;

  • 优点:没有任务切换的开销。


  • 多任务

  • 执行速度快:1) 轻量级的任务,上下文切换快; 2)没有系统调用的开销

  • 运行的确定性:基于优先级的抢占式调度确保了高优先级任务的响应速度。


  • Ready

  • Delay: waiting for a mount of time to pass

  • Pend: waiting for an object event

  • Pend & Delay

  • Suspend


  • VxWorks中管理任务的是Wind Kernal

  • 使用TCB跟踪管理任务;

  • TCB数据结构定义:WIND_TCB

  • 获取TCB指针:函数taskTcb()

  • 对每一个PendEvent,有独立的Queue


  • 分为两种类型:SynchronousAsynchronous

  • Asynchronous切换是由ISR引起的任务切换

  • Synchronous需要保存的寄存器少,所以速度更快

  • ISR的优先级比任务高


  • 抢占式调度是基于优先级的,高优先级抢占低优先级的任务

  • 重新调度发生的时刻:1) Kernal calls2) Interrupts (e.g. System clock ticks)

  • 优先级的高低取决于任务计时的要求,而不是任务的重要性

Round-Robin 调度

  • 作用于相同优先级的任务

  • 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 (don’t 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.

Multitasking 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 devices



  • TCB

  • Stack:存储自动变量和函数参数

Creating 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).

  • 相关函数:taskIdSelf, taskIdListGet, taskIdVerify

Task Name

  • 相关函数:taskName, taskNameToId

Task Priority

  • Timing requirements rather than hazy ideas about task importance should govern priorities.

  • One can manipulate 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

  • 相关函数:taskDelete, exit



  • 相关函数:taskRestart

  • 通常用于错误恢复

  • 一个任务重起自身时,是由任务tRestart完成

Suspend & Resume

  • 相关函数:taskSuspend, taskResume


  • 相关函数:taskDelay(ticks)

  • 延迟1/7 秒:taskDelay (sysClkRateGet( ) / 7)

  • sysClkRateGetGet the number of ticks per second of the system clock

Reentrancy 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


  • 全局变量errno用来保存当前执行任务的错误状态;

  • 任务上下文切换时,errno会保存到任务的TCB中;

  • 底层函数根据情况设置errno,上层调用函数检查errno的值确定函数调用失败的原因;

  • 错误码格式:模块编码(16bits)+错误类型(16bits)

  • 由错误码获取描述信息:shell命令printErrno, 函数strerror( )

  • 定义用户自己的错误码;


  • tUsrRoot

  • tLogTask

  • tExcTask

  • tWdbTask


real time rendering 学习笔记(一)

Real time rendering 学习笔记(一)第二章 图形渲染管线图形渲染管线的作用是在给定视角、三维物体、光源、着色方程、纹理等条件时,产生或者渲染出一幅二维图像。实时渲染可以被粗略地分为三...

RCNN学习笔记(3):《Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks》

Abstract 目前最先进的目标检测网络需要先用区域建议算法推测目标位置,像SPPnet[7]和Fast R-CNN[5]这些网络已经减少了检测网络的运行时间,这时计算区域建议就成了瓶颈问题。本文中...

Real-Time Multitasking Executives.pdf

  • 2014年03月20日 20:57
  • 728KB
  • 下载

[深度学习论文笔记][Object Detection] Faster R-CNN: Towards Real-Time Object

Ren, Shaoqing, et al. “Faster R-CNN: Towards real-time object detection with region proposal network...

[深度学习论文笔记][Object Detection] You Only Look Once: Unified, Real-Time Object Detection

Redmon, Joseph, et al. “You only look once: Unified, real-time object detection.” arXiv preprint arX...


  • 2012年08月03日 16:21
  • 157KB
  • 下载

VxWorks 培训学习笔记(5)

  • 2009年07月07日 13:20
  • 34KB
  • 下载

TypeScript 学习笔记9: Real-World Application Development

终于要做一个完整的Web app了。除了使用TypeScript的各种语法糖,创建一个真正的web app还需要更多的功能:引用第三方库、declaration file、source map等等。...

Real Time Operating System VxWorks

  • 2012年03月18日 11:14
  • 4.49MB
  • 下载


  • 2017年11月03日 17:04
  • 1.4MB
  • 下载
您举报文章:VxWorks学习笔记-Real-Time Multitasking