In real-time systems, “when” an instruction is executed is often just as important as “what” instruction is executed. For example, in a stimulus-response measurement system, a measurement device may need to wait a precise amount of time after applying a stimulus before measuring a response.
Unfortunately for real-time systems, the instruction sets of modern computer processors do not provide a way to define when an instruction should be executed. For example, the number of clock cycles that it takes to execute an instruction typically varies, depending on various factors including, for example, whether needed data resides in a cache, and the available bandwidth and latency for accessing main memory. In addition, different computer processors (or even the same computer processor) can operate at different clock speeds, thereby making the length of a clock cycle an “unknown” at the time a computer program is written.
Recently, an attempt was made to bring timing certainty back to embedded processors. See, Ip and Edwards, “A Processor Extension for Cycle-Accurate Real-Time Software”, Proceedings of the IFIP International Conference on Embedded and Ubiquitous Computing”, Seoul, Korea, Aug. 1-4, 2006. As disclosed by Ip and Edwards, a processor may be designed to respond to wait instructions which make the processor wait a particular number of clock cycles before executing a next instruction. However, a problem with wait instructions (also referred to as no-operation instructions, or “no-ops”) is their lack of portability for the purpose of real-time programming. That is, running a computer program on two processors using the same instruction set, but having different clock speeds, will result in a change in program behavior (or will require changes to the number of clock cycles referenced by each wait instruction).
Illustrative embodiments of the invention are illustrated in the drawings, in which:
In light of the needs of real-time systems, and other systems that would benefit from the availability of real-time instructions,
The computer processor 102 illustrated in
The at least one real-time instruction may take the form of a single or multiple real-time instructions. By way of example, and in some embodiments of the computer processor 102, the at least one real-time instruction may comprise an instruction that specifies an execution timing indicating when execution of the instruction is to be commenced in relation to the start of execution of a computer program. Such an instruction might take the form of “t1; instruction”, where “t1” is the desired time for commencing execution of “instruction”. Two of this type of instruction 200, 202 are illustrated in
Similarly to the instruction described in the preceding paragraph, the at least one real-time instruction could also (or alternately) comprise an instruction that specifies an execution timing indicating when execution of the instruction is to be completed in relation to a start of execution of a computer program. Such an instruction might take the form of “instruction @ t1”, where “t1” is the desired time for completing execution of “instruction”. An instruction 204 of this type may be referred to as a “deadline” instruction and is illustrated in
Real-time instructions of other types are also contemplated, such as real-time instructions that specify how long an instruction should take to execute (e.g., “load $R5 $R4=t2”, setting a time limit of t2 for the amount of time to load values $R5 and $R4).
By way of example, the computer program to which an instruction's execution timing is tied may be the same computer program that contains the real-time instruction that is associated with the execution timing. Alternately, the computer program may be a computer program other than the computer program containing the real-time instruction that is associated with the execution timing. The computer program may also take the form of a computer program thread (i.e., when a computer program is configured to be executed by one or more computer processors that execute a plurality of computer program threads in parallel).
In addition to (or instead of) the above instructions, the at least one real-time instruction executed by the computer processor 102 may comprise an instruction that specifies 1) an execution timing indicating when execution of the instruction is to be commenced in relation to an execution timing of another instruction, or 2) an execution timing indicating when execution of the instruction is to be completed in relation to an execution timing of another instruction. A real-time instruction that is to be commenced in relation to an execution timing of another instruction might take the form of “$T1+t1; instruction”, where “t1” indicates a time, after the time stored in register T1, at which the execution of “instruction” is to be commenced. Similarly, a real-time instruction that is to be completed in relation to an execution timing of another instruction might take the form of “instruction @ $T1+t1”, where “t1” is the time, after the time stored in register T1, by which execution of “instruction” is to be completed. Instructions of these types are respectively illustrated by the “store” instruction 302 shown in
In some embodiments, and in addition to one or more real-time instructions, the instruction set of the computer processor 102 may include at least one real-time capture instruction, wherein each of the at least one real-time capture instruction specifies an execution timing to be captured. By way of example, the at least one real-time capture instruction may comprise 1) an instruction that specifies capture of an execution timing indicating when the execution of the instruction is started, or 2) an instruction that specifies capture of an execution timing indicating when the execution of the instruction is completed. A real-time capture instruction designed to capture the execution start time for an instruction might take the form of “:T1; instruction”, indicating that the execution start time for “instruction” should be stored in register T1. See, instruction 300 (
The execution timing(s) specified by one or more real-time capture instructions may be stored by the computer processor 102 in a set of one or more registers 104 (
The set of one or more registers 104 are shown in
In one embodiment, the computer processor 102 may be configured to determine whether to execute a real-time instruction of a first particular type, in accord with an execution timing specified by the real-time instruction of the first particular type, by comparing i) the execution timing specified by the instruction to ii) one of the event times stored in one of the registers 104. If the execution timing specified by the first particular type of real-time instruction is a commencement-type execution timing, the computer processor 102 may delay execution of the instruction until the result of the comparison indicates an appropriate execution commencement. On the other hand, if the execution timing specified by the first particular type of real-time instruction is a deadline-type execution timing, the computer processor may attempt to execute the instruction prior to the execution deadline. The computer processor 102 may also hold off processing other instructions during the period shortly before the instruction is to be executed; and in a multi-core machine, one core may be reserved for this.
In the same or different embodiment described in the preceding paragraph, the computer processor 102 may be configured to determine whether to execute a real-time instruction of a second particular type, in accord with an execution timing specified by the real-time instruction of the second particular type, by comparing i) the execution timing specified by the instruction to ii) an elapsed time stored in one of the registers 104. If the execution timing specified by the particular type of real-time instruction is a commencement-type execution timing, the computer processor 102 may delay execution of the instruction until the result of the comparison indicates an appropriate execution commencement. On the other hand, if the execution timing specified by the particular type of real-time instruction is a deadline-type execution timing, the computer processor may attempt to execute the instruction prior to the execution deadline.
In addition to attempting to ensure compliance with the execution timings specified by real-time instructions, the computer processor 102 may be configured to take particular actions when the execution timing specified by a real-time instruction is missed (e.g., when an execution timing is not met—typically because execution of an instruction is commenced or completed late). In one embodiment, the computer processor 102 may be configured to halt execution of a computer program when an execution timing specified by a real-time instruction is missed. Alternately or additionally, the computer processor may be configured to generate an error indication when the execution timing is missed. In other embodiments, the computer processor 102 may be configured to execute a real-time instruction regardless of whether its execution timing is missed, but may also generate an error indication when the execution timing is missed.