[go: up one dir, main page]

CN1737764A - Task Scheduling Method of Embedded Real-time Operating System Supporting OSEK Standard - Google Patents

Task Scheduling Method of Embedded Real-time Operating System Supporting OSEK Standard Download PDF

Info

Publication number
CN1737764A
CN1737764A CN 200510060735 CN200510060735A CN1737764A CN 1737764 A CN1737764 A CN 1737764A CN 200510060735 CN200510060735 CN 200510060735 CN 200510060735 A CN200510060735 A CN 200510060735A CN 1737764 A CN1737764 A CN 1737764A
Authority
CN
China
Prior art keywords
task
scheduling
state
priority
running environment
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
CN 200510060735
Other languages
Chinese (zh)
Other versions
CN100351793C (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.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
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 Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CNB2005100607354A priority Critical patent/CN100351793C/en
Publication of CN1737764A publication Critical patent/CN1737764A/en
Application granted granted Critical
Publication of CN100351793C publication Critical patent/CN100351793C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

This invention relates to one task dispatching optimization method to support OSEK standard imbedded operation system, which comprises the following steps: a, analyzing each switch situations according to task situation; b, dividing the dispatching process into four steps: finding optimization task in the prepare task; storing the current operation task environment; demoting the CPU needle; restoring optimization task running environment; c, optimizing the dispatching strategy according to four steps covering situation into four types of strategy; d, selecting different dispatching strategy according to real dispatching situation.

Description

支持OSEK标准的嵌入式实时操作系统的任务调度方法Task Scheduling Method of Embedded Real-time Operating System Supporting OSEK Standard

技术领域technical field

本发明涉及嵌入式实时操作系统技术,主要是一种支持OSEK标准的嵌入式操作系统的任务调度优化方法。The invention relates to an embedded real-time operating system technology, and mainly relates to a task scheduling optimization method of an embedded operating system supporting the OSEK standard.

背景技术Background technique

随着软硬件技术的快速发展,嵌入式操作系统已经应用到各个领域,自动控制、交通、航空航天等等。嵌入式实时操作系统(Real-Time Operating System,简称RTOS)与其他普通的系统之间的最大的不同就是要严格满足事务与时间的关系。比如大型设备的控制部分、汽车电控系统,都要求所采用的实时操作系统能快速响应,快速进行调度,来应对各种对时间要求很苛刻的情况。With the rapid development of software and hardware technology, embedded operating systems have been applied to various fields, such as automatic control, transportation, aerospace and so on. The biggest difference between embedded real-time operating system (Real-Time Operating System, RTOS for short) and other common systems is to strictly satisfy the relationship between transactions and time. For example, the control part of large-scale equipment and the electronic control system of automobiles all require the real-time operating system adopted to be able to respond quickly and dispatch quickly to deal with various situations with strict time requirements.

任务调度是嵌入式实时操作系统中最核心、最关键的部分,调度效率直接影响到RTOS的实时性能。衡量一个RTOS的技术,最重要的指标就是调度的任务切换时间TsTask scheduling is the core and most critical part of the embedded real-time operating system, and the scheduling efficiency directly affects the real-time performance of the RTOS. To measure the technology of an RTOS, the most important indicator is the scheduled task switching time T s .

市场上占有率比较高的商用实时操作系统大多数是多任务实时微内核的结构,采用的是基于优先级的可抢占式调度策略。在各种调度情况上,调用同一个函数来完成任务的切换。开放源代码的uC/OS-II提供的实时任务调度方法,就是采用调度函数OSSched()完成的。在OSSched()中,先找到最高优先级的任务,然后用宏调用OS TASK_SW通过系统软中断来完成实际的任务切换的过程,将被挂起任务的运行环境压入堆栈,后面运行的较高优先级任务的运行环境从堆栈中恢复。Most of the commercial real-time operating systems with a relatively high market share are multi-task real-time microkernel structures, and adopt a priority-based preemptive scheduling strategy. In various scheduling situations, call the same function to complete task switching. The real-time task scheduling method provided by the open source uC/OS-II is completed by using the scheduling function OSSched(). In OSSched(), first find the task with the highest priority, and then use the macro to call OS TASK_SW to complete the actual task switching process through the system soft interrupt, push the running environment of the suspended task into the stack, and then run the higher The execution context of the priority task is restored from the stack.

其实这是最复杂的任务切换情况需要做的工作,即当前正在运行的任务被打断,需要保存当前任务的运行环境,再切换到一个原先运行过的任务,需要恢复原先的运行环境,保存和恢复运行环境占据了整个任务切换的大部分时间。对一些简单调度点,如结束当前任务再运行刚激活的任务这种情况,保存和恢复运行环境的过程都是浪费的。这是因为结束任务意味着任务已经完成其功能,不需要保存其运行环境,而激活的任务刚开始运行,也没有以前的运行环境。这也就说明了不考虑所切换任务的状态而采用统一调度,势必会大大影响嵌入式实时操作系统的调度效率。In fact, this is the work that needs to be done in the most complicated task switching situation, that is, the currently running task is interrupted, the running environment of the current task needs to be saved, and then switched to a previously running task, the original running environment needs to be restored, saved And restoring the running environment occupies most of the time of the whole task switching. For some simple scheduling points, such as ending the current task and then running the newly activated task, the process of saving and restoring the running environment is a waste. This is because ending a task means that the task has completed its function and does not need to save its running environment, while an activated task has just started running and has no previous running environment. This also shows that the unified scheduling is adopted regardless of the status of the switched tasks, which will greatly affect the scheduling efficiency of the embedded real-time operating system.

发明内容Contents of the invention

本发明的目的是针对上述缺陷,提供一种支持OSEK标准的嵌入式操作系统的任务调度优化方法。The purpose of the present invention is to provide a kind of task scheduling optimization method of the embedded operating system that supports OSEK standard for above-mentioned defect.

本发明解决其技术问题所采用的方案是:通过详细分析支持OSEK标准的操作系统的任务切换状态,细分不同的调度点情况,针对每种调度点采用专用的调度策略,使任务切换时间在多数情况下明显减少,大大优化实时操作系统的时间性能。The scheme adopted by the present invention to solve its technical problems is: by analyzing in detail the task switching state of the operating system supporting the OSEK standard, subdividing the situation of different scheduling points, adopting a special scheduling strategy for each scheduling point, so that the task switching time is within Significantly reduced in most cases, greatly optimizing the timing performance of real-time operating systems.

本发明的实现步骤如下:The realization steps of the present invention are as follows:

1)、根据任务状态分析各类调度切换情况:1) Analyze various scheduling switching situations according to task status:

1.1)、OSEK标准中根据任务状态分类的不同,将系统分为BCC1(基本任务)、ECC1(扩展任务)两种情况;其中BCC1中的任务状态包含三种情况:运行、就绪、挂起,ECC1中的任务状态包含四种情况:运行、就绪、等待、挂起。本发明将其中的任务就绪状态细分为中间态和初始态,中间态即是任务运行到一半被抢占或等待的事件发生后进入就绪的状态,初始态是任务从挂起被激活到就绪状态或系统启动时任务直接进入的就绪状态;1.1), in the OSEK standard, according to the classification of task status, the system is divided into two situations: BCC1 (basic task) and ECC1 (extended task); among them, the task status in BCC1 includes three situations: running, ready, suspended, The task state in ECC1 includes four situations: running, ready, waiting, and suspended. The present invention subdivides the task ready state into an intermediate state and an initial state. The intermediate state is the state in which the task enters the ready state after half of the task is preempted or waiting for an event to occur. The initial state is that the task is activated from the suspension to the ready state. Or the ready state that the task enters directly when the system starts;

1.2)、在BCC1下的调度情况分为以下三种:1.2), the scheduling situation under BCC1 is divided into the following three types:

调度情况1:当前任务运行结束进入挂起状态,即将运行的高优先级任务为初始态;不用保存当前任务运行环境,直接进行指针赋值等操作后,即可运行后一高优先级任务;Scheduling situation 1: The current task finishes running and enters the suspended state, and the high-priority task that is about to run is in the initial state; there is no need to save the current task running environment, and the next high-priority task can be run after directly performing operations such as pointer assignment;

调度情况2:当前任务运行结束进入挂起状态,即将运行的高优先级任务为中间态;不用保存当前任务运行环境,进行指针赋值等操作后,恢复后一高优先级任务的运行环境,再运行;Scheduling situation 2: The current task finishes running and enters the suspended state, and the high-priority task that is about to run is in the intermediate state; there is no need to save the current task running environment, and after performing operations such as pointer assignment, restore the running environment of the next high-priority task, and then run;

调度情况3:当前任务被抢占进入就绪状态,即将运行的高优先级为初始态;保存当前任务运行环境,进行指针赋值等操作后即可运行高优先级任务。Scheduling situation 3: The current task is preempted and enters the ready state, and the high-priority to be run is the initial state; the high-priority task can be run after saving the current task running environment and performing operations such as pointer assignment.

1.3)、在ECC1下的调度情况,除上述1.2)以外,再加以下三种:1.3) For scheduling under ECC1, in addition to the above 1.2), add the following three:

调度情况4:当前任务进入等待状态,即将运行的高优先级任务为中间态;保存当前任务运行环境,进行指针赋值等操作后,恢复后一高优先级任务的运行环境,再运行;Scheduling situation 4: The current task enters the waiting state, and the high-priority task that is about to run is in the intermediate state; after saving the running environment of the current task, performing pointer assignment and other operations, restore the running environment of the next high-priority task, and then run;

调度情况5:当前任务进入等待状态,即将运行的高优先级任务为初始态;保存当前任务运行环境,进行指针赋值等操作后即可运行高优先级任务;Scheduling situation 5: The current task enters the waiting state, and the high-priority task to be executed is the initial state; the high-priority task can be run after saving the current task running environment and performing operations such as pointer assignment;

调度情况6:当前任务被抢占进入就绪状态,即将运行的高优先级任务为中间态,且该任务是因为其等待的事件发生了而进入中间态的;保存当前任务运行环境,进行指针赋值等操作后,恢复高优先级任务的运行环境,再运行;Scheduling situation 6: The current task is preempted and enters the ready state, and the high-priority task to be run is in the intermediate state, and the task enters the intermediate state because the event it is waiting for occurs; save the current task running environment, perform pointer assignment, etc. After the operation, restore the running environment of the high-priority task and run again;

2)、把调度过程可以分为以下四个步骤:2), the scheduling process can be divided into the following four steps:

2.1)、在就绪任务中查找到最高优先级的任务;2.1), find the highest priority task in the ready task;

2.2)、保存当前运行任务的运行环境;2.2), save the running environment of the current running task;

2.3)、进行CPU占用指针赋值,即交换CPU占有权;2.3), carry out CPU occupancy pointer assignment, that is, exchange CPU occupancy right;

