Management system and management method for timer in software system
Technical Field
The present invention relates to a timing and timing technology in a software system, and more particularly, to a management system and a management method for a timer in a software system, which can be used in a mobile terminal and a network side switching device.
Background
At present, the complexity of a software system of the communication equipment is increased day by day, and the requirement on management and use of the timer is also the ship height. The requirements of the existing software system for the use of the timer are to reduce the system load caused by timer management to the minimum, reduce the timing error caused by timer updating, achieve strong universality of timer management and use, reduce the development difficulty and development cost of the software system, and improve the working efficiency and stability of the timer of the software system.
Chinese patent application No. CN02110936 proposes a timing method for a timer in an embedded real-time operating system, which comprises the following steps: a. setting a timer description array of the required maximum timer number; b. forming a circular timing queue by adopting an array with a certain length and a circular pointer variable, wherein the circular pointer variable points to each array element in a circular mode; c. when the upper application program needs a timer task, inserting a needed new timer into a circular timing queue; d. when each timing cycle arrives, the circular pointer variable moves backwards, whether the linked list queue of the pointed array element is empty is inquired, and if the linked list queue is empty, the arrival of the next timing cycle is waited; if not, judging whether the multiple value in the description structure of the timer in the linked list queue is 0 one by one, if so, indicating that the timing time of the timer is up, carrying out corresponding time-reporting operation and timer reinsertion operation, and simultaneously deleting the timer description array from the linked list queue; if the multiple value is not 0, the multiple value is reduced by 1, and then the next timer is judged. The above technical solution of this patent application includes the following drawbacks: 1. the multiple value in the linked list queue is decreased progressively, so that the burden of the system is increased; 2. it does not consider the problem of a lengthy timer.
Disclosure of Invention
In order to solve the above problems, an objective of the present invention is to provide a simple and efficient management system and management method for timers in a software system, which do not need to perform a decrement operation on the timing duration of each timer, not only consider the management of a short duration timer queue, but also increase the management of a long duration timer queue. The basic idea of the invention is as follows: uniformly managing timer resources in a software system; timers set by application tasks/processes are divided into two categories, namely absolute timers and relative timers, and different kinds of timers are respectively managed by different timer queues.
To achieve the above object, the present invention provides a management system for timers in a software system, which is suitable for timers set by application tasks/processes, wherein the timers set by the application tasks/processes include an absolute timer and a relative timer, and the management system at least includes an absolute timer management module and a relative timer management module, wherein:
the absolute timer management module at least comprises: an absolute timer queue for managing said absolute timer;
the relative timer management module at least comprises: a TICK queue for managing relative timers with short duration, wherein a relative timer queue with short duration is hung under each element in the TICK queue; and a long-duration relative timer queue for managing the long-duration relative timers.
Wherein, the absolute timer queue is a two-way linked list; the TICK queue is an array, the length of the array is MAX _ TMCB _ NUM, wherein MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module; the timing duration of the relative timer in each short-duration relative timer queue is less than or equal to MAX _ TMCB _ NUM TICKs, wherein the TICK is a unit time; and the relative timer in each relative timer queue with the short time length is up at the same time.
In addition, the long relative timer queue is an array, the length of the array is MAX _ TMCB _ NUM, where MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module; the timing duration of the relative timer in the long-duration relative timer queue is greater than MAX _ TMCB _ NUM TICKs, wherein the TICK is a unit time.
In order to achieve the above object, the present invention provides a method for managing a timer in a software system, which is suitable for a timer set by an application task/process, and at least comprises the following steps:
step 1: the management system divides the timer set by the application task/process into an absolute timer and a relative timer;
step 2: the management system judges whether the timer to be managed is an absolute timer or a relative timer, if the timer to be managed is the absolute timer, the step 3 is executed; if the relative timer is set, executing step 4;
and step 3: the absolute timer management module combines the absolute timers into an absolute timer queue, and the absolute timer queue manages the absolute timers;
and 4, step 4: the management system judges whether the timing duration of the relative timer is greater than MAX _ TMCB _ NUM TICKs, if not, step 5 is executed; otherwise, executing step 6;
and 5: the relative timer management module forms a relative timer queue with short time length by using relative timers which arrive at the same time and have the time length less than or equal to MAX _ TMCB _ NUM TICKs, the relative timer management module hangs the relative timer queue with short time length under one element in the TICK queue, and the TICK queue manages the relative timers with the time length less than or equal to MAX _ TMCB _ NUM TICKs; the array length of the TICK queue is MAX _ TMCB _ NUM, and MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module;
step 6: the relative timer management module makes relative timers with timing duration longer than MAX _ TMCB _ NUM TICKs form a long relative timer queue, and the long relative timer queue manages the relative timers with timing duration longer than MAX _ TMCB _ NUM TICKs; the array length of the long relative timer queue is MAX _ TMCB _ NUM, and MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module; each element in the long-duration relative timer queue indicates whether a TMCB having the same index number is set.
For example, the 10 th element in the long relative timer queue is TRUE (TRUE), indicating that TMCB [10] has been used by a certain timer.
Wherein, the step 3 comprises the following steps:
step 301: the absolute timer management module makes the absolute timer form the absolute timer queue according to the length of the set time, namely, the absolute timer which arrives earliest is arranged at the head of the absolute timer queue, and the absolute timer which arrives latest is arranged at the tail of the absolute timer queue;
step 302: the timer scanning task scans the absolute timer arranged at the head of the absolute timer queue in a scanning period;
step 303: the timer scanning task judges whether the absolute timer arranged at the head of the absolute timer queue expires, if not, the timer scanning task continues to scan the absolute timer in the next scanning period; if yes, go to step 304;
step 304: the timer scanning task removes the absolute timer from the head of the absolute timer queue and sends an overtime message to the task which sets the absolute timer; then step 305 is executed;
step 305: the timer scanning task scans the absolute timer arranged at the head of the absolute timer queue at the moment in the next scanning period;
step 306: and repeating the steps 303 to 305 until the absolute timer arranged at the head of the absolute timer queue does not expire or the absolute timer queue is empty.
The step 5 of composing the relative timer queue of the short duration includes the steps of:
step 501: the relative timer management module sets a system cursor, wherein the system cursor represents the current system time, and the value range of the system cursor is 0 to (MAX _ TMCB _ NUM-1);
step 502: the relative timer management module converts the timing duration of each relative timer with the timing duration less than or equal to MAX _ TMCB _ NUM TICKs into an offset in TICK units relative to the system cursor;
step 503: the relative timer management module combines all the relative timers with the same offset position as the system cursor into a relative timer queue with a short duration and hangs them down to an element in the TICK queue.
Wherein, in the step 5, managing the relative timer whose one timing duration is less than or equal to the MAX _ TMCB _ NUM TICKs includes the following steps:
step 504: the timer scanning task scans the relative timer in a scanning period, and the system vernier is increased by 1;
step 505: the timer scanning task judges whether the system cursor is overlapped with the relative timer, if not, the timer scanning task continues to scan the relative timer in the next scanning period, and the system cursor is increased by 1; otherwise, go to step 506;
step 506: and the timer scanning task removes the relative timer queue with the short time length where the relative timer is positioned from the TICK queue, and sends an overtime message to the task which sets the relative timer.
In step 503, all the relative timers in the short duration relative timer queue expire at the same time, since the TICK offset positions of all the relative timers and the system cursor are the same, regardless of whether all the relative timers in the short duration relative timer queue are set at the same time; the method for calculating the position of any relative timer with the timing duration less than or equal to MAX _ TMCBNUM TICKs in the TICK queue comprises the following steps: position (system cursor current position value + TICK number relative to timing duration of timer) mod (MAX _ TMCB _ NUM).
Wherein, for a relative timer in the long-duration relative timer queue, where one of the timing durations is greater than MAX _ TMCB _ NUM TICKs, the step 6 includes the following steps:
step 601: the relative timer management module sets a system cursor; wherein the system cursor represents the current system time, and the value range is 0 to (MAX _ TMCB _ NUM-1);
step 602: the relative timer management module gives a compensation value to the relative timer, and the final timing duration of the relative timer is the sum of the compensation value and the TICK number of the timing duration of the relative timer to be set, that is, the final timing duration of the relative timer is equal to the compensation value plus the TICK number of the timing duration of the relative timer to be set;
step 603: the timer scanning task scans the relative timer in a scanning period, and the system vernier is increased by 1;
step 604: subtracting the time lengths of MAX _ TMCB _ NUM TICKs from the final timing time length of the corresponding relative timer at the position of the system cursor by the timer scanning task;
step 605: the relative timer management module determines whether the reduced timing duration of the relative timer in the step 604 is less than or equal to MAX _ TMCB _ NUM TICKs, if yes, execute step 606; otherwise, go to step 607;
step 606: the relative timer management module takes the relative timer in step 604 out of the long relative timer queue and then puts it into the tail of the short relative timer queue hanging under one of the elements in the TICK queue;
step 607: step 603 to step 605 are repeatedly executed.
In addition, since the time taken for the system cursor to return to the original position after the system cursor circularly rotates one turn from the starting position is just the time of MAX _ TMCB _ NUM TICKs, the timer scanning task in step 604 may consider that the corresponding relative timer at the position where the system cursor arrives has passed the time of MAX _ TMCB _ NUM TICKs.
In step 602, the method for calculating the offset value by the relative timer management module includes:
step 611: the relative timer management module determines whether the index number (tid) of the TMCB used by the relative timer is greater than the current position value of the system cursor, if yes, step 612 is executed; otherwise, go to step 613;
step 612: MAX _ TMCB _ NUM- (index (tid) of TMCB used relative to timer-current position value of system cursor);
step 613: compensation value-the current position value of the system cursor-the index (tid) of TMCB used relative to the timer.
The management system and the management method have the advantages of the following aspects: 1. the burden of timer management in a software system in timing and timing is relieved; 2. confusion in the use of timers in software systems is prevented.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
FIG. 1 is a schematic view of a main flow of a management method according to the present invention;
FIG. 2 is a diagram of a TICK queue consisting of 2000 array elements according to the present invention.
Detailed Description
An embodiment is now proposed based on the present invention, but the present invention is not limited to this specific embodiment.
Fig. 1 is a schematic view of a main flow of the management method of the present invention. As shown in fig. 1, it comprises at least the following steps:
step 1: the management system divides the timer set by the application task/process into an absolute timer and a relative timer;
step 2: the management system judges whether the timer to be managed is an absolute timer or a relative timer, if the timer to be managed is the absolute timer, the step 3 is executed; if the relative timer is set, executing step 4;
and step 3: the absolute timer management module combines the absolute timers into an absolute timer queue, and the absolute timer queue manages the absolute timers;
and 4, step 4: the management system judges whether the timing duration of the relative timer is greater than MAX _ TMCB _ NUM TICKs, if not, step 5 is executed; otherwise, executing step 6;
and 5: the relative timer management module forms a relative timer queue with short time length by using relative timers which arrive at the same time and have the time length less than or equal to MAX _ TMCB _ NUM TICKs, the relative timer management module hangs the relative timer queue with short time length under one element in the TICK queue, and the TICK queue manages the relative timers with the time length less than or equal to MAX _ TMCB _ NUM TICKs; the array length of the TICK queue is MAX _ TMCB _ NUM, and MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module;
step 6: the relative timer management module makes a relative timer with the timing duration greater than MAX _ TMCB _ NUM TICKs form a long relative timer queue TiCAlrray [ MAX _ TMCB _ NUM ], and the long relative timer queue manages the relative timers with the timing duration greater than MAX _ TMCB _ NUM TICKs; the array length of the long relative timer queue is MAX _ TMCB _ NUM, and MAX _ TMCB _ NUM is the maximum timer number allowed to be set by the relative timer management module; each element in the long-duration relative timer queue indicates whether a TMCB having the same index number is set.
For the management of the absolute timer, the timing precision set by the absolute timer management module is in the second level, and the management method of the absolute timer management module comprises the following steps:
step 301: the absolute timer management module makes the absolute timer form the absolute timer queue according to the length of the set time, namely, the absolute timer which arrives earliest is arranged at the head of the absolute timer queue, and the absolute timer which arrives latest is arranged at the tail of the absolute timer queue;
step 302: the timer scanning task scans the absolute timer arranged at the head of the absolute timer queue in a scanning period;
step 303: the timer scanning task judges whether the absolute timer arranged at the head of the absolute timer queue expires, if not, the timer scanning task continues to scan the absolute timer in the next scanning period; if yes, go to step 304;
step 304: the timer scanning task removes the absolute timer from the head of the absolute timer queue and sends an overtime message to the task which sets the absolute timer; then step 305 is executed;
step 305: the timer scanning task scans the absolute timer arranged at the head of the absolute timer queue at the moment in the next scanning period;
step 306: and repeating the steps 303 to 305 until the absolute timer arranged at the head of the absolute timer queue does not expire or the absolute timer queue is empty.
FIG. 2 is a schematic diagram of a TICK queue composed of 2000 array elements, a system cursor represents a current system time, and the value range of the system cursor is 0-1999. The management of the relative timers according to the invention is described below with reference to fig. 1 and 2.
For the relative timer with the timing duration less than or equal to 2000 TICKs, the relative timer queue with the short duration comprises the following steps:
step 501: the relative timer management module sets a system cursor, wherein the system cursor represents the current system time, and the value range of the system cursor is 0-1999;
step 502: said relative timer management module converting the timing duration of each of said relative timers having said timing duration less than or equal to 2000 TICKs to a TICK-unit offset with respect to said system cursor;
step 503: the relative timer management module combines all the relative timers with the same offset position as the system cursor into a relative timer queue with a short duration and hangs them down to an element in the TICK queue.
The method for managing the relative timer with the timing duration less than or equal to 2000 TICKs by the relative timer management module comprises the following steps:
step 504: the timer scanning task scans the relative timer in a scanning period, and the system vernier is increased by 1; the lifetimes of all the relative timers in the relative timer queue, which indicates the short duration in which the relative timer resides, are reduced by one TICK;
step 505: the timer scanning task judges whether the system cursor is overlapped with the relative timer, if not, the timer scanning task continues to scan the relative timer in the next scanning period, and the system cursor is increased by 1; otherwise, go to step 506;
step 506: and the timer scanning task removes the relative timer queue with the short time length where the relative timer is positioned from the TICK queue, and sends an overtime message to the task which sets the relative timer.
For example: a relative timer is set with a timing duration of 800 TICKs, and the offset of the relative timer relative to the system cursor is 800. In each scanning period, the system cursor is increased by 1, and the system cursor is just coincided with the relative timer after the timer scanning task scans for 800 times, namely the service life of the relative timer with the timing duration of 800 TICKs is ended.
For a relative timer with a timing duration greater than 2000 TICKs, the method for managing the relative timer with one timing duration greater than 2000 TICKs in the long-duration relative timer queue TidArray [2000] by the relative timer management module comprises the following steps:
step 601: the relative timer management module sets a system cursor; the system vernier represents the current system time, and the value range of the system vernier is 0-1999;
step 602: the relative timer management module gives a compensation value to the relative timer, and the final timing duration of the relative timer is the sum of the compensation value and the TICK number of the timing duration of the relative timer to be set, that is, the final timing duration of the relative timer is equal to the compensation value plus the TICK number of the timing duration of the relative timer to be set;
step 603: the timer scanning task scans the relative timer in a scanning period, and the system vernier is increased by 1;
step 604: subtracting the time length of 2000 TICKs from the final timing time length of the corresponding relative timer at the position of the system cursor by the timer scanning task; since the time taken for the system cursor to return to the original position after one rotation from the initial position is exactly 2000 TICKs, the timer scanning task in step 604 can assume that the corresponding relative timer at the position of the system cursor has elapsed 2000 TICKs;
step 605: the relative timer management module determines whether the reduced timing duration of the relative timer in the step 604 is less than or equal to 2000 TICKs, if yes, execute the step 606; otherwise, go to step 607;
step 606: the relative timer management module fetches the relative timer of step 604 from the long relative timer queue TidArray [2000] and then places it at the tail of the short relative timer queue pending one of the elements in the TICK queue;
step 607: step 603 to step 605 are repeatedly executed.
In step 602, the method for calculating the offset value by the relative timer management module includes:
step 611: the relative timer management module determines whether the index number (tid) of the TMCB used by the relative timer is greater than the current position value of the system cursor, if yes, step 612 is executed; otherwise, go to step 613;
step 612: the offset value is 2000- (index (tid) of TMCB used relative to timer-current position value of system cursor);
step 613: compensation value-the current position value of the system cursor-the index (tid) of TMCB used relative to the timer.
For example, assuming that the current position value of the system cursor is 1500, the number of TICKs of the timing duration of the relative timer to be set is 3000, and the index number (tid) of the TMCB used by the relative timer is 1000, the compensation value given to the relative timer by the relative timer management module is: 1500-: 500+3000 ═ 3500. The timer scanning process comprises the following steps: the system cursor needs to move to the position of the relative timer after 1500 TICK duration, namely to TidArray [1000 ]; at this time, the timer scanning task subtracts 2000 TICKs from the final timing duration of the relative timer, and 1500 TICKs remain; since the remaining timing duration of the relative timer is less than 2000 TICKs, the relative timer management module takes the relative timer TidArray [1000] out of the long relative timer queue TidArray [2000] and then places it at the tail of the short relative timer queue hanging under one of the elements in the TICK queue.
The foregoing detailed description illustrates the principles of the present invention, but this is merely an example of an embodiment for the convenience of understanding and is not to be taken as a limitation on the scope of the invention. Also, various possible equivalent changes or substitutions may be made in accordance with the technical solution of the present invention and the description of the preferred embodiment thereof, and all such changes or substitutions shall fall within the scope of the claims of the present invention.