Deadlock detection method, device and related equipment
By combining the lock waiting chain and the RPC call chain to form an execution entity check chain, the problem of inaccurate deadlock detection in the operating system is solved, and the accuracy of deadlock detection and system security and reliability are improved.
Patent Information
- Application Number
- CN202110525149.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-13
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2041-05-13
AI Technical Summary
In the operating system, under the mechanism of separation of execution and scheduling, the accuracy of lock waiting chain inspection is not high, resulting in inaccurate deadlock detection, which may lead to inefficiency or failure of the system.
By combining the lock waiting chain and the RPC call chain for deadlock detection, an execution entity inspection chain is formed, the length of the detection chain is increased to improve the accuracy of deadlock detection, and data is processed in the kernel state and user state space to improve system security and reliability.
It improves the accuracy of deadlock detection, reduces data in kernel-state space, enhances the security and reliability of the system, rationally utilizes system resources, and can effectively detect and handle deadlocks.
Smart Images

Figure CN115344360B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of operating systems, and in particular to a deadlock detection method, apparatus, and related equipment. Background Art
[0002] In an operating system, when multiple threads are executed concurrently, there is a certain probability that two or more threads will wait for each other and stagnate, which is called deadlock. Deadlock will lead to low system efficiency and even cause operating system failure.
[0003] By checking the lock wait chain, it is possible to determine whether there is a deadlock in the operating system. Specifically, when the lock holder is the lock waiter, and a loop is formed between the lock holder and the lock waiter, it can be determined that a deadlock exists. For example, thread A owns lock A. Thread A is waiting for lock B. Thread B owns lock B. Thread B is waiting for lock A. At this time, thread A, the holder of lock A, is the waiter of lock B (abbreviated as AB), and thread B, the holder of lock B, is the waiter of lock A (abbreviated as BA). In addition, a loop (ABA) is formed between thread A and thread B.
[0004] In order to reduce the performance loss caused by inter-process communication (IPC), a mechanism of separation of execution and scheduling can be adopted. In the scenario of separation of execution and scheduling, threads are divided into two parts: execution entity and scheduling entity. The execution entity is located in the server process. The scheduling entity runs the execution entity by initiating a remote procedure call (RPC) to the server process.
[0005] In the mechanism of separation of execution and scheduling, the accuracy of lock waiting chain checking is not high. Specifically, when the lock holder is not the lock waiter, and there is no loop between the lock holder and the lock waiter, deadlock may still exist in the operating system. Summary of the invention
[0006] The present application provides a deadlock detection method, apparatus and related devices. By using a lock wait chain and an RPC call chain to perform deadlock detection, the accuracy of determining deadlock can be improved.
[0007] The first aspect of the present application provides a deadlock detection method. The deadlock detection method is applied to an operating system. The deadlock detection method includes: the operating system obtains a first RPC call chain of a first scheduling entity. The first RPC call chain includes information reflecting the calling relationship of execution entity A1 calling execution entity B1 (abbreviated as A1-B1). The operating system obtains a first lock waiting chain of a first server process. The first lock waiting chain includes information reflecting the waiting relationship of execution entity A2 waiting for execution entity A1 (abbreviated as A2-A1). Among them, execution entity A2 is the waiter of lock A, and execution entity A1 is the holder of lock A. If execution entity B1 is execution entity A2, or execution entity B1 and execution entity A2 have an association relationship, it is determined that a deadlock exists. Among them, the association relationship includes a calling relationship; or the association relationship includes a waiting relationship; or the association relationship includes a collection of calling relationships and waiting relationships.
[0008] In the present application, when the execution entity B1 and the execution entity A2 are associated, the associated relationship is abbreviated as B1-A2. At this time, the execution entity checks whether the chain A1-B1-A2-A1 forms a loop. The loop includes not only the lock waiting chain but also the RPC call chain. When the RPC call chain is missing, the loop cannot be established, that is, the existence of a deadlock cannot be determined by checking the lock waiting chain. Therefore, the present application can improve the accuracy of deadlock detection.
[0009] For the convenience of description, the concept of an execution entity check chain is introduced in this application. The starting point of the execution entity check chain is A1. When the execution entity check chain includes the first RPC call chain, the execution entity check chain includes A1-B1. By continuously introducing RPC call chains and lock wait chains, the length of the execution entity check chain can be continuously increased. When the execution entity check chain forms a loop, it indicates that there is a deadlock in the operating system.
[0010] In an optional manner of the first aspect, the operating system obtains the first RPC call chain in the kernel state space in the first scheduling entity. The operating system obtains the first lock wait chain in the user state space in the first server process. By storing the lock wait chain in the user state space, the data in the kernel state space can be reduced, thereby improving the security and reliability of the system.
[0011] In an optional manner of the first aspect, before the operating system obtains the first RPC call chain of the first scheduling entity, the deadlock detection method also includes: the operating system obtains the waiting lock time of the first scheduling entity. If the waiting lock time of the first scheduling entity is greater than the first threshold, the operating system obtains the first RPC call chain of the first scheduling entity. Among them, when a deadlock exists, the scheduling entity will stop running and enter the waiting lock state. The waiting lock state records the length of time the scheduling entity waits for the lock (referred to as the waiting lock time). When the waiting lock time is greater than the first threshold, the operating system performs deadlock detection and obtains the first RPC call chain of the first scheduling entity. Therefore, by setting the first threshold, the operating system can be flexibly controlled to perform deadlock detection and reasonably utilize system resources.
[0012] In an optional manner of the first aspect, execution entity B1 is the last execution entity called by the first scheduling entity. After the operating system obtains the first RPC call chain of the first scheduling entity, the deadlock detection method also includes: if the first RPC call chain indicates that there is no deadlock in the first scheduling entity, the operating system obtains the second lock waiting chain of the second server process. The second lock waiting chain includes information (abbreviated as B1-B2) that reflects the waiting relationship between execution entity B1 and execution entity B2. Execution entity B1 is the waiter of lock B, and execution entity B2 is the holder of lock B. Among them, when the existence of a deadlock cannot be determined through the first RPC call chain, it indicates that the current execution entity check chain is not a loop. At this time, by introducing the lock waiting chain through execution entity B1, the length of the execution entity check chain can be increased, and the accuracy of determining the deadlock can be improved.
[0013] In an optional manner of the first aspect, the second lock wait chain can be obtained by the following steps: the operating system obtains the base address of the execution entity B1 according to the register corresponding to the execution entity B1. The operating system determines the lock-wait field of the execution entity B1 according to the base address of the execution entity B1 and the first offset. The operating system obtains the base address of lock B in the lock-wait field of the execution entity B1. When the base address of lock B is in the lock-wait field of the execution entity B1, it indicates that the execution entity B1 is the waiter of lock B. The operating system determines the lock-owner field according to the base address of lock B and the second offset. The operating system obtains the identifier of the execution entity B2 in the lock-owner field. When the identifier of the execution entity B2 is in the lock-owner field, it indicates that the execution entity B2 is the holder of lock B.
[0014] In an optional manner of the first aspect, the identifier of the execution entity B2 is the base address of the execution entity B2. If the identifier of the execution entity B2 is other content, such as the letter B2, the system needs to have a mapping relationship between the letter B2 and the execution entity B2. Then, the base address of the execution entity B1 is obtained from the register corresponding to the execution entity B2. Therefore, when the identifier of the execution entity B2 is the base address of the execution entity B2, the efficiency of acquiring the lock wait chain can be improved.
[0015] In an optional manner of the first aspect, after the operating system obtains the second lock waiting chain of the second server process, the deadlock detection method further includes: the operating system determines the second scheduling entity that is running the execution entity B2. The operating system obtains the second RPC call chain of the second scheduling entity. The second RPC call chain includes information reflecting the call relationship of the execution entity B2 calling the execution entity A2 (abbreviated as B2-A2). If there is a waiting relationship of the execution entity B1 waiting for the execution entity B2, and a call relationship of the execution entity B2 calling the execution entity A2, the operating system determines that there is a deadlock. Among them, when the first RPC call chain and the second lock waiting chain cannot be deadlocked, it is characterized that the current execution entity check chain is not looped. By introducing the second RPC call chain by the execution entity B2, the length of the execution entity check chain can be increased, and the accuracy of determining the deadlock can be improved. After the operating system obtains the second RPC call chain, B1-A2 can be characterized as B1-B2, B2-A2. At this time, the execution entity check chain is looped. Specifically, the execution entity check chain can be expressed as A1-B1-B2-A2-A1.
[0016] In an optional manner of the first aspect, after determining that a deadlock exists, the deadlock detection method further includes: the operating system generates a deadlock alarm. The deadlock alarm includes a first RPC call chain, an association relationship, and a first lock wait chain. The association relationship includes a second lock wait chain and a second RPC call chain. Among them, the deadlock alarm carries information about the execution entity check chain. After determining that a deadlock exists in the execution entity check chain, the operating system can perform subsequent operations through the execution entity check chain, such as eliminating anomalies, restoring business, etc.
[0017] In an optional manner of the first aspect, the execution entity B1 is the last execution entity called by the first scheduling entity. After the operating system obtains the first RPC call chain of the first scheduling entity, the deadlock detection method also includes: if the first RPC call chain indicates that there is no deadlock, the operating system obtains the second lock wait chain of the second server process. If the second lock wait chain indicates that the execution entity B1 is not the waiter of lock B, the deadlock detection of the third scheduling entity is started. Among them, the execution entity B1 is not the waiter of lock B, which indicates that the execution entity check chain stops. At this time, the execution entity check chain A1-B1 does not form a loop. The system performs deadlock detection on other scheduling entities.
[0018] In an optional manner of the first aspect, the deadlock detection method further includes: the operating system generates an alarm. The alarm includes a first RPC call chain. The alarm indicates that the first RPC call chain is in a dead loop or blocking state. Wherein, when the waiting lock time of the first scheduling entity is greater than the first threshold, the execution entity checks that the chain is not looped. At this time, it indicates that the first scheduling entity is in a dead loop or blocking state. The operating system can locate the position of the dead loop or blocking according to the first RPC call chain, thereby eliminating the dead loop or blocking.
[0019] The second aspect of the present application provides a deadlock detection device. The deadlock detection device includes a first acquisition module, a second acquisition module and a processing module. Among them, the first acquisition module is used to obtain a first RPC call chain of a first scheduling entity. The first RPC call chain includes information reflecting the call relationship of execution entity A1 calling execution entity B1. The second acquisition module is used to obtain a first lock waiting chain of a first server process. The first lock waiting chain includes information reflecting the waiting relationship of execution entity A2 waiting for execution entity A1. Among them, execution entity A2 is the waiter of lock A, and execution entity A1 is the holder of lock A. The processing module is used to determine that a deadlock exists if execution entity B1 is execution entity A2, or execution entity B1 and execution entity A2 have an association relationship. Among them, the association relationship includes a call relationship, a wait relationship, or a set of a call relationship and a wait relationship.
[0020] In an optional manner of the second aspect, the first acquisition module is specifically used to acquire the first RPC call chain in the kernel state space in the first scheduling entity. The second acquisition module is specifically used to acquire the first lock waiting chain in the user state space in the first server process.
[0021] In an optional manner of the second aspect, the first acquisition module is further used to acquire the waiting lock time of the first scheduling entity. If the waiting lock time of the first scheduling entity is greater than a first threshold, a first RPC call chain of the first scheduling entity is acquired.
[0022] In an optional manner of the second aspect, the execution entity B1 is the last execution entity called by the first scheduling entity. The second acquisition module is also used to acquire the second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock in the first scheduling entity. The second lock waiting chain includes information reflecting the waiting relationship between the execution entity B1 and the execution entity B2. Among them, the execution entity B1 is the waiter of lock B, and the execution entity B2 is the holder of lock B.
[0023] In an optional manner of the second aspect, the second acquisition module is specifically used to acquire the base address of the execution entity B1 according to the register corresponding to the execution entity B1. The second acquisition module is specifically used to determine the lock-wait field of the execution entity B1 according to the base address of the execution entity B1 and the first offset. The second acquisition module is specifically used to acquire the base address of the lock B in the lock-wait field of the execution entity B1. Among them, the base address of the lock B indicates that the execution entity B1 is the waiter of the lock B. The second acquisition module is specifically used to determine the lock-owner field according to the base address of the lock B and the second offset. The second acquisition module is specifically used to acquire the identifier of the execution entity B2 in the lock-owner field. Among them, the identifier of the execution entity B2 indicates that the execution entity B2 is the holder of the lock B.
[0024] In an optional manner of the second aspect, the identifier of the execution entity B2 is a base address of the execution entity B2.
[0025] In an optional manner of the second aspect, the processing module is further used to determine a second scheduling entity that is running the execution entity B2. The first acquisition module is also used to acquire a second RPC call chain of the second scheduling entity. The second RPC call chain includes information reflecting a call relationship of the execution entity B2 calling the execution entity A2. The processing module is specifically used to determine that a deadlock exists if there is a waiting relationship of the execution entity B1 waiting for the execution entity B2, and a call relationship of the execution entity B2 calling the execution entity A2.
[0026] In an optional manner of the second aspect, the device further includes a generation module. The generation module is used to generate a deadlock alarm. The deadlock alarm includes a first RPC call chain, an association relationship, and a first lock wait chain. The association relationship includes a second lock wait chain and a second RPC call chain.
[0027] In an optional manner of the second aspect, the execution entity B1 is the last execution entity called by the first scheduling entity. The second acquisition module is also used to acquire the second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock. The processing module is also used to start deadlock detection of the third scheduling entity if the second lock waiting chain indicates that the execution entity B1 is not a waiter of lock B.
[0028] In an optional manner of the second aspect, the device further includes a generation module. The generation module is used to generate an alarm. The alarm includes a first RPC call chain. The alarm indicates that the first scheduling entity is in an infinite loop or blocking state.
[0029] The third aspect of the present application provides a deadlock detection device. The deadlock detection device includes a processor and a memory. A first RPC call chain and a first lock wait chain are stored in the memory. The first RPC call chain includes information reflecting the call relationship of execution entity A1 calling execution entity B1. The first lock wait chain includes information reflecting the wait relationship of execution entity A2 waiting for execution entity A1. Among them, execution entity A2 is the waiter of lock A, and execution entity A1 is the holder of lock A. The processor is used to obtain the first RPC call chain and the first lock wait chain. If execution entity B1 is execution entity A2, or execution entity B1 and execution entity A2 have an association relationship, it is determined that a deadlock exists. Among them, the association relationship includes a call relationship, a wait relationship, or a set of a call relationship and a wait relationship.
[0030] In an optional manner of the third aspect, the memory includes a kernel state space and a user state space. The processor is specifically configured to obtain a first RPC call chain in the kernel state space in the first scheduling entity. The processor is specifically configured to obtain a first lock wait chain in the user state space in the first server process.
[0031] In an optional manner of the third aspect, the memory further stores the waiting lock time of the first scheduling entity. The processor is also used to obtain the waiting lock time of the first scheduling entity. The processor is specifically used to obtain the first RPC call chain of the first scheduling entity if the waiting lock time of the first scheduling entity is greater than a first threshold.
[0032] In an optional manner of the third aspect, the execution entity B1 is the last execution entity called by the first scheduling entity. The processor is also used to obtain the second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock in the first scheduling entity. The second lock waiting chain includes information reflecting the waiting relationship between the execution entity B1 and the execution entity B2. Among them, the execution entity B1 is the waiter of lock B, and the execution entity B2 is the holder of lock B.
[0033] In an optional manner of the third aspect, the processor is specifically used to obtain the base address of the execution entity B1 according to the register corresponding to the execution entity B1. The processor is specifically used to determine the lock-wait field of the execution entity B1 according to the base address of the execution entity B1 and the first offset. The processor is specifically used to obtain the base address of lock B in the lock-wait field of the execution entity B1. Among them, the base address of lock B indicates that the execution entity B1 is the waiter of lock B. The processor is specifically used to determine the lock-owner field according to the base address of lock B and the second offset. The processor is specifically used to obtain the identifier of the execution entity B2 in the lock-owner field. Among them, the identifier of the execution entity B2 indicates that the execution entity B2 is the holder of lock B.
[0034] In an optional manner of the third aspect, the identifier of the execution entity B2 is a base address of the execution entity B2.
[0035] In an optional manner of the third aspect, the processor is further used to determine a second scheduling entity that is running the execution entity B2. The processor is also used to obtain a second RPC call chain of the second scheduling entity. The second RPC call chain includes information reflecting a call relationship between the execution entity B2 and the execution entity A2. The processor is specifically used to determine that a deadlock exists if there is a waiting relationship between the execution entity B1 and the execution entity B2, and a call relationship between the execution entity B2 and the execution entity A2.
[0036] In an optional manner of the third aspect, the processor is further configured to generate a deadlock alarm. The deadlock alarm includes a first RPC call chain, an association relationship, and a first lock wait chain. The association relationship includes a second lock wait chain and a second RPC call chain.
[0037] In an optional manner of the third aspect, the execution entity B1 is the last execution entity called by the first scheduling entity. The processor is also used to obtain the second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock. The processor is also used to start deadlock detection of the third scheduling entity if the second lock waiting chain indicates that the execution entity B1 is not a waiter of lock B.
[0038] In an optional manner of the third aspect, the processor is further configured to generate an alarm, wherein the alarm includes the first RPC call chain. The alarm indicates that the first scheduling entity is in an infinite loop or blocking state.
[0039] The fourth aspect of the present application provides a computer storage medium, characterized in that instructions are stored in the computer storage medium, and when the instructions are executed on a computer, the computer executes the method described in the first aspect or any one of the embodiments of the first aspect.
[0040] A fifth aspect of the present application provides a computer program product, characterized in that when the computer program product is executed on a computer, the computer is caused to execute the method described in the first aspect or any one of the embodiments of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a structural diagram of the deadlock state provided in this application;
[0042] Figure 2 A flowchart of a deadlock detection method provided in this application;
[0043] Figure 3 A schematic diagram of the structure of the operating system provided in this application;
[0044] Figure 4 A flowchart of the RPC call provided in this application;
[0045] Figure 5 A schematic diagram of the structure of the scheduling entity provided in this application;
[0046] Figure 6 A schematic diagram of the structure of the server process provided in this application;
[0047] Figure 7 A schematic diagram of the location of the address of the lock-wait field provided in this application;
[0048] Figure 8 A schematic diagram of the location of the address of the lock-owner field provided in this application;
[0049] Fig. 9 A schematic diagram of the process of acquiring a lock provided in this application;
[0050] Fig.10 A schematic diagram of the process of releasing a lock provided in this application;
[0051] Fig.11 Another flowchart of the deadlock detection method provided in this application;
[0052] Fig.12 A schematic diagram of the structure of the execution entity inspection chain provided in this application;
[0053] Fig.13 This is a schematic diagram of the structure of the deadlock detection device provided in this application;
[0054] Fig.14 This is a schematic diagram of the structure of the deadlock detection device provided in this application. DETAILED DESCRIPTION
[0055] The present application provides a deadlock detection method, apparatus and related equipment. In the present application, the accuracy of deadlock detection can be improved by using a lock wait chain and an RPC call chain for deadlock detection. It should be understood that the "first", "second" and the like used in the present application are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order. In order to facilitate the understanding of the technical solutions in the present application, some professional terms appearing in the present application are described below.
[0056] An operating system is system software that manages computer hardware and software resources. An operating system needs to handle basic tasks such as managing and configuring memory, determining the priority of system resource supply and demand, controlling input and output devices, operating networks, and managing file systems. An operating system can provide an operating interface for users to interact with the system. An operating system can include one or more processes, and the same process can include one or more threads.
[0057] In the mechanism of separation of execution and scheduling, the execution entity (activation) and the scheduling entity are parts of the thread respectively. The execution entity contains the register information and virtual memory address space information required for the thread to run. The scheduling entity contains the scheduling related information such as the priority required for the thread to run. Among them, the process that provides the execution entity is also called the server process.
[0058] Inter-Process Communication (IPC) is a general term for a type of data communication method between processes in an operating system. The two or more parties involved in the communication transfer data between processes by calling primitives such as message sending and receiving, thereby completing data communication.
[0059] Remote Procedure Call (RPC) is a mode of inter-process communication, where programs are distributed in different address spaces. If the two communicating processes are in the same host, RPC can communicate through different virtual address spaces (even if the same physical address is used). If the two communicating processes are in different hosts, RPC can interact through different physical addresses.
[0060] The RPC call chain includes the call relationship of the execution entity. In the scheduling entity, after calling an execution entity through RPC, the execution entity initiates another RPC call again, forming an RPC call chain. For example, execution entity A calls execution entity B, and the RPC call chain is AB.
[0061] The lock wait chain includes the waiting relationship of the execution entities. A thread is waiting for a lock, and the thread holding the lock is waiting for another lock, thus forming a lock wait chain. For example, thread A is waiting for the lock held by thread B, and thread B is waiting for the lock held by thread C. In the mechanism of separation of execution and scheduling, the lock wait chain can be understood as an execution entity is waiting for a lock, and the execution entity holding the lock is waiting for another lock, thus forming a lock wait chain. For example, execution entity A is waiting for the lock held by execution entity B, and execution entity B is waiting for the lock held by execution entity C.
[0062] The macro kernel architecture is a kernel architecture scheme for operating systems. Under the macro kernel architecture, the operating system places all kernel components in the kernel state space, such as the IPC module, permission management module, file system, and network protocol stack. The user state space is responsible for running application code.
[0063] Microkernel architecture is a kernel architecture scheme for operating systems. Under the microkernel architecture, the operating system only retains core kernel components in the kernel state space, such as the IPC module and the permission management module. The operating system puts traditional components into the user state space, such as the file system and the network protocol stack.
[0064] Compared with the traditional macro kernel architecture, the micro kernel architecture puts some traditional components into the user space, thereby enhancing the security and reliability of the system. However, under the micro kernel architecture, when an application obtains system services, it needs to use IPC. IPC will generate IPC processing overhead. The additional IPC processing overhead brings huge performance loss. In order to minimize the performance loss caused by IPC, a mechanism of separation of execution and scheduling can be adopted in the micro kernel architecture. In the mechanism of separation of execution and scheduling, threads are divided into two parts: execution entity and scheduling entity. The execution entity is located in the server process. The scheduling entity runs the execution entity by initiating a remote procedure call (RPC) to the server process.
[0065] In the mechanism where execution and scheduling are separated, the accuracy of lock waiting chain checking is not high. For example, Figure 1 This is a schematic diagram of the deadlock state provided in this application. Figure 1As shown, the operating system includes a server process 101, a scheduling entity 102, a server process 103 and a scheduling entity 104. Scheduling entity 102 is also called a first scheduling entity. Scheduling entity 104 is also called a second scheduling entity. Server process 101 is also called a first server process. Server process 103 is also called a second server process. Among them, server process 101 includes execution entity A1 and execution entity A2. Server process 103 includes execution entity B1 and execution entity B2. Scheduling entity 102 calls execution entity A1 through RPC. Scheduling entity A calls execution entity B1 through RPC. Execution entity B1 is waiting for lock B held by execution entity B2. Execution entity B1 is a waiter for lock B, and execution entity B2 is the owner of lock B. Similarly, scheduling entity 104 calls execution entity B2 through RPC. Execution entity B2 calls execution entity A2 through RPC. Execution entity A2 is waiting for lock A held by execution entity A1. Execution entity A2 is the waiter for lock A, and execution entity A1 is the owner of lock A. Therefore, scheduling entity 102 is waiting for scheduling entity 104 to release lock B, and scheduling entity 104 is waiting for scheduling entity 102 to release lock A. Scheduling entity 102 and scheduling entity 104 are waiting for each other, resulting in a deadlock.
[0066] However, the existence of a deadlock cannot be determined by checking the lock wait chain. Figure 1 As shown, execution entity A2 waits for lock A (abbreviated as A2-A1) held by execution entity A1, and execution entity B1 waits for lock B (abbreviated as B1-B2) held by execution entity B2. The lock waiting chain includes A2-A1 and B1-B2. The lock waiting chain is not a loop, and it is impossible to determine whether there is a deadlock in the operating system.
[0067] To this end, the present application provides a deadlock detection method. In the deadlock detection method, not only a lock wait chain is used, but also an RPC call chain is used, thereby improving the accuracy of deadlock detection. In the present application, the execution subject of the deadlock detection method can be a deadlock detection device, an operating system in the deadlock detection device, or a monitoring module in the operating system. In this context, the deadlock detection method of the present application will be described by taking the execution subject as an operating system as an example.
[0068] Figure 2 FIG. 1 is a flow chart of the deadlock detection method provided in this application. Figure 2 As shown, the deadlock detection method includes the following steps.
[0069] In step 201, the operating system obtains the first RPC call chain of the first scheduling entity. The first RPC call chain includes information (abbreviated as A1-B1) that reflects the call relationship between execution entity A1 and execution entity B1. It should be understood that execution entity A1 can call execution entity B1 directly through RPC or indirectly through RPC. When execution entity A1 calls execution entity B1 indirectly through RPC, execution entity A1 first calls other execution entities through RPC, and other execution entities then call execution entity B1 through RPC. For example, execution entity A1 calls execution entity C1 through RPC, and execution entity C1 calls execution entity B1 through RPC. Alternatively, execution entity A1 calls execution entity C1 through RPC, execution entity C1 calls execution entity C2 through RPC, and execution entity C2 calls execution entity B1 through RPC.
[0070] In step 202, the operating system obtains the first lock waiting chain of the first server process. The first lock waiting chain includes information reflecting the waiting relationship between execution entity A2 and execution entity A1 (abbreviated as A2-A1). Among them, execution entity A2 is the waiter of lock A, and execution entity A1 is the holder of lock A. It should be understood that there is no strictly defined timing relationship between step 201 and step 202.
[0071] In step 203, if the execution entity B1 is the execution entity A2, or the execution entity B1 and the execution entity A2 have an association relationship, the operating system determines that a deadlock exists. When the execution entity B1 is the execution entity A2, it means that the execution entity B1 and the execution entity A2 are the same execution entity. At this time, the execution entity check chain includes A1-A2-A1. The execution entity check chain forms a ring. Therefore, it can be determined that a deadlock exists in the operating system. The association relationship includes a call relationship, a wait relationship, or a collection of a call relationship and a wait relationship.
[0072] When the association relationship includes a waiting relationship, the execution entity B1 and the execution entity A2 have a waiting relationship (abbreviated as B1-A2). For example, the execution entity B1 is the waiter of lock C, and the execution entity A2 is the owner of lock C. At this time, the execution entity check chain includes A1-B1-A2-A1. The execution entity check chain forms a ring. Therefore, it can be determined that there is a deadlock in the operating system.
[0073] When the association relationship includes a calling relationship, there is a calling relationship (abbreviated as B1-A2) between the execution entity B1 and the execution entity A2. For example, the execution entity B1 calls the execution entity A2 through RPC. At this time, the execution entity check chain includes A1-B1-A2-A1. The execution entity check chain forms a ring. Therefore, it can be determined that there is a deadlock in the system.
[0074] When the association relationship includes a set of calling relationships and waiting relationships, the execution entity B1 and the execution entity A2 establish an association relationship (abbreviated as B1-X, X-A2) through the set of calling relationships and waiting relationships. For example, the association relationship includes a second RPC calling chain and a second lock waiting chain. The second lock waiting chain includes information that reflects the waiting relationship of the execution entity B1 waiting for the execution entity B2 (abbreviated as B1-B2). Among them, the execution entity B1 is the waiter of lock B, and the execution entity B2 is the owner of lock B. The second RPC calling chain includes information that reflects the calling relationship of the execution entity B2 calling the execution entity A2 (abbreviated as B2-A2). At this time, the execution entity check chain includes A1-B1-B2-A2-A1. The execution entity check chain is ring-shaped. Therefore, it can be determined that a deadlock exists.
[0075] And, if Figure 1 As shown, according to the scheduling entity 102, the execution entity A1 calls the execution entity B1 through RPC (abbreviated as A1-B1). According to the server process 103, the execution entity B1 waits for the lock B held by the execution entity B2 (abbreviated as B1-B2). According to the scheduling entity 104, the execution entity B2 calls the execution entity A2 through RPC (abbreviated as B2-A2). According to the server process 101, the execution entity A2 waits for the lock A held by the execution entity A1 (abbreviated as A2-A1). The aforementioned RPC call relationship and lock waiting relationship are connected in series to obtain the execution entity check chain A1-B1-B2-A2-A1. Therefore, Figure 1 The deadlock state in the embodiment is consistent with the execution entity check chain in the present application. Through the deadlock detection method in the present application, the execution entity check chain is used to perform deadlock detection, which can effectively detect deadlock.
[0076] It should be understood that in actual applications, when the association relationship includes a set of call relationships and wait relationships, the association relationship may also include more RPC call chains and lock wait chains. For example, the association relationship includes a second RPC call chain, a second lock wait chain, a third RPC call chain, and a third lock wait chain. The second RPC call chain is abbreviated as B1-B2. The second lock wait chain is abbreviated as B2-C1. The third RPC call chain is abbreviated as C1-C2. The third lock wait chain is abbreviated as C2-A2. At this time, the execution entity check chain includes A1-B1-B2-C1-C2-A2-A1. The execution entity check chain forms a loop. Therefore, it can be determined that there is a deadlock in the system.
[0077] To facilitate understanding of the deadlock detection method in the present application, an exemplary description of the operating system in the present application is given below. Figure 3 Schematic diagram of the structure of the operating system provided in this application. Figure 3As shown, the operating system includes a microkernel 301 , a monitoring module 302 , a server process 303 , a scheduling entity 304 and a server process 305 .
[0078] The monitoring module 302 is a functional module of the operating system. The monitoring module 302 has the ability to read memory data in other process spaces across processes. The microkernel 301 is used to provide a system call interface for the monitoring module 302. The monitoring module 302 is used to obtain the RPC call chain of the scheduling entity through the system call interface. Specifically, the monitoring module 302 obtains the RPC call chain through the execution entity call stack of the scheduling entity. For example, Figure 3 In the example, the scheduling entity 304 is used to initiate an RPC call to the server process 303 and the server process 305. The server process 303 and the server process 305 are used to allocate an execution entity to the scheduling entity 304. The microkernel 301 maintains an execution entity call stack for the scheduling entity 304. The execution entity call stack is located in the kernel state space. In the execution entity call stack, the call relationship of the scheduling entity 304 is recorded, and the call relationship is also called the RPC call chain. When the base of the scheduling entity 304 calls the execution entity A1 through RPC, the microkernel 301 allocates the execution entity A1 from the server process 305. The microkernel 301 pushes the execution entity A1 into the execution entity call stack of the scheduling entity 304 to execute the RPC call. Similarly, when the execution entity A1 of the scheduling entity 304 calls the execution entity B1 through RPC, the microkernel 301 allocates the execution entity B1 from the server process 303. The microkernel 301 pushes the execution entity B1 into the execution entity call stack of the scheduling entity 304 to execute the RPC call. After the RPC call ends and returns, the microkernel 301 pops the execution entity A1 and the execution entity B1 from the execution entity call stack of the scheduling entity 304. The microkernel 301 can provide the monitoring module 302 with a corresponding system call interface. The monitoring module 302 reads the execution entity call stack of the scheduling entity 304 through the system call interface to obtain the RPC call chain. Figure 3 In the example, the monitoring module 302 obtains the RPC call chain A1-B1 of the scheduling entity 304 through the system call interface.
[0079] exist Figure 3 In the example, the scheduling entity 304 initiates RPC calls to two server processes. In actual applications, a scheduling entity can initiate RPC calls to one or more server processes. The following is an example of a scheduling entity initiating an RPC call to one server process. Figure 4 This is a flow chart of the RPC call provided in this application. Figure 4As shown, the operating system includes a scheduling entity 401 and a server process 402. The server process 402 includes an execution entity A1, an execution entity B2, and an execution entity B3. When the base of the scheduling entity 401 calls the execution entity A1 through RPC, the microkernel of the operating system allocates the execution entity A1 from the server process 402. The microkernel pushes the execution entity A1 into the execution entity call stack of the scheduling entity 401 to execute the RPC call. At this time, the RPC call chain of the scheduling entity 401 includes A1. Afterwards, the execution entity A1 of the scheduling entity 401 calls the execution entity B2 through RPC. After the execution entity B2 is allocated, the RPC call chain of the scheduling entity 401 includes A1-B2. Afterwards, the execution entity B2 of the scheduling entity 401 calls the execution entity B3 through RPC. After the execution entity B3 is allocated, the RPC call chain of the scheduling entity 401 includes A1-B2-B3.
[0080] The monitoring module 302 periodically (for example, every 1 second) reads the waiting lock state of the scheduling entity in the operating system through the system call interface. Specifically, the monitoring module 302 reads the content of the lock-wait-state field of the scheduling entity. The lock-wait-state field is located in the dedicated memory (kernel state space). The monitoring module 302 can obtain the waiting lock duration of the scheduling entity through the lock-wait-state field. For example, Figure 5 FIG. 1 is a schematic diagram of a scheduling entity provided in this application. Figure 5 As shown, the scheduling entity 401 includes a corresponding lock-wait-state field. The lock-wait-state field records the waiting time of the scheduling entity 401 or the time when the scheduling entity 401 enters the waiting state. Specifically, after the scheduling entity 401 calls the execution entity B3 through RPC, the execution entity B3 will try to get lock B. If lock B is already held by other execution entities, the scheduling entity 401 will be suspended by the microkernel. At this time, the scheduling entity 401 enters the waiting state. If the lock-wait-state field records the time when the scheduling entity 401 enters the waiting state, the lock-wait-state field records the current time. If the lock-wait-state field records the waiting time of the scheduling entity 401, the lock-wait-state field is a timer. The start time of the timer is the current time. For the convenience of description, the corresponding description will be made later by taking the recording of the waiting time in the lock-wait-state field as an example. After the execution entity B3 successfully obtains lock B, the operating system clears the content in the lock-wait-state field.
[0081] It should be understood that the name of the lock-wait-state field in this application is just an example for the convenience of description. This application does not limit the name of the field. For example, the lock-wait-state field can also be called the M field. Similarly, in the subsequent description, the lock-wait field and the lock-owner field are also just examples for the convenience of description.
[0082] The monitoring module 302 is also used to obtain the lock waiting chain of the server process. Specifically, the monitoring module 302 reads the lock-owner field and the lock-wait field of the server process. The lock-owner field and the lock-wait field are located in the dedicated memory (user state space) of the server process. The lock-owner field records the identifier of the execution entity holding the lock. The identifier of the execution entity can be the execution entity identifier Thread ID, or the base address of the execution entity. The lock-wait field records the base address of the lock that the execution entity waiting for the lock is waiting for. The lock waiting chain includes the lock waiter-lock holder. For example, if the execution entity A1 holds lock A, the lock-owner field of lock A records the identifier of the execution entity A1. If the execution entity A2 is the waiter of lock A, the lock-wait field of the execution entity A2 records the base address of lock A. At this time, the lock waiting chain includes the execution entity A2-execution entity A1 (abbreviated as A2-A1).
[0083] The lock-owner field and the lock-wait field are described below with reference to specific examples. Figure 6 This is a schematic diagram of the structure of the server process provided in this application. Figure 6 As shown, the server process 402 includes execution entity A1, execution entity B2, execution entity B3, lock-owner field of lock A, lock-owner field of lock B, and three lock-wait fields. The three lock-wait fields correspond to the three execution entities one by one.
[0084] Each execution entity has a corresponding register. The register stores the base address of the execution entity. The address of the lock-wait field is related to the base address of the execution entity. Specifically, Figure 7 FIG. 1 is a schematic diagram of the location of the address of the lock-wait field provided in this application. Figure 7As shown, there is a first offset between the base address of execution entity A1 and the address of the lock-wait field of execution entity A1. When the first offset is known, the monitoring module 302 can obtain the address of the lock-wait field of execution entity A1 through the first offset and the base address of execution entity A1. The monitoring module 302 can read the data in the lock-wait field through the address of the lock-wait field of execution entity A1. When the monitoring module 302 and execution entity A1 are in different processes, the monitoring module 302 can read the data in the lock-wait field across processes.
[0085] In other embodiments, the offset of the address of each execution entity and the corresponding lock-wait field is the same. For example, there is a first offset between the base address of execution entity A1 and the address of the lock-wait field of execution entity A1. There is a first offset between the base address of execution entity B2 and the address of the lock-wait field of execution entity B2. At this time, the monitoring module 302 can obtain the address of the lock-wait field of execution entity B2 and the address of the lock-wait field of execution entity A1 through the first offset. Therefore, this embodiment can save the storage resources of the operating system and improve the efficiency of obtaining the content of the lock-wait field.
[0086] The base address of the lock is related to the address of the lock-owner field. Specifically, Figure 8 This is a schematic diagram of the location of the address of the lock-owner field provided in this application. Figure 8 As shown, there is a second offset between the base address of lock A and the address of the lock-owner field of lock A. When the second offset is known, the monitoring module 302 can obtain the address of the lock-owner field of lock A through the second offset and the base address of lock A. The monitoring module 302 can read the data in the lock-owner field through the address of the lock-owner field of lock A.
[0087] In other embodiments, the second offset is the same as the first offset. At this time, when the first offset is already obtained, the monitoring module 302 can obtain the address of the lock-wait field of the execution entity A1 and the base address of the lock A through the first offset, the base address of the lock A, and the base address of the execution entity A1. Therefore, this embodiment can save the storage resources of the operating system.
[0088] The above describes the location of the lock-owner field and the lock-wait field. Figure 6 , describes the functions of the lock-owner field and the lock-wait field. Fig. 9 This is a schematic diagram of the process of acquiring a lock provided in this application. Fig. 9 As shown, the process of acquiring a lock includes the following steps.
[0089] In step 901, the operating system saves the base address of the lock to the lock-wait field of the current execution entity. Figure 6 In the example, execution entity A1 tries to get lock A, and the operating system adds the base address of lock A to the lock-wait field of execution entity A1.
[0090] In step 902, if the lock is already held by another scheduling entity, the operating system sets the current scheduling entity to the waiting lock state through the system call interface, records the waiting lock duration, and suspends the current scheduling entity. Figure 6 In the example, when execution entity B2 obtains lock B, the lock-owner field of lock B records the identifier of execution entity B2. After execution entity B2 obtains lock B, execution entity B3 tries to obtain lock B. However, since lock B is already held by execution entity B2, execution entity B3 enters the lock-wait state. The lock-wait field of execution entity B3 records the base address of lock B. And, Figure 5 The scheduling entity in the lock-wait-state field records the lock-wait-state duration.
[0091] In step 903, if the lock is not held by other scheduling entities, the operating system executes the lock acquisition operation and saves the base address of the current execution entity to the Lock-owner field of the lock. Figure 6 In the example, after execution entity A1 obtains lock A, the operating system adds the identifier of execution entity A1 to the Lock-owner field of lock A.
[0092] In step 904, the operating system clears the lock-wait field of the current execution entity. For example, in the aforementioned step 901, the operating system adds the base address of lock A to the lock-wait field of execution entity A1. After execution entity A1 obtains lock A, the operating system clears the lock-wait field of execution entity A1.
[0093] Fig.10 This is a schematic diagram of the process of releasing the lock provided in this application. Fig.10 As shown, the process of releasing the lock includes the following steps.
[0094] In step 1001, the operating system clears the Lock-owner field of the lock. Figure 6In the example, when execution entity A1 obtains lock A, the identifier of execution entity A1 is recorded in the Lock-owner field of lock A. When releasing the lock, the operating system clears the Lock-owner field of lock A to zero.
[0095] In step 1002, the operating system executes an operation to release the lock, such as modifying the lock flag through an atomic operation, waking up other scheduling entities waiting for the lock by calling a system call interface, and so on.
[0096] Combined with the above Figures 3 to 10 , the operating system in this application is described. It should be understood that the foregoing description of the operating system is only one or more specific examples. In practical applications, those skilled in the art can make adaptive changes to the operating system as needed. After the adaptive change, if it is necessary to use the RPC call chain and the lock wait chain for deadlock detection, it still belongs to the protection scope of this application. The adaptive change includes but is not limited to one or more of the following contents.
[0097] For example, in Figure 3 In the embodiment, the operating system includes a monitoring module 302. The monitoring module 302 is used to obtain the RPC call chain, the lock waiting chain and the waiting lock state. In practical applications, the monitoring module can be a part of the microkernel. At this time, the microkernel is responsible for executing all operations performed by the monitoring module. Specifically, the microkernel reads the RPC call chain, the lock waiting chain and the waiting lock state.
[0098] For example, in Figure 5 and Figure 6 In the example, the Lock-owner field and the lock-wait field are located in the user state space. In actual applications, the Lock-owner field and the lock-wait field can be located in the kernel state space.
[0099] For example, in Figure 7 In the example, after adding the first offset to the base address of execution entity A1, the address of the lock-wait field can be obtained. In practical applications, the operating system can store a mapping table of the base address of execution entity A1 and the address of the lock-wait field. After determining the base address of execution entity A1, the operating system can obtain the address of the lock-wait field by searching the mapping table. Similarly, the operating system can also store a mapping table of the base address of lock A and the address of the Lock-owner field. After determining the base address of lock A, the operating system can obtain the address of the Lock-owner field by searching the mapping table.
[0100] For example, in Fig. 9In the example above, when the current execution entity tries to get the lock, the operating system saves the base address of the lock to the lock-wait field of the current execution entity. After getting the lock, the operating system clears the lock-wait field of the current execution entity. In actual applications, when the current execution entity tries to get the lock, the operating system does not save the base address of the lock to the lock-wait field of the current execution entity. Only when it is determined that the lock is already held by other execution entities, the operating system saves the base address of the lock to the lock-wait field of the current execution entity. At this time, if it is determined that the lock is not held by other execution entities, the operating system does not need to clear the lock-wait field.
[0101] Combine the following Figures 3 to 10 The deadlock detection method in this application is described. Fig.11 FIG. 2 is another flow chart of the deadlock detection method provided in this application. Fig.11 As shown, the deadlock detection method includes the following steps.
[0102] In step 1101, the operating system reads the first scheduling entity that has timed out waiting for the lock state. Figure 5 From the description, it can be seen that the scheduling entity corresponds to a lock-wait-state field. Therefore, by reading the contents of N lock-wait-state fields, the operating system can obtain N lock-wait times of N scheduling entities. N is an integer greater than or equal to 1. If the lock-wait time of the scheduling entity is greater than the first threshold, it indicates that the lock-wait state of the scheduling entity has timed out. The operating system determines the maximum lock-wait time as the target lock-wait time. The target lock-wait time is greater than the first threshold. The scheduling entity corresponding to the target lock-wait time is the first scheduling entity whose lock-wait state has timed out.
[0103] In step 1102, the operating system sets the first scheduling entity that has timed out waiting for the lock state as the current scheduling entity. Figure 4 As described in , the operating system maintains an execution entity call stack for the current scheduling entity. The operating system sets the execution entity call stack corresponding to the current scheduling entity as the current execution entity call stack. The operating system sets the first execution entity on the current execution entity call stack as the current execution entity. The operating system establishes an empty execution entity check chain.
[0104] In step 1103, the operating system adds the current execution entity to the execution entity checking chain.
[0105] In step 1104, the operating system determines whether the execution entity check chain is looped. If so, step 1105 is executed, and if not, step 1106 is executed.
[0106] In step 1105, if the execution entity check chain forms a loop, the operating system determines that a deadlock exists. After determining that a deadlock exists, the operating system generates a deadlock alarm. The deadlock alarm includes an execution entity check chain. The execution entity check chain is used to locate the deadlock. After locating the deadlock, the operating system can further take recovery actions on the execution entities on the execution entity check chain. In order to eliminate the anomaly and restore the business as soon as possible, the recovery action can adopt the least recovery action. For example, the recovery action includes killing the scheduling entity, adjusting the scheduling entity priority, etc.
[0107] In step 1106, if the execution entity check chain is not a loop, the operating system determines whether the current execution entity is the last calling entity on the current execution entity call stack. If the current execution entity is the last calling entity on the current execution entity call stack, step 1108 is executed. If the current execution entity is not the last calling entity on the current execution entity call stack, step 1107 is executed.
[0108] In step 1107, the operating system sets the next execution entity called by the current execution entity as the current execution entity. Step 1103 is executed.
[0109] In step 1108, the operating system determines whether the lock-wait field of the current execution entity is empty. Figure 6 As can be seen from the description, the current execution entity has a corresponding lock-wait field. The operating system reads the content in the lock-wait field to determine whether the lock-wait field is empty. If the lock-wait field of the current execution entity is empty, it indicates that the current execution entity is not a lock waiter, and step 1109 is executed. If the lock-wait field of the current execution entity is not empty, it indicates that the current execution entity is a lock waiter, and step 1113 is executed. In addition, when the lock-wait field of the current execution entity is empty, the operating system can generate an alarm. The alarm indicates that the current scheduling entity is in a dead loop or blocking state. Specifically, the current scheduling entity will enter the waiting lock state only when the current scheduling entity is suspended. However, it can be seen from step 1104 that the execution entity check chain is not a loop, that is, the reason for suspending the current scheduling entity is not a deadlock. Therefore, there may be other reasons that cause the current scheduling entity to be suspended, such as an dead loop or blocking. The alarm includes an execution entity check chain. The operating system can locate the location of the dead loop or blocking according to the execution entity check chain, and then eliminate the dead loop or blocking.
[0110] In step 1109, the operating system determines whether all scheduling entities that have timed out from the waiting lock state have been checked. In the aforementioned step 1101, the operating system obtained N waiting lock time lengths. Among the N waiting lock time lengths, if there are multiple waiting lock time lengths that are greater than the first threshold, it indicates that there are multiple scheduling entities that have timed out from the waiting lock state. If in addition to the current scheduling entity, other scheduling entities that have timed out from the waiting lock state are included, the operating system determines that all scheduling entities that have timed out from the waiting lock state have not been checked, and executes step 1111. If in addition to the current scheduling entity, other scheduling entities that have timed out from the waiting lock state are included, the operating system determines that all scheduling entities that have timed out from the waiting lock state have been checked, and executes step 1110.
[0111] In step 1110, the operating system ends deadlock detection.
[0112] In step 1111, the operating system reads the next scheduling entity that times out in the waiting lock state.
[0113] In step 1112, the operating system initializes the execution entity check chain. Step 1102 is executed.
[0114] In step 1113, the operating system reads the base address of the lock in the lock-wait field of the current execution entity. Fig. 9 As can be seen from the description, when the execution entity is in the lock waiting state, the lock-wait field corresponding to the execution entity will record the base address of the lock. Therefore, if the lock-wait field of the current execution entity is not empty, the base address of the lock can be read from the lock-wait field of the current execution entity. Figure 8 As can be seen from the description, based on the second offset and the base address of the lock, the operating system can obtain the address of the lock-owner field. The lock-owner field records the identifier of the execution entity that holds the lock. The execution entity corresponding to the identifier of the execution entity is set as the current execution entity.
[0115] In step 1114, the operating system adds the current execution entity to the execution entity check chain.
[0116] In step 1115 , the operating system determines whether the execution entity check chain is looped, if so, it executes step 1116 , if not, it executes step 1117 .
[0117] In step 1116, if the execution entity checks are chained in a loop, the operating system determines that a deadlock exists.
[0118] In step 1117, if the execution entity check chain is not looped, the operating system determines whether the lock-wait field of the current execution entity is empty. If the lock-wait field of the current execution entity is not empty, step 1113 is executed. If the lock-wait field of the current execution entity is empty, step 1118 is executed.
[0119] In step 1118, the operating system reads the scheduling entity where the current execution entity is located, sets the scheduling entity as the current scheduling entity, and sets the execution entity call stack of the current scheduling entity as the current execution entity call stack.
[0120] In step 1119, the operating system determines whether the current execution entity is the last calling entity on the current execution entity call stack. If the current execution entity is the last calling entity on the current execution entity call stack, step 1108 is executed. If the current execution entity is not the last calling entity on the current execution entity call stack, step 1107 is executed.
[0121] Combined with the above Figures 3 to 10 For this application Fig.11 The deadlock detection method in Figure 1 For example, the deadlock state in Fig.11 Specifically, when the deadlock detection method in this application is used to detect Figure 1 When a deadlock state occurs in the process, the deadlock detection method includes the following steps.
[0122] In step 1101, assume that the current scheduling entity is Figure 1 The scheduling entity 102 in.
[0123] In step 1102, according to Figure 1 It can be known from the scheduling entity 102 in that the current execution entity call stack includes execution entity A1 and execution entity B1 (the execution entities between execution entity A1 and execution entity B1 are ignored here). Therefore, the first execution entity on the current execution entity call stack is execution entity A1.
[0124] In step 1103, the operating system adds the execution entity A1 to the execution entity check chain. At this time, the execution entity check chain is the execution entity A1 (abbreviated as A1).
[0125] In step 1104 , the operating system determines that the execution entity check chain A1 does not form a loop, and executes step 1106 .
[0126] In step 1106, the operating system determines that the current execution entity is not the last calling entity on the current execution entity call stack, and executes step 1107. Specifically, according to Figure 1It can be seen that the current execution entity call stack also includes the execution entity B1. Therefore, the current execution entity is not the last calling entity on the current execution entity call stack.
[0127] In step 1107, according to the current execution entity call stack, it can be known that the next execution entity called by execution entity A1 is execution entity B1. The operating system sets execution entity B1 as the current execution entity and returns to step 1103.
[0128] In step 1103, the operating system adds the execution entity B1 to the execution entity check chain. At this time, the execution entity check chain is the execution entity A1 and the execution entity B1 (abbreviated as A1-B1).
[0129] In step 1104 , the operating system determines that the execution entity checks that the chain A1 - B1 does not form a loop, and executes step 1106 .
[0130] In step 1106 , the operating system determines that the current execution entity is the last calling entity on the current execution entity call stack, and executes step 1108 .
[0131] In step 1108, the operating system determines that the lock-wait field of the current execution entity is not empty, and executes step 1113. Specifically, according to Figure 1 It can be known from the server process 103 in that the execution entity B1 is the waiter of lock B. At this time, the lock-wait field of the execution entity B1 records the base address of lock B. Therefore, the lock-wait field of the current execution entity is not empty.
[0132] If the lock-wait field of the current execution entity is empty, it indicates that the execution entity B1 is not a waiter for lock B, and the operating system starts deadlock detection of the third scheduling entity. The third scheduling entity is another scheduling entity that has timed out waiting for the lock state. In addition, the operating system can generate an alarm. The alarm indicates that the scheduling entity 102 is in an infinite loop or blocking state. The alarm includes the execution entity check chain A1-B1. The operating system locates the position of the alarm according to the entity check chain A1-B1.
[0133] In step 1113, the operating system reads the base address of lock B in the lock-wait field. The operating system determines the lock-owner field of lock B based on the base address of lock B and the second offset. The operating system reads the content in the lock-owner field. Since execution entity B2 is the owner of lock B, the identifier of execution entity B2 is recorded in the lock-owner field. The operating system uses execution entity B2 as the current execution entity.
[0134] In step 1114, the operating system adds the execution entity B2 to the execution entity check chain. At this time, the execution entity check chain is the execution entity A1, the execution entity B1, and the execution entity B2 (abbreviated as A1-B1-B2).
[0135] In step 1115 , the operating system determines that the execution entity checks that the chain A1 - B1 - B2 does not form a loop, and executes step 1117 .
[0136] In step 1117, the operating system determines that the lock-wait field of the current execution entity is empty, and executes step 1118. Specifically, according to Figure 1 It can be seen that the execution entity B2 is not a lock waiter. Therefore, the lock-wait field of the execution entity B2 is empty.
[0137] In step 1118, the operating system reads the scheduling entity 104 where the execution entity B2 is located. The operating system sets the scheduling entity 104 as the current scheduling entity. The operating system sets the execution entity call stack of the scheduling entity 104 as the current execution entity call stack. The current execution entity call stack includes the execution entity B2 and the execution entity A2 (the execution entities between the execution entity B2 and the execution entity A2 are ignored here).
[0138] In step 1119, the operating system determines that the current execution entity is not the last calling entity on the current execution entity call stack, and executes step 1107. Specifically, according to Figure 1 It can be seen that, in addition to the execution entity B2, the current execution entity call stack also includes the execution entity A2. Therefore, the current execution entity is not the last calling entity on the current execution entity call stack.
[0139] In step 1107, according to the current execution entity call stack, it can be known that the next execution entity called by execution entity B2 is execution entity A2. The operating system sets execution entity A2 as the current execution entity and returns to step 1103.
[0140] In step 1103, the operating system adds the execution entity B1 to the execution entity check chain. At this time, the execution entity check chain is the execution entity A1, the execution entity B1, the execution entity B2, and the execution entity A2 (abbreviated as A1-B1-B2-A2).
[0141] In step 1104 , the operating system determines that the execution entity checks that the chain A1 - B1 - B2 - A2 does not form a loop, and executes step 1106 .
[0142] In step 1106 , the operating system determines that the current execution entity is the last calling entity on the current execution entity call stack, and executes step 1108 .
[0143] In step 1108, the operating system determines that the lock-wait field of the current execution entity is not empty, and executes step 1113. Specifically, according to Figure 1 It can be known from the server process 101 in that the execution entity A2 is the waiter of lock A. At this time, the lock-wait field of the execution entity A2 records the base address of lock A. Therefore, the lock-wait field of the current execution entity is not empty.
[0144] In step 1113, the operating system reads the base address of lock A in the lock-wait field. The lock-owner field of lock B is determined based on the base address of lock A and the second offset. The content in the lock-owner field is read. Since execution entity A1 is the owner of lock B, the identifier of execution entity A1 is recorded in the lock-owner field. The operating system uses execution entity A1 as the current execution entity.
[0145] In step 1114, the operating system adds execution entity A1 to the execution entity check chain. At this time, the execution entity check chain is execution entity A1, execution entity B1, execution entity B2, execution entity A2, execution entity A1 (abbreviated as A1-B1-B2-A2-A1).
[0146] In step 1115 , the operating system determines that the execution entity checks that the chain A1 - B1 - B2 - A2 - A1 forms a loop, and executes step 1116 .
[0147] In step 1116, the operating system determines that there is a deadlock. After determining that there is a deadlock, the operating system generates a deadlock alarm. The deadlock alarm includes an execution entity check chain A1-B1-B2-A2-A1. The execution entity check chain includes a first RPC call chain A1-B1, an association relationship and a first lock wait chain A2-A1. The association relationship includes a second lock wait chain B1-B2 and a second RPC call chain B2-A2. After determining that there is a deadlock, the operating system can check other scheduling entities that have timed out waiting for the lock state, that is, execute step 1111. After reading the next scheduling entity that has timed out waiting for the lock state through step 1111, the execution entity check link is initialized through step 1112. Initialization refers to clearing the execution entity check chain. After initialization, the execution entity check chain is empty.
[0148] The aforementioned Figure 1 Taking the deadlock state shown in FIG. 1 as an example, the deadlock detection method in the present application is described. It should be understood that Figure 1 This is just an example of a deadlock scenario. In practical applications, the deadlock detection method in this application can be applied to more deadlock scenarios. For example, in Figure 1In the example, execution entity A1 and execution entity A2 belong to server process 102. Execution entity B1 and execution entity B2 belong to server process 103. Server process 102 and server process 103 belong to different processes. In actual applications, execution entity A1, execution entity A2, execution entity B1 and execution entity B2 may belong to the same process.
[0149] According to the aforementioned Fig.11 The description of the deadlock detection method is in Figure 1 As can be seen from the application in the present application, the deadlock detection method in this application uses both the RPC call chain and the lock wait chain. Moreover, the RPC call chain and the lock wait chain are alternately distributed in the execution entity check chain. Fig.12 This is a structural diagram of the execution entity check chain provided in the present application. The execution entity check chain includes an RPC call chain and a lock wait chain. The operating system starts deadlock detection from the RPC call chain. When the last execution entity of the RPC call chain is checked and no deadlock is found, the operating system uses the last execution entity as the starting point of the lock wait chain and starts checking the lock wait chain. When the last execution entity of the lock wait chain is checked and no deadlock is found, the operating system uses the last execution entity as the starting point of the RPC call chain and starts checking the RPC call chain. Repeat the above process until the execution entity check chain stops or the execution entity check chain forms a loop.
[0150] It should be understood that Fig.11 and Fig.12 In the example, the operating system starts deadlock detection from the RPC call chain. Therefore, the beginning of the execution entity check chain is the RPC call chain. In actual applications, the operating system can also start deadlock detection from the lock wait chain. In this case, the beginning of the execution entity check chain is the lock wait chain.
[0151] The deadlock detection method in the present application is described above, and the deadlock detection device in the present application is described below. Fig.13 Schematic diagram of the deadlock detection device provided in this application. Fig.13As shown, the deadlock detection device includes a first acquisition module 1301, a second acquisition module 1302 and a processing module 1303. Among them, the first acquisition module 1301 is used to obtain the first RPC call chain of the first scheduling entity. The first RPC call chain includes information reflecting the call relationship of the execution entity A1 calling the execution entity B1. The second acquisition module 1302 is used to obtain the first lock waiting chain of the first server process. The first lock waiting chain includes information reflecting the waiting relationship of the execution entity A2 waiting for the execution entity A1. Among them, the execution entity A2 is the waiter of lock A, and the execution entity A1 is the holder of lock A. The processing module 1303 is used to determine that a deadlock exists if the execution entity B1 is the execution entity A2, or the execution entity B1 and the execution entity A2 have an association relationship. Among them, the association relationship includes a call relationship, a wait relationship, or a set of a call relationship and a wait relationship.
[0152] In other embodiments, the deadlock detection device may further include a generation module, etc. The module in the deadlock detection device is specifically used to execute Figure 2 or Fig.11 The operating system in the corresponding embodiment can perform all or part of the operations.
[0153] The deadlock detection device in the present application is described above, and the deadlock detection device in the embodiment of the present application is described below. Fig.14 Schematic diagram of the structure of the deadlock detection device provided in this application. The deadlock detection device in this application can be a desktop computer, a notebook, a smart phone, etc. Fig.14 As shown, the deadlock detection device includes: a processor 1401 and a memory 1403 .
[0154] The processor 1410 may be a central processing unit (CPU), a network processor (NP) or a combination of a CPU and a NP. The processor 1410 may further include a hardware chip or other general-purpose processor. The hardware chip may be an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) and other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. or any combination thereof. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0155] The memory 1403 may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), etc.
[0156] The memory 1403 stores a first RPC call chain and a first lock wait chain. The first RPC call chain includes information reflecting the call relationship of execution entity A1 calling execution entity B1. The first lock wait chain includes information reflecting the wait relationship of execution entity A2 waiting for execution entity A1. Among them, execution entity A2 is the waiter of lock A, and execution entity A1 is the holder of lock A. Processor 1401 is used to obtain the first RPC call chain and the first lock wait chain. If execution entity B1 is execution entity A2, or execution entity B1 and execution entity A2 have an association relationship, it is determined that a deadlock exists. Among them, the association relationship includes a call relationship, a wait relationship, or a set of a call relationship and a wait relationship.
[0157] In other embodiments, the deadlock detection device further includes a transceiver 1402. The transceiver 1402 may be a fiber optic transceiver, a wireless radio frequency module, and the like.
[0158] In other embodiments, the memory 1403 stores a computer program that can be executed by the processor 1401. When the processor 1401 reads and executes the computer program, the above-mentioned Figure 2 or Fig.11 All or part of the deadlock detection method in .
[0159] The present application also provides a digital processing chip. The digital processing chip integrates a circuit and one or more interfaces for implementing the functions of the above-mentioned processor 1401. When the digital processing chip integrates a memory, the digital processing chip can complete the method steps of any one or more of the above-mentioned embodiments. When the digital processing chip does not integrate a memory, it can be connected to an external memory through an interface. The digital processing chip implements the above-mentioned according to the program code stored in the external memory. Figure 2 or Fig.11 Deadlock detection method in .
[0160] The above are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.
Claims
1. A deadlock detection method, characterized in that: include: Acquire a first RPC call chain of the first scheduling entity, where the first RPC call chain includes information reflecting a call relationship between execution entity A1 and execution entity B1; The acquiring the first RPC call chain of the first scheduling entity comprises: acquiring the first RPC call chain in the kernel state space in the first scheduling entity; Acquire a first lock waiting chain of a first server process, wherein the first lock waiting chain includes information reflecting a waiting relationship between execution entity A2 and execution entity A1, wherein execution entity A2 is a waiter of lock A, and execution entity A1 is a holder of lock A; acquiring the first lock waiting chain of the first server process includes: acquiring the first lock waiting chain in a user space in the first server process; If the execution entity B1 is the execution entity A2, or the execution entity B1 and the execution entity A2 are associated, it is determined that a deadlock exists; The association relationship includes a calling relationship, a waiting relationship, or a combination of a calling relationship and a waiting relationship.
2. The method according to claim 1, characterized in that Before acquiring the first RPC call chain of the first scheduling entity, the method further includes: Obtaining the lock waiting time of the first scheduling entity; If the waiting lock time of the first scheduling entity is greater than a first threshold, the first RPC call chain of the first scheduling entity is obtained.
3. The method according to claim 1, characterized in that The execution entity B1 is the last execution entity called by the first scheduling entity. After obtaining the first RPC call chain of the first scheduling entity, the method further includes: If the first RPC call chain indicates that there is no deadlock in the first scheduling entity, then the second lock waiting chain of the second server process is obtained, and the second lock waiting chain includes information reflecting the waiting relationship between the execution entity B1 and the execution entity B2, wherein the execution entity B1 is the waiter of lock B, and the execution entity B2 is the holder of lock B.
4. The method according to claim 3, characterized in that The obtaining of the second lock waiting chain of the second server process comprises: Acquire a base address of the execution entity B1 according to a register corresponding to the execution entity B1; Determine the lock-wait field of the execution entity B1 according to the base address and the first offset of the execution entity B1; Obtaining the base address of lock B in the lock-wait field of the execution entity B1, wherein the base address of lock B indicates that the execution entity B1 is a waiter of lock B; Determine the lock-owner field according to the base address of lock B and the second offset; The identifier of the execution entity B2 in the lock-owner field is obtained, wherein the identifier of the execution entity B2 indicates that the execution entity B2 is the holder of lock B.
5. The method according to claim 4, characterized in that The identifier of the execution entity B2 is the base address of the execution entity B2.
6. The method according to claim 3, characterized in that After acquiring the second lock wait chain of the second server process, the method further includes: Determine a second scheduling entity that is running the execution entity B2; Acquire a second RPC call chain of the second scheduling entity, where the second RPC call chain includes information reflecting a call relationship of the execution entity B2 calling the execution entity A2; If the execution entity B1 and the execution entity A2 are associated, determining that a deadlock exists includes: If there is a waiting relationship in which the execution entity B1 waits for the execution entity B2, and a calling relationship in which the execution entity B2 calls the execution entity A2, it is determined that a deadlock exists.
7. The method according to claim 6, characterized in that After determining that a deadlock exists, the method further includes: Generate a deadlock alarm, wherein the deadlock alarm includes the first RPC call chain, the association relationship and the first lock wait chain; Among them, the association relationship includes the second lock waiting chain and the second RPC call chain.
8. The method according to claim 1, characterized in that The execution entity B1 is the last execution entity called by the first scheduling entity. After obtaining the first RPC call chain of the first scheduling entity, the method further includes: If the first RPC call chain indicates that there is no deadlock, obtaining a second lock waiting chain of the second server process; If the second lock waiting chain indicates that the execution entity B1 is not the waiter of lock B, the deadlock detection of the third scheduling entity is started.
9. The method according to claim 8, characterized in that The method further comprises: An alarm is generated, wherein the alarm includes the first RPC call chain, and the alarm indicates that the first scheduling entity is in an infinite loop or blocking state.
10. A deadlock detection device, characterized in that: include: A first acquisition module is used to acquire a first RPC call chain of a first scheduling entity, wherein the first RPC call chain includes information reflecting a call relationship between execution entity A1 and execution entity B1; the first acquisition module is specifically used to acquire the first RPC call chain in a kernel state space in the first scheduling entity; A second acquisition module is used to acquire a first lock waiting chain of a first server process, wherein the first lock waiting chain includes information reflecting a waiting relationship between execution entity A2 and execution entity A1, wherein the execution entity A2 is a waiter of lock A, and the execution entity A1 is a holder of the lock A; the second acquisition module is specifically used to acquire the first lock waiting chain in a user state space in the first server process; A processing module, configured to determine that a deadlock exists if the execution entity B1 is the execution entity A2, or if the execution entity B1 and the execution entity A2 are associated with each other; The association relationship includes a calling relationship, a waiting relationship, or a combination of a calling relationship and a waiting relationship.
11. The device according to claim 10, characterized in that The first acquisition module is further used to acquire the waiting lock time of the first scheduling entity; If the waiting lock time of the first scheduling entity is greater than a first threshold, the first RPC call chain of the first scheduling entity is obtained.
12. The device according to claim 10, characterized in that The execution entity B1 is the last execution entity called by the first scheduling entity; The second acquisition module is also used to obtain the second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock in the first scheduling entity, and the second lock waiting chain includes information reflecting the waiting relationship between the execution entity B1 and the execution entity B2, wherein the execution entity B1 is the waiter of lock B, and the execution entity B2 is the holder of lock B.
13. The device according to claim 12, characterized in that The obtaining of the second lock waiting chain of the second server process comprises: The second acquisition module is specifically used to acquire the base address of the execution entity B1 according to the register corresponding to the execution entity B1; The second acquisition module is specifically used to determine the lock-wait field of the execution entity B1 according to the base address and the first offset of the execution entity B1; The second acquisition module is specifically used to acquire the base address of lock B in the lock-wait field of the execution entity B1, wherein the base address of lock B indicates that the execution entity B1 is a waiter of lock B; The second acquisition module is specifically used to determine the lock-owner field according to the base address of the lock B and the second offset; The second acquisition module is specifically used to obtain the identifier of the execution entity B2 in the lock-owner field, wherein the identifier of the execution entity B2 indicates that the execution entity B2 is the holder of lock B.
14. The device according to claim 13, characterized in that The identifier of the execution entity B2 is the base address of the execution entity B2.
15. The device according to claim 12, characterized in that The processing module is further used to determine a second scheduling entity that is running the execution entity B2; The first acquisition module is further used to acquire a second RPC call chain of the second scheduling entity, where the second RPC call chain includes information reflecting a call relationship between the execution entity B2 and the execution entity A2; The processing module is specifically configured to determine that a deadlock exists if there is a waiting relationship between the execution entity B1 and the execution entity B2, and a calling relationship between the execution entity B2 and the execution entity A2.
16. The device according to claim 15, characterized in that The device also includes: A generating module, configured to generate a deadlock alarm, wherein the deadlock alarm includes the first RPC call chain, the association relationship and the first lock waiting chain; Among them, the association relationship includes the second lock waiting chain and the second RPC call chain.
17. The device according to claim 10, characterized in that The execution entity B1 is the last execution entity called by the first scheduling entity: The second acquisition module is further configured to acquire a second lock waiting chain of the second server process if the first RPC call chain indicates that there is no deadlock; The processing module is further configured to start deadlock detection of the third scheduling entity if the second lock waiting chain indicates that the execution entity B1 is not a waiter for lock B.
18. The device according to claim 17, characterized in that The device also includes: A generation module is used to generate an alarm, wherein the alarm includes the first RPC call chain, and the alarm indicates that the first scheduling entity is in an infinite loop or blocking state.
19. A deadlock detection device, characterized in that: include: A processor and a memory, wherein the memory includes a kernel state space and a user state space; The memory stores a first RPC call chain and a first lock wait chain, wherein the first RPC call chain includes information reflecting a call relationship between execution entity A1 and execution entity B1, and the first lock wait chain includes information reflecting a wait relationship between execution entity A2 and execution entity A1; The execution entity A2 is the waiter of lock A, and the execution entity A1 is the holder of lock A; The processor is used to obtain the first RPC call chain and the first lock wait chain; the processor is specifically used to obtain the first RPC call chain in the kernel state space in the first scheduling entity, and the processor is specifically used to obtain the first lock wait chain in the user state space in the first server process; The processor is further configured to determine that a deadlock exists if the execution entity B1 is the execution entity A2, or the execution entity B1 and the execution entity A2 are associated with each other; The association relationship includes a calling relationship, a waiting relationship, or a combination of a calling relationship and a waiting relationship.
