The present invention is related to data structures, operating systems, and computer programming and, in particular, an efficient method for queuing time outs, n a variety of different computational settings, including operating systems, controllers, networking protocols, communications drivers, and other computational entities that manage time outs, for subsequent handling.
Many different types of computational entities, from operating systems, low-level device drivers, and communications drivers to relatively high-level application programs, need to manage sets of time-associated data objects with respect to a time, as represented by a system timer or other time-reporting device. In general, a time-associated data object represents a task or event that needs to be handled by the computational entity after the elapse of an amount of time associated with the data object. For example, in a networking protocol, a client entity may send a request message to a remote computational entity that is obligated, according to the networking protocol, to return a response within some fixed period of time. The client computational entity, along with sending the request, generally sets a timer or, in other words, queues a time-associated data object to a queue, so that the client computational entity will be subsequently notified should no response be received in the fixed period of time. If a response is received in the fixed period of time, the client computational entity is notified, or awakened, and removes the time-associated data object from the queue. However, when a response fails to be returned by the remote computational entity, a timer process, which monitors the time-associated-data-object queue with respect to a clock or other timing device to detect and de-queue data objects associated with a time equal to, or less than, the current time, awakens or notifies the client computational entity.
A number of primitive operations are generally carried out on a queue of time-associated data objects, or timer queue. The timer queue is generally kept, by a timer process, in ascending time-value order. The timer process needs to be able to find the proper position within the timer queue for inserting a time-associated data object, or timer, and also needs to find a particular time-associated data object in the queue for removal. However, as timer queues grow in size, due to various latencies and bottlenecks or problems in handling timer-associated tasks, these primitive operations may incur increasing computational overhead. In many cases, this computational overhead may further exacerbate computational inefficiencies and overheads associated with a processing-cycle-bound processes and routines handling timer-associated tasks, compounding overload situations. For this reason, computer scientists, designers and implementers of systems and software that employ timer queues as well as routines and processes that manage timer-associated tasks, and users of such systems and software have all recognized the need for more efficient timer-queue management to prevent the increase in computational overhead associated with timer queues of increasing lengths.
Embodiments of the present invention are directed to computationally efficient timer-queue management. In one embodiment of the present invention, a timer queue is implemented as a circular-timer queue, containing timers, or time-associated data objects, due to expire in a relatively short period of time, and a second queue or list of timers or time-associated data objects, referred to as the “later queue,” containing timers or time-associated data objects due to expire after a period of time longer than the period of time during which the timers or timer-associated data objects on the circular-timer queue are due to expire. At generally regular intervals, as timers or time-associated data objects are removed from the circular-timer queue, timers or time-associated data objects are transferred from the later queue to the circular-timer queue.
FIGS. 1A-E illustrate a generalized, currently available timer queue and two important operations carried out on such timer queues.
FIGS. 2A-F illustrate one embodiment of the present invention.
FIGS. 3A-B show control-flow diagrams for methods that represent embodiments of the present invention.
The present invention is directed to computationally efficient management of timer queues. Timer queues are list-like or queue-like data structures that contain timers, or time-associated data objects, and that are sorted in increasing time order. Timer queues are created by, or created on behalf of, and managed by, or managed on behalf of, many different types of computational processes, including processes that implement networking protocols, communications drivers, operating systems, and even application programs. An entry in a timer queue is generally associated with a time value, and may contain other data values or pointers that allow a task, process, or event associated with a timer entry to be identified by a process or routine that manages time-associated processes, events, data structures, and other such time-associated entities. A timer queue and timer process together server to alert a process or routine of events or other entities associated with timers after an amount of time specified by the timer has elapsed, much like a kitchen timer alerts a cook when a specified period of time associated with a cooking task has elapsed.
FIGS. 1A-E illustrate a generalized, currently available timer queue and two important operations carried out on such timer queues.
Timer processes generally need to initialize timer queues, add entries to timer queues, remove entries from timer queues, and carry out other timer-queue management tasks. FIGS. 1B-C illustrate addition of a timer, or time-associated time object, to a timer queue. As shown in
A timer process may also be requested to remove an entry from a timer queue. FIGS. 1D-E illustrate removal of a timer, or time-associated data object, from a timer queue by a timer process. As shown in
Although the timer queue shown in FIGS. 1A-E are represented as simple linked lists, there are many different types of timer queues currently in use. As one example, rather than a linked list of time-associated data objects, a timer queue may alternatively be a linked list, or array, containing pointers to additional linked lists or arrays, each associated with a particular time value. However, in general, currently available timer queues generally have the property that, as the length of the timer queues, or, in other words, the number of timers or time-associated data objects contained in the queue grows, the basic operations of identifying particular time-associated positions within the timer queues in order to add or delete entries from the timer queues incurs an increasing computational overhead, both in time and processing cycles. The increase in computational time may be linear, for many timer-queue-traversal implementations, including various types of search algorithms, or may be greater than linear for certain types of timer-queue implementations.
Timer queues and timers are often employed by real-time processes and routines, including operating systems and network-protocol-implementing processes and routines, that are prone to becoming computationally bound due to high loads or high numbers of tasks to manage. Unfortunately, in such cases, the timer queues often grow to large lengths, and incur increasing computational overhead for the primitive operations of identifying particular time-associated positions within the timer queues for timer entry and timer removal, further exacerbating the computational overload of the processes and routines using timers and timer queues. For this reason, better timer-queue-management methods and systems are needed.
FIGS. 2A-F illustrate one embodiment of the present invention.
By partitioning a timer queue into a CTQ and a later queue, and when most operations carried out by the timer process are directed to timer-queue entries associated with time values in the not-too-distant future, and therefore stored in the CTQ, great computational efficiencies can be obtained. As discussed below, rather than traversing an entire timer queue to locate time-associated positions within the timer queue in order to insert and delete entries, a timer process can easily calculate, using modular arithmetic, the index of the CTQ entry that represents the set of all timers or time-associated data objects associated with a particular point in time. In certain implementations, the later queue may be sorted in increasing time order, while in other implementations, the later queue may simply be a heap of time-associated data objects, ordering and processing of which are deferred by the timer process until convenient points in time for processing them. Various intermediary implementations are also possible, in which the later queue is partially time ordered.
(Final−Now+N)mod N
where the pointers Final and Now are monotonically increasing indices of CTQ entries, as shown in
(Now+t)mod N,
as shown by arrow 242 in
t−[(Final−Now+N)mod N]−1
where the later-queue entries begin with entry 0, in the case that the later queue is a fully time-ordered list.
The two-part timer queue is processed by the timer process at each fixed time equal to the interval of time represented by two successive entries in the CTQ. At each clock tick, the timer process removes any timers or time-associated data objects associated with the CTQ entry referenced by the pointer “Now,” and increments the pointer “Now” by 1.
At regular points in time, in one embodiment equal to some fixed number of clock ticks, such as N/2, entries are transferred from the later queue to the CTQ.
FIGS. 3A-B show control-flow diagrams for methods that represent embodiments of the present invention.
Although the present invention has been described in terms of particular embodiments, it is not intended that the invention be limited to these embodiments. Modifications within the spirit of the invention will be apparent to those skilled in the art. For example, any of an almost limitless number of different types of data structures can be used to implement a two-part timer queue that represents an embodiment of the present invention. For example, the timers or time-associated data structures associated with a particular time and CTQ entry or later-queue entry can be implemented as an array of pointers, a linked list, or by other such data structures. Similarly, the later queue can be implemented by any of a number of different data structures. As discussed above, the later queue can be time ordered, to facilitate efficient transfer of timers from the later queue to the CTQ, but, in alternative implementations, may be partially ordered or unordered, with computational overhead deferred through relatively widely spaced intervals to a relatively large CTQ. The size of the CTQ may vary, depending on time-queue-access behavior, interval between clock ticks, and other such parameters. Timers or time-associated data objects may include, besides a numerical representation of the time value, any of an almost limitless number of additional data values needed by routines and processes that employ timers and timer-associated data objects, manage events, processes, and other such entities. Any number of different CTQ-management routines, in any number of different programming languages using any number of different types of control structures, data structures, modular organizations, and other such program parameters can be implemented, according to the needs and capabilities of these systems in which CTQ data structures are used.
The foregoing description, for purposes of explanation, used specific nomenclature to provide a thorough understanding of the invention. However, it will be apparent to one skilled in the art that the specific details are not required in order to practice the invention. The foregoing descriptions of specific embodiments of the present invention are presented for purpose of illustration and description. They are not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations are possible in view of the above teachings. The embodiments are shown and described in order to best explain the principles of the invention and its practical applications, to thereby enable others skilled in the art to best utilize the invention and various embodiments with various modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalents:
This application claims the benefit of Provisional Application No. 60/789,084, filed Apr. 3, 2006.
Number | Date | Country | |
---|---|---|---|
60789084 | Apr 2006 | US |