A thread processing method and related apparatus

CN123011480APending Publication Date: 2026-10-30HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510572915.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

然而,在一些场景下,计算机中仍然可能出现一直运行较低优先级的线程,而较高优先级的线程则一直无法运行的现象,导致重要程度较高的任务无法及时响应

Benefits of technology

[0045]上述第二方面至第七方面的有益效果可以参考上述第一方面的介绍,在此不再赘述。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011480A_ABST
    Figure CN123011480A_ABST
Patent Text Reader

Abstract

A thread processing method is applied to implement the scheduling of threads. In the thread processing method, when a first thread is blocked, information is acquired that the first thread is woken up by other threads at a historical time, and then a second thread that can cause the first thread to be blocked is predicted. In this way, by adjusting the priority of the second thread with low priority to be consistent with the priority of the first thread, the second thread on which the first thread depends can be executed preferentially, the first thread is prevented from being affected by the second thread with low priority and being unable to execute for a long time, the problem of priority inversion is effectively solved, and high-priority threads can be executed as soon as possible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a thread processing method and related apparatus. Background Technology

[0002] In a computer, the scheduling system within the operating system is the core module for managing the allocation of computing resources. It is primarily responsible for coordinating the competition among processes, threads, and other tasks for resources such as processors and memory. Taking thread scheduling as an example, because processor resources in a computer are limited, while there may be many threads that need to execute simultaneously, the scheduling system needs to determine which thread will gain the right to use the processor through thread scheduling.

[0003] Generally, in computers, different threads often correspond to different priorities, with threads of higher importance typically having higher priorities. Therefore, during thread scheduling, a higher-priority thread can preempt a lower-priority thread, thereby forcibly interrupting a lower-priority thread currently running on the processor, ensuring that the higher-priority thread executes as early as possible.

[0004] Thread scheduling is based on thread priority, and in most cases, the scheduling system can prioritize the execution of high-priority threads. However, in some scenarios, a computer may still experience a situation where lower-priority threads run indefinitely, while higher-priority threads remain inactive, causing critical tasks to fail to respond promptly. Summary of the Invention

[0005] This application provides a thread processing method that can improve the execution efficiency of high-priority threads.

[0006] Firstly, a thread processing method is provided, applied to an execution device running multiple threads. This thread processing method includes: when a first thread becomes blocked, the execution device acquires first wake-up information, which indicates that the first thread was woken up by other threads in a historical time period. The first wake-up information is obtained by the execution device by recording events in a historical time period where the first thread was woken up by other threads.

[0007] Then, based on the first wake-up information, the execution device determines the second thread, which is the thread that caused the first thread to be blocked, as predicted by the first wake-up information. That is, the execution device predicts the thread that might cause the first thread to be blocked based on the first wake-up information, and then predicts the second thread.

[0008] Finally, the execution device adjusts the execution priority of the second thread to the target priority, which is the execution priority of the first thread, and the original execution priority of the second thread is lower than the target priority. In other words, the execution device effectively increases the execution priority of the second thread, thereby allowing the second thread, which originally had a lower execution priority, to be scheduled for execution first.

[0009] In this solution, when the first thread becomes blocked, information about when the first thread was awakened by other threads in the past is retrieved, thus predicting the second thread that might cause the first thread to become blocked. In this way, by adjusting the priority of the low-priority second thread to match the priority of the first thread, the second thread that the first thread depends on can be executed first, preventing the first thread from being delayed due to the influence of the low-priority second thread. This effectively solves the priority inversion problem and ensures that high-priority threads can execute as quickly as possible.

[0010] In one possible implementation, the first wake-up information is used to indicate the number of times the first thread has been woken up by other M threads in the historical time, where M is greater than or equal to 1.

[0011] The execution device can determine the wake-up probability of each of the M threads based on the first wake-up information. This wake-up probability indicates the probability that a thread can wake up the first thread. Then, based on the wake-up probabilities of the M threads, the execution device determines the second thread from among the M threads. The second thread includes the N threads with the highest wake-up probabilities among the M threads, where N is greater than or equal to 1. In other words, the more times a thread has historically woken up the first thread, the greater the probability that the execution device can currently consider that thread to be able to wake up the first thread.

[0012] In this scheme, by recording the number of times the first thread is awakened by other threads, and determining the awakening probability of each thread based on the number of times the first thread is awakened, the thread with the highest awakening probability is determined as the thread that needs to be given higher execution priority. This can effectively identify the thread that the first thread actually depends on, thereby ensuring that the first thread can be executed in a timely manner.

[0013] In one possible implementation, after adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset interval, the execution device obtains the second wake-up information, which is used to indicate that the second thread was woken up by other threads in the past.

[0014] Furthermore, based on the second wake-up information, the execution device determines the third thread and adjusts its execution priority to the target priority. The third thread is the one predicted by the second wake-up information to cause the second thread to block.

[0015] In other words, after adjusting the execution priority of the second thread, which the first thread depends on, if the scheduling system finds that the first thread is still blocked, it can assume that the second thread may also be blocked, thus preventing the first thread from executing. Therefore, the scheduling system continues to backtrack to the thread that the second thread depends on (i.e., the third thread mentioned above) and increases the execution priority of the thread that the second thread depends on to ensure that the thread that the second thread depends on can be executed as soon as possible, thereby accelerating the execution of the second thread and the first thread.

[0016] In this solution, by adjusting the execution priority of the threads that the first thread directly depends on and finding that the first thread still has not executed in time, we continue to backtrack on the dependency chain and adjust the execution priority of the upper-level threads. This can effectively solve the priority inversion problem caused by multi-level blocking, thereby ensuring that the first thread can execute smoothly.

[0017] In one possible implementation, after determining the second thread, the execution device continues to acquire second wake-up information, which indicates that the second thread was woken up by other threads in a historical timeframe. Furthermore, based on the second wake-up information, the execution device determines a third thread and adjusts its execution priority to the target priority. The third thread is the thread predicted by the second wake-up information that caused the second thread to block.

[0018] In this solution, when the first thread is found to be blocked, the execution priority of the multi-level threads before the first thread is directly backtracked on the dependency chain and adjusted. This can effectively solve the priority inversion problem caused by multi-level blocking, thereby ensuring that the first thread can execute smoothly.

[0019] In one possible implementation, the first wake-up information is based on relationship identifiers assigned to the first thread and other threads to record information about how the first thread was woken up by other threads in a historical time. The data size of the relationship identifiers is smaller than that of the thread identifiers. That is, when recording the first wake-up information, instead of using the thread identifiers of the first thread and other threads themselves to represent them, relationship identifiers specifically assigned to these threads are used.

[0020] In this scheme, by using an additional relation identifier to represent the thread that needs to record wake-up information, it is possible to replace the thread identifier with a larger amount of data with a relation identifier with a smaller amount of data, thereby realizing the recording of wake-up information and effectively reducing the amount of data of the recorded wake-up information, which is beneficial to realize the recording of wake-up information using limited storage resources.

[0021] In one possible implementation, the first thread is a predefined key thread, and the relation identifiers corresponding to the first thread and other threads are allocated from a relation set. The relation identifiers in the relation set are only used to allocate to key threads and threads that wake up key threads.

[0022] In other words, the wake-up information of a critical thread only needs to be recorded when the critical thread is awakened, and the relation identifiers in the relation set are also assigned to the critical thread and the thread that awakened the critical thread. In this way, the execution device can pre-define a relation set, which includes relation identifiers with a small amount of data. These relation identifiers can be used to replace thread identifiers to record wake-up information, thereby reducing the storage overhead of wake-up information.

[0023] In one possible implementation, after the first thread finishes execution, the execution device restores the execution priority of the second thread to its original execution priority, thus avoiding the impact on the normal execution of other threads caused by adjusting the execution priority of the second thread for an extended period of time.

[0024] In one possible implementation, after the first thread is awakened, the execution device updates the first wake-up information based on the information of the thread that woke up the first thread.

