Lock competition mechanism testing method and system under high-concurrency scene

By using lock status flags and competition reset instructions in high concurrency scenarios, the problem of uneven participation of processing units in lock competition function testing is solved, and a more comprehensive and efficient testing process is achieved.

CN119718699APending Publication Date: 2025-03-28SHANGHAI SMARTLOGIC TECHNOLOGY LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411758054.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

In high concurrency scenarios, it is difficult for the prior art to comprehensively and fairly test the lock competition function of multiple processing units participating in, resulting in some processing units being unable to participate in the test due to competition failure, and wasting CPU resources.

Method used

Under the management of the control processing unit, the lock status flag is used to determine whether each processing unit has obtained the target lock resource, and after each test round, the competition reset instruction is sent to each processing unit to restart the competition and update the number of test rounds.

Benefits of technology

Ensure that each processing unit has the opportunity to acquire lock resources in multiple rounds of tests, improves the comprehensiveness and fairness of the test, reduces performance overhead, and avoids long-term busy waiting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718699A_ABST
    Figure CN119718699A_ABST
Patent Text Reader

Abstract

The invention relates to a method and a system for testing a lock competition mechanism in a high-concurrency scene, and relates to the technical field of computers. The method comprises the following steps: a plurality of processing units perform competition processing on target lock resources based on a preset spin lock test function; the target processing unit obtains the target lock resource and updates the occupation state of the target lock resource through the lock state flag; after determining that each processing unit obtains the target lock resource according to the lock state flag, controlling the processing unit to send a competition reset instruction to each processing unit, so that each processing unit restarts competition processing of the target lock resource, and the number of test rounds is updated; and after the test round number reaches a preset number of times, the control processing unit controls to quit the competition test of the target lock resource. By adopting the method, an efficient, accurate and reliable test process can be formed through competition processing of the multiple processing units, optimization of a synchronization mechanism and resetting and round number management of the control processing units.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and system for testing a lock contention mechanism in a high-concurrency scenario. Background Art

[0002] The lock contention mechanism is a synchronization technique used to ensure mutually exclusive access to shared resources in a multi-processor or multi-threaded environment. The lock mechanism can prevent multiple processing units or threads from accessing and modifying the same resource at the same time, thereby avoiding resource contention and data inconsistency. In a multi-processing unit system, each processing unit (processor core or virtual core) can be regarded as a Hart, which is usually used to represent the basic unit of concurrent processing capability. Each Hart can execute instructions and process tasks independently. Under the lock contention mechanism, multiple processing units may try to obtain exclusive access to a resource at the same time. In the process of acquiring the lock, the processing unit will check the status of the lock. If the lock is not occupied, the processing unit can successfully acquire the lock; if the lock is occupied by other processing units, the processing unit will enter a waiting state until the lock is released. In this regard, a testing method is currently needed to effectively and comprehensively test the lock contention function of all processing units in high concurrency situations. Summary of the invention

[0003] Based on this, it is necessary to provide a lock contention mechanism testing method and system, device and storage medium in a high concurrency scenario to address the above technical issues.

[0004] In a first aspect, the present application provides a method for testing a lock contention mechanism in a high-concurrency scenario. The method comprises:

[0005] Multiple processing units perform competition processing for target lock resources based on a preset spin lock test function;

[0006] The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag;

[0007] After determining that each of the processing units has obtained the target lock resource according to the lock status flag, the control processing unit sends a contention reset instruction to each of the processing units, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds;

[0008] After the number of test rounds reaches a preset number, the control processing unit controls to exit the competition test of the target lock resource.

[0009] In one of the embodiments, the lock status flag is a competition completion flag;

[0010] The method further comprises:

[0011] The target processing unit releases the target lock resource, sets the target lock resource to a released state through the competition completion flag, and records in the competition completion flag that the target processing unit completes the competition.

[0012] In one embodiment, after determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units comprises:

[0013] The control processing unit determines the number of processing units that have completed competition according to the competition completion flag;

[0014] If the number of the processing units that have completed the contention is equal to the total number of the plurality of processing units, the control processing unit sends a contention reset instruction to each of the other processing units and resets the contention completion flag.

[0015] In one of the embodiments, the lock status flag is a competition participation flag;

[0016] The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag, including:

[0017] The target processing unit obtains the target lock resource and records in the competition participation flag that the target processing unit has participated in the competition.

