Method, system and equipment for detecting real-time performance of spin lock and medium

By introducing test threads bound to multiple CPU cores and hardware timers into spinlock detection, the accuracy problem of spinlock detection is solved, enabling accurate and flexible detection of spinlock performance. This addresses technical issues not detected in existing technologies and improves the accuracy and flexibility of spinlock performance evaluation.

CN121029550APending Publication Date: 2025-11-28NO 30 INST OF CHINA ELECTRONIC TECH GRP CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510927954.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-07
Publication Date
2025-11-28

AI Technical Summary

Technical Problem

Existing spinlock detection methods have low accuracy and lack detection methods that directly fit actual operation, resulting in spinlocks being unable to effectively evaluate their real-time performance in multi-core application scenarios, thus affecting the overall system performance.

Method used

A spinlock is created in the main thread, and a test thread bound to multiple CPU cores simulates concurrent access to the critical section by multiple threads. A hardware timer is used to calculate the time consumed by the spinlock and the critical section, and the results are fed back to the main thread for analysis and output.

Benefits of technology

It improves the accuracy and operability of real-time performance evaluation of spinlocks, and the detection results are closer to the actual operating conditions. It can detect hidden time-consuming anomalies, quantitatively improve lock performance, and is suitable for multi-core parallel scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121029550A_ABST
    Figure CN121029550A_ABST
Patent Text Reader

Abstract

The invention discloses a spin lock real-time performance detection method, system and device and a medium, and the method comprises the steps: creating a spin lock through a main thread, and creating a test thread bound with a multi-CPU core; the method comprises the following steps: simulating a phenomenon that multiple threads concurrently access a critical zone in a multi-CPU core application scene by testing behaviors of a thread preempting a spin lock and accessing the critical zone, and timing behavior key points; and collecting, processing and analyzing captured data through a main thread, and outputting a real-time detection result of the spin lock. According to the method, the real-time performance of the spin lock can be tested by taking the time of the hardware timer as a reference and taking the time of actually preempting the spin lock and accessing the critical zone by a plurality of test threads as a basis.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of real-time operating system, and particularly relates to a spin lock real-time detection method, system, device and medium. BACKGROUND

[0002] At present, the real-time operating system has strict requirements on the real-time of each link of code running, that is, the maximum time consumption, especially in the multi-core application scenario of multi-thread parallel high preemption. Any thread waiting time that is too long will destroy the overall realtime of the system. A typical high preemption position is the critical section. In order to coordinate the fast access of multi-thread to the critical section, the real-time operating system introduces a spin lock to manage the sharing of resources and prevent data competition and deadlock caused by simultaneous access of multiple threads to the critical section.

[0003] Although the introduction of the spin lock locks the occupation of the shared resource by a single thread and prevents the interference of the remaining threads, if a thread waits for the release of the spin lock for a long time, it will occupy the CPU core where it resides, resulting in a high CPU core occupancy rate, and the remaining work cannot be performed, and the real-time of the system is destroyed. The spin lock mechanism designed for fast access to the critical section finally leads to non-real-time of the real-time system and substandard basic performance, which is contrary to the original design intention. Therefore, it is necessary to detect the real-time of the spin lock before the operating system is released, so as to ensure that the key point related to the real-time of the system can meet the maximum tolerable time consumption.

[0004] The current detection method of the spin lock mainly stays in the detection of deadlock, and the goal is to eliminate deadlock and ensure availability. There are few detection methods for the performance of the spin lock, and only a few of them mention the detection of the time of the spin lock. However, such time detection is based on formula auxiliary calculation or counter counting, and lacks a detection method directly matching the actual running. SUMMARY

[0005] In view of the problems of unknown real-time of the spin lock, low accuracy of the existing detection method, and single detection point in the design, implementation and subsequent use scene of the multi-core real-time operating system, the present application provides a spin lock real-time detection method, system, device and medium, which can complete the detection of the spin lock at any time. The present application can take the time of the hardware timer as the reference, and take the time of the actual preemption of the spin lock and access to the critical section by the multiple test threads as the basis to realize the test of the real-time of the spin lock.