[0025] In this scheme, after the first thread is awakened, the wake-up information related to the first thread is updated in a timely manner. This ensures the real-time and comprehensiveness of the wake-up information, which is beneficial for subsequent more accurate prediction of the thread that can wake up the first thread based on the wake-up information, thus ensuring the subsequent execution efficiency of the first thread.

[0026] In one possible implementation, the first wake-up information is obtained from a directed graph. This directed graph records information about critical threads being woken up by other threads in a historical timeframe, and the first thread is considered a critical thread. The directed graph includes nodes and directed edges between them. Nodes represent threads, directed edges represent the direction of thread wake-up, and the properties of the directed edges indicate the number of times each node is woken up.

[0027] In this scheme, a directed graph is used to record information about critical threads being awakened by other threads, which makes the awakening paths between threads clearer, more intuitive and comprehensive, and helps to backtrack the threads in the dependency chain of the thread.

[0028] In one possible implementation, the first wake-up information is obtained after the first thread belonging to the critical thread has been blocked for a period of time exceeding a preset duration.

[0029] In this solution, by setting the execution thread processing method to be triggered only for critical threads that have been blocked for more than a preset time, the execution efficiency of the critical thread can be improved. This ensures that the execution device only focuses on high-priority threads running in the operating system that have encountered blocking exceptions, reducing the consumption of processing resources and thus solving the priority inversion problem with limited processing resources.

[0030] In a second aspect, a thread processing apparatus is provided, comprising: an acquisition module, configured to acquire first wake-up information when a first thread is blocked, the first wake-up information indicating that the first thread was woken up by another thread in a historical time; a processing module, configured to determine a second thread based on the first wake-up information, the second thread being the thread that caused the first thread to be blocked based on the prediction of the first wake-up information; and the processing module further configured to adjust the execution priority of the second thread to a target priority, the target priority being the execution priority of the first thread, and the original execution priority of the second thread being lower than the target priority.

[0031] In one possible implementation, the first wake-up information is used to indicate the number of times the first thread has been woken up by other M threads in a historical time period, where M is greater than or equal to 1; the processing module is specifically used to: determine the wake-up probability of the threads among the M threads based on the first wake-up information, where the wake-up probability is used to indicate the probability that a thread wakes up the first thread; and determine the second thread among the M threads based on the wake-up probability, where the second thread includes the N threads with the highest wake-up probability among the M threads, where N is greater than or equal to 1.

[0032] In one possible implementation, the processing module is further configured to: after adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset interval, obtain second wake-up information, the second wake-up information being used to indicate that the second thread was woken up by other threads in a historical time; based on the second wake-up information, determine the third thread, the third thread being the thread that caused the second thread to be blocked based on the prediction of the second wake-up information; and adjust the execution priority of the third thread to the target priority.

[0033] In one possible implementation, the processing module is further configured to: after determining the second thread, obtain second wake-up information, the second wake-up information being used to indicate that the second thread was woken up by other threads in a historical time; based on the second wake-up information, determine the third thread, the third thread being the thread that caused the second thread to be blocked based on the prediction of the second wake-up information; and adjust the execution priority of the third thread to the target priority.

[0034] In one possible implementation, the first wake-up information is based on the relationship identifiers assigned to the first thread and other threads to record information about when the first thread was woken up by other threads in a historical time. The amount of data in the relationship identifiers is less than the amount of data in the thread identifiers.

[0035] In one possible implementation, the first thread is a predefined key thread, and the relation identifiers corresponding to the first thread and other threads are allocated from a relation set. The relation identifiers in the relation set are only used to allocate to key threads and threads that wake up key threads.

[0036] In one possible implementation, the processing module is further configured to: restore the execution priority of the second thread to its original execution priority after the first thread has finished executing.

[0037] In one possible implementation, the processing module is further configured to: after the first thread is awakened, update the first wake-up information based on the information of the thread that awakened the first thread.

[0038] In one possible implementation, the first wake-up information is obtained from a directed graph. The directed graph is used to record information about critical threads being woken up by other threads in a historical time. The first thread belongs to the critical threads. The directed graph includes nodes and directed edges between nodes. Nodes are used to represent threads, directed edges are used to represent the direction of thread wake-up, and the attributes of the directed edges are used to indicate the number of times the nodes are woken up.

[0039] In one possible implementation, the first wake-up information is obtained after the first thread belonging to the critical thread has been blocked for a period of time exceeding a preset duration.

[0040] A third aspect of this application provides a thread processing apparatus, which may include a processor and a memory coupled together. The memory stores program instructions, and when the program instructions stored in the memory are executed by the processor, the method described in the first aspect or any implementation thereof is implemented. For details regarding the steps of the various possible implementations of the first aspect executed by the processor, please refer to the first aspect; further details will not be repeated here.

[0041] The fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the method of any implementation of the first aspect described above.

[0042] The fifth aspect of this application provides a circuit system including a processing circuit configured to perform the method of any implementation of the first aspect described above.

[0043] The sixth aspect of this application provides a computer program product that, when run on a computer, causes the computer to perform any implementation of the first aspect described above.

[0044] A seventh aspect of this application provides a chip system including a processor for implementing the functions involved in any implementation of the first aspect, such as processing data and / or information involved in the methods described above. In one possible design, the chip system further includes a memory for storing necessary program instructions and data. This chip system may be composed of chips or may include chips and other discrete devices.

[0045] The beneficial effects of the second to seventh aspects mentioned above can be referred to the introduction of the first aspect above, and will not be repeated here. Attached Figure Description

[0046] Figure 1 A schematic diagram illustrating a priority reversal provided in this application;

[0047] Figure 2 A schematic diagram of a system architecture provided for this application;

[0048] Figure 3 A flowchart illustrating a thread processing method provided in this application;

[0049] Figure 4 This application provides a schematic diagram of a system architecture in a practical application.

[0050] Figure 5 This application provides a schematic diagram of a thread processing implementation in a practical application;

[0051] Figure 6 A schematic diagram of a directed graph provided in this application;

[0052] Figure 7 A schematic diagram illustrating how to obtain a probability transition matrix based on a directed graph, as provided in this application;

[0053] Figure 8 This application provides a schematic diagram of performing backpropagation in a directed graph to achieve dependency chain backtracking;

[0054] Figure 9 A schematic diagram of the structure of a thread processing device provided in this application;

[0055] Figure 10 A schematic diagram of the structure of an execution device provided in this application;

[0056] Figure 11 This is a schematic diagram of the structure of a computer-readable storage medium provided in this application. Detailed Implementation

[0057] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0058] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein.

[0059] Furthermore, the terms “comprising” and “having”, and any variations thereof, are intended to cover non-exclusive inclusion, such that a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such process, method, product, or apparatus.

[0060] For ease of understanding, some technical terms involved in the embodiments of this application will be introduced below.

[0061] (1) Process

[0062] A process is a single execution of a program on a specific set of data in a computer. It is the basic unit for resource allocation in a system and the foundation of the operating system architecture. In early process-oriented computer architectures, a process was the fundamental execution entity of a program; in contemporary thread-oriented computer architectures, a process is a container for threads. An application program is a description of instructions, data, and their organization; a process is a single execution of an application program.

[0063] (2) Thread

[0064] A thread is the smallest unit of computation that an operating system can schedule. Threads are contained within processes and are the actual units of operation within a process. A thread refers to a single, sequential flow of control within a process; multiple threads can run concurrently within a process, each executing different tasks in parallel.

[0065] (3) Thread blocking

[0066] Thread blocking refers to a situation in a multithreaded environment where a thread is temporarily unable to continue execution for some reason, thus relinquishing processor resources and waiting for a certain condition to be met before resuming execution. For example, when a thread is waiting for resources such as locks, semaphores, or condition variables, the thread will enter the kernel to trigger thread blocking.

[0067] (4) Thread wake-up

[0068] Thread wake-up refers to resuming execution of a thread that is in a blocked state.

