Search

CN-116820696-B - Processing method and device for resource waiting queue and related equipment

CN116820696BCN 116820696 BCN116820696 BCN 116820696BCN-116820696-B

Abstract

The invention provides a processing method, a device and related equipment of a resource waiting queue, and relates to the technical field of operating systems, wherein the method comprises the steps of acquiring an atomic lock of a first resource waiting queue for the first time under the condition that a first resource of a task context or an interrupt context is released; writing a first set value into a first bit of the atomic lock when the atomic lock is acquired, waking up tasks of other resource waiting queues by using the first resource after the set value is written, writing a second set value into a second bit of the atomic lock when the atomic lock is not acquired, popping the task positioned at the head of the queue from the first resource waiting queue, acquiring the atomic lock of the first resource waiting queue for the second time, and popping the task positioned at the head of the queue from the first resource waiting queue based on the value of the first bit. The invention improves the resource utilization rate of the system by modifying the first bit after the atomic lock of the first resource waiting queue is acquired, without busy and the like.

Inventors

  • ZHANG HONGWEI

Assignees

  • 中移物联网有限公司
  • 中国移动通信集团有限公司

Dates

Publication Date
20260512
Application Date
20220321

Claims (19)

  1. 1. A method for processing a resource wait queue, the method comprising: Under the condition that a first resource of a task context or an interrupt context is released, acquiring an atomic lock of a first resource waiting queue for the first time, wherein the first resource corresponds to the first resource waiting queue; writing a first set value into a first bit of the atomic lock under the condition that the atomic lock is acquired by a second resource, wherein the value of the first bit is used for indicating that a task to be executed by the first resource needs to be executed by the second resource, and the second resource is one resource other than the first resource; After the set value is written, the first resource is utilized to wake up tasks of other resource waiting queues, and the other resource waiting queues are one resource waiting queue outside the first resource waiting queue; Writing a second set value into a second bit of the atomic lock under the condition that the atomic lock is not acquired by a second resource, wherein the second bit is used for indicating that the atomic lock is acquired by the first resource; ejecting a task positioned at the head of a queue from the first resource waiting queue and executing the task; acquiring the atomic lock of the first resource waiting queue for the second time; ejecting a task at the head of a queue from the first resource waiting queue based on the value of the first bit, and executing the task; Releasing the atomic lock of the first resource wait queue.
  2. 2. The method of claim 1, wherein popping the first-located task from the first resource wait queue based on the value of the first bit comprises: recording the first bit of the atomic lock acquired for the first time as a first variable; Recording the first bit of the atomic lock acquired for the second time as a second variable; And popping the task at the head of the queue from the first resource waiting queue, wherein the popping times are the ratio of the difference value of the second variable and the first variable to the first set value.
  3. 3. The method of claim 2, wherein in the event of a failure of the releasing the atomic lock of the first resource wait queue, the method comprises: under the condition that the first resource waiting queue has tasks, acquiring the atomic lock for the third time; Recording the first bit of the atomic lock acquired for the third time as a third variable; Ejecting tasks at the head of the queue from the first resource waiting queue, wherein the ejecting times are the ratio of the difference value of the third variable and the second variable to the first set value; releasing the atomic lock of the first resource wait queue; And forcibly releasing the atomic lock of the first resource waiting queue under the condition that the task does not exist in the resource waiting queue.
  4. 4. The method of claim 1, wherein prior to the first acquisition of the atomic lock of the first resource wait queue, the method further comprises: Closing a plurality of interrupt tasks under the condition that the processor corresponding to the first resource is multi-core; closing a timing interrupt task when the processor corresponding to the first resource is a single core, wherein the timing interrupt task is one of the interrupt tasks; after said releasing said atomic lock of said first resource wait queue, said method further comprises: And opening the interrupt tasks.
  5. 5. The method according to claim 1, wherein the method further comprises: Repeatedly acquiring an atomic lock of a first resource waiting queue under the condition that a task context cannot acquire a first resource until the atomic lock is acquired; inserting the task into the first resource waiting queue according to the priority of the task; Releasing the atomic lock of the first resource wait queue.
  6. 6. The method of claim 5, wherein prior to the repeatedly acquiring the atomic lock of the first resource wait queue until the atomic lock is acquired, the method further comprises: Closing a plurality of interrupt tasks under the condition that the processor corresponding to the first resource is multi-core; closing a timing interrupt task when the processor corresponding to the first resource is a single core, wherein the timing interrupt task is one of the interrupt tasks; after said releasing said atomic lock of said first resource wait queue, said method further comprises: And opening the interrupt tasks.
  7. 7. The method according to claim 1, wherein the method further comprises: Repeatedly acquiring an atomic lock of the first resource waiting queue under the condition that a task in the timing interrupt context has a timeout task of the first resource queue until the atomic lock is acquired; removing the overtime task from the first resource waiting queue; Releasing the atomic lock of the first resource wait queue.
  8. 8. The method of claim 7, wherein prior to the repeatedly acquiring the atomic lock of the first resource wait queue until the atomic lock is acquired, the method further comprises: Closing a plurality of interrupt tasks under the condition that the processor corresponding to the first resource queue is multi-core; if the processor corresponding to the first resource queue is a single core, the interrupt task is not closed; after said releasing said atomic lock of said first resource wait queue, said method further comprises: And opening the interrupt tasks.
  9. 9. A processing apparatus for a resource wait queue, comprising: The first acquisition module is used for acquiring the atomic lock of the first resource waiting queue for the first time under the condition that the first resource of the task context or the interrupt context is released, wherein the first resource corresponds to the first resource waiting queue; The first processing module is used for writing a first set value into a first bit of the atomic lock under the condition that the atomic lock is acquired by a second resource, wherein the value of the first bit is used for indicating that the second resource needs to execute a task to be executed by the first resource, and the second resource is one resource other than the first resource; The second processing module is used for waking up tasks of other resource waiting queues by using the first resource after the set value is written, wherein the other resource waiting queues are one resource waiting queue outside the first resource waiting queue; The third processing module is used for writing a second set value into a second bit of the atomic lock when the atomic lock is not acquired by a second resource, wherein the second bit is the second set value and is used for indicating that the atomic lock is acquired by the first resource; The fourth processing module is used for popping up the task positioned at the head of the queue from the first resource waiting queue and executing the task; a second obtaining module, configured to obtain the atomic lock of the first resource waiting queue for a second time; A fifth processing module, configured to pop up a task located at the head of a queue from the first resource waiting queue based on the value of the first bit, and execute the task; And the first releasing module is used for releasing the atomic lock of the first resource waiting queue.
  10. 10. The apparatus of claim 9, wherein the fifth processing module comprises: the first recording unit is used for recording the first bit of the atomic lock acquired for the first time as a first variable; the second recording unit is used for recording the first bit of the atomic lock acquired for the second time as a second variable; and the first processing unit is used for popping the task positioned at the head of the queue from the first resource waiting queue, and the popping frequency is the ratio of the difference value of the second variable and the first variable to the first set value.
  11. 11. The apparatus of claim 10, wherein in the event of a failure of the first release module to execute, the apparatus comprises: a third obtaining module, configured to obtain, when a task exists in the first resource waiting queue, the atomic lock for the third time; The first recording module is used for recording that the first bit of the atomic lock acquired for the third time is a third variable; The sixth processing module is used for popping up the task at the head of the queue from the first resource waiting queue, wherein the popping-up times are the ratio of the difference value of the third variable and the second variable to the first set value; A second releasing module, configured to release the atomic lock of the first resource waiting queue; and the third releasing module is used for forcedly releasing the atomic lock of the first resource waiting queue under the condition that the task does not exist in the resource waiting queue.
  12. 12. The apparatus of claim 9, wherein prior to the first acquisition module, the apparatus further comprises: the first closing module is used for closing a plurality of interrupt tasks under the condition that the processor corresponding to the first resource is multi-core; The second closing module is used for closing a timing interrupt task when the processor corresponding to the first resource is a single core, wherein the timing interrupt task is one of the interrupt tasks; After the first release module, the device further comprises: and the first opening module is used for opening the interrupt tasks.
  13. 13. The apparatus of claim 9, wherein the apparatus further comprises: a fourth obtaining module, configured to repeatedly obtain an atomic lock of the first resource waiting queue until the atomic lock is obtained, where the task context cannot obtain the first resource; a seventh processing module, configured to insert a task into the first resource waiting queue according to a priority of the task; And a fourth releasing module, configured to release the atomic lock of the first resource waiting queue.
  14. 14. The apparatus of claim 13, wherein prior to the fourth acquisition module, the apparatus further comprises: the third closing module is used for closing a plurality of interrupt tasks under the condition that the processor corresponding to the first resource is multi-core; a fourth closing module, configured to close a timer interrupt task when the processor corresponding to the first resource is a single core, where the timer interrupt task is one of the multiple interrupt tasks; After the fourth release module, the device further comprises: And the second opening module is used for opening the interrupt tasks.
  15. 15. The apparatus of claim 9, wherein the apparatus further comprises: a fifth obtaining module, configured to repeatedly obtain an atomic lock of the first resource waiting queue until the atomic lock is obtained, where the task in the timer interrupt context has a timeout task of the first resource queue; An eighth processing module, configured to shift out the timeout task from the first resource waiting queue; And a fifth releasing module, configured to release the atomic lock of the first resource waiting queue.
  16. 16. The apparatus of claim 15, wherein prior to the fifth acquisition module, the apparatus further comprises: a fifth closing module, configured to close a plurality of interrupt tasks when the processor corresponding to the first resource queue is multi-core; A sixth closing module, configured to, in case that the processor corresponding to the first resource queue is a single core, not close an interrupt task; After the fifth release module, the apparatus further comprises: and the third opening module is used for opening the interrupt tasks.
  17. 17. A processing device of resource waiting queue is characterized by comprising a transceiver and a processor, The processor is configured to obtain, for the first time, an atomic lock of a first resource waiting queue in a case where a first resource of a task context or an interrupt context is released, where the first resource corresponds to the first resource waiting queue; The processor is further configured to, when the atomic lock is acquired by a second resource, write a first set value into a first bit of the atomic lock, where a value of the first bit is used to indicate that the second resource needs to execute a task to be executed by the first resource, and the second resource is a resource other than the first resource; The processor is further configured to wake up, after the writing of the set value, a task of another resource waiting queue with the first resource, where the other resource waiting queue is a resource waiting queue other than the first resource waiting queue; the processor is further configured to write a second set value to a second bit of the atomic lock, where the second bit is the second set value and is used to indicate that the atomic lock is acquired by the first resource, where the atomic lock is not acquired by the second resource; The processor is further used for popping up a task positioned at the head of the queue from the first resource waiting queue and executing the task; The processor is further configured to acquire the atomic lock of the first resource waiting queue for a second time; The processor is further configured to pop up a task located at the head of a queue from the first resource waiting queue based on the value of the first bit, and execute the task; The processor is further configured to release the atomic lock of the first resource wait queue.
  18. 18. A communication device comprising a transceiver, a memory, a processor and a program stored on the memory and executable on the processor, characterized in that the processor is arranged to read the program in the memory to implement the steps of the method for processing a resource wait queue according to any one of claims 1 to 8.
  19. 19. A readable storage medium storing a program, wherein the program, when executed by a processor, implements the steps in the method of processing a resource wait queue as claimed in any one of claims 1 to 8.

