Real-time operating system monitoring methods, devices, electronic equipment and storage media
By introducing shared memory and core competition mechanisms into multi-core processors, the problem of faulty cores being unable to output data in real-time operating system monitoring is solved, and robust monitoring data output is achieved in the event of core failure.
Patent Information
- Application Number
- CN202510630684.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2026-11-17
AI Technical Summary
In real-time operating system monitoring, when a fault occurs in the local kernel, monitoring data cannot be transmitted, rendering the monitoring ineffective.
By introducing shared memory into a multi-core processor, the last running time of the target core can be obtained to determine whether it is a faulty core. In the event of a fault, monitoring data can be obtained from the shared memory and output. The main core or sub-core competition mechanism is used to ensure data transmission.
Even when some cores are alive in a multi-core processor, monitoring data of the faulty core can be output, which improves the robustness of operating system monitoring and solves the problem that monitoring data cannot be output when a core fails in the existing technology.
Smart Images

Figure CN123114879A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of operating system technology, and in particular to a real-time operating system monitoring method, apparatus, electronic device, and storage medium. Background Technology
[0002] Real-Time OS Monitoring (RTOS) is a technology that continuously tracks system status with extremely low latency, aiming to instantly detect anomalies and respond quickly to problems. It is suitable for scenarios with extremely high timeliness requirements. Its core lies in millisecond-level data acquisition, real-time analysis, and automated intervention.
[0003] Figure 1 This is a schematic diagram of the operational structure of real-time operating system monitoring in related technologies, such as... Figure 1 As shown, the design of traditional real-time operating system monitoring adopts the AMP (Asymmetric Multi-Processing) operating structure, that is, the same copy of the operating system runs on each core, manages its own core, and provides an execution environment similar to a single-processor system for each monitoring thread.
[0004] However, this operating mode makes the monitoring thread too dependent on the running status of the local core. When the local core fails, the original monitoring data cannot be transmitted, so monitoring can only be effective when the system is running normally. Summary of the Invention
[0005] This application provides a real-time operating system monitoring method, apparatus, electronic device, and storage medium, which helps to solve the problem that monitoring data of the fault core cannot be transmitted.
[0006] To address the aforementioned problems, in a first aspect, embodiments of this application provide a real-time operating system monitoring method, the method comprising:
[0007] Obtain the last execution time of the target core monitoring thread from shared memory. The target core is a core in the multi-core processor other than the current core, and the current core is a core in the multi-core processor.
[0008] Based on the last running time, determine whether the target core is a faulty core;
[0009] If the target core is a faulty core, the monitoring data of the faulty core is obtained from the shared memory and the monitoring data is output.
[0010] Optionally, determining whether the target core is a faulty core based on the last running time includes:
[0011] If the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to the first target duration, the target core is determined to be a faulty core.
[0012] Optionally, the step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data includes:
[0013] When the current core is the main core and the faulty core is the child core, the main core is used to obtain the monitoring data of the faulty core from the shared memory and output the monitoring data.
[0014] Optional, also includes:
[0015] When the current core monitoring thread is running, the current running time of the current core monitoring thread is recorded in the shared memory.
[0016] Optional, also includes:
[0017] When the current core monitoring thread is running, the monitoring data of the current core is written to the shared memory.
[0018] Optionally, before obtaining the monitoring data of the faulty core from the shared memory, the method further includes:
[0019] When the current core is a sub-core, if the faulty core is the master core, then a competition for the master core is initiated.
[0020] The step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data includes:
[0021] When the current core becomes the new master core, the monitoring data of the faulty core is obtained from the shared memory using the new master core, and the monitoring data is output.
[0022] Optionally, obtaining the last execution time of the target core monitoring thread from shared memory includes:
[0023] When the current core is used as a sub-core, the last execution time of the main core monitoring thread is obtained from the shared memory;
[0024] The step of determining whether the target core is a faulty core based on the last running time includes:
[0025] If the time interval between the last run time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
[0026] Optionally, after initiating the operation of competing for the main core, the following steps are also included:
[0027] If other sub-cores simultaneously initiate operations to compete for the main core, then based on the election algorithm, one sub-core is elected from among the competing sub-cores to become the new main core.
[0028] Optionally, after selecting a sub-core from among the competing sub-cores based on the election algorithm to serve as the new main core, the method further includes:
[0029] Update the value of the main core variable in shared memory to the identifier of the new main core.
[0030] Secondly, embodiments of this application provide a real-time operating system monitoring device, the device comprising:
[0031] The runtime acquisition module is used to acquire the last runtime of the target core monitoring thread from shared memory. The target core is a core in a multi-core processor other than the current core, and the current core is a core in the multi-core processor.
[0032] The fault core determination module is used to determine whether the target core is a fault core based on the last running time.
[0033] The monitoring data output module is used to obtain monitoring data of the faulty core from the shared memory and output the monitoring data when the target core is a faulty core.
[0034] Optionally, the fault core determination module is specifically used for:
[0035] If the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to the first target duration, the target core is determined to be a faulty core.
[0036] Optionally, the monitoring data output module is specifically used for:
[0037] When the current core is the main core and the faulty core is the child core, the main core is used to obtain the monitoring data of the faulty core from the shared memory and output the monitoring data.
[0038] Optionally, the device further includes:
[0039] The runtime recording module is used to record the runtime of the current core monitoring thread in the shared memory when the current core monitoring thread is running.
[0040] Optionally, the device further includes:
[0041] The monitoring data recording module is used to write the current core monitoring data into the shared memory when the current core monitoring thread is running.
[0042] Optionally, the device further includes:
[0043] The contention operation initiation module is used to initiate a contention operation for the master core when the current core is a sub-core and the faulty core is the master core.
[0044] The monitoring data output module is specifically used for:
[0045] When the current core becomes the new master core, the monitoring data of the faulty core is obtained from the shared memory using the new master core, and the monitoring data is output.
[0046] Optionally, the runtime acquisition module is specifically used for:
[0047] When the current core is used as a sub-core, the last execution time of the main core monitoring thread is obtained from the shared memory;
[0048] Optionally, the fault core determination module is specifically used for:
[0049] If the time interval between the last run time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
[0050] Optionally, the device further includes:
[0051] The election module is used to select a new main core from among the competing main cores if other sub-cores simultaneously initiate operations to compete for the main core after the operation of initiating competition for the main core has been completed.
[0052] Optionally, the device further includes:
[0053] The main core variable value update module is used to update the value of the main core variable in the shared memory to the identifier of the new main core after electing a sub-core from the competing sub-cores based on the election algorithm.
[0054] Thirdly, embodiments of this application also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the real-time operating system monitoring method described in embodiments of this application.
[0055] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the real-time operating system monitoring method described in embodiments of this application.
[0056] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the real-time operating system monitoring method described in embodiments of this application.
[0057] The real-time operating system monitoring method, apparatus, electronic device, and storage medium provided in this application obtain the last running time of the target core monitoring thread from shared memory, determine whether the target core is a faulty core based on the last running time, and if the target core is a faulty core, obtain the monitoring data of the faulty core from shared memory and output the monitoring data. In this way, the last running time and monitoring data of each core are stored in shared memory, and the faulty core can be determined based on the last running time. When a core fails, the monitoring data of the faulty core is output through the surviving core. In a multi-core processor, as long as there is a surviving core, the monitoring data of the faulty core can be output, which solves the problem that the monitoring data cannot be output when the processor core fails in the prior art and improves the robustness of operating system monitoring. Attached Figure Description
[0058] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is a schematic diagram of the operational structure of real-time operating system monitoring in related technologies;
[0060] Figure 2 This is a flowchart of a real-time operating system monitoring method provided in an embodiment of this application;
[0061] Figure 3 This is a flowchart of a real-time operating system monitoring method provided in an embodiment of this application;
[0062] Figure 4 This is a schematic diagram of the operational structure of the real-time operating system monitoring in the embodiments of this application;
[0063] Figure 5 This is a schematic diagram of the structure of a real-time operating system monitoring device provided in an embodiment of this application;
[0064] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0065] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0066] Figure 2 This is a flowchart illustrating a real-time operating system monitoring method provided in an embodiment of this application. This real-time operating system monitoring method is applied to a multi-core processor and can be executed by one core of the multi-core processor, which serves as the current core. Figure 2 As shown, the method includes steps 210 to 240.
[0067] Step 210: Obtain the last running time of the target core monitoring thread from the shared memory. The target core is a core in the multi-core processor other than the current core, and the current core is a core in the multi-core processor.
[0068] In one exemplary embodiment, shared memory is a shared memory region among all cores in a multi-core processor, accessible to all cores in the multi-core processor.
[0069] In one exemplary embodiment, the monitoring thread in each core runs periodically, once at regular intervals. While the monitoring thread is running, it monitors the current core and also the last running time of other cores. When monitoring the current core, the monitoring thread monitors the current core's working status based on data metrics and acquires monitoring data, which is then written to shared memory.
[0070] In one exemplary embodiment, the monitoring thread of the current core automatically detects the running status of the target core, that is, it obtains the last running time of the target core from shared memory, so as to determine whether the target core has failed based on the last running time. The target core can be the main core or a sub-core. For example, when the current core is the main core, the target core includes various sub-cores; when the current core is a sub-core, the target core is the main core.
[0071] Step 220: Determine whether the target core is a faulty core based on the last running time.
[0072] In one exemplary embodiment, for each target core, it can be determined whether the target core is faulty based on the last running time. If the core is faulty, it is identified as a faulty core. For example, the time interval between the last running time and the current time can be determined, and this time interval can be compared with the running cycle of the monitoring thread to determine whether the target core is faulty. If the time interval is greater than a certain multiple of the running cycle, the target core is determined to be faulty; otherwise, the target core is not faulty.
[0073] In some embodiments of this application, determining whether the target core is a faulty core based on the last running time includes: if the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to a first target duration, then the target core is determined to be a faulty core.
[0074] In an exemplary embodiment, the first target duration can be set according to requirements, generally multiple running cycles of the monitoring thread, such as two or more running cycles, to avoid the core business being too busy and crowding out the operation of the monitoring thread. In this way, the monitoring thread can determine the core fault when it has not run for multiple running cycles, which can improve the accuracy of core fault judgment.
[0075] In an exemplary embodiment, for each target core, the time interval between the last running time of the target core and the current time is determined, and the relationship between the time interval and the first target duration is compared. If the time interval is greater than or equal to the first target duration, it is determined that the target core has failed, and the target core is identified as a failed core.
[0076] The target core is identified as a faulty core when the time interval between the last run time and the current time of the target core is greater than or equal to the first target duration. The first target duration is generally greater than the running cycle of the monitoring thread. This can avoid the problem of the monitoring thread not running on time due to system jitter and improve the accuracy of core fault judgment.
[0077] Step 230: If the target core is a faulty core, obtain the monitoring data of the faulty core from the shared memory and output the monitoring data.
[0078] In one exemplary embodiment, the monitoring data is data that can comprehensively reflect the performance and load of the operating system, and may include CPU utilization, memory utilization, disk utilization, network status, etc.
[0079] In one exemplary embodiment, when the current core monitoring thread determines that a target core is faulty, it retrieves the monitoring data of the faulty core from shared memory and outputs the monitoring data of the faulty core in a target output mode, facilitating fault analysis of the faulty core based on the monitoring data. For example, the target output mode can be serial port printing, Ethernet output, etc., and the specific target output mode can be pre-configured.
[0080] The real-time operating system monitoring method provided in this application obtains the last running time of the target core monitoring thread from shared memory, determines whether the target core is a faulty core based on the last running time, and if the target core is a faulty core, obtains the monitoring data of the faulty core from shared memory and outputs the monitoring data. In this way, the last running time and monitoring data of each core are stored in shared memory, and the faulty core can be determined based on the last running time. When a core fails, the monitoring data of the faulty core is output through the surviving core. In a multi-core processor, as long as there is a surviving core, the monitoring data of the faulty core can be output, which solves the problem that the monitoring data cannot be output when the processor core fails in the prior art and improves the robustness of operating system monitoring.
[0081] Based on the above technical solution, the step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data includes: when the current core is the main core and the faulty core is the child core, using the main core to obtain monitoring data of the faulty core from the shared memory and outputting the monitoring data.
[0082] In one exemplary embodiment, the main core monitoring thread runs periodically, once every certain period. While monitoring the main core, the main core monitoring thread also monitors the last running time of each sub-core, and outputs the sub-core's monitoring data when a sub-core failure is detected.
[0083] In one exemplary embodiment, the sub-core monitoring thread runs periodically, once at regular intervals. The last time the sub-core monitoring thread ran is the time of its last execution.
[0084] In an exemplary embodiment, when the current core acts as the master core, the current core monitoring thread automatically detects the running status of each sub-core. That is, it obtains the last running time of each sub-core from the shared memory, determines whether the sub-core is faulty based on the time interval between the last running time and the current time, and outputs the monitoring data of the sub-core when it fails. In this way, the master core detects the survival status of the sub-cores and outputs the monitoring data of the sub-cores when they fail, instead of all surviving cores outputting the monitoring data of the faulty cores, which can save resources.
[0085] Based on the above technical solution, the method may further include: recording the current running time of the current core monitoring thread in the shared memory during the current core monitoring thread's runtime.
[0086] Regardless of whether the current core is the main core or a child core, as long as the current core monitoring thread is running, the current core monitoring thread will record the current core monitoring thread's current running time in shared memory. This allows other cores to monitor the current core for faults based on the current core's running time recorded in shared memory. Similarly, when other cores (such as the target core) are running, their monitoring threads will also record the current running time of those other cores in shared memory. For example, when the current core is the master core, the current core monitoring thread records the runtime of this operation in shared memory. If the current core fails and cannot update the runtime in shared memory, the child core can determine the master core failure based on the master core's last runtime in shared memory. It can then compete for the master core, and when a new master core is created, the failed master core will become the child core. The new master core will perform fault detection, and if it determines the child core is faulty, it can output the monitoring data of that child core. Similarly, when the current core is the child core, the current core monitoring thread records the runtime of this operation in shared memory. If the current core fails and cannot update the runtime in shared memory, the master core can determine the child core failure based on the child core's last runtime in shared memory and can output the monitoring data of the faulty child core in shared memory.
[0087] Based on the above technical solution, the method may further include: writing the current core monitoring data into the shared memory while the current core monitoring thread is running.
[0088] Whether a core is acting as the main core or a child core, when the current core monitoring thread is running, it monitors the core's operational status based on data metrics, acquires monitoring data, and writes the data to shared memory. For example, the main core monitoring thread monitors the main core's operational status based on data metrics, acquires monitoring data, and writes the data to shared memory; similarly, the child core monitoring thread monitors the operational status of its respective child core based on data metrics, acquires monitoring data, and writes the data to shared memory. Likewise, other core monitoring threads also monitor the operational status of their respective cores based on data metrics, acquires monitoring data, and writes the data to shared memory.
[0089] By having the current core monitoring thread write the current core's monitoring data to shared memory during runtime, other cores can output the current core's monitoring data from shared memory when they detect a fault in the current core.
[0090] Based on the above technical solution, before obtaining the monitoring data of the faulty core from the shared memory, it may further include: when the current core is a sub-core, if the faulty core is the master core, then initiate a competition for the master core operation;
[0091] The step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data may include: when the current core becomes the new master core, using the new master core to obtain monitoring data of the faulty core from the shared memory and outputting the monitoring data.
[0092] In an exemplary embodiment, although the above mechanism ensures that data from abnormal sub-cores can be transmitted from the main core, thereby increasing system stability, since the main core may also fail, the sub-cores need to do one more thing: monitor the operating status of the main core. When the main core fails, all detected sub-cores need to compete for the main core.
[0093] In one exemplary embodiment, when the current core acts as a sub-core, it is necessary to monitor the operating status of the main core. Upon determining a main core failure, an operation to compete for the main core is initiated. For example, initiating this operation could utilize the processor's atomic operation capabilities to modify the value of a main core variable; that is, to change the value of the main core variable to the identifier of the current core. Atomic operation capabilities ensure that when multiple sub-cores are competing for the main core simultaneously, only one sub-core can successfully modify the value of the main core variable. Alternatively, after initiating the main core competition operation, if other sub-cores are also competing for the main core, a distributed election algorithm can be used to elect a new main core from among the competing sub-cores.
[0094] In one exemplary embodiment, when the current core becomes the new master core, the current core retrieves monitoring data of the failed core (the previous master core) from shared memory and outputs the monitoring data.
[0095] By monitoring the running status of the main core when the current core is acting as a child core, initiating a competition for the main core when the main core fails, and retrieving and outputting the monitoring data of the failed core from shared memory when the new main core becomes the new main core, the monitoring data of the failed core can be output through the new main core when the main core fails.
[0096] Based on the above technical solution, obtaining the last running time of the target core monitoring thread from the shared memory may include: when the current core is a sub-core, obtaining the last running time of the main core monitoring thread from the shared memory;
[0097] The step of determining whether the target core is a faulty core based on the last running time may include: if the time interval between the last running time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
[0098] In one exemplary embodiment, the second target duration can be set according to requirements, generally multiple running cycles of the monitoring thread, such as two or more running cycles, to avoid the main core being too busy to occupy the running of the monitoring thread. In this way, the main core monitoring thread can determine the main core failure when it has not run for multiple running cycles, which can improve the accuracy of the main core failure judgment.
[0099] In one exemplary embodiment, the last execution time of the main core monitoring thread is the time when the main core monitoring thread last ran, which is recorded in shared memory by the main core monitoring thread during runtime.
[0100] In an exemplary embodiment, when the current core is acting as a child core, the running status of the main core is monitored. The last running time of the main core monitoring thread is obtained from shared memory. Based on the last running time of the main core monitoring thread, it is determined whether the main core has failed. That is, the time interval between the last running time of the main core monitoring thread and the current time is determined. The relationship between the time interval and the second target duration is compared. If the time interval is greater than or equal to the second target duration, it is determined that the main core has failed. At this time, the current core can initiate a competition for the main core.
[0101] The sub-core monitors the running status of the main core based on the last running time of the main core monitoring thread. When a main core failure is detected, it initiates a competition for the main core, so that the monitoring data of the faulty main core (which becomes the sub-core after the main core competition is successful) can be output after the main core competition is successful.
[0102] Based on the above technical solution, after initiating the operation of competing for the main core, it may further include: if other sub-cores simultaneously initiate the operation of competing for the main core, then based on the election algorithm, elect a sub-core from each sub-core of the competing main core as the new main core.
[0103] In one exemplary embodiment, the election algorithm can be an existing distributed election algorithm, such as the Bully algorithm, Raft algorithm, Paxos algorithm, ZAB (Zookeeper Atomic Broadcast) protocol, etc. The specific election algorithm can be selected according to the requirements, and this application embodiment does not limit it.
[0104] In one exemplary embodiment, all child cores that detect a primary core failure will initiate a competition for the primary core. If the current core detects a primary core failure and simultaneously receives competition requests from other child cores, an election algorithm is used to elect a new primary core from among all competing child cores. For example, when electing a new primary core based on a distributed election algorithm, if the current core detects a primary core failure, it sends an election message to all child cores with IDs higher than its own. If the current core does not receive a response, it becomes the new primary core; otherwise, it waits for a child core with a higher ID to take over. The child core with the highest ID declares victory and becomes the new primary core.
[0105] In an exemplary embodiment, the monitoring threads of the sub-cores participating in the main core competition can be considered to be in a normal state because the competition is initiated by the core itself. When a new main core is successfully elected, the new main core continues to execute the function of transmitting abnormal monitoring data.
[0106] The technical solution of this application embodiment can ensure that, at the same time, as long as a core is alive, the main core can definitely transmit abnormal monitoring data.
[0107] If the current core monitor detects a main core failure and other sub-cores simultaneously initiate operations to compete for the main core, a new main core can be elected from among the competing sub-cores based on an election algorithm, ensuring that only one sub-core is successfully elected when multiple sub-cores are competing for the main core.
[0108] Based on the above technical solution, after electing a sub-core from among the competing sub-cores based on the election algorithm to serve as the new master core, it may further include: updating the value of the master core variable in shared memory to the identifier of the new master core.
[0109] In an exemplary embodiment, the value of the main core variable is used to record the identifier of the current main core. The value of the main core variable can be stored in shared memory for each core in the processor to read, so that each core can know the current main core, which facilitates the main core to monitor the running status of each sub-core, and at the same time, it facilitates the sub-core to know the main core and monitor the running status of the main core.
[0110] In one exemplary embodiment, if the current core monitoring thread is elected as the new master core, the current core monitoring thread updates the value of the master core variable in shared memory, updating the value of the master core variable to the identifier of the new master core, that is, updating the value of the master core variable to the identifier of the current core.
[0111] By updating the value of the master core variable in shared memory to the identifier of the new master core after a new master core is elected, each core in the processor can easily understand the current master core.
[0112] Figure 3 This is a flowchart illustrating a real-time operating system monitoring method provided in an embodiment of this application. This real-time operating system monitoring method is applied to a multi-core processor and can be executed by one core of the multi-core processor, which serves as the current core. Figure 3 As shown, the method includes steps 310 to 360.
[0113] Step 310: When the current core is used as a sub-core, obtain the last running time of the main core monitoring thread from the shared memory.
[0114] When the current core is used as a sub-core, the last execution time of the main core monitoring thread is obtained from shared memory to monitor the running status of the main core.
[0115] Step 320: If the time interval between the last running time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
[0116] Step 330: When the current core is a sub-core, if the faulty core is the master core, then initiate a competition for the master core.
[0117] When the current core is acting as a sub-core, if the main core fails, a contest for the main core will be initiated. Simultaneously, other sub-cores that detect the main core failure will also initiate contests for the main core, but only one sub-core will succeed in winning the contest.
[0118] Step 340: When the current core becomes the new master core, use the new master core to obtain the last running time of the target core monitoring thread from the shared memory.
[0119] When the current core becomes the new main core, the current core obtains the last execution time of the target core (each sub-core) monitoring thread from shared memory, and monitors the running status of other sub-cores based on the last execution time of the target core monitoring thread.
[0120] Step 350: If the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to the first target duration, then the target core is determined to be a faulty core.
[0121] Step 360: When the current core is the main core and the faulty core is the child core, the main core is used to obtain the monitoring data of the faulty core from the shared memory and outputs the monitoring data.
[0122] When the current core is the main core and the faulty core is determined to be a child core, the monitoring data of the faulty core is obtained from the shared memory and output. At this time, the current core will output the monitoring data of the previously faulty main core and other faulty child cores.
[0123] The real-time operating system monitoring method provided in this application monitors the operating status of the main core by using the last runtime of the main core in shared memory when the current core is a sub-core. When a main core failure is determined, a competition for the main core is initiated. When the main core becomes the new main core, the operating status of each sub-core is monitored by using the last runtime of each sub-core in shared memory. When a sub-core failure is determined, the monitoring data of the failed core is obtained from shared memory and output. In this way, as long as there is a surviving core in a multi-core processor, the monitoring data of the failed core can be output, which solves the problem that monitoring data cannot be output when the processor core fails in the prior art and improves the robustness of operating system monitoring.
[0124] Figure 4 This is a schematic diagram of the operational structure of the real-time operating system monitoring in an embodiment of this application, as shown below. Figure 4 As shown in the embodiment of this application, the design of the real-time operating system monitoring also adopts the AMP (Active Programming) architecture. Each core (x cores in the diagram) runs the same copy of the operating system, managing its own core. Each monitoring thread monitors its own core. An inter-core shared memory region is added between all cores of the processor. Each core's monitoring thread records its last runtime (i.e., previous runtime) and monitoring data in this shared memory region. The main core monitoring thread, in addition to monitoring the main core, also has a child core death detection function. It can monitor the previous runtime of each child core to determine if a child core has failed, and when a child core fails, it retrieves the monitoring data of that child core from the shared memory and transmits it out. The child core monitoring thread, in addition to monitoring the current child core, also has a main core contention function. It can monitor the previous runtime of the main core and initiate a main core contention operation when a main core failure is determined. When multiple child core monitoring threads compete for the main core simultaneously, only one child core monitoring thread succeeds in being elected. The new main core monitoring thread can transmit the monitoring data of the failed main core (now a child core).
[0125] This application embodiment supports status capture between multiple monitoring threads and ensures that as long as one core is alive, abnormal monitoring data of other cores can be transmitted to support problem localization. Compared with existing technical solutions, the technical solution of this application embodiment does not increase hardware costs. It improves the security level of the monitoring thread operation by slightly increasing memory and CPU load resources, and can output information for problem localization when system failure occurs.
[0126] Figure 5This is a schematic diagram of a real-time operating system monitoring device provided in an embodiment of this application. The real-time operating system monitoring device is applied to one core of a multi-core processor, with the core serving as the current core. Figure 5 As shown, the device includes:
[0127] The runtime acquisition module 510 is used to acquire the last runtime of the target core monitoring thread from the shared memory. The target core is a core in the multi-core processor other than the current core, and the current core is a core in the multi-core processor.
[0128] The fault core determination module 520 is used to determine whether the target core is a fault core based on the last running time.
[0129] The monitoring data output module 530 is used to obtain monitoring data of the faulty core from the shared memory and output the monitoring data when the target core is a faulty core.
[0130] Optionally, the fault core determination module is specifically used for:
[0131] If the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to the first target duration, the target core is determined to be a faulty core.
[0132] Optionally, the monitoring data output module is specifically used for:
[0133] When the current core is the main core and the faulty core is the child core, the main core is used to obtain the monitoring data of the faulty core from the shared memory and output the monitoring data.
[0134] Optionally, the device further includes:
[0135] The runtime recording module is used to record the runtime of the current core monitoring thread in the shared memory when the current core monitoring thread is running.
[0136] Optionally, the device further includes:
[0137] The monitoring data recording module is used to write the current core monitoring data into the shared memory when the current core monitoring thread is running.
[0138] Optionally, the device further includes:
[0139] The contention operation initiation module is used to initiate a contention operation for the master core when the current core is a sub-core and the faulty core is the master core.
[0140] The monitoring data output module is specifically used for:
[0141] When the current core becomes the new master core, the monitoring data of the faulty core is obtained from the shared memory using the new master core, and the monitoring data is output.
[0142] Optionally, the runtime acquisition module is specifically used for:
[0143] When the current core is used as a sub-core, the last execution time of the main core monitoring thread is obtained from the shared memory;
[0144] Optionally, the fault core determination module is specifically used for:
[0145] If the time interval between the last run time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
[0146] Optionally, the device further includes:
[0147] The election module is used to select a new main core from among the competing main cores if other sub-cores simultaneously initiate operations to compete for the main core after the operation of initiating competition for the main core has been completed.
[0148] Optionally, the device further includes:
[0149] The main core variable value update module is used to update the value of the main core variable in the shared memory to the identifier of the new main core after electing a sub-core from the competing sub-cores based on the election algorithm.
[0150] The real-time operating system monitoring device provided in this application embodiment is used to implement the steps of the real-time operating system monitoring method described in this application embodiment. The specific implementation of each module of the device is described in the corresponding steps, and will not be repeated here.
[0151] The real-time operating system monitoring device provided in this application obtains the last running time of the target core monitoring thread from shared memory, determines whether the target core is a faulty core based on the last running time, and if the target core is a faulty core, obtains the monitoring data of the faulty core from shared memory and outputs the monitoring data. In this way, the last running time and monitoring data of each core are stored in shared memory, and the faulty core can be determined based on the last running time. When a core fails, the monitoring data of the faulty core is output through the surviving core. In a multi-core processor, as long as there is a surviving core, the monitoring data of the faulty core can be output, which solves the problem that the monitoring data cannot be output when the processor core fails in the prior art and improves the robustness of operating system monitoring.
[0152] Figure 6This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application, such as... Figure 5 As shown, the electronic device 500 may include one or more processors 610 and one or more memories 620 connected to the processors 610. The electronic device 600 may also include an input interface 630 and an output interface 640 for communicating with another device or system. Program code executed by the processor 610 may be stored in the memory 620.
[0153] The processor 610 in the electronic device 600 calls the program code stored in the memory 620 to execute the real-time operating system monitoring method described in the above embodiments.
[0154] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the real-time operating system monitoring method as described in this application.
[0155] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the real-time operating system monitoring method as described in this application.
[0156] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus embodiments, since they are fundamentally similar to the method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0157] The above provides a detailed description of a real-time operating system monitoring method, apparatus, electronic device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. 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 this application. Therefore, the content of this specification should not be construed as a limitation of this application.
[0158] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
Claims
1. A real-time operating system monitoring method, characterized in that, The method includes: Obtain the last execution time of the target core monitoring thread from shared memory. The target core is a core in the multi-core processor other than the current core, and the current core is a core in the multi-core processor. Based on the last running time, determine whether the target core is a faulty core; If the target core is a faulty core, the monitoring data of the faulty core is obtained from the shared memory and the monitoring data is output.
2. The method according to claim 1, characterized in that, The step of determining whether the target core is a faulty core based on the last running time includes: If the target core is a sub-core, and the time interval between the last running time and the current time is greater than or equal to the first target duration, the target core is determined to be a faulty core.
3. The method according to claim 1 or 2, characterized in that, The step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data includes: When the current core is the main core and the faulty core is the child core, the main core is used to obtain the monitoring data of the faulty core from the shared memory and output the monitoring data.
4. The method according to any one of claims 1-3, characterized in that, Also includes: When the current core monitoring thread is running, the current running time of the current core monitoring thread is recorded in the shared memory.
5. The method according to any one of claims 1-4, characterized in that, Also includes: When the current core monitoring thread is running, the monitoring data of the current core is written to the shared memory.
6. The method according to any one of claims 1-5, characterized in that, Before retrieving the monitoring data of the faulty core from the shared memory, the method further includes: When the current core is a sub-core, if the faulty core is the master core, then a competition for the master core is initiated. The step of obtaining monitoring data of the faulty core from the shared memory and outputting the monitoring data includes: When the current core becomes the new master core, the monitoring data of the faulty core is obtained from the shared memory using the new master core, and the monitoring data is output.
7. The method according to claim 6, characterized in that, The step of obtaining the last execution time of the target core monitoring thread from shared memory includes: When the current core is used as a sub-core, the last execution time of the main core monitoring thread is obtained from the shared memory; The step of determining whether the target core is a faulty core based on the last running time includes: If the time interval between the last run time of the main core monitoring thread and the current time is greater than or equal to the second target duration, the main core is determined to be a faulty core.
8. The method according to claim 6, characterized in that, Following the operation of initiating contention for the main core, the following is also included: If other sub-cores simultaneously initiate operations to compete for the main core, then based on the election algorithm, one sub-core is elected from among the competing sub-cores to become the new main core.
9. The method according to claim 8, characterized in that, After the election algorithm is used to elect a sub-core from among the competing sub-cores to become the new main core, the process further includes: Update the value of the main core variable in shared memory to the identifier of the new main core.
10. A real-time operating system monitoring device, characterized in that, The device includes: The runtime acquisition module is used to acquire the last runtime of the target core monitoring thread from shared memory. The target core is a core in a multi-core processor other than the current core, and the current core is a core in the multi-core processor. The fault core determination module is used to determine whether the target core is a fault core based on the last running time. The monitoring data output module is used to obtain monitoring data of the faulty core from the shared memory and output the monitoring data when the target core is a faulty core.
11. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the real-time operating system monitoring method according to any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the real-time operating system monitoring method according to any one of claims 1 to 9.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the real-time operating system monitoring method according to any one of claims 1 to 9.