[0069] (5) Lock

[0070] A lock is an abstract control structure used to restrict access to shared resources in a concurrent environment. When a thread or process acquires a lock, other threads / processes must wait for the lock to be released before accessing the resource, thus avoiding data inconsistency issues. Common locks generally include mutex locks and read-write locks.

[0071] (6) Semaphore

[0072] A semaphore, also known as a leading indicator, is a facility used in a multithreaded environment to prevent two or more critical code sections from being called concurrently. Before entering a critical code section, a thread must acquire a semaphore; once the critical code section is complete, the thread must release the semaphore. Other threads wanting to enter the critical code section must wait until the first thread releases the semaphore.

[0073] Currently, in computers, thread scheduling is based on thread priority, and the scheduling system can usually prioritize the execution of higher-priority threads. However, in some scenarios, a lower-priority thread may continue to run while higher-priority threads remain inactive, causing critical tasks to fail to respond promptly.

[0074] The applicant's research revealed that the phenomenon in computers where lower-priority threads consistently run while higher-priority threads are unable to execute is essentially a priority inversion phenomenon. Priority inversion refers to the situation where a high-priority thread is blocked while waiting for shared resources held by a lower-priority thread. This phenomenon prevents high-priority threads from executing promptly and may even lead to them being preempted by lower or medium-priority threads, thus disrupting the determinism of real-time systems. For example, if the blocked high-priority task is a rendering thread or a voice thread, priority inversion can cause dropped frames or popping sounds on the terminal device, directly impacting the user experience.

[0075] For example, please refer to Figure 1 , Figure 1 This is a schematic diagram illustrating a priority inversion provided in this application. For example... Figure 1As shown, suppose there are three threads with a priority order of thread A > thread B > thread C. First, thread C (low priority) is executing and holding a shared resource (such as a lock or semaphore). Then, thread A (high priority) is scheduled to execute and preempts thread C. During thread A's execution, thread A attempts to acquire the shared resource but is blocked because the resource is held by thread C. After thread A is blocked, the operating system's waiting threads include thread B and thread C. Because thread B has a higher priority than thread C, thread B is scheduled to execute, thus preempting processor resources and causing thread A to wait for a long time. Only after thread B finishes executing can thread C continue to execute and release the shared resource. Therefore, thread A can only continue execution after thread C releases the shared resource. Clearly, in the entire scheduling process, the high-priority thread A is indirectly blocked by the low-priority thread C, while the medium-priority thread B executes first, resulting in priority inversion.

[0076] In view of this, this application provides a thread processing method that, when a first thread becomes blocked, triggers the acquisition of information about when the first thread was awakened by other threads in a historical time period, thereby predicting a second thread that may cause the first thread to become blocked. In this way, by adjusting the priority of the low-priority second thread to be consistent with the priority of the first thread, the second thread on which the first thread depends can be executed first, avoiding the first thread being delayed due to the influence of the low-priority second thread. This effectively solves the priority inversion problem and ensures that high-priority threads can execute as quickly as possible.

[0077] Please see Figure 2 , Figure 2 This is a schematic diagram of a system architecture provided for this application. (For example...) Figure 2 As shown, in the system architecture, the execution device 101 can be a terminal device such as a physical server, personal computer, laptop, smartphone, or tablet computer. The execution device 101 includes multiple threads to be executed and a scheduling system. The scheduling system in the execution device adjusts the thread priorities to complete the thread processing method provided in this application.

[0078] Furthermore, the execution device 101 is communicatively connected to the data storage system 102 to obtain the program code stored in the data storage system 102, thereby implementing the thread processing method provided in this application. The data storage system 102 can be implemented as a storage device deployed on the execution device 101, for example, the execution device 101 is a physical server, and the data storage system 102 is a hard disk deployed on the physical server. Alternatively, the data storage system 102 can be implemented as a storage device independent of the execution device, for example, the execution device 101 is a computing server, and the data storage system 102 is a dedicated data server for storing program code.

[0079] During operation, the execution device 101 can obtain program code and relevant data (such as thread wake-up information) required for executing thread processing methods from the data storage system 102, and implement thread scheduling processing on the execution device 101 based on the thread processing method provided in this application.

[0080] Please see Figure 3 , Figure 3 This is a flowchart illustrating a thread processing method provided in this application. Figure 3 As shown, the execution process of the thread processing method includes the following steps 301-303.

[0081] Step 301: When the first thread is blocked, obtain the first wake-up information. The first wake-up information is used to indicate that the first thread was woken up by other threads in the past.

[0082] In this application, the thread processing method can be specifically executed by the scheduling system in the operating system of the execution device. The scheduling system adjusts the thread priority by executing the thread processing method, thereby resolving the priority inversion problem.

[0083] The first thread can be a high-priority thread in the execution device (such as a critical thread predefined by the user or operating system), and therefore, the first thread is often executed first in the execution device. A critical thread refers to a thread that is of high importance or affects the user experience. If the scheduling system detects that the first thread is blocked, the scheduling system can trigger the acquisition of the first wake-up information to execute the thread processing method provided in this application.

[0084] The first wake-up information is obtained by the execution device through recording events in historical time where the first thread is woken up by other threads. That is, before step 301, as long as the first thread has been woken up by other threads, the execution device will record the event of the first thread being woken up by other threads, so that the execution device can obtain the aforementioned first wake-up information when the first thread is blocked.

[0085] Furthermore, in a historical timeframe, the first thread may have been awakened by one or more threads. The execution device can record the number of times each thread awakened the first thread to predict which thread is more likely to awaken the first thread currently. For example, the first wake-up information could specifically indicate the number of times the first thread was awakened by each of the other M threads in a historical timeframe, where M is an integer greater than or equal to 1. For instance, assuming the first thread was awakened by three threads in a historical timeframe, the first wake-up information could indicate the number of times the first thread was awakened by each of those three threads.

[0086] Optionally, in some examples, to conserve processing resources, the scheduling system may acquire the first wake-up information after recognizing that the first thread belonging to the critical thread has been blocked for a duration exceeding a preset time. That is, the scheduling system will only execute the thread processing method provided in this application for the critical thread when the critical thread is blocked for a duration exceeding the preset time, thereby ensuring that the critical thread can be executed as quickly as possible. The preset time can be a duration pre-set according to the actual application scenario, such as 10 milliseconds (ms), 50ms, or 100ms, etc., and this application does not specifically limit it. Of course, if the duration of the critical thread being blocked does not exceed the preset time, then the scheduling system can consider the duration of the critical thread being blocked to be within the normal time range, and it is not necessary to perform corresponding processing for the critical thread at this time.

[0087] For some non-critical threads, the scheduling system does not care about the blocking status of these non-critical threads. That is, even if the blocking time of a non-critical thread exceeds the preset time, the scheduling system will not execute the thread processing method provided in this application for the non-critical thread.

[0088] In this way, by setting the execution of the thread processing method to be triggered only for critical threads that have been blocked for more than a preset time, the execution efficiency of the critical thread can be improved. This ensures that the scheduling system only focuses on high-priority threads running in the operating system that have encountered blocking exceptions, reducing the consumption of processing resources and thus solving the priority inversion problem with limited processing resources.

[0089] Optionally, to reduce the amount of data in the wake-up information, the first wake-up information can specifically record the information about how the first thread was woken up by other threads in a historical time period, based on the relationship identifiers assigned to the first thread and the other threads that woke up the first thread. The amount of data in the relationship identifiers assigned to the first thread and the other threads that woke up the first thread is less than the amount of data in the thread identifiers. That is, when recording the first wake-up information, instead of using the thread identifiers of the first thread and other threads themselves to represent the first thread and other threads, a relationship identifier specifically assigned to these threads is used.