[0018] In one embodiment, after determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units comprises:

[0019] The target processing unit releases the target lock resource, and determines the number of processing units that have participated in the competition according to the competition participation flag;

[0020] If the number of the processing units that have participated in the competition is equal to the total number of the multiple processing units, the target processing unit sends a competition reset instruction to each of the other processing units and resets the competition participation flag, otherwise it enters a low power standby mode.

[0021] In one of the embodiments, the lock state flag includes a plurality of lock state sub-flags, each lock state sub-flag corresponding to a different part of the processing unit;

[0022] The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag, including:

[0023] The target processing unit obtains the target lock resource, and updates the occupation status of the target lock resource through all lock status flags corresponding to the target processing unit;

[0024] After determining that each of the processing units has obtained the target lock resource according to the lock state flag, the control processing unit sends a contention reset instruction to each of the processing units, so that each processing unit restarts the contention processing of the target lock resource, including:

[0025] After determining that each corresponding specific processing unit has obtained the target lock resource according to the target lock status sub-flag, the control processing unit sends a competition reset instruction to each specific processing unit so that each specific processing unit restarts the competition processing for the target lock resource.

[0026] In one embodiment, the method further comprises:

[0027] The control processing unit determines a plurality of processing units participating in each round of testing of the target lock resource based on the preset test times and processing performance information of each processing unit and the plurality of lock resources to be tested;

[0028] After determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units, including:

[0029] After determining that each of the processing units has obtained the target lock resource according to the lock status flag, the control processing unit sends a competition reset instruction to each candidate processing unit participating in the next round of testing according to the number of test rounds, so that each candidate processing unit restarts the competition processing for the lock resource.

[0030] In a second aspect, the present application also provides a lock contention mechanism testing system in a high concurrency scenario. The system includes multiple processing units and a control processing unit, wherein:

[0031] The multiple processing units are used to:

[0032] Based on the preset spin lock test function, the competition for the target lock resource is processed;

[0033] Obtain the target lock resource, and update the occupation status of the target lock resource through a lock status flag;

[0034] The control processing unit is used for:

[0035] After determining that each of the processing units has obtained the target lock resource according to the lock state flag, sending a contention reset instruction to each of the processing units, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds;

[0036] After the number of test rounds reaches a preset number, the competition test of the target lock resource is exited.

[0037] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the processing steps of the processing unit in the method described in the first aspect are implemented.

[0038] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.

[0039] In a fifth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.

[0040] The lock contention mechanism testing method in a high-concurrency scenario disclosed in the present application is adopted. After the control processing unit determines that each processing unit has obtained the target lock resource according to the lock status flag, it sends a competition reset instruction to make each processing unit restart the competition. This method ensures that each processing unit has the opportunity to obtain the lock resource in multiple rounds of testing, improves the comprehensiveness and fairness of the test, and avoids the situation where some processing units are unable to participate in the test due to competition failure. In the traditional busy waiting mode, the processing unit will continuously check the lock status flag in a loop, resulting in a large amount of CPU resource waste. With this method, although the processing unit will still be busy waiting after the competition fails, it will be reset and restarted after each round of testing, avoiding long busy waiting, thereby reducing performance overhead. In this way, an efficient, accurate and reliable test process can be formed through the competition processing of multiple processing units, the optimization of the synchronization mechanism, and the reset and round number management of the control processing unit. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is a flowchart of a method for testing a lock contention mechanism in a high-concurrency scenario in an embodiment;

[0042] Figure 2 A schematic diagram of a lock contention mechanism testing system architecture in a high concurrency scenario in an embodiment;

[0043] Figure 3 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0045] In a multi-processor system, a spin lock is a commonly used synchronization mechanism. A spin lock uses a flag to implement lock contention. If the lock is occupied by other processors, the processor requesting the lock will enter a busy wait (spin) state until the lock is released. The prior art solution usually uses a control processing unit (which may be called a control Hart) to manage the lock contention test of other Harts. The control Hart notifies other Harts to start contention for the lock through a lock status flag. Other Harts determine whether to start contention for the lock by checking the lock status flag. If the lock status flag is modified, other Harts will enter the while1 loop and wait for the lock to be released. However, as the number of Harts increases, some Harts may remain in the while1 loop after the lock status flag is modified, causing the test program to get stuck, thereby causing the test to fail.

