Timer merging suppression method and device for Linux operating system
By grouping timers and setting group identification and group callback policies in the Linux operating system, the resource waste and process scheduling impacts caused by a large amount of timeout are solved, and more efficient resource utilization and exception response are achieved.
Patent Information
- Application Number
- CN202510838230.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-23
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2045-06-23
AI Technical Summary
In Linux operating systems, when a large number of timers expire, the existing technology leads to waste of resources and process scheduling, and the module's separate statistics on abnormal situations are not accurate enough.
Group timers and set group identification and group callback policies. The timeout timer is handled uniformly through group callback functions, reducing separate calls, and realizing the merge and suppression of timer groups.
Save system resources, improve the response speed of abnormal situations, accurately judge the status, reduce the number of callback calls, and adapt to different business types and scenarios.
Smart Images

Figure CN120353559A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of operating systems, and in particular relates to a method and device for suppressing timer merging in a Linux operating system. Background Art
[0002] Timers are an important function of the Linux operating system. When using a timer, the expiration time interval of the timer and the callback function to be executed after expiration can be specified. When the Linux operating system detects that a timer has timed out, its callback function is immediately called.
[0003] When the number of timers in the Linux operating system is small, or a large number of timers are cancelled before timing out, the overall burden on the Linux operating system is relatively light; when a large number of timers in the Linux operating system time out, since each timer needs to call its callback function separately for processing, and the timers in the kernel are triggered by interrupts, it will affect the normal scheduling and operation of other processes in the Linux operating system.
[0004] In practical applications, some timers serve the same function, and in the case of frequent timer timeouts, their timer callback functions need to process the same event a large number of times in a short period, which is not necessary. In order to improve efficiency and save system resources, a large number of applications will merge and process similar messages. For example, multiple modules in the kernel need to communicate with a certain server, and timers are started to monitor the timeout of the server response message. When a large number of such timers time out in a short period, it is very likely that the server has failed. At this time, if the existing processing method is still followed, and the timeout callbacks of the timers are performed one by one, it will not only slow down the responses of multiple modules, but also the inefficient processing method will cause waste of resources in the Linux operating system and affect other processes.
[0005] The common current solution for such a situation is to separately add statistics and special processing for such events in a certain module or a certain application. Since there are multiple modules, if all modules separately perform statistics and special processing on the timer callbacks, it will cause serious waste of system resources. In addition, when some modules perform statistics separately, since they only count the execution of the callback functions of their own modules, it is possible that no abnormality is found when the modules are counted separately, but when the timer callbacks of these modules are counted overall, an abnormality can be found. At this time, this processing method cannot handle abnormal situations in a better way. Summary of the Invention
[0006] The present invention provides a method and device for suppressing timer merging in a Linux operating system to solve the above technical problem of waste of resources in the Linux operating system.
[0007] A method for suppressing timer merging in a Linux operating system is proposed in the first aspect of the present invention. The method includes: Set a number of timer groups, and assign a group identifier, configure a group callback policy and a group callback function for each timer group. Each timer group includes a number of timers; the timer groups are specified by the user; When a new timer is created in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer. Specifically, when it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for the timer; when it belongs to an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for the independent timer; When there is a situation where a timer times out in the Linux operating system: Obtain the group identifier of the timed-out timer; specifically: When the group identifier is zero, call the callback function of the timed-out timer itself; When the group identifier is not zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to the timed-out timer, call the group callback function of the timer group when the group callback timing specified by the group callback policy is reached; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timed-out timer, call the callback function of the timed-out timer itself when the callback timing of the timed-out timer is reached; Among them, the suppressed state refers to the state in which the callback function of the timer group reaches the threshold of the timer group due to the timeout condition, resulting in the timer group using the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, the timer group includes a number of timers.
[0008] Preferably, when assigning a group identifier, configuring a group callback policy and a group callback function for each timer group, the group callback policy includes: The first group callback policy: use the moment when the timeout frequency of the timer group reaches or exceeds a preset threshold as the group callback timing; The second group callback policy: set the minimum trigger interval as T1, the maximum trigger interval as T2, the exponential growth period as T3, the fallback period as T4, initialize the trigger count num as 0, and initialize the trigger interval time as 0; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is greater than the fallback period T4, the timer group is in a non-suppressed state; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is less than T1, the value of the trigger count num is incremented by 1. The timing of incrementing the value of the trigger count num is used as the group callback timing, and the timer group is in a suppressed state; If 2 num-1 ×T3 is less than or equal to T2, the duration of the continuous suppression state of the timer group is 2 num-1 ×T3; otherwise, the duration of the continuous suppression state of the timer group is T2.
[0009] Preferably, when a new timer is created in the Linux operating system, it is determined whether the timer belongs to a timer group or is an independent timer. When it belongs to a timer group, the group identifier of the corresponding timer group is configured for it, and its own callback timing and callback function are configured for the timer; When it is an independent timer, its group identifier is set to zero, and its own callback timing and callback function are configured for the independent timer, including: When a new timer is created in the Linux operating system, it is determined whether the timer belongs to a timer group or is an independent timer; When the timer belongs to a timer group, based on the expiration time of the timer and the timer group to which it belongs, it is determined whether the timer group is in a suppressed state at the expiration time of the timer. If it is in a non-suppressed state, the timer is added to the timer group, and its own callback timing and callback function are configured for the timer; If it is in a suppressed state, the timer is not added to the timer group, and an error value is returned to the Linux operating system; When the timer is an independent timer, its group identifier is set to zero, and its own callback timing and callback function are configured for the independent timer.
[0010] Preferably, when there is a situation of timer timeout in the Linux operating system, the group identifier of the timeout timer is obtained; When the group identifier is zero, the callback function of the timeout timer itself is called; When the group identifier is not zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to the timeout timer, when the group callback timing specified by the group callback policy is reached, the group callback function of the timer group is called; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timeout timer, when the callback timing of the timeout timer itself is reached, the callback function of the timeout timer itself is called, including: When there is a situation of timer timeout in the Linux operating system, the group identifier of the timeout timer is obtained; When the group identifier is zero, the callback function of the timeout timer itself is called; When the group identifier is not zero and the timer group is in a non-suppressed state, the callback function of the timeout timer itself is called; When the group identifier is not zero and the corresponding timer group is switched from a non-suppressed state to a suppressed state due to the timeout timer, at the group callback timing specified by the group callback policy, determine the suppression duration of the timer group; check the timers belonging to the timer group. If the timeout time of a timer is within the suppression duration period of the timer group, store the timer in the suppressed timer data structure of the timer group and delete the timer from the system timer; call the group callback function of the timer group; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timeout timer, at the callback timing of the timeout timer itself, call the callback function of the timeout timer itself.
[0011] Preferably, the timer merging and suppression method of the Linux operating system further includes: When deleting a timer, obtain the group identifier of the timer to be deleted; When the group identifier is zero, delete the timer to be deleted from the system timer; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a suppressed state, delete the timer to be deleted from the suppressed timer data structure of the timer group; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a non-suppressed state, delete the timer to be deleted from the system timer.
[0012] A second aspect of the present invention proposes a timer merging and suppression device for a Linux operating system, and the device includes: The device includes: An initialization module, configured to: set a number of timer groups, and assign a group identifier, configure a group callback policy and a group callback function for each timer group, and each timer group includes a number of timers; the timer groups are specified by the user; A timer configuration module, configured to: When a new timer is created in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer, where: when it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure the callback timing and callback function of the timer itself; when it belongs to an independent timer, set its group identifier to zero, and configure the callback timing and callback function of the independent timer itself; When there is a situation where a timer in the Linux operating system times out: Obtain the group identifier of the timeout timer; where: When the group identifier is zero, call the callback function of the timeout timer itself; When the group identifier is not zero and due to the timeout timer, the corresponding timer group switches from the non-suppressed state to the suppressed state, at the group callback timing specified by the group callback policy, call the group callback function of the timer group; When the group identifier is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, at the callback timing of the timeout timer itself, call the callback function of the timeout timer itself; Among them, the suppressed state means that due to the timeout condition of the callback function of the timer group reaching the threshold of the timer group, the timer group uses the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, the timer group includes several timers.
[0013] The third aspect of the present invention provides an electronic device, the electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; where, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described above.
[0014] The fourth aspect of the present invention provides a non-transitory computer-readable storage medium storing computer instructions, and the computer instructions are used to cause the computer to execute the method as described above.
[0015] The present invention has the following technical effects: (1) The present invention provides a merging and suppression scheme for timers, which converges the timeout data of multiple timers. Compared with separate statistics for each module or application, it can more accurately judge and maintain the state and better save system resources.
[0016] (2) When the timer group switches to the suppressed state, the present invention uniformly calls the group callback function, reducing the number of callback calls and saving system resources.
[0017] (3) The state transition of the timer group triggered by the timeout of one or more timers in the present invention can be quickly propagated to other timer adders, which improves the response speed to abnormal situations compared with the individual detection and statistics of each module. When the timer group is in the suppression state, newly added timers may immediately determine that they are still in the suppression state when they time out, which enables the caller to handle abnormal situations in advance. The callback strategy of the timer group belongs to an independent unit and can be implemented for different service types and scenarios through various callback strategies. Description of the Drawings
[0018] Figure 1 It is a schematic flowchart of the timer merging and suppression method for the Linux operating system of the present invention; Figure 2 It is a schematic structural diagram of the timer merging and suppression device for the Linux operating system of the present invention. Specific Embodiments
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without creative efforts shall fall within the scope of protection of the present disclosure.
[0020] As Figure 1 shown, the present invention provides a timer merging and suppression method for the Linux operating system, and the method includes: Set a number of timer groups, and assign a group identifier, configure a group callback strategy and a group callback function for each timer group. Each timer group includes a number of timers; the timer groups are specified by the user; When a new timer is created in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer. Specifically: when it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for the timer; when it is an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for the independent timer; When there is a situation where a timer times out in the Linux operating system: Obtain the group identifier of the timeout timer. Specifically: When the group identifier is zero, call the callback function of the timeout timer itself; When the group identifier is non-zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to a timeout timer, when the group callback timing specified by the group callback policy is reached, the group callback function of the timer group is called; When the group identifier is non-zero and the corresponding timer group is not in a suppressed state due to a timeout timer, when the callback timing of the timeout timer itself is reached, the callback function of the timeout timer itself is called; Among them, the suppressed state means that due to the timeout condition of the callback function of the timer group reaching the threshold of the timer group, the timer group uses the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, the timer group includes several timers.
[0021] The timer group is configured by the user and uniquely determined by the group identifier. For timers belonging to the same timer group, their timeout states affect each other, that is, the timeout states of some of the timers affect the timeout of other timers.
[0022] The callback function of the timer group is different from the callback function of the timer itself. The difference is that the callback function of the timer group acts on all timers belonging to the timer group; while the callback function of a single timer only acts on the timer itself. For an ordinary timer, when adding, it is necessary to specify the callback function of the timer, the callback function parameters, and the timeout duration; the timer group includes an executed callback function, and the parameters of its callback function when called are the timer group identifier (determined when creating the timer group) and the current processing timeout time period (that is, the time range of the timeout timers to be processed by this call to the group callback function), and there is no timeout duration, and its callback timing and timeout time period are dynamically determined by the callback policy of the timer group and the timeout situation of the timers within the timer group.
[0023] Assigning a group identifier to each timer group, configuring the group callback policy and the group callback function, among which, the group callback policy includes: The first group callback policy: taking the moment when the timeout frequency of the timer group reaches or exceeds the preset threshold as the group callback timing; The second group callback policy: setting the minimum trigger interval as T1, the maximum trigger interval as T2, the exponential growth period as T3, the fallback period as T4, initializing the trigger count num as 0, and initializing the trigger interval time as 0; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is greater than the fallback period T4, the timer group is in a non-suppressed state; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is less than T1, the value of the trigger count num is incremented by 1. The moment when the value of the trigger count num is incremented by 1 is used as the group callback moment, and the timer group is in the suppressed state; if 2 num-1 ×T3 is less than or equal to T2, the duration of the continuous suppression state of the timer group is 2 num-1 ×T3; otherwise, the duration of the continuous suppression state of the timer group is T2.
[0024] For the first group of callback strategies, for example, when the number of callbacks reaches 20 times within every 50 milliseconds, the timeout frequency of the timer group exceeds the preset threshold. The moment when the number of callbacks reaches 20 times is used as the group callback moment. The timer group enters the suppressed state and calls the group callback function.
[0025] For the second group of callback strategies, for example, the minimum trigger interval is 10 milliseconds, the maximum trigger interval is 1000 milliseconds, the exponential growth period is 10 milliseconds, and the fallback period is 100 milliseconds. When triggered for the first time in the initial state, the timer group enters the suppressed state, and the duration of the suppressed state is 10 milliseconds. If there is another trigger within the minimum trigger interval of 10 milliseconds, the duration of the suppressed state is 20 milliseconds; if there is another trigger within the minimum trigger interval of 10 milliseconds, the duration of the suppressed state is 40 milliseconds, until it reaches the maximum value of 1000 milliseconds. When no timer is triggered within the fallback period of 100 milliseconds, the group timer resumes the non-suppressed state.
[0026] When the group timer does not conform to either the first group of callback strategies or the second group of callback strategies, the timer group is in the non-suppressed state. When reaching the callback moment of a certain timer itself, the callback function of that timer itself is called.
[0027] When creating a new timer in the Linux operating system, it is determined whether the timer belongs to a timer group or is an independent timer. When it belongs to a timer group, the group identifier of the corresponding timer group is configured for it, and the callback moment and callback function of its own are configured for this timer; when it is an independent timer, its group identifier is set to zero, and the callback moment and callback function of its own are configured for this independent timer, including: When creating a new timer in the Linux operating system, it is determined whether the timer belongs to a timer group or is an independent timer; When the timer belongs to a timer group, based on the expiration time of the timer and the timer group to which it belongs, it is determined whether the timer group is in the suppressed state at the expiration time of this timer. If it is in the non-suppressed state, this timer is added to the timer group, and the callback moment and callback function of its own are configured for this timer; if it is in the suppressed state, this timer is not added to the timer group, and an error value is returned to the Linux operating system; When the timer is an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for this independent timer.
[0028] When there is a situation where a timer times out in the Linux operating system, obtain the group identifier of the timed-out timer; when the group identifier is zero, call the callback function of the timed-out timer itself; when the group identifier is not zero and the timer group corresponding to the timed-out timer switches from a non-suppressed state to a suppressed state due to the timed-out timer, when the group callback timing specified by the group callback policy is reached, call the group callback function of the timer group; when the group identifier is not zero and the timer group corresponding to the timed-out timer is not in a suppressed state, when the callback timing of the timed-out timer itself is reached, call the callback function of the timed-out timer itself, including: When there is a situation where a timer times out in the Linux operating system, obtain the group identifier of the timed-out timer; When the group identifier is zero, call the callback function of the timed-out timer itself; When the group identifier is not zero and the timer group is in a non-suppressed state, call the callback function of the timed-out timer itself; When the group identifier is not zero and the timer group corresponding to the timed-out timer switches from a non-suppressed state to a suppressed state due to the timed-out timer, when the group callback timing specified by the group callback policy is reached, determine the suppression duration of the timer group; check the timers belonging to the timer group, if the timeout time of the timer is within the suppression duration period of the timer group, store the timer in the suppressed timer data structure of the timer group, and delete the timer from the system timer; call the group callback function of the timer group; When the group identifier is not zero and the timer group corresponding to the timed-out timer is not in a suppressed state due to the timed-out timer, when the callback timing of the timed-out timer itself is reached, call the callback function of the timed-out timer itself.
[0029] Further, the timer merging and suppression method of the Linux operating system further includes: When deleting a timer, obtain the group identifier of the timer to be deleted; When the group identifier is zero, delete the timer to be deleted from the system timer; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a suppressed state, delete the timer to be deleted from the suppressed timer data structure of the timer group; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a non-suppressed state, delete the timer to be deleted from the system timer.
[0030] The following describes the device for implementing the present invention. For the specific implementation process and technical effects, please refer to the above, and will not be elaborated below.
[0031] Optionally, as Figure 2 shown, the present invention provides a timer merging suppression device for a Linux operating system, and the device 200 includes: Initialization module 201: configured to: set a plurality of timer groups, and assign a group identifier, configure a group callback policy and a group callback function for each timer group, and each timer group includes a plurality of timers; the timer groups are specified by a user; Timer configuration module 202: configured to: When a new timer is created in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer, where: when belonging to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for the timer; when belonging to an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for the independent timer; When there is a situation where a timer in the Linux operating system times out: Obtain the group identifier of the timeout timer; where: When the group identifier is zero, call the callback function of the timeout timer itself; When the group identifier is not zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to the timeout timer, when the group callback timing specified by the group callback policy is reached, call the group callback function of the timer group; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timeout timer, when the callback timing of the timeout timer itself is reached, call the callback function of the timeout timer itself; Wherein, the suppressed state refers to a state in which the callback function timeout condition of the timer group reaches the threshold of the timer group, resulting in the timer group using the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, the timer group includes a plurality of timers.
[0032] The above modules may be one or more integrated circuits configured to implement the above methods. For example: one or more Application Specific Integrated Circuits (ASICs), or one or more digital signal processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of processing element scheduler code, the processing element may be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Again, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0033] The above modules may be connected or communicate with each other via a wired connection or a wireless connection. The wired connection may include metal wires, optical fibers, hybrid wires, etc., or any combination thereof. The wireless connection may include connections in the form of LAN, WAN, Bluetooth, ZigBee, or NFC, etc., or any combination thereof. Two or more modules may be combined into a single module, and any one module may be divided into two or more units. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described systems and devices may refer to the corresponding processes in the method embodiments, and will not be elaborated in the present invention.
[0034] It should be noted that the above modules may be one or more integrated circuits configured to implement the above methods. For example: one or more Application Specific Integrated Circuits (ASICs), or one or more Digital Singnal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of processing element scheduler code, the processing element may be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Again, these modules may be integrated together and implemented in the form of a System-on-a-chip (SOC).
[0035] The electronic device includes a processor, a memory, a communication interface, a display screen, and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner. The wireless manner can be implemented through WIFI, a carrier network, near field communication (NFC), or other technologies. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen. The input device of the electronic device can be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the electronic device, or an external keyboard, touchpad, or mouse, etc.
[0036] The present invention also provides a program product, such as a computer-readable storage medium, including a program that is used to execute the above method embodiments when executed by a processor.
[0037] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the devices or units can be in an electrical, mechanical, or other form.
[0038] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0039] In addition, each functional unit in various embodiments of the present invention can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware, or in the form of a combination of hardware and software functional units.
[0040] The integrated unit implemented in the form of software functional units can be stored in a computer-readable storage medium. The above-mentioned software functional units are stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to execute some steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (English: Read-Only Memory, abbreviated as: ROM), random access memories (English: Random Access Memory, abbreviated as: RAM), magnetic disks, or optical discs that can store program codes.
Claims
1. A method for suppressing timer merging in a Linux operating system, characterized in that, The method includes: Set a number of timer groups, and assign a group identifier, configure a group callback policy and a group callback function for each timer group. Each timer group includes a number of timers; the timer groups are specified by the user; When a new timer is created in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer. Specifically, when it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for the timer; when it is an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for the independent timer; When there is a situation where a timer times out in the Linux operating system: Obtain the group identifier of the timeout timer; specifically: When the group identifier is zero, call the callback function of the timeout timer itself; When the group identifier is not zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to the timeout timer, when the group callback timing specified by the group callback policy is reached, call the group callback function of the timer group; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timeout timer, when the callback timing of the timeout timer itself is reached, call the callback function of the timeout timer itself; Among them, the suppressed state refers to the state in which the callback function of the timer group reaches the threshold of the timer group due to the timeout condition, resulting in the timer group using the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, the timer group includes a number of timers.
2. The method according to claim 1, wherein Assigning a group identifier, configuring a group callback policy and a group callback function for each timer group, where the group callback policy includes: The first group callback policy: regard the moment when the timeout frequency of the timer group reaches or exceeds a preset threshold as the group callback timing; The second group callback policy: set the minimum trigger interval to T1, the maximum trigger interval to T2, the exponential growth period to T3, the fallback period to T4, initialize the trigger count num to 0, and initialize the trigger interval time to 0; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is greater than the fallback period T4, the timer group is in a non-suppressed state; When the timer group is triggered by the timeout event of a timer belonging to the timer group, and the time interval between this trigger and the last trigger is less than T1, the value of the trigger count num is incremented by 1. The timing of incrementing the value of the trigger count num is used as the group callback timing, and the timer group is in a suppressed state; if 2 num-1 ×T3 is less than or equal to T2, the duration of the suppressed state of the timer group is 2 num-1 ×T3; otherwise, the duration of the suppressed state of the timer group is T2.
3. The method according to claim 1, characterized in that When a new timer is created in the Linux operating system, determine whether the timer belongs to a timer group or is an independent timer. When it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for the timer; When it is an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for the independent timer, including: When a new timer is created in the Linux operating system, determine whether the timer belongs to a timer group or is an independent timer; When the timer belongs to a timer group, determine whether the timer group is in a suppressed state at the expiration time of the timer based on the expiration time of the timer and the timer group to which it belongs. If it is in a non-suppressed state, add the timer to the timer group, and configure the callback timing and callback function of the timer itself; if it is in a suppressed state, do not add the timer to the timer group, and return an error value to the Linux operating system; When the timer is an independent timer, set its group identifier to zero, and configure the callback timing and callback function of the independent timer itself.
4. The method according to claim 3, wherein When there is a situation where a timer in the Linux operating system times out, obtain the group identifier of the timeout timer; when the group identifier is zero, call the callback function of the timeout timer itself; when the group identifier is not zero and the timer group corresponding to the timeout timer switches from a non-suppressed state to a suppressed state, when the group callback timing specified by the group callback policy is reached, call the group callback function of the timer group; when the group identifier is not zero and the timer group corresponding to the timeout timer is not in a suppressed state, when the callback timing of the timeout timer itself is reached, call the callback function of the timeout timer itself, including: When there is a situation where a timer in the Linux operating system times out, obtain the group identifier of the timeout timer; When the group identifier is zero, call the callback function of the timeout timer itself; When the group identifier is not zero and the timer group is in a non-suppressed state, call the callback function of the timeout timer itself; When the group identifier is not zero and the timer group corresponding to the timeout timer switches from a non-suppressed state to a suppressed state, when the group callback timing specified by the group callback policy is reached, determine the duration of the suppressed state of the timer group; check the timers belonging to the timer group. If the timeout time of a timer is within the duration of the suppressed state of the timer group, store the timer in the suppressed timer data structure of the timer group, and delete the timer from the system timer; call the group callback function of the timer group; When the group identifier is not zero and the timer group corresponding to the timeout timer is not in a suppressed state, when the callback timing of the timeout timer itself is reached, call the callback function of the timeout timer itself.
5. The method according to claim 1, wherein The timer merging and suppression method of the Linux operating system further includes: When deleting a timer, obtain the group identifier of the timer to be deleted; When the group identifier is zero, delete the timer to be deleted from the system timer; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a suppressed state, delete the timer to be deleted from the suppressed timer data structure of the timer group; When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in a non-suppressed state, delete the timer to be deleted from the system timer.
6. A timer merging suppression device for a Linux operating system, characterized in that, The device includes: An initialization module, configured to: set a plurality of timer groups, and assign a group identifier, configure a group callback policy and a group callback function for each timer group, and each timer group includes a plurality of timers; the timer groups are specified by the user; A timer configuration module, configured to: When creating a new timer in the Linux operating system: Save the timer to the system timer; Determine whether the timer belongs to a timer group or is an independent timer. Specifically, when it belongs to a timer group, configure the group identifier of the corresponding timer group for it, and configure its own callback timing and callback function for this timer; when it is an independent timer, set its group identifier to zero, and configure its own callback timing and callback function for this independent timer; When there is a situation where a timer times out in the Linux operating system: Obtain the group identifier of the timed-out timer. Specifically: When the group identifier is zero, call the callback function of the timed-out timer itself; When the group identifier is not zero and the corresponding timer group switches from a non-suppressed state to a suppressed state due to the timed-out timer, call the group callback function of this timer group when the group callback timing specified by the group callback policy is reached; When the group identifier is not zero and the corresponding timer group is not in a suppressed state due to the timed-out timer, call the callback function of the timed-out timer itself when the callback timing of this timed-out timer is reached; Among them, the suppressed state refers to the state where, due to the callback function of the timer group reaching the threshold of the timer group, the timer group uses the group callback mechanism instead of the callback mechanism of a single timer within the timer group for processing; The group identifier of each timer group is non-zero, that is, the group identifier is a non-zero integer, indicating that the timer group is a valid timer group, that is, this timer group includes several timers.
7. An electronic device, characterized in that, The device includes: At least one processor; and A memory communicatively connected to the at least one processor; among them, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1-5.
8. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-5.
Citation Information
Patent Citations
Scheduling processing method and device based on Linux system
CN112433834A
Timer implementation method and device, equipment and medium
CN114546613A
Energy Efficient Implementation Of Read-Copy Update For Light Workloads Running On Systems With Many Processors
US20140006820A1