[0090] Specifically, since execution devices typically contain a large number of threads, thread identifiers often require a large amount of data to represent them; for example, a single thread identifier typically takes up to 2 bytes (i.e., the maximum value of a thread identifier can be 65536). However, in practical applications, threads experiencing priority inversion are relatively few, and not all threads need to resolve priority inversion issues. That is, only threads with higher importance typically need priority inversion resolution, thus the number of threads requiring wake-up information recording is usually small. For instance, in some examples, the maximum value of the relation identifier allocated to a thread can be 1024, meaning the relation identifier often takes up less than 1 byte. Therefore, by using an additional relation identifier to represent the thread requiring wake-up information recording, it is possible to replace the larger thread identifier with a smaller relation identifier, thereby achieving wake-up information recording and effectively reducing the amount of recorded wake-up information. This is beneficial for utilizing limited storage resources to record wake-up information.

[0091] For example, the first thread is a predefined key thread, and the relationship identifiers corresponding to the first thread and other threads are allocated from a relationship set. The relationship identifiers in the relationship set are only used to assign to the key thread and the thread that wakes it up. That is, the wake-up information of the key thread only needs to be recorded when it is woken up, and the relationship identifiers in the relationship set are also assigned to the key thread and the thread that woke it up. In this way, the scheduling system can pre-define a relationship set, which includes a small number of relationship identifiers. These relationship identifiers can be used to replace thread identifiers to record wake-up information, thereby reducing the storage overhead of wake-up information.

[0092] Optionally, the aforementioned first wake-up information can be obtained from a directed graph. The directed graph records information about critical threads being woken up by other threads in a historical timeframe, with the first thread being a critical thread. The directed graph includes multiple nodes and directed edges between them. In the directed graph, nodes represent threads, and directed edges represent the direction of thread wake-up. Furthermore, the attributes of the directed edges can indicate the number of times threads are woken up. For example, if directed edge 1 points from node A to node B, it means that thread A, represented by node A, wakes up node B, represented by node B; and if the attribute value of directed edge 1 is 5, it means that thread A has woken up thread B 5 times.

[0093] In other words, this application uses a directed graph to record information about critical threads being awakened by other threads, making the awakening paths between threads clearer, more intuitive and comprehensive, which helps to trace back the dependencies of each thread in the chain.

[0094] Step 302: Based on the first wake-up information, determine the second thread. The second thread is the thread that caused the first thread to be blocked, which is predicted based on the first wake-up information.

[0095] In practical applications, scheduling systems often struggle to determine the cause of blocking for each thread. However, since the first wake-up information indicates when the first thread was woken up by other threads in a historical timeframe, this application allows the scheduling system to predict which threads might be causing the first thread's blocking, and thus predict the second thread. Specifically, if the first thread is frequently woken up by a particular thread in a historical timeframe, there is likely an execution dependency between the first thread and that thread (e.g., the thread holds shared resources required by the first thread, or the first thread needs to wait for data resources generated by that thread before it can continue executing). Therefore, if the first thread is currently blocked, it is highly likely that that thread will be responsible for waking it up. Based on this, and using the first wake-up information corresponding to the first thread, the scheduling system can identify and detect the related threads that the first thread depends on (i.e., the aforementioned second thread).

[0096] For example, when the first wake-up information indicates the number of times the first thread has been woken up by the other M threads in a historical time period, the scheduling system can determine the wake-up probability of each of the M threads based on the first wake-up information. The wake-up probability indicates the probability that a thread can wake up the first thread. That is, the scheduling system can determine the probability (i.e., the wake-up probability) that each thread can currently wake up the first thread based on the number of times each of the M threads has woken up the first thread.

[0097] Then, based on the wake-up probabilities of the M threads, the scheduling system can determine a second thread from among the M threads. The second thread includes the N threads with the highest wake-up probability among the M threads, where N is greater than or equal to 1. Furthermore, N must be a value less than M. That is, the second thread can include one or more threads. For example, in the case where M is 5 and N is 2, the scheduling system can determine the two threads with the highest wake-up probability from the five threads that previously woke up the first thread, so as to subsequently increase the execution priority of these two threads.

[0098] Generally, the more times a thread wakes up the first thread in a historical timeframe, the greater the probability that the scheduling system can consider that thread to be able to wake up the first thread at present. Of course, in some embodiments, the first wake-up information may also include other relevant information about the M threads waking up the first thread (such as wake-up type, time of each wake-up, etc.), and the scheduling system can comprehensively determine the wake-up probability of each thread based on the relevant information about the M threads waking up the first thread. This application does not make specific limitations in this regard.

[0099] Step 303: Adjust the execution priority of the second thread to the target priority, which is the execution priority of the first thread, and the original execution priority of the second thread is lower than the target priority.

[0100] If the scheduling system determines that the first thread's blocking might be due to the second thread, it can increase the execution priority of the second thread, adjusting its priority to be the same as the first thread's. This allows the second thread, which initially had a lower priority, to be scheduled for execution first. For example, if the second thread initially had a low priority while the first thread had a high priority, the scheduling system can adjust the second thread's priority to high. If the second thread does indeed have an execution dependency on the first thread (e.g., the second thread holds a shared resource that the first thread is waiting for, or the second thread can generate the data resources needed for the first thread's execution), then increasing the second thread's priority allows it to be executed faster. This, in turn, allows the first thread to be executed without being blocked, thus improving the first thread's execution efficiency.

[0101] In summary, by identifying the second thread that the first thread depends on when it is blocked based on the historical wake-up information of the first thread, and by increasing the execution priority of the second thread, the second thread that the first thread depends on can be executed first. This allows the first thread to execute quickly after the second thread has finished executing, avoiding the first thread from being continuously blocked while waiting for the second thread, and effectively ensuring the execution efficiency of the first thread.

[0102] Optionally, after the first thread finishes execution, the scheduling system can restore the execution priority of the second thread to its original priority. In short, in this scheme, the purpose of adjusting the execution priority of the second thread is to ensure that the first thread, which depends on the second thread, can execute as quickly as possible. Therefore, after the first thread successfully completes execution, the scheduling system needs to restore the execution priority of the second thread to its original state to ensure that all threads in the system can be scheduled according to their execution priorities, avoiding prolonged adjustments to the second thread's execution priority that could affect the normal execution of other threads.

[0103] Optionally, after the first thread is awakened, the scheduling system can update the first wake-up information based on the information of the thread that woke up the first thread. For example, if the first thread is awakened by a second thread, the scheduling system can increment the number of times the second thread woke up the first thread in the first wake-up information, thereby updating the first wake-up information. Of course, if the first wake-up also records other relevant information about the first thread being awakened (such as wake-up type or wake-up time), the scheduling system can also add the relevant information about the second thread waking up the first thread to the first wake-up information.

[0104] In this scheme, after the first thread is awakened, the wake-up information related to the first thread is updated in a timely manner. This ensures the real-time and comprehensiveness of the wake-up information, which is beneficial for subsequent more accurate prediction of the thread that can wake up the first thread based on the wake-up information, thus ensuring the subsequent execution efficiency of the first thread.

[0105] The above describes the process of determining associated threads based on historical wake-up information and then ensuring timely execution of threads by increasing the execution priority of associated threads. However, in practical applications, a thread being blocked may not be due to just one thread. A dependency chain may exist between threads. For example, in the dependency chain of thread A → thread B → thread C, it means that the execution of thread B depends on thread A, and the execution of thread C depends on thread B. Therefore, when a thread at the end of the dependency chain is blocked, it is often necessary to execute all threads in the dependency chain before the blocking problem at the end of the chain can be resolved. Based on this, in cases where there is a dependency chain between threads, this application also proposes to continuously backtrack and adjust the execution priority of threads in the dependency chain, thereby ensuring that the first thread is executed in a timely manner.

[0106] In Implementation Method 1, after adjusting the execution priority of the threads that the first thread directly depends on, if the first thread still fails to execute in time, then continue to backtrack and adjust the execution priority of the threads in the dependency chain that the first thread is in.

