A timer merging suppression method and device for Linux operating system
By setting up timer groups and group callback policies in the Linux operating system and merging the processing of similar timer timeout events, the problems of system resource waste and response delay are solved, and more efficient resource utilization and rapid exception response are achieved.
Patent Information
- Application Number
- CN202510838230.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-23
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2045-06-23
AI Technical Summary
In the Linux operating system, when there are a large number of timers or a large number of timers time out, it leads to waste of system resources and delays in scheduling other processes. The existing processing method cannot efficiently handle the merging of similar timers, resulting in waste of system resources and response delays.
By setting up a timer group, configuring the group identifier, group callback policy, and group callback function, the timeout events of the same type of timers are merged and processed. The group callback function is called uniformly to reduce the number of individual calls, thus achieving the suppression state switching and unified processing of the timer group.
It achieves more accurate status judgment and resource conservation, improves the response speed to abnormal situations, and reduces system resource waste and scheduling delays.
Smart Images

Figure CN120353559B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of operating systems, and in particular relates to a timer merging suppression method and device for a Linux operating system. Background Art
[0002] Timers are an important feature of the Linux operating system. When using a timer, you can specify the timer's expiration interval and a callback function to be executed after the expiration. When the Linux operating system detects that a timer has timed out, it immediately calls the callback function.
[0003] When there are not many timers in the Linux operating system, or a large number of timers are canceled 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 actual applications, some timers serve the same function, and when timers frequently time out, their timer callback functions need to process a large number of the same events in a short period of time, which is not necessary. In order to improve efficiency and save system resources, many applications will merge and process similar messages. For example, multiple modules in the kernel need to communicate with a server, and all start timers to monitor the server's response message timeout. When a large number of such timers time out in a short period of time, it is very likely that the server has failed. At this time, if the existing processing method is still used to perform timeout callbacks for timers one by one, it will not only slow down the response of multiple modules, but the inefficient processing method will also cause a waste of Linux operating system resources and affect other processes.
[0005] Currently, a common solution for this situation is to add statistics and special handling for such events within a specific module or application. However, due to the presence of multiple modules, if all modules were to perform separate statistics and special handling for timer callbacks, system resources would be severely wasted. Furthermore, when individual modules perform statistics, only their callback function executions are counted. Consequently, individual module statistics may fail to detect an anomaly, but only when the timer callbacks of all modules are aggregated and counted, an anomaly is discovered. This approach, however, does not provide a more optimal way to handle anomalies. Summary of the Invention
[0006] The present invention proposes a timer merging suppression method and device for a Linux operating system, so as to solve the technical problem of waste of Linux operating system resources.
[0007] A first aspect of the present invention provides a timer merging suppression method for a Linux operating system, the method comprising:
[0008] Set up several timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes several timers; the timer group is specified by the user;
[0009] When creating a new timer in the Linux operating system:
[0010] Save the timer to the system timer;
[0011] Determine whether the timer belongs to a timer group or is an independent timer, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function;
[0012] When a timer times out in the Linux operating system:
[0013] Get the group ID of the timeout timer; where:
[0014] When the group ID is zero, the callback function of the timeout timer itself is called;
[0015] When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached;
[0016] When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached;
[0017] The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group.
[0018] 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.
[0019] Preferably, the method allocates a group identifier to each timer group, configures a group callback policy and a group callback function, wherein the group callback policy includes:
[0020] The first callback strategy: The time when the timer group's timeout frequency reaches or exceeds the preset threshold is used as the group callback timing;
[0021] The second callback strategy: Set the minimum trigger interval to T1, the maximum trigger interval to T2, the exponential growth period to T3, the fallback period to T4, the initial trigger count num to 0, and the initial trigger interval time to 0;
[0022] When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the current triggering and the last triggering is greater than the fallback period T4, the timer group is in the non-suppressed state;
[0023] When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the trigger time and the last trigger time is less than T1, the trigger count num value is increased by 1, and the timing of the trigger count num value increasing by 1 is used as the group callback timing, and the timer group is in the suppressed state; if 2 num-1 × T3 is less than or equal to T2, then the timer group continues to suppress the state for 2 seconds. num-1 × T3; otherwise, the timer group remains in the suppression state for T2.
[0024] Preferably, when a new timer is created in the Linux operating system, determining whether the timer belongs to a timer group or is an independent timer, if the timer belongs to a timer group, configuring the group identifier of the corresponding timer group for the timer, and configuring the timer with its own callback timing and callback function; if the timer is an independent timer, setting its group identifier to zero, and configuring the independent timer with its own callback timing and callback function, includes:
[0025] When creating a new timer in the Linux operating system, determine whether the timer belongs to a timer group or is an independent timer;
[0026] 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.
[0027] 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.
[0028] Preferably, when a timer times out in the Linux operating system, the group identifier of the timer is obtained; when the group identifier is zero, the callback function of the 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, the group callback function of the timer group is called 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 timeout timer, the callback function of the timer itself is called when the callback timing of the timeout timer itself is reached, including:
[0029] When a timer times out in the Linux operating system, obtain the group ID of the timer.
[0030] When the group ID is zero, the callback function of the timeout timer itself is called;
[0031] When the group ID is not zero and the timer group is in the non-suppressed state, the callback function of the timeout timer itself is called;
[0032] When the group identifier is non-zero and the corresponding timer group switches from the unsuppressed state to the suppressed state due to a timeout timer, the suppressed state duration of the timer group is determined when the group callback timing specified by the group callback policy is reached; timers belonging to the timer group are checked, and if the timer's timeout period falls within the suppressed state duration period of the timer group, the timer is stored in the suppressed timer data structure of the timer group and deleted from the system timer; and the group callback function of the timer group is called;
[0033] When the group identifier is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached.
[0034] Preferably, the timer merging suppression method of the Linux operating system further includes:
[0035] When deleting a timer, obtain the group ID of the timer to be deleted;
[0036] When the group ID is zero, the timer to be deleted is deleted from the system timer;
[0037] When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in the suppressed state, the timer to be deleted is deleted from the suppressed timer data structure of the timer group;
[0038] 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, the timer to be deleted is deleted from the system timer.
[0039] A second aspect of the present invention provides a timer merging suppression device for a Linux operating system, the device comprising:
[0040] The device comprises:
[0041] The initialization module is configured to: set up a number of timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes a number of timers; the timer group is specified by the user;
[0042] The timer configuration module is configured as follows:
[0043] When creating a new timer in the Linux operating system:
[0044] Save the timer to the system timer;
[0045] Determine whether the timer belongs to a timer group or is an independent timer, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function;
[0046] When a timer times out in the Linux operating system:
[0047] Get the group ID of the timeout timer; where:
[0048] When the group ID is zero, the callback function of the timeout timer itself is called;
[0049] When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached;
[0050] When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached;
[0051] The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group.
[0052] 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.
[0053] A third aspect of the present invention provides an electronic device, comprising:
[0054] at least one processor; and
[0055] a memory communicatively connected to the at least one processor; wherein,
[0056] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.
[0057] A fourth aspect of the present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method as described above.
[0058] The present invention has the following technical effects:
[0059] (1) The present invention provides a timer merging suppression solution that aggregates the timeout data of multiple timers. Compared with statistics for each module or application separately, it can more accurately judge and maintain the status and better save system resources.
[0060] (2) When the timer group is switched to the suppression state, the present invention uniformly calls the group callback function, thereby reducing the number of callback calls and saving system resources.
[0061] (3) The present invention can quickly propagate the state transition of a timer group triggered by the timeout of one or more timers to other timer adders, thereby improving its response speed to abnormal situations compared to the detection and statistics of each module separately. When the timer group is in the suppressed state, the newly added timer may immediately determine that it is still in the suppressed state when it times out, which allows the caller to handle the abnormal situation in advance. The callback strategy of the timer group is an independent unit, and a variety of callback strategies can be used to achieve universal coverage for different business types and scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 Schematic diagram of the flow of the timer merging and suppression method of the Linux operating system of the present invention;
[0063] Figure 2 The diagram is a structural diagram of a timer merging and suppressing device for a Linux operating system according to the present invention. DETAILED DESCRIPTION
[0064] To make the purpose, technical solutions, and advantages of the embodiments of the present disclosure more clear, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present disclosure.
[0065] like Figure 1 As shown, the present invention provides a timer merging suppression method for a Linux operating system, the method comprising:
[0066] Set up several timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes several timers; the timer group is specified by the user;
[0067] When creating a new timer in the Linux operating system:
[0068] Save the timer to the system timer;
[0069] Determine whether the timer belongs to a timer group or is an independent timer, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function;
[0070] When a timer times out in the Linux operating system:
[0071] Get the group ID of the timeout timer; where:
[0072] When the group ID is zero, the callback function of the timeout timer itself is called;
[0073] When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached;
[0074] When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached;
[0075] The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group.
[0076] 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.
[0077] A timer group is configured by the user and uniquely identified by a group ID. Timers in the same timer group have their expiration states affecting each other, meaning that the expiration state of some timers affects the expiration of other timers.
[0078] The callback function of a timer group differs from the callback function of a timer itself in that the callback function of a timer group applies to all timers belonging to the timer group, while the callback function of a single timer applies only to the timer itself. When adding a regular timer, you need to specify the callback function, callback function parameters, and timeout duration of the timer. A timer group includes an executed callback function, and its parameters when called are the timer group identifier (determined when the timer group is created) and the timeout period for this processing (i.e., the time range of the timeout timers that should be processed by the current call to the group callback function). There is no timeout period, and the callback timing and timeout period are dynamically determined by the callback policy of the timer group and the timeout conditions of the timers within the timer group.
[0079] The method of allocating a group identifier to each timer group, configuring a group callback policy and a group callback function, wherein the group callback policy includes:
[0080] The first callback strategy: The time when the timer group's timeout frequency reaches or exceeds the preset threshold is used as the group callback timing;
[0081] The second callback strategy: Set the minimum trigger interval to T1, the maximum trigger interval to T2, the exponential growth period to T3, the fallback period to T4, the initial trigger count num to 0, and the initial trigger interval time to 0;
[0082] When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the current triggering and the last triggering is greater than the fallback period T4, the timer group is in the non-suppressed state;
[0083] When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the trigger time and the last trigger time is less than T1, the trigger count num value is increased by 1, and the timing of the trigger count num value increasing by 1 is used as the group callback timing, and the timer group is in the suppressed state; if 2 num-1 × T3 is less than or equal to T2, then the timer group continues to suppress the state for 2 seconds. num-1 × T3; otherwise, the timer group remains in the suppression state for T2.
[0084] For the first callback policy, for example, if the number of callbacks reaches 20 within 50 milliseconds, the timer group's timeout frequency exceeds the preset threshold, and the timing when the number of callbacks reaches 20 is used as the group callback timing. The timer group enters the suppressed state, and the group callback function is called.
[0085] For the second callback policy, for example, with a minimum trigger interval of 10 milliseconds, a maximum trigger interval of 1000 milliseconds, an exponential growth period of 10 milliseconds, and a fallback period of 100 milliseconds, the timer group enters the suppressed state for 10 milliseconds when the initial state is triggered for the first time. If another trigger occurs within the minimum trigger interval of 10 milliseconds, the suppressed state lasts for 20 milliseconds. If another trigger occurs within the minimum trigger interval of 10 milliseconds, the suppressed state lasts for 40 milliseconds, and so on until the maximum value of 1000 milliseconds is reached. If no timer triggers within the fallback period of 100 milliseconds, the group timer returns to the unsuppressed state.
[0086] When the group timer does not comply with either the first or second callback policy, the timer group is in a non-inhibited state. When the callback timing of a timer itself is reached, the callback function of the timer itself is called.
[0087] 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. If the timer belongs to a timer group, the group identifier of the corresponding timer group is configured for the timer, and the callback timing and callback function of the timer are configured for the timer; if the timer is an independent timer, the group identifier is set to zero, and the callback timing and callback function of the independent timer are configured for the independent timer, including:
[0088] When creating a new timer in the Linux operating system, determine whether the timer belongs to a timer group or is an independent timer;
[0089] 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.
[0090] 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.
[0091] When a timer times out in the Linux operating system, the group identifier of the timer is obtained; when the group identifier is zero, the callback function of the 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 timer expiration, the group callback function of the timer group is called 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 timer expiration, the callback function of the timer itself is called when the timer expiration timing is reached, including:
[0092] When a timer times out in the Linux operating system, obtain the group ID of the timer.
[0093] When the group ID is zero, the callback function of the timeout timer itself is called;
[0094] When the group ID is not zero and the timer group is in the non-suppressed state, the callback function of the timeout timer itself is called;
[0095] When the group identifier is non-zero and the corresponding timer group switches from the unsuppressed state to the suppressed state due to a timeout timer, the suppressed state duration of the timer group is determined when the group callback timing specified by the group callback policy is reached; timers belonging to the timer group are checked, and if the timer's timeout period falls within the suppressed state duration period of the timer group, the timer is stored in the suppressed timer data structure of the timer group and deleted from the system timer; and the group callback function of the timer group is called;
[0096] When the group identifier is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached.
[0097] Furthermore, the timer merging suppression method of the Linux operating system further includes:
[0098] When deleting a timer, obtain the group ID of the timer to be deleted;
[0099] When the group ID is zero, the timer to be deleted is deleted from the system timer;
[0100] When the group identifier is not zero and the timer group to which the timer to be deleted belongs is in the suppressed state, the timer to be deleted is deleted from the suppressed timer data structure of the timer group;
[0101] 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, the timer to be deleted is deleted from the system timer.
[0102] The following describes the device for implementing the present invention. The specific implementation process and technical effects are described above and will not be repeated below.
[0103] Alternatively, as Figure 2 As shown, the present invention provides a timer merging suppression device for a Linux operating system, the device 200 comprising:
[0104] Initialization module 201: configured to: set up several timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes several timers; the timer group is specified by the user;
[0105] Timer configuration module 202: configured to:
[0106] When creating a new timer in the Linux operating system:
[0107] Save the timer to the system timer;
[0108] Determine whether the timer belongs to a timer group or is an independent timer, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function;
[0109] When a timer times out in the Linux operating system:
[0110] Get the group ID of the timeout timer; where:
[0111] When the group ID is zero, the callback function of the timeout timer itself is called;
[0112] When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached;
[0113] When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached;
[0114] The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group.
[0115] 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.
[0116] The above modules can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more digital singular processors (DSPs), or one or more field programmable gate arrays (FPGAs). For example, when a module is implemented by scheduling program code through a processing element, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0117] The above modules can be connected or communicate with each other via a wired connection or a wireless connection. The wired connection may include a metal cable, an optical cable, a hybrid cable, etc., or any combination thereof. The wireless connection may include a connection in the form of a LAN, a WAN, Bluetooth, ZigBee, or NFC, or any combination thereof. Two or more modules can be combined into a single module, and any module can be divided into two or more units. Those skilled in the art will clearly understand that for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in the present invention.
[0118] It should be noted that the above modules can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs). For example, when a module is implemented by scheduling program code through a processing element, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0119] An electronic device includes a processor, memory, a communication interface, a display, and an input device connected via a system bus. The processor of the electronic device provides computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal via wired or wireless communication, where wireless communication can be achieved via Wi-Fi, a carrier network, near-field communication (NFC), or other technologies. The display of the electronic device can be a liquid crystal display or an electronic ink display. The input device of the electronic device can be a touchscreen covering the display, buttons, a trackball, or a touchpad provided on the electronic device housing, or an external keyboard, touchpad, or mouse.
[0120] The present invention also provides a program product, such as a computer-readable storage medium, comprising a program, which is used to perform the above method embodiments when executed by a processor.
[0121] In the 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 merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0122] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0123] In addition, the functional units in various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or hardware plus software functional units.
[0124] The aforementioned integrated unit implemented as a software functional unit can be stored in a computer-readable storage medium. The software functional unit, stored in a storage medium, includes instructions for causing a computer device (which may be a personal computer, server, or network device, etc.) or a processor to execute portions of the method steps described in various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a removable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
Claims
1. A timer merging suppression method for a Linux operating system, characterized in that: The method comprises: Set up several timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes several timers; the timer group is specified by the user; 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, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function; When a timer times out in the Linux operating system: Get the group ID of the timeout timer; where: When the group ID is zero, the callback function of the timeout timer itself is called; When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached; When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached; The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group. 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; The method of allocating a group identifier to each timer group, configuring a group callback policy and a group callback function, wherein the group callback policy includes: The first callback strategy: The time when the timer group's timeout frequency reaches or exceeds the preset threshold is used as the group callback timing; The second callback strategy: Set the minimum trigger interval to T1, the maximum trigger interval to T2, the exponential growth period to T3, the fallback period to T4, the initial trigger count num to 0, and the initial trigger interval time to 0; When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the current triggering and the last triggering is greater than the fallback period T4, the timer group is in the non-suppressed state; When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the trigger time and the last trigger time is less than T1, the trigger count num value is increased by 1, and the timing of the trigger count num value increasing by 1 is used as the group callback timing, and the timer group is in the suppressed state; if 2 num-1 × T3 is less than or equal to T2, then the timer group continues to suppress the state for 2 seconds. num-1 × T3; otherwise, the timer group remains in the suppression state for T2.
2. The method according to claim 1, wherein 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. If the timer belongs to a timer group, the group identifier of the corresponding timer group is configured for the timer, and the callback timing and callback function of the timer are configured for the timer; For an independent timer, set its group ID to zero and configure its own callback timing and callback function for the independent timer, including: When creating a new timer 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, 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.
3. The method according to claim 2, wherein When a timer times out in the Linux operating system, the group identifier of the timer is obtained; when the group identifier is zero, the callback function of the 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 timer expiration, the group callback function of the timer group is called 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 timer expiration, the callback function of the timer itself is called when the timer expiration timing is reached, including: When a timer times out in the Linux operating system, obtain the group ID of the timer. When the group ID is zero, the callback function of the timeout timer itself is called; When the group ID is not zero and the timer group is in the non-suppressed state, the callback function of the timeout timer itself is called; When the group ID is non-zero and the corresponding timer group switches from the unsuppressed state to the suppressed state due to a timeout timer, the suppressed state duration of the timer group is determined when the group callback timing specified by the group callback policy is reached; timers belonging to the timer group are checked, and if the timer's timeout period falls within the suppressed state duration period of the timer group, the timer is stored in the suppressed timer data structure of the timer group and deleted from the system timer; and 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 the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached.
4. 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 ID of the timer to be deleted; When the group ID is zero, the timer to be deleted is 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 the suppressed state, the timer to be deleted is 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, the timer to be deleted is deleted from the system timer.
5. A timer merging suppression device for a Linux operating system, characterized in that: The device comprises: The initialization module is configured to: set up a number of timer groups, assign a group identifier to each timer group, configure a group callback policy and a group callback function, each timer group includes a number of timers; the timer group is specified by the user; The timer configuration module is configured as follows: 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, wherein: if the timer belongs to a timer group, configure the corresponding timer group group identifier for the timer, and configure the timer with its own callback timing and callback function; if the timer belongs to an independent timer, set its group identifier to zero, and configure the independent timer with its own callback timing and callback function; When a timer times out in the Linux operating system: Get the group ID of the timeout timer; where: When the group ID is zero, the callback function of the timeout timer itself is called; When the group ID is not zero and the corresponding timer group switches from the non-suppressed state to the suppressed state due to a timeout, the group callback function of the timer group is called when the group callback timing specified by the group callback policy is reached; When the group ID is not zero and the corresponding timer group is not in the suppressed state due to the timeout timer, the callback function of the timeout timer itself is called when the callback timing of the timeout timer itself is reached; The suppressed state refers to a state in which the timer group uses the group callback mechanism instead of the callback mechanism of a single timer in the timer group to process the time because the timeout condition of the callback function of the timer group reaches the threshold of the timer group. 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; The method of allocating a group identifier to each timer group, configuring a group callback policy and a group callback function, wherein the group callback policy includes: The first callback strategy: The time when the timer group's timeout frequency reaches or exceeds the preset threshold is used as the group callback timing; The second callback strategy: Set the minimum trigger interval to T1, the maximum trigger interval to T2, the exponential growth period to T3, the fallback period to T4, the initial trigger count num to 0, and the initial trigger interval time to 0; When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the current triggering and the last triggering is greater than the fallback period T4, the timer group is in the non-suppressed state; When a timer group is triggered by a timeout event of a timer belonging to the timer group, and the time interval between the trigger time and the last trigger time is less than T1, the trigger count num value is increased by 1, and the timing of the trigger count num value increasing by 1 is used as the group callback timing, and the timer group is in the suppressed state; if 2 num-1 × T3 is less than or equal to T2, then the timer group continues to suppress the state for 2 seconds. num-1 × T3; otherwise, the timer group remains in the suppression state for T2.
6. An electronic device, characterized in that: The device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 4.
7. 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 to 4.
Citation Information
Patent Citations
Scheduling processing method and device based on Linux system
CN112433834A
Timer implementation method and device, equipment and medium
CN114546613A