Real-time operating system with a CPU cycle time base
View Patent ↗An improved real-time operating system (RTOS) design that uses cycle-based scheduling rather than tick-based scheduling is described herein. Using cycle-based scheduling, versus the traditional tick-based scheduling, provides technical benefits to embedded systems. For example, the cycle-based scheduling can change the basic unit of time of the embedded system by increasing the resolution of scheduling. Instead of relying on the system tick used in typical RTOS implementations (e.g., a tick that occurs every 1 millisecond), the improved RTOS design described herein uses CPU cycles internally for some or all operations. Operations such as task delays, timeouts, and/or software timers, which were specified in units of system ticks in typical RTOS implementations, can now be specified in CPU cycles.
1 . A computing device comprising:
a memory device configured to store an operating system; and
a hardware processor in communication with the memory device, wherein the hardware processor is configured with computer-executable instructions that, when executed by the hardware processor, cause the hardware processor to execute the operating system and to:
cause a first hardware timer of the computing device to increment a cycle count value each cycle of the hardware processor, wherein the first hardware timer is used for long-term time measurement;
determine that a task running on the hardware processor has called an application programming interface (API) function, wherein the API function specifies a timeframe within which the task is to be awakened;
in response to the API function being called, set a second hardware timer of the computing device programmed by the operating system to decrement a count value each cycle of the hardware processor, wherein the second hardware timer is a one-shot timer;
determine that the second hardware timer has expired;
cause the second hardware timer to generate an interrupt;
determine that the timeframe specified by the API function has passed using a current version of the cycle count value; and
awaken the task.
2 . The computing device of claim 1 , wherein the computer-executable instructions, when executed, further cause the hardware processor to determine that the count value has reached one of zero or a value corresponding to the timeframe.
3 . The computing device of claim 1 , wherein the timeframe comprises one of a number of cycles of the hardware processor, a unit of time, or a unit of system tick.
4 . The computing device of claim 1 , wherein the operating system comprises a real-time operating system.
5 . The computing device of claim 1 , wherein the computing device comprises an embedded system.
6 . The computing device of claim 1 , wherein the operating system is compatible with an extended API, wherein the extended API comprises at least one of a first function, a second function, or a third function, wherein the first function, when called, passes a first parameter to the operating system in which a unit of ticks is specified and that directs the operating system to schedule the interrupt to trigger after a first number of cycles of the hardware processor corresponding to the first parameter has passed, wherein the second function, when called, passes a second parameter to the operating system in which a second number of cycles of the hardware processor is specified and that directs the operating system to schedule the interrupt to trigger after the second number of cycles of the hardware processor has passed, and wherein the third function, when called, passes a third parameter to the operating system in which a unit of time is specified and that directs the operating system to schedule the interrupt to trigger after a third number of cycles of the hardware processor corresponding to the third parameter has passed.
7 . The computing device of claim 6 , wherein the unit of time comprises one of milliseconds, microseconds, or nanoseconds.
8 . A computer-implemented method comprising:
causing a first hardware timer of a computing device that comprises a hardware processor that executes an operating system to increment a cycle count value each cycle of the hardware processor, wherein the first hardware timer is used for long-term time measurement;
determining that a task running on the hardware processor has called an application programming interface (API) function, wherein the API function specifies a timeframe within which the task is to be awakened;
in response to the API function being called, setting a second hardware timer of the computing device programmed by the operating system to decrement a count value each cycle of the hardware processor, wherein the second hardware timer is a one-shot timer;
determining that the second hardware timer has expired;
causing the second hardware timer to generate an interrupt;
determining that the timeframe specified by the API function has passed using a current version of the cycle count value; and
awakening the task,
wherein the computer-implemented method is performed by the operating system executed by the hardware processor.
9 . The computer-implemented method of claim 8 , wherein determining that the second hardware timer has expired further comprises determining that the count value has reached one of zero or a value corresponding to the timeframe.
10 . The computer-implemented method of claim 8 , wherein the timeframe comprises one of a number of cycles of the hardware processor, a unit of time, or a unit of system tick.
11 . The computer-implemented method of claim 8 , wherein the operating system comprises a real-time operating system.
12 . The computer-implemented method of claim 8 , wherein an embedded system comprises the hardware processor.
13 . The computer-implemented method of claim 8 , wherein the operating system is compatible with an extended API, wherein the extended API comprises at least one of a first function, a second function, or a third function, wherein the first function, when called, passes a first parameter to the operating system in which a unit of ticks is specified and that directs the operating system to schedule the interrupt to trigger after a first number of cycles of the hardware processor corresponding to the first parameter has passed, wherein the second function, when called, passes a second parameter to the operating system in which a second number of cycles of the hardware processor is specified and that directs the operating system to schedule the interrupt to trigger after the second number of cycles of the hardware processor has passed, and wherein the third function, when called, passes a third parameter to the operating system in which a unit of time is specified and that directs the operating system to schedule the interrupt to trigger after a third number of cycles of the hardware processor corresponding to the third parameter has passed.
14 . The computer-implemented method of claim 13 , wherein the unit of time comprises one of milliseconds, microseconds, or nanoseconds.
15 . A computing device comprising:
a memory device configured to store an operating system; and
a hardware processor in communication with the memory device, wherein the hardware processor is configured with computer-executable instructions that, when executed by the hardware processor, cause the hardware processor to:
cause a first hardware timer to increment a cycle count value each cycle of the hardware processor;
determine that a task running on the hardware processor has called an application programming interface (API) function that specifies a timeframe;
in response to the API function being called, set a second hardware timer to change a count value each cycle of the hardware processor;
determine that the second hardware timer has expired;
cause the second hardware timer to generate an interrupt, wherein the operating system is compatible with an extended API, wherein the extended API comprises a first function, wherein the first function, when called, passes a first parameter to the operating system in which a unit of ticks is specified and that directs the operating system to schedule the interrupt to trigger after a first number of cycles of the hardware processor corresponding to the first parameter has passed;
determine that the timeframe specified by the API function has passed using a current version of the cycle count value; and
awaken the task.
16 . The computing device of claim 15 , wherein the computer-executable instructions, when executed, further cause the hardware processor to determine that the count value has reached one of zero or a value corresponding to the timeframe.
17 . The computing device of claim 15 , wherein the timeframe comprises one of a number of cycles of the hardware processor, a unit of time, or a unit of system tick.
18 . The computing device of claim 15 , wherein the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to increment the count value each cycle of the hardware processor.
19 . The computing device of claim 15 , wherein the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to decrement the count value each cycle of the hardware processor.
20 . The computing device of claim 15 , wherein the operating system comprises a real-time operating system.
21 . The computing device of claim 15 , wherein the first hardware timer is used for long-term time measurement, and wherein the second hardware timer is a one-shot timer.