[0107] In implementation method 1, the scheduling system can first adjust the execution priority of the thread that the first thread directly depends on (i.e., the second thread mentioned above), and observe whether the first thread can be executed in a timely manner. If the first thread still cannot be executed in a timely manner, the scheduling system will then consider continuing to trace back the dependency chain in which the first thread is located, and then adjust the execution priority of the deeper threads until the first thread can be executed.

[0108] For example, after adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset interval, the scheduling system obtains second wake-up information. This second wake-up information indicates that the second thread was woken up by another thread at a historical time. The information included in the second wake-up information is similar to that included in the first wake-up information, the only difference being that the second wake-up information is the wake-up information corresponding to the second thread, while the first wake-up information is the wake-up information corresponding to the first thread. Please refer to the description of the first wake-up information above for details.

[0109] Then, the scheduling system determines the third thread based on the second wake-up information. The third thread is the thread that caused the second thread to be blocked, as predicted by the second wake-up information. The way the scheduling system determines the third thread based on the second wake-up information is similar to step 302 above, and will not be repeated here.

[0110] Secondly, the scheduling system adjusts the execution priority of the third thread to the target priority.

[0111] In other words, after adjusting the execution priority of the second thread, which the first thread depends on, if the scheduling system finds that the first thread is still blocked, it can assume that the second thread may also be blocked, thus preventing the first thread from executing. Therefore, the scheduling system continues to backtrack to the thread that the second thread depends on (i.e., the third thread mentioned above) and increases the execution priority of the thread that the second thread depends on to ensure that the thread that the second thread depends on can be executed as soon as possible, thereby accelerating the execution of the second thread and the first thread.

[0112] It's important to note that the example above illustrates how the scheduling system backtracks down the threads that the second thread, which in turn depends on the first thread, further depends on. That is, the scheduling system backtracks two levels down the dependency chain of the first thread to identify the threads that the first thread directly depends on and those that it indirectly depends on. In practical applications, the scheduling system can determine the number of backtracking levels (e.g., 2, 3, or 5 levels) based on actual needs or user-defined strategies, thereby determining the number of threads whose execution priorities need to be adjusted. Generally, the more backtracking levels, the higher the probability that the first thread will be executed as quickly as possible, but the more computational resources will be consumed during backtracking. Furthermore, since a higher backtracking level also means a greater number of threads whose execution priorities need adjustment, the impact on system stability tends to be greater. Therefore, in practical applications, the scheduling system can determine the number of backtracking levels based on actual needs or user-defined strategies to achieve a balance.

[0113] In this solution, by adjusting the execution priority of the threads that the first thread directly depends on and finding that the first thread still has not executed in time, we continue to backtrack on the dependency chain and adjust the execution priority of the upper-level threads. This can effectively solve the priority inversion problem caused by multi-level blocking, thereby ensuring that the first thread can execute smoothly.

[0114] In implementation method 2, after the first thread is blocked, a backtracking is triggered and the execution priority of multiple threads in the dependency chain of the first thread is adjusted at the same time.

[0115] In implementation method 2, the scheduling system can immediately trigger the backtracking of the threads that the first thread directly depends on and the threads that the first thread indirectly depends on after it is found that the first thread is blocked, and ensure that the first thread can be executed in a timely manner by adjusting the execution priority of these threads that affect the execution of the first thread at the same time.

[0116] For example, after determining the second thread, the scheduling system obtains second wake-up information, which indicates that the second thread was woken up by other threads in a historical timeframe. Based on this second wake-up information, the scheduling system determines a third thread, which is the thread predicted by the second wake-up information to have caused the second thread to block. The scheduling system then adjusts the execution priority of the third thread to the target priority.

[0117] It should be noted that the example in Implementation Method 2 only illustrates the scheduling system backtracking the threads that the second thread, which in turn depends on the first thread, further depends on. In practical applications, the scheduling system can also determine the number of backtracking levels (such as 2, 3, or 5 levels) based on actual needs or user-defined strategies, thereby determining the number of threads whose execution priorities need to be adjusted. This application does not impose specific limitations on this.

[0118] In this solution, when the first thread is found to be blocked, the execution priority of the multi-level threads before the first thread is directly backtracked on the dependency chain and adjusted. This can effectively solve the priority inversion problem caused by multi-level blocking, thereby ensuring that the first thread can execute smoothly.

[0119] The execution process of a thread processing method provided in this application has been described above. For ease of understanding, the following will detail how to implement the thread processing method provided in this application in practical applications, using specific examples.

[0120] Please see Figure 4 , Figure 4 This is a schematic diagram of a system architecture for a practical application provided in this application. For example... Figure 4As shown, in practical applications, the system architecture includes user space and kernel space. User space includes waiting threads (i.e., blocked threads) and waking threads (i.e., threads responsible for waking up blocked threads). Kernel space includes a detection module, a prediction module, and a feedback module. The detection module detects the waiting / waking relationships between threads and extracts the execution context related to the waiting and waking threads. This allows the construction module to build a directed graph indicating the waiting / waking relationships between threads based on the extracted execution context. The prediction module predicts the associated threads that the blocked threads depend on based on the directed graph built by the construction module, thereby increasing the execution priority of the associated threads. The feedback module detects the actual wake-up results of the blocked threads and provides feedback to the construction and prediction modules to update the directed graph and adjust subsequent predictions.

[0121] Please see Figure 5 , Figure 5 This application provides a flowchart illustrating a practical application of thread processing. For example... Figure 5 As shown, the process of implementing thread processing in practical applications includes the following steps 501-508.

[0122] Step 501: Determine the key thread set and the relationship set.

[0123] After the execution device starts up, the scheduling system in the execution device first determines the critical thread set C = {C0, C1, ..., C...}. n The critical thread set includes multiple critical threads. These critical threads may include user-defined threads, threads identified by the operating system using a critical thread identification method, or threads closely related to the execution of predefined threads that the operating system further discovers based on user-defined threads. This application does not specifically limit the method for determining critical threads.

[0124] After determining the set of critical threads, the scheduling system can create a relation set R = {R0, R1, ..., R...} of a corresponding order of magnitude based on the number of critical threads included in the set. n} Where n is 1024, indicating that there are 1024 relation identifiers in the relation set. Furthermore, the relation identifiers in the relation set are used to assign to critical threads and to wake up threads that are associated with critical threads (i.e., the threads associated with critical threads). Simply put, the relation identifiers in the relation set are used to replace thread identifiers to represent the corresponding threads; therefore, each thread uniquely corresponds to one relation identifier.

[0125] Step 502: When the critical thread is awakened, assign relationship identifiers from the relationship set to the critical thread and its associated threads.

[0126] During the operation of the execution device, when the scheduling system detects that a critical thread C is awakened by a thread T, if neither critical thread C nor thread T has been assigned a corresponding relationship identifier, the scheduling system will retrieve the unassigned relationship identifier from the relationship set and assign the corresponding relationship identifier to critical thread C and thread T. Of course, if critical thread C or thread T has already been assigned a corresponding relationship identifier, the scheduling system will not assign a relationship identifier to a thread that has already been assigned one.

[0127] Step 503: Extract the execution context of the awakened key thread and its associated thread.

[0128] For the critical thread C that is awakened and the associated thread T that awakened C, the scheduling system further extracts the execution context of these two threads during the wake-up process. The execution context includes, for example, the relationship identifier of the awakened critical thread C, the relationship identifier of the associated thread T that awakened C, and the wake-up type (e.g., lock-based or semaphore-based). Optionally, the execution context may also include optional features such as the program counter (PC) register and the thread call stack. Whether these optional features need to be extracted can be determined based on the thread prediction strategy.

[0129] Step 504: Build or update the directed graph used to indicate inter-thread dependencies.

[0130] When the scheduling system first extracts the execution context of a critical thread when it is awakened, it constructs a directed graph based on that extracted execution context. If the scheduling system has already constructed the directed graph, it updates the directed graph based on the newly extracted execution context.