[0006] The technical scheme adopted by the present application is as follows: A spin lock real-time detection method, comprising: creating a spin lock by a main thread, and creating a test thread bound to multiple CPU cores; By testing the behavior of threads preempting spinlocks and accessing critical sections, the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario is simulated, and key points of behavior are timed. The main thread collects, processes, and analyzes the captured data, and outputs the real-time performance test results of the spinlock.

[0007] Furthermore, the step of creating a spinlock through the main thread and creating a test thread bound to multiple CPU cores includes: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

[0008] Furthermore, the behavior of test threads in preempting spinlocks and accessing critical sections simulates the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario, and timings key behavioral points, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual time taken to acquire the lock: C=t b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread obtains the timer t d Then, calculate the C, R, and t values. d The results are fed back to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

[0009] Furthermore, the process of collecting, processing, and analyzing captured data through the main thread, and outputting the spinlock real-time detection results, includes: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

[0010] A real-time spinlock detection system, comprising: The software testing environment setup module is configured to create spinlocks via the main thread and create test threads that are bound to multiple CPU cores; The spinlock real-time detection module is configured to simulate the phenomenon of multi-threaded concurrent access to the critical section in a multi-CPU core application scenario by testing the behavior of the test thread in preempting the spinlock and accessing the critical section, and to time the key points of the behavior. The detection result output module is configured to collect, process, and analyze captured data through the main thread, and output the real-time detection results of the spinlock.

[0011] Furthermore, in the software testing environment setup module, a spinlock is created through the main thread, and test threads bound to multiple CPU cores are created, including: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

[0012] Furthermore, the spinlock real-time detection module simulates the phenomenon of multi-threaded concurrent access to critical sections in multi-CPU core application scenarios by testing the behavior of threads preempting spinlocks and accessing critical sections, and times key behavioral points, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual time taken to acquire the lock: C=t b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread obtains the timer t d Then, calculate the C, R, and t values. dThe results are fed back to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

[0013] Furthermore, in the detection result output module, the main thread collects, processes, and analyzes the captured data, and outputs the spinlock real-time detection result, including: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

[0014] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the above-described spinlock real-time detection method.

[0015] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described spinlock real-time detection method.

[0016] The beneficial effects of this invention are as follows: (1) This invention improves the accuracy and operability of real-time performance evaluation of spinlocks; (2) Compared with traditional calculation methods and isolated observation single-thread timing methods, the detection results of this invention are more accurate, the feature display is more comprehensive, and the usage is more flexible. It not only helps to discover hidden time-consuming anomalies, but also helps to quantify and improve lock performance. (3) Compared with existing testing tools, the results measured by this invention are closer to the actual operating conditions, and the optimization clues are more accurate; (4) This invention can reflect not only single parallelism, but also the time characteristics of each thread preempting the spin lock in multiple parallelisms, which is beneficial for focusing the tuning threads under different purposes; (5) The present invention has multiple sets of critical zone time consumption test cases to choose from, which can balance detection time and detection coverage; (6) The present invention can filter and selectively present the detection results through configuration. Attached Figure Description

[0017] Figure 1 This is a flowchart of a spinlock real-time detection method according to Embodiment 1 of the present invention.

[0018] Figure 2 This is a flowchart of the main thread-related actions in Embodiment 1 of the present invention.

[0019] Figure 3This is a flowchart of the actions related to the spinlock in Embodiment 1 of the present invention.

[0020] Figure 4 This is a flowchart of the actions related to the test thread in Embodiment 1 of the present invention.

[0021] Figure 5 This is a single result diagram of a single critical section time consumption test case in Embodiment 2 of the present invention. Detailed Implementation