2.4)、恢复最高优先级任务的运行环境;2.4), restore the operating environment of the highest priority task;

3、根据对调度过程四个步骤的覆盖情况,优化调度策略,分为以下四类:3. According to the coverage of the four steps of the scheduling process, optimize the scheduling strategy, which is divided into the following four categories:

3.1)、调度策略A:最简单情况,只做调度过程步骤的2.1)、2.3);3.1), scheduling strategy A: the simplest case, only 2.1) and 2.3) of the scheduling process steps;

3.2)、调度策略B:一般情况,只做调度过程步骤的2.1)、2.2)、2.3);3.2), scheduling strategy B: in general, only 2.1), 2.2), 2.3) of the scheduling process steps are done;

3.3)、调度策略C:一般情况,只做调度过程步骤的2.1)、2.3)、2.4);3.3), scheduling strategy C: in general, only 2.1), 2.3), and 2.4) of the scheduling process steps are done;

3.4)、调度策略D:最复杂情况,做全部调度过程步骤的2.1)、2.2)、2.3)、2.4);3.4), scheduling strategy D: the most complicated situation, do 2.1), 2.2), 2.3), 2.4) of all scheduling process steps;

4、根据任务运行时实际调度情况的不同,选用不同的调度策略:每种情况的调度所耗费的时间T根据所选策略的不同有所不同,D对应的TSD最多,A对应的TSA最少,B和C对应的TSB、TSC为中间值。4. According to the actual scheduling situation when the task is running, different scheduling strategies are selected: the time T spent in the scheduling of each situation is different according to the selected strategy, D corresponds to the most T SD , and A corresponds to T SA At least, T SB and T SC corresponding to B and C are intermediate values.

本发明的显著优点:Significant advantage of the present invention:

统一函数的调度方法的任务切换时间设为TS,从分析上可以直观的看到,本发明的优化调度策略涉及过程少,具有以下调度时间上的明显优势,明显的优化了系统调度的性能:The task switching time of the unified function scheduling method is set as T S . It can be seen intuitively from the analysis that the optimal scheduling strategy of the present invention involves less processes and has the following obvious advantages in scheduling time, which obviously optimizes the performance of system scheduling :

TSA<TST SA < T S ,

TSB<TST SB <T S ,

TSC<TST SC < T S ,

而TSD和TS基本持平。And T SD and T S are basically the same.

附图说明Description of drawings

图1BCC1基本任务状态转换图;Figure 1 BCC1 basic task state transition diagram;

图2本发明的细化后的BCC1基本任务状态转换图;The refined BCC1 basic task state transition diagram of Fig. 2 of the present invention;

图3ECC1扩展任务状态转换图;Figure 3 ECC1 extended task state transition diagram;

图4本发明的细化后的ECC1扩展任务状态转换图;ECC1 extended task state transition diagram after refinement of Fig. 4 of the present invention;

图5本发明的实施例1;Embodiment 1 of the present invention of Fig. 5;

图6本发明的实施例2;Embodiment 2 of the present invention of Fig. 6;

具体实施方式Detailed ways

下面结合附图和两个实施例对发明作进一步介绍。这种支持OSEK标准的嵌入式操作系统的任务调度优化方法,实现步骤如下:The invention will be further introduced below in conjunction with the accompanying drawings and two embodiments. The task scheduling optimization method of the embedded operating system supporting the OSEK standard, the implementation steps are as follows:

一、根据任务状态仔细分析各类调度切换情况。1. Carefully analyze various scheduling switching situations according to the task status.

OSEK标准中根据任务状态分类的不同,将系统分为BCC1(基本任务)、ECC1(扩展任务)两种情况。In the OSEK standard, according to the different task status classifications, the system is divided into BCC1 (basic task) and ECC1 (extended task).

按照OSEK标准,BCC1中的任务状态包含三种情况:运行、就绪、挂起。运行状态的任务是指当前占用CPU的任务,就绪状态的任务是已经做好运行准备、只等CPU时间的任务或运行一半后被其他任务抢占、又在等待CPU时间的任务,挂起状态的任务是自行运行结束或刚刚产生而等待激活的任务。According to the OSEK standard, the task state in BCC1 includes three situations: running, ready, and suspended. Tasks in the running state refer to tasks that currently occupy the CPU. Tasks in the ready state are tasks that are ready to run and only wait for CPU time, or tasks that are preempted by other tasks after running halfway and are waiting for CPU time. Tasks in the suspended state A task is a task that has finished running by itself or has just been generated and is waiting to be activated.

ECC1中的任务状态包含四种情况:运行、就绪、等待、挂起。等待状态是任务等待某一事件发生的状态。其他三种状态和BCC1的情形一样。The task state in ECC1 includes four situations: running, ready, waiting, and suspended. A wait state is a state in which a task is waiting for an event to occur. The other three states are the same as the case of BCC1.

BCC1的基本任务状态转换关系如图1所示。任务就绪态又可以细分为中间态、初始态。中间态即是任务运行到一半被抢占后进入就绪的状态,初始态是任务从挂起被激活到就绪状态或系统启动时任务直接进入的就绪状态。细化后的BCC1任务状态转换关系如图2所示。The basic task state transition relationship of BCC1 is shown in Figure 1. The task ready state can be subdivided into intermediate state and initial state. The intermediate state is the state in which the task enters the ready state after it is preempted half way through its operation. The initial state is the state in which the task enters the ready state directly when the task is activated from suspend or when the system starts. The refined BCC1 task state transition relationship is shown in Figure 2.

