Title of Invention

METHOD AND APPARATUS FOR MEASURING THE EXECUTION TIME FOR A TASK IN A REAL-TIME SYSTEM

Abstract A method for measuring the execution times of tasks in a real-time system, comprising a number of tasks, using at least one chronometer, at least some of the tasks being associated with different priority levels, and the chronometer being started at the beginning of a first task which is to be measured and being stopped when the task to, be measured has ended, characterized in that the state of the chronometer is stored if the first task is interrupted by a second task having a higher priority level and the chronometer is started again from the stored state when the first task continues, the chronometer measuring the execution time of the second task during the interruption to the first task. FIGURE 2.
Full Text

ROBERT BOSCH GMBH, 70442 Stuttgart
Method and apparatus for measuring the execution time for a task in a real-time system
Prior art
The present invention relates to a method and an apparatus for measuring the execution time for a task in a real-time system, particularly in a real-time operating system. Typical real-time operating systems which may be mentioned by way of example are RCOS or ERCOS,
A task is understood to be an executable program section within a real-time system. The sum of all the tasks produces the overall real-time system. This is also referred to as a multitasking system. A real-time system is a computer program whose timing is subject to stringent requirements. It is thus necessary to ensure that the program reacts to particular events within a prescribed interval of time. Real-time systems and, in particular, real-time operating systems are used predominantly for safety-critical systems.
To be certain that the overall system has the desired timing, it is necessary to ensure that every task adheres to particular time stipulations. In this regard, the tasks in a real-time system have different time requirements, "deadlines". These are represented as different priorities. It is assumed that tasks having a relatively high priority can interrupt those having a lower priority. This means that, as soon as a

superior task is executed, it interrupts execution of an inferior task.
To determine and, if appropriate, to modify the timing in the overall system, it is necessary to measure the execution time for each individual task in the course of the program development, in the test phase and also during operation of the overall system, particularly in the event of subsequent program changes.
It is known practice to ascertain the execution time for a task manually. This is done using a CPU emulator, for example. The problem which arises in this context is that measuring the execution time for a task involves said task being interrupted by a task with higher priority (preemptive multitasking). The measured time is distorted, since it is no longer just the execution time for one particular task which is being measured. In addition, manual measurement is very time consuming. This increases the cost and time for developing the program.
Another known method for measuring the execution time for a task provides for a timer to be left running concurrently in every task. The timer used can be, by way of example, a high-resolution hardware timer. Alternatively, a pure software solution is conceivable. In this context, the step size in the timer must be much shorter than the usual task execution times. Although this ensures that time measurement is always started at the start of a task, this method allows only the gross execution time for the task, that is to say the actual execution time or net execution time for the task plus the interruptions by superior tasks, to be measured. Although this method requires less work than the manual method described previously, the results ascertained are not much more exact. There is therefore also no decisive advantage over the manual method.

EP 0 534 8 84 Al discloses a method for checking the timing in a multitasking system. The method provides for the execution time for individual tasks to be measured and, if appropriate, for an alarm to be triggered when a prescribable period of time is exceeded. The period of time is determined using a timer or a counter. In this case, the period of time is determined as a multiple of the processor's cycle, The multitasking system has a number of tasks which all have a particular associated priority. It is thus possible for an inferior task to be interrupted by a superior task. To ensure that the whole program adheres to the necessary time requirements, it must be possible to determine the execution time for each individual task.
At the start of execution of a task whose execution time in processor cycles needs to be determined, the counter is started. The counter starts at a prescribed value and decreases its state after every cycle. If a particular lower limit is reached, an alarm signal is emitted. If the task is interrupted by a task with higher priority, the counter is stopped and the current state is stored. When the interruption has ended, the counter is restarted beginning at the stored state.
A drawback of the method described in EP 0 534 884 Al is that it is only ever possible to measure the execution time for one task during a measurement pass. Only when the execution time for the task has been determined, i.e. the task has ended, can the counter be used to determine the execution time for another task. A measurement pass starts when the execution of a task starts and ends.
It is therefore an object of the present invention to propose a method and an apparatus which allow exact

