Timer service uses a single timer function to perform timing services for both relative and absolute timers

A timer service uses a single timer function to perform timing services for both relative and absolute timers. The first timers from a sorted array of absolute timers and relative timers are used in a function that will return when the earliest absolute timer expires or will timeout when the earliest relative timer expires. The timer function may be interrupted when a new timer is added to one of the arrays. The function will operate in a predictable and consistent manner, even when a system clock is adjusted.

BACKGROUND

Timer services may be provided at an operating system level for various computer systems. Timer services may be used by various applications or other services to initiate various functions at a future time.

Timers may be defined in absolute and relative manners. In an absolute timer, the timer may be set to go off or respond at a specific time according to a system clock. A relative timer may be set to operate at a certain number of minutes or seconds after being set, without regard to the system clock.

Timer services may behave erratically or unpredictably when changes are made to a system clock. Changes may be made, for example, when the system changes time zones, during the change between daylight savings time and standard time occurs, or when the system clock is reset for some other reason, including slight adjustments to the clock to coordinate with another system.

SUMMARY

A timer service uses a single timer function to perform timing services for both relative and absolute timers. The first timers from a sorted array of absolute timers and relative timers are used in a function that will return when the earliest absolute timer expires or will timeout when the earliest relative timer expires. The timer function may be interrupted when a new timer is added to one of the arrays. The function will operate in a predictable and consistent manner, even when a system clock is adjusted.

DETAILED DESCRIPTION

A timing service may be an operating system level service that may be used by multiple applications to initiate certain actions at a future time. Timers may be defined in either an absolute mode, where a specific time is defined with respect to the system clock, or a relative mode, where the time for an action is defined relative to the current time.

Timing services operate using a system clock as the standard for determining when a timer is to be fired or actuated. When the clock is shifted or adjusted, such as for daylight savings time, when a mobile device changes time zones, or when a system clock is adjusted to correspond with a master clock, the effects on a timing service may be minimized by providing a timing function that will fire on either the first absolute timer or the first relative timer.

Many absolute and relative timers may be stored in sorted arrays that may be used to generate a single timer function in the timing service. When starting a timer function, any timers that are past due may be dispositioned prior to starting the timer function.

When a change to the system clock occurs, the timer function will fire at the sooner of the absolute or relative timer. In general, a shift backward or forward in a system clock will delay or hasten the action of an absolute timer but a relative timer will still operate independent of the system clock change.

The timing service consolidates timing operations from many different applications and services into a single function. By consolidating the timers, many separate threads and functions may be reduced into a single one, relieving the system of many processes and threads that may be used for other functions.

Specific embodiments of the subject matter are used to illustrate specific inventive aspects. The embodiments are by way of example only, and are susceptible to various modifications and alternative forms. The appended claims are intended to cover all modifications, equivalents, and alternatives falling within the spirit and scope of the invention as defined by the claims.

Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by an instruction execution system. Note that the computer-usable or computer-readable medium could be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via, for instance, optical scanning of the paper or other medium, then compiled, interpreted, of otherwise processed in a suitable manner, if necessary, and then stored in a computer memory.

FIG. 1is a diagram of an embodiment100showing a system with a timer service. The timer service may aggregate various timing or wait actions from several different applications into a single timer function. By aggregating many different timer requests into a single service, multiple timer functions that would otherwise use multiple computing resources may be consolidated into a single function.

The timer service of embodiment100may handle both absolute and relative timer requests. An absolute timer request may be activated at a specific time as defined by a system clock, which is in contrast to a relative timer request which may be active a certain amount of time after the current time.

The difference between absolute and relative timers may be seen when a system time change occurs. For example, if the current system time is 10:00, an absolute timer may be set for 10:15 and a relative timer may be set for 15 minutes from the current time. If there is no change to the system clock, both timers may become due at the same time, or at 10:15. If the current system clock is adjusted forward five minutes in order to correlate with a network administered time, for example, the current time would actually be 10:05. In the example, the relative timer would become due at 10:20, since it is due 15 minutes after the current time, but the absolute timer would still become due at 10:15.

Various applications104may send a timer request with a work item106to the timer service102. The timer request may include a work item that may be a specific function that is to be called at the specified time. The work item may also include a context, which may include data or pointers to data that may be used by the work item when the work item is executed.

In some instances, a timer request may be defined with a period for repeating the work item. For example, a timer request may be established to initiate a partial backup operation each evening at a specific time. Another request may have a full backup operation performed on the first Sunday of each month. Different embodiments may enable different periodicity definitions for timer requests.

The timer request106may be received by an input function108. The input function108may determine if the timer is a relative or absolute timer request and store the timer request in either an absolute timer array110or a relative timer array112. In some instances, the absolute timer array110and relative timer array112may be sorted in order of chronology so that the timing requests may be pulled from the arrays in order of the earliest request.

The earliest absolute timer request114and the earliest relative timer request116may be sent to a launch timer function118. The timer function122may operate with the system clock124to wait until one of the two timer requests114or116are satisfied. When one of the timer requests are satisfied, the appropriate work item may be launched126, and the timer function may be restarted with the next set of timers.

