A spinlock deadlock detection method of a multi-core operating system
By employing a multi-core operating system spinlock deadlock detection method, the problem of spinlock deadlock detection was solved, achieving efficient and accurate deadlock detection and problem feedback, thus ensuring stable system operation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIAN AVIATION COMPUTING TECH RES INST OF AVIATION IND CORP OF CHINA
- Filing Date
- 2022-12-15
- Publication Date
- 2026-05-15
AI Technical Summary
Spinlock deadlock in multi-core operating systems is difficult to detect effectively, causing processor cores to wait for each other and become unable to run. Deadlock is particularly unavoidable in critical software with high real-time requirements.
A spinlock deadlock detection method for multi-core operating systems is designed. The method obtains the processor core set, extracts the core set to be detected, determines the spinlock state and reports the deadlock result, and uses a bitmap coloring method to mark the core state to ensure the efficiency and accuracy of detection.
It achieves efficient and accurate detection of spinlock deadlocks, promptly identifies and reports deadlocked processor cores and their waiting spinlocks, ensuring normal system operation.
Smart Images

Figure CN116107766B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer system software design technology, specifically to a method for detecting spinlock deadlock in a multi-core operating system. Background Technology
[0002] The development of multi-core operating systems currently lags behind that of multi-core processors. Synchronization and mutual exclusion among multiple cores are key challenges in multi-core operating system research. Mutual exclusion mechanisms among multiple cores mainly include atomic operations, spinlocks, memory fences, and mutex semaphores. Among these, while spinlocks provide global resource protection, they also introduce uncertain waiting problems, which can lead to spinlock deadlocks.
[0003] Spinlock deadlock occurs in a multi-core operating system when two or more processor cores are locked in a wait-and-see state while competing for a spinlock. Without external intervention, these cores cannot continue running. In critical software with high real-time requirements, it is essential to prevent processor cores from entering a deadlock state.
[0004] Currently, effective methods for preventing deadlocks at the operating system level include deadlock avoidance. Spin lock deadlock avoidance strategies strictly limit the use of spin locks by the operating system, thus preventing deadlocks caused by spin locks. However, in complex user application scenarios, deadlock avoidance measures may not meet application requirements. In such cases, a method for spin lock deadlock detection is needed. Summary of the Invention
[0005] In order to detect and determine whether there is a spinlock deadlock in a multi-core operating system and report it in a timely manner to avoid the continuous occurrence of spinlock deadlock and ensure the normal operation of the multi-core operating system, this invention designs a spinlock deadlock detection method for multi-core operating systems.
[0006] The technical solution to achieve the purpose of the invention is as follows: A method for detecting spinlock deadlock in a multi-core operating system, comprising the following steps:
[0007] S1. Obtain the processor core set of the operating system;
[0008] S2. Based on the spinlock information to be acquired, extract the core set to be detected from the processor core set;
[0009] S3. Determine whether the kernel set to be detected is empty;
[0010] If empty, then there is no deadlock in the processor core of the operating system;
[0011] If not empty, then there is a deadlock in the processor core of the operating system, and S4 is entered and executed;
[0012] S4. Randomly select a processor core from the set of cores to be detected as the current core;
[0013] S5. Based on the spinlock information to be acquired and the set of acquired spinlocks, determine whether the current kernel is in a deadlock state;
[0014] If the current kernel is determined to be in a deadlock state, the deadlock result is reported.
[0015] If it is determined that the current kernel is not in a deadlock state, then proceed to and execute S6;
[0016] S6. Delete the current core, and repeat steps S4 to S5 until all processor cores in the core set to be detected have been detected.
[0017] In one embodiment, in step S1 above, the processor core set of the operating system is all enabled processor cores, and the enabled processor cores are marked as 1.
[0018] In another embodiment, in step S1 above, the processor core set of the operating system includes enabled processor cores and disabled processor cores, wherein the enabled processor cores are marked as 1 and the disabled processor cores are marked as 0.
[0019] In an improved embodiment of the above embodiments, step S2, the method for extracting the set of cores to be detected from the processor core set based on the spinlock information to be acquired, includes:
[0020] S201. Obtain the variables of each processor core in the processor core set;
[0021] S202. Extract the spinlock information to be obtained from the variables;
[0022] S203. Remove processor cores from the processor core set that do not correspond to the spinlock information to be acquired, and form the core set to be detected.
[0023] In an improved embodiment of the above embodiments, the method for determining whether the current core is in a deadlock state based on the spinlock information to be acquired and the acquired spinlock set in step S5 includes:
[0024] S501. Obtain the spinlock information to be acquired for the current core in the core set to be detected, and obtain the acquired spinlock set for the remaining processor cores;
[0025] S502. Based on the acquired spinlock set, determine the spinlock information to be acquired;
[0026] S503. If the spinlock information to be acquired is not in the set of acquired spinlocks, then the current core is determined to be in a deadlock state; if the spinlock information to be acquired is in the set of acquired spinlocks, then the current core is determined to be in a deadlock state.
[0027] In one embodiment, the spinlock deadlock detection method for a multi-core operating system further includes step S0, which defines a variable for each processor core in the operating system. The variable includes the spinlock information to be acquired and the set of acquired spinlocks, wherein the set of acquired spinlocks includes the spinlocks already acquired by the processor core.
[0028] Compared with the prior art, the beneficial effects of the present invention are as follows: The spinlock deadlock detection method for multi-core operating systems designed in this invention has the advantages of high efficiency, accuracy, simplicity and convenience. It can detect whether a deadlock caused by acquiring a spinlock has occurred when the system is stagnant, as well as the processor core that caused the deadlock and the spinlock that the processor core is waiting to acquire. This allows for early detection and feedback of problems, enabling users to take corresponding deadlock-resolving measures based on the feedback deadlock results (including the processor core that caused the deadlock and the spinlock it is waiting to acquire), thereby ensuring the continued operation of the system. Attached Figure Description
[0029] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below.
[0030] Figure 1 This is a flowchart of a spinlock deadlock detection method for a multi-core operating system in a specific implementation method. Detailed Implementation
[0031] The present invention will be further described below with reference to specific embodiments, and the advantages and features of the present invention will become clearer as a result. However, these embodiments are merely exemplary and do not constitute any limitation on the scope of the present invention. Those skilled in the art should understand that modifications or substitutions can be made to the details and form of the technical solutions of the present invention without departing from the spirit and scope of the present invention, but all such modifications and substitutions fall within the protection scope of the present invention.
[0032] Multi-core operating systems include two or more processor cores, and each processor core uses a spinlock for mutual exclusion protection. In order to avoid deadlock caused by two or more processor cores waiting for the same spinlock, which would lead to the stagnation of the operating system, this specific embodiment discloses a spinlock deadlock detection method for multi-core operating systems.
[0033] Before performing spinlock deadlock detection, the operating system of this invention defines a waiting spinlock core set bitmap, with each processor core corresponding to one bit. When the operating system powers on and runs, the waiting spinlock core set bitmap is initialized, setting each processor core's bit to 0. Simultaneously, a variable is defined for each processor core in the operating system (i.e., step S0). This variable includes the spinlock information to be acquired and the set of acquired spinlocks for each processor core. The set of acquired spinlocks includes the spinlocks already acquired by the processor core. Specifically, before acquiring a spinlock, the spinlock ID is stored in the waiting spinlock set member of the variable of the processor core running the current detection program; after successfully acquiring the spinlock, the spinlock ID is stored in the acquired spinlock set member, and the spinlock in the waiting spinlock set is cleared; when releasing the spinlock, the information of the spinlock in the acquired spinlock set is cleared.
[0034] See Figure 1 As shown, the spinlock deadlock detection method for a multi-core operating system includes the following steps:
[0035] S1. Obtain the processor core set of the operating system.
[0036] In this specific embodiment, since there are enabled processor cores and disabled processor cores in a multi-core processor, and when running the spinlock deadlock detection program, there are currently detected processor cores, detected processor cores, and undetected processor cores, in order to distinguish the different states of the above processor cores, the present invention uses a bitmap coloring method to mark each processor core in the processor core set.
[0037] For example, in one embodiment of this step, the processor core set of the operating system includes enabled processor cores and disabled processor cores. In this processor core set, enabled processor cores are marked as 1 and disabled processor cores are marked as 0.
[0038] For example, in another embodiment of this step, the operating system's processor core set extracts only the enabled processor cores according to the system configuration and marks the enabled processor cores as 1.
[0039] S2. Based on the spinlock information to be acquired, extract the core set to be detected from the processor core set.
[0040] In this step, since only the processor cores in the spinlock waiting to be acquired may experience deadlock, and not every processor core in the processor core set acquired in step S1 is in the spinlock waiting state, it is necessary to extract the processor cores in the spinlock waiting state from the processor core set to form the core set to be detected.
[0041] The method for extracting the kernel set to be detected in this step includes the following steps:
[0042] S201. Obtain the variables of each processor core in the processor core set;
[0043] S202. Extract the spinlock information to be obtained from the variables;
[0044] S203. Remove processor cores from the processor core set that do not correspond to the spinlock information to be acquired, and form the core set to be detected.
[0045] In this step, a bitmap coloring method is used to mark all processor cores in the core set to be detected as 1, and mark all other processor cores in the core set except the core set to be detected as 0.
[0046] The core set to be tested formed by the above steps S201 to S203 may contain no processor cores or may contain one or more processor cores, requiring further judgment using the following step S3.
[0047] S3. Determine whether the kernel set to be detected is empty;
[0048] If the value is empty, it is determined that there is no processor core in the core set to be detected that has a spinlock to acquire. Therefore, there is no deadlock in the processor cores of the operating system, and the spinlock deadlock detection can be terminated.
[0049] If it is not empty, it is determined that there is at least one processor core in the core set to be detected that is waiting to acquire a spinlock. If so, there is a deadlock in the processor core in the operating system, and S4 is entered and executed.
[0050] S4. Randomly select a processor core from the set of cores to be detected as the current core.
[0051] S5. Based on the spinlock information to be acquired and the set of acquired spinlocks, determine whether the current kernel is in a deadlock state.
[0052] If the current core is determined to be in a deadlock state, the deadlock result (including the processor core that is deadlocked and the spinlock it is waiting to acquire) is reported, and the current core is marked as 0 using a bitmap coloring method.
[0053] If it is determined that the current kernel is not in a deadlock state, then proceed to and execute S6.
[0054] In one embodiment of this step, the method for determining whether the current kernel is in a deadlock state includes:
[0055] S501. Obtain the spinlock information to be acquired for the current core in the core set to be detected, and obtain the acquired spinlock set for the remaining processor cores;
[0056] S502. Based on the acquired spinlock set, determine the spinlock information to be acquired;
[0057] S503. If the spinlock information to be acquired is in the set of acquired spinlocks, then the current core is determined to be in a deadlock state.
[0058] If the spinlock information to be acquired is not in the set of acquired spinlocks, then the current core is determined not to be in a deadlock state, and the current core is in a normal operating state.
[0059] S6. Delete the current core, and repeat steps S4 to S5 until all processor cores in the core set to be detected have been detected.
[0060] In this step, a bitmap coloring method is used to mark the deleted current kernel as 0, indicating that the current kernel has been detected.
[0061] The spinlock deadlock detection method for multi-core operating systems designed in this invention has the advantages of high efficiency, accuracy, simplicity and convenience. It can detect whether a deadlock caused by acquiring a spinlock has occurred when the system is stalled, as well as the processor core that caused the deadlock and the spinlock that the processor core is waiting to acquire. This allows for early detection and feedback of problems, enabling users to take corresponding deadlock-resolving measures based on the feedback results (including the processor core that caused the deadlock and the spinlock it is waiting to acquire), thereby ensuring the continued operation of the system.
[0062] This specific embodiment also discloses a computer 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 above-described spinlock deadlock detection method for a multi-core operating system.
[0063] This specific embodiment also discloses a computer-readable storage medium storing a spinlock deadlock detection method for the aforementioned multi-core operating system.
[0064] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
[0065] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
Claims
1. A method for detecting spinlock deadlock in a multi-core operating system, characterized in that, Includes the following steps: S1. Define a variable for each processor core in the operating system. The variable includes spinlock information to be acquired and a set of acquired spinlocks. The set of acquired spinlocks includes spinlocks acquired by the processor core. Acquire the processor core set of the operating system, wherein the processor core set of the operating system consists of enabled processor cores, and the enabled processor cores are marked as 1. S2. Based on the spinlock information to be acquired, extract the core set to be detected from the processor core set. The bitmap coloring method is used to mark all processor cores in the core set to be detected as 1, and mark all other processor cores in the processor core set except the core set to be detected as 0. S3. Determine whether the kernel set to be detected is empty; If empty, then there is no deadlock in the processor core of the operating system; If not empty, then there is a deadlock in the processor core of the operating system, and S4 is entered and executed; S4. Randomly select a processor core from the set of cores to be detected as the current core; S5. Based on the spinlock information to be acquired and the set of acquired spinlocks, determine whether the current kernel is in a deadlock state; If the current kernel is determined to be in a deadlock state, the deadlock result is reported, and the current kernel is marked as 0 using a bitmap coloring method. If it is determined that the current kernel is not in a deadlock state, then proceed to and execute S6; S6. Delete the current core and mark the deleted current core as 0 using a bitmap coloring method. Repeat steps S4 to S5 until all processor cores in the core set to be detected have been detected.
2. The spinlock deadlock detection method according to claim 1, characterized in that: In step S1, the processor core set of the operating system includes enabled processor cores and disabled processor cores, wherein the enabled processor cores are marked as 1 and the disabled processor cores are marked as 0.
3. The spinlock deadlock detection method according to claim 1 or 2, characterized in that: In step S2, the method for extracting the set of cores to be detected from the processor core set based on the spinlock information to be acquired includes: S201. Obtain the variables of each processor core in the processor core set; S202. Extract the spinlock information to be obtained from the variables; S203. Remove processor cores from the processor core set that do not correspond to the spinlock information to be acquired, and form the core set to be detected.
4. The spinlock deadlock detection method according to claim 1 or 2, characterized in that: In step S5, the method for determining whether the current kernel is in a deadlock state based on the spinlock information to be acquired and the acquired spinlock set includes: S501. Obtain the spinlock information to be acquired for the current core in the core set to be detected, and obtain the acquired spinlock set for the remaining processor cores; S502. Based on the acquired spinlock set, determine the spinlock information to be acquired; S503. If the spinlock information to be acquired is not in the set of acquired spinlocks, then the current core is determined to be in a deadlock state; if the spinlock information to be acquired is in the set of acquired spinlocks, then the current core is determined to be in a deadlock state.