因此,在BCC1下的调度情况可以分为以下几种:(RunningTask代表当前运行的任务,HighestTask代表已经找到的最高优先级任务,PCPUCur代表当前占用CPU的任务的指针,调度前PCPUCur指向RunningTask)Therefore, the scheduling situation under BCC1 can be divided into the following types: (RunningTask represents the currently running task, HighestTask represents the highest priority task that has been found, PCPUCur represents the pointer of the task currently occupying the CPU, PCPUCur points to RunningTask before scheduling)

调度情况1:RunningTask运行结束进入挂起状态,HighestTask为初始态。Scheduling situation 1: RunningTask enters the suspended state after running, and HighestTask is in the initial state.

不用保存RunningTask运行环境,直接进行PCPUCur的赋值等操作(把PCPUCur指向HighestTask)后,即可运行HighestTask任务体。这是最简单的情况,只做指针的赋值,不用保存也不用恢复相关运行环境。You don't need to save the running environment of the RunningTask, and you can run the HighestTask task body after directly performing operations such as assignment of PCPUCur (pointing PCPUCur to HighestTask). This is the simplest case, only assigning pointers, without saving or restoring the relevant operating environment.

调度情况2:RunningTask运行结束进入挂起状态,HighestTask为中间态。Scheduling situation 2: RunningTask enters the suspended state after running, and HighestTask is in the intermediate state.

不用保存RunningTask运行环境,进行PCPUCur的赋值等操作后,恢复原来HighestTask的运行环境,继续运行。这是一般情况,需要指针的赋值,恢复相关运行环境,不用保存当前运行环境。There is no need to save the running environment of RunningTask, after performing operations such as assignment of PCPUCur, restore the original running environment of HighestTask and continue running. This is a general situation, which requires the assignment of pointers to restore the relevant operating environment without saving the current operating environment.

调度情况3:RunningTask被抢占进入就绪状态,HighestTask为初始态。Scheduling situation 3: RunningTask is preempted and enters the ready state, and HighestTask is in the initial state.

保存RunningTask运行环境,进行PCPUCur的赋值等操作后即可运行HighestTask任务体。这也是比较一般的情况,需要指针的赋值,需要保存当前运行环境,但不用恢复原先运行环境。Save the RunningTask operating environment, and perform operations such as PCPUCur assignment to run the HighestTask task body. This is also a relatively general situation, which requires the assignment of pointers and the need to save the current operating environment, but does not need to restore the original operating environment.

ECC1情况下扩展任务状态转换关系如图3所示。和BCC1类似,把任务就绪态分为中间态、初始态。不过中间态除了任务被抢占造成的,还可能是因为处于等待状态的任务其等待的事件发生了,该任务进入就绪状态,这种就绪状态也归属到中间态。细化后的ECC1任务状态转换关系如图4所示。In the case of ECC1, the extended task state transition relationship is shown in Figure 3. Similar to BCC1, the task ready state is divided into intermediate state and initial state. However, in addition to being preempted by the task, the intermediate state may also be caused by the waiting event of the task in the waiting state, and the task enters the ready state, which also belongs to the intermediate state. The refined ECC1 task state transition relationship is shown in Figure 4.

因为增加了等待状态,分析后可以知道,除了BCC1下已有的四种调度情况,ECC1还有另外三种情况:Because of the added waiting state, after analysis, we can know that in addition to the four existing scheduling situations under BCC1, there are three other situations in ECC1:

调度情况4:RunningTask进入等待状态,HighestTask为中间态。Scheduling situation 4: RunningTask enters the waiting state, and HighestTask is in the intermediate state.

保存RunningTask运行环境,进行PCPUCur的赋值等操作后,恢复原来HighestTask的运行环境,继续运行。这就是最复杂的调度情况,指针赋值、保存当前运行环境、恢复原先运行环境三种操作都需要。Save the running environment of RunningTask, and after performing operations such as PCPUCur assignment, restore the original running environment of HighestTask and continue running. This is the most complicated scheduling situation, all three operations are required for pointer assignment, saving the current operating environment, and restoring the original operating environment.

调度情况5:RunningTask进入等待状态,HighestTask为初始态。Scheduling situation 5: RunningTask enters the waiting state, and HighestTask is in the initial state.

保存RunningTask运行环境,进行PCPUCur的赋值等操作后,直接运行函数体,不需要恢复运行环境的操作。这在操作复杂度上和调度情况3一样。After saving the running environment of RunningTask and performing operations such as PCPUCur assignment, the function body can be run directly without restoring the running environment. This is the same as scheduling case 3 in terms of operational complexity.

调度情况6:RunningTask被抢占进入就绪状态,HighestTask为中间态,且HighestTask是因为其等待的事件发生了而进入中间态的。Scheduling situation 6: RunningTask is preempted to enter the ready state, HighestTask is in the intermediate state, and HighestTask enters the intermediate state because the event it is waiting for occurs.

保存RunningTask运行环境,进行PCPUCur的赋值等操作后,恢复原来HighestTask的运行环境,继续运行。这在操作复杂度上和调度情况4一样,也是最复杂的情况。Save the running environment of RunningTask, and after performing operations such as PCPUCur assignment, restore the original running environment of HighestTask and continue running. This is the same as scheduling case 4 in terms of operational complexity, and is also the most complicated case.

二、把调度过程分段2. Segment the scheduling process