[0046] In view of the problems in the prior art, the embodiment of the present application provides a method for testing the lock contention mechanism in a high-concurrency scenario. The method is applicable to the test environment of the lock contention mechanism of multiple processing units, especially for the high-concurrency scenario with a large number of processing units. The method mainly tests the performance of the spin lock in a high-concurrency situation, and checks whether the lock fails by competing for the lock with a large number of Hart processors. Regardless of the number of Harts, the lock contention test can be performed. The more Harts there are, the higher the probability of lock contention.

[0047] In one embodiment, Figure 1 As shown, a method for testing the lock contention mechanism in a high concurrency scenario is provided, including the following steps:

[0048] Step 101: multiple processing units perform contention processing for target lock resources based on a preset spin lock test function.

[0049] In the implementation, each processing unit (Hart) runs a preset spin lock test function, which contains the logic of acquiring and releasing the lock. All Harts can be started at the same time to try to acquire the same target lock resource. When competing for the target lock resource, Hart checks the lock status flag by busy waiting (spin waiting) to determine whether the target lock resource is occupied by other Harts. Spin lock is a lock mechanism. When a Hart tries to acquire a lock that is occupied by other Harts, it will continuously loop to check the lock status until the lock is released.

[0050] Step 102: The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through the lock status flag.

[0051] In implementation, the lock status flag is a global variable used to indicate whether the lock resource is occupied. When a Hart (i.e., the target processing unit) successfully acquires the target lock resource, the lock status flag can be updated to indicate that the target lock resource is occupied. The update of the lock status flag enables other Harts to accurately determine the status of the lock resource and avoid invalid competition. Similarly, when the target processing unit releases the target lock resource, it can also update the lock status flag to indicate that the target lock resource is released.

[0052] Step 103, after determining that each processing unit has obtained the target lock resource according to the lock status flag, the control processing unit sends a contention reset instruction to each processing unit, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds.

[0053] In implementation, the control processing unit may be a processing unit responsible for monitoring and managing the test process, usually an independent thread or process. The control processing unit may determine whether each processing unit has obtained the target lock resource through the lock status flag. After determining that all processing units have obtained the target lock resource, the control processing unit may send a competition reset instruction to each processing unit to notify Hart to reset its internal state and restart the competition for the target lock resource. At the same time, the control processing unit may mark that the current round of the lock competition mechanism test has been completed, and at the same time update the number of test rounds and record the progress of the current test. It can be understood that in the lock status flag, the acquisition status of the processing unit for the target lock resource may be recorded. Specifically, if there are n processing units participating in the lock competition mechanism test, then the lock status flag may be preset with n status bits, each status bit corresponding to a processing unit. After a processing unit obtains the target lock resource, each status bit may be adjusted from the initial value to a predetermined value. In this way, when the values ​​of all status bits are predetermined values, it can be determined that all processing units have obtained the target lock resource.

[0054] Step 104 , after the number of test rounds reaches a preset number, the control processing unit controls the exit of the contention test of the target lock resource.

[0055] In implementation, the control processing unit updates the number of test rounds after each round of testing. When the number of test rounds reaches a preset number (e.g., 1000 times), the control processing unit sends an exit instruction to all Harts. After receiving the exit instruction, Hart can stop competing for lock resources and exit the spin lock test function. Afterwards, the control processing unit can collect and analyze the test results and output a test report.

[0056] The lock contention mechanism testing method in a high-concurrency scenario disclosed in the present application is adopted. After the control processing unit determines that each processing unit has obtained the target lock resource according to the lock status flag, it sends a competition reset instruction to make each processing unit restart the competition. This method ensures that each processing unit has the opportunity to obtain the lock resource in multiple rounds of testing, improves the comprehensiveness and fairness of the test, and avoids the situation where some processing units are unable to participate in the test due to competition failure. In the traditional busy waiting mode, the processing unit will continuously check the lock status flag in a loop, resulting in a large amount of CPU resource waste. With this method, although the processing unit will still be busy waiting after the competition fails, it will be reset and restarted after each round of testing, avoiding long busy waiting, thereby reducing performance overhead. In this way, an efficient, accurate and reliable test process can be formed through the competition processing of multiple processing units, the optimization of the synchronization mechanism, and the reset and round number management of the control processing unit.

[0057] In one embodiment, the lock state flag is a competition completion flag; the above method also includes: the target processing unit releases the target lock resource, sets the target lock resource to a released state through the competition completion flag, and records in the competition completion flag that the target processing unit completes the competition.

