A kind of process real-time scheduling method
Technical field
The present invention relates to computer processes scheduling field, be specifically related to a kind of process real-time scheduling method.
Background technology
Be widely used in fields such as embedded system, control in real time along with L inux system, the real-time that strengthens linux kernel becomes particularly important, and the core of linux kernel is a scheduling strategy, the optimization of scheduling strategy and real-time are improved to be dispatching algorithm at all, is an important field of research of real-time domain to real-time scheduling's research.The priority type of drive is that real-time system is dispatched modal a kind of mode, customizing messages according to task is given priority of each task, select next will moving of task according to priority when system need dispatch, assurance system justice, effective response are finished the work.
The Real-Time Scheduling strategy can be divided into three kinds: based on the scheduling strategy of priority, based on the scheduling strategy of time driving and the scheduling strategy of sharing based on ratio.Dispatching algorithm based on priority can be divided into two types: static priority dispatching algorithm and dynamic priority scheduling algorithm.Preferential (the Least Slack First) dispatching algorithm of smallest margin is a dynamic priority scheduling algorithm more common in the real-time system, and it is to the earliest by the preferentially improvement of (EDF) dispatching algorithm of phase.Preferential (EDF) algorithm is to use maximum a kind of dynamic priority scheduling algorithms time limit the earliest, this algorithm each task in the ready queue of giving is distributed priority according to their deadline (Deadline), and the task with nearest deadline has the highest priority.
LSF is each task setting slack time in system, and preferential execution of system has the task of minimum slack time.Although EDF algorithm and LSF algorithm table are understood its optimality under normal system load, but under the situation of overload, system can not guarantee that all tasks can both satisfy the off period, at this moment EDF or LSF algorithm performance can occur and sharply descend, and may cause unstable owing to miss the vital task deadline date.Moreover, off period or free time task most critical not necessarily, system can't guarantee in time finishing of mission critical under the situation of overload, thereby system performance can not demote grazioso, cause occurring thrashing even collapse.In addition, in the LSF algorithm, when system has above smallest margin close or equal and be when having the task of smallest margin in the system, frequent task can take place in system switches, and the phenomenon of promptly jolting can cause resource waste.
Summary of the invention
The object of the present invention is to provide a kind of process real-time scheduling method, this algorithm can guarantee under the situation of overload, the back-up system performance is demoted grazioso, unlikely thrashing even collapse appear, entire system is worth is maximized and is maintained on the acceptable level, reduce the system resource waste that the phenomenon of jolting causes simultaneously.
In order to achieve the above object, the embodiment of the invention provides a kind of process real-time scheduling method, comprising:
Steps A, set in advance the value value of process task, the value value of task should be got a value according to the value of task itself between the priority value of process and current all process greatest priority values;
Step B, when the priority of process task is close or equal, the value value of process task relatively, preferential operation is worth big task; Perhaps, the also value value of more current all tasks when system overload, the process task of operation value value maximum guarantees the entire system value maximization and is maintained on the acceptable level.
The described value value that sets in advance process task is specially:
In process control block (PCB) task_struct, increase the priority association attributes: task residue execution time Ct, task submission time Et, task is relatively by time limit Dt, priority value St, current time in system T is got by the priority value defined formula: St=(Et+Dt)-Ct-T;
Keep the mode of choosing and the real-time task priority attribute of operation queue structure, candidate's task of Linux2.6 kernel constant, according to priority be arranged in order the same priority task from small to large;
In the clock interruption subroutine, increase the real-time update of margin value is handled, promptly along with clock period increase task residue execution time Ct, reduce the priority value St of waiting process, also in the clock interruption subroutine, revise of the selection operation of value value as candidate's task of seizing threshold values;
Improve the real-time scheduling that will realize, revise kernel code and recompility, finish and improve the realization of algorithm in system.
Described step B comprises:
B11, the priority time of obtaining each process task, forward task priority is high more the off period when priority is identical;
B12: judge whether current system exists a task that above priority is close or identical, if do not exist, show the system task phenomenon of can not jolting, then carry out step B18;
B13, judge that whether this priority be the minimum priority of current system, if not, show that then this task is not hot job, then carries out step B18;
B14, whether judge this priority greater than 0, eliminate this task when priority less than 0 the time, nargin participates in scheduling more than or equal to 0.
B15, obtain the value value of close or identical and its value of these priority values more than or equal to 0 task;
B16, these priority of comparison are close or identical and its value more than or equal to the value value of 0 task;
B17, according to the size of task value value, seize execution successively;
B18, execution LSF scheduling.
Described step B comprises:
B21, when dormant state, certain process allow to be seized CPU or from interrupting or system call turns back to situation such as user's attitude and occurs, scheduling occasion brings because process initiatively enters, system enters dispatch state;
B22, carry out system call by dispatching algorithm;
B23, judge whether system transships, if there is not the execution of maintaining the statusquo; If then undertaken by B24;
B24, the comparison priority value is close or identical and its value more than or equal to the value value of 0 task;
B25, according to the value value size of task, the CPU right to use of current task is seized in the priority of task with maximum value value, and the like execution;
B26, judge whether system recovers normal condition, if then do not jump to B24, to obtain the value value of entire system maximum, if normally jump to B22, system normally moves.The present invention is by introducing based on the threshold values of seizing that is worth, both can be under the system overload situation, system can guarantee in time finishing of mission critical, keeping system performance demotes grazioso, unlikely thrashing even collapse appear, finally reach just total system value maximization, can also reduce the wasting of resources that causes because of the phenomenon of jolting.
The embodiment of the invention is by introducing based on the threshold values of seizing that is worth, both can be under the system overload situation, system can guarantee in time finishing of mission critical, keeping system performance demotes grazioso, unlikely thrashing even collapse appear, finally reach just total system value maximization, can also reduce the wasting of resources that causes because of the phenomenon of jolting.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art, to do to introduce simply to the accompanying drawing of required use in embodiment or the description of the Prior Art below, apparently, accompanying drawing in describing below only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
Fig. 1 is the process real-time scheduling method process flow diagram in the embodiment of the invention;
Fig. 2 is the value value method flow diagram that sets in advance process task in the embodiment of the invention;
Real-time scheduling's process flow diagram that Fig. 3 will realize for the improvement in the embodiment of the invention;
Another process flow diagram of real-time scheduling that Fig. 4 will realize for the improvement in the embodiment of the invention.
Embodiment
A kind of process real-time scheduling method is provided in the embodiment of the invention, and it is at first determined by the value value of task: task is worth, and promptly task is key, and this task is with respect to the significance level of other tasks in the task-set.As seizing threshold values, is the value value of task the key of improving algorithm.Seize threshold values and directly have influence on the frequency that task is switched, also have influence on the miss rate of task off period, also have influence on the effective rate of utilization of CPU.If the value value of task is greater than current all process greatest priority values, then dispatching algorithm deteriorates to the non-model of seizing.If the value value of task less than the nargin (priority value) of process, has then lost the meaning that the task of giving is worth way.Concrete 1 can consult process flow diagram among Fig. 1, comprising:
S101: set in advance the value value of process task, the value value of task should be got a value according to the value of task itself between the priority value of process and current all process greatest priority values;
S102: when the priority of process task is close or equal, the value value of process task relatively, preferential operation is worth big task; Perhaps, the also value value of more current all tasks when system overload, the process task of operation value value maximum guarantees the entire system value maximization and is maintained on the acceptable level.
In sum, the value value of task should be got a value according to the value of task itself between the nargin (priority value) of process and current all process greatest priority values.Each task also has a value value, thereby constitutes a dual priority system except distributing priority by nargin.Dual priority system promptly when the rich degree of task is close or equal, the value value of comparison task, preferential operation is worth big task, it can reduce the system resource waste that the phenomenon of jolting causes.The also value value of more current all tasks when system overload, the task of operation value value maximum guarantees the entire system value maximization and is maintained on the acceptable level;
Concrete, consult Fig. 2, as follows about the value value performing step that sets in advance process task:
S201, in process control block (PCB) task_struct, increase " nargin " association attributes: task residue execution time Ct, task submission time Et, task is relatively by time limit Dt, margin value St, current time in system T.Get by the nargin defined formula: St=(Et+Dt)-Ct-T.
The mode of choosing and the real-time task priority attribute of S202, the operation queue structure that keeps the Linux2.6 kernel, candidate's task are constant, are arranged in order the same priority task from small to large by margin value.
S203, in the clock interruption subroutine, increase the real-time update of margin value is handled, promptly along with clock period increase task residue execution time Ct, reduce the margin value St of waiting process, also in the clock interruption subroutine, revise of the selection operation of value value as candidate's task of seizing threshold values.
The real-time scheduling that S204, improvement will realize revises kernel code and recompility, finishes and improves the realization of algorithm in system.
Consult Fig. 3, about improving the real-time scheduling that will realize among the S102, revise kernel code and recompility, finish and improve the realization of algorithm in system, the improvement algorithm concrete steps of being mentioned are achieved as follows:
S301, the slack time of obtaining each task, i.e. " nargin ", forward task priority is high more the off period when nargin is identical.
S302 judges whether current system exists a task that above nargin is close or identical, if do not exist, shows the system task phenomenon of can not jolting, and jumps to S308, carries out the LSF scheduling.The purpose of this step is the anti-locking system phenomenon of jolting.
S303 judges whether this nargin is current system smallest margin, if not, show that then this task is not hot job, jump to S308, carry out the LSF scheduling.
Whether S304 judges this nargin greater than 0, eliminates this task less than 0 the time when nargin, and nargin participates in scheduling more than or equal to 0.
S305 obtains the value value of close or identical and its value of these nargin more than or equal to 0 task, and this value value is being determined as before told.
S306, relatively close or identical and its value of these nargin is more than or equal to the value value of 0 task, and the purpose of this step is to guarantee that entire system is worth the acceptable level that is maintained at.
S307 according to the size of task value value, seizes execution successively, guarantees the task that the value value is beaten, and promptly mission critical is preferentially carried out.
S308 carries out the LSF scheduling.
Referring to Fig. 4, Fig. 4 improves the algorithmic dispatching applicating flow chart, and the scheduling step is as follows:
S401, when dormant state, certain process allow to be seized CPU or from interrupting or system call turns back to situation such as user's attitude and occurs, scheduling occasion brings because process initiatively enters, system enters dispatch state.
S402, above-mentioned improved dispatching algorithm is carried out system call, changes the generation that step can the assurance system reduces the phenomenon of jolting, and saves system resource.Can guarantee that also entire system is worth the acceptable level that is maintained at.
S403 judges whether system transships, if there is not the execution of maintaining the statusquo.If then carry out S404, the purpose of this step is that the assurance system develops towards the overall value maximization under the situation of system overload.
S404, relatively close or identical and its value of these nargin is more than or equal to the value value of 0 task, and the purpose of this step is to guarantee that entire system is worth the acceptable level that is maintained at.
S405, according to the value value size of task, the CPU right to use of current task is seized in the priority of task with maximum value value, and the like execution.
S406 judges whether system recovers normal condition, if then do not jump to S404, to obtain the value value of entire system maximum, if normally jump to S402, system normally moves.
To sum up, the embodiment of the invention is by introducing based on the threshold values of seizing that is worth, both can be under the system overload situation, system can guarantee in time finishing of mission critical, keeping system performance demotes grazioso, unlikelyly thrashing even collapse occur, finally reach just total system value maximization, can also reduce the wasting of resources that causes because of the phenomenon of jolting.
One of ordinary skill in the art will appreciate that all or part of step in the whole bag of tricks of the foregoing description is to instruct relevant hardware to finish by program, this program can be stored in the computer-readable recording medium, storage medium can comprise: ROM (read-only memory) (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), disk or CD etc.
More than to visual the listening method of the geography information of a kind of digital home that the embodiment of the invention provided, be described in detail, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that all can change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.