分析并综合各类情况,调度过程可以分为以下四步:Analyzing and synthesizing various situations, the scheduling process can be divided into the following four steps:

1.在就绪任务中查找到最高优先级的任务(HighestTask)准备切换(必要步骤)1. Find the highest priority task (HighestTask) in the ready task and prepare to switch (necessary step)

2.保存当前运行任务(RunningTask)的运行环境(可选步骤)2. Save the running environment of the current running task (RunningTask) (optional step)

3.进行PCPUCur的指针赋值,即交换CPU占有权(必要步骤)3. Perform pointer assignment of PCPUCur, that is, exchange CPU possession (necessary steps)

4.恢复最高优先级任务(HighestTask)的运行环境(可选步骤)4. Restore the operating environment of the highest priority task (HighestTask) (optional step)

三、对调度策略进行分类。3. Classify scheduling strategies.

根据对调度过程四个步骤的覆盖情况,将调度策略分为以下四类:According to the coverage of the four steps of the scheduling process, the scheduling strategies are divided into the following four categories:

调度策略A:最简单情况,只做调度过程步骤的1、3。Scheduling strategy A: In the simplest case, only steps 1 and 3 of the scheduling process are performed.

调度策略B:一般情况,只做调度过程步骤的1、2、3。Scheduling strategy B: In general, only do steps 1, 2, and 3 of the scheduling process.

调度策略C:一般情况,只做调度过程步骤的1、3、4。Scheduling strategy C: In general, only do steps 1, 3, and 4 of the scheduling process.

调度策略D:最复杂情况,做全部调度过程步骤的1、2、3、4。Scheduling strategy D: In the most complicated case, do steps 1, 2, 3, and 4 of all scheduling processes.

四、根据任务运行时实际调度情况的不同,选用优化的调度策略。4. Select an optimized scheduling strategy according to the actual scheduling situation when the task is running.

每种情况的调度所耗费的时间T根据所选策略的不同有所不同,D对应的TSD最多,A对应的TSA最少,B和C对应的TSB、TSC为中间值。The time T spent in scheduling in each case varies according to the selected strategy. D corresponds to T SD the most, A corresponds to T SA the least, and B and C correspond to T SB and T SC as intermediate values.

实施例1:如图5所示。在BCC1状态下的操作系统,采用全抢占方式。共有三个基本任务,P1,P2,P3,优先级从高到低排列,即P1优先级最高,P2次之,P3优先级最低。Embodiment 1: as shown in Figure 5. The operating system in the BCC1 state adopts the full preemption method. There are three basic tasks, P1, P2, and P3, and the priorities are arranged from high to low, that is, P1 has the highest priority, P2 takes the second place, and P3 has the lowest priority.

t0时刻系统启动,此时任务P1挂起,P2、P3就绪,P2优先级高而先运行,P3处于就绪状态中的初始态。到t1时刻,发生第一次调度,当前任务P2运行结束,初始态的高优先级任务P3运行,这属于最简单的调度情况,采用优化后的调度策略A。The system starts at time t0. At this time, task P1 is suspended, P2 and P3 are ready, P2 has a higher priority and runs first, and P3 is in the initial state of the ready state. At time t1, the first scheduling occurs, the current task P2 finishes running, and the initial high-priority task P3 runs. This is the simplest scheduling situation, and the optimized scheduling strategy A is adopted.

P3一直运行,直到其激活P1。因为P1优先级高于P3,则P3被抢占,t2时刻发生第二次调度,P3进入就绪状态的中间态,P1运行。因为P3没有运行完毕,所以被抢占时需要保存其上下文环境,P1是从挂起直接被激活而进入就绪状态的,所以采用调度策略B。P3 runs until it activates P1. Because the priority of P1 is higher than that of P3, P3 is preempted, the second scheduling occurs at time t2, P3 enters the intermediate state of the ready state, and P1 runs. Because P3 has not finished running, it needs to save its context when it is preempted. P1 is activated directly from suspension and enters the ready state, so scheduling strategy B is adopted.

P1一直运行到结束,t3时刻发生第三次调度,当前就绪任务中只有P3,P3得到CPU并运行。因为P1是运行结束后进入挂起状态的,所以不需要保存其运行环境。而P3是从就绪状态的中间态开始运行的,所以需要恢复其运行环境,因此采用调度策略C。P1 has been running until the end, and the third scheduling occurs at time t3. Only P3 is currently in the ready task, and P3 gets the CPU and runs. Because P1 enters the suspended state after running, there is no need to save its running environment. However, P3 starts running from the intermediate state of the ready state, so it needs to restore its operating environment, so scheduling strategy C is adopted.

在CME555开发板上对比运行采用统一调度函数和采用本发明后的优化调度策略的操作系统,CPU为MPC555,频率40MHz。在逻辑分析仪上,采用100M的采样频率,测试得到各时刻的任务切换时间分别如下表1所示: 调度时刻   统一调度函数时的任务切换时间(us)   优化调度策略后 对比效果   任务切换时间(us)   调度策略   t1   7.5   1   A   TSA大幅度小于TS   t2   7.5   4.5   B   TSB明显小于TS   t3   7.5   4.5   C   TSC明显小于TS On the CME555 development board, the operating system using the unified scheduling function and the optimized scheduling strategy of the present invention is compared and run, and the CPU is MPC555 with a frequency of 40MHz. On the logic analyzer, using a sampling frequency of 100M, the task switching time at each moment is tested as shown in Table 1 below: Scheduling time Task switching time when unified scheduling function (us) After optimizing the scheduling strategy contrast effect Task switching time (us) Scheduling strategy t1 7.5 1 A T SA is significantly smaller than T S t2 7.5 4.5 B T SB is significantly smaller than T S t3 7.5 4.5 C T SC is significantly smaller than T S

                            表1 Table 1

