CN1529233A - Binary chop type task dispatching method for embedding real-time operating system - Google Patents

Binary chop type task dispatching method for embedding real-time operating system Download PDF

Info

Publication number
CN1529233A
CN1529233A CNA2003101004637A CN200310100463A CN1529233A CN 1529233 A CN1529233 A CN 1529233A CN A2003101004637 A CNA2003101004637 A CN A2003101004637A CN 200310100463 A CN200310100463 A CN 200310100463A CN 1529233 A CN1529233 A CN 1529233A
Authority
CN
China
Prior art keywords
task
priority
user
value
ready
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.)
Granted
Application number
CNA2003101004637A
Other languages
Chinese (zh)
Other versions
CN1238787C (en
Inventor
孙晓民
蔡云鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Tsinghua University filed Critical Tsinghua University
Priority to CN 200310100463 priority Critical patent/CN1238787C/en
Publication of CN1529233A publication Critical patent/CN1529233A/en
Application granted granted Critical
Publication of CN1238787C publication Critical patent/CN1238787C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

State mask is adopted in the method to indicate ready state of user's task in a task table arranged in sequence according to priority high and low. Then, dichotomy search is realized by using shift comparison to locate task with highest priority rapidly, based on which, despatcher carries out task scheduling and switching. The method uses first level mask to indicate priority distribution of tasks in ready state. Dichotomy search is utilized to raise efficiency for locating task with highest priority, and to reduce number of time for accessing memory. The invention possesses advantages of stable dispatching time delay, high efficiency and less memory space used. The method implemented in MPC555 hardware platform is as a part of Tsinghua open system of electrical car (Tsinghua OSEK).

Description

The binary chop formula method for scheduling task of embedded real-time operating system
Technical field
The binary chop formula method for scheduling task of embedded real-time operating system belongs to the embedded real-time operating system technical field, particularly based on the embedded real-time operating system of PowerPC processor structure.
Technical background
Task scheduling is one of core of multiple task operating system.The major function of task scheduling is to select a ready user task according to certain rule from user task, and jumps to the user task execution.Most embedded real-time operating system kernels are based on priority scheduling, and both each task was endowed a numerical priority value according to the difference of its significance level, and scheduler is always selected the ready the highest task run of priority.Free sheet rotation therapy of common dispatching method and method of first-in, first-out based on priority.
Task scheduling is mainly realized by scheduler.In order to realize above-mentioned dispatching method, scheduler must be searched task list, obtains the information of the task of should carrying out by scheduling rule, and jumps to correct memory address.Scheduling implementation method described in the present invention, what refer to is exactly this process.
Because it is very frequent that operating system is dispatched in operational process, so the performance of scheduler directly affects the operational efficiency and the system stability of operating system.On the other hand, in Embedded Application, applicable storage resources is very limited, so the design of scheduler will also should consider will save as far as possible the use of resource in requirement of real time, thereby gives application program with bigger usage space.
At present, existing embedded real-time operating system is of a great variety, and their scheduling implementation method differs from one another.In existing disclosed technology, there is order to travel through that ready task is lined up method or improved traversal is lined up method, the structure variable that this method is used is simple, use flexibly, but instability consuming time, must travel through whole task queue under the worst case, therefore under a lot of situation of priority, the longest traversal time-delay is that real-time system is unacceptable.Some real time operating systems such as μ C/OS-II adopt the method for packet map table, and this method is consuming time stable, and efficient is very high, but the structure variable complexity of this method, the storage space of use is big, and is unfavorable for dynamically-changing priority.
Summary of the invention
The object of the present invention is to provide a kind of consuming time stable, efficient is high and structure variable simple, save storage space, is suitable for dynamically changing the embedded real-time operating system binary chop formula dispatching method of task priority.
Main contents of the present invention are:
Employing state mask is represented the ready state of task in the task list, when operating system generates, according to user configured greatest priority distribution state mask, each of this mask has all identified a priority state, when wherein one when being 0, the task of representing this corresponding priority does not all have ready, and promptly this priority tasks lines up to be sky, on the contrary when for 1 the time, represent that ready promptly this priority tasks of this task that corresponding priority is arranged lines up non-NULL.In the operating system process, whenever there being task to enter ready attitude need move the time, perhaps during task termination, corresponding system kernel operation will be revised the respective priority mode bit of state mask.
Utilize displacement method relatively to realize binary chop, locate the limit priority task fast.At first the form with unsigned number reads current state mask value, and priority is that the mask value that the task correspondence of k is read is 2 kTo the system of n task priority, generate comparative factor 2 for the first time N/2, compare with the state mask, if comparative factor greater than mask, then changes comparative factor into 2 N/2-n/4, otherwise change comparative factor into 2 N/2+n/4, repeating above-mentioned comparison step, the increment of each comparative factor reduces by half, and is 1 up to comparative factor, can obtain the mask value of limit priority task correspondence.Total number of comparisons only needs log 2(n+1) inferior.
The invention is characterized in: it is a kind of when task is initiatively applied for scheduling or stopped, when perhaps interrupt service routine has activated new task, at the PowerPC processor and based on the fifo queue dispatching method of priority; Its first employing state mask is represented the ready state of task in the task list, and task list is that list by order according to priority is big or small for the user, utilize displacement method relatively to realize binary chop then, locate the limit priority task fast, scheduler then carries out task in view of the above and switches; Whole process realizes that with the form of operating system code it contains following steps successively:
(1) setting operation system code, it is kept in the storer of MPC555 controller, comprises as the lower part:
The system start-up code: the operation that contains hardware initialization, initialization storehouse, the tabulation of initialization ready task successively and begin to dispatch automatically performs when system power-on reset;
The system kernel operation code: it supports preemption scheduling, comprises the code of activate a task, terminated task and the scheduler operation of calling for system start-up code, user task code or interrupt handling routine; Described scheduler operation code is meant that strategy is chosen the operation that a user task jumps to this task execution again from the ready task tabulation according to the rules;
The user task code: should by user-defined user task can other task of calling system kernel operations deactivation, application scheduling or stop self execution;
The interrupt handling routine operation code: it contains interrupt handling routine inlet, user interrupt service routine and interrupt handling routine successively and finishes three parts; Break in service calling system kernel operations deactivation new task; The priority of Interrupt Process is higher than user task priority;
Ready task tabulation: write down current can carry out arrange and, comprise these three numerical value of task priority, user program entry address and user stack pointer with the user task information of formation form appearance according to priority classification;
Ready attitude task status mask: be used for the current state that the mark task priority is lined up, it is when operating system generates, come the distribution state mask according to user configured priority orders, each binary digit of mask has identified a priority state, priority is the n position of the corresponding mask of task of n, when this position is 0, that the task of representing corresponding priority does not have is ready (or this priority tasks line up be empty), when being 1, represent that the task of corresponding priority is ready (or this priority tasks line up in have ready task);
(2) determine the limit priority task with binary chop:
Search target in the binary chop, be decided to be all ready attitude Charge-de-Mission's element sum here, i.e. state mask value, priority is that to be equivalent to search the tabulation intermediate value be 2 to the task of n nElement; When the limit priority task priority of ready attitude is k, then the element of its representative is 2 k, and all ready attitude Charge-de-Mission's element sum is more than or equal to 2 k, and less than 2 K+1, and just in time fall on the position of limit priority task correspondence at last between the seek area of binary chop;
Set the performance variable of binary chop:
The copy variable of current priority distribution mask;
Two fens incremental variables write down each recycle ratio priority increment, the size of sublist when its expression is searched at every turn, and initial value is half of state mask figure place;
The comparative factor variable, the comparative factor that the each circulation of record generates, it represents the value of the element of being read in each binary chop, and initial value is 0;
The priority variable that adds up, its final value is exactly a highest priority value, and initial value is 0; The position that pointer is searched in its representative at every turn, each recycle ratio than the time, according to last time result relatively, its value or keep last value, the perhaps result who adds up for self last value and two fens incremental variable values;
The transition variable uses when generating comparative factor, and initial value is 0;
Search procedure is as follows successively:
Numerical value among CPU general-purpose register r27~r31 is kept in the user stack, and these registers are used as the above-mentioned storage space of respectively searching variable;
Form with unsigned number is loaded into current state mask value in the priority state mask copy variable;
Carry out the circulation comparison procedure according to the following steps:
At first two fens incremental variables and priority add up variable and be placed in the transition variable, be to make power in the end to obtain comparative factor by the transition variable with 2;
Again comparative factor and state mask value relatively, if the value of comparative factor is less than the state mask value, then the priority variate-value that adds up is made as the currency of transition variable, and variable remains unchanged otherwise priority adds up;
Two fens incremental variables are reduced by half, repeat above comparison procedure, until two fens increments are 1 can't reduce by half again, this moment, the priority value of preserving in the variable that adds up was the highest current priority value;
(3) obtain user task information: the limit priority with acquisition is an index, and the element of this squadron of priority query head is taken out in the task priority formation in the tabulation of visit ready task, promptly obtains the user task information that carry out;
(4) task is switched: the operation scene of scheduler reading and saving from the user task storehouse of goal task is the CPU register information, and they are write back in the CPU register, and the code that jumps to this user task then goes to carry out.
The present invention uses simple one-level mask structure and need not other supplementary structure, thereby has reduced memory space requirements, uses efficiently binary chop and reduces the internal storage access number of times, makes scheduler latency stable, and operation is efficient, and has improved dirigibility.Reach the purpose of when satisfying the system real time requirement, also having saved storage space by these technical characterstics.
Description of drawings
Fig. 1: binary chop schematic diagram.
Fig. 2: the OSEK of Tsing-Hua University operating system sketch.
Fig. 3: the corresponding relation figure of ready task tabulation and task status mask.
Fig. 4: scheduler theory diagram.
Fig. 5: the realization flow figure of scheduler on MPC555 microcontroller platform.
Fig. 6: MPC555 microcontroller register classification synoptic diagram.
Embodiment
Binary chop is a kind of ordered list lookup method commonly used.Its principle is seen Fig. 1.Be without loss of generality, establish element in the tabulation by arranging from big to small.Binary chop begins whole tabulation is searched most.Search the element of pointed tabulation mid point, get the element comparison that this element and desired value promptly will be searched,, then search successfully if both are equal just; If the mid point element value is less than desired value, the element that explanation will be searched is at the first half of table, otherwise the element that explanation will be searched is at the latter half of table.According to judged result, get the first half sublist or the latter half sublist of tabulation, will search the mid point element of the pointed sublist comparison procedure above repeating, up to searching till success or tabulation can't split again.Binary chop is that the tabulation of n at most only need be searched [log to length 2(n+1)] ([] expression round up) is inferior, needs at most to compare for n time with sequential search, and efficient obviously improves.
The method that the present invention proposes is the part of embedded real-time operating system kernel, with the form realization of operating system code.Below with the OSEK of Tsing-Hua University (automobile-used open system and the interface specification thereof) operating system of Tsing-Hua University's independent development, be example based on the hardware platform environment of MPC555 microcontroller, the embodiment of this dispatching method is described.
Tsing-Hua University's OSEK operating system that runs on the MPC555 platform comprises six parts: start-up code, system kernel operation, user task code, interrupt handling routine, ready task tabulation and task status mask.As shown in Figure 2.
The interrupt vector table of MPC555 microcontroller has been stipulated a plurality of program entries address.Wherein 0x100 is the entry address of system start-up code.Start-up code automatically performs when system power-on reset.The first step is carried out the hardware initialization operation earlier, promptly temporarily forbids hardware interrupts, system clock frequency is set and closes software watchdog.The details of these operations sees Table 1 explanation.The second step operation is the address (concrete numerical value is specified by the user) that SP and data segment base address register is set to system stack and data segment respectively.The 3rd step operation is that the task that can begin to carry out is added in the ready task tabulation and set up task priority and line up and task status mask (detailed description is seen below).At last, start-up code is opened the hardware interrupts switch and is allowed hardware interrupts, and the operation of the scheduler in the executive system kernel operations again begins to carry out user task.Scheduler method used according to the invention selects user task to carry out from ready tabulation.
Table 1MPC555 initialization procedure main hardware operating list
Hardware operation The corresponding hardware method to set up
Forbid hardware interrupts Write any number toward No. 81 specified register, as carrying out assembly instruction mtspr 81, r3.
Allow hardware interrupts Write any number toward No. 80 specified register, as carrying out assembly instruction mtspr 80, r3.
System clock frequency is set Phaselocked loop is set, low electricity and the control register PLPRCR that resets (address 0x12FC284), when the hardware crystal oscillator is 4MHz, if PLPRCR=0x900000, system clock frequency is 40MHz, if during PLPRCR=0x400000, system clock frequency is 20MHz.
Close software watchdog With minimum the 3rd clear 0 (such as the SYPCR=0xFFFFFF03) of system protection control register SYPCR (address 0x12FC004).
The system kernel operation comprises activate a task, terminated task and three operations of scheduler.The activate a task operation is added a user task to the ready task tabulation, and the terminated task operation is with task deletion from the ready task tabulation.Scheduler is the core of task handover mechanism, chooses a user task according to certain strategy from the ready task tabulation, jumps to this task and begins to carry out.The system kernel operation code is supported preemption scheduling, when promptly working as the user task of a high priority of user task code or interrupt handling routine calling system kernel operations activation, the activate a task operation can be called scheduler and be selected new activating of task, pressure interrupts the lower user task of priority that is moving, and the task of forwarding activation to goes to carry out.
Interrupt handling routine is a part relatively independent in the operating system, and this part code is placed on place, interrupt handling routine entry address.It is triggered by the hardware event in the system, and the software and hardware state decision when when carrying out by operation can't be estimated in design.In the MPC555 microcontroller, the external interrupt handling procedure is placed on 0x500 place, entry address, and the counter interrupt handling routine is placed on 0x900 place, entry address.After hardware produced look-at-me, CPU responded interruption, automatically switched to corresponding entry address execution command.Interrupt handling routine can the calling system kernel operations, activates new task, thereby upsets the flow process that user task is carried out.It contains interrupt handling routine inlet, user interrupt service routine and interrupt handling routine successively and finishes three parts.The priority of Interrupt Process is higher than user task priority, by the new task that user interrupt service routine has activated, carries out by scheduler after can only waiting interrupt handling routine to finish again.Be embodied in the system of Fig. 2, when the interruption handling procedure calls the kernel operations of " activate a task ", this kernel operations will be never called scheduler, but be called by the interrupt handling routine latter end.
The current user task information that can carry out of ready task list records comprises task priority, user program entry address, user stack pointer.These three numerical value define voluntarily by the user at first.In system's operational process, personal code work or operating system code can be revised the value of user stack pointer, preserve or the purpose of restore data thereby reach in storehouse.If a task is placed in the ready task tabulation, claim these tasks to be in ready attitude.Ready tabulation is made up of a plurality of task priority formations, and the number of formation is identical with the number of numerical priority value.User task information is arranged according to priority classification, and the task of each priority is placed in the formation.It is a series of first in first out (FIFO) formations that task priority is lined up, formation of each priority.When carrying out the activate a task operation, the system kernel operation is added this task to the ready task tabulation, and its mission number is added in the fifo queue of respective priority, carries out mask map then and finishes the mapping of ready list state to task state mask.
The task status mask is used for the current state that the mark task priority is lined up.When operating system generates, according to user configured greatest priority distribution state mask, each binary digit of mask has identified a priority state, priority be the corresponding mask of the task of n the n position, when this position is 0, that the task of representing corresponding priority does not have is ready (or this priority tasks line up be empty), when being 1, represents that the task of corresponding priority is ready (or this priority tasks line up in have ready task).The mask figure place of distributing is 2 power, if task greatest priority value is 2 nWith 2 N+1Between, then distribute 2 N+1The position.When user task or interrupt service routine calling system kernel operations activate a task, if a certain priority tasks is lined up by space-variant to not empty, then activate a task is operated the mask that will change the priority correspondence and is put 1.When user task finished, empty if this priority tasks lines up to become, then the terminated task operation was with the mask of this priority correspondence clear 0.Ready task lines up to see shown in Figure 3 with the corresponding relation of task status mask.
The OSEK of Tsing-Hua University has following feature as the operating system that meets the OSEK standard:
Each task is with its significance level of priority number value representation.The task that scheduler is selected to be in the limit priority in the ready task tabulation is carried out.The task of same priority is deferred to the principle of first in first out, and the priority of task that promptly adds the ready task tabulation is earlier carried out.
Support preemption scheduling, promptly high user task of priority can force to interrupt the execution of the low user task of priority.
Interrupt handling routine priority is higher than user task priority.If in interrupt handling routine, activated new task, can not carry out task scheduling at once, and just carry out after should waiting interrupt handling routine to finish.So preemption scheduling only occurs in ground floor interrupt routine end.
In the operating system that meets the OSEK standard, select next task to move two kinds of situations.A kind of is because the user has activated the task higher than the priority of current task, and in this case, system directly carries out task and switches between the two, and the concrete steps that task is switched are described in detail in the back.At this moment, need not to consider again the situation of whole ready task tabulation.Another kind of situation is when initiatively applying for scheduling or termination by task, when perhaps interrupt service routine has activated new task, when perhaps jumping to the user task execution by system initialization code, scheduler will consider that whole ready task tabulation could determine the task of next operation.In the system that the present invention realizes, to the processing of first kind of situation and the processing basically identical of present other operating system, that is to say, in the system of Fig. 2, when user task calls scheduler and carries out task scheduling by " activate a task " kernel operations, will not relate to the method that the present invention adopts.The system that the present invention realizes is primarily aimed at the above-mentioned second class situation and improves.
The theory diagram of implementation procedure of the present invention as shown in Figure 4.Scheduler is carried out following situation: user task directly calls scheduler or passes through " terminated task " system kernel operation calls scheduler, perhaps interrupt service routine has activated new task and called scheduler when Interrupt Process finishes, and perhaps scheduler is finished and called when preparing to switch to user task to system initialization code.In these cases, scheduler is carried out by the method that the present invention realizes.At first determine limit priority with binary chop.The performance variable that this step relates to has: priority state mask copy variable (the priority distribution mask that loading system is current), two fens incremental variables (writing down each round-robin priority increment), comparative factor variable (comparative factor that the each circulation of record generates), priority add up variable (its accumulation result is a highest priority value) and transition variable (using when generating comparative factor), be in operation, system puts into user stack with original numerical value of CPU general-purpose register r27~r31, and this several 32 general-purpose register uses as the storage space of above-mentioned variable respectively.The initial value of two fens incremental variables is half of state mask figure place, other variable initial value is 0, form with unsigned number is loaded into current state mask value in the priority state mask copy variable then, begin to carry out the circulation comparison procedure: the variate-value that at first two fens incremental variable values and priority added up and put into the transition variable, is that end power obtains comparative factor by the transition variable with 2, then comparative factor and state mask value are compared, if its value is less than the state mask value, then the priority variate-value that adds up is made as the current value of transition variable, variate-value remains unchanged otherwise priority adds up, then two fens incremental variable values are removed two, regenerate comparative factor, repeat comparison procedure.For example to the system of n priority, the initial value of two fens incremental variables is n/2, and drawing first round transition variable relatively thus is n/2, and comparative factor is 2 N/2, if the value of this comparative factor is less than the state mask value, then the priority variate-value that adds up is made as n/2, and increment was reduced to n/4 in two minutes, and such second comparative factor of taking turns generation is 2 N/2+n/4, variable remains 0 constantly otherwise priority adds up, and increment was reduced to n/4 in two minutes, and second comparative factor of taking turns generation just is 2 N/4=2 N/2-n/4Said process repeats to two fens increments always and is 1, finishes in the time of can not reducing by half again.The value of preserving in priority adds up variable at this moment, is exactly a highest current priority value.
Said process is a kind of distortion of binary chop.Priority is that the task of the n intermediate value that is equivalent to tabulate is 2 nElement.Search target in the binary chop, be decided to be all ready attitude Charge-de-Mission's element sum here, i.e. the state mask value.The limit priority task priority of supposing to be in ready attitude is k, and then the element of its representative is 2 k, and all ready attitude Charge-de-Mission's element sum is more than or equal to 2 k, and less than 2 K+1, like this, just in time fall on the position of limit priority task correspondence at last between the seek area of binary chop.Search procedure does not have explicit structure to search tabulation, and the value of the element of being read in only needing at every turn search with the representative of comparative factor variable, with the priority position that the variable representative searches pointer of adding up, the size of sublist when incremental variable was represented to search in two minutes at every turn.Each relatively the time, if comparative factor, changes the priority variable that adds up greater than the state mask, the first half that is equivalent to get sublist continues to search, otherwise the latter half that is equivalent to get sublist is searched.Thereby saved the memory headroom that takies greatly.
After obtaining current limit priority, come location tasks according to it.With priority is that index carries out memory address one time, and the task that just can navigate to current this operation from ready task tabulation is lined up, and reads the user task information of head of the queue.
Obtain the mission bit stream of limit priority in system after, carry out task and switch.Task is switched when being meant that forwarding another task to interrupting current task carries out, the task run scene that to be interrupted is that the register holds of CPU is in the user stack to the memory headroom that the user reserves, when returning to this user task execution, the content of preserving is write the CPU register again, like this, user task can be as not being interrupted normal operation.The MPC555 microcontroller belongs to the processor of PowerPC structure, and its register complete or collected works see Fig. 6, and wherein, the register that user program operation need be preserved is as shown in table 2.
In the PowerPC processor structure, return address when LR preserves function call, the processor configuration status of MSR save routine operational process, SRR0 preserves the return address after the End of Interrupt, SRR1 preserves the MSR state when interrupting taking place, CR, XER preserve the zone bit that integer arithmetic, logical operation and floating-point operation instruction are provided with, and CTR is used for the program loop counting.These registers are that program operation process is requisite.Therefore, recovered to carry out, must recover the original state of these registers, just can make program run normal if one section program interrupts the back.Among general-purpose register r0~r31, r1 is a stack pointer, and r2, r13 are the base address of system's small data segments, and the content of these several registers can not destroyed by user task.R0, import into when r3~r12 is used for function call and return parameters, r14~r31 is used to preserve temporary variable, and user task will normally move and must guarantee that these registers are correctly kept and recover.
The main register tabulation of table 2 PowerPC structure treatment device
Title Write a Chinese character in simplified form
General-purpose register GPR0~GPR31 (write a Chinese character in simplified form r0~r31),
Flating point register FPR0~FPR31 (write a Chinese character in simplified form f0~f31),
Link register ????LR
Condition register ????CR
Machine status register(MSR) ????MSR
Machine state preservation/recovery register ????SRR0、SRR1
The floating-point status register ????FPSCR
The integer exception register ????XER
Counter register ????CTR
According to PowerPC-EABI standard (based on the embedded system code interface standard of PowerPC structure), general-purpose register r1 as the pointer to stack of current task, is called stack register again in operating system, is called for short SP.
User task activate interrupted or apply for dispatching in, activate a task operation or scheduler be SP directed towards user storehouse, and preserve the on-the-spot requisite space of CPU with moving on the stack pointer, then the user task scene is kept in this memory headroom; When decision switches to this task execution, the user task scene that scheduler will originally be kept in the user stack installs in the CPU relevant register, then stack pointer is moved down same space, write down the position that the user task code should begin or continue execution this moment in the SRR0 register, scheduler is carried out the rfi instruction, just jumps in the user task code and carries out.
The process flow diagram that software program of the present invention is realized as shown in Figure 5.
After system realized, we ran at the MPC555 evaluating system this dispatching method under the clock frequency of 40M and test, and the needed time of process of seeking limit priority is stabilized in 2.5 μ S, and it is promptly efficiently stable again to line up method than the traversal ready task.More outstanding aspect storage demand, only need 4 bytes, with the huge storage demand contrast of the method for level packet mapping, this method had both been saved storage space, and was flexible again.
In the system to n priority, it is [log that the maximum of the needs of employing the inventive method is searched number of times 2(n+1)] inferior, and employing in proper order the maximum that needs of traversal method to search number of times be n time, the inventive method obviously is better than order traversal method on algorithm complex, and is slightly poorer than the level packet reflection method (no matter priority how much, all only needs twice table lookup operation) that μ C/OS-II operating system adopts.But the inventive method is significantly less than the level packet reflection method on storage space takies.For example to the system of 32 priority, the inventive method only need be represented the state mask with 4 bytes (32 binary digits).And the level packet reflection method need be one to set up upright mapping table with 8 priority, and first order mask needs 1 byte, and mapping table needs 4 bytes, and second level mask needs 8 bytes, and mapping table needs 2 8=256 bytes need 269 bytes altogether.Concrete comparative result sees Table 3.In addition, compare with the packet map method, the mask structure that the inventive method adopts is simpler, thereby dynamically changes in operating system under the situation of task priority, changes the required operation of state mask and wants much less than the grouping reflection method.As seen, the inventive method has comprehensive performance.
The time of several scheduling implementation methods of table 3 and space efficiency be (is example with 32 priority) relatively
Dispatching method Search number of times The speed assessment Storage demand
The inventive method ????5 Stable, very fast 4 bytes (low)
The level packet reflection method ????2 Stable, fast 269 bytes (height)
Order traversal method ????1~32 Unstable 4 bytes (low)

Claims (1)

1. the binary chop formula method for scheduling task of embedded real-time operating system, the lookup method that comprises the ready task formation, it is characterized in that: it is a kind of when task is initiatively applied for scheduling or stopped, when perhaps interrupt service routine has activated new task, at the PowerPC processor and based on the fifo queue dispatching method of priority; Its first employing state mask is represented the ready state of task in the task list, and task list is that list by order according to priority is big or small for the user, utilize displacement method relatively to realize binary chop then, locate the limit priority task fast, scheduler then carries out task in view of the above and switches; Whole process realizes that with the form of operating system code it contains following steps successively:
(1) setting operation system code, it is kept in the storer of MPC555 controller, comprises as the lower part:
The system start-up code: the operation that contains hardware initialization, initialization storehouse, the tabulation of initialization ready task successively and begin to dispatch automatically performs when system power-on reset;
The system kernel operation code: it supports preemption scheduling, comprises the code of activate a task, terminated task and the scheduler operation of calling for system start-up code, user task code or interrupt handling routine; Described scheduler operation code is meant that strategy is chosen the operation that a user task jumps to this task execution again from the ready task tabulation according to the rules;
The user task code: should by user-defined user task can other task of calling system kernel operations deactivation, application scheduling or stop self execution;
The interrupt handling routine operation code: it contains interrupt handling routine inlet, user interrupt service routine and interrupt handling routine successively and finishes three parts; Break in service calling system kernel operations deactivation new task; The priority of Interrupt Process is higher than user task priority;
Ready task tabulation: write down current can carry out arrange and, comprise these three numerical value of task priority, user program entry address and user stack pointer with the user task information of formation form appearance according to priority classification;
Ready attitude task status mask: be used for the current state that the mark task priority is lined up, it is when operating system generates, come the distribution state mask according to user configured priority orders, each binary digit of mask has identified a priority state, priority is the n position of the corresponding mask of task of n, when this position is 0, that the task of representing corresponding priority does not have is ready (or this priority tasks line up be empty), when being 1, represent that the task of corresponding priority is ready (or this priority tasks line up in have ready task);
(2) determine the limit priority task with binary chop:
Search target in the binary chop, be decided to be all ready attitude Charge-de-Mission's element sum here, i.e. state mask value, priority is that to be equivalent to search the tabulation intermediate value be 2 to the task of n nElement; When the limit priority task priority of ready attitude is k, then the element of its representative is 2 k, and all ready attitude Charge-de-Mission's element sum is more than or equal to 2 k, and less than 2 K+1, and just in time fall on the position of limit priority task correspondence at last between the seek area of binary chop;
Set the performance variable of binary chop:
The copy variable of current priority distribution mask;
Two fens incremental variables write down each recycle ratio priority increment, the size of sublist when its expression is searched at every turn, and initial value is half of state mask figure place;
The comparative factor variable, the comparative factor that the each circulation of record generates, it represents the value of the element of being read in each binary chop, and initial value is 0;
The priority variable that adds up, its final value is exactly a highest priority value, and initial value is 0; The position that pointer is searched in its representative at every turn, each recycle ratio than the time, according to last time result relatively, its value or keep last value, the perhaps result who adds up for self last value and two fens incremental variable values;
The transition variable uses when generating comparative factor, and initial value is 0;
Search procedure is as follows successively:
Numerical value among CPU general-purpose register r27~r31 is kept in the user stack, and these registers are used as the above-mentioned storage space of respectively searching variable;
Form with unsigned number is loaded into current state mask value in the priority state mask copy variable;
Carry out the circulation comparison procedure according to the following steps:
At first two fens incremental variables and priority add up variable and be placed in the transition variable, be to make power in the end to obtain comparative factor by the transition variable with 2;
Again comparative factor and state mask value relatively, if the value of comparative factor is less than the state mask value, then the priority variate-value that adds up is made as the currency of transition variable, and variable remains unchanged otherwise priority adds up;
Two fens incremental variables are reduced by half, repeat above comparison procedure, until two fens increments are 1 can't reduce by half again, this moment, the priority value of preserving in the variable that adds up was the highest current priority value;
(3) obtain user task information: the limit priority with acquisition is an index, and the element of this squadron of priority query head is taken out in the task priority formation in the tabulation of visit ready task, promptly obtains the user task information that carry out;
(4) task is switched: the operation scene of scheduler reading and saving from the user task storehouse of goal task is the CPU register information, and they are write back in the CPU register, and the code that jumps to this user task then goes to carry out.
CN 200310100463 2003-10-17 2003-10-17 Binary chop type task dispatching method for embedding real-time operating system Expired - Fee Related CN1238787C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200310100463 CN1238787C (en) 2003-10-17 2003-10-17 Binary chop type task dispatching method for embedding real-time operating system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200310100463 CN1238787C (en) 2003-10-17 2003-10-17 Binary chop type task dispatching method for embedding real-time operating system

Publications (2)

Publication Number Publication Date
CN1529233A true CN1529233A (en) 2004-09-15
CN1238787C CN1238787C (en) 2006-01-25

Family

ID=34304047

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200310100463 Expired - Fee Related CN1238787C (en) 2003-10-17 2003-10-17 Binary chop type task dispatching method for embedding real-time operating system

Country Status (1)

Country Link
CN (1) CN1238787C (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100349121C (en) * 2005-07-08 2007-11-14 北京中星微电子有限公司 Embedded type parallel computation system and embedded type parallel computing method
CN100351793C (en) * 2005-09-12 2007-11-28 浙江大学 Task scheduling method for embedded real-time operation system supporting OSEK standard
CN102004664A (en) * 2010-10-18 2011-04-06 北京控制工程研究所 Scheduling method of embedded real-time operating system of space vehicle
CN102957178A (en) * 2011-08-24 2013-03-06 上海晨兴希姆通电子科技有限公司 Application method of modified binary search algorithm in charge management
CN101547149B (en) * 2009-04-20 2013-06-19 浙江大学 Dynamic scheduling method for OSEK COM messages based on CAN network
CN103729245A (en) * 2013-12-27 2014-04-16 普华基础软件股份有限公司 OSEK operating system kernel dynamic process staticizing method
US20150215633A1 (en) * 2012-08-22 2015-07-30 Nec Corporation Image-data binary arithmetic decoding device and image decoding device
CN105467873A (en) * 2015-11-27 2016-04-06 北京友信宏科电子科技有限公司 Task scheduling method and device of vehicle alternating-current motor controller
CN110673937A (en) * 2019-09-19 2020-01-10 惠州志顺电子实业有限公司 Single chip microcomputer and synchronous and asynchronous control method thereof
CN116974728A (en) * 2023-09-20 2023-10-31 深圳市德兰明海新能源股份有限公司 Singlechip task scheduling method, singlechip product and storage medium
CN118025049A (en) * 2024-04-15 2024-05-14 成都创科升电子科技有限责任公司 Control method and system for vehicle electric control based on scheduler and vehicle

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100349121C (en) * 2005-07-08 2007-11-14 北京中星微电子有限公司 Embedded type parallel computation system and embedded type parallel computing method
CN100351793C (en) * 2005-09-12 2007-11-28 浙江大学 Task scheduling method for embedded real-time operation system supporting OSEK standard
CN101547149B (en) * 2009-04-20 2013-06-19 浙江大学 Dynamic scheduling method for OSEK COM messages based on CAN network
CN102004664A (en) * 2010-10-18 2011-04-06 北京控制工程研究所 Scheduling method of embedded real-time operating system of space vehicle
CN102957178A (en) * 2011-08-24 2013-03-06 上海晨兴希姆通电子科技有限公司 Application method of modified binary search algorithm in charge management
CN102957178B (en) * 2011-08-24 2015-09-09 上海晨兴希姆通电子科技有限公司 The application process of binary search algorithm in Charge Management improved
US20150215633A1 (en) * 2012-08-22 2015-07-30 Nec Corporation Image-data binary arithmetic decoding device and image decoding device
CN103729245B (en) * 2013-12-27 2017-03-08 普华基础软件股份有限公司 A kind of OSEK operating system nucleus dynamic process static method
CN103729245A (en) * 2013-12-27 2014-04-16 普华基础软件股份有限公司 OSEK operating system kernel dynamic process staticizing method
CN105467873A (en) * 2015-11-27 2016-04-06 北京友信宏科电子科技有限公司 Task scheduling method and device of vehicle alternating-current motor controller
CN105467873B (en) * 2015-11-27 2018-04-17 北京友信宏科电子科技有限公司 A kind of method for scheduling task and device of vehicle AC motor control
CN110673937A (en) * 2019-09-19 2020-01-10 惠州志顺电子实业有限公司 Single chip microcomputer and synchronous and asynchronous control method thereof
CN110673937B (en) * 2019-09-19 2022-11-15 惠州志顺电子实业有限公司 Single chip microcomputer and synchronous and asynchronous control method thereof
CN116974728A (en) * 2023-09-20 2023-10-31 深圳市德兰明海新能源股份有限公司 Singlechip task scheduling method, singlechip product and storage medium
CN116974728B (en) * 2023-09-20 2024-01-02 深圳市德兰明海新能源股份有限公司 Singlechip task scheduling method, singlechip product and storage medium
CN118025049A (en) * 2024-04-15 2024-05-14 成都创科升电子科技有限责任公司 Control method and system for vehicle electric control based on scheduler and vehicle

Also Published As

Publication number Publication date
CN1238787C (en) 2006-01-25

Similar Documents

Publication Publication Date Title
CN1208721C (en) Graded task switching method based on PowerPC processor structure
US10255287B2 (en) Method and apparatus for on-disk deduplication metadata for a deduplication file system
Graefe Implementing sorting in database systems
CN1294485C (en) Dependence-chain processors
Tian et al. Practical methods for constructing suffix trees
US10007605B2 (en) Hardware-based array compression
CN1238787C (en) Binary chop type task dispatching method for embedding real-time operating system
US20130117494A1 (en) Optimizing available computing resources within a virtual environment
JP7047228B2 (en) Data query methods, devices, electronic devices, readable storage media, and computer programs
EP1402254A1 (en) Method and apparatus for high-speed approximate sub-string searches
CN1783020A (en) Interrupt managing method for embedded operation system based on PowerPC system structure
US11016676B2 (en) Spot coalescing of distributed data concurrent with storage I/O operations
EP1899799A2 (en) Storage architecture for embedded systems
US7653643B2 (en) Method and apparatus for compressing a data set
US20100191717A1 (en) Optimization of query processing with top operations
CN101051302A (en) Method and system for loading programme on computer system
CN1260546A (en) Method and apparatus for storing and searching data in hand-held device
CN200953143Y (en) Virtual hardware system
CN1109979C (en) Method for quick protection and recovery for hard disc data of computer
Guyetant et al. Cluster of re-configurable nodes for scanning large genomic banks
Park et al. KV-CSD: A Hardware-Accelerated Key-Value Store for Data-Intensive Applications
Marin et al. High-performance priority queues for parallel crawlers
Tang et al. Stem: Streaming-based fpga acceleration for large-scale compactions in lsm kv
CN1238788C (en) First-in first-out register quenue arrangement capable of processing variable-length data and its control method
CN1118758C (en) Realizing method of plug-and-play (pnp) virtual CD memory system with very high capacity

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
C19 Lapse of patent right due to non-payment of the annual fee
CF01 Termination of patent right due to non-payment of annual fee