[0131] For example, please refer to Figure 6 , Figure 6 This is a schematic diagram of a directed graph provided in this application. For example... Figure 6 As shown, in a directed graph, nodes represent threads, directed edges represent the wake-up directions between nodes, and attribute values ​​on the directed edges represent the number of times nodes are woken up. Figure 6 In the diagram, nodes 0-7 represent threads 0-7 respectively, and threads 0, 1, and 3-6 are all critical threads. Thread 2 is the associated thread that wakes up thread 6, and thread 7 is the associated thread that wakes up thread 4. The directed edge between node 1 and node 0 points from node 1 to node 0, and its attribute value is 1, indicating that thread 1 has woken up thread 0 once. The directed edge between node 5 and node 4 points from node 5 to node 4, and its attribute value is 5, indicating that thread 5 has woken up thread 4 five times.

[0132] Step 505: Construct or update the probability transition matrix based on the directed graph.

[0133] After constructing or updating a directed graph, the scheduling system can construct or update a probability transition matrix based on the directed graph. This probability transition matrix can indicate the probability that each critical thread will be awakened by its associated thread.

[0134] For example, please refer to Figure 7 , Figure 7 This is a schematic diagram illustrating how to obtain a probability transition matrix based on a directed graph, as provided in this application. Figure 7 As shown, for a directed graph representing the wake-up relationships between threads, the scheduling system can first represent the directed graph as a matrix to obtain a dependency matrix. In the dependency matrix, one wake-up thread corresponds to one column, and one waiting thread corresponds to one row. The element in the x-th row and y-th column of the matrix represents the number of times the wake-up thread corresponding to the y-th column wakes up the waiting thread corresponding to the x-th row. For example, the element in the 0-th row and 1-th column is 4, which means that thread 1 corresponding to the 1-th column wakes up thread 0 corresponding to the 0-th row four times. In practical applications, the dependency matrix can be represented using multiple triples. For example, if the first element of a triple represents the wake-up thread, the second element represents the waiting thread, and the third element represents the number of wake-ups, then the triple (1, 0, 4) represents thread 1 waking up thread 0 four times.

[0135] Based on the dependency matrix, a total dependency count matrix can be generated. This matrix contains elements only on the main diagonal, and each element on the main diagonal is the sum of all elements in the same row of the dependency matrix. Therefore, each element in each row of the total dependency count matrix represents the total number of times the corresponding waiting thread has been awakened by other threads. For example, in the total dependency count matrix, the element in row 0 is 5, representing that thread 0 has been awakened by other threads a total of 5 times; the element in row 1 is 8, representing that thread 1 has been awakened by other threads a total of 8 times; ..., the element in row 7 is 3, representing that thread 7 has been awakened by other threads a total of 3 times.

[0136] Thus, based on the dependency matrix and the total number of dependencies matrix, the probability transition matrix can be obtained. Each element in the probability transition matrix represents the probability that a waiting thread will be awakened by a certain waking thread (i.e., the awakening probability mentioned above). For example, the element in row 0, column 1 is 4 / 5, representing the probability that thread 1 can currently awaken thread 0 is 4 / 5. The element in row 1, column 3 is 2 / 8, representing the probability that thread 3 can currently awaken thread 1 is 2 / 8. In summary, for a waiting thread, the probability that the waiting thread will be awakened by a certain waking thread is the number of times the waiting thread has been awakened by a waking thread divided by the total number of times the waiting thread has been awakened.

[0137] It should be noted that the above calculation uses the number of wake-ups between waiting threads and waking threads as the attribute value to determine the wake-up probability of each waking thread relative to the waiting thread. In some examples, the scheduling system may also combine other information extracted from the execution context or the actual wake-up results of subsequent waiting threads to determine the wake-up probability; this application does not specifically limit this.

[0138] Step 506: When the target critical thread is blocked for a long time, determine the associated threads of the target critical thread and the wake-up probability of each associated thread based on the probability transition matrix.

[0139] When the scheduling system detects that a target critical thread (corresponding to the first thread mentioned above) is blocked for an extended period, such as exceeding a preset blocking time, the scheduling system can assume that the target critical thread may have been affected by priority inversion. Therefore, the scheduling system can determine the associated threads of the target critical thread (i.e., threads capable of waking up the target critical thread) and the wake-up probability of each associated thread based on the probability transition matrix. Simply put, the associated threads of the target critical thread are those threads that have previously woken up the target critical thread. Furthermore, the more times an associated thread has woken up the target critical thread historically, the higher its wake-up probability.

[0140] For example, with Figure 7 Taking the probability transition matrix shown as an example, assuming that thread 4 is the target critical thread, then the associated threads of thread 4 include thread 5 and thread 7, and the wake-up probability of thread 5 is 5 / 6, while the wake-up probability of thread 7 is 1 / 6.

[0141] Of course, in some examples, the scheduling system may not build or update the probability transition matrix first, but instead obtain the wake-up information related to the target key thread from the directed graph when it is found that the target key thread is blocked for a long time, and then build or update the probability transition matrix based on the wake-up information related to the target key thread.

[0142] Step 507: Based on the wake-up probability corresponding to each associated thread, determine the target associated thread and adjust the execution priority of the target associated thread to the execution priority of the target critical thread.

[0143] After determining the wake-up probability of each associated thread of the target critical thread, the scheduling system can identify one or more threads from all associated threads of the target critical thread as target associated threads. For example, the scheduling system can identify the N threads with the highest wake-up probability as target associated threads, where N is an integer greater than or equal to 1. Furthermore, N can be a pre-set value (such as 1 or 3), or it can be determined based on a pre-set ratio according to the total number of associated threads of the target critical thread (for example, if the pre-set ratio is 50%, and there are 4 associated threads, N is 4 * 50% = 2).

[0144] After identifying the target-related threads, the scheduling system can consider these target-related threads as the threads most likely to cause the target critical thread to be blocked. Therefore, the scheduling system adjusts the execution priority of the target-related threads to the execution priority of the target critical thread so that the target-related threads can be executed as soon as possible, thereby enabling the target critical thread to start execution as early as possible.

[0145] Optionally, in some examples, since the target critical thread may be on a long dependency chain, in order to ensure that the target critical thread can be executed as soon as possible, the scheduling system can also determine and adjust the execution priority of other threads that the target critical thread indirectly depends on by performing multi-level backtracking on the dependency chain (i.e., performing back propagation based on directed edges on the directed graph).

[0146] When backtracking the dependency chain for a target critical thread, the scheduling system can determine the backtracking level and the number of associated threads to be determined each time backtracking based on a pre-set backtracking strategy, thereby determining the threads whose execution priority needs to be adjusted.

[0147] For example, please refer to Figure 8 , Figure 8 This application provides a schematic diagram of a method for implementing dependency chain backtracking by performing backpropagation in a directed graph. For example... Figure 8As shown, when the backtracking strategy specifies a backtracking level of 3 and requires identifying one associated thread in each backtracking iteration, for the currently blocked thread 4, the scheduling system performs backpropagation based on the directed edges in the directed graph (i.e., determining associated threads along the opposite direction of the directed edges), thereby achieving backtracking of the dependency chain in which thread 4 resides. Specifically, when the scheduling system backtracks to the first level for thread 4, it can identify thread 5, which has the highest probability of waking up thread 4; when backtracking to the second level for thread 4, it can identify thread 3, which has the highest probability of waking up thread 5; and when backtracking to the third level for thread 4, it can identify thread 6, which has the highest probability of waking up thread 3. Ultimately, the scheduling system can determine that threads 5, 3, and 6 are all threads on the dependency chain in which thread 4 resides, and that they have affected the blocking of thread 4. Therefore, the scheduling system can adjust the execution priorities of threads 5, 3, and 6 to the execution priority of thread 4, so that threads 5, 3, and 6 can execute as quickly as possible, thereby ensuring that thread 4 can also execute as quickly as possible.