measurement of the execution time for a task and which can also be used to determine the execution times for a plurality of tasks in one measurement pass.
The object for the method is achieved by a method having the features of Claim 1.
The object for the apparatus is achieved by an apparatus having the features of Claim 6 [sic].
Advantageous refinements of the invention can be found in the subclaims.
Advantages of the invention
The inventive method is used for measuring the execution time for a task in a real-time system having a number of tasks, at least some of which have different priority levels associated with them. In this case, the individual tasks can all be executed at different priority levels. Alternatively, it is possible for some or else all of the tasks to be executed at the same priority level or at the same priority levels. To measure the execution time, a timer is provided whose state portrays the execution time. At the start of a task whose execution time needs to be determined, the timer is started. If the task is interrupted by a task having a higher priority, i.e. if there is a change of priority level, the timer is stopped and the current state is stored. When the interruption has ended, that is to say as soon as the task whose execution time needs to be determined is executed again, the stored state of the timer is restored and the timer is restarted beginning at the stored state.
Expediently, the state of the timer is stored as early as possible when a first task is interrupted and, when

the interruption has ended, is restored as late as possible, i.e. as directly as possible before the task is restarted. With this proviso, the net execution times for a task can be measured with particular accuracy. This is found to be advantageous because a systematic measurement error cannot be prevented from arising, since part of the priority switch is also measured before the state of the timer has been saved. The same applies to restoration of a stored state of the timer. By virtue of the state of the timer being stored as quickly as possible in the event of an interruption and being restored as late as possible when the interruption has ended, this error can be minimized. This measurement error is in any case much smaller than the measurement error when the gross execution time is measured.
In line with one preferred embodiment of the inventive method, if the first task is interrupted on account of a second task which has higher priority, the execution time for the second task is measured during the interruption in the execution time for the first task. In this case, it is naturally possible, during corresponding interruptions in the second task, to measure the execution time for a third task etc. The invention thus allows the tasks arising essentially during one pass in a real-time system to be measured essentially simultaneously.
As a result, the net execution time for the task or tasks is determined, as already mentioned, since time measurement is always started at the start of a task and is stopped during an interruption.
Expediently, only one timer is provided for all the priority levels. Within a priority level, all the tasks run cooperatively, that is to say that they do not interrupt one another. In the event of a change of

priority level, namely at the start of a superior task, the state of the CPU used is saved so that the CPU is in the same state after the end of the interruption as before the interruption. In addition, every change of priority involves the state of the timer being saved. Thus, one timer can be used to determine the execution times for a plurality of tasks running at different priority levels in one measurement pass.
The inventive method can be used to measure the net execution times for all the tasks in the system more easily than before. The additional complexity is in the starting of measurement at the start of every task and in the saving and restoration of the timer with each change of priority. All interruptions by other tasks are automatically excluded in this case. Improved and simpler monitoring of the system resource 'execution time' is thus possible. The method is independent of the operating system used and of the underlying hardware. The resource requirement in terms of timers for measurement does not depend on the number of priority levels, since just one timer is needed. Each priority level needs to be provided only with the space for saving the state of the measurement. This is fundamental to the implementation, since the number of timers available is usually restricted to a higher degree than the storage space available.
The inventive apparatus for measuring the execution time for a task in a real-time system having a number of tasks, each of which is executed at a particular priority level, has a timer. In addition, means are provided which allow the timer to be started and stopped. The timer has a memory available whose capacity is matched to the number of priority levels.

The apparatus for measuring the execution time is preferably a hardware timer. This can already be implemented in the CPU.
Advantageously, the step size for the timer is much
shorter than the usual execution time for the tasks.
The smaller the step size, the more exact are the
results of the measurements,
The invention is explained in more detail with reference to the appended drawing, in which:
Figure 1 shows the time curve for the state of a timer
in the case of a conventional method;
Figure 2 shows the time curve for the state of a timer
in the case of the inventive method;
Figure 3 shows a schematic illustration of an
apparatus in accordance with the invention.
Figure 1 shows the time curve for the state of a timer in the case of a conventional method. It shows a graph 1 having two abscissae 2 and a first ordinate 3 and a second ordinate 4. The two abscissae 2 plot the time. The first ordinate 3 can be used to determine the state of the timer. The second ordinate 4 portrays the priority level at which the tasks run. A first straight line 5 and a second straight line 6 portray the time curve for the state of the timer.
At time ti, a task A starts. The priority level for this task can be read from the second ordinate 4. Also at time ti, the timer is started. The first straight line 5 illustrates the change in the state of the timer over time. At time 8, the task A is interrupted by the superior task B. This task B runs at a higher priority level. The change in the state of the timer over time