[0058] In implementation, after obtaining the target lock resource, the target processing unit can enter the critical section to perform related tasks. After the target processing unit completes the task in the critical section, the target lock resource can be released. The operation of releasing the target lock resource may include setting the resource status bit of the competition completion flag (ipi_flag) from 1 to 0, indicating that the target lock resource has been released, which ensures that other processing units can detect the available state of the target lock resource, thereby having the opportunity to obtain the lock resource and enter the critical section. Here, the competition completion flag can be a flag for recording the completion status of each processing unit's competition for lock resources. It can be an array or a bitmap, each processing unit corresponds to a hart flag bit, and the initial value of the hart flag bit can be set to 0. After the target processing unit successfully obtains and releases the lock resource, its corresponding hart flag bit can be set to 1, indicating that the target processing unit has successfully completed a lock resource competition. In this way, the control processing unit can determine the completion status of the competition of each processing unit by checking the hart flag bit value in the competition completion flag. After releasing the target lock resource, the target processing unit may enter a low power standby mode until receiving a contention reset instruction sent by the control processing unit to restart a new round of contention test of the target lock resource.

[0059] In one embodiment, based on the situation where the lock status flag is a competition completion flag, the processing of step 103 can be specifically as follows: the control processing unit determines the number of processing units that have completed the competition according to the competition completion flag; if the number of processing units that have completed the competition is equal to the total number of multiple processing units, the control processing unit sends a competition reset instruction to each other processing unit and resets the competition completion flag.

[0060] In implementation, the contention completion flag may include an array ipi_flag[0,1,2,...,n-1], where n may be the total number of processing units. The initial value of each hart flag bit may be set to 0, indicating that the processing unit has not yet completed the contention. The control processing unit may periodically check each hart flag bit in ipi_flag. Specifically, the control processing unit may traverse the ipi_flag array or bitmap and count the number of flag bits whose values ​​are 1, and these flag bits whose values ​​are 1 indicate that the corresponding processing unit has successfully completed a contention for lock resources. After the statistics are completed, the control processing unit compares the number of processing units that have completed the contention with the total number of processing units. If the number of processing units that have completed the contention is equal to the total number of processing units, it means that each processing unit has successfully acquired and released the target lock resource at least once.

[0061] After the control processing unit confirms that all processing units have completed the competition, the competition reset process can be triggered. The specific steps are as follows: the control processing unit sends a competition reset instruction to each processing unit to notify the processing unit to prepare for a new round of lock resource competition test. At the same time, the control processing unit can reset ipi_flag and reset the values ​​of all hart flags to 0. In this way, all processing units can restart recording their competition completion status in the new round of competition.

[0062] Furthermore, at the beginning of each round of testing, a processing unit can be randomly selected as the control processing unit for this round of testing based on the ID of each processing unit. In this way, the control processing unit is not fixed, and each processing unit has equal and consistent testing competition opportunities, which can ensure that each processing unit has the opportunity to participate in acquiring lock resources in multiple rounds of testing, thereby improving the comprehensiveness of the test and ensuring that all processing units are fully tested.

[0063] In one embodiment, the lock state flag is a competition participation flag; the processing of step 102 may be specifically as follows: the target processing unit obtains the target lock resource, and records in the competition participation flag that the target processing unit has participated in the competition.

[0064] In implementation, after the target processing unit obtains the target lock resources, it can enter the critical area to perform related tasks. At the same time, the target processing unit can update the competition participation flag (run_flag) to record that the target processing unit has participated in the competition. Here, the competition participation flag can be a flag used to record whether each processing unit has participated in the lock resource competition. It can be an array or a bitmap. Each processing unit corresponds to a hart flag bit. The initial value of the hart flag bit can be set to 0, indicating that the corresponding processing unit has not yet participated in the competition. After the target processing unit successfully obtains the target lock resources, its corresponding hart flag bit can be set to 1, indicating that the target processing unit has successfully participated in the competition for the target lock resources. In this way, through run_flag, it can be clearly confirmed which processing units have participated in the competition for the target lock resources, thereby ensuring that all processing units have the opportunity to participate in the competition.