实施例2:在实施例1的基础上,再来看实施例2。如图6所示。实施例2为ECC1状态下的操作系统,采用全抢占方式。共有三个基本任务,P4,P5,P6,优先级从高到低排列,即P4优先级最高,P5次之,P6优先级最低。为了说明的简单,实例2只突出“等待”状态的调度情况。Embodiment 2: On the basis of Embodiment 1, look at Embodiment 2 again. As shown in Figure 6. Embodiment 2 is an operating system in the ECC1 state, which adopts the full preemption mode. There are three basic tasks, P4, P5, and P6, and the priorities are arranged from high to low, that is, P4 has the highest priority, P5 is the second, and P6 has the lowest priority. For simplicity of illustration, Example 2 only highlights the scheduling situation of the "waiting" state.

t0时刻系统启动,此时任务P4挂起,P5、P6均就绪,P5优先级最高而先运行,此时P6处于就绪状态中的初始态。到t1时刻,P5运行结束,发生第一次调度,P6运行,和实例1的t1时刻类似,采用调度策略A。The system starts at time t0, task P4 is suspended at this time, P5 and P6 are both ready, P5 has the highest priority and runs first, and at this time P6 is in the initial state of the ready state. At time t1, the operation of P5 ends, the first scheduling occurs, and P6 runs, which is similar to the time t1 of instance 1, and the scheduling strategy A is adopted.

P6一直运行,直到其激活P4。因为P4优先级高于P6,则P6被抢占,t2时刻发生第二次调度,P6进入就绪状态的中间态,P4运行。和实例1的t2时刻类似,采用调度策略B。P6 runs until it activates P4. Because the priority of P4 is higher than that of P6, P6 is preempted, the second scheduling occurs at time t2, P6 enters the intermediate state of the ready state, and P4 runs. Similar to time t2 of Example 1, scheduling strategy B is adopted.

P4一直运行,直到其等待事件1。即t3时刻发生第二次调度,P4进入等待状态,P6运行。因为P4是进入等待状态而并没有运行完毕,所以需要保存其运行环境,同时P6是从就绪态的中间态进入运行,也需要恢复运行环境,所以采用调度策略D,这就是最复杂的调度情况。P4 runs until it waits for event 1. That is, the second scheduling occurs at time t3, P4 enters the waiting state, and P6 runs. Because P4 enters the waiting state but has not finished running, it needs to save its running environment. At the same time, P6 enters running from the intermediate state of the ready state, and also needs to restore the running environment, so the scheduling strategy D is adopted, which is the most complicated scheduling situation. .

P6一直运行,直到其设置了事件1。P4因为等待的事件1发生,则进入就绪态的中间态。因为P4优先级高,则t4时刻就发生第三次调度,P6被抢占进入就绪状态的中间态,P4运行。因为P6运行环境需要保存,P4是从等待状态进入就绪状态的中间态再进入运行的,需要恢复其运行环境,又也是最复杂的调度情况,采用调度策略D。P6 runs until it sets event 1. P4 enters the intermediate state of the ready state because the waiting event 1 occurs. Because P4 has a high priority, the third scheduling occurs at time t4, P6 is preempted and enters the intermediate state of the ready state, and P4 runs. Because the P6 operating environment needs to be saved, and P4 enters the running state from the waiting state to the ready state, and its operating environment needs to be restored, which is also the most complicated scheduling situation. Scheduling strategy D is adopted.

同样在CME555开发板上对比运行采用统一调度函数和采用本发明的优化调度策略的操作系统。Also on the CME555 development board, compare and run the operating system using the unified scheduling function and the optimized scheduling strategy of the present invention.

测试得到各时刻的任务切换时间分别如下表2所示: 调度时刻   统一调度函数时的任务切换时间(us)   优化调度策略后 对比效果   任务切换时间(us)   调度策略   t1   7.5   1   A   TSA大幅度小于TS   t2   7.5   4.5   B   TSB明显小于TS   t3   7.5   7.8   D   TSD和TS基本持平   t4   7.5   7.8   D   TSD和TS基本持平 The task switching time at each moment obtained from the test is shown in Table 2 below: Scheduling time Task switching time when unified scheduling function (us) After optimizing the scheduling strategy contrast effect Task switching time (us) Scheduling strategy t1 7.5 1 A T SA is significantly smaller than T S t2 7.5 4.5 B T SB is significantly smaller than T S t3 7.5 7.8 D. T SD and T S are basically the same t4 7.5 7.8 D. T SD and T S are basically the same

表2Table 2

Claims (4)

