Kernel soft lock monitoring and dynamic optimization method based on eBPF and electronic device
By embedding a soft lock information acquisition function in the operating system kernel and utilizing the eBPF mechanism, the soft lock problem caused by spin wait timeout is solved, enabling real-time monitoring and dynamic optimization of soft lock events, improving the system's self-healing capability and reliability, and reducing operational complexity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING LINX SOFTWARE CORP
- Filing Date
- 2025-12-23
- Publication Date
- 2026-06-09
Smart Images

Figure CN121858228B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of operating system technology, and in particular to a kernel soft lock monitoring and dynamic optimization method and electronic device based on eBPF. Background Technology
[0002] In the resource synchronization and hardware interaction system of modern operating system kernels, when a process or kernel thread needs to acquire critical resources such as shared locks or hardware signals, it will enter different waiting modes depending on the characteristics of the waiting scenario. Typical waiting modes include blocking wait and spin wait. In blocking wait mode, the thread actively releases the CPU and enters a sleep state until it is awakened by the kernel when the resource becomes available. Spin wait, on the other hand, is an efficient mechanism designed for scenarios of "short-term, high-frequency resource contention." During the waiting period, the thread does not release the CPU but continuously checks the resource status through a loop until the resource becomes available and then immediately resumes execution. The introduction of spin wait aims to reduce context switching overhead and improve system performance in scenarios with high requirements for resource response speed.
[0003] Spin wait, as a crucial component of kernel synchronization mechanisms, is designed based on the assumption of short-duration resource contention. In multi-core systems, this mechanism effectively avoids unnecessary thread switching, thereby improving the execution efficiency of critical paths. However, the implementation characteristics of spin wait also severely limit its applicability: if the resource holding time exceeds expectations, or if deadlocks or hardware response anomalies occur, the waiting thread will enter a long busy-wait loop, continuously occupying CPU resources and unable to perform effective work. Especially in server systems where kernel preemption is disabled to ensure low latency, the spin thread will completely dominate its CPU core, preventing that core from scheduling any other tasks, leading to severe local or even global system unresponsiveness. The kernel uses a watchdog mechanism to uniformly diagnose such CPU scheduling stagnation as a "soft lockup" event. Spin wait timeout is the most common and typical trigger for soft lockups, but it is not the only cause; kernel infinite loops, excessively long critical sections, etc., can also lead to similar symptoms. Existing mechanisms for responding to soft locks remain at a uniform passive alarm level, lacking precise handling capabilities.
[0004] Currently, the management and monitoring mechanisms for spin waits in operating system kernels are relatively basic, mainly relying on critical section conditions preset by developers. Timeouts may trigger warnings or degradation processing. However, in scenarios where preemption is prohibited, even if a spin timeout occurs, the thread cannot be forcibly scheduled out, and the system lacks the ability to dynamically adjust spin behavior and alleviate CPU waste at runtime. Furthermore, spin waits typically occur in kernel mode, and their root causes are often closely related to user-mode business logic and call paths. However, existing kernel logs and debugging tools, when recording spin wait events, can usually only capture kernel-mode call stack information, making it difficult to automatically correlate and trace back to the user-mode process and its call context that caused the contention. This poses a significant obstacle to problem localization and root cause analysis.
[0005] Existing technologies for handling soft lock events (especially long-term spin waits) suffer from two main problems: First, they lack a runtime dynamic recovery mechanism. In low-latency systems with preemption disabled, abnormal threads can cause CPU cores to be permanently occupied, requiring a restart for recovery and resulting in severe business interruptions. Second, they lack the ability to trace user-mode call chains. Kernel logs for soft lock events cannot automatically capture the complete user-mode stack information that triggered the contention, forcing troubleshooting to be done manually across different levels, leading to inefficient localization and difficulty in guiding business optimization. Summary of the Invention
[0006] Based on the above analysis, the embodiments of the present invention aim to provide a kernel soft lock monitoring and dynamic optimization method and electronic device based on eBPF, in order to solve the problem that existing systems are prone to permanent CPU freezes and the root cause of the fault is difficult to locate when encountering spin anomalies.
[0007] On one hand, embodiments of the present invention provide a kernel soft lock monitoring and dynamic optimization method based on eBPF, including the following steps:
[0008] A soft lock information acquisition function is implanted into the operating system kernel, and the constructed eBPF program is mounted to the entry point of the soft lock information acquisition function based on the eBPF mechanism to form a monitoring hook;
[0009] When a soft lock event occurs in the kernel, the soft lock information acquisition function is called, triggering the monitoring hook to execute the eBPF program;
[0010] The eBPF program collects the context information of the soft lock event and transmits the context information to the user space through eBPF mapping;
[0011] The user-space program receives and parses the context information, and dynamically adjusts the kernel scheduling mode based on the parsing results.
[0012] Furthermore, the dynamic adjustment of the kernel scheduling mode based on the parsing results includes:
[0013] Based on the analysis results, determine whether the soft lock was triggered by a spin wait timeout. If so, enable the kernel's global preemptive mode. Simultaneously, acquire the process that triggered the soft lock and start periodic monitoring of the kernel-mode CPU utilization of that process.
[0014] When the kernel-mode CPU utilization of the process is detected to be lower than a preset threshold, the kernel global preemptive mode is disabled.
[0015] Furthermore, the on-site information includes: the process ID, process name, CPU ID, kernel-mode call stack information, and user-mode call stack information that triggered the soft lock timeout event;
[0016] If the kernel-mode call stack information contains a spinlock operation function, then the soft lock is determined to be caused by a spin wait timeout.
[0017] Furthermore, the soft lock information acquisition function is a preset function embedded in the kernel soft lock detection path, which is called when the kernel soft lock event is confirmed, and provides the eBPF program with a mounting entry point and a key context access interface.
[0018] Furthermore, the eBPF is mapped as a circular buffer; the eBPF program calls bpf_ringbuf_reserve to reserve buffer space and fill it with the field information, and then calls bpf_ringbuf_submit for transmission; the user-space program asynchronously receives the field information by associating it with the circular buffer and setting a callback function.
[0019] Furthermore, the periodic monitoring includes:
[0020] Read the kernel-mode CPU time consumption field of the process that triggered the soft lock at fixed intervals;
[0021] Calculate the difference of this field over two consecutive periods to obtain the CPU time consumed in kernel mode by the process that triggered the soft lock during the monitoring period;
[0022] The kernel-mode CPU utilization rate is obtained by the ratio of CPU time consumed to the monitoring cycle duration.
[0023] Furthermore, user-space programs enable the kernel's global preemptive mode by writing "full" to the / sys / kernel / debug / sched / preempt interface, and disable the kernel's global preemptive mode by writing "none".
[0024] Furthermore, the step of attaching the constructed eBPF program based on the eBPF mechanism to the entry point of the soft lock information acquisition function includes:
[0025] The constructed eBPF program is compiled, verified, and then loaded into the kernel;
[0026] By utilizing the kernel's kprobe mechanism, a jump instruction is inserted at the assembly entry point of the soft lock information acquisition function; when the soft lock information acquisition function is called, the CPU prioritizes jumping to execute the eBPF program.
[0027] Furthermore, if the soft lock is not triggered by a spin wait timeout, then the kernel global preemptive mode is enabled, and an alarm message is output based on the parsing result.
[0028] On the other hand, embodiments of the present invention provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor; the processor executes the computer program to implement the above-described method.
[0029] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:
[0030] This invention provides a kernel soft lock monitoring and dynamic optimization method and electronic device based on eBPF. Through eBPF technology, it can simultaneously collect full-scale context information, including the complete kernel and user-mode call stacks, the moment a soft lock occurs. This overcomes the pain points of traditional mechanisms, such as fragmented diagnostic information and difficulty in tracing the source. It achieves accurate and automated identification of the root cause of soft locks, enabling real-time, accurate monitoring and intelligent handling of kernel soft lock events. It transforms the traditional passive and fragmented alarm mechanism into an active, closed-loop management system. After confirming a soft lock, it automatically improves system preemptibility to ensure responsiveness. Based on continuous monitoring of the kernel-mode utilization of the target process, it automatically reduces scheduling overhead after recovery. This allows the system to automatically enhance resilience during anomalies and automatically return to its optimal performance state after recovery, significantly improving system reliability and self-healing capabilities while greatly reducing operational complexity.
[0031] In this invention, the above-described technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of this invention will be set forth in the following description, and some advantages may become apparent from the description or be learned by practicing the invention. The objects and other advantages of this invention can be realized and obtained from what is particularly pointed out in the description and drawings. Attached Figure Description
[0032] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts.
[0033] Figure 1This is a flowchart illustrating the kernel soft lock monitoring and dynamic optimization method based on eBPF provided in Embodiment 1 of the present invention;
[0034] Figure 2 This is a schematic diagram of the architecture of the kernel soft lock monitoring and dynamic optimization method based on eBPF provided in Embodiment 1 of the present invention. Detailed Implementation
[0035] Preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, which form part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not intended to limit the scope of the present invention.
[0036] Current technologies can only output alarm logs for soft lock events, lacking the ability to actively intervene at runtime. In environments where preemption is disabled, even if a soft lock is detected, the system lacks a mechanism to dynamically adjust scheduling policies (such as temporarily enabling full preemption) to restore CPU scheduling capabilities and prevent fault propagation. Recovery often relies solely on a reboot, leading to service interruptions. The root cause of a soft lock may originate from specific user-mode business logic, but standard kernel alarms only provide kernel-mode call stack fragments, failing to automatically and completely capture and correlate the complete user-mode call chain that triggered the kernel contention. This forces operations personnel to perform time-consuming, cross-layer manual reasoning, resulting in inefficient fault location and difficulty in guiding business-level optimization. Even if the system possesses some recovery capability (such as manual intervention), it lacks continuous quantitative monitoring of the subsequent behavior of abnormal processes (such as kernel-mode CPU utilization). Consequently, it cannot scientifically determine when the system has recovered from the anomaly and automatically rescind temporary control measures, failing to achieve a dynamic balance between security and performance.
[0037] In summary, existing technologies for handling soft lock events remain at the post-event recording level, lacking a closed-loop management system that integrates real-time triggering, on-site snapshots, proactive control, intelligent diagnosis, and feedback recovery. This results in weak system recovery capabilities, difficulty in fault location, and a heavy maintenance burden when facing such severe anomalies. Therefore, this embodiment provides a kernel soft lock monitoring and dynamic optimization method based on eBPF, which can monitor soft locks and dynamically optimize soft lock events, especially those caused by spin wait timeouts.
[0038] Example 1
[0039] A specific embodiment of the present invention discloses a kernel soft lock monitoring and dynamic optimization method based on eBPF, such as... Figure 1 and Figure 2 As shown, it includes the following steps:
[0040] S1. Implant a soft lock information acquisition function into the operating system kernel, and attach the constructed eBPF program to the entry point of the soft lock information acquisition function based on the eBPF mechanism to form a monitoring hook.
[0041] Specifically, the soft lock information acquisition function is a preset function embedded in the kernel soft lock detection path, which is called when the kernel soft lock event is confirmed, and provides the eBPF program with a mounting entry point and a key context access interface.
[0042] More specifically, the soft lock information acquisition function is embedded into the kernel's watchdog detection callback execution path.
[0043] During implementation, the constructed eBPF program is attached to the entry point of the soft lock information acquisition function based on the eBPF mechanism, including:
[0044] S11. Compile and verify the built eBPF program, then load it into the kernel.
[0045] Specifically, the user space submits the compiled eBPF kernel-mode program to the kernel through the libbpf library. The kernel verifier will verify the security and legality of the program to ensure that it does not have the risk of malicious logic or resource overruns.
[0046] S12. Using the kernel's kprobe mechanism, a jump instruction is inserted at the assembly entry point of the soft lock information acquisition function; when the soft lock information acquisition function is called, the CPU prioritizes jumping to execute the eBPF program.
[0047] Specifically, the user space sends a mount request to the kernel space, and the kernel inserts an eBPF program trigger point (jump instruction) at the assembly entry point of the function soft lock information acquisition function, thereby completing the hooking.
[0048] S2. When a soft lock event occurs in the kernel, the soft lock information acquisition function is called to trigger the monitoring hook to execute the eBPF program.
[0049] Specifically, during system operation, if a process on a CPU causes the watchdog to time out due to specific factors (such as an infinite loop or a long-term spinlock), the system will call a callback function, which will then trigger the execution of the soft lock information acquisition function. Once the soft lock information acquisition function is executed, the inserted jump instruction will take effect immediately, and the CPU will then switch to executing the mounted eBPF program.
[0050] S3. The eBPF program collects the on-site information of the soft lock event and transmits the on-site information to the user space through eBPF mapping.
[0051] During implementation, the on-site information includes: the process ID, process name, CPU ID, kernel-mode call stack information, and user-mode call stack information of the process that triggered the soft lock timeout event.
[0052] Specifically, the eBPF program first parses the parameters of the soft lock information acquisition function, which contains key information passed by the watchdog, namely which process is suspected of having a soft lock on which CPU; the eBPF program uses kernel helper functions (such as bpf_get_current_comm) to obtain the name of the process.
[0053] Specifically, `bpf_get_stack` retrieves kernel-mode and user-mode call stack information. When this function is called in an eBPF program, it returns an array containing call stack frames. Each element in the array represents information about a call stack frame, such as function address and offset. By parsing this information, the call path at the time of the soft lock event can be reconstructed, helping developers quickly locate the root cause of the problem. Furthermore, the `bpf_get_stack` function supports setting stack depth limits to avoid acquiring excessive useless information and improve the efficiency of information collection.
[0054] In implementation, the eBPF is mapped as a ring buffer; the eBPF program calls bpf_ringbuf_reserve to reserve buffer space and fill the field information, and then calls bpf_ringbuf_submit for transmission; the user-space program asynchronously receives the field information by associating with the ring buffer and setting a callback function.
[0055] Specifically, after the eBPF program completes information collection, it calls bpf_ringbuf_reserve to allocate a memory space of appropriate size in the ring buffer (ringbuf); it packages all the collected field information into this reserved space according to a predefined structure format; and finally calls bpf_ringbuf_submit to submit the data.
[0056] S4. The user-mode program receives and parses the context information, and dynamically adjusts the kernel scheduling mode based on the parsing results.
[0057] Specifically, the user-mode program establishes an association with the kernel's ring buffer in another thread and sets up a callback function; when the kernel submits new data, this callback function is automatically triggered; the user-mode program reads the raw data packet from the ring buffer and parses it according to the agreed format, restoring it into readable information.
[0058] Specifically, after parsing the field information, the user-space program first converts the field information into a readable format and outputs it to the log or console, and then makes dynamic adjustments.
[0059] In implementation, the dynamic adjustment of the kernel scheduling mode based on the parsing results includes:
[0060] Based on the analysis results, determine whether the soft lock was triggered by a spin wait timeout. If so, enable the kernel's global preemptive mode. Simultaneously, acquire the process that triggered the soft lock and start periodic monitoring of the kernel-mode CPU utilization of that process.
[0061] When the kernel-mode CPU utilization of the process is detected to be lower than a preset threshold, the kernel global preemptive mode is disabled.
[0062] Specifically, if the kernel-mode call stack information in the context information contains a spinlock operation function, then the soft lock is determined to be caused by a spin wait timeout.
[0063] Specifically, the threshold for kernel-mode CPU utilization is set according to specific needs; for example, the threshold is set to 90%.
[0064] In specific implementation, the periodic monitoring includes:
[0065] Read the kernel-mode CPU time consumption field of the process that triggered the soft lock at fixed intervals;
[0066] Calculate the difference of this field over two consecutive periods to obtain the CPU time consumed in kernel mode by the process that triggered the soft lock during the monitoring period;
[0067] The kernel-mode CPU utilization rate is obtained by the ratio of CPU time consumed to the monitoring cycle duration.
[0068] Specifically, the cycle is set according to specific needs; for example, the cycle is set to 5 seconds.
[0069] In practice, user-space programs enable the kernel's global preemptive mode by writing "full" to the / sys / kernel / debug / sched / preempt interface, and disable the kernel's global preemptive mode by writing "none".
[0070] Preferably, in this embodiment, the following dynamic scheduling method may also be used:
[0071] Based on the analysis results, determine whether the soft lock was triggered by a spin wait timeout. If so, enable the kernel's global preemptive mode. Simultaneously, acquire the process that triggered the soft lock and initiate periodic monitoring of that process and the system.
[0072] When the preset first condition is met, a preset observation period begins, during which the system's stability and performance indicators are continuously monitored.
[0073] If no anomalies are observed during the observation period and the stability assessment is passed, then the kernel global preemptive mode is disabled.
[0074] If abnormal system indicators are detected during the observation period, the kernel global preemptive mode will remain enabled, and the process will return to the start periodic monitoring step.
[0075] Specifically, the first condition is that the kernel-mode CPU utilization of the monitoring process is lower than a first threshold for multiple consecutive monitoring cycles.
[0076] Specifically, the duration of the observation period is dynamically adjusted based on the historical frequency of soft lock events, and the observation period is automatically extended for events that have occurred repeatedly recently.
[0077] Specifically, the monitored system stability and performance indicators include process scheduling latency, recurrence of soft lock events, and changes in response latency of critical system calls.
[0078] Specifically, the stability assessment adopts a multi-dimensional weighted scoring mechanism, including stability, performance, and scheduling health dimensions. When the comprehensive score exceeds the passing threshold, the assessment is deemed to have passed.
[0079] Preferably, when multiple processes trigger soft lock events simultaneously, a global coordination strategy is adopted to always maintain the kernel scheduling mode at the highest preemption level required by all processes.
[0080] Understandably, in this embodiment, dynamic adjustment can automatically initiate preemption in emergencies to restore system response. While ensuring system resilience, it minimizes scheduling overhead, significantly improves the system's self-healing ability in the face of anomalies, and transforms the operation and maintenance mode from post-event manual rescue to in-event automatic handling and pre-event trend prevention, greatly enhancing the availability and maintainability of high-load or low-latency critical business environments.
[0081] During implementation, if the soft lock is not triggered by a spin wait timeout, the kernel global preemptive mode is enabled, and an alarm message is output based on the parsing result.
[0082] Specifically, based on the kernel-mode and user-mode call stacks of the soft lock event, the specific type of soft lock that triggered it is determined.
[0083] If the soft lock is caused by a kernel infinite loop, enable the kernel's global preemptive mode; at the same time, send a SIGSTOP signal to the problematic process to forcibly suspend its execution, and optionally trigger a kernel dump to save the complete situation for offline in-depth analysis;
[0084] If the soft lock is caused by an interrupt shutdown, the system marks it as a high-priority emergency event and enables the kernel's global preemptive mode. At the same time, it can also attempt to wake up the stuck CPU core through non-maskable interrupts (NMI) and immediately push the highest-level alarm to the operation and maintenance platform.
[0085] If the software lock is caused by a hardware timeout, enable the kernel's global preemptive mode; at the same time, record the relevant hardware device identifiers and status in detail, and explicitly recommend performing recovery operations such as device reset or driver reload in the alarm.
[0086] Furthermore, after the response is executed, the system does not passively wait but initiates an intelligent recovery monitoring mechanism centered on process status. Monitoring targets include whether the process has exited or entered an interruptible sleep state, and it establishes security timeout and manual confirmation interfaces to form a controllable recovery loop. In addition, it automatically circuit breakers, downgrades, or isolates specific code paths that frequently trigger soft locks to prevent repeated occurrences and spread of faults. Simultaneously, by building and continuously improving a historical case knowledge base, the system can perform similarity comparisons when new events occur, recommending proven solutions to operations personnel, thereby achieving a shift from emergency response to preventative optimization.
[0087] Specifically, in this embodiment, the user space is responsible for loading and verifying the eBPF program, parsing data, controlling the scheduling mode, and detecting CPU utilization. These are sequentially connected through a "trigger-execution" logic to form a closed-loop control flow. The kernel space is responsible for mounting the kprobe hook and collecting soft lock context information. It establishes a one-way data transmission channel with the user space through the ringbuf mechanism to ensure efficient and low-latency transmission of collected data. There are only two data transmission channels between the user space and the kernel space: "kernel space → user space" (based on eBPF ringbuf) and "user space → kernel space" (based on libbpf API). There are no redundant connections, ensuring clear data flow and minimal system overhead.
[0088] It should be noted that the entire process described above in this embodiment can be a continuously running daemon process; when it needs to be stopped, the user-space program will perform cleanup work: first, it will turn off the timer, then send an instruction to the kernel to unload the kprobe hook, and finally unload the eBPF program and close the ring buffer, releasing all occupied system resources.
[0089] Compared with existing technologies, this embodiment provides a kernel soft lock monitoring and dynamic optimization method based on eBPF. Through eBPF technology, full-scale context information, including the complete kernel and user-mode call stack, can be collected simultaneously at the moment a soft lock occurs. This overcomes the pain points of fragmented diagnostic information and difficulty in tracing the source in traditional mechanisms, achieving accurate and automated identification of the root cause of soft locks. It enables real-time, accurate monitoring and intelligent handling of kernel soft lock events, transforming the traditional passive and fragmented alarm mechanism into an active and closed-loop management system. After confirming a soft lock, the system automatically improves preemptibility to ensure responsiveness. Based on continuous monitoring of the kernel-mode utilization of the target process, the system automatically reduces scheduling overhead after recovery. This allows the system to automatically enhance resilience when anomalies occur and automatically return to the optimal performance state after recovery, significantly improving the system's reliability and self-healing capabilities and greatly reducing operational complexity.
[0090] Example 2
[0091] Another specific embodiment of the present invention discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor; when the processor executes the computer program, it implements the method described in Embodiment 1.
[0092] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.
[0093] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.
Claims
1. A kernel soft lock monitoring and dynamic optimization method based on eBPF, characterized in that, Includes the following steps: A soft lock information acquisition function is implanted into the operating system kernel, and the constructed eBPF program is mounted to the entry point of the soft lock information acquisition function based on the eBPF mechanism to form a monitoring hook; When a soft lock event occurs in the kernel, the soft lock information acquisition function is called, triggering the monitoring hook to execute the eBPF program; The eBPF program collects the context information of the soft lock event and transmits the context information to the user space through eBPF mapping; The user-space program receives and parses the context information, and dynamically adjusts the kernel scheduling mode based on the parsing results; including: Based on the analysis results, determine whether the soft lock is caused by a spin wait timeout. If so, enable the kernel's global preemptive mode. Simultaneously, acquire the process that triggered the soft lock and initiate periodic monitoring of the kernel-mode CPU utilization of that process: When the kernel-mode CPU utilization of the process is detected to be lower than a preset threshold, the kernel global preemptive mode is disabled.
2. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, The on-site information includes: the process ID, process name, CPU ID, kernel-mode call stack information, and user-mode call stack information that triggered the soft lock timeout event; If the kernel-mode call stack information contains a spinlock operation function, then the soft lock is determined to be caused by a spin wait timeout.
3. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, The soft lock information acquisition function is a preset function embedded in the kernel soft lock detection path. It is called when the kernel soft lock event is confirmed and provides the eBPF program with a mounting entry point and a key context access interface.
4. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, The eBPF is mapped as a ring buffer; the eBPF program calls bpf_ringbuf_reserve to reserve buffer space and fill it with the field information, and then calls bpf_ringbuf_submit for transmission; the user-space program asynchronously receives the field information by associating it with the ring buffer and setting a callback function.
5. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, The periodic monitoring includes: Read the kernel-mode CPU time consumption field of the process that triggered the soft lock at fixed intervals; Calculate the difference of this field over two consecutive periods to obtain the CPU time consumed in kernel mode by the process that triggered the soft lock during the monitoring period; The kernel-mode CPU utilization rate is obtained by the ratio of CPU time consumed to the monitoring cycle duration.
6. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, User-space programs enable kernel-wide preemptive mode by writing "full" to the / sys / kernel / debug / sched / preempt interface; and disable kernel-wide preemptive mode by writing "none".
7. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, The process of attaching the constructed eBPF program based on the eBPF mechanism to the entry point of the soft lock information acquisition function includes: The constructed eBPF program is compiled, verified, and then loaded into the kernel; By utilizing the kernel's kprobe mechanism, a jump instruction is inserted at the assembly entry point of the soft lock information acquisition function; when the soft lock information acquisition function is called, the CPU prioritizes jumping to execute the eBPF program.
8. The kernel soft lock monitoring and dynamic optimization method based on eBPF according to claim 1, characterized in that, If the soft lock is not triggered by a spin wait timeout, then enable the kernel's global preemptive mode and output an alarm message based on the parsing result.
9. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor; when the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Kernel preemption switching method and computing device
CN118012612A
Soft lock detection analysis method and system based on ebpf, medium and product
CN120821530A