In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to create tasks in the VxWorks system, the article is very detailed, has a certain reference value, interested friends must read it!
How to create tasks in VxWorks system.
The commonly used function is taskSpawn (). The prototype of the function in the 32-bit system is as follows:
Task can be thought of as composed of Stack and TCB. So the first step in taskSpawn () is to allocate memory for Stack and TCB, initialize them, and finally put the task in the Ready queue.
This function has many arguments, so let's take a look at them one by one.
Name
The name of the task, which is mainly used by developers when debugging in Shell. There is no limit to the character and length of the name, and you can even use NULL directly, and the system will automatically assign it a decimal number whose tN,N is incremented from 1. Even the names of different tasks can be the same, so if you manage tasks by name, be careful. Operating systems or applications usually use their ID when managing tasks. The name and ID can be converted to each other through these two functions
Priority
The priority of the task, which is based on which VxWorks schedules tasks. Priority ranges from 0 to 255, which can be changed or queried dynamically.
Note: among multiple tasks, the priority is relative. If there are only two tasks An and B in the system, and the priority is 1 and 10, or 1 and 100, respectively, the scheduling in both cases is exactly the same. Those with high priority will be preempted, and must wait for it to exit the Ready queue before the lower priority can occupy CPU. Unlike some operating systems that use time-sharing scheduling, the level of priority will affect the length of the time slice.
What is the appropriate priority setting in our own application? Many people are used to setting kernel tasks to 100 and user-mode tasks a little lower, 150 or 200, which is no limit, as long as the relationship between many application tasks is balanced. However, it is recommended that the priority of application tasks should not be higher than that of system tasks. For example, in "Common system tasks in Task", we mentioned that the priority of WDB tasks is 3 by default, so we try not to apply tasks higher than 4, otherwise it may affect debugging.
Options
Task options, in Bit units, vary from version to version, so try to use the macro definition of the option in your code instead of the corresponding value. For example, the options available in 6.9 are as follows.
LVX_FP_TASK-use a floating-point coprocessor, otherwise tasks with floating-point operations will not save the value of the floating-point register when switching, resulting in a floating-point exception. The special case is that floating-point instructions are generated when C++ statements are compiled, so this option must be enabled when C++ statements are called in a task.
LVX_NO_STACK_FILL-not populated with Stack
LVX_NO_STACK_PROTECT-does not provide overflow and underflow protection for Stack
LVX_ALTIVEC_TASK-use the Altivec instruction set (PowerPC only)
LVX_SPE_TASK-use the SPE engine (PowerPC only)
LVX_DSP_TASK-use DSP (SuperH only)
LVX_PRIVATE_ENV-support for private environment variables (actually cancelled in 6.9, only for compatibility)
StackSize
The stack of tasks, in Byte, allocated from the system memory pool. Once assigned, the size is fixed. If the allocated value is too large, it will increase the initialization time a little bit and waste part of the memory space, but the impact is not significant; while the allocation is too small, there is a risk of stack overflow, which is fatal. Therefore, in the development process, it is necessary to evaluate the specific values. So how do we know if the allocation is appropriate? You can use checkStack () in Shell to check.
EntryPt
The entry address of the task main function, which can contain up to 10 int parameters, arg1- arg10.
Return value
The return value of taskSpawn () is the ID assigned by Kernel to the task, which is a number of 32Bit and is globally unique. However, after the task exits, the ID value can be re-assigned to other tasks, that is, it can be reused. Tasks can query their own ID through taskIdSelf (), verify the existence of a task through taskIdVerify (), and get the current task list through taskIdListGet (). Many API in taskLib use task ID as a parameter. A value of 0 generally indicates the current task itself.
In addition, you can use taskCreate () to create a task, which just initializes the task and requires taskActivate () to put it in the Ready queue.
The advantage of doing it in two steps is that you can initialize the task when the whole system is initialized, and activate it when you need it, which is equivalent to reducing the activation time. In fact, taskSpawn () is the combination of the two.
The initialization of Stack and TCB in taskSpawn () is done in taskCreate (). The following is a piece of Benchmark data from many years ago.
You can see that under the hardware and software (Pentium3) configuration at that time, the time consuming of Kernel operation is generally microsecond, but taskSpawn () is much slower than other functions. Therefore, when the real-time requirements of the project are very high, you can consider using the combination of taskCreate () and taskActivate (). There is also a POSIX-style API that can be used to create a task or get a task handle, taskOpen (). This function is mostly used when supporting processes because it creates tasks as public objects so that multiple processes and Kernel can access each other. When we introduce RTP communication, we will talk about it in more detail.
The above is all the contents of the article "how to create tasks in VxWorks system". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.