1, a kind of task scheduling optimization method of supporting the embedded OS of OSEK standard, it is characterized in that: performing step is as follows:
1), analyze all kinds of scheduling switch instances according to task status:
1.1), in the OSEK standard according to the difference of task status classification, system is divided into two kinds of situations of BCC1 (basic task), ECC1 (expansion task); Wherein the task status among the BCC1 comprises three kinds of situations: operation, ready, hang up, the task status among the ECC1 comprises four kinds of situations: operation, ready, wait for, hang up; The ready state of task is subdivided into intermediate state and initial state, promptly to be task run enter ready state to intermediate state after half incident of being seized or waiting for takes place, the ready state that initial state is task task directly enters when hang-up is activated into ready state or system start-up;
1.2), the scheduling situation under BCC1 is divided into following three kinds:
Scheduling situation 1: the current task end of run enters suspended state, and the high-priority task that is about to operation is an initial state; Need not preserve current task running environment, directly carry out operation such as pointer assignment after, can move back one high-priority task;
Scheduling situation 2: the current task end of run enters suspended state, and the high-priority task that is about to operation is an intermediate state; Need not preserve current task running environment, carry out operation such as pointer assignment after, recover the running environment of back one high-priority task, rerun;
Scheduling situation 3: current task is seized enters ready state, and the high priority that is about to operation is an initial state; Preserve current task running environment, carry out to move high-priority task after the operation such as pointer assignment.
1.3), the scheduling situation under ECC1, except that above-mentioned 1.2), add following three kinds again:
Scheduling situation 4: current task enters waiting status, and the high-priority task that is about to operation is an intermediate state; Preserve current task running environment, carry out operation such as pointer assignment after, recover the running environment of back one high-priority task, rerun;
Scheduling situation 5: current task enters waiting status, and the high-priority task that is about to operation is an initial state; Preserve current task running environment, carry out to move high-priority task after the operation such as pointer assignment;
Scheduling situation 6: current task is seized enters ready state, the high-priority task that is about to operation is an intermediate state, and this task is to have entered intermediate state because the incident of its wait has taken place, preserve current task running environment, after carrying out operation such as pointer assignment, recover the running environment of high-priority task, rerun;
2), can be divided into following four steps to scheduling process:
2.1), in ready task, find the task of limit priority;
2.2), preserve the running environment of current operation task;
2.3), carry out CPU and take pointer assignment, promptly exchange the CPU right of possession corporeal right;
2.4), recover the running environment of limit priority task;
3), according to the coverage condition of four steps of scheduling process, the Optimization Dispatching strategy is divided into following four classes:
3.1), scheduling strategy A: simple scenario, only do the scheduling process step 2.1), 2.3);
3.2), scheduling strategy B: generalized case, only do the scheduling process step 2.1), 2.2), 2.3);
3.3), scheduling strategy C: generalized case, only do the scheduling process step 2.1), 2.3), 2.4);
3.4), scheduling strategy D: complex situations, do whole scheduling process steps 2.1), 2.2), 2.3), 2.4);
4), the difference of actual schedule situation during according to task run, select different scheduling strategies for use: the dispatching office consumed time T of every kind of situation is different different according to selected strategy, the T of D correspondence SDAt most, the T of A correspondence SAMinimum, the T of B and C correspondence SB, T SCBe intermediate value.
2, the task scheduling optimization method of the embedded OS of support according to claim 1 OSEK standard is characterized in that: the state of task be divided into operation, ready, hang up, four kinds of waits.The task of running status is meant the task of the current CPU of taking, the task of ready state be carried out operation prepare, only etc. CPU time task or move half back by other task preemption, again in the task of waiting for CPU time, the task of suspended state be voluntarily end of run or just produced and etc. task to be activated; The task of waiting status is the task of waiting for that a certain incident takes place.Ready state is subdivided into intermediate state and initial state again.The task of attitude and initial state is different to the environment requirement of resuming operation because mediate, and these two kinds of different states were optimized when scheduling strategy switched at task.For the task of initial state, directly remove the step of the environment that resumes operation, thereby reduce the time of scheduling, improve performance.
3, the task scheduling optimization method of the embedded OS of support OSEK standard according to claim 1, it is characterized in that: operating system adopts the mode of seizing entirely, so the task switching point does not occur over just after the task run end, when also occurring in the task preemption low priority task of high priority.These two kinds of scheduling situations also are different to the requirement that whether needs to preserve current operation task running environment.When task run finishes to dispatch, because finished all operations, so do not need to preserve its running environment.And being seized of task is not also finished all operations, needs to continue in due course operation, so system need preserve running environment for it.
4, the task scheduling optimization method of the embedded OS of support OSEK standard according to claim 1 is characterized in that: OSEK standard code, the task status under the ECC1 operating system have a kind of waiting status that is.Task enters waiting status because waiting for the generation of some incidents, initiatively abandons CPU, and follow-up reforwarding row takes place waiting event.Wait for the scheduling that takes place because of task, the task of entering waiting status is not finished all operations yet, need continue operation after the incident of waiting for takes place, so system also will preserve running environment for it.
CNB2005100607354A 2005-09-12 2005-09-12 Task scheduling method for embedded real-time operation system supporting OSEK standard Expired - Fee Related CN100351793C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005100607354A CN100351793C (en) 2005-09-12 2005-09-12 Task scheduling method for embedded real-time operation system supporting OSEK standard

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005100607354A CN100351793C (en) 2005-09-12 2005-09-12 Task scheduling method for embedded real-time operation system supporting OSEK standard

Publications (2)

Publication Number Publication Date
CN1737764A true CN1737764A (en) 2006-02-22
CN100351793C CN100351793C (en) 2007-11-28

Family

ID=36080567

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005100607354A Expired - Fee Related CN100351793C (en) 2005-09-12 2005-09-12 Task scheduling method for embedded real-time operation system supporting OSEK standard

Country Status (1)