[0065] In one embodiment, based on the situation where the lock status flag is a competition participation flag, the processing of step 103 can be specifically as follows: the target processing unit releases the target lock resources, and determines the number of processing units that have participated in the competition according to the competition participation flag; if the number of processing units that have participated in the competition is equal to the total number of multiple processing units, the target processing unit sends a competition reset instruction to each other processing unit and resets the competition participation flag, otherwise it enters a low-power standby mode.

[0066] In implementation, after the target processing unit acquires the target lock resource and completes the task of the critical section, the acquired target lock resource can be released. The specific operation may include setting the resource status bit of ipi_flag from 1 to 0, indicating that the target lock resource has been released. While releasing the target lock resource, the target processing unit may check the number of processing units that have participated in the competition in run_flag. The specific processing may include traversing the run_flag array or bitmap and counting the number of hart flag bits whose values ​​are 1. After the statistics are completed, the target processing unit compares the number of processing units that have participated in the competition that can be counted with the total number of processing units. If the counted number is equal to the total number of processing units, it means that all processing units have participated in the competition. At this time, the target processing unit can serve as a temporary control processing unit to send a competition reset instruction to each other processing unit to notify them to prepare for a new round of lock resource competition test. At the same time, the target processing unit can reset run_flag and reset the values ​​of all hart flag bits to 0 so as to re-record the competition participation of each processing unit in the new round of competition. If the number of processing units that have participated in the competition that is counted is not equal to the total number of processing units, it means that there are still processing units that have not participated in the competition. In this case, the target processing unit will enter a low-power standby mode until a new competing instruction is received.

[0067] For example, assume a multi-processing unit system, including 4 processing units (0, 1, 2, 3), each processing unit has a corresponding hart flag. Initially, the value of run_flag is [0, 0, 0, 0], indicating that all processing units have not yet participated in the competition.

[0068] Processing unit 0 obtains the lock resource and executes ipi_flag=1, indicating that processing unit 0 has obtained the lock resource. Executing run_flag[0]=1 indicates that processing unit 0 has participated in the competition.

[0069] Processing unit 0 releases the lock resource and executes ipi_flag = 0, indicating that processing unit 0 has released the lock resource. Check run_flag and count the number of flag bits with a value of 1. Assuming that the current run_flag is [1, 0, 0, 0], the statistical result is 1, which is not equal to 4, and processing unit 0 enters low-power standby mode.

[0070] Processing unit 1 obtains the lock resource and executes ipi_flag=1, indicating that processing unit 1 has obtained the lock resource. Executing run_flag[1]=1 indicates that processing unit 1 has participated in the competition.

[0071] Processing unit 1 releases the lock resource and executes ipi_flag = 0, indicating that processing unit 1 has released the lock resource. Check run_flag and count the number of flag bits with a value of 1. Assuming that the current run_flag is [1,1,0,0], the statistical result is 2, which is not equal to 4, and processing unit 1 enters low-power standby mode.

[0072] Processing unit 2 obtains the lock resource and executes ipi_flag=1, indicating that processing unit 2 has obtained the lock resource. Executing run_flag[2]=1 indicates that processing unit 2 has participated in the competition.

[0073] Processing unit 2 releases the lock resource and executes ipi_flag = 0, indicating that processing unit 2 has released the lock resource. Check run_flag and count the number of flag bits with a value of 1. Assuming that the current run_flag is [1,1,1,0], the statistical result is 3, which is not equal to 4, and processing unit 2 enters low-power standby mode.

[0074] Processing unit 3 obtains the lock resource and executes ipi_flag=1, indicating that processing unit 3 has obtained the lock resource. Executing run_flag[3]=1 indicates that processing unit 3 has participated in the competition.

[0075] Processing unit 3 releases the lock resource and executes ipi_flag=0, indicating that processing unit 3 has released the lock resource. Check run_flag and count the number of flag bits with a value of 1. Assume that the current run_flag is [1,1,1,1], the statistical result is 4, which is equal to 4. Processing unit 3 acts as a temporary control processing unit and sends a contention reset instruction to each other processing unit. Reset run_flag to [0,0,0,0] to prepare for a new round of contention testing.

[0076] In this way, run_flag is used to record whether each processing unit has participated in the competition, and the last processing unit that obtains the lock resource serves as the control unit to trigger the next round of lock contention test. The control processing unit is not fixed, and each processing unit has equal and consistent test competition opportunities, which can ensure that each processing unit has the opportunity to obtain lock resources in multiple rounds of testing, thereby improving the comprehensiveness of the test and ensuring that all processing units are fully tested.

