Summary of the invention
Fundamental purpose of the present invention is to provide a kind of method for scheduling task of operating system, device and computing machine, need to consume extra data space with the method for scheduling task solved in the operating system of prior art, and under same priority, support the problem of multiple task.
To achieve these goals, according to an aspect of the present invention, a kind of method for scheduling task of operating system is provided.
The method for scheduling task of operations according to the instant invention system comprises: the task of being triggered scheduling operation system by the conversion of task status; In task dictionary, sitation index corresponding to this task is obtained according to the priority of task; According to the sitation index more position of new task in ready task chained list.
Further, before the step obtaining sitation index corresponding to this task according to the priority of task in task dictionary, method also comprises: creation task concordance list, task dictionary comprises one or more index record, each index record is for recording first and the sitation index of last task node in ready task chained list corresponding to a priority, wherein, the corresponding one or more task node of any one priority, each task node is corresponding unique priority respectively.
Further, the step according to the sitation index more position of new task in ready task chained list comprises: obtain the node location of task in ready task chained list that sitation index characterizes, ready task chained list is for recording the node location of each priority tasks; Task is inserted or removes node location.
Further, after according to the step of the sitation index more position of new task in ready task chained list, method also comprises: according to the reposition of task in ready task chained list, obtain the new url index of this priority tasks in task dictionary, original sitation index is replaced by new join index.
Further, after the conversion by task status triggers the step of the task of scheduling operation system, method also comprises: the conversion whether handover success judging task status, wherein, when task status handoff failure, switch to delay state simultaneously, then by task delay Task-list, otherwise trigger the step success of the task of scheduling operation system.
Further, when moment arrival or the time-out of delay state, task switch success.
To achieve these goals, according to another aspect of the present invention, a kind of task scheduling apparatus of operating system is provided.
The task scheduling apparatus of operations according to the instant invention system comprises: trigger module, for being triggered the task of scheduling operation system by the conversion of task status; Scheduler module, for obtaining sitation index corresponding to this task according to the priority of task in task dictionary; First update module, for according to the sitation index more position of new task in ready task chained list.
Further, device also comprises: creation module, for creation task concordance list, task dictionary comprises one or more index record, each index record is for recording first and the sitation index of last task node in ready task chained list corresponding to a priority, wherein, the corresponding one or more task node of any one priority, each task node is corresponding unique priority respectively.
Further, the first update module comprises: acquisition module, and for obtaining the node location of task in ready task chained list that sitation index characterizes, ready task chained list is for recording the node location of each priority tasks; Change module, for task being inserted or removing node location.
Further, device also comprises: the second update module, for according to the reposition of task in ready task chained list, obtains the new url index of this priority tasks in task dictionary, original sitation index is replaced by new join index.
Further, device also comprises: judge module, for judging the conversion whether handover success of task status, wherein, when task status handoff failure, switch to delay state simultaneously, then by task delay Task-list, otherwise trigger the step success of the task of scheduling operation system, wherein, when moment arrival or the time-out of delay state, task switch success.
To achieve these goals, in accordance with a further aspect of the present invention, a kind of computing machine is provided.This computing machine comprises the task scheduling apparatus of any one operating system above-mentioned.
By the present invention, adopt the task of being triggered scheduling operation system by the conversion of task status; In task dictionary, sitation index corresponding to this task is obtained according to the priority of task; According to the sitation index more position of new task in ready task chained list, the method for scheduling task solved in the operating system of prior art needs to consume extra data space, and under same priority, support the problem of multiple task, and then it is simple to reach realization, flexible and efficient method for scheduling task, improves the effect of the work efficiency of operating system task scheduling.
Embodiment
In order to make technical matters to be solved by this invention, technical scheme and beneficial effect clearly, understand, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
The invention provides a kind of method for scheduling task of operating system.Fig. 1 is the process flow diagram of the method for scheduling task of operating system according to the embodiment of the present invention.As shown in Figure 1, the method for scheduling task of this operating system comprises the steps:
Step S102, triggers the task of scheduling operation system by the conversion of task status.
Step S104, obtains sitation index corresponding to this task according to the priority of task in task dictionary.This step realizes setting up the scheduling concordance list of task of being scheduled, the traffic order that the task of different priorities is corresponding different, i.e. corresponding different link position.
Step S106, according to the sitation index more position of new task in ready task chained list.This step realizes the node location being carried out this task in unified management ready task chained list by the sitation index of task dictionary record, the system of realization can obtain task dispatch state now efficiently, and does not need extra to safeguard multiple Task-list according to priority.
The above embodiment of the present invention is by safeguarding that the mode of ready task chained list (based on first in first out) and priority tasks concordance list realizes the scheduling to task, first the sitation index of different priorities task is preserved by creating also management role concordance list, such as this sitation index can provide the positional information of the insertion ready task chained list of correspondence for this task, make this task when transferring ready state to from suspended state, only need the positional information first obtaining this task can determine that this task is in ready state, so that system carries out running this task, save storage space.
The above embodiment of the present invention before the step obtaining sitation index corresponding to this task according to the priority of task in task dictionary, method can also comprise: creation task concordance list, task dictionary comprises one or more index record, each index record is for recording first and the sitation index of last task node in ready task chained list corresponding to a priority, wherein, the corresponding one or more task node of any one priority, each task node is corresponding unique priority respectively.This embodiment can be implemented as different priority tasks and sets up different chained commands, and the doubly linked list technology of employing takes up room less.
Preferably, the step according to the sitation index more position of new task in ready task chained list comprises: obtain the node location of task in ready task chained list that sitation index characterizes, ready task chained list is for recording the node location of each priority tasks; Task is inserted or removes node location.This embodiment can realize only the positional information of this node ready Task-list need being deleted when task transfers suspended state to from ready state, or when task transfers ready state to from suspended state, the node location that only need change pointed just realizes increasing this task in ready task chained list, the storage space of the method simply efficiently, not outside occupying volume.
In the above embodiment of the present invention after according to the step of the sitation index more position of new task in ready task chained list, method can also comprise: according to the reposition of task in ready task chained list, obtain the new url index of this priority tasks in task dictionary, original sitation index is replaced by new join index.
Wherein, after the conversion by task status triggers the step of the task of scheduling operation system, this embodiment can perform the conversion whether handover success judging task status, wherein, when task status handoff failure, switch to delay state simultaneously, then by task delay Task-list, otherwise trigger the step success of the task of scheduling operation system.Preferably, in above-described embodiment when the moment arrival of delay state or time-out, task switch is successfully.
The implementation method of the task scheduling that the above embodiment of the present invention is described, namely realize above-mentioned mentioned according to feature task scheduling rule (namely carrying out task scheduling according to the priority of task), find the method that corresponding task performs, support the task of multiple equal priority, and the adjustment of task priority.The dispatching method that the present invention proposes realizes simple, consuming time stable and flexible and efficient.
Be described in detail below in conjunction with the implementation procedure of example to the embodiment of the present invention.
Fig. 2 is according to task status transition graph embodiment illustrated in fig. 1.The present invention is by safeguarding that the mode of ready task chained list (based on first in first out) and priority tasks concordance list realizes the scheduling to task.Comprise task state transition and task scheduling, as shown in Figure 2, the implementation procedure that operating system describes task scheduling according to the State Transferring of task is as follows:
First, system creation task also arranges task status, the information such as priority, and with this assignment task control block (TCB) (TCB.Tack Control Block).The basic status of task can be divided into following three kinds: running status (Running), blocked state (Pending), ready state (Ready).
As shown in Figure 2, the transition relationship of above-mentioned three kinds of states of task and trigger condition comprise following a few class situation respectively:
Ready state is converted in the process of running status (Ready-> Running), current when being in the task generation state transition of running status Running, the task of being in the limit priority of ready state Ready will enter running status Running.If be in this priority by multiple task, so select task according to first in first out (FIFO:First-in, First-out).
Running state conversion is in the process of ready state (Running-> Ready), when higher priority task ready or the current task of being in running status Running change, this task can revise self priority in priority tasks concordance list.
Running state conversion is in the process of blocked state (Running-> Pending), the current following action of tasks carrying being in running status Running: wait for certain event; Call delay function (Delay) and wait for the some time; (Suspend) this task of hang-up; Wait enters Pending state.
Ready state is converted in the process of blocked state (Ready-> Pending), and current task is suspended.
Blocked state is converted in the process of ready state (Pending-> Ready), the current following action of tasks carrying being in blocked state: the event that system task is waited for occurs; Task (Suspended) after hang-up is waken up (Resume); If now task delay time enters ready state Ready to task when (Timeout) from blocked state Pending.
Secondly, system is each task creation doubly linked list of ready state, chained list afterbody points to Idle task, each node in this chained list comprises task control block (TCB) (TCB.Tack Control Block) and points to precursor pointer and the heir pointer of front and back node address, by this doubly linked list realize task when three kinds of states perform migration action each other, determine the position in node of this task.
In addition, also need to set up task dictionary, concordance list is that each task priority retains a task index record, records first and the sitation index of last task node in ready task chained list of this priority.
During task scheduling, system produces the switching between each state of task by the first node directly found in ready task chained list.
Such as, when certain task proceeds to ready state by suspended state, find the node location needing to insert ready task chained list from task dictionary according to own priority, and this task is inserted node corresponding to node location; When certain task proceeds to pending state by ready state, then can delete this node from ready task chained list, upgrade concordance list record simultaneously.
In addition, if if certain task calls delay function, then by this task delay Task-list.When each Interruption produces, in Interrupt Service Routine, successively the delay designations of task in chained list (tick number) is subtracted one.If certain task time delay moment arrives (tick is 0), then enter ready state, and insert ready task chained list.
By safeguarding that the mode of ready task chained list (based on first in first out) and priority tasks concordance list realizes the scheduling to task in the above embodiment of the present invention.Wherein, Fig. 3 is ready task chained list according to the embodiment of the present invention and task dictionary structural drawing.Specifically as shown in Figure 3, each node in ready task chained list comprises task control block (TCB) (TCB.Tack Control Block) and front and back node address; The task of equal priority (such as priority N or M etc.) can be connected on adjacent node according to FIFO Principle Chain.The sitation index of each task in task dictionary have recorded first of the task of equal priority (such as priority N or M etc.) in ready task chained list and the position of last node.When task scheduling, can operate ready task chained list according to the node location of sitation index record easily.
When just describing generation task scheduling below in detail, the handoff procedure between each state of this task.
Fig. 4 is the change structural drawing of Task-list when proceeding to running status according to any task of the embodiment of the present invention by ready state and task dictionary.When task status occurs to proceed to the migration of running status (Runing) by ready state (Ready), triggering tasks is dispatched.Now, scheduler directly finds the first node in ready task chained list, produces task switch subsequently.As shown in Figure 4, specifically can comprise the steps:
First, scheduler gets the gauge outfit node in ready state Task-list; Then, by empty for the pre pointed of second node of the next pointed of this gauge outfit node node; Again empty for present node next pointed node; Updating form head node again, using this second node as new gauge outfit node; Finally, upgrade the index record of task dictionary, first node position in task dictionary is pointed to the gauge outfit node after this renewal (i.e. second node).
Fig. 5 is the change structural drawing of Task-list when proceeding to ready state according to any task of the embodiment of the present invention by blocked state and task dictionary.When certain task proceeds to ready state (Ready) by blocked state (Pending), find the node location needing to insert ready task chained list from task dictionary according to own priority, insert node.As shown in Figure 5, specifically can comprise the steps:
First, obtain the task index record of task dictionary according to the priority of task self, namely obtain the chained address of the node of this priority in task dictionary; Secondly, the node of last task of equal priority can be obtained by index record; Then, this node can the task of the next pointed of the own node not pre pointed of first task node of equal priority; Meanwhile, the pre pointer of the next pointed own node of last original for same priority task node; Finally, the record in task dictionary is upgraded.
Fig. 6 is the change structural drawing of Task-list when proceeding to blocked state according to any task of the embodiment of the present invention by ready state and task dictionary.When certain task proceeds to blocked state by ready state, from ready task chained list, delete this node, upgrade concordance list record simultaneously.As shown in Figure 6, specifically can comprise the steps:
First, task control block (TCB) (TCB) node of self is obtained; Then, the task control block (TCB) node pointed by the next pointer of the next pointed present node of the previous node pointed by the pre pointer in present node; Now, be last task node of this priority recorded in task dictionary record at present node, upgrade the record in task dictionary.
Fig. 7 is the change structural drawing of Task-list and task dictionary when entering ready state after any task wait timeout according to the embodiment of the present invention.When certain task is by time delay, then in delay Task-list.When each Interruption produces, in Interrupt Service Routine, successively the time delay tick of task in chained list mark is subtracted one.If certain task time delay moment to (tick is 0), then enters ready state, and inserts ready task chained list.As shown in Figure 7, specifically can to comprise the steps:
First, system deletes this task node from delayed tasks chained list; Then from task dictionary, same priority task node index is obtained according to the priority of overtime task; Again the task node of the next pointed of last task node of the next pointed equal priority of overtime task node; Meanwhile, by the next pointed overtime task node of last task node of equal priority; And the node of last task of the pre pointed equal priority of overtime task; Finally perform the step of the record upgrading task dictionary.
It should be noted that, the embodiment of the present invention can perform in the step shown in the process flow diagram of accompanying drawing in the computer system of such as one group of computer executable instructions, and, although show logical order in flow charts, but in some cases, can be different from the step shown or described by order execution herein.
Fig. 8 is the structural representation of the task scheduling apparatus of operating system according to the embodiment of the present invention.As shown in Figure 8, this device comprises: trigger module 801, scheduler module 803 and the first update module 805.
Wherein, trigger module 801, for triggering the task of scheduling operation system by the conversion of task status; Scheduler module 803, for obtaining sitation index corresponding to this task according to the priority of task in task dictionary; First update module 805, for according to the sitation index more position of new task in ready task chained list.
Trigger module 801 in above-described embodiment can realize the function of step S102 in Fig. 1, and scheduler module 803 can realize the function of step S104 in Fig. 1, and the first update module 805 can realize the function of step S106 in Fig. 1.By this device by safeguarding that the mode of ready task chained list (based on first in first out) and priority tasks concordance list realizes the scheduling to task, the task node location after state switching that will dispatch is determined according to the sitation index in scheduler module 803, such as this sitation index can provide the positional information of the insertion ready task chained list of correspondence for this task, making this task when transferring ready state to from suspended state, only needing the positional information first obtaining this task can determine that this task is in ready state.Said apparatus of the present invention saves data space, improves the dispatching efficiency of system.Realize simple, consuming time stable, flexible and efficient task scheduling implementation method.
Preferably, this device can also comprise: creation module 807, for creation task concordance list, task dictionary comprises one or more index record, each index record is for recording first and the sitation index of last task node in ready task chained list corresponding to a priority, wherein, the corresponding one or more task node of any one priority, each task node is corresponding unique priority respectively.
Preferably, the first update module 805 can comprise: acquisition module 8051, and for obtaining the node location of task in ready task chained list that sitation index characterizes, ready task chained list is for recording the node location of each priority tasks; Change module 8052, for task being inserted or removing node location.
Preferably, said apparatus of the present invention can also comprise: the second update module 809, for according to the reposition of task in ready task chained list, obtain the new url index of this priority tasks in task dictionary, original sitation index is replaced by new join index.
Preferably, said apparatus of the present invention can also comprise: judge module 811, for judging the conversion whether handover success of task status, wherein, when task status handoff failure, switch to delay state simultaneously, then by task delay Task-list, otherwise trigger the step success of the task of scheduling operation system, wherein, when moment arrival or the time-out of delay state, task switch success.
To achieve these goals, present invention also offers a kind of computing machine.This computing machine comprises the task scheduling apparatus of any one operating system above-mentioned.
From above embodiment describes, can find out, present invention achieves following technique effect: the implementation method of task scheduling of the present invention, scheduler latency is stablized, and runs efficient, and supports the task of multiple equal priority, and the adjustment of task priority.While dirigibility is improved, decrease the use of data space.Realize simple, consuming time stable, flexible and efficient task scheduling implementation method, and support the task of multiple equal priority, and the adjustment of task priority.
Obviously, those skilled in the art should be understood that, above-mentioned of the present invention each module or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on network that multiple calculation element forms, alternatively, they can realize with the executable program code of calculation element, thus, they can be stored and be performed by calculation element in the storage device, or they are made into multiple integrated circuit modules respectively, or the multiple module in them or step are made into single integrated circuit module to realize.Like this, the present invention is not restricted to any specific hardware and software combination.
Above-mentioned explanation illustrate and describes a preferred embodiment of the present invention, but as previously mentioned, be to be understood that the present invention is not limited to the form disclosed by this paper, should not regard the eliminating to other embodiments as, and can be used for other combinations various, amendment and environment, and can in invention contemplated scope described herein, changed by the technology of above-mentioned instruction or association area or knowledge.And the change that those skilled in the art carry out and change do not depart from the spirit and scope of the present invention, then all should in the protection domain of claims of the present invention.