[0148] It should be noted that the timing of multiple backtracking operations on the dependency chain for the target critical thread by the scheduling system can be determined based on a pre-defined strategy. For example, in some strategies, the scheduling system may immediately begin multiple backtracking operations on the dependency chain for the target critical thread and adjust the execution priorities of the associated threads discovered during the backtracking once it detects that the target critical thread is blocked. In other strategies, the scheduling system may first perform one backtracking operation on the dependency chain for the target critical thread (i.e., only identifying the threads directly dependent on the target critical thread), and if, after adjusting the execution priorities of the threads directly dependent on the target critical thread, it still finds that the target critical thread has not executed in time, then it will perform multiple backtracking operations on the dependency chain for the target critical thread and adjust the execution priorities of the associated threads discovered during the backtracking.

[0149] Step 508: After the target critical thread has finished executing, restore the execution priority of the target associated thread.

[0150] After the target critical thread has finished executing, it means that the execution of the target critical thread no longer depends on the target associated thread. Therefore, the scheduling system can restore the execution priority of the target associated thread to its original execution priority to ensure the normal execution of thread scheduling.

[0151] The methods provided in the embodiments of this application have been described in detail above. Next, the device for performing the above methods provided in the embodiments of this application will be described.

[0152] Please see Figure 9 , Figure 9 This is a schematic diagram of the structure of a thread processing device provided in this application. Figure 9As shown, the thread processing device includes: an acquisition module 901, configured to acquire first wake-up information when a first thread is blocked, the first wake-up information indicating that the first thread was woken up by other threads in a historical time; a processing module 902, configured to determine a second thread based on the first wake-up information, the second thread being the thread that caused the first thread to be blocked based on the prediction of the first wake-up information; the processing module 902 is further configured to adjust the execution priority of the second thread to a target priority, the target priority being the execution priority of the first thread, and the original execution priority of the second thread being lower than the target priority.

[0153] In one possible implementation, the first wake-up information is used to indicate the number of times the first thread has been woken up by other M threads in the historical time, where M is greater than or equal to 1; the processing module 902 is specifically used to: determine the wake-up probability of the threads among the M threads based on the first wake-up information, where the wake-up probability is used to indicate the probability that a thread wakes up the first thread; and determine the second thread among the M threads based on the wake-up probability, where the second thread includes the N threads with the highest wake-up probability among the M threads, where N is greater than or equal to 1.

[0154] In one possible implementation, the processing module 902 is further configured to: after adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset time interval, obtain second wake-up information, the second wake-up information being used to indicate that the second thread was woken up by other threads in a historical time; based on the second wake-up information, determine the third thread, the third thread being the thread that caused the second thread to be blocked based on the prediction of the second wake-up information; and adjust the execution priority of the third thread to the target priority.

[0155] In one possible implementation, the processing module 902 is further configured to: after determining the second thread, obtain second wake-up information, the second wake-up information being used to indicate that the second thread was woken up by other threads in a historical time; based on the second wake-up information, determine the third thread, the third thread being the thread that caused the second thread to be blocked based on the prediction of the second wake-up information; and adjust the execution priority of the third thread to the target priority.

[0156] In one possible implementation, the first wake-up information is based on the relationship identifiers assigned to the first thread and other threads to record information about when the first thread was woken up by other threads in a historical time. The amount of data in the relationship identifiers is less than the amount of data in the thread identifiers.

[0157] In one possible implementation, the first thread is a predefined key thread, and the relation identifiers corresponding to the first thread and other threads are allocated from a relation set. The relation identifiers in the relation set are only used to allocate to key threads and threads that wake up key threads.

[0158] In one possible implementation, the processing module 902 is further configured to: restore the execution priority of the second thread to its original execution priority after the first thread has finished executing.

[0159] In one possible implementation, the processing module 902 is further configured to: after the first thread is awakened, update the first wake-up information based on the information of the thread that awakened the first thread.

[0160] In one possible implementation, the first wake-up information is obtained from a directed graph. The directed graph is used to record information about critical threads being woken up by other threads in a historical time. The first thread belongs to the critical threads. The directed graph includes nodes and directed edges between nodes. Nodes are used to represent threads, directed edges are used to represent the direction of thread wake-up, and the attributes of the directed edges are used to indicate the number of times the nodes are woken up.

[0161] In one possible implementation, the first wake-up information is obtained after the first thread belonging to the critical thread has been blocked for a period of time exceeding a preset duration.

[0162] Please see Figure 10 , Figure 10 This is a schematic diagram of the structure of an execution device provided in this application. Figure 10 As shown, the execution device 1000 can specifically manifest as a smartphone, personal computer, laptop computer, tablet computer, smart car, or server, etc., without limitation. Specifically, the execution device 1000 includes: a receiver 1001, a transmitter 1002, a processor 1003, local memory 1004, and global memory 1005. The execution device 1000 can have multiple processors 1003. Figure 10 Only one processor is shown in the image; the number of local memories 1004 in execution device 1000 can be multiple. Figure 10 Only one local memory is shown. Furthermore, a local memory and one or more processors constitute a CC domain, thereby enabling the execution device 1000 to include multiple CC domains. Processor 1003 may include application processor 10031 and communication processor 10032. In some embodiments of this application, receiver 1001, transmitter 1002, processor 1003, and local memory 1004 may be connected via a bus or other means.

[0163] Local memory 1004 may include read-only memory (ROM) and random access memory (RAM), and provides instructions and data to processor 1003. A portion of local memory 1004 may also include non-volatile random access memory (NVRAM). Local memory 1004 stores processor and operation instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operation instructions may include various operation instructions for implementing various operations.

[0164] Processor 1003 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together through a bus system, which may include not only the data bus, but also power buses, control buses, and status signal buses. However, for clarity, all buses are referred to as the bus system in the diagram.

[0165] The methods disclosed in the embodiments of this application described above can be applied to processor 1003, or implemented by processor 1003. Processor 1003 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 1003 or by instructions in the form of software. The processor 1003 described above can be a CPU, GPU, NPU, digital signal processor (DSP), microprocessor or microcontroller, and may further include application-specific integrated circuit (ASIC), field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0166] The processor 1003 can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in local memory 1004. The processor 1003 reads information from local memory 1004 and, in conjunction with its hardware, completes the steps of the above methods.

[0167] Receiver 1001 can be used to receive input digital or character information, and to generate signal inputs related to the settings and function control of the execution device. Transmitter 1002 can be used to output digital or character information through the first interface; transmitter 1002 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; transmitter 1002 may also include a display device such as a display screen.

[0168] The execution device provided in this application embodiment can specifically be a chip, which includes a processing unit and a communication unit. The processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, pins, or circuits. The processing unit can execute computer execution instructions stored in the storage unit to cause the chip in the execution device to execute the methods described in the above embodiments. Optionally, the storage unit can be an internal storage unit within the chip, such as a register or cache. Alternatively, the storage unit can be an external storage unit located within the wireless access device, such as a read-only memory or other types of static storage devices capable of storing static information and instructions, such as random access memory.

[0169] Please refer to Figure 11 , Figure 11 This is a schematic diagram of a computer-readable storage medium provided in this application. This application also provides a computer-readable storage medium in some embodiments, wherein the above-described... Figure 3 The disclosed method can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of art.

[0170] Figure 11 A conceptual partial view of an example computer-readable storage medium arranged according to at least one embodiment shown herein is illustrated schematically. The example computer-readable storage medium includes a computer program for executing computer processes on a computing device.

[0171] In one embodiment, the computer-readable storage medium 1100 is provided using a signal bearer medium 1101. The signal bearer medium 1101 may include one or more program instructions 1102, which, when executed by one or more processors, can provide the above-mentioned... Figure 3 The described function or part of the function.

[0172] In some examples, the signal carrying medium 1101 may include a computer-readable medium 1103, such as, but not limited to, a hard disk drive, a compact disc (CD), a digital video disc (DVD), a digital magnetic tape, a memory, ROM, or RAM, etc.