[0077] It is worth mentioning that in the various embodiments of the present disclosure, the term "simultaneously" does not strictly limit the execution sequence of the relevant steps. The relevant steps can be started at the same time or have a certain start time difference. The order of execution can also be determined according to the situation.

[0078] In one embodiment, the lock status flag includes multiple lock status sub-flags, each lock status sub-flag corresponds to a different part of the processing unit; the processing of step 102 can be corresponding as follows: the target processing unit obtains the target lock resource, and updates the occupancy status of the target lock resource through all lock status flags corresponding to the target processing unit; the processing of step 103 can be corresponding as follows: after determining that each corresponding specific processing unit has obtained the target lock resource according to the target lock status sub-flag, the control processing unit sends a competition reset instruction to each specific processing unit, so that each specific processing unit restarts the competition processing of the target lock resource.

[0079] In implementation, the lock state flag may include multiple lock state sub-flags, each lock state sub-flag corresponds to a group of processing units, the specific processing units included in each group of processing units are not exactly the same, and the same processing unit may correspond to multiple lock state sub-flags. Through multiple lock state sub-flags, the competition status of different groups of processing units can be managed more finely to ensure that each group of processing units can participate in the competition for lock resources fairly. After the target processing unit successfully obtains the target lock resources, it can enter the critical area to perform related tasks. At the same time, the target processing unit can update its competition participation in all corresponding lock state sub-flags. Specifically, the target processing unit will set the hart flag bit in all corresponding lock state sub-flags from 0 to 1.

[0080] The control processing unit can determine whether each processing unit has obtained the target lock resource through the lock state flag. In this embodiment, the control processing unit can poll each lock state sub-flag to determine the lock competition participation status of each corresponding processing unit. After determining that each corresponding specific processing unit has obtained the target lock resource according to the target lock state sub-flag, the control processing unit can send a competition reset instruction to each specific processing unit to notify Hart to reset its internal state and restart the competition for lock resources. It should be noted that at this time, the lock competition mechanism test of the current round is not necessarily completed, only all specific processing units have completed the participation in a lock competition. Further, a competition reset number bit can also be set in each lock state sub-flag to record the number of lock competition resets of the processing unit corresponding to the current lock state sub-flag in the current round of testing. It can be understood that each lock state sub-flag is preset with a preset value of the number of competition resets. Only when the value of the number of competition resets in all lock state sub-flags is equal to the preset value, the control processing unit can mark the current round of lock competition mechanism test as completed, and update the number of test rounds at the same time to record the progress of the current test.

[0081] In this way, by grouping the processing units through the lock status sub-flags, the number of times each processing unit participates in the competition during a round of lock contention testing can be flexibly set, thereby making the lock contention test more flexible and comprehensive, and able to better match various actual lock resource competition scenarios.

[0082] In one embodiment, the method also includes: controlling the processing unit to determine multiple processing units participating in each round of testing of the target lock resource based on a preset number of tests and processing performance information of each processing unit, and multiple lock resources to be tested; after determining according to the lock status flag that each processing unit has obtained the target lock resource, controlling the processing unit to send a competition reset instruction to each processing unit, including: after determining according to the lock status flag that each processing unit has obtained the target lock resource, controlling the processing unit to send a competition reset instruction to each candidate processing unit participating in the next round of testing according to the number of test rounds, so that each candidate processing unit restarts the competition processing for the lock resource.

[0083] In implementation, each processing unit may have a preset number of tests corresponding to the actual test requirements. The preset number of tests for each processing unit refers to the rounds that the processing unit needs to participate in all tests. For example, processing unit 0 may need to participate in 10 rounds of tests, processing unit 1 may need to participate in 5 rounds of tests, and so on. In addition, different processing units may have different processing performance information, and processing performance information refers to the performance indicators of each processing unit, such as processing speed, power consumption, etc. This information can help the control processing unit to reasonably arrange the test rounds, ensuring that high-performance processing units can participate in the test more frequently, and low-performance processing units can also have the opportunity to participate. At the same time, there may be multiple lock resources in the system that need to be tested, and each lock resource may have different processing units competing in different test rounds.

