CN102043668B - Method for activating task in embedded real-time operating system for multiple times - Google Patents
Method for activating task in embedded real-time operating system for multiple times Download PDFInfo
- Publication number
- CN102043668B CN102043668B CN 201010582446 CN201010582446A CN102043668B CN 102043668 B CN102043668 B CN 102043668B CN 201010582446 CN201010582446 CN 201010582446 CN 201010582446 A CN201010582446 A CN 201010582446A CN 102043668 B CN102043668 B CN 102043668B
- Authority
- CN
- China
- Prior art keywords
- task
- ready
- tcb
- priority
- control block
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
- 238000000034 method Methods 0.000 title claims abstract description 19
- 230000003213 activating effect Effects 0.000 title claims abstract description 8
- 230000004913 activation Effects 0.000 claims abstract description 79
- 230000015572 biosynthetic process Effects 0.000 claims description 103
- 238000005755 formation reaction Methods 0.000 claims description 103
- 230000003068 static effect Effects 0.000 claims description 8
- 230000008569 process Effects 0.000 claims description 7
- 238000011084 recovery Methods 0.000 claims description 4
- 230000001427 coherent effect Effects 0.000 claims description 3
- 238000003780 insertion Methods 0.000 claims description 2
- 230000037431 insertion Effects 0.000 claims description 2
- 238000010586 diagram Methods 0.000 description 21
- 230000000875 corresponding effect Effects 0.000 description 19
- 230000008859 change Effects 0.000 description 5
- 230000007246 mechanism Effects 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 3
- 230000007704 transition Effects 0.000 description 2
- 230000002596 correlated effect Effects 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000012163 sequencing technique Methods 0.000 description 1
- 230000026676 system process Effects 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
Images
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a method for activating a task in an embedded real-time operating system for multiple times. In the method, ready blocks are used, and each ready block (RB) has two elements, namely a pointer to the next RB and a pointer to a corresponding task control block (TCB). Simultaneously, a data structure of the conventional TCB is improved and an element for recording the current activation frequency of the task is added into the TCB. Therefore, a structure queuing in a ready task queue is the RB which only has two elements and occupies storage spaces smaller than spaces occupied by the TCB queuing directly; and each task in the system only has one control block all the time, the subsequent instance can be operated only when the previous instance finishes operating or is terminated, namely a plurality of instances in one task are not completely independent of one another, and a new thread cannot be created by activating the task for multiple times.
Description
Technical field
The invention belongs to the auto electronic control technology field, more specifically say, relate to a kind of method of activating task in embedded real-time operating system for multiple times.
Background technology
1, the requirement that repeatedly activates about task in the OSEK standard
In the auto electronic control technology field, the controller system of some automotive electronics need to use embedded real-time operating system, so that the application software running environment of multitask to be provided.OSEK/VDX has proposed the embedded real-time operating system standard in relevant Vehicle Electronic Control field, OSEK is Open Systemsand the Corresponding Interfaces For Automotive Electronics, open system and the interface software standard of the German automobiles industry member automotive electronics of uniting release in 1993, and VDX is Vehicle Distributed Executive, the standard similar to OSEK that the french car industry member proposes, 1994 and the merging of OSEK standard, thus the OSEK/VDX standard system formed.
Fig. 1 is the state transition graph of basic task.
At the Operating of OSEK/VDX standard System Specification Version2.2.2, July 5th in 2004, has proposed in the application system of a multitask concept that basic task (hereinafter to be referred as task) can repeatedly be activated.Its concrete meaning is:
(1), the task in a system can repeatedly be activated.The state of task has three kinds of run mode, ready attitude and pending states, as shown in Figure 1.
The reason of changing between relevant task status is as shown in table 1:
Ready attitude | Run mode | Pending state | |
Ready attitude | - | Operating system is dispatched | - |
Run mode | Be preempted | - | Stop |
Pending state | Activate | - | - |
Table 1
In table 1, the task of being in run mode is just moving in CPU of task, is in the task of ready attitude just in the distribution of waiting for CPU resource, and the task of being in pending state can not participate in the distribution of cpu resource.
(2), task is called activation from the process that pending state changes ready attitude into.Activate a task is that the ActivateTask or the ChainTask funcall that use operating system to provide are completed.
(3), in the situation that configuration allows, task can repeatedly be activated.What is called repeatedly activates, and just refers to that after certain task in system had been in the state that is activated, task had been in run mode or ready attitude, situation about being activated again.This code that is equivalent to this task has increased again an example that can move in system, have simultaneously in other words a plurality of ready task objects with identical function in system, or be called task instances.
(3), as long as do not reach the maximum activation number of times that configures, new activation behavior is feasible.The new task instances that activates need to be queued up in the original priority formation of its configuration, and by the sequencing that activates, begins to queue up from the formation afterbody.
(4), the new task instances that activates when it moves for the first time, operating system need to guarantee to begin to carry out from article one instruction of its code.
(5), be not fully independently between the Multi-instance of task, only have after (being terminated) completed in the example operation of its front, the example of back could move, i.e. new activation behavior can not create new execution thread.
2, the problem of existing RTOS Tasks Management administrative mechanism
Existing embedded real-time operating system adopts the ready task formation that the task of being in run mode, ready attitude is managed usually.The ready task formation is used for the ready task of management system, comprises operation task unique in system, and the ready task on equal priority is ranked.Ready task formations all in system form array, and the length of array equals the greatest priority number of system, and each array element is exactly a ready task formation, and corresponding priority.
Fig. 2 is the ready task queue structure schematic diagram of existing embedded real-time operating system
As shown in Figure 2, suppose total n+1 priority in certain system, ready task formation array just has altogether n+1 element, and numbering is from 0~n, and numbering has also represented the priority of task simultaneously.Such as the priority of all tasks of queuing up in No. 0 formation is all 0, the priority of all tasks of queuing up in No. 1 formation is all 1, by that analogy.The form of each ready task formation is a single-track link table, such as the TCB in Fig. 2
00~TCB
0XForm a single-track link table, TCB
20~TCB
2yForm a single-track link table, etc.TCB is the abbreviation of task control block (TCB) (Task Control Block), and its subscript is that the two dimension of TCB is numbered as 00~0x, 20~2y, n0~nz etc., and two dimensions represent respectively the residing priority of this TCB and its sequence number in formation, such as TCB
00The priority of expression task is 0, and its sequence number in formation is 0; And TCB
2yThe priority of expression task is 2, and its sequence number in formation is y.Because the ready task quantity of each priority is not necessarily identical, so the maximum sequence number of each formation is also not necessarily identical.Such as system shown in Figure 2, numbering is that priority is that in 0 formation, total x+1 task is in queuing, and its maximum sequence number is x; Numbering is that priority is that in 2 formation, total y+1 task is in queuing, and its maximum sequence number is y.Each formation has a head pointer and tail pointer, points to respectively first task control block (TCB) and last task control block (TCB) of formation.Such as in being numbered 2 formation, head pointer Head2 points to TCB
20, tail pointer Tail2 points to TCB
2y
The operation of ready task formation is comprised add ready task, obtain the earliest ready task, take off ready task etc.Table 2 is task status transformation matrices, the principle below follow the position when task is placed in ready queue or moved:
● when inserting new ready task, insert from the formation afterbody, so the head pointer of ready task formation points in this priority ready the earliest task, tail pointer points in this priority ready at the latest task.
● when operating system is carried out task scheduling, need to obtain the highest ready task of current priority, this task must be the task of the ready task formation gauge outfit of certain priority.
● when current operation task priority changed, during as the operation task releasing resource, its priority can reduce, and it is inserted into the head of the task queue of the priority after changing.
● when task status changed, the position of task in formation can change, and when taking off current operation task or ready task, must be the task of formation head.Task only has from run mode just can become pending state, and therefore will hanging up of task must be first task in formation, so adopt single-track link table just can satisfy the operation requirements of ready task formation.
Table 2
Adopt existing RTOS Tasks Management administrative mechanism, can not satisfy the functional requirement that the OSEK/VDX standard repeatedly activates for task, distribute a task control block (TCB) because they when creating new task instances, are all this task instances, this can produce the problem of 2 aspects:
A), task control block (TCB) comprised all information of task run, storage space takies larger;
B), each task control block (TCB) has represented an execution thread, if be that each new task is distributed a controll block, independently between them, this does not meet the requirement of the OSEK/VDX standard of analyzing the front: be not fully independently between the Multi-instance of task, only have after (being terminated) completed in the example operation of its front, the example of back could move; New activation behavior can not create new execution thread.
Summary of the invention
The object of the invention is to overcome the deficiencies in the prior art, provide in a kind of embedded real-time operating system, between the Multi-instance of task be not fully independently and new activation behavior can not create the method that the task of new execution thread repeatedly activates, to solve the problem of traditional RTOS Tasks Management administrative mechanism, satisfy the OSEK/VDX standard for the functional requirement of automotive electronics embedded OS.
For achieving the above object, the method for activating task in embedded real-time operating system for multiple times of the present invention is characterized in that, comprises the following steps:
(1), set up a ready task formation array and be used for the management ready task
Ready task on equal priority is ranked, form a plurality of ready task formations identical with priority quantity; All ready task formations form array, and the length of array equals priority number, and each array element is a ready task formation, and corresponding priority;
Ready task in the ready task formation is with ready indication, two elements are arranged in each ready, namely refer to the pointer of next ready and the pointer of the corresponding task control block (TCB) of sensing, if ready is positioned at ready task formation last position, its pointer that points to next ready be sky;
Each ready task formation has a head pointer and tail pointer, point to respectively first ready of the ready task formation and last ready, when head pointer is used for the tasks carrying of corresponding priority, search first task, when tail pointer is used for the insertion of new ready, search ready of afterbody, if there is no ready task in the ready task formation, head pointer and tail pointer are empty;
(2), the data structure of task control block (TCB) is improved
2.1, task control block (TCB) comprises following element:
● task status
Task status is used for the logger task state, and its value is: operation, ready, hang-up and ready and operation for the first time;
When being ready, task is moved by recovering its context when the state value of task; When the state of task was ready and moves for the first time, operating system began to carry out from the task code entry address;
● the current activation number of times of task
The current activation number of times of task is used for the current activation number of times of logger task, activates example whenever task increases by one, and the value of this element adds 1; Whenever an example end of run of task, the value of this element subtracts 1; When the current activation number of times of task was reduced to 0, the state of this task became pending state;
● the task current priority
The task current priority is used for the current priority of logger task, and its value has represented the priority of that example that task may be moved the earliest;
● the task configuration information list index
The task configuration information list index points to the task configuration information structure, can obtain the information of the static configuration of task by it;
● the task context pointer
The task context information of task context pointed operating system storage can be obtained the contextual information of task by it, and when being ready, this task is moved by recovering its contextual information when the state value of task;
2.2, the information in the task configuration information structure is all by user's static configuration, immovable in the operational process of task, its coherent element is as follows:
● the task code entry address
Can obtain article one function code of task by the task code entry address, when the state of task was ready and moves for the first time, operating system was from the entry address execution of task code;
● the base priority of task
When task was newly activated an example, ready of this example was inserted into corresponding formation afterbody according to this priority;
● the maximum activation number of times of task
The maximum activation number of times of task records the maximum activation number of times that this task allows, when attempting to activate a task, if its current activation number of times less than the configuration the maximum activation number of times, task can successfully be activated, but namely increase an operation task example, otherwise can not be activated;
(3), the operation that repeatedly activates of task
3.1, increase of task and activate example
A, the task control block (TCB) of this task is carried out following operation:
1), judge at first whether the current activation number of times of task in task control block (TCB) has equaled the maximum activation number of times of the task in the task configuration information structure;
2) if the current activation number of times of task equals the maximum activation number of times of task, can not increase again one and activate example, program is returned;
3) if the current activation number of times of task less than the maximum activation number of times of task, obtain a ready of free time, and the pointed task control block (TCB) that it points to corresponding task control block (TCB) is set, with ready new afterbody that is inserted into the corresponding ready task formation of original priority of task: with new ready of inserting of pointed of next ready of the former last sensing of ready of this ready task formation, the tail pointer of this ready task formation points to new ready of inserting; The current activation number of times of task is added 1;
If the task current state is pending state, revising in task control block (TCB) task status is ready and operation for the first time;
If the priority of the new activate a task of priority ratio of the current operation task of b operating system is low, and system satisfies the executive condition of scheduler program, and operating system is carried out task scheduling; If the result of scheduling is the new task run that activates, by the task context pointer in the task control block (TCB) of current operation task, preserve the context of current operation task, and the state of revising activate a task is ready, jump to the place, code entry address of activate a task, the operation of beginning activate a task;
3.2, the current running example that ends task
1), ready with current running example returns to system;
2), the current activation number of times of the task of task control block (TCB) is subtracted 1;
3), judge whether the value of the current activation number of times of task is 0, if be not 0, task status be set to ready and for the first time the operation; If the current activation number of times of task is 0, task status is set to pending state;
4) adjusting the task current priority is the base priority of the task in the task configuration information structure;
5) if system satisfies the executive condition of scheduler program, operating system is carried out task scheduling; For ready of the task of the needs of new scheduling operation, check the task status of ready task control block (TCB) pointed, if be ready, directly come the operation of recovery tasks by recovering its context, if be ready and operation for the first time, it is ready revising task status, jumps to place, task code entry address, the operation of beginning task.
Goal of the invention of the present invention is achieved in that
In order to solve the problem of traditional RTOS Tasks Management administrative mechanism, satisfy the OSEK/VDX standard for the specific function requirement of automotive electronics embedded OS, the present invention designs a kind of method that has realized that task repeatedly activates, and in other words traditional task management mechanism is improved:
In order to satisfy the processing that task is repeatedly activated, the implementation method that is different from traditional embedded real-time operating system, the present invention does not directly use task control block (TCB) to queue up in the ready task formation, but used a kind of data structure of queuing up of being used for specially: ready, we are referred to as ReadyBlock, be abbreviated as RB, two elements are arranged in each ready, namely point to the pointer (pointerToNextRB) of next ready and the pointer (pointerToTCB) of the corresponding task control block (TCB) of sensing.The pointer that points to next ready is used for ready formation that connects into the chain sheet form, and the pointer that points to corresponding task control block (TCB) is used for access task controll block; Simultaneously, the data structure of traditional task control block (TCB) is improved, increased the element of the current activation number of times of logger task in task control block (TCB).Because this operating system call is complete static configuration, therefore in the design of data structure, the information that configuration is relevant is independent, is placed on specially in the task configuration information structure maximum activation number of times that logger task allows in this structure.Like this, the structure of queuing up in the ready task formation is ready, and it only has two elements, and it is less than the space of directly queuing up with task control block (TCB) to taking of storage space; In system, each task only has a controll block to exist all the time, only after its previous example operation is completed or is terminated, the example of its back could move, and namely not exclusively independent between the Multi-instance of a task, the behavior that repeatedly activates of task can not create new thread.
Description of drawings
Fig. 1 is the state transition graph of basic task;
Fig. 2 is the ready task queue structure schematic diagram of existing embedded real-time operating system;
Fig. 3 is the improved ready task of the present invention queue structure schematic diagram;
Fig. 4 is task control block (TCB) and a kind of embodiment structural drawing of configuration information structure in the present invention;
Fig. 5 is the variation schematic diagram of task status in embodiment of the invention operating system process;
Fig. 6 is t0 shown in Figure 5 ready task queue structure schematic diagram constantly;
Fig. 7 is t1 shown in Figure 5 ready task queue structure schematic diagram constantly;
Fig. 8 is t2 shown in Figure 5 ready task queue structure schematic diagram constantly;
Fig. 9 is t3 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 10 is t4 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 11 is t5 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 12 is t6 shown in Figure 5~t9 ready task queue structure schematic diagram constantly;
Figure 13 is t10 shown in Figure 5~t12 ready task queue structure schematic diagram constantly;
Figure 14 is t13 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 15 is t14 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 16 is t15 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 17 is t16 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 18 is t17 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 19 is t18 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 20 is t19 shown in Figure 5 ready task queue structure schematic diagram constantly;
Figure 21 is t20 shown in Figure 5 ready task queue structure schematic diagram constantly.
Embodiment
Below in conjunction with accompanying drawing, the specific embodiment of the present invention is described, so that those skilled in the art understands the present invention better.What need to point out especially is that in the following description, when perhaps the detailed description of known function and design can desalinate main contents of the present invention, these were described in here and will be left in the basket.
Embodiment
Fig. 3 is the improved ready task of the present invention queue structure schematic diagram.
As shown in Figure 3, in the present embodiment, the numbering of task control block (TCB) TCB becomes one dimension, and its subscript has represented the numbering of task, such as task control block (TCB) TCB
1Represent the controll block of task 1, TCB
2Represent the controll block of task 2, by that analogy.Ready RB substituted the position of task control block (TCB) TCB in Fig. 2, and the numbering of ready RB is two-dimentional, and two dimensions represent respectively this ready residing priority of RB and its sequence number in formation, such as RB
00The priority of expression task is 0, and its sequence number in formation is 0; And RB
2yThe priority of expression task is 2, and its sequence number in formation is y.Because the ready task quantity of each priority is not necessarily identical, so the maximum sequence number of each formation is also not necessarily identical.Such as system shown in Figure 3, numbering is that priority is that in 0 formation, total x+1 task is in queuing, and its maximum sequence number is x; Be numbered that in 2 formation, total y+1 task is in queuing, its maximum sequence number is y.Each formation has a head pointer and tail pointer, points to respectively first ready of formation and last ready.Such as in being numbered 2 formation, head pointer Head2 points to RB
20, tail pointer Tail2 points to RB
2y
In each ready RB, two elements are arranged, namely point to the pointer pointerToNextRB of next ready and the pointer pointerToTCB of the corresponding task control block (TCB) of sensing.PointerToNextRB is used for ready RB connected into the formation of chain sheet form, and pointerToTCB is used for access task controll block TCB.The ready RB that points to same task control block (TCB) TCB can be one or more, and ready RB number pointing to same task control block (TCB) TCB just equals the example number that the current number of times that is activated of task can move in other words.Such as in Fig. 3, task control block (TCB) TCB
1The task of representative has been activated 2 times, and it has 2 examples that can move, and one is arranged in priority is 2 formation, by ready RB
20Expression; One is arranged in the formation that priority is n, by ready RB
n1Expression.Task control block (TCB) TCB
2But the task of representative also has 2 running examples that are activated, and all is arranged in priority and is 2 formation, by ready RB
21And RB
2yExpression.
It should be noted that in the present embodiment, new activating of task all enters ready queue with its original priority.Although task its priority when using resource can change, but the current run entity that only has this task, therefore that task instances that namely is activated the earliest just may be changed priority, points in the ready task formation that ready of same task controll block be present at most 2 priority.
For the requirement that realizes that task repeatedly activates, the data structure of traditional task control block (TCB) is improved, increased the element of the current activation number of times of logger task in task control block (TCB).Because this operating system call is complete static configuration, therefore in the design of data structure, the information that configuration is relevant is independent, is placed on specially in the task configuration information structure maximum activation number of times that logger task allows in this structure.Relevant task control block (TCB) and configuration information structure are as shown in Figure 4.
Fig. 4 is task control block (TCB) and a kind of embodiment structural drawing of configuration information structure in the present invention.
In the present embodiment, as shown in Figure 4, task control block (TCB) comprises following element:
● task status status
State status is used for the logger task state, and its value can be any in following 4 kinds of situations:
Operation RUNNING, the expression task is in run mode;
Ready READY, the expression task is in ready attitude;
Hang up SUSPEND, the expression task is in pending state;
Ready reaching moved READY﹠amp for the first time; FIRST_RUN, the expression task is in ready attitude and is to move for the first time.
Wherein ready reaching moved READY﹠amp for the first time; FIRST_RUN is custom-designed for the repeatedly activation of supporting task, it is the expansion to the legacy operating system task status, purpose be in order to ensure the new task instances that activates when it moves for the first time, operating system guarantees to begin to carry out from article one instruction of its code: when the state value of task was READY, task was moved by recovering its context; When the state of task is READY﹠amp; During FIRST_RUN, operating system begins from the task code entry address to carry out.
● the current activation number of times of task curActiveNum
The current activation number of times of task curActiveNum is used for the current activation number of times of logger task, activates example whenever task increases by one, and the value of this element adds 1; Whenever an example end of run of task, the value of this element subtracts 1; When curActiveNum was reduced to 0, the state of this task became pending state.
● task current priority curPriority
The task current priority is used for the current priority of logger task, and it has represented the priority of that example that task may be moved the earliest, and the scheduler program that it can be operated system uses;
● task configuration information list index configTable
Task configuration information list index configTable points to the task configuration information structure, can obtain the information of some static configuration of task by it;
● task context pointer context
Task context pointer context points to the pointer of store tasks contextual information, can obtain the contextual information of task by it, because when the state value of task was READY, it moved by the recovery tasks context.
In the present embodiment, as shown in Figure 4, the information in the task configuration information structure can not change in the operational process of task all by user's static configuration.Being described as follows of its coherent element:
● task code entry address entry
Can obtain article one function code of task by task code entry address entry, when the state of task is READY﹠amp; During FIRST_RUN, operating system is the entry address from task code, and namely article one function code begins to carry out.
● the ID taskId of task
Be the numbering of task in system.
● the base priority basePriority of task
When task was newly activated an example, ready of this example was inserted into corresponding formation afterbody according to this priority.
● the maximum activation number of times maxActive of task
The maximum activation number of times maxActive of task records the maximum activation number of times that this task allows, when attempting to activate a task, if its current activation number of times is less than the maximum activation number of times of configuration, task can successfully be activated, but namely increase an operation task example, otherwise can not be activated.
Due to may have in system a plurality of ready corresponding with same task control block (TCB), so the content in task control block (TCB) can only reflect the situation of current that example that moving or that may move the earliest.When a current running example that activates example or end task of newly-increased task, can true(-)running for ensureing next example, the operation that need to be correlated with to ready, task control block (TCB), specifically, need to complete following operation:
One of A, increase task is activated example:
A, the task control block (TCB) of this task is carried out following operation:
1), judge at first whether the current activation number of times of the task curActiveNum in task control block (TCB) has equaled the maximum activation number of times maxActive of the task in the task configuration information structure;
2) if the current activation number of times of task curActiveNum equals the maximum activation number of times maxActive of task, show that task has reached its maximum activation number of times, can not increase again one and activate example, program is returned;
3) if the current activation number of times of task curActiveNum less than the maximum activation number of times maxActive of task, obtain a ready of free time, and pointer pointerToTCB that the corresponding task control block (TCB) of its sensing is set points to task control block (TCB), and with ready new afterbody that is inserted into the corresponding ready task formation of original priority of task, the current activation number of times of task CurActiveNum is added 1;
If the task current state is pending state, revising in task control block (TCB) task status is ready and operation for the first time;
If the priority of the new activate a task of priority ratio of the current operation task of b operating system is low, and system satisfies the executive condition of scheduler program, and operating system is carried out task scheduling; If the result of scheduling is the new task run that activates, by the task context pointer in the task control block (TCB) of current operation task, preserve the context of current operation task,
And the state of revising activate a task is ready, jumps to the place, code entry address of activate a task, the operation of beginning activate a task;
B, the current running example that ends task
1), ready with current running example returns to system;
2), the current activation number of times of the task of task control block (TCB) CurActiveNum is subtracted 1;
Whether the value that 3), judges the current activation number of times of task CurActiveNum is 0, if be not 0, mean that other examples to be moved that this task is still arranged exist, be state ready and that move for the first time for next running example, need task status to be set to ready and move for the first time READY ﹠amp; FIRST_RUN; If the current activation number of times of task CurActiveNum is 0, task status is set to pending state;
4), adjusting the task current priority is the base priority of the task in the task configuration information structure;
5) if system satisfies the executive condition of scheduler program, operating system is carried out task scheduling; For ready of the task of the needs of new scheduling operation, check the task status of ready task control block (TCB) pointed, if be ready, directly come the operation of recovery tasks by recovering its context, if be ready and operation for the first time, it is ready revising task status, jumps to place, task code entry address, the operation of beginning task.
Example
Improvement through above-mentioned has realized the requirement that OSEK/VDX operating system repeatedly activates for task.The below is the example of a reality, and the situation that a plurality of tasks are repeatedly activated in a system has been described, and in this process the situation of change of ready in the task queue of each priority.
In this example, have 5 task T1~T5 in system, the priority of these 5 tasks is from high to low successively: T2 priority is the highest, T1 priority is taken second place, the priority of T3, T4, T5 is identical and minimum.Fig. 5 has showed the certain operations of doing in system's operational process, and the state variation situation of T1, T2, T3, T4 and T5 task.
The below is in this system's operational process, the some events that occurs in chronological order, and the explanation of each task status situation of change:
1) t0 is constantly:
A) operation: system initialization;
B) ready task formation situation: as shown in Figure 6, the activation number of times of T1 is 1, so the task control block (TCB) TCB of T1
1Only have 1 RB coupled;
C) task status: as shown in Figure 5, only have task T1 ready, other tasks are pending state, operating system scheduling T1 operation, and T1 is run mode;
In Fig. 6, the piece of being filled by shade (as
) expression ready of current moving of task, lower with.
2) t1 is constantly:
A) operation: T1 activates T4;
B) ready task formation situation: as shown in Figure 7, it is the task control block (TCB) TCB of 1, T4 that T4 activates number of times
4There is 1 RB coupled;
C) task status: as shown in Figure 5, T4 becomes ready attitude;
3) t2 is constantly:
A) operation: T1 activates T4 again;
B) ready task formation situation: as shown in Figure 8, it is the task control block (TCB) TCB of 2, T4 that T4 activates number of times
4There are 2 RB coupled;
C) task status: as shown in Figure 5, T4 is still ready attitude;
4) t3 is constantly:
A) operation: T1 activates T5;
B) ready task formation situation: as shown in Figure 9, it is the task control block (TCB) TCB of 1, T5 that T5 activates number of times
5There is 1 RB coupled;
C) task status: T5 becomes ready attitude;
5) t4 is constantly:
A) operation: T1 activates T3;
B) ready task formation situation: as shown in figure 10, it is the task control block (TCB) TCB of 1, T3 that T3 activates number of times
3There is 1 RB coupled;
C) task status: as shown in Figure 5, T3 becomes ready attitude;
6) t5 is constantly:
A) operation: T1 activates T4;
B) ready task formation situation: as shown in figure 11, it is the task control block (TCB) TCB of 3, T4 that T4 activates number of times
4There are 3 RB coupled;
C) task status: as shown in Figure 5, T4 is still ready attitude;
7) t6 is constantly:
A) operation: T1 activates T5;
B) ready task formation situation: as shown in figure 12, it is the task control block (TCB) TCB of 2, T5 that T5 activates number of times
5There are 2 RB coupled;
C) task status: as shown in Figure 5, T5 is still ready attitude;
8) t7 is constantly:
A) operation: T1 activates T3;
B) ready task formation situation: as shown in figure 12, arrived the maximum activation number of times of its configuration due to T3, this time activated unsuccessfully the task control block (TCB) TCB of T3
3Still only have 1 RB coupled;
C) task status: as shown in Figure 5, T3 is still ready attitude;
9) t8 is constantly:
A) operation: T1 activates T4;
B) ready task formation situation: as shown in figure 12, arrived the maximum activation number of times of its configuration due to T4, this time activated unsuccessfully the task control block (TCB) TCB of T4
4Remain 3 RB coupled;
C) task status: as shown in Figure 5, T4 is still ready attitude;
10) t9 is constantly:
A) operation: T1 activates T5;
B) ready task formation situation: as shown in figure 12, arrived the maximum activation number of times of its configuration due to T5, this time activated unsuccessfully the task control block (TCB) TCB of T5
5Remain 2 RB coupled;
C) task status: as shown in Figure 5, T5 is still ready attitude;
11) t10 is constantly:
A) operation: T1 activates T2;
B) ready task formation situation: as shown in figure 13, T2 activation number of times is that the task control block (TCB) of 1, T1 and T2 is all that 1 RB is coupled;
C) task status: as shown in Figure 5, T2 becomes ready attitude, and higher than T1, T2 seizes T1 due to T2 priority, and T2 becomes run mode, and T1 gets back to ready attitude;
12) t11 is constantly:
A) operation: T2 activates T2;
B) ready task formation situation: as shown in figure 13, arrived the maximum activation number of times of its configuration due to T2, this time activated unsuccessfully the task control block (TCB) TCB of T2
2Still only have 1 RB coupled;
C) task status: as shown in Figure 5, T2 is still run mode;
13) t12 is constantly:
A) operation: T2 activates T3;
B) ready task formation situation: as shown in figure 13, arrived the maximum activation number of times of its configuration due to T3, this time activated unsuccessfully the task control block (TCB) TCB of T3
3Still only have 1 RB coupled;
C) task status: as shown in Figure 5, T3 is still ready attitude;
14) t13 is constantly:
A) operation: T2 stops T2;
B) ready task formation situation: as shown in figure 14, become 0 because T2 activates number of times by 1, will no longer include the RB that is connected with the task control block (TCB) of T2 in system;
C) task status: as shown in Figure 5, T2 becomes pending state, system call T1 operation, and T1 is run mode;
15) t14 is constantly:
A) operation: T1 stops T1;
B) ready task formation situation: as shown in figure 15, become 0 because T1 activates number of times by 1, will no longer include the RB that is connected with the task control block (TCB) of T1 in system;
C) task status: as shown in Figure 5, T1 becomes pending state, operating system scheduling T4 operation, and T4 is run mode;
16) t15 is constantly:
A) operation: T4 links T4, and namely T4 attempts stopping current running example, and activates a new example;
B) ready task formation situation: as shown in figure 16, with TCB
4The new RB that is connected is inserted into the formation afterbody, and current moving and TCB
4The RB that is connected takes off from the formation stem, the task run that the next RB of operating system scheduling is connected, and this task remains T4, and only T4 re-executes from article one function code; Through this link, the task control block (TCB) TCB of T4
4Still there are 3 RB coupled;
C) task status: as shown in Figure 5, task T4 is still run mode;
17) t16 is constantly:
A) operation: T4 stops T4;
B) ready task formation situation: as shown in figure 17, T4 activates number of times by the 3 task control block (TCB) TCB that become 2, T4
4There are 2 RB coupled; Operating system reschedules, and in the ready task formation of limit priority, first RB is corresponding is the task control block (TCB) TCB of T5 at this moment
5, T5 becomes run mode;
C) task status: as shown in Figure 5, T4 becomes ready attitude, and T5 becomes run mode;
18) t17 is constantly:
A) operation: T5 activates T4;
B) ready task formation situation: as shown in figure 18, T4 activates the task control block (TCB) TCB that number of times becomes 3, T4
4There are 3 RB coupled;
C) task status: as shown in Figure 5, the T4 state is still ready attitude;
19) t18 is constantly:
A) operation: T5 links T5, and namely T5 attempts stopping current running example, and activates a new example;
B) ready task formation situation: as shown in figure 19, new and TCB
5The RB that is connected is inserted into the formation afterbody, and the current RB that is moving is removed from the formation stem, with the task control block (TCB) TCB of T5
5The RB that is connected is 2; The corresponding task of the next RB of operating system scheduling is the T3 operation;
C) task status: as shown in Figure 5, the state of T5 becomes ready attitude, and T3 is run mode;
20) t19 is constantly:
A) operation: T3 links T3, and namely T3 attempts stopping current running example, and activates a new example;
B) ready task formation situation: as shown in figure 20, new and TCB
3The RB that is connected is inserted into the formation afterbody, and the current RB that is moving is removed from the formation stem, with the task control block (TCB) TCB of T3
3The RB that is connected is 1; The corresponding task of the next RB of operating system scheduling is the T4 operation;
C) task status: as shown in Figure 5, the state of T3 becomes ready attitude, and T4 is run mode;
21) t20 is constantly:
A) operation: T4 stops T4;
B) ready task formation situation: as shown in figure 21, the activation number of times of T4 becomes 2 by 3, the task control block (TCB) TCB of itself and T4
4The RB that is connected is 2; The corresponding task of the next RB of operating system scheduling is the T5 operation
C) task status: as shown in Figure 5, the state of T4 becomes ready attitude, and T5 becomes run mode;
By following the tracks of the ruuning situation of said system, objectively proved that in the present invention, designed method has satisfied the requirement that task repeatedly activates, solved 2 problems that exist in the prior art, that is:
The structure of 1, queuing up in the ready task formation is RB, and it only has 2 elements, and it is less than the space of directly queuing up with task control block (TCB) to taking of storage space;
2, in system, each task only has a controll block to exist all the time, only after (being terminated) completed in its previous example operation, the example of its back could move, and namely not exclusively independent between the Multi-instance of a task, the behavior that repeatedly activates does not create new thread.
Although the above is described the illustrative embodiment of the present invention; so that the technician of present technique neck understands the present invention; but should be clear; the invention is not restricted to the scope of embodiment; to those skilled in the art; as long as various variations appended claim limit and the spirit and scope of the present invention determined in, these variations are apparent, all utilize innovation and creation that the present invention conceives all at the row of protection.
Claims (1)
1. the method for an activating task in embedded real-time operating system for multiple times, is characterized in that, comprises the following steps:
(1), set up a ready task formation array and be used for the management ready task
Ready task to equal priority is ranked, and forms a plurality of ready task formations identical with priority quantity; All ready task formations form array, and the length of array equals priority number, and each array element is a ready task formation, and corresponding priority;
Ready task in the ready task formation is with ready indication, two elements are arranged in each ready, namely point to the pointer of next ready and the pointer of the corresponding task control block (TCB) of sensing, if ready is positioned at ready task formation last position, its pointer that points to next ready be sky;
Each ready task formation has a head pointer and tail pointer, point to respectively first ready of the ready task formation and last ready, when head pointer is used for the tasks carrying of corresponding priority, search first task in ready task formation corresponding to this priority, when tail pointer is used for ready new insertion, search ready task formation afterbody corresponding to this new priority of ready ready, if there is no ready task in the ready task formation, head pointer and tail pointer are empty;
(2), the data structure of task control block (TCB) is improved
2.1, task control block (TCB) comprises following element:
● task status
Task status is used for the logger task state, and its value is: operation, ready, hang-up and ready and operation for the first time;
When being ready, task is moved by recovering its context when the state value of task; When the state of task was ready and moves for the first time, operating system began to carry out from the task code entry address;
● the current activation number of times of task
The current activation number of times of task is used for the current activation number of times of logger task, activates example whenever task increases by one, and the value of the current activation number of times of task adds 1; Whenever an example end of run of task, the value of the current activation number of times of task subtracts 1; When the current activation number of times of task was reduced to 0, the state of this task became pending state;
● the task current priority
The task current priority is used for the current priority of logger task, and its value has represented the priority of that example that task may be moved the earliest;
● the task configuration information list index
The task configuration information list index points to the task configuration information structure, can obtain the information of the static configuration of task by it;
● the task context pointer
The task context information of task context pointed operating system storage can be obtained the contextual information of task by it, and when being ready, this task is moved by recovering its contextual information when the state value of task;
2.2, the information in the task configuration information structure is all by user's static configuration, immovable in the operational process of task, its coherent element is as follows:
● the task code entry address
Can obtain article one function code of task by the task code entry address, when the state of task was ready and moves for the first time, operating system was from the entry address execution of task code;
● the base priority of task
When task was newly activated an example, ready of this example was inserted into corresponding formation afterbody according to this priority;
● the maximum activation number of times of task
The maximum activation number of times of task records the maximum activation number of times that this task allows, when attempting to activate a task, if its current activation number of times less than the configuration the maximum activation number of times, task can successfully be activated, but namely increase an operation task example, otherwise can not be activated;
(3), the operation that repeatedly activates of task
3.1, increase of task and activate example
A, the task control block (TCB) of this task is carried out following operation:
1), judge at first whether the current activation number of times of task in task control block (TCB) has equaled the maximum activation number of times of the task in the task configuration information structure;
2) if the current activation number of times of task equals the maximum activation number of times of task, can not increase again one and activate example, program is returned;
3) if the current activation number of times of task less than the maximum activation number of times of task, obtain a ready of free time, and ready of this free time pointed task control block (TCB) that points to corresponding task control block (TCB) is set to form new ready, with ready new afterbody that is inserted into the corresponding ready task formation of base priority of task: new ready of inserting of pointed that the former last sensing of ready of this ready task formation is next ready, the tail pointer of this ready task formation points to new ready of inserting; The current activation number of times of task adds 1;
If the task current state is pending state, revising in task control block (TCB) task status is ready and operation for the first time;
If the priority of the new activate a task of priority ratio of the current operation task of b operating system is low, and system satisfies the executive condition of scheduler program, and operating system is carried out task scheduling; If the result of scheduling is the new task run that activates, by the task context pointer in the task control block (TCB) of current operation task, preserve the context of current operation task, and the task status of revising the task control block (TCB) of activate a task is ready, jump to the place, task code entry address of the task control block (TCB) of activate a task, the operation of beginning activate a task;
3.2, the current running example that ends task
1), ready with current running example returns to system;
2), the current activation number of times of the task of task control block (TCB) is subtracted 1;
3), judge whether the value of the current activation number of times of task is 0, if be not 0, task status be set to ready and for the first time the operation; If the current activation number of times of task is 0, task status is set to pending state;
4), adjusting the task current priority is the base priority of the task in the task configuration information structure;
5) if system satisfies the executive condition of scheduler program, operating system is carried out task scheduling; For ready of the task of the needs of new scheduling operation, check the task status of ready task control block (TCB) pointed, if be ready, directly come the operation of recovery tasks by recovering its context, if be ready and operation for the first time, it is ready revising task status, jumps to place, task code entry address, the operation of beginning task.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 201010582446 CN102043668B (en) | 2010-12-10 | 2010-12-10 | Method for activating task in embedded real-time operating system for multiple times |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 201010582446 CN102043668B (en) | 2010-12-10 | 2010-12-10 | Method for activating task in embedded real-time operating system for multiple times |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102043668A CN102043668A (en) | 2011-05-04 |
CN102043668B true CN102043668B (en) | 2013-05-22 |
Family
ID=43909824
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN 201010582446 Expired - Fee Related CN102043668B (en) | 2010-12-10 | 2010-12-10 | Method for activating task in embedded real-time operating system for multiple times |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102043668B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20130074088A1 (en) | 2011-09-19 | 2013-03-21 | Timothy John Purcell | Scheduling and management of compute tasks with different execution priority levels |
CN104239134B (en) * | 2013-06-21 | 2018-03-09 | 华为技术有限公司 | The task management method and device of a kind of many-core system |
CN103729245B (en) * | 2013-12-27 | 2017-03-08 | 普华基础软件股份有限公司 | A kind of OSEK operating system nucleus dynamic process static method |
CN106201695A (en) * | 2016-07-15 | 2016-12-07 | 郑州飞机装备有限责任公司 | It is applicable to the multi-task scheduling method of embedded software system |
CN108121911B (en) * | 2016-11-30 | 2021-04-27 | 中国移动通信有限公司研究院 | A software detection method and device |
CN107346263B (en) * | 2017-06-29 | 2021-01-12 | 上海联影医疗科技股份有限公司 | Task execution method, storage medium, and computer device |
CN111913790A (en) * | 2020-07-03 | 2020-11-10 | 佛山市顺德区美的洗涤电器制造有限公司 | Task scheduling method and device, household appliance and computer readable storage medium |
CN114372727A (en) * | 2022-01-14 | 2022-04-19 | 深圳前海环融联易信息科技服务有限公司 | A Workflow-based Task Suspended Processing Method |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6449614B1 (en) * | 1999-03-25 | 2002-09-10 | International Business Machines Corporation | Interface system and method for asynchronously updating a share resource with locking facility |
CN1490722A (en) * | 2003-09-19 | 2004-04-21 | 清华大学 | Hierarchical Task Switching Method Based on PowerPC Processor Architecture |
CN1655124A (en) * | 2005-03-04 | 2005-08-17 | 清华大学 | Interrupt Management Method of Automotive Operating System Based on PowerPC Processor |
CN1737764A (en) * | 2005-09-12 | 2006-02-22 | 浙江大学 | Task Scheduling Method of Embedded Real-time Operating System Supporting OSEK Standard |
-
2010
- 2010-12-10 CN CN 201010582446 patent/CN102043668B/en not_active Expired - Fee Related
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6449614B1 (en) * | 1999-03-25 | 2002-09-10 | International Business Machines Corporation | Interface system and method for asynchronously updating a share resource with locking facility |
CN1490722A (en) * | 2003-09-19 | 2004-04-21 | 清华大学 | Hierarchical Task Switching Method Based on PowerPC Processor Architecture |
CN1655124A (en) * | 2005-03-04 | 2005-08-17 | 清华大学 | Interrupt Management Method of Automotive Operating System Based on PowerPC Processor |
CN1737764A (en) * | 2005-09-12 | 2006-02-22 | 浙江大学 | Task Scheduling Method of Embedded Real-time Operating System Supporting OSEK Standard |
Non-Patent Citations (1)
Title |
---|
陈二涛.OSEK OIL配置器研究与应用.《太原科技大学》.2009,第1页至第75页. * |
Also Published As
Publication number | Publication date |
---|---|
CN102043668A (en) | 2011-05-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102043668B (en) | Method for activating task in embedded real-time operating system for multiple times | |
CN101226487B (en) | Implementation method of kernel-level thread library based on embedded Linux operating system | |
US9378069B2 (en) | Lock spin wait operation for multi-threaded applications in a multi-core computing environment | |
US8683180B2 (en) | Intermediate register mapper | |
US10248463B2 (en) | Apparatus and method for managing a plurality of threads in an operating system | |
CN101414270A (en) | Method for implementing assist nuclear task dynamic PRI scheduling with hardware assistant | |
CN100530111C (en) | Multi-thread access indirect register scheduling method | |
US20030233392A1 (en) | Method and system for managing the execution of threads and the processing of data | |
CN102681894A (en) | Method and system for multitask concurrent scheduling | |
CN103473031A (en) | Cooperative concurrent message bus, driving member assembly model and member disassembly method | |
CN102541642A (en) | Task management method for enhancing real-time performance | |
CN102004664A (en) | Scheduling method of embedded real-time operating system of space vehicle | |
US7971205B2 (en) | Handling of user mode thread using no context switch attribute to designate near interrupt disabled priority status | |
CN102567096A (en) | Mutual-exclusion semaphore management method for preventing deadlock under multi-task environment | |
CN109308213B (en) | Multi-task breakpoint debugging method based on improved task scheduling mechanism | |
CN112346835A (en) | Scheduling processing method and system based on coroutine | |
CN106201695A (en) | It is applicable to the multi-task scheduling method of embedded software system | |
CN105677467A (en) | Yarn resource scheduler based on quantified labels | |
CN100349149C (en) | Process Scheduling Method of Embedded Real-time Operating System | |
US20140052432A1 (en) | Method for a design evaluation of a system | |
KR102031853B1 (en) | Method of Switching Task-level Criticality-mode for Mixed-Criticality Systems | |
CN112416539A (en) | Multi-task parallel scheduling method for heterogeneous many-core processor | |
Goyette | An analysis and description of the inner workings of the freertos kernel | |
US8782378B2 (en) | Dynamic instruction splitting | |
CN112948136A (en) | Method for implementing asynchronous log record of embedded operating system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20130522 Termination date: 20151210 |
|
EXPY | Termination of patent right or utility model |