Real-time abnormal monitoring local automatic recovery method and device
By constructing a baseline model and real-time monitoring of RTOS interrupt service routines, the problem of lack of continuous monitoring and analysis of ISR execution behavior in RTOS is solved, enabling early identification and graded recovery of ISR anomalies, and improving the reliability and real-time performance of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU JINQILI INFORMATION TECH CO LTD
- Filing Date
- 2026-03-30
- Publication Date
- 2026-05-05
AI Technical Summary
Existing real-time operating systems (RTOS) lack continuous monitoring and analysis of interrupt service routine (ISR) execution behavior, making it difficult to identify and handle ordinary interrupt exceptions, resulting in a decline in system real-time performance and stability. Furthermore, the lack of a unified monitoring and analysis framework makes it impossible to perform local automatic recovery.
Construct a baseline model of the interrupt service routine's runtime behavior, inject lightweight monitoring logic at the interrupt entry and exit points, collect and compare statistical features in real time, determine abnormal states based on the comparison results and preset judgment rules, and trigger corresponding local automatic recovery actions, such as resetting peripherals, clearing buffers, or restarting threads, to avoid a system-wide restart.
It enables the identification of ISR anomalies before processor hardware failures occur, reduces the overall system restart probability through tiered recovery actions, improves system reliability and real-time performance, and avoids unnecessary resets during system-level recovery.
Smart Images