[0173] In some embodiments, the signal carrying medium 1101 may comprise a computer-recordable medium 1104, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal carrying medium 1101 may comprise a communication medium 1105, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.). Therefore, for example, the signal carrying medium 1101 may be transmitted by a wireless form of communication medium 1105 (e.g., a wireless communication medium conforming to the IEEE 802.X standard or other transmission protocols).

[0174] One or more program instructions 1102 may be, for example, computer-executable instructions or logical implementation instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to one or more program instructions 1102 conveyed to the computing device via a computer-readable medium 1103, a computer-recordable medium 1104, and / or a communication medium 1105.

[0175] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the accompanying drawings of the device embodiments provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.

[0176] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods of the various embodiments of this application.

[0177] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.

[0178] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, computer instructions may be transferred from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).

Claims

1. A thread processing method, characterized in that, include: When the first thread is blocked, the first wake-up information is obtained. The first wake-up information is used to indicate that the first thread was woken up by other threads in a historical time. Based on the first wake-up information, a second thread is determined, which is the thread that caused the first thread to be blocked, as predicted based on the first wake-up information. The execution priority of the second thread is adjusted to the target priority, which is the execution priority of the first thread, and the original execution priority of the second thread is lower than the target priority.

2. The method according to claim 1, characterized in that, The first wake-up information is used to indicate the number of times the first thread has been woken up by other M threads in the historical time, where M is greater than or equal to 1; The step of determining the second thread based on the first wake-up information includes: Based on the first wake-up information, the wake-up probability of each of the M threads is determined, and the wake-up probability is used to indicate the probability that a thread wakes up the first thread; Based on the wake-up probability, the second thread is determined from the M threads. The second thread includes the N threads with the highest wake-up probability among the M threads, where N is greater than or equal to 1.

3. The method according to claim 1 or 2, characterized in that, The method further includes: After adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset interval, then the second wake-up information is obtained. The second wake-up information is used to indicate that the second thread was woken up by other threads in the past. Based on the second wake-up information, a third thread is determined, wherein the third thread is the thread that caused the second thread to be blocked, which is predicted based on the second wake-up information. Adjust the execution priority of the third thread to the target priority.

4. The method according to claim 1 or 2, characterized in that, The method further includes: After determining the second thread, obtain the second wake-up information, which is used to indicate that the second thread was woken up by other threads in a historical time. Based on the second wake-up information, a third thread is determined, wherein the third thread is the thread that caused the second thread to be blocked, which is predicted based on the second wake-up information. Adjust the execution priority of the third thread to the target priority.

5. The method according to any one of claims 1-4, characterized in that, The first wake-up information is based on the relationship identifiers assigned to the first thread and the other threads to record information about when the first thread was woken up by the other threads in a historical time period. The amount of data in the relationship identifier is less than the amount of data in the thread identifier.

6. The method according to claim 5, characterized in that, The first thread is a predefined key thread, and the relationship identifiers corresponding to the first thread and the other threads are allocated from a relationship set. The relationship identifiers in the relationship set are only used to allocate to the key thread and the thread that wakes up the key thread.

7. The method according to any one of claims 1-6, characterized in that, The method further includes: After the first thread finishes execution, the execution priority of the second thread is restored to the original execution priority.

8. The method according to any one of claims 1-7, characterized in that, The method further includes: After the first thread is awakened, the first wake-up information is updated based on the information of the thread that woke up the first thread.

9. The method according to any one of claims 1-8, characterized in that, The first wake-up information is obtained from a directed graph, which is used to record information about a critical thread being woken up by other threads in a historical time period, and the first thread belongs to the critical thread. The directed graph includes nodes and directed edges between nodes. The nodes represent threads, the directed edges represent the direction of thread wake-up, and the attributes of the directed edges indicate the number of wake-up cycles between nodes.

10. The method according to any one of claims 1-9, characterized in that, The acquisition of the first wake-up information is triggered after it is detected that the first thread, which belongs to the critical thread, has been blocked for a period of time exceeding a preset duration.

11. A thread processing device, characterized in that, include: The acquisition module is used to acquire first wake-up information when the first thread is blocked. The first wake-up information is used to indicate information that the first thread was woken up by other threads in a historical time. The processing module is configured to determine a second thread based on the first wake-up information, wherein the second thread is the thread that caused the first thread to be blocked, as predicted by the first wake-up information. The processing module is further configured to adjust the execution priority of the second thread to a target priority, wherein the target priority is the execution priority of the first thread, and the original execution priority of the second thread is lower than the target priority.

12. The apparatus according to claim 11, characterized in that, The first wake-up information is used to indicate the number of times the first thread has been woken up by other M threads in the historical time, where M is greater than or equal to 1; The processing module is specifically used for: Based on the first wake-up information, the wake-up probability of each of the M threads is determined, and the wake-up probability is used to indicate the probability that a thread wakes up the first thread; Based on the wake-up probability, the second thread is determined from the M threads. The second thread includes the N threads with the highest wake-up probability among the M threads, where N is greater than or equal to 1.

13. The apparatus according to claim 11 or 12, characterized in that, The processing module is further configured to: After adjusting the execution priority of the second thread to the target priority, if the first thread still has not started execution after a preset interval, then the second wake-up information is obtained. The second wake-up information is used to indicate that the second thread was woken up by other threads in the past. Based on the second wake-up information, a third thread is determined, wherein the third thread is the thread that caused the second thread to be blocked, which is predicted based on the second wake-up information. Adjust the execution priority of the third thread to the target priority.

14. The apparatus according to claim 11 or 12, characterized in that, The processing module is further configured to: After determining the second thread, obtain the second wake-up information, which is used to indicate that the second thread was woken up by other threads in a historical time. Based on the second wake-up information, a third thread is determined, wherein the third thread is the thread that caused the second thread to be blocked, which is predicted based on the second wake-up information. Adjust the execution priority of the third thread to the target priority.

15. The apparatus according to any one of claims 11-14, characterized in that, The first wake-up information is based on the relationship identifiers assigned to the first thread and the other threads to record information about when the first thread was woken up by the other threads in a historical time period. The amount of data in the relationship identifier is less than the amount of data in the thread identifier.

16. The apparatus according to claim 15, characterized in that, The first thread is a predefined key thread, and the relationship identifiers corresponding to the first thread and the other threads are allocated from a relationship set. The relationship identifiers in the relationship set are only used to allocate to the key thread and the thread that wakes up the key thread.

17. The apparatus according to any one of claims 11-16, characterized in that, The processing module is further configured to: After the first thread finishes execution, the execution priority of the second thread is restored to the original execution priority.

18. The apparatus according to any one of claims 11-17, characterized in that, The processing module is further configured to: After the first thread is awakened, the first wake-up information is updated based on the information of the thread that woke up the first thread.

19. The apparatus according to any one of claims 11-18, characterized in that, The first wake-up information is obtained from a directed graph, which is used to record information about a critical thread being woken up by other threads in a historical time period, and the first thread belongs to the critical thread. The directed graph includes nodes and directed edges between nodes. The nodes represent threads, the directed edges represent the direction of thread wake-up, and the attributes of the directed edges indicate the number of wake-up cycles between nodes.

20. The apparatus according to any one of claims 11-19, characterized in that, The acquisition of the first wake-up information is triggered after it is detected that the first thread, which belongs to the critical thread, has been blocked for a period of time exceeding a preset duration.

21. A thread processing device, characterized in that, The device includes a memory and a processor; the memory stores code, and the processor is configured to execute the code, wherein when the code is executed, the device performs the method as described in any one of claims 1 to 10.

22. A computer storage medium, characterized in that, The computer storage medium stores instructions that, when executed by the computer, cause the computer to perform the method according to any one of claims 1 to 10.

23. A computer program product, characterized in that, The computer program product stores instructions that, when executed by a computer, cause the computer to perform the method described in any one of claims 1 to 10.