Real-time operating system using CPU cycle time base
A cycle-based scheduling system using CPU cycles addresses the inefficiencies of traditional RTOS by enhancing scheduling resolution and reducing power consumption in embedded systems.
Patent Information
- Application Number
- JP2024522676
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2022-08-12
- Filing Date
- 2022-08-16
- Publication Date
- 2024-10-28
- Estimated Expiration
- 2042-08-16
AI Technical Summary
Traditional RTOS implementations rely on system ticks, which limit scheduling resolution and lead to inefficient resource usage and excessive power consumption due to unnecessary interrupts, and cannot accommodate tasks requiring shorter delays.
Implementing a cycle-based scheduling system that uses CPU cycles as the time base, allowing for finer granularity in task delays and interrupts, reducing unnecessary interrupts and improving resource utilization.
Enhances scheduling resolution, enabling precise task execution and reducing power consumption by eliminating unnecessary interrupts, thus improving the efficiency of embedded systems.
Smart Images

Figure 2024539043000001_ABST
Abstract
Description
[Technical field]
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS This application claims the benefit of U.S. Provisional Application No. 63 / 271,037, filed October 22, 2021, entitled “REAL-TIME OPERATING SYSTEM WITH A CPU CYCLE TIME BASE,” the disclosure of which is incorporated by reference in its entirety into this specification.
[0002] Copyright Notice A portion of the disclosure of this patent document contains material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction of this patent document or the patent disclosure, as appearing in the Patent and Trademark Office patent file or patent records, but otherwise reserves all copyright rights whatsoever. [Background technology]
[0003] An embedded computing system (or embedded system) may include electrical systems controlled by one or more processors or central processing units (CPUs), as well as memory and input / output (I / O) units. Examples of embedded systems may include household (white goods) appliances such as microwave ovens, dishwashers, ovens, and refrigerators, communication systems such as cordless phones, mobile phones, and telephone base stations, automotive systems such as anti-lock braking systems and engine control systems, entertainment systems such as portable audio players, movie players, and portable gaming devices, industrial systems including industrial controllers, measurement devices, medical devices, etc.
[0004] The software and firmware of these embedded devices can be very complex. For example, these embedded devices may run real-time operating systems (RTOS) that allow the execution of multiple tasks on a single central processing unit (CPU) core of a microcontroller. Summary of the Invention
[0005] An aspect of the present disclosure provides a computing device including a memory device configured to store an operating system, the computing device further including a hardware processor in communication with the memory device, the hardware processor 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 with each cycle of the hardware processor; determine that a task executing on the hardware processor has called an application programming interface (API) function that specifies a time period; set a second hardware timer to change a count value with each cycle of the hardware processor in response to the API function being called; determine that the second hardware timer has expired; cause the second hardware timer to generate an interrupt; determine that a time period specified by the API function has elapsed using a current version of the cycle count value; and launch the task.
[0006] The computing device of the previous paragraph may include any subcombination of the following features: the computer-executable instructions, when executed, further cause the hardware processor to determine that the count value has reached either zero or a value corresponding to the time period; the time period comprises one of a number of cycles of the hardware processor, a unit of time, or a unit system tick; the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to increment the count value every cycle of the hardware processor; the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to decrement the count value every cycle of the hardware processor; the operating system comprises a real-time operating system; the computing device comprises an embedded system; the operating system is compatible with an extended API, the extended API comprising a first function , a second function, or a third function, wherein the first function, when called, passes to the operating system a first parameter specifying a unit of ticks and instructing the operating system to schedule an interrupt after a first number of cycles of the hardware processor corresponding to the first parameter, the second function, when called, passes to the operating system a second parameter specifying a second number of cycles of the hardware processor and instructing the operating system to schedule an interrupt after the second number of cycles of the hardware processor, and the third function, when called, passes to the operating system a third parameter specifying a unit of time and instructing the operating system to schedule an interrupt after a third number of cycles of the hardware processor corresponding to a third parameter; the unit of time comprises one of milliseconds, microseconds, or nanoseconds;and the first hardware timer is used for long-term time measurement, and the second hardware timer is a one-shot timer;
[0007] Another aspect of the present disclosure provides a computer-implemented method executed by an operating system executed by the hardware processor, the computer-implemented method including: causing a first hardware timer to increment a cycle count value every cycle of a hardware processor; determining that a task running on the hardware processor has called an application programming interface (API) function that specifies a time period; setting a second hardware timer to change a count value every cycle of the hardware processor in response to the API function being called; determining that the second hardware timer has expired; causing the second hardware timer to generate an interrupt; determining that the time period specified by the API function has elapsed using a current version of the cycle count value; and initiating the task.
[0008] The computer-implemented method of the preceding paragraph may include any subcombination of the following features: determining that the second hardware timer has expired further includes determining that the count value has reached either zero or a value corresponding to the time frame; the time frame includes one of a number of cycles of the hardware processor, a unit of time, or a unit system tick; setting the second hardware timer further includes setting the second hardware timer to increment the count value every cycle of the hardware processor; setting the second hardware timer further includes setting the second hardware timer to decrement the count value every cycle of the hardware processor; the operating system includes a real-time operating system; the embedded system includes a hardware processor; the operating system is compatible with an extended API, the extended API being a first function, a second function, or a third function. the first function, when called, passes to the operating system a first parameter specifying a unit of ticks and instructing the operating system to schedule an interrupt after a first number of cycles of the hardware processor corresponding to the first parameter, the second function, when called, passes to the operating system a second parameter specifying a second number of cycles of the hardware processor and instructing the operating system to schedule an interrupt after the second number of cycles of the hardware processor, and the third function, when called, passes to the operating system a third parameter specifying a unit of time and instructing the operating system to schedule an interrupt after a third number of cycles of the hardware processor corresponding to a third parameter; the unit of time includes one of milliseconds, microseconds, or nanoseconds;and the first hardware timer is used for long-term time measurement, and the second hardware timer is a one-shot timer;
[0009] For the purpose of summarizing the present disclosure, certain aspects, advantages, and novel features of some embodiments are described herein. It should be understood that not all such advantages may necessarily be achieved according to any particular embodiment of the embodiments disclosed herein. Thus, the embodiments disclosed herein may be embodied or performed in a manner that achieves or optimizes one advantage or group of advantages as taught herein, without necessarily achieving other advantages as taught or suggested herein. [Brief description of the drawings]
[0010] Features disclosed herein will now be described with reference to the drawings, which are provided to illustrate embodiments of the invention described herein and are not intended to limit the scope thereof.
[0011] FIG. 1 shows an example of an operating environment that includes an embedded system running an RTOS implementation with cycle-based scheduling.
[0012] FIG. 2 illustrates example operations performed by components of the operating environment of FIG. 1 to initiate a task.
[0013] FIG. 3 illustrates an example of a cycle-based scheduling routine that may be implemented in the embedded system of FIG. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0014] As described above, an embedded device may run an RTOS that allows for the execution of multiple tasks on a single CPU core of a microcontroller. A typical RTOS implementation uses a system tick that is used as a time base (e.g., a basic unit of time). Generally, a typical RTOS implementation uses a hardware timer to generate periodic system tick interrupts, and all RTOS timeouts, task delays, and / or periods are specified in system ticks rather than times (e.g., milliseconds). In other words, timeouts, task delays, and / or periods in a typical RTOS implementation are aligned to the system tick such that the timeouts, task delays, and / or periods occur at integer multiples of the system tick. The system tick is user configurable, but is typically set to 1 millisecond in a typical RTOS implementation. Setting the system tick to 1 millisecond would cause the hardware timer to be programmed to generate 1000 system tick interrupts per second in a typical RTOS implementation.
[0015] However, a system tick interrupt occurring every 1 millisecond may be insufficient to perform operations that may be required in modern embedded systems. For example, because task delays and / or timeouts are aligned to the system tick, a task delay and / or timeout cannot expire within the time between two system tick interrupts. Thus, in a typical RTOS implementation, it may not be possible to configure a task delay that has a delay with a period shorter than the period between successive system tick interrupts.
[0016] Furthermore, system tick interrupts occurring every millisecond (or other period) can result in wasted computational resources and / or excessive power consumption. For example, if a CPU core is executing only one task for several consecutive system ticks, the scheduler is not running during this time, so no interrupt is needed to trigger the scheduler. However, typical RTOS implementations have no mechanism to track task execution and adjust system tick interrupts accordingly. Rather, the hardware timer continues to generate system tick interrupts and wake up the scheduler, regardless of the execution state of the task, thereby wasting computational resources and / or consuming excessive power.
[0017] Thus, an improved RTOS implementation is described herein that uses cycle-based scheduling rather than tick-based scheduling. The use of cycle-based scheduling over traditional tick-based scheduling provides technical advantages to embedded systems, as described in more detail below. Although the improved RTOS implementation described herein uses cycle-based scheduling instead of tick-based scheduling, the improved RTOS implementation described herein may still be compatible with application programming interface (API) functions present in traditional RTOS implementations (e.g., the improved RTOS described herein can read and execute API functions present in traditional RTOS implementations). By maintaining compatibility with traditional RTOS API functions, the improved RTOS implementation described herein allows existing code to maintain the same timing (e.g., integer multiples of system ticks, typically milliseconds), and thus existing code can be maintained unchanged. The improved RTOS implementation described herein may also implement additional API functions to support cycle-based scheduling, as described below.
[0018] For example, the cycle-based scheduling described herein can change the basic unit of time of an embedded system by improving the resolution of scheduling. Instead of relying on system ticks (e.g., ticks that occur every millisecond) used in typical RTOS implementations, the improved RTOS implementation described herein uses CPU cycles internally for some or all operations. Operations such as task delays, timeouts, and / or software timers that are specified in units (e.g., multiples) of ticks (e.g., milliseconds) in typical RTOS implementations can now be specified in CPU cycles (e.g., internal units of the embedded system). Operations may be specified in traditional ticks or milliseconds, as well as in system-independent high-resolution units such as microseconds, nanoseconds, etc. As used herein, a CPU cycle may be the time it takes a microcontroller to execute a processor operation and may be equal to the inverse of the clock rate of the embedded system.
[0019] The finer time granularity provided by the improved RTOS implementations described herein can mean that the timing needs of applications running on the embedded system can be met with better precision and accuracy as compared to a typical RTOS implementation. For example, the improvement over a typical RTOS implementation can be measured in orders of magnitude (e.g., three, four, five, etc.).
[0020] With this improvement, scheduling in the improved RTOS implementation described herein may become usable in many situations where scheduling was previously not possible with a typical RTOS implementation due to the coarse time resolution provided by the typical RTOS implementation. For example, there are many situations where a delay between 5 microseconds and 100 microseconds is required by a task or subroutine, but cannot be achieved with a typical RTOS implementation, which is a tick-based system. However, a delay of 5 microseconds to 100 microseconds may be achieved with the cycle-based scheduling described herein.
[0021] An RTOS implementation that implements cycle-based scheduling as described herein may provide several technical advantages. For example, any type of delay may be specified in smaller units, such as microseconds, CPU clock cycles, nanoseconds, and / or the like. Because these units may be passed as integers, a higher unit resolution may provide greater delay precision. As another example, the increased unit resolution may allow an improved RTOS implementation described herein to use timed delays where timed delays were not previously available. As another example, delays may be more precise. In a typical RTOS implementation, when the API function delay(10) is called, it may pause the operation of a thread for between 9 and 10 ms, depending on how far away the next system tick of the embedded system is. In an RTOS implementation that implements cycle-based scheduling, such as the implementation described herein, when the API function delay_ms(10) is called, it may pause the operation of a thread for exactly or nearly exactly (e.g., within 1%, 2%, 3%, etc.) 10 ms. As another example, cycle-based scheduling may not result in periodic interrupt generation that can waste computational resources and / or consume excessive power. Rather, an RTOS implementation that implements cycle-based scheduling, such as the implementation described herein, may cause a hardware timer to generate an interrupt in response to a particular API function being called (e.g., delay_ms(t)). In other words, an RTOS implementation that implements cycle-based scheduling as described herein may cause a hardware timer to generate an interrupt when a time-based action is required. In this manner, a CPU core of a microcontroller in an embedded system that implements an RTOS implementation using cycle-based scheduling as described herein may enter a hibernate mode to perform other tasks and / or conserve energy in situations where generation of an interrupt is not necessary or desired.
[0022] As used herein, the terms "real-time" and "near real-time," in addition to having their ordinary meanings, are often used herein to describe operations or actions that are performed fast enough so as to cause no perceptible delay in the operation of the embedded system, and may, but need not, mean "immediately" or "instantaneously." Further, in addition to having their ordinary meanings, the terms "software" and "firmware" may be used interchangeably herein. Furthermore, although some example functionality is described herein with respect to the C programming language, the features described herein are not so limited. Rather, any programming language may be used to implement the features described herein.
[0023] The foregoing aspects and many of the attendant advantages of the present disclosure will become more readily appreciated as the same become better understood by reference to the following detailed description, when considered in conjunction with the accompanying drawings.
[0024] Example of an embedded system using an RTOS that implements cycle-based scheduling Figure 1 illustrates an example operating environment 100 that includes an embedded system 120 that runs an RTOS implementation with cycle-based scheduling. As shown in Figure 1, embedded system 120 includes one or more hardware timers 121, optional counters 122, memory 123, one or more CPUs 125, and optionally input / output (I / O) ports, timers, data storage devices, sensors, and / or other such hardware 126.
[0025] An RTOS implementation that implements cycle-based scheduling may be loaded into memory 123 of embedded system 120 and executed by a single CPU 125 or multiple CPUs 125 (e.g., symmetric multi-processing) of embedded system 120. An RTOS implementation that implements cycle-based scheduling and executed by CPU 125 may be referred to herein as an "improved RTOS" or an "RTOS executed by CPU 125." CPU 125 may also be referred to herein as a processor, hardware processor, processing core, and / or the like. CPU 125 may be configured with computer-executable instructions that, when executed by CPU 125, cause CPU 125 to perform some or all of the operations described herein. The RTOS executed by CPU 125 may allow one or more threads to be executed simultaneously. A thread may be a "thread of execution" of a program. These threads may execute quasi-concurrently even if the embedded system 120 on which the threads execute has a single CPU 125. CPU 125 may execute threads simultaneously in one of at least two ways: time slicing or priority-controlled scheduling.
[0026] If CPU 125 implements time slicing (e.g., also known as "round robin" scheduling), CPU 125 executes some or all threads (that are not blocked for some reason but are ready to run) for a certain amount of time (e.g., a time slice). CPU 125 then executes the next thread for a certain amount of time (typically the same amount of time). In this way, some or all threads share CPU 125 equally. As an example, a time slice may be a millisecond or a multiple of a millisecond.
[0027] One issue with time slicing is that it may take many time slices (e.g., milliseconds, tens of milliseconds, etc.) for a particular task to be performed. This latency may not be important for tasks such as rendering and / or displaying a user interface (UI), where a user may not notice a 10 millisecond delay in response. On the other hand, low latency may be more important for tasks such as the network stack, which can operate on a separate thread. If the network stack cannot achieve low latency, the network stack may not be able to perform certain operations.
[0028] Priority control scheduling may overcome the technical deficiencies of time slicing by providing more time-critical tasks with a higher priority than less time-critical tasks. For example, the UI task may have a lower priority than the network stack task. The network stack task may wait for an event, such as an event triggered by an interrupt. The interrupt may be triggered by an interrupt service routine (ISR) when a packet is received by the embedded system 120. When the interrupt is triggered, the RTOS executed by the CPU 125 may immediately, or nearly immediately, launch the network stack task, which can then process and react to the received packet.
[0029] The RTOS executed by CPU 125 may implement time slicing scheduling, priority controlled scheduling, and / or a combination of time slicing and priority controlled scheduling. For example, the RTOS may use priority controlled scheduling for tasks that run at different priorities and time slicing scheduling for tasks that run at the same priority.
[0030] A typical RTOS implementation uses one hardware timer configured to generate a periodic interrupt, typically once every millisecond. In an embodiment, an RTOS implementing cycle-based scheduling and executed by the CPU 125 may operate using two or more hardware timers 121. For example, in an embodiment in which there are multiple hardware timers 121, a first hardware timer 121 may increment (or decrement) a cycle count value (e.g., CycleCnt) every cycle of the CPU 125 and may be used by the RTOS for long-term accuracy. The first hardware timer 121 may run in a continuous mode but may not generate an interrupt. Rather, the first hardware timer 121 may periodically increment (or decrement) a cycle count value, which may be used by the RTOS as a time base for calculating the current embedded system 120 time in cycles of the CPU 125.
[0031] The second hardware timer 121 can be programmed by the RTOS to generate an interrupt after a defined time. For example, the second hardware timer 121 can increment or decrement a count value at a specified frequency and can be operated in single shot mode, which means that the second hardware timer 121 counts down to 0 or counts up to its counter limit and generates a single interrupt when it reaches 0 or the counter limit.
[0032] Alternatively, an RTOS that implements cycle-based scheduling and is executed by the CPU 125 can operate using a single hardware timer 121. The single hardware timer 121 can increment (or decrement) every cycle of the CPU 125, run in a continuous mode, can be used for long-term precision, and can generate one or more interrupts. Thus, the functionality of the first and second hardware timers 121 described above can be combined into a single hardware timer 121.
[0033] Although this disclosure describes the hardware timer 121 as being capable of running in a continuous mode and incrementing (or decrementing) the cycle count value, this is not meant to be limiting. For example, the hardware timer 121 may implement the functionality of a counter (e.g., counter 122) by periodically incrementing (or decrementing) the cycle count value every cycle of the CPU 125 for long-term accuracy. As another example, a counter 122 separate from the hardware timer 121 may implement the functionality of the counter described above. In this embodiment, the hardware timer 121 may not run in a continuous mode. Rather, a separate counter 122 may run in a continuous mode and provide long-term accuracy by incrementing (or decrementing) the cycle count value.
[0034] In an embodiment, the cycle count value is a 64-bit value. Although overflow of the 64-bit cycle count value can occur, the overflow occurs within approximately 2 years, which is approximately 585 years if the system is powered on and running continuously. 64The overflow occurs after about 585 cycles of the CPU 125 (assuming a 1 GHz clock). If the overflow occurring after about 585 years is a problem, the RTOS executed by the CPU 125 may be configured to overcome the problem. For example, the CPU 125 may be configured to use a slower clock source (e.g., a clock with a speed less than 1 GHz, such as 100 MHz). For example, if the CPU 125 uses a 100 MHz clock, the overflow occurs after about 5850 years. As another example, the least significant bit of the hardware timer 121 may be ignored. If 28 bits of the hardware timer 121 are used instead of the full 32 bits of the hardware timer 121, the frequency observed by the RTOS executed by the CPU 125 may be reduced by a factor of 16, resulting in an overflow occurring after about 9360 years. As another example, the overflow may be handled by the RTOS executed by the CPU 125. As an illustrative example, the RTOS may be written to appropriately account for overflows (e.g., maintain a count value representing the previous value of the cycle count value and a second count value that is incremented each time the current value of the cycle count value is less than the previous value of the cycle count value and represents the number of overflows).
[0035] A counter value (e.g., TickCnt) that represents the number of time ticks (e.g., interrupts) since the embedded system 120 started, present in a typical RTOS implementation, is optionally eliminated in the RTOS executed by the CPU 125. In a typical RTOS implementation, it was sometimes useful to obtain the system time in milliseconds for display in a network (e.g., web) interface or for use in a tight loop with a timeout. In an RTOS executed by the CPU 125 that implements cycle-based scheduling, there is no longer a fixed 1 millisecond system tick, so it may not be necessary to display the system time in a network interface. As described herein, the hardware timer 121 may still generate an interrupt, but the interrupt need not necessarily be periodic. Instead, the hardware timer 121 may be a single-shot timer that is programmed to generate an interrupt precisely when needed by a task, scheduler, and / or the like.
[0036] In the RTOS executed by the CPU 125, the counter value representing the number of time ticks may be eliminated, but this is not meant to be a limitation. For example, the RTOS executed by the CPU 125 may still generate a periodic interrupt every millisecond (or any other time unit) if desired by a user or operator of the embedded system 120. In particular, to replicate the counter value representing the number of time ticks, the RTOS may call a first API function (e.g., OS_TIME_GetCycles()) to obtain a cycle base time (e.g., the number of cycles of the CPU 125 that have occurred since the embedded system 120 began or was started operating, as indicated by a count value maintained by the second hardware timer 121 or counter 122). The RTOS may then divide the cycle base time by the cycle frequency of the CPU 125 (e.g., the number of cycles of the CPU 125 in a time unit, such as milliseconds). As an illustrative example, in a 600 MHz embedded system 120, the RTOS may call a first API function and divide the resulting value by 600000 to obtain a time value in milliseconds that represents the number of time units that have elapsed since embedded system 120 began or started operating. Alternatively or additionally, the RTOS executed by CPU 125 may support an API function (e.g., OS_TIME_GetTime_ms()) that, when called, returns the number of time units that have elapsed since embedded system 120 began or started operating.
[0037] As described above, the RTOS executed by CPU 125 may support one or more API functions available in a typical RTOS implementation. For example, an API function supported by a typical RTOS implementation may behave in the same manner as a typical RTOS implementation when called by an RTOS executed by CPU 125. As an illustrative example, an API function OS_Delay() supported by a typical RTOS implementation and providing millisecond-adjusted timings may still provide the same millisecond-adjusted timings when called by an RTOS executed by CPU 125. Thus, the timing of an application that originally ran on an embedded system with a typical RTOS and is migrated to embedded system 120 running an improved RTOS may not change.
[0038] Additionally, the RTOS executed by the CPU 125 may support one or more additional API functions not supported by a typical RTOS. For example, the RTOS executed by the CPU 125 may support OS_Delay_ms(), OS_delay_us(), OS_Delay_Cycles(), and / or any other API function that, when called, waits for a period of time specified in units of time or cycles of the CPU 125 and transitions a task from one state to another state (e.g., from waiting to ready) after the period has expired. OS_Delay_ms() may be a function that, when called, pauses the calling task, waits for a period of time specified in milliseconds, and transitions the task from one state to another state (e.g., from waiting to ready) after the period has expired. OS_Delay_us() may be a function that, when called, pauses the calling task, waits for a period of time specified in microseconds, and transitions the task from one state to another state (e.g., from waiting to ready) after the time has expired. OS_Delay_Cycles() may be a function that, when called, suspends the calling task, waits for a period of time specified in cycles of CPU 125, and transitions the task from one state to another (e.g., from waiting to ready) after the period has expired. Some or all of these additional API functions may enable more precise timing for reasons described herein. Overall, by supporting API functions supported by a typical RTOS implementation and additional API functions not supported by a typical RTOS implementation, the RTOS executed by CPU 125 can provide the same level of precision as a typical RTOS for applications that use API functions supported by the typical RTOS implementation and the improved RTOS, and can provide more precise timing than a typical RTOS for applications modified to use one or more additional API functions.
[0039] CPU 125 may be any hardware processor and may include a single core or multiple cores. In some embodiments, embedded system 120 may include multiple discrete CPUs 125. Memory 123 may include random access memory (RAM) and / or read-only memory (ROM). In the illustrated embodiment, memory 123 includes one or more real-time programs 124 (or, optionally, one or more programs that do not execute in real-time). In one embodiment, programs 124 are stored in ROM. Programs 124 may also be stored in RAM in some embodiments.
[0040] The embedded system 120 can communicate with other electronic or computing devices via the network 110. For example, the network 110 may include any wired network, wireless network, or combination thereof. For example, the network 110 may be a personal area network, a local area network, a wide area network, a wireless broadcast network (e.g., for radio or television), a cable network, a satellite network, a cellular network, or combinations thereof. As a further example, the network 110 may be a publicly accessible network of linked networks, such as the Internet, which may be operated by various separate parties. In some embodiments, the network 110 may be a private or semi-private network, such as a corporate or university intranet. The network 110 may include one or more wireless networks, such as a Global System for Mobile Communications (GSM) network, a Code Division Multiple Access (CDMA) network, a Long Term Evolution (LTE) network, or any other type of wireless network. The network 110 may use protocols and components for communicating over the Internet or any of the other aforementioned types of networks. For example, protocols used by network 110 may include such as HyperText Transfer Protocol (HTTP), HyperText Transfer Protocol Secure (HTTPS), Message Queuing Telemetry Transport (MQTT), Constrained Application Protocol (CoAP), etc. Protocols and components for communicating over the Internet or any of the aforementioned other types of communications networks are well known to those of skill in the art and thus will not be described in further detail herein.
[0041] Example implementation As noted above, an RTOS implementing cycle-based scheduling as described herein may be a priority-controlled (and / or time-slicing) multitasking operating system designed for use in developing and running real-time or near-real-time applications for various electronic or computing devices (e.g., embedded system 120, computers, microcontrollers, etc.). The RTOS may be executed by CPU 125 and access memory 123. For ease of explanation, the RTOS is described herein as being executed by CPU 125 of embedded system 120. However, the RTOS may be executed by a CPU core or multiple CPU cores of any type of electronic or computing device.
[0042] A task may be a program that runs on the CPU 125 of the embedded system 120. A thread may be a task that shares the same memory layout with other threads, and a process may be a task that has its own memory layout. The improved RTOS may enable multiple tasks to run on a single CPU 125 and / or multiple CPUs 125 by providing a multitasking operating system as described above. The improved RTOS may schedule tasks for execution.
[0043] An interrupt generated by hardware timer 121 may be an interruption of a program caused by hardware timer 121. When an interrupt occurs, CPU 125 may save its registers and execute a subroutine of CPU 125 called an ISR. After the ISR completes, the program may return to the highest priority task ready to run. For example, the ISR may respond to the expiration of hardware timer 121 by determining whether a task should be started and / or run.
[0044] Unlike typical RTOS implementations that use system ticks as a time base, the improved RTOS uses cycles of the CPU 125 as a time base. For example, one hardware timer 121 or counter 122 may run at a particular frequency, such as a frequency determined by the CPU 125 clock rate (e.g., the hardware timer 121 or counter 122 may increment or decrement a cycle count value every cycle of the CPU 125, as described above). The improved RTOS may rely on a single hardware timer 121 or multiple hardware timers 121 (and / or counters 122). In an embodiment in which the improved RTOS relies on multiple hardware timers 121 (and / or counters 122), the first hardware timer 121 increments or decrements a cycle count value every cycle of the CPU 125 (rather than every system tick or every unit of time) and may be used for a long-term time base (e.g., may generate a cycle count value that continuously increases or decreases over the course of operation of the embedded system 120). The second hardware timer 121 may be used to increment or decrement a count value at a specified frequency (e.g., in units of time, CPU 125 cycles, and / or system ticks specified in an API call by the task) and generate one or more interrupts, such as when the count value reaches 0 or a counter limit. Expiration of the second hardware timer 121 may cause an interrupt to be generated, which may cause an ISR (or other CPU 125 subroutine) to read the cycle count value maintained by the first hardware timer 121 and determine whether the cycle count value maintained by the first hardware timer 121 has reached a value that will cause the task to wake up and / or run.
[0045] The second hardware timer 121 may be a one-shot timer that is periodically reset by the improved RTOS. For example, one or more tasks may generate an API function call that specifies a time window in which the respective task should be woken up and / or executed. The time window may be specified in units of time, number of CPU 125 cycles, and / or number of system ticks, and the improved RTOS may convert the unit of time and / or number of system ticks to an equivalent number of CPU 125 cycles if the time window is not specified in number of CPU 125 cycles. The improved RTOS can determine which task is launched first, and (1) set the second hardware timer 121 to start a count value with a number of CPU 125 cycles corresponding to the API function call generated by the first task to be launched (e.g., a number of CPU 125 cycles specified in the API function call generated by the first task to be launched, or a number of CPU 125 cycles determined to be equal to a unit time or a unit system tick specified in the API function call generated by the first task to be launched) and decrement the count value to 0 (or 1), or (2) set the second hardware timer 121 to start a count value at 0 (or 1) and increase the count value until it reaches the number of CPU 125 cycles specified in the API function call generated by the first task to be launched.
[0046] When the count value reaches 0 (or 1) or the number of cycles of the CPU 125, the first hardware timer 121 may generate an interrupt, and an ISR or other subroutine of the CPU 125 may check the cycle count value of the first hardware timer 121 to determine whether the first task waiting to be started should be started. If the first task should be started, the scheduler of the improved RTOS, the first task, and / or the CPU 125 or other subroutines of the improved RTOS may perform operations as a result (e.g., start the first task). Upon and / or before these operations are completed, the improved RTOS may reset the second hardware timer 121 and determine which task should be started next. The improved RTOS may then perform at least one of two actions. The improved RTOS may set the second hardware timer 121 to start a count value with a number of cycles of the CPU 125 corresponding to an API function call generated by a next task waiting to be woken up minus a number of cycles of the CPU 125 already elapsed due to previously executed second hardware timer 121 and any operations performed by the scheduler, the first task, and / or other subroutines (e.g., a number of cycles of the CPU 125 specified in an API function call generated by the first task waiting to be woken up, or a number of cycles of the CPU 125 determined to be equal to a unit time or unit system tick specified in an API function call generated by the first task waiting to be woken up minus a number of cycles of the CPU 125 that have elapsed since the second hardware timer 121 was initially set), and decrement the count value to 0 (or 1).Alternatively or additionally, the improved RTOS may set the second hardware timer 121 to start a count value at 0 (or 1) and increment the count value until it reaches the number of cycles of the CPU 125 specified in the API function call generated by the first task waiting to be woken up minus the number of cycles of the CPU 125 already elapsed due to the second hardware timer 121 previously executed and any operations performed by the scheduler, the first task, and / or other subroutines. When the count value reaches 0 (or 1) or the number of cycles of the CPU 125, the first hardware timer 121 may generate an interrupt and an ISR or other subroutine may check the cycle count value of the first hardware timer 121 to determine whether to wake up the next task waiting to be woken up. This process may be repeated any number of times for any number of tasks generating API function calls as described herein.
[0047] Because the frequency at which CPU 125 cycles occur may be the inverse of the clock rate, CPU 125 cycles may occur much more frequently than once per millisecond. Because the improved RTOS relies on CPU 125 cycles as a time base, tasks executed by the improved RTOS may be configured to wake up in response to interrupts and execute at times or frequencies based on the occurrence units or multiples of CPU 125 cycles, and thus occur with finer time resolution than once per millisecond, or more frequently than once per millisecond. However, system ticks may occur at most once per millisecond. Thus, tasks executed by the improved RTOS may be configured to wake up and execute with much finer time resolution than that provided by a typical RTOS implementation that relies on system ticks as a time base. As a result, fewer interrupts may be generated, conserving CPU 125 resources and reducing power consumption.
[0048] Despite using CPU 125 cycles as a time base rather than system ticks, the improved RTOS may still be compatible with existing API functions. For example, the improved RTOS may include API functions that, when called, convert CPU 125 cycles to system ticks (assuming one tick per millisecond) and / or return units system ticks, API functions that, when called, convert CPU 125 cycles to time units and / or return time units (e.g., milliseconds, microseconds, nanoseconds, etc.), API functions that, when called, convert time units to CPU 125 cycles and / or return units of CPU 125 cycles, and / or the like.
[0049] Figure 2 illustrates an example of operations performed by components of operating environment 100 to initiate task 210. As shown in Figure 2, hardware timer 121A may increment a cycle count value every CPU cycle at (1). Hardware timer 121A may operate in a continuous mode such that the cycle count value continues to be incremented every CPU cycle regardless of operations being performed by other components of operating environment 100. Hardware timer 121A may also be referred to herein as first hardware timer 121A.
[0050] Task 210 may generate an API function call that specifies a time frame to be initiated in (2). For example, the time frame may be a unit of time, a cycle of CPU 125, a unit system tick, and / or the like. RTOS 225 may receive the API function call and set hardware timer 121B. Hardware timer 121B may also be referred to herein as second hardware timer 121B. In particular, RTOS 225 may set hardware timer 121B to increase or decrease a count value based on the time frame specified in the API function call in (3). The count value may be increased or decreased every cycle of CPU 125. As an illustrative example, RTOS 225 may set hardware timer 121B to increase a count value until the count value matches the number of cycles of CPU 125 specified in the API function call, until the count value matches a value that would be reached when a unit of time specified in the API function call has elapsed, until the count value matches a value that would be reached when a unit system tick specified in the API function call has been satisfied, and / or until such a value. As another illustrative example, RTOS 225 may set hardware timer 121B to decrement the count value until the count value is decremented a number of times corresponding to a number of CPU 125 cycles specified in the API function call, until the count value is decremented a number of times corresponding to a number that would be reached when a unit time specified in the API function call has elapsed, until the count value is decremented a number of times corresponding to a number that would be reached when a unit system tick specified in the API function call has been satisfied, and / or until such a number. In embodiments in which the count value is decremented, the count value is initially set to a value such that the count value becomes zero when any of the above conditions are met.
[0051] In response, hardware timer 121B can increment or decrement the count value at (4). Hardware timer 121B can increment or decrement the count value every cycle of CPU 125. RTOS 225 can monitor the count value at (5) and determine when the count value reaches zero (e.g., in the situation where the count value is decremented) or when the time period specified in the API function call is reached (e.g., in the situation where the count value is incremented).
[0052] Hardware timer 121B may generate an interrupt at (6) when RTOS 225 determines that the count value has reached zero or a specified time period. ISR 220 may determine that an interrupt has been triggered and determine the current cycle count value of hardware timer 121A at (7). If the current cycle count value indicates that a number of CPU cycles has elapsed that equals or exceeds the time period in which task 210 should be woken up, ISR 220 may wake up task 210 at (8).
[0053] Example of a Cycle-Based Scheduling Routine Figure 3 illustrates an example of a cycle-based scheduling routine 300 that may be implemented in embedded system 120 of Figure 1. For example, CPU 125 executing an improved RTOS and / or other components of embedded system 120 may execute cycle-based scheduling routine 300. Cycle-based scheduling routine 300 begins at block 302.
[0054] In block 304, the first hardware timer increments a cycle count value every CPU cycle. For example, the first hardware timer may begin incrementing the cycle count value when the embedded system 120 on which the first hardware timer executes is started.
[0055] In block 306, an API function call is obtained from a task running on the CPU 125. For example, the API function call may specify a time window during which the task is to be woken up. The task may go to sleep, hibernate, or wait after calling the API function.
[0056] A second hardware timer is set to increment or decrement a count value every CPU cycle in block 308. For example, the manner in which the second hardware timer is set may depend on the time frame specified in the API function call.
[0057] In block 310, an interrupt is generated in response to the expiration of the second hardware timer. For example, the second hardware timer may generate an interrupt.
[0058] At block 312, in response to determining that the time frame specified by the API function call has elapsed, the task is initiated. For example, an interrupt may be generated to cause the ISR to check the cycle count value. The determination may be made by checking the cycle count value to determine whether a difference between the current cycle count value and a previous cycle count value (e.g., the current cycle count value when the API function was called) corresponds to (e.g., matches) the time frame specified in the API function call. After the task is initiated, the second hardware timer may be reset for future use in initiating the task or another task, and the cycle-based scheduling routine 300 terminates.
[0059] term Many other variations beyond those described herein may be apparent from the present disclosure. For example, in some embodiments, any particular operations, events, or functions of an algorithm described herein may be performed in a different order, added, merged, or omitted entirely (e.g., not all operations or events described may be necessary to the implementation of an algorithm). Furthermore, in certain embodiments, operations or events may be performed simultaneously rather than sequentially, for example, through multi-threading, interrupt processing, or on multiple processors or processor cores, or other parallel architectures. Furthermore, different tasks or processes may be performed by different machines and / or computing systems that can function together.
[0060] The various exemplary logic blocks, modules, and algorithmic elements described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or a combination of both. To clearly illustrate this interchangeability of hardware and software, the various exemplary components, blocks, modules, and elements have been described above generally in terms of their functionality. Whether such functionality is implemented as hardware or software depends on the particular application and design constraints imposed on the overall system. The described functionality may be implemented in various ways for each particular application, and such implementation decisions should not be interpreted as causing a departure from the scope of the present disclosure.
[0061] The various example logic blocks and modules described in connection with the embodiments disclosed herein may be implemented or executed by a machine or hardware processor, such as a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general purpose processor may be a microprocessor, but alternatively, the processor may be a controller, a microcontroller, or a state machine, combinations thereof, or the like. A processor may include electrical circuitry configured to process computer executable instructions. In another embodiment, a processor may include an FPGA or other programmable device that performs logical operations without processing computer executable instructions. A processor may be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors in combination with a DSP core, or any other such configuration. Although described herein primarily with respect to digital technology, a processor may include primarily analog components. For example, some or all of the signal processing algorithms described herein may be implemented in analog circuitry or mixed analog and digital circuitry. The computing environment may include any type of computer system, including, but not limited to, a microprocessor-based computer system, a mainframe computer, a digital signal processor, a portable computing device, a device controller, or a computational engine within an appliance.
[0062] Elements of the methods, processes, or algorithms described in connection with the embodiments disclosed herein may be embodied directly in hardware, in software modules stored in one or more memory devices and executed by one or more processors, or in a combination of the two. The software modules may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM, or any other form of non-transitory computer-readable storage medium, medium, or physical computer storage known in the art. An example of a storage medium may be coupled to the processor such that the processor can read information from and write information to the storage medium. Alternatively, the storage medium may be integral to the processor. The storage medium may be volatile or non-volatile. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. Alternatively, the processor and the storage medium may reside as discrete components in a user terminal.
[0063] Conditional language used herein, such as "can," "may," "may," "for example," and the like, may be generally intended to convey that certain embodiments include certain features, elements, and / or conditions while other embodiments do not, unless specifically stated otherwise or understood otherwise within the context in which it is used. Thus, such conditional language may not generally imply that features, elements, and / or conditions may be required in any manner for one or more embodiments, or that one or more embodiments necessarily include logic for determining, with or without author input or prompting, whether these features, elements, and / or conditions may be included or performed in any particular embodiment. Terms such as "include," "comprise," "have," and the like, are synonymous and may be used in an inclusive, open-ended manner and do not exclude additional elements, features, acts, operations, etc. Additionally, the term "or" may be used in an inclusive (rather than exclusive) sense, e.g., when used to connect a list of elements, the term "or" may mean one, some, or all of the elements in the list. Further, the term "every" as used herein, in addition to having its ordinary meaning, can refer to any subset of the set of elements to which the term "every" can apply.
[0064] Disjunctive language, such as the phrase "at least one of X, Y, or Z," may be understood in the context where it is generally used to indicate that an item, term, etc. may be either X, Y, or Z, or any combination thereof (e.g., X, Y, and / or Z), unless specifically stated otherwise. Thus, such disjunctive language may not be, and should not be, generally intended to mean that a particular embodiment requires that at least one of X, at least one of Y, or at least one of Z, respectively, be present.
[0065] While the above detailed description illustrates, describes, and points out novel features applicable to various embodiments, it can be understood that various omissions, substitutions, and changes in the form and details of the described apparatus or algorithms can be made without departing from the spirit of the present disclosure. As can be recognized, certain embodiments described herein can be implemented in a form that does not provide all of the features and advantages described herein, since some features can be used or practiced separately from other features.
Claims
1. A memory device configured to store an operating system; A hardware processor in communication with the memory device, the hardware processor being configured to, when executed by the hardware processor, cause the hardware processor to: causing a first hardware timer to increment a cycle count value every cycle of the hardware processor; determining that a task executing on the hardware processor has invoked an application programming interface (API) function that specifies a time period; In response to the API function being called, setting a second hardware timer to change a count value every cycle of the hardware processor; determining that the second hardware timer has expired; causing the second hardware timer to generate an interrupt; Using the current version of the cycle count value to determine that a time period specified by the API function has elapsed; Initiating said task; A computing device that includes a hardware processor that is configured with computer-executable instructions.
2. 2. The computing device of claim 1, wherein the computer-executable instructions, when executed, further cause the hardware processor to determine when the count value has reached either zero or a value corresponding to the time period.
3. The computing device of claim 1 , wherein the time frame comprises one of a number of cycles of the hardware processor, a unit of time, or a unit system tick.
4. 2. The computing device of claim 1, wherein the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to increment the count value every cycle of the hardware processor.
5. 2. The computing device of claim 1, wherein the computer-executable instructions, when executed, further cause the hardware processor to set the second hardware timer to decrement the count value every cycle of the hardware processor.
6. The computing device of claim 1 , wherein the operating system comprises a real-time operating system.
7. The computing device of claim 1 , wherein the computing device comprises an embedded system.
8. 2. The computing device of claim 1 , wherein the operating system is compatible with an extended API, the extended API including at least one of a first function, a second function, or a third function, the first function, when called, passing a first parameter to the operating system specifying a unit tick and instructing the operating system to schedule an interrupt after a first number of cycles of the hardware processor corresponding to the first parameter, the second function, when called, passing a second parameter to the operating system specifying a second number of cycles of the hardware processor and instructing the operating system to schedule an interrupt after the second number of cycles of the hardware processor, and the third function, when called, passing a third parameter to the operating system specifying a unit time and instructing the operating system to schedule an interrupt after a third number of cycles of the hardware processor corresponding to a third parameter.
9. The computing device of claim 8 , wherein the unit of time comprises one of milliseconds, microseconds, or nanoseconds.
10. The computing device of claim 1 , wherein the first hardware timer is used for long term time measurements and the second hardware timer is a one shot timer.
11. 1. A computer-implemented method comprising: causing a first hardware timer to increment a cycle count value every cycle of the hardware processor; determining that a task executing on the hardware processor has called an application programming interface (API) function that specifies a time period; responsive to the API function being called, setting a second hardware timer to change a count value every cycle of the hardware processor; determining that the second hardware timer has expired; causing the second hardware timer to generate an interrupt; using a current version of the cycle count value to determine that a time period specified by the API function has elapsed; initiating the task; A computer-implemented method performed by an operating system executed by said hardware processor.
12. 12. The computer-implemented method of claim 11, wherein determining that the second hardware timer has expired further comprises determining that the count value has reached either zero or a value corresponding to the time period.
13. 12. The computer-implemented method of claim 11, wherein the time frame comprises one of a number of cycles of the hardware processor, a unit of time, or a unit system tick.
14. 12. The computer-implemented method of claim 11, wherein setting the second hardware timer further comprises setting the second hardware timer to increment the count value every cycle of the hardware processor.
15. 12. The computer-implemented method of claim 11, wherein setting the second hardware timer further comprises setting the second hardware timer to decrement the count value every cycle of the hardware processor.
16. The computer-implemented method of claim 11 , wherein the operating system comprises a real-time operating system.
17. The computer-implemented method of claim 11 , wherein the embedded system includes a hardware processor.
18. 12. The computer-implemented method of claim 11, wherein the operating system is compatible with an extended API, the extended API including at least one of a first function, a second function, or a third function, the first function, when called, passing to the operating system a first parameter specifying a unit tick and instructing the operating system to schedule an interrupt after a first number of cycles of the hardware processor corresponding to the first parameter, the second function, when called, passing to the operating system a second parameter specifying a second number of cycles of the hardware processor and instructing the operating system to schedule an interrupt after the second number of cycles of the hardware processor, and the third function, when called, passing to the operating system a third parameter specifying a unit time and instructing the operating system to schedule an interrupt after a third number of cycles of the hardware processor corresponding to a third parameter.
19. 20. The computer-implemented method of claim 18, wherein the unit of time comprises one of milliseconds, microseconds, or nanoseconds.
20. 12. The computer-implemented method of claim 11, wherein the first hardware timer is used for long term time measurements and the second hardware timer is a one-shot timer.
Citation Information
Patent Citations
Operating system and its time managing method, and information processor and storage medium
JP2000047880A
Switch cluster and its constituting method
JP2004032159A
Control method for control software execution system
JP2004164664A
Image forming apparatus
JP2009271715A
Information processor and program
JP2010003153A