remains unaffected thereby, as illustrated by the first straight line 5. At time t3, the task B ends. When the interruption has ended, the task A continues. At time t4, the task A ends. The timer is stopped. The state of the timer can be read from the first ordinate 3. However, the value ascertained does not portray the net execution time but rather the gross execution time for the task A. When the task A has ended, the state of the timer is reset. A task C running at the same priority level as the task A starts. The timer is restarted. In this context, the second straight line 6 portrays the state of the timer.
Figure 2 shows the graph 1 from Figure 1, which shows the time curve for the state of a timer in the case of the inventive method. The time sequence for the tasks A, B and C corresponds to the sequence in Figure 1. A third straight line 11, a fourth straight line 12, a fifth straight line 13 and a sixth straight line 14 portray the curve for the state of the timer.
Again at time t1, the task A starts. The timer is started. The state changes over time in accordance with the third straight line 11. At time t2, the task B starts. The task A is interrupted. The state of the timer is stored and is then reset. During the execution time for the task B, the fourth straight line 12 portrays the state of the timer. When the task B has ended at time t3, the first ordinate 3 can be used to determine the state of the timer and hence the execution time for the task B. When the task B has ended at time t3, the task A continues, as shown by means of the fifth straight line 13. The state stored at time t2 is restored, so that the timer continues beginning at the stored state. When the task A has ended at time t4, the state of the timer can be read from the first ordinate 3. This state is a measure of the net execution time of the task A. When the task A

has ended, the task C starts. This task C runs at the same priority level as the task A and was or is thus not able to interrupt execution thereof. The sixth straight line 14 portrays the curve for the state of the timer.
Figure 3 shows a schematic illustration of an apparatus in accordance with the invention for measuring the execution time for a task. The apparatus has a timer 15 and a memory 16 which are connected to one another by means of a data line 17. The timer 15 can use the data line 17 to store its state in the memory 16. The timer 15 contains means 18 which allow the timer 15 to be started and stopped.




ROBERT BOSCH GMBH, 70442 Stuttgart
Claims
1. Method for measuring the execution time for at least one task in a real-time system comprising a number of tasks using at least one timer (15) , where the timer (15) is started at the start of a first task to be measured and the state of the timer (15) is stored if the first task is interrupted, and, when the first task continues, the stored state of the timer (15) is restored and the timer (15) is started again from this stored state.
2. Method according to Claim 1, characterized in that the state of the at least one timer (15) is stored as early as possible when the first task is interrupted and is restored as late as possible when the interruption has ended.
3. Method according to one of Claims 1 or 2, characterized in that, if the first task is interrupted on account of a second task which has higher priority, the execution time for the second task is measured during the interruption in the execution time for the first task.
4. Method according to one of the preceding claims, characterized in that all the execution-time measurements for all the tasks are performed using precisely one timer whose storage capacity is matched to the number of different priority levels for the tasks.

5. Apparatus for measuring the execution time for at least one task in a real-time system comprising a number of tasks, having at least one timer (15) and means (18) for starting and stopping the timer (15) , characterized in that the timer (15) has an associated memory (16) having a storage capacity which is matched to the number of priority levels for the tasks.
6. Apparatus according to Claim 5, characterized in that the timer is a hardware timer.
7. Apparatus according to one of Claims 5 or 6, characterized in that the step size for the timer (15) is much shorter than the usual execution time
for the tasks.

8, A method for measuring the execution time substantially as herein described with reference to the accompanying drawings.


Documents:

082-chenp-2003-abstract.pdf

082-chenp-2003-claims filed.pdf

082-chenp-2003-claims granted.pdf

082-chenp-2003-correspondnece-others.pdf

082-chenp-2003-correspondnece-po.pdf

082-chenp-2003-description(complete) filed.pdf

082-chenp-2003-description(complete) granted.pdf

082-chenp-2003-drawings.pdf

082-chenp-2003-form 1.pdf

082-chenp-2003-form 26.pdf

082-chenp-2003-form 3.pdf

082-chenp-2003-form 5.pdf

082-chenp-2003-other documents.pdf

082-chenp-2003-pct.pdf

abs-82-chenp-2003.jpg


Patent Number 209630
Indian Patent Application Number 82/CHENP/2003
PG Journal Number 50/2007
Publication Date 14-Dec-2007
Grant Date 05-Sep-2007
Date of Filing 14-Jan-2003
Name of Patentee M/S. ROBERT BOSCH GMBH
Applicant Address Postfach 30 02 20 70442 Stuttgart
Inventors:
# Inventor's Name Inventor's Address
1 PISECKY, Manfred Arnikaweg 107/17 A-1220 Wien
PCT International Classification Number G06F 9/48
PCT International Application Number PCT/DE2001/002516
PCT International Filing date 2001-07-06
PCT Conventions:
# PCT Application Number Date of Convention Priority Country
1 100 34 459.3 2000-07-15 Germany