Figure CN121979644A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication anomaly handling technology, specifically to a method and apparatus for real-time anomaly monitoring and local automatic recovery. Background Technology
[0002] In real-time operating systems (RTOS), interrupt and exception management typically includes functions such as registering and unloading interrupt service routines, enabling and disabling interrupts, and installing exception handlers to ensure that the system can enter a predefined processing flow in abnormal situations. However, existing technologies still have the following shortcomings in interrupt and exception management: 1. Lack of continuous monitoring capabilities for ordinary interrupt behavior. In existing RTOSs, Interrupt Service Routines (ISRs) are typically considered normal operating paths, and their execution behavior is assumed to be "correct and controllable." During operation, the system generally does not continuously monitor or statistically analyze the execution time, trigger frequency, nesting depth, and execution jitter of ISRs. Therefore, when ISRs exhibit abnormally prolonged execution time, abnormally increased trigger frequency, or abnormal nesting, the system struggles to detect these issues in a timely manner, often only discovering them after task scheduling has been severely disrupted or the system has crashed. 2. Anomaly detection mechanisms rely on processor exception interrupts as triggering conditions, representing reactive processing. Existing anomaly handling mechanisms primarily depend on processor-provided exception interrupts (such as illegal instructions, illegal memory access, or bus errors). These anomalies are only triggered after the system has entered a serious error state, a typical reactive approach. Existing technologies struggle to promptly identify and handle ordinary interrupt anomalies that have not yet triggered processor exceptions but have already impacted system real-time performance and stability. 3. Lack of a unified monitoring and analysis framework covering ordinary interrupts and anomalies. Existing RTOS typically manages normal interrupts and exception handling as two independent mechanisms: normal interrupts are only responsible for event response, and exception interrupts are only responsible for error handling, lacking a unified monitoring and analysis framework. This fragmented design makes it impossible for the system to uniformly model, classify, and locate interrupt behavior, and also makes it impossible to analyze the impact of interrupts and exceptions on task scheduling and system state from a system-wide perspective. 4. Exception handling is coarse-grained and lacks local automatic recovery capabilities. In existing technologies, when the system detects an exception, it usually prints exception information and performs a system reset or shutdown, resulting in data loss. For multi-tasking real-time systems, existing technologies struggle to perform local repairs on abnormal interrupts or related threads without interrupting the overall system operation. 5. Lack of analysis and prediction capabilities based on ISR behavioral characteristics. Existing RTOS generally do not establish historical models of interrupt service routine (ISR) behavior, making it impossible to analyze and predict anomaly trends based on the statistical characteristics of interrupt execution behavior, and making it difficult to take targeted intervention measures before or in the early stages of anomalies.
[0003] In Real-Time Operating Systems (RTOS), the interrupt mechanism is fundamental for real-time system response and peripheral event handling, and its operation spans the entire system lifecycle. RTOS responds quickly to external events through interrupt service routines and resumes task scheduling upon interrupt return. Normally, interrupts are part of the system's routine operation and are not considered exceptions. However, in real-world environments, even ordinary interrupts can exhibit problems such as abnormal execution time, abnormal triggering frequency, or abnormal nesting depth due to program defects, peripheral malfunctions, or changes in system load. These problems often do not initially trigger processor exception interrupts or immediately cause system crashes, but they gradually affect the real-time performance of task scheduling and the overall stability of the system, representing a potential operational risk. Existing RTOS management of ordinary interrupts typically focuses on interrupt registration, masking, and response order control, lacking a continuous monitoring and analysis mechanism for the execution behavior of interrupt service routines. Whether an interrupt executes correctly often relies solely on manual verification by developers during the debugging phase; once the system enters a long-term operational state, related abnormal behaviors are difficult to detect in a timely manner. For exception handling, current technologies primarily rely on the exception interrupt mechanism provided by the processor. When the processor detects a serious exception such as an illegal instruction, illegal memory access, or bus error, it enters the corresponding exception handling routine through the exception vector table. This type of approach typically records the context information after the exception occurs and restores system operation by resetting the system or entering a safe state. Additionally, some systems incorporate a watchdog mechanism; when a system freezes due to a normal interrupt or task exception, the watchdog triggers a hardware reset to restore the system. However, this method is reactive and cannot provide fine-grained management of interrupt execution status, nor can it distinguish between normal interrupt exceptions and system-level exceptions. Summary of the Invention
[0004] To address the aforementioned shortcomings, this invention discloses a real-time anomaly monitoring and local automatic recovery method and apparatus, which can reduce the overall system restart probability and improve system reliability and real-time performance.
[0005] The first aspect of this invention discloses a real-time anomaly monitoring and local automatic recovery method, comprising: When the system is initialized or running stably, a baseline model of the interrupt service routine's running behavior is constructed. The baseline model includes at least one standard statistical characteristic used to describe the interrupt service routine under normal operating conditions. The interrupt service routine is used to trigger any one or more processing threads. Lightweight monitoring logic is injected at the entry and exit points of the interrupt service routine to monitor the execution process of the interrupt service routine in real time and to collect at least one real-time statistical feature of the interrupt service routine during its execution. The real-time statistical features collected in real time are compared with standard statistical features to obtain the comparison results. Based on the comparison results and preset judgment rules, it is determined whether the current interrupt service routine is in an abnormal state, where abnormal states include interruption, nested exceptions, and interrupt task preemption. When the current interrupt service routine is in an abnormal state, the abnormality level is evaluated, and an automatic recovery action matching the abnormality level is triggered based on the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
[0006] As an optional implementation, in the first aspect of the present invention, injecting lightweight monitoring logic at the entry and exit points of the interrupt service routine is based on the premise of not modifying the interrupt service routine.
[0007] As an optional implementation, in the first aspect of the present invention, the lightweight monitoring logic includes at least recording a first timestamp or period count value when an interrupt enters, recording a second timestamp or period count value when an interrupt exits to calculate the interrupt execution duration, counting the interrupt triggering frequency per unit time, detecting whether the stack usage reaches a threshold, and detecting the abnormal nesting depth during the execution of the interrupt service routine.
[0008] As an optional implementation, in the first aspect of the present invention, the standard statistical characteristics include average execution time, peak execution time, interrupt trigger frequency range, maximum interrupt nesting depth, execution time jitter range, and stack usage.
[0009] As an optional implementation, in the first aspect of the present invention, determining whether the current interrupt service routine is in an abnormal state based on the comparison result and preset judgment rules includes: When the interrupt execution duration, interrupt triggering frequency, or exception nesting depth exceeds the set threshold or preset deviation range, it is defined as being in an abnormal state. An interrupt service routine is defined as being in an abnormal state when the interrupt execution duration, interrupt trigger frequency, and exception nesting depth show a continuous or monotonically increasing trend over multiple consecutive sampling periods.
[0010] As an optional implementation, in the first aspect of the present invention, the anomaly level includes local transient anomaly, processing thread anomaly, and global stable anomaly. The evaluation of the anomaly level includes: determining whether the anomaly level is a local transient anomaly, a processing thread anomaly, or a global stable anomaly based on a first dimension, a second dimension, and a third dimension. The first dimension includes determining whether the interrupt execution duration is greater than a first threshold, whether the interrupt triggering frequency is greater than a second threshold, whether the anomaly nesting depth is greater than a third threshold, and whether any one of the interrupt execution duration, interrupt triggering frequency, and anomaly nesting depth shows a continuous increasing trend. The second dimension includes whether the interrupt task preemption delay is greater than a set threshold. The third dimension includes whether the duration of the abnormal state within a continuous sampling period exceeds a preset period threshold.
[0011] As an optional implementation, in a first aspect of the present invention, triggering an automatic recovery action matching the anomaly level based on the anomaly level includes: When the exception level is transient, an interrupt-level self-healing process is executed. The interrupt-level self-healing process includes resetting associated peripherals, clearing hardware buffers, or reinitializing the interrupt controller. During the execution of the interrupt-level self-healing process, task scheduling is maintained to run normally. When the exception level is a processing thread exception, the associated processing thread is terminated and rebuilt, the processing thread context and message queue are restored, while other processing threads unrelated to this interrupt service routine continue to run. When the anomaly level is a globally stable anomaly, a preset system-level soft reboot is performed, and preset key application data and diagnostic logs are retained during the system-level soft reboot process.
[0012] A second aspect of this invention discloses a real-time anomaly monitoring and local automatic recovery device, comprising: Baseline model building module: used to build a baseline model of the interrupt service routine's running behavior when the system is initialized or running stably. The baseline model of running behavior includes at least one standard statistical characteristic to describe the interrupt service routine under normal operating conditions. The interrupt service routine is used to trigger any one or more processing threads. Real-time feature acquisition module: used to inject lightweight monitoring logic at the entry and exit points of the interrupt service routine to monitor the execution process of the interrupt service routine in real time, and to acquire at least one real-time statistical feature of the interrupt service routine during the execution process. The execution feature comparison module is used to compare the real-time statistical features collected in real time with standard statistical features to obtain the comparison results, and to determine whether the current interrupt service routine is in an abnormal state based on the comparison results and preset judgment rules. Partial interrupt recovery module: When the current interrupt service routine is in an abnormal state, it evaluates the abnormality level and triggers an automatic recovery action that matches the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
[0013] As an optional implementation, in the second aspect of the present invention, injecting lightweight monitoring logic at the entry and exit points of the interrupt service routine is based on the premise of not modifying the interrupt service routine.
[0014] As an optional implementation, in the second aspect of the present invention, the monitoring logic includes at least recording a first timestamp or period count value when the interrupt enters, recording a second timestamp or period count value when the interrupt exits to calculate the interrupt execution duration, counting the interrupt triggering frequency per unit time, detecting whether the stack usage reaches a threshold, and detecting the abnormal nesting depth during the execution of the interrupt service routine.
[0015] As an optional implementation, in the second aspect of the present invention, the standard statistical characteristics include average execution time, peak execution time, interrupt trigger frequency range, maximum interrupt nesting depth, execution time jitter range, and stack usage.
[0016] As an optional implementation, in a second aspect of the present invention, determining whether the current interrupt service routine is in an abnormal state based on the comparison result and a preset judgment rule includes: When the interrupt execution duration, interrupt triggering frequency, or exception nesting depth exceeds the set threshold or preset deviation range, it is defined as being in an abnormal state. An interrupt service routine is defined as being in an abnormal state when the interrupt execution duration, interrupt trigger frequency, and exception nesting depth show a continuous or monotonically increasing trend over multiple consecutive sampling periods.
[0017] As an optional implementation, in the second aspect of the present invention, the exception level includes local transient exception, processing thread exception, and global stable exception.
[0018] As an optional implementation, in a second aspect of the present invention, triggering an automatic recovery action matching the anomaly level based on the anomaly level includes: When the exception level is transient, an interrupt-level self-healing process is executed. The interrupt-level self-healing process includes resetting associated peripherals, clearing hardware buffers, or reinitializing the interrupt controller. During the execution of the interrupt-level self-healing process, task scheduling is maintained to run normally. When the exception level is a processing thread exception, the associated processing thread is terminated and rebuilt, the processing thread context and message queue are restored, while other processing threads unrelated to this interrupt service routine continue to run. When the anomaly level is a globally stable anomaly, a preset system-level soft reboot is performed, and preset key application data and diagnostic logs are retained during the system-level soft reboot process.
[0019] A third aspect of the present invention discloses an electronic device, comprising: a memory storing executable program code; a processor coupled to the memory; the processor calling the executable program code stored in the memory to execute the real-time anomaly monitoring local automatic recovery method disclosed in the first aspect of the present invention.
[0020] A fourth aspect of the present invention discloses a computer-readable storage medium storing a computer program, wherein the computer program causes a computer to execute the real-time anomaly monitoring local automatic recovery method disclosed in the first aspect of the present invention.
[0021] Compared with the prior art, the embodiments of the present invention have the following beneficial effects: In this embodiment of the invention, by injecting monitoring logic into the interrupt entry / exit points, the system can collect behavioral data in each interrupt execution cycle and compare it with the baseline model in real time. The system can identify the sub-health state of the interrupt service routine before the processor hardware is abnormally triggered, or even before the system scheduling deteriorates significantly. By evaluating the severity of the anomaly, the system can take recovery actions of different granularities according to the severity and scope of the anomaly. For ISR anomalies caused by transient peripheral failures, only the peripheral is reset and the buffer is cleared, while other tasks are completely unaffected. For the processing thread bound to the ISR that is stuck, only that thread is restarted, and threads unrelated to the interrupt in the system continue to run. System-level recovery is only considered when the above measures are ineffective. By continuously monitoring and analyzing the running behavior of ordinary interrupt service routines, abnormal trends can be identified during the normal operation of the system, and graded and local automatic recovery can be implemented according to the anomaly level, thereby reducing the overall system restart probability and improving system reliability and real-time performance. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating a real-time anomaly monitoring and local automatic recovery method disclosed in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a real-time anomaly monitoring and local automatic recovery device provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] It should be noted that the terms "first," "second," "third," "fourth," etc., in the specification and claims of this invention are used to distinguish different objects, not to describe a specific order. The terms "comprising" and "having," and any variations thereof, in the embodiments of this invention are intended to cover non-exclusive inclusion. Exemplarily, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0026] This invention discloses a real-time anomaly monitoring and local automatic recovery method, device, electronic device, and storage medium. By injecting monitoring logic into the interrupt entry / exit point, the system can collect behavioral data in each interrupt execution cycle and compare it with a baseline model in real time. The system can identify the sub-health state of the interrupt service routine before the processor hardware anomaly is triggered, or even before the system scheduling deteriorates significantly. By evaluating the severity of the anomaly, the system can take recovery actions of different granularities according to the severity and scope of the anomaly. For ISR anomalies caused by transient peripheral failures, only the peripheral is reset and the buffer is cleared, while other tasks are completely unaffected. For the processing thread bound to the ISR that is stuck, only that thread is restarted, and threads unrelated to the interrupt in the system continue to run. System-level recovery is only considered when the above measures are ineffective. Through continuous monitoring and analysis of the running behavior of ordinary interrupt service routines, anomaly trends can be identified during the normal operation of the system, and graded and local automatic recovery can be implemented according to the anomaly level, thereby reducing the overall system restart probability and improving system reliability and real-time performance.
[0027] Example 1 Please see Figure 1 , Figure 1This is a flowchart illustrating the real-time anomaly monitoring and local automatic recovery method disclosed in this embodiment of the invention. The execution entity of the method described in this embodiment is an execution entity composed of software and / or hardware. This execution entity can receive relevant information via wired or / or wireless means and can send certain instructions. It may also have certain processing and storage functions. This execution entity can control multiple devices, such as remote physical servers or cloud servers and related software, or local hosts or servers and related software that perform related operations on devices located in a certain location. In some scenarios, it can also control multiple storage devices, which may be placed in the same location as the devices or in different locations. Figure 1 As shown, the real-time anomaly monitoring and local automatic recovery method includes the following steps: 101. When the system is initialized or running stably, a baseline model of the running behavior of the interrupt service routine is constructed. The baseline model of the running behavior includes at least one standard statistical feature used to describe the interrupt service routine under normal working conditions. The interrupt service routine is used to trigger any one or more processing threads.
[0028] During system initialization, the real-time operating system kernel constructs a corresponding runtime behavior baseline model for each registered interrupt service routine. This baseline model describes the statistical characteristics of the interrupt under normal operating conditions. The standard statistical characteristics include average execution time, peak execution time, interrupt trigger frequency range, maximum interrupt nesting depth, execution time jitter range, and stack usage.
[0029] 102. Lightweight monitoring logic is injected at the entry and exit points of the interrupt service routine to monitor the execution process of the interrupt service routine in real time, and at least one real-time statistical feature of the interrupt service routine during the execution process is collected in real time.
[0030] Injecting lightweight monitoring logic at the entry and exit points of interrupt service routines is based on the premise of not modifying the interrupt service routines. In this step, without changing the original implementation of the interrupt service routine, the real-time operating system kernel automatically injects lightweight monitoring logic at the interrupt entry and exit points to collect data on the interrupt execution process in real time.
[0031] The monitoring logic includes at least recording the first timestamp or period count value when the interrupt enters, recording the second timestamp or period count value when the interrupt exits to calculate the interrupt execution duration, calculating the interrupt trigger frequency per unit time, detecting whether the stack usage reaches a threshold, and detecting the nesting depth of exceptions during the execution of the interrupt service routine. After the interrupt execution ends, the monitoring logic writes the collected statistical information into the exception detection engine for subsequent analysis.
[0032] 103. Compare the real-time statistical features collected in real time with the standard statistical features to obtain the comparison results, and determine whether the current interrupt service program is in an abnormal state based on the comparison results and preset judgment rules.
[0033] This step involves setting up anomaly detection to analyze and determine interrupted operational behavior. The analysis process is based on real-time collected interrupt monitoring data and combined with the behavioral baseline model of the interrupt service routine.
[0034] The determination of whether the current interrupt service routine is in an abnormal state is based on the comparison results and preset judgment rules, including: an abnormal state is defined as one or more of the following: interrupt execution duration exceeds a first threshold, interrupt triggering frequency exceeds a second threshold, or abnormal nesting depth exceeds a third threshold; or an abnormal state is defined as one where the interrupt execution duration, interrupt triggering frequency, or abnormal nesting depth of the interrupt service routine shows a continuous or monotonically increasing trend over multiple consecutive sampling periods. Interrupt execution duration is the execution time from the entry point to the exit point of the interrupt service routine.
[0035] More specifically, 1. The current interruption execution behavior is compared with the corresponding ISR behavior baseline model. When the interruption execution duration is greater than the first threshold, the interruption trigger frequency is greater than the second threshold, or the abnormal nesting depth is greater than the third threshold, it is judged as abnormal; 2. Anomaly judgment based on running trends: The changing trend of interruption execution behavior in multiple consecutive sampling periods is analyzed. When any one or more of the interruption execution time, interruption trigger frequency, or abnormal nesting depth is detected to show a continuous growth or abnormal fluctuation trend, it is judged as abnormal.
[0036] The anomaly levels include local transient anomalies, processing thread anomalies, and global stability anomalies. When an anomaly manifests only as a short-term deviation in interrupt execution time, trigger frequency, or stack usage and has not yet affected system operation, it is classified as a local transient anomaly, and only the anomaly information is recorded and monitoring is strengthened. When an anomaly persists for multiple consecutive sampling periods but is mainly limited to a single interrupt or related peripheral, it is classified as a local anomaly and interrupt-level automatic recovery is triggered. When an anomaly has affected the processing thread associated with the interrupt or system scheduling, it is classified as a thread anomaly and thread-level automatic recovery is performed. When an anomaly persists and cannot be eliminated through interrupt-level or thread-level recovery, or has caused a significant decrease in system stability and real-time performance, it is classified as a system anomaly and a system soft restart or entry into a safe operating state is triggered. This achieves an automatic recovery mechanism that escalates according to the severity of the anomaly, avoiding the operational interruption problems caused by the single system reset method in existing technologies. The determination of the above-mentioned short-term deviation, persistence, and significant decrease is preferably quantified through interrupt behavior thresholds, associated impact thresholds, and duration thresholds.
[0037] In this embodiment, anomaly detection is based on three dimensions: The first dimension is the interruption behavior judgment, including whether the interruption execution duration is greater than the first threshold T1, whether the interruption trigger frequency is greater than the second threshold T2, whether the abnormal nesting depth is greater than the third threshold T3, and whether the above parameters (interruption execution duration, interruption trigger frequency, and abnormal nesting depth) show a continuous increasing trend; the second dimension is the correlation impact judgment, including whether the interruption task preemption delay is greater than the set threshold T4; the third dimension is the persistence judgment, that is, whether the duration of the abnormal state in the continuous sampling period exceeds the preset period threshold. Based on the above three dimensions, the anomaly level is determined according to the following rules: When any one of the following conditions is met—interrupt execution duration greater than the first threshold T1, interrupt triggering frequency greater than the second threshold T2, or anomaly nesting depth greater than the third threshold T3—and the interrupt task preemption delay is less than or equal to threshold T4, and the anomaly duration is less than the first preset period threshold N1, it is determined to be a local transient anomaly; when the interrupt execution duration is greater than the first threshold T1, interrupt triggering frequency greater than the second threshold T2, or anomaly nesting depth greater than the third threshold T3, and the interrupt task preemption delay is greater than threshold T4, or the anomaly duration is greater than or equal to the first preset period threshold N1, it is determined to be a processing thread anomaly; when the anomaly duration is greater than or equal to the second preset period threshold N2, and the interrupt behavior parameter exceeds a preset multiple K of the corresponding threshold, or multiple interrupt sources simultaneously meet the above anomaly conditions, or the system timer tick jitters and the scheduling delay is continuously greater than threshold T4, it is determined to be a global stable anomaly.
[0038] Preferably, the first preset period threshold N1 can be 3 sampling periods, the second preset period threshold N2 can be 10 sampling periods, and the preset multiple K can be 5 times. Through the above determination rules, the abnormal state is progressively escalated from a local transient abnormality to a processing thread abnormality, and then to a globally stable abnormality.
[0039] 104. When the current interrupt service routine is in an abnormal state, evaluate the abnormality level and trigger an automatic recovery action that matches the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
[0040] For the three anomaly levels, the embodiment implements a three-level automatic recovery mechanism to minimize the need for a system-wide restart. When the anomaly level is transient, an interrupt-level self-healing process is executed, which includes resetting associated peripherals, clearing hardware buffers, or reinitializing the interrupt controller; during the execution of the interrupt-level self-healing process, task scheduling continues to run normally. When the anomaly level is a processing thread anomaly, the associated processing thread is terminated and rebuilt, and the processing thread context and message queue are restored; other processing threads unrelated to the interrupt service routine continue to run. When the anomaly level is a globally stable anomaly, a preset system-level soft reboot is executed, and preset key application data and diagnostic logs are retained during the system-level soft reboot.
[0041] Whether an exception is classified as a partial interrupt exception, a thread-related exception, or an unrecoverable system-level exception is not determined by a single metric. Instead, the exception detection engine makes the judgment based on a comprehensive analysis of the interrupt behavior baseline deviation, the exception persistence, and its impact on system operation. Specifically, when an exception is detected as a deviation from its behavioral baseline model only in the execution time, triggering frequency, nesting depth, or stack usage of a single interrupt service routine, and the exception does not significantly affect the task scheduling of the real-time operating system after interrupt-level monitoring or short-term intervention, it is classified as a partial interrupt exception and a local ISR is triggered. Self-healing; when an anomaly originates from an interrupted operation but has caused scheduling delays, blocking, or operational anomalies in the processing threads associated with the interrupt, or when interrupt-level recovery fails to eliminate the anomaly, it is determined to be a processing thread-related anomaly and escalated to thread-level recovery; when the above recovery measures still fail to bring the interrupted operation back to the baseline range within a preset number of times or a preset time window, or when the anomaly has spread and affected multiple interrupts, multiple threads, or the overall real-time performance and stability of the system, it is determined to be a system-level anomaly that cannot be locally recovered, and a system-level soft restart or entry into a safe operating mode is triggered, thereby forming an anomaly judgment and recovery mechanism that escalates from local to overall.
[0042] Level 1 recovery is local USR self-healing. When an exception is determined to be a local interrupt exception, local recovery operations are performed, including but not limited to: resetting peripherals or driver modules associated with the ISR; clearing the ring buffer or cache used by the interrupt; and reinitializing relevant hardware registers. This recovery process does not affect the operation of other modules in the system and does not require a system restart. Level 2 recovery is thread-level self-healing. When an exception is related to the processing thread bound to the interrupt, thread-level recovery is performed, including: restarting the processing thread associated with the interrupt; allowing other threads in the system to continue running; and saving the thread context information at the time of the exception for subsequent diagnosis. Level 3 recovery is selective system soft reboot. When an exception continues to occur or cannot be resolved by local or thread-level recovery, a system soft reboot is performed. Unlike a hardware reset, a soft reboot retains critical application data and configuration parameters during the reboot process to reduce the impact of system downtime.
[0043] As an improved real-time approach, the embodiment also records interrupted monitoring data, abnormal events, and recovery process information, and supports storing the information in local Flash or uploading it to a remote diagnostic system via a network interface for offline analysis and system optimization.
[0044] Example 2 Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of a real-time anomaly monitoring and local automatic recovery device disclosed in an embodiment of the present invention. Figure 2 As shown, the real-time anomaly monitoring and local automatic recovery device may include: a baseline model construction module 201, a real-time feature acquisition module 202, an execution feature comparison module 203, and a local interruption recovery module 204. The baseline model construction module 201 is used to construct a baseline model of the interrupt service routine's running behavior when the system is initialized or running stably. The baseline model includes at least one standard statistical feature describing the interrupt service routine under normal operating conditions. The interrupt service routine is used to trigger any one or more processing threads. The real-time feature acquisition module 202 is used to inject light... The scale monitoring logic monitors the execution process of the interrupt service routine in real time and collects at least one real-time statistical feature of the interrupt service routine during execution. The execution feature comparison module 203 is used to compare the real-time collected statistical features with standard statistical features to obtain a comparison result, and determine whether the current interrupt service routine is in an abnormal state based on the comparison result and preset judgment rules. The partial interrupt recovery module 204 is used to evaluate the abnormality level when the current interrupt service routine is in an abnormal state, and trigger an automatic recovery action matching the abnormality level according to the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
[0045] The injection of lightweight monitoring logic at the entry and exit points of the interrupt service routine is based on the premise of not modifying the interrupt service routine. This monitoring logic includes at least recording the first timestamp or period count value when the interrupt enters, recording the second timestamp or period count value when the interrupt exits to calculate the interrupt execution duration, statistically analyzing the interrupt triggering frequency per unit time, detecting whether stack usage reaches a threshold, and detecting abnormal nesting depth during the execution of the interrupt service routine. The standard statistical characteristics include average execution time, peak execution time, interrupt triggering frequency range, maximum interrupt nesting depth, execution time jitter range, and stack usage.
[0046] In the execution feature comparison module 203, the current interrupt service routine is judged to be in an abnormal state based on the comparison results and preset judgment rules, including: when the interrupt execution duration, interrupt trigger frequency, and abnormal nesting depth exceed the set threshold or preset deviation range, it is defined as being in an abnormal state; when the interrupt execution duration, interrupt trigger frequency, and abnormal nesting depth of the interrupt service routine show a continuous increase or monotonically increasing trend in multiple consecutive sampling periods, it is defined as being in an abnormal state.
[0047] The exception levels in this embodiment include local transient exceptions, processing thread exceptions, and globally stable exceptions. Interrupt exceptions are classified according to the exception determination results, and automatic recovery actions of different granularities are triggered based on the exception level, including but not limited to interrupt-level recovery, thread-level recovery, and system-level soft restart. This avoids the "one-size-fits-all" system reset method in the prior art, improving system availability and operational continuity. The local interrupt recovery module 204 triggers automatic recovery actions matching the exception level, including: when the exception level is transient, executing an interrupt-level self-healing process, which includes resetting associated peripherals, clearing hardware buffers, or reinitializing the interrupt controller; wherein, task scheduling continues to operate normally during the execution of the interrupt-level self-healing process; when the exception level is processing thread exception, terminating and rebuilding the associated processing thread, restoring the processing thread context and message queue, wherein other processing threads unrelated to the interrupt service routine continue to run; when the exception level is globally stable exception, executing a preset system-level soft restart, and retaining preset key application data and diagnostic logs during the system-level soft restart process.
[0048] Example 3 Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. The electronic device can be a computer, a server, etc. Of course, in certain cases, it can also be a mobile phone, tablet computer, monitoring terminal, or other smart device, as well as an image acquisition device with processing capabilities. Figure 3 As shown, the electronic device may include: Memory 301 storing executable program code; Processor 302 coupled to memory 301; The processor 302 calls the executable program code stored in the memory 301 to execute some or all of the steps in the real-time anomaly monitoring local automatic recovery method in Embodiment 1.
[0049] This invention discloses a computer-readable storage medium storing a computer program that causes a computer to perform some or all of the steps in the real-time anomaly monitoring local automatic recovery method of Embodiment 1.
[0050] This invention also discloses a computer program product, wherein when the computer program product is run on a computer, the computer performs some or all of the steps in the real-time anomaly monitoring local automatic recovery method in Embodiment 1.
[0051] This invention also discloses an application publishing platform, which is used to publish computer program products. When the computer program products are run on a computer, the computer performs some or all of the steps in the real-time anomaly monitoring local automatic recovery method in Embodiment 1.
[0052] In various embodiments of the present invention, it should be understood that the sequence number of each process does not necessarily imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0053] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they can be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0054] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0055] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several requests to cause a computer device (which can be a personal computer, server, or network device, specifically a processor in the computer device) to execute some or all of the steps of the methods described in the various embodiments of the present invention.
[0056] In the embodiments provided by this invention, it should be understood that "B corresponding to A" means that B is associated with A, and B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information.
[0057] Those skilled in the art will understand that some or all of the steps in the various methods of the embodiments described can be implemented by a program instructing related hardware. This program can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0058] The above provides a detailed description of the real-time anomaly monitoring local automatic recovery method, apparatus, electronic device, and storage medium disclosed in the embodiments of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for real-time anomaly monitoring and local automatic recovery, characterized in that, include: When the system is initialized or running stably, a baseline model of the interrupt service routine's running behavior is constructed. The baseline model includes at least one standard statistical characteristic used to describe the interrupt service routine under normal operating conditions. The interrupt service routine is used to trigger any one or more processing threads. Lightweight monitoring logic is injected at the entry and exit points of the interrupt service routine to monitor the execution process of the interrupt service routine in real time and to collect at least one real-time statistical feature of the interrupt service routine during its execution. The real-time statistical features collected in real time are compared with standard statistical features to obtain the comparison results. Based on the comparison results and preset judgment rules, it is determined whether the current interrupt service routine is in an abnormal state, where abnormal states include interruption, nested exceptions, and interrupt task preemption. When the current interrupt service routine is in an abnormal state, the abnormality level is evaluated, and an automatic recovery action matching the abnormality level is triggered based on the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
2. The real-time anomaly monitoring and local automatic recovery method according to claim 1, characterized in that, Injecting lightweight monitoring logic at the entry and exit points of an interrupt service routine is based on the premise of not modifying the interrupt service routine.
3. The real-time anomaly monitoring and local automatic recovery method according to claim 1, characterized in that, The lightweight monitoring logic includes at least recording the first timestamp or period count value when the interrupt enters, recording the second timestamp or period count value when the interrupt exits to calculate the interrupt execution duration, calculating the interrupt trigger frequency per unit time, detecting whether the stack usage reaches a threshold, and detecting the abnormal nesting depth during the execution of the interrupt service routine.
4. The real-time anomaly monitoring and local automatic recovery method according to claim 1, characterized in that, The standard statistical characteristics include average execution time, peak execution time, interrupt trigger frequency range, maximum interrupt nesting depth, execution time jitter range, and stack usage.
5. The real-time anomaly monitoring and local automatic recovery method according to claim 3, characterized in that, Based on the comparison results and preset judgment rules, determine whether the current interrupt service routine is in an abnormal state, including: An abnormal state is defined as one or more of the following: the interrupt execution duration exceeds the first threshold, the interrupt triggering frequency is greater than the second threshold, and the exception nesting depth is greater than the third threshold. An abnormal state is defined as one where any one or more of the interrupt execution duration, interrupt trigger frequency, or exception nesting depth of an interrupt service routine show a continuous or monotonically increasing trend over multiple consecutive sampling periods.
6. The real-time anomaly monitoring and local automatic recovery method according to claim 1, characterized in that, The anomaly levels include local transient anomalies, processing thread anomalies, and globally stable anomalies. The evaluation of the anomaly level includes determining whether the anomaly level is a local transient anomaly, a processing thread anomaly, or a globally stable anomaly based on a first dimension, a second dimension, and a third dimension. The first dimension includes determining whether the interrupt execution duration is greater than a first threshold, whether the interrupt triggering frequency is greater than a second threshold, whether the anomaly nesting depth is greater than a third threshold, and whether any one of the interrupt execution duration, interrupt triggering frequency, and anomaly nesting depth shows a continuous increasing trend. The second dimension includes whether the interrupt task preemption delay is greater than a set threshold. The third dimension includes whether the duration of the abnormal state within a continuous sampling period exceeds a preset period threshold.
7. The real-time anomaly monitoring and local automatic recovery method according to claim 6, characterized in that, Based on the aforementioned anomaly level, an automatic recovery action matching the anomaly level is triggered, including: When the exception level is transient, an interrupt-level self-healing process is executed. The interrupt-level self-healing process includes resetting associated peripherals, clearing hardware buffers, or reinitializing the interrupt controller. During the execution of the interrupt-level self-healing process, task scheduling is maintained to run normally. When the exception level is a processing thread exception, the associated processing thread is terminated and rebuilt, the processing thread context and message queue are restored, while other processing threads unrelated to this interrupt service routine continue to run. When the anomaly level is a globally stable anomaly, a preset system-level soft reboot is performed, and preset key application data and diagnostic logs are retained during the system-level soft reboot process.
8. A real-time anomaly monitoring and local automatic recovery device, characterized in that, include: Baseline model building module: used to build a baseline model of the interrupt service routine's running behavior when the system is initialized or running stably. The baseline model of running behavior includes at least one standard statistical characteristic to describe the interrupt service routine under normal operating conditions. The interrupt service routine is used to trigger any one or more processing threads. Real-time feature acquisition module: used to inject lightweight monitoring logic at the entry and exit points of the interrupt service routine to monitor the execution process of the interrupt service routine in real time, and to acquire at least one real-time statistical feature of the interrupt service routine during the execution process. The execution feature comparison module is used to compare the real-time statistical features collected in real time with standard statistical features to obtain the comparison results, and to determine whether the current interrupt service routine is in an abnormal state based on the comparison results and preset judgment rules. Partial interrupt recovery module: When the current interrupt service routine is in an abnormal state, it evaluates the abnormality level and triggers an automatic recovery action that matches the abnormality level. The automatic recovery action includes at least one partial recovery operation that does not interrupt system operation.
9. An electronic device, characterized in that, include: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the real-time anomaly monitoring local automatic recovery method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program causes a computer to perform the real-time anomaly monitoring local automatic recovery method according to any one of claims 1 to 7.