When restarting the timer function, the launch timer function118may evaluate whether the time for any unfulfilled timer requests have been passed. If additional timer requests exist for which the time has passed, the work items for those timer requests may also be launched.

When a new request106is received by the input function108, an interrupt120may be generated if the new timer request is earlier than its corresponding timer request that is in the timer function122. For example, if a new timer request is for a relative timer and has an activation time that is earlier than the earliest relative timer116, an interrupt120may be created and the timer function122halted. The timer function122may then be restarted with the new timer request.

FIG. 2is a flowchart illustration of an embodiment200showing a timer service operation.

A timer request is received in block202. A determination is made in block204as to whether the timer request is an absolute timer or a relative timer. If the timer request is an absolute timer, the timer is stored in the absolute timer array in block206, otherwise the timer is stored in the relative timer array in block208.

If the new timer is earlier than the current earliest timer in block210, the timer function is interrupted in block212. An interruption may be performed when the new timer request is an earlier timer request than one of the timers in the current timer function. An interruption may be performed in block212when the new timer is earlier than the current time of the same type. For example, a new timer request that is a relative timer and earlier than the current earliest relative timer may initiate an interruption in block212. A new timer request that is an absolute timer but is earlier than the current earliest relative timer may not initiate an interruption unless it was earlier than the current earliest absolute timer.

The array of absolute timers is sorted in block214and the earliest absolute timer is determined in block216. Similarly, the array of relative timers is sorted in block218and the earliest relative timer is determined in block220. In some embodiments, the arrays of timers may not be sorted. In other embodiments, sorting the arrays may make it easier to select the earliest timer.

If any unlaunched timers exist that are earlier than the current time in block222, the timers may be dispositioned. In some instances, a timer may be dispositioned by ignoring the timer, while in other instances the work item associated with the timer may be launched. Some timers may have a setting that may be evaluated to determine if the work item is to be launched or ignored in such a situation.

If the timer is to be launched in block226, the work item is launched in block228.

If there are no unlaunched timers in block222or if all the timers have been processed in block224, a timer function is launched in block230using the earliest absolute timer request and the earliest relative timer request.

The timer function as started may have a time function set to expire on the expiration time of the absolute timer and a timeout function set to the relative timer. A time function may be a function call that evaluates the system clock until a specified time is reached. When the time is reached, the time function may return and cause the work item for the absolute timer request to be executed.

The timeout function may be a function that waits for a specified period of time before returning. The timeout function may not use the system clock, but may count a specific number of clock cycles on a system or use some other method for determining if a specific wait period has been reached.

By configuring a timer function in this manner, a change to the system clock may affect the absolute timers and relative timers appropriately. A change to the system clock may cause absolute timers to be activated earlier or later, depending on the time adjustment. However, changes to the system clock may not adversely affect any relative timers, since the relative timers may be activated by a timeout function rather than the time function.

After the timer function has returned in block232, a work item associated with the fired timer is launched in block234. The process returns to block214.

When a new timer is added in block210but is not earlier than the current timers, the process continues to block232, waiting for the timer function to return.

The embodiment200is a method to consolidate many different timer functions into a single process operating on a system. The timer service executes the timers that are the next to be executed so that many different timer threads or processes exist on a system. Each timer request is processed in turn based on the earliest to be executed.

The timer service executes absolute timer requests that reference the system clock as well as relative timers that may use an elapsed actual time as opposed to a system time for actuation.

FIG. 3Ais a diagram illustration of an embodiment300showing a timeline with various timers. The timeline302has a current system time304shown, along with a set of absolute timers306and relative timers308. The timeline302illustrates the system time of the system clock, not actual time.

The absolute timers306comprise timers listed A, B, and C and are fixed with respect to the timeline. The relative timers308are shown as X+Y and X+Z, with X being the current time. The relative timers are designed to expire at a designated delay from the current time.

When the current time is adjusted to time310, the timer A in the absolute timers306has come due, but the relative timers are adjusted312so that the same delay in time occurs regardless of the adjustment made to the system time.

The current time may be adjusted for many different reasons, including daylight savings time, moving from one time zone to another, or for synchronizing the system clock of a device with another time source, such as an atomic clock standard.

FIG. 3Bis another diagram illustration of an embodiment314showing a timeline with various timers. The timeline316is a system timeline and shows a current system time318, some absolute timers320, and a group of relative timers322.

As withFIG. 3B, the absolute timers320comprise timers listed A, B, and C and are fixed with respect to the timeline. The relative timers322are shown as X+Y and X+Z, with X being the current time. The relative timers are designed to expire at a designated delay from whatever the current time is.

When the system clock is adjusted backwards to the adjusted time324, the adjusted relative timers326may also be adjusted. Because the relative timers are defined as a delay from the current time, the adjusted relative timers326illustrate when the relative timers322would occur. The adjusted relative timers326are not reset or changed, but will appear to occur sooner in system time than they would have before the system time was adjusted.