[0022] To provide a clearer understanding of the technical features, objectives, and effects of the present invention, specific embodiments are now described. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention; that is, the described embodiments are only a part of the embodiments of the invention, not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0023] Example 1 like Figure 1 As shown, this embodiment provides a method for real-time detection of spinlocks, including: The software testing environment is set up by creating a spinlock in the main thread and creating test threads that are bound to multiple CPU cores. By testing the behavior of threads preempting spinlocks and accessing critical sections, the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario is simulated, and key points of behavior are timed to capture the real-time characteristics of concurrent access in this software testing environment. The main thread collects, processes, and analyzes the captured data, and outputs the real-time performance test results of the spinlock.

[0024] It should be noted that there can be multiple test threads, but the operations involved are the same. Spin locks and test threads are created by the main thread, and except for parameter configuration which requires manual intervention, the rest of the operations are completed automatically. Among the configurable parameters are the number of test threads bound to multiple CPU cores, the priority of test threads, the number of rounds a test thread goes through the critical section, the result presentation method (whether to output statistical values ​​or draw a result graph), and the result filtering settings (whether to present all results or focus on the maximum value of multiple tests by a single thread), etc.

[0025] Preferably, a spinlock is created through the main thread, and a test thread bound to multiple CPU cores is created, including: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

[0026] Preferably, the behavior of test threads in preempting spinlocks and accessing critical sections is used to simulate the phenomenon of multiple threads concurrently accessing critical sections in multi-CPU core application scenarios, and key behavioral points are timed, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual time taken to acquire the lock: C=t b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread will use C, R, and t d Feedback is sent to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

[0027] Preferably, the main thread collects, processes, and analyzes the captured data, and outputs the spinlock real-time detection results, including: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

[0028] Preferably, such as Figure 2 As shown, the main thread-related actions in this embodiment include: (1) Confirm whether there is a risk of overflow in the hardware timer. If there is a risk, reset the hardware timer. (2) Create a spinlock; (3) Create test threads with the same number of CPU cores; (4) Set the test thread to a higher priority; (5) Bind the test threads to different CPU cores in sequence; (6) Collect the results reported by the test threads; (7) After completing the expected number of data collections as set, process and analyze the results, and complete the output as required (if set to plot, complete the plot of the results). (8) According to the settings, decide whether to jump directly to (3) or adjust the critical section of the test thread first, increase the access time, and then jump to (3) to continue to complete a round of testing and output until all test cases of the set critical section are traversed, and finally close the spinlock.

[0029] Preferably, such as Figure 3 As shown, the spinlock-related actions in this embodiment include: (1) The spinlock is created by the main thread; (2) The spinlock was acquired by a test thread; (3) The critical section is handed over to the test thread for execution of the program segment; (4) The spinlock is released by the test thread; (5) Repeat the above actions until the spinlock is closed by the main thread.

[0030] Preferably, such as Figure 4 As shown, the actions related to the test thread in this embodiment include: (1) Created by the main thread; (2) Set as high priority by the main thread; (3) It is bound to a CPU core by the main thread; (4) Get the current time t a ; (5) Seize the spinlock; (6) Get the current time t b ; (7) After the critical section program segment is executed, the time t is obtained. c ; (8) Get the current timer t d ; (9) To reduce the amount of communication fed back to the main thread, the actual lock acquisition time C (C=t) is calculated in advance. b -t a ), the time consumed by the critical section program segment R (R=t) c -t b ), then C, R and t d Feedback is sent to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a Execute a new round of spinlock preemption.

[0031] Example 2 This embodiment is based on embodiment 1: This embodiment provides a method for real-time detection of spinlocks. On a multi-core ARM platform, assuming there are n CPU cores, test cases for detecting the time consumption of a single test and the critical section are set (4 test cases with times of 1μs, 5μs, 10μs and 50μs respectively), and the ARM platform's built-in 64-bit global hardware timer is used for timing.

[0032] In this embodiment, after the main thread checks that the hardware timer has no overflow risk, it completes the creation of the spinlock and n test threads. After completing the priority creation of the test threads, the main thread binds each thread to n cores in sequence. The first test thread to complete the binding, Thread 1, obtains the current time t. 1a And preempt the spinlock. After preemption, test thread 1 obtains the current time t. 1b Then, the first critical section timeout test case (1μs) is executed. After execution, test thread 1 obtains the current time t. 1c Then release the spinlock. After the spinlock is released, test thread 1 obtains the current time t. 1d And calculate your actual lock acquisition time C (C=t) b -t a ), the time consumed by the critical section program segment R (R=t) c -t b ), then C, R and t d Feedback is sent to the main thread.

[0033] Afterwards, switching to the second critical section time-consuming test case (5μs), test thread 1 re-acquires a new t. 1a This restarts a new round of spin lock preemption actions and subsequent time acquisition operations, using the newly acquired C, R, and t. d Feedback is sent to the main thread. Then, switch to the third critical section time-consuming test case (10μs) and the fourth critical section time-consuming test case (50μs), repeating the same operation until the process stops.

[0034] Similarly, test threads 2 through n also complete the same operations, and the main thread collects all the results. According to the plotting settings, the main thread plots the curves for the time consumption of the four critical section test cases. The curve for a single critical section test case is shown below. Figure 5 As shown, the interlocking time is D1=t. mb -t 1d (m represents the test thread number that preempted the spinlock immediately after test thread 1), and so on, the main thread draws D2~D at the corresponding positions. n-1 .

[0035] Example 3 This embodiment is based on embodiment 1: This embodiment provides a method for real-time detection of spinlocks. Compared with the single test in Embodiment 2, this embodiment sets up multiple tests.

[0036] In this embodiment, the output value is determined after multiple tests and statistical calculations. Since the real-time performance of spinlocks is often concerned with the maximum time consumption, the smaller values ​​are discarded, the maximum value is selected for output, and a graph is plotted.

[0037] Example 4 This embodiment is based on embodiment 1: This embodiment provides a spinlock real-time performance detection method. Compared to the output of CPU cores 1 to n in Embodiment 3, this embodiment focuses on observing the output value of a specific core. For example, it focuses on core 1.

[0038] In this embodiment, after multiple tests and statistical calculations, the maximum value is output and plotted on a graph. Because the number of repetitions is sufficient and the spinlock operates under high preemption conditions, the results from the core 1 test thread can broadly reflect the overall global situation, allowing testers to focus on optimization.

[0039] Example 5 This embodiment provides a spinlock real-time performance detection system, including: The software testing environment setup module is configured to create spinlocks via the main thread and create test threads that are bound to multiple CPU cores; The spinlock real-time detection module is configured to simulate the phenomenon of multi-threaded concurrent access to the critical section in a multi-CPU core application scenario by testing the behavior of the test thread in preempting the spinlock and accessing the critical section, and to time the key points of the behavior. The detection result output module is configured to collect, process, and analyze captured data through the main thread, and output the real-time detection results of the spinlock.

[0040] Preferably, in the software testing environment setup module, a spinlock is created through the main thread, and a test thread bound to multiple CPU cores is created, including: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

[0041] Preferably, in the spinlock real-time detection module, the behavior of test threads preempting spinlocks and accessing critical sections is used to simulate the phenomenon of multi-threaded concurrent access to critical sections in multi-CPU core application scenarios, and key behavioral points are timed, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual time taken to acquire the lock: C=t b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread will use C, R, and t d Feedback is sent to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

[0042] Preferably, in the detection result output module, the captured data is collected, processed, and analyzed through the main thread, and the spinlock real-time detection result is output, including: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

[0043] Example 6 This embodiment is based on embodiment 1: This embodiment provides a computer device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the spinlock real-time detection method of Embodiment 1. The computer program can be in the form of source code, object code, executable file, or some intermediate form.

[0044] Example 7 This embodiment is based on embodiment 1: This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the spinlock real-time detection method of Embodiment 1. The computer program can be in the form of source code, object code, executable file, or some intermediate form. The storage medium includes any entity or device capable of carrying computer program code, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc. It should be noted that the content contained in the storage medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the storage medium does not include electrical carrier signals and telecommunication signals.

[0045] It should be noted that, for the sake of simplicity, the foregoing method embodiments are described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

Claims

1. A method for real-time detection of spinlock, characterized in that, include: Create a spinlock using the main thread, and create a test thread that is bound to multiple CPU cores; By testing the behavior of threads preempting spinlocks and accessing critical sections, the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario is simulated, and key points of behavior are timed. The main thread collects, processes, and analyzes the captured data, and outputs the real-time performance test results of the spinlock.

2. The method for real-time detection of spinlock according to claim 1, characterized in that, The process of creating a spinlock via the main thread and creating a test thread bound to multiple CPU cores includes: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

3. The method for real-time detection of spinlock according to claim 1, characterized in that, The test simulates the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario by testing the behavior of threads preempting spinlocks and accessing critical sections, and times key points of the behavior, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual lock acquisition time C=t. b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread obtains the timer t d Then, calculate the C, R, and t values. d The results are fed back to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

4. The method for real-time detection of spinlock according to claim 1, characterized in that, The process of collecting, processing, and analyzing captured data through the main thread, and outputting the real-time detection results of the spinlock, includes: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

5. A real-time detection system for spinlocks, characterized in that, include: The software testing environment setup module is configured to create spinlocks via the main thread and create test threads that are bound to multiple CPU cores; The spinlock real-time detection module is configured to simulate the phenomenon of multi-threaded concurrent access to the critical section in a multi-CPU core application scenario by testing the behavior of the test thread in preempting the spinlock and accessing the critical section, and to time the key points of the behavior. The detection result output module is configured to collect, process, and analyze captured data through the main thread, and output the real-time detection results of the spinlock.

6. The spinlock real-time detection system according to claim 5, characterized in that, The software testing environment setup module creates a spinlock through the main thread and creates test threads bound to multiple CPU cores, including: The main thread checks whether there is a risk of overflow in the hardware timer; if there is a risk, it resets the hardware timer. The main thread creates a spinlock; The main thread creates test threads with the same number of CPU cores, sets the test threads to high priority, and binds the test threads to different CPU cores in sequence.

7. The spinlock real-time detection system according to claim 5, characterized in that, The spinlock real-time detection module simulates the phenomenon of multiple threads concurrently accessing critical sections in a multi-CPU core application scenario by testing the behavior of threads preempting spinlocks and accessing critical sections, and times key points of behavior, including: The test thread is bound to a specific CPU core by the main thread to obtain the current timer t. a ; The test thread preempts the spin lock and obtains the current timer t. b ; After the test thread finishes executing the critical section, it obtains the timer t. c ; The test thread obtains the current timer t. d ; The test thread pre-calculates the actual lock acquisition time C=t. b -t a And the time consumed by the critical section R=t c -t b This reduces the amount of communication sent back to the main thread. The test thread obtains the timer t d Then, calculate the C, R, and t values. d The results are fed back to the main thread, and a decision is made based on the loop settings whether to re-acquire a new t. a And to execute a new round of spinlock preemption.

8. The spinlock real-time detection system according to claim 5, characterized in that, The detection result output module collects, processes, and analyzes captured data through the main thread, and outputs the spinlock real-time detection results, including: The main thread collects the results from the test thread, completes the expected number of collections as set, processes and analyzes the results, and outputs them as required. The main thread adjusts the critical section of the test thread according to the settings, increases the access time, and continues to execute the next round of testing and output until all test cases of the set critical section have been traversed, and finally closes the spinlock.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the spinlock real-time detection method according to any one of claims 1-4.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the spinlock real-time detection method according to any one of claims 1-4.