[0084] In view of the above situation, a lock contention test across lock resources can be carried out in the lock contention mechanism test phase, that is, according to the preset test times and processing performance information of each processing unit, the test rounds of each lock resource and the processing units participating in each round of testing can be reasonably arranged. The processing units in each round of testing are different, and the lock resources are also different. Specifically, the control processing unit can reasonably allocate the processing units participating in each round of testing according to the preset test times and processing performance information of each processing unit. For example, if a specific lock resource needs to be tested in a round, the control processing unit will select a processing unit with higher performance from the processing units that have not completed the preset test times to participate. Assume that there are 4 processing units (0, 1, 2, 3) in the system, the preset test times are (10, 5, 7, 8) respectively, the processing performance information is (high speed, medium speed, medium speed, low speed) respectively, and there are 2 lock resources to be tested (A and B). The control processing unit can reasonably arrange the participating processing units in each round of testing based on this information.

[0085] After arranging the lock resources and participating processing units for each round of testing, the control unit can determine whether all processing units participating in the current test round have obtained the current lock resources according to the lock status flag corresponding to each round of lock resources. If so, the control processing unit can determine the candidate processing units participating in the next round of testing and the lock resources for the next round according to the number of test rounds, and then send a contention reset instruction carrying a lock resource identifier to each candidate processing unit participating in the next round of testing, so that each candidate processing unit restarts the corresponding lock resource contention processing.

[0086] In this way, based on the above processing, the test cost, the performance of the processing unit and the lock resources that need to be tested can be comprehensively considered, and the test process can be reasonably designed to realize the testing of the lock contention mechanism across lock resources, thereby meeting more complex testing requirements and making the testing of the lock contention mechanism more comprehensive and flexible.

[0087] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0088] Based on the same inventive concept, Figure 2 As shown, the embodiment of the present application also provides a lock contention mechanism testing system in a high concurrency scenario. The system includes multiple processing units and a control processing unit, wherein:

[0089] The multiple processing units are used to:

[0090] Based on the preset spin lock test function, the competition for the target lock resource is processed;

[0091] Obtain the target lock resource, and update the occupation status of the target lock resource through a lock status flag;

[0092] The control processing unit is used for:

[0093] After determining that each of the processing units has obtained the target lock resource according to the lock state flag, sending a contention reset instruction to each of the processing units, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds;

[0094] After the number of test rounds reaches a preset number, the competition test of the target lock resource is exited.

[0095] In one of the embodiments, the lock status flag is a competition completion flag;

[0096] A target processing unit among the plurality of processing units is configured to:

[0097] The target lock resource is released, the target lock resource is set to a released state through the competition completion flag, and the target processing unit completes the competition in the competition completion flag.

[0098] In one embodiment, the control processing unit is specifically used to:

[0099] Determine the number of processing units that have completed competition according to the competition completion flag;

[0100] If the number of the processing units that have completed the contention is equal to the total number of the plurality of processing units, a contention reset instruction is sent to each of the other processing units, and the contention completion flag is reset.

[0101] In one of the embodiments, the lock status flag is a competition participation flag;

[0102] The target processing unit among the multiple processing units is specifically used for:

[0103] The target lock resource is obtained, and the target processing unit is recorded in the competition participation flag as having participated in the competition.

[0104] In one embodiment, the target processing unit among the plurality of processing units is specifically used for:

[0105] releasing the target lock resource, and determining the number of processing units that have participated in the competition according to the competition participation flag;

[0106] If the number of the processing units that have participated in the competition is equal to the total number of the multiple processing units, a competition reset instruction is sent to each of the other processing units, and the competition participation flag is reset; otherwise, a low power consumption standby mode is entered.

[0107] In one of the embodiments, the lock state flag includes a plurality of lock state sub-flags, each lock state sub-flag corresponding to a different part of the processing unit;

[0108] The target processing unit among the multiple processing units is specifically used for:

[0109] Obtain the target lock resource, and update the occupancy status of the target lock resource through all lock status flags corresponding to the target processing unit;

[0110] The control processing unit is specifically used for:

[0111] After determining that each corresponding specific processing unit has obtained the target lock resource according to the target lock state sub-flag, a contention reset instruction is sent to each specific processing unit to enable each specific processing unit to restart the contention process for the target lock resource.

[0112] In one embodiment, the control processing unit is further used for:

[0113] Based on the preset test times and processing performance information of each processing unit, and the multiple lock resources to be tested, determine the multiple processing units participating in each round of testing of the target lock resource;

[0114] The control processing unit is specifically used for:

[0115] After determining that each of the processing units has obtained the target lock resource according to the lock status flag, a contention reset instruction is sent to each candidate processing unit participating in the next round of testing according to the number of test rounds, so that each candidate processing unit restarts the contention processing for the lock resource.

[0116] In one embodiment, a computer device is provided, whose internal structure diagram can be as follows: Figure 3 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The input / output interface of the computer device is used to exchange data between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a lock contention mechanism testing method in a high concurrency scenario is implemented.

[0117] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0118] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0119] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0120] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0121] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The processor involved in each embodiment provided in this application can be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, etc., but is not limited thereto.

[0122] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0123] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for testing lock contention mechanism in high concurrency scenarios, characterized in that: The method comprises: Multiple processing units perform competition processing for target lock resources based on a preset spin lock test function; The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag; After determining that each of the processing units has obtained the target lock resource according to the lock status flag, the control processing unit sends a contention reset instruction to each of the processing units, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds; After the number of test rounds reaches a preset number, the control processing unit controls to exit the competition test of the target lock resource.

2. The method according to claim 1, characterized in that The lock status flag is a competition completion flag; The method further comprises: The target processing unit releases the target lock resource, sets the target lock resource to a released state through the competition completion flag, and records in the competition completion flag that the target processing unit completes the competition.

3. The method according to claim 2, characterized in that After determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units comprises: The control processing unit determines the number of processing units that have completed competition according to the competition completion flag; If the number of the processing units that have completed the contention is equal to the total number of the plurality of processing units, the control processing unit sends a contention reset instruction to each of the other processing units and resets the contention completion flag.

4. The method according to claim 1, characterized in that: The lock status flag is a competition participation flag; The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag, including: The target processing unit obtains the target lock resource and records in the competition participation flag that the target processing unit has participated in the competition.

5. The method according to claim 4, characterized in that After determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units comprises: The target processing unit releases the target lock resource, and determines the number of processing units that have participated in the competition according to the competition participation flag; If the number of the processing units that have participated in the competition is equal to the total number of the multiple processing units, the target processing unit sends a competition reset instruction to each of the other processing units and resets the competition participation flag, otherwise it enters a low power standby mode.

6. The method according to claim 1, characterized in that The lock state flag includes a plurality of lock state sub-flags, each lock state sub-flag corresponding to a different part of the processing unit; The target processing unit obtains the target lock resource and updates the occupation status of the target lock resource through a lock status flag, including: The target processing unit obtains the target lock resource, and updates the occupation status of the target lock resource through all lock status flags corresponding to the target processing unit; After determining that each of the processing units has obtained the target lock resource according to the lock state flag, the control processing unit sends a contention reset instruction to each of the processing units, so that each processing unit restarts the contention processing of the target lock resource, including: After determining that each corresponding specific processing unit has obtained the target lock resource according to the target lock status sub-flag, the control processing unit sends a competition reset instruction to each specific processing unit so that each specific processing unit restarts the competition processing for the target lock resource.

7. The method according to claim 1, characterized in that The method further comprises: The control processing unit determines a plurality of processing units participating in each round of testing of the target lock resource based on the preset test times and processing performance information of each processing unit and the plurality of lock resources to be tested; After determining, according to the lock status flag, that each of the processing units has obtained the target lock resource, controlling the processing unit to send a contention reset instruction to each of the processing units, including: After determining that each of the processing units has obtained the target lock resource according to the lock status flag, the control processing unit sends a competition reset instruction to each candidate processing unit participating in the next round of testing according to the number of test rounds, so that each candidate processing unit restarts the competition processing for the lock resource.

8. A lock contention mechanism testing system in a high-concurrency scenario, characterized in that: The system comprises a plurality of processing units and a control processing unit, wherein: The multiple processing units are used to: Based on the preset spin lock test function, the target lock resource competition is processed; Obtain the target lock resource, and update the occupancy status of the target lock resource through a lock status flag; The control processing unit is used for: After determining that each of the processing units has obtained the target lock resource according to the lock state flag, sending a contention reset instruction to each of the processing units, so that each processing unit restarts the contention process for the target lock resource and updates the number of test rounds; After the number of test rounds reaches a preset number, the competition test of the target lock resource is exited.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the processing steps of the processing unit in any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Data processing method, parallel processor, electronic equipment and storage medium

    CN121301037A

  • Data processing method, parallel processor, electronic device, storage medium

    CN121301037B