Country Link
CN (1) CN100351793C (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100416463C (en) * 2006-10-12 2008-09-03 浙江大学 Scheduling method for low-power real-time task parameter model for embedded systems
CN100465857C (en) * 2006-10-12 2009-03-04 浙江大学 A Simplified Method for Low-power Real-time Task Scheduling in Embedded Systems
CN101290588B (en) * 2008-03-07 2010-06-16 重庆邮电大学 A micro-embedded real-time task scheduler and scheduling method
CN102013191A (en) * 2010-09-02 2011-04-13 东北师范大学 Intelligent teaching aid used for operation system experiment teaching
CN102043668A (en) * 2010-12-10 2011-05-04 成电汽车电子产业园(昆山)有限公司 Method for activating task in embedded real-time operating system for multiple times
CN102801551A (en) * 2012-03-14 2012-11-28 中国汽车技术研究中心 Open systems and the corresponding interfaces for automotive electronics (OSEK) network management-based controller area network (CAN) management method
CN101547149B (en) * 2009-04-20 2013-06-19 浙江大学 Dynamic scheduling method for OSEK COM messages based on CAN network
CN117806807A (en) * 2024-02-29 2024-04-02 双一力(宁波)电池有限公司 Task scheduling method, device, electronic equipment and computer-readable storage medium
CN120448072A (en) * 2025-06-06 2025-08-08 禾洛半导体(徐州)有限公司 ARM-based RTOS multi-task priority scheduling and real-time control method

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010034751A1 (en) * 2000-04-21 2001-10-25 Shinichiro Eto Real-time OS simulator
CN1238787C (en) * 2003-10-17 2006-01-25 清华大学 Binary chop type task dispatching method for embedding real-time operating system

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100465857C (en) * 2006-10-12 2009-03-04 浙江大学 A Simplified Method for Low-power Real-time Task Scheduling in Embedded Systems
CN100416463C (en) * 2006-10-12 2008-09-03 浙江大学 Scheduling method for low-power real-time task parameter model for embedded systems
CN101290588B (en) * 2008-03-07 2010-06-16 重庆邮电大学 A micro-embedded real-time task scheduler and scheduling method
CN101547149B (en) * 2009-04-20 2013-06-19 浙江大学 Dynamic scheduling method for OSEK COM messages based on CAN network
CN102013191A (en) * 2010-09-02 2011-04-13 东北师范大学 Intelligent teaching aid used for operation system experiment teaching
CN102013191B (en) * 2010-09-02 2012-10-03 东北师范大学 Intelligent teaching aid used for operation system experiment teaching
CN102043668A (en) * 2010-12-10 2011-05-04 成电汽车电子产业园(昆山)有限公司 Method for activating task in embedded real-time operating system for multiple times
CN102043668B (en) * 2010-12-10 2013-05-22 成电汽车电子产业园(昆山)有限公司 Method for activating task in embedded real-time operating system for multiple times
CN102801551A (en) * 2012-03-14 2012-11-28 中国汽车技术研究中心 Open systems and the corresponding interfaces for automotive electronics (OSEK) network management-based controller area network (CAN) management method
CN102801551B (en) * 2012-03-14 2014-09-24 中国汽车技术研究中心 CAN Network Management Method Based on OSEK Network Management
CN117806807A (en) * 2024-02-29 2024-04-02 双一力(宁波)电池有限公司 Task scheduling method, device, electronic equipment and computer-readable storage medium
CN117806807B (en) * 2024-02-29 2024-05-17 双一力(宁波)电池有限公司 Task scheduling method, device, electronic equipment and computer readable storage medium
CN120448072A (en) * 2025-06-06 2025-08-08 禾洛半导体(徐州)有限公司 ARM-based RTOS multi-task priority scheduling and real-time control method

Also Published As

Publication number Publication date
CN100351793C (en) 2007-11-28

Similar Documents

Publication Publication Date Title
CN1270239C (en) Processing system or tast control method on computer system and and computer program
US9858115B2 (en) Task scheduling method for dispatching tasks based on computing power of different processor cores in heterogeneous multi-core processor system and related non-transitory computer readable medium
CN1601476A (en) Systems and methods for CPI scheduling on SMT processors
CN102473118A (en) Information processing system
CN100342342C (en) Java virtual machine implementation method supporting multi-process
CN106897136A (en) A kind of method for scheduling task and device
CN100351793C (en) Task scheduling method for embedded real-time operation system supporting OSEK standard
US20090292846A1 (en) Method of interrupt scheduling
CN114579285B (en) Task running system and method and computing device
CN1912923A (en) Systems and methods for managing data processing stages of a logical graphics pipeline
CN1315045C (en) A method for implementing centralized concurrent management to cluster
CN1637712A (en) Apparatus and method for interrupt control
CN1101573C (en) Computer system
CN1828541A (en) Realization Method of Timed Task in Java Operating System
CN100347676C (en) PowerPC processor based vehicular operating system interrupt management method
CN103309734A (en) Embedded task scheduling method based on priority grouping
CN1825286A (en) Embedded SRAM Operating System Thread Realization and Thread State Conversion Method
CN101030152A (en) Operation controller and controlling method based on pseudo-clock mode
CN103677959B (en) A kind of virtual machine cluster migration method and system based on multicast
CN1851693A (en) Method for realizing system resources management
CN1855068A (en) Method for testing multi-thread software concurrent conflict
CN1882914A (en) Task management system
CN1889045A (en) Cocurrent event processing device and method in multi-task software system
CN108874517B (en) An Energy Consumption Optimization Method for Utilization Division of Fixed Priority Standby Standby System
CN1384431A (en) Context saving

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

Granted publication date: 20071128

Termination date: 20170912