Description

Processing method and device for resource waiting queue and related equipment Technical Field The present invention relates to the technical field of operating systems, and in particular, to a method and an apparatus for processing a resource waiting queue, and a related device. Background In an operating system, there are cases where multiple tasks or multiple interrupts need to access a resource wait queue at the same time, and lock the resource wait queue is needed, so that the resource wait queue is prevented from being accessed by multiple tasks or multiple interrupts in parallel. However, in the related art, after the resource waiting queue is locked, the resource that does not access the resource waiting queue needs to wait for the lock to be released, and the resource is busy waiting at this time, so that the resource utilization rate of the system is low. It can be seen that the prior art has the problem of low resource utilization rate of the system. Disclosure of Invention The embodiment of the invention provides a method, a device and related equipment for processing a resource waiting queue, which are used for solving the problem of low resource utilization rate of a system in the prior art. To solve the above problems, the present invention is achieved as follows: in a first aspect, an embodiment of the present invention provides a method for processing a resource waiting queue, where the method includes: Under the condition that a first resource of a task context or an interrupt context is released, acquiring an atomic lock of a first resource waiting queue for the first time, wherein the first resource corresponds to the first resource waiting queue; writing a first set value into a first bit of the atomic lock under the condition that the atomic lock is acquired by a second resource, wherein the value of the first bit is used for indicating that a task to be executed by the first resource needs to be executed by the second resource, and the second resource is one resource other than the first resource; After the set value is written, the first resource is utilized to wake up tasks of other resource waiting queues, and the other resource waiting queues are one resource waiting queue outside the first resource waiting queue; Writing a second set value into a second bit of the atomic lock under the condition that the atomic lock is not acquired by a second resource, wherein the second bit is used for indicating that the atomic lock is acquired by the first resource; ejecting a task positioned at the head of a queue from the first resource waiting queue and executing the task; acquiring the atomic lock of the first resource waiting queue for the second time; ejecting a task at the head of a queue from the first resource waiting queue based on the value of the first bit, and executing the task; Releasing the atomic lock of the first resource wait queue. In a second aspect, an embodiment of the present invention further provides a processing apparatus for a resource waiting queue, including: The first acquisition module is used for acquiring the atomic lock of the first resource waiting queue for the first time under the condition that the first resource of the task context or the interrupt context is released, wherein the first resource corresponds to the first resource waiting queue; The first processing module is used for writing a first set value into a first bit of the atomic lock under the condition that the atomic lock is acquired by a second resource, wherein the value of the first bit is used for indicating that the second resource needs to execute a task to be executed by the first resource, and the second resource is one resource other than the first resource; The second processing module is used for waking up tasks of other resource waiting queues by using the first resource after the set value is written, wherein the other resource waiting queues are one resource waiting queue outside the first resource waiting queue; The third processing module is used for writing a second set value into a second bit of the atomic lock when the atomic lock is not acquired by a second resource, wherein the second bit is the second set value and is used for indicating that the atomic lock is acquired by the first resource; The fourth processing module is used for popping up the task positioned at the head of the queue from the first resource waiting queue and executing the task; a second obtaining module, configured to obtain the atomic lock of the first resource waiting queue for a second time; A fifth processing module, configured to pop up a task located at the head of a queue from the first resource waiting queue based on the value of the first bit, and execute the task; And the first releasing module is used for releasing the atomic lock of the first resource waiting queue. In a third aspect, an embodiment of the present invention further provides a processing apparatus for a resource wait queue,