Thread scheduling method, device, storage medium and electronic device

By prioritizing the processing of user interaction events with the longest waiting time in electronic devices, the lag issue caused by multiple applications running was resolved, thus improving the user experience.

CN111813520BActive Publication Date: 2024-11-19GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010627109.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-01
Publication Date
2024-11-19
Estimated Expiration
2040-07-01

AI Technical Summary

Technical Problem

Electronic devices are prone to lag during user interaction scenarios when running multiple applications, which affects the user experience.

Method used

By traversing the task list of the target processor unit in descending order of priority, the thread with the longest waiting time related to user interaction events is identified and executed first, ensuring that these threads can be processed in a timely manner and reducing lag.

Benefits of technology

It improves the smoothness of user interaction scenarios and enhances the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111813520B_ABST
    Figure CN111813520B_ABST
Patent Text Reader

Abstract

The present application discloses a thread scheduling method, device, storage medium and electronic device. The method comprises: traversing multiple task lists of a target processor unit in order of priority from high to low, until a task list with a non-zero number of threads is obtained as a target task list; detecting whether there is a first-class thread in the target task list, the first-class thread is a thread that executes tasks related to user interaction events; when there is a first-class thread in the target task list, determining the first-class thread with the longest waiting time from the target task list as the first target thread; and executing the first target thread based on the target processor unit. In the present application, the target processor unit will give priority to processing the first-class thread, so that the first-class thread that executes tasks related to user interaction events can be executed in time, thereby reducing the jamming phenomenon in the user interaction scenario.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a thread scheduling method, device, storage medium and electronic equipment. Background Art

[0002] With the development of technology, more and more applications are installed in electronic devices, such as video applications, game applications, and instant messaging applications, etc. This requires electronic devices to often run multiple applications in the foreground and background, which is prone to freezes in user interaction scenarios. Summary of the invention

[0003] Embodiments of the present application provide a thread scheduling method, device, storage medium, and electronic device, which can reduce the jamming phenomenon in interactive scenarios.

[0004] In a first aspect, an embodiment of the present application provides a thread scheduling method, the method comprising:

[0005] Traversing multiple task linked lists of the target processor unit in descending order of priority until a task linked list with a non-zero number of threads is obtained as the target task linked list;

[0006] Detecting whether there is a first type of thread in the target task linked list, where the first type of thread is a thread that executes a task related to a user interaction event;

[0007] When there are threads of the first type in the target task linked list, determining the thread of the first type with the longest waiting time from the target task linked list as the first target thread;

[0008] The first target thread is executed based on the target processor unit.

[0009] In a second aspect, an embodiment of the present application provides a thread scheduling device, the device comprising:

[0010] An acquisition module, used for traversing multiple task linked lists of the target processor unit in order of priority from high to low, until a task linked list with a non-zero number of threads is acquired as the target task linked list;

[0011] A detection module, used to detect whether there is a first type of thread in the target task linked list, where the first type of thread is a thread that executes a task related to a user interaction event;

[0012] A determination module, configured to, when there are threads of the first type in the target task linked list, determine the thread of the first type with the longest waiting time from the target task linked list as the first target thread;

[0013] A processing module is configured to execute the first target thread based on the target processor unit.

[0014] In a third aspect, an embodiment of the present application provides a storage medium on which a computer program is stored. When the computer program is executed on a computer, the computer executes the method provided by the embodiment of the present application.

[0015] In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the processor is used to execute the method provided in the embodiment of the present application by calling a computer program stored in the memory.

[0016] In the embodiment of the present application, multiple task lists of the target processor unit are traversed in order from high to low priority until a task list with a non-zero number of threads is obtained as the target task list; it is detected whether there is a first-class thread in the target task list, and the first-class thread is a thread that executes related tasks in the user interaction event; when the first-class thread exists in the target task list, the first-class thread with the longest waiting time is determined from the target task list as the target thread; the target thread is executed based on the target processor unit. Therefore, when the target processor unit selects the thread to be executed, it searches for a target task list with a non-zero number of threads and the highest priority in order from high to low priority. If there is a first-class thread on the target task list, the target processor unit will give priority to the first-class thread, so that the first-class thread that executes tasks related to the user interaction event can be executed in time, thereby reducing the jamming phenomenon in the user interaction scenario and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The technical solution and beneficial effects of the present application will be made apparent by describing in detail the specific implementation modes of the present application in conjunction with the accompanying drawings.

[0018] Figure 1 It is a flowchart of the thread scheduling method provided in an embodiment of the present application.

[0019] Figure 2 This is another flowchart of the thread scheduling method provided in an embodiment of the present application.

[0020] Figure 3 It is a scenario diagram of the thread scheduling method provided in an embodiment of the present application.

[0021] Figure 4 It is a structural diagram of a thread scheduling device provided in an embodiment of the present application.

[0022] Figure 5 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0023] Figure 6 It is another structural schematic diagram of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] Please refer to the drawings, where the same component symbols represent the same components. The principle of the present application is illustrated by implementing it in an appropriate computing environment. The following description is based on the illustrated specific embodiments of the present application, which should not be considered as limiting other specific embodiments of the present application that are not described in detail herein.

[0025] It is understandable that the execution subject of the embodiments of the present application may be an electronic device such as a smart phone or a tablet computer.

[0026] See also Figure 1 , Figure 1 : is a flow chart of a thread scheduling method provided in an embodiment of the present application. The thread scheduling method can be applied to electronic devices. The process of the thread scheduling method can include:

[0027] In 101, multiple task linked lists of the target processor unit are traversed in order of priority from high to low, until a task linked list with a non-zero number of threads is obtained as the target task linked list.

[0028] With the development of technology, more and more applications are installed in electronic devices, such as video applications, game applications, and instant messaging applications, etc. This requires electronic devices to often run multiple applications in the foreground and background, which is prone to freezes in user interaction scenarios.

[0029] In the embodiment of the present application, the operating system of the electronic device may be a system based on the Linux kernel, such as an Android operating system. System processes and application processes are running on the electronic device. A thread is an execution path of a process and is the smallest unit of program execution. A process can have multiple threads, but at least one thread.

[0030] For the kernel, when scheduling resources, such as CPU scheduling, it is specific to a certain thread. There is a main thread in the process, and it will also create many sub-threads to assist in the work. For example, a process of a content interactive application will create a main thread to execute code, and during the execution, it will also create other sub-threads to assist in running the task code of each part.

[0031] In general, threads in the kernel are distinguished by scheduling classes. The most common threads in the kernel are CFS (complete fair schedule) scheduling class threads (such as UI threads, Render threads and many common threads are CFS), RT (RealTime scheduler, real-time scheduling) scheduling class threads (such as Surface flinger threads and some other core threads). The priorities of different scheduling classes are different (the priority here refers to the priority of a certain scheduling class thread as a whole relative to another scheduling class thread). For example, the priority of the scheduling class is reflected in: when the multi-core CPU is scheduled, the RT thread will be selected to run through the task scheduling method of the RT scheduling class first. If there is no RT thread, the CFS thread will be selected from the scheduling method of the CFS scheduling class, that is, the priority of the RT scheduling class is higher than the priority of the CFS scheduling class. Of course, in the respective scheduling methods of these two scheduling classes, the priorities of the threads processed by each other will be distinguished (the priority here refers to the priority of each thread within a certain scheduling class), such as the RT thread in the RT scheduling class, the RT priority of the thread will be distinguished. The scheme of the embodiment of the present application is applicable to the scheduling of RT threads or CFS threads.

[0032] Next, the scheme of the embodiment of the present application is explained by taking the scheduling of RT threads as an example. The RT threads adopt a priority-based scheduling strategy. Common scheduling strategies include FIFO (First In First Out), RR (Round Robin), etc. Regardless of the FIFO scheduling strategy or the RR scheduling strategy, when the thread priorities are different, they are scheduled in order from high to low according to the thread priorities, and the thread with the highest priority will be processed first. When the threads have the same priority, the FIFO scheduling strategy, the first thread to arrive will get the processor resources first, and will occupy the resources until the thread enters the sleep state. For the RR scheduler, threads with the same priority will share processor resources in a take-turn execution manner. When a thread starts running, if the thread will not be blocked, then the thread will run until the time slice assigned to the thread expires. When the time slice is used up, the thread will be placed at the end of the task list.

[0033] In addition, the embodiments of the present application can be applied to multi-core processors. In the ARM standard architecture, there are differences in the computing power of CPU cores. Generally, cores with stronger computing power are called large cores, and cores with weaker computing power are called small cores. For example, for an eight-core processor, there are generally four large cores and four small cores. It should be noted that the above number of cores is only for example. The embodiments of the present application do not specifically limit the number of cores of the processor. When there are at least two cores, the solution of the embodiments of the present application can be used. If the processor of the electronic device is a multi-core processor, each processor core can be used as an independent processing unit. For example, if the electronic device is an eight-core processor, each core is an independent processing unit.

[0034] Each processor unit maintains a run queue. When a thread is ready to be executed, it will be mounted on the run queue of the corresponding target processor unit. The run queue maintains these threads to be executed through the structure of the task list. The run queue includes multiple task lists. Different task lists correspond to different priorities. Threads of the same priority are mounted on the same task list, and threads of different priorities are mounted on different task lists. Newly created threads will also be mounted on the task list of the corresponding priority according to their priority.

[0035] For the run queue of a processor unit, the threads in the run queue use the processor unit resources together. At each moment, only one thread is running, and the thread adopts a priority-based scheduling strategy. Therefore, when the target processor unit selects the thread to be executed, it will traverse the multiple task lists of the target processor unit in order from high to low priority until a task list with a non-zero number of threads is obtained as the target task list. In other words, the target processor unit searches for a task list with a non-zero number of threads in order from high to low priority of the task list, as the target task list. The target task list is the task list with the highest priority and a non-empty number of threads in all current task lists. Among them, when there are threads to be scheduled for execution in the run queue of a processor unit, the processor unit is used as the target processor unit, and the threads in its run queue are scheduled for execution according to the scheme proposed in the embodiment of the present application.

[0036] For example, there are currently five task lists of different priorities: Table 1, Table 2, Table 3, Table 4, Table 5, and the order of the priorities of the task lists from high to low is: Table 1, Table 2, Table 3, Table 4, Table 5. When the target processor selects the thread to be executed, it will start from Table 1 to determine whether the number of threads is not zero. If there are threads in Table 1, Table 1 will be used as the target task list, and Table 2, Table 3, Table 4, and Table 5 will not be searched further. That is, Table 1 is the task list with the current number of threads not being zero and the highest priority. If there are currently no threads in Table 1, Table 2 will be searched further. If there are currently threads in Table 2, Table 2 will be used as the target task list, and Table 3, Table 4, and Table 5 will not be searched further. That is, Table 2 is the task list with the current number of threads not being zero and the highest priority.

[0037] In 102, it is detected whether there is a first type of thread in the target task linked list, wherein the first type of thread is a thread that executes a task related to the user interaction event.

[0038] In an embodiment of the present application, when the target processor unit schedules a thread, it first obtains a target task list whose current thread number is not zero and whose priority is the highest; then, it detects whether there is a first-class thread in the target task list, wherein the first-class thread is a thread that executes related tasks in a user interaction event.

[0039] Among them, whether the thread that executes relevant tasks in the user interaction event can run smoothly determines whether user-perceivable lag will occur in the user interaction event. Therefore, in the embodiment of the present application, the thread that executes relevant tasks in the user interaction event is determined, and these threads closely related to the user experience are recorded as ux (user experience) threads as the first type of threads.

[0040] Since the scenarios that cause user-perceivable interface freezes are mostly relative to the process running in the foreground, therefore, in one embodiment, when it is detected that a process is switched to the foreground, the foreground process is determined; threads used to execute tasks related to the user interaction event are identified from the threads of the foreground process, and these threads are regarded as first-class threads.

[0041] In one embodiment, the first type of threads include some threads created when the process is running and used to directly execute tasks related to user interaction events, such as UI (user interface) threads, Render threads, GL threads, user input event distribution threads, user input event detection threads, etc. Whether these threads can run smoothly determines whether user-perceivable lag will occur in the interaction interface between the user and the process.

[0042] Among them, the first type of threads are generally application-level threads, which can be determined by analyzing actual jamming scenarios. For example, in a test, if an application jam occurs in a certain user interaction scenario, and the analysis of the scenario finds that the jam is caused by a thread processing tasks too slowly, then it can be considered that the thread is used to execute related tasks in the user interaction event, and the operation of the thread is closely related to the user experience, so the thread can be regarded as a first-type thread.

[0043] Since in the process of executing user interaction events, in addition to application-level threads, some system-level threads may also be involved to complete tasks, the system framework layer also needs to mark these system-level threads as first-class threads. Generally, these threads are created when the system starts. Therefore, when the system starts, these threads can be identified and marked, such as Surfaceflinger threads, system animation threads, etc. Alternatively, during the operation of the system, if it is detected that threads of new system processes are created and used to execute tasks related to user interaction events, the system framework layer will also mark these threads as first-class threads.

[0044] In addition, in one embodiment, there are some threads that do not directly execute tasks related to user interaction events, but the operation of these threads will also affect the operation of the first class of threads, and then indirectly affect the execution of tasks related to user interaction events. In other words, these threads are not always related to user experience, but these threads may be associated with the first class of threads through resource constraints during a certain period of time during the execution process. Therefore, in some embodiments, in order to further reduce the jamming phenomenon in the interactive scenario, the kernel layer also marks these threads with constraints between the first class of threads as first class threads. Once this constraint relationship ends, the thread will be restored to a non-first class thread. Among them, the specific constraint relationship includes but is not limited to inter-process communication, inter-thread communication, or holding critical resources. For example, ordinary threads requested by the first class of threads through inter-process communication, ordinary threads holding critical resources such as waiting semaphores, read-write semaphores, and mutexes required by the first class of threads, etc., in the embodiment of the present application, such threads are also marked as first class threads.

[0045] In 103, when there is a first-class thread in the target task linked list, a first-class thread with the longest waiting time is determined from the target task linked list as the first target thread.

[0046] All threads in the target task list have the same priority, that is, the first-class threads and the second-class threads in the target task list have the same priority. Among them, the first-class threads are closely related to the user experience. Whether the first-class threads can run smoothly determines whether there will be user-perceivable lag in user interaction events. Threads other than the first-class threads are recorded as second-class threads. The operation of the second-class threads generally does not affect the user experience, or has little impact on the user experience.

[0047] Therefore, in the embodiment of the present application, from the perspective of whether the running status of the thread will affect the user experience, when the target processor unit selects the thread to be executed, the target processor unit will give priority to scheduling the first-class threads that directly or indirectly affect the user experience. That is to say, when there are both first-class threads and second-class threads in the target task linked list, the target processor unit will give priority to scheduling the first-class threads, wherein when scheduling the first-class threads, the target processor unit will determine the first-class thread with the longest waiting time, that is, determine the first-class thread that is first mounted to the target task linked list, and as the first target thread, it will be scheduled first.

[0048] Among them, when the threads in the target task linked list are arranged in a first-in-first-out order, the closer the thread is to the head position of the target task linked list, the longer the waiting time is. Therefore, it is possible to detect whether the threads in the target task linked list are first-class threads in sequence starting from the head position of the target task linked list until the first-class thread is detected, thereby determining the first-class thread with the longest waiting time from the target task linked list and using it as the first target thread.

[0049] When the threads in the target task list are arranged in other ways, all the threads in the target task list can be traversed to obtain all the first-class threads in the target task list and the waiting time of each first-class thread, and then the waiting time of all the first-class threads is compared to determine the first-class thread with the longest waiting time and use it as the first target thread.

[0050] At 104, a first target thread is executed based on a target processor unit.

[0051] After the target processor unit determines the first type of thread with the longest waiting time from the target task linked list, it executes the first target thread.

[0052] The thread scheduling method provided in the embodiment of the present application is that when the target processor unit selects the thread to be executed, it searches the target task list with a non-zero number of threads and the highest priority in descending order of priority. If there is a first-class thread on the target task list, the target processor unit will give priority to the first-class thread. It can also be understood that although the first-class thread and the second-class thread in the target task list have the same priority, the resources of the target processor unit will be preferentially allocated to the first-class thread, so that the first-class thread that executes the task related to the user interaction event can be executed in time, shortening its waiting time, reducing the jamming phenomenon in the user interaction scenario, and improving the user experience.

[0053] See also Figure 2 , Figure 2 Another flowchart of the thread scheduling method provided in the embodiment of the present application may include:

[0054] In 201, a second target thread for executing a task related to a user interaction event is determined.

[0055] In the embodiment of the present application, the operating system of the electronic device may be a system based on the Linux kernel, such as an Android operating system. System processes and application processes are running on the electronic device. A thread is an execution path of a process and is the smallest unit of program execution. A process can have multiple threads, but at least one thread.

[0056] For the kernel, when scheduling resources, such as CPU scheduling, it is specific to a certain thread. There is a main thread in the process, and it will also create many sub-threads to assist in the work. For example, a process of a content interactive application will create a main thread to execute code, and during the execution, it will also create other sub-threads to assist in running the task code of each part.

[0057] Among them, whether the thread that executes the relevant tasks in the user interaction event can run smoothly determines whether a user-perceivable lag will occur in the user interaction event. Therefore, in the embodiment of the present application, the thread that executes the relevant tasks in the user interaction event is determined, and these threads that are closely related to the user experience are recorded as ux threads (user experience), that is, the second target thread.

[0058] In 202, a preset tag is added to the second target thread to mark the second target thread as a first-category thread.

[0059] Since whether the second target thread can run smoothly determines whether user-perceivable lag will occur in the user interaction event, in an embodiment of the present application, a second target thread that executes related tasks in the user interaction event is determined, and a preset label is added to the second target thread to mark the second target thread as a first-class thread.

[0060] Among them, the system architecture of the electronic device includes at least an application framework layer and a kernel layer. In an embodiment of the present application, ux threads are identified and marked from the perspective of the application framework layer and the kernel layer. For example, the application framework layer adds preset labels to some threads that directly execute related tasks in user interaction events to mark these threads as static ux threads, and the kernel layer marks some threads that indirectly affect the execution of related tasks in user interaction events as dynamic ux threads.

[0061] It can be understood that the preset tag can be a ux tag, which is added as follows: Linux uses the task_struct structure to describe and record threads, and each thread has a corresponding task_struct structure. The task_struct records the name, identifier, state, priority, memory pointer, context data and other attribute information of the thread. Therefore, the application framework layer can add a corresponding ux flag member to the task_struct structure to mark the UI thread, Render thread, GL thread and other threads of the foreground process that perform related tasks in the user interaction event with the ux flag bit, so that the kernel layer can identify the task attributes of the thread.

[0062] The processes in the embodiments of the present application include system-level processes and application-level processes. Since the scenarios that produce user-perceivable interface freezes are mostly relative to the process running in the foreground. Therefore, in the scheme of the embodiments of the present application, "determining a second target thread for executing related tasks in user interaction events" includes: when it is detected that a process switches to the foreground, determining the foreground process; identifying a first preset thread for executing related tasks in the user interaction event from the threads of the foreground process, and using the first preset thread as the second target thread.

[0063] In one embodiment, the first preset thread includes some threads created when the process is running and used to directly execute tasks related to user interaction events, such as UI (user interface) thread, Render thread, GL thread, user input event distribution thread, user input event detection thread, etc. Whether these threads can run smoothly determines whether user-perceivable lag will occur in the interaction interface between the user and the process.

[0064] For example, a user uses a chat software to chat with a friend. The user enters text in the dialog box, and the electronic device sends the text entered by the user to the friend's electronic device through the server. In this interaction event, the UI thread, Render thread, user input event distribution thread, user input event detection thread and other threads need to work together to complete this user interaction event. The operation of each thread requires the system to allocate resources for it. Therefore, when it is detected that the chat software is running in the foreground, these threads are identified, and these threads are used as the first preset threads and marked as ux threads.

[0065] The first preset thread is generally an application-level thread, which can be determined by analyzing actual jamming scenarios. For example, in a test, if an application jam occurs in a certain user interaction scenario, and the analysis of the scenario finds that the jam is caused by a thread processing tasks too slowly, then the thread can be considered to be used to execute related tasks in the user interaction event, and the operation of the thread is closely related to the user experience, so the thread can be used as the first preset thread.

[0066] Based on this, various possible jamming scenarios can be tested to record the threads that cause jamming. The electronic device stores the relevant information of the first preset threads, and when the process is switched to the foreground, all threads belonging to the pre-recorded first preset threads under the process are marked as ux threads.

[0067] It is understandable that, for the electronic device, the stored relevant information of the first preset thread is not unmodifiable, and when the system is upgraded, the relevant information of the first preset thread can be updated.

[0068] In one embodiment, after adding a preset tag to the second target thread, the method further includes: if the foreground process is an application process, then when it is detected that the foreground process switches to background operation, deleting the preset tag of the first preset thread. When the foreground process switches to background operation, the operation of the process is no longer related to the user experience, and the importance of its thread has also decreased. Therefore, the ux tag of the first preset thread corresponding to the process can be deleted, and these ux threads can be restored to ordinary threads.

[0069] In addition, in another embodiment, the method further includes: when it is detected that a second preset thread is created, using the created second preset thread as a second target thread, wherein the second preset thread is a system-level thread.

[0070] Since in the process of executing user interaction events, in addition to application-level threads, some system-level threads may be involved to complete tasks, the system framework layer also needs to mark these system-level threads as ux threads. Generally, these threads are created when the system starts, so when the system starts, these threads can be identified and marked, such as Surfaceflinger threads, system animation threads, etc. Alternatively, during the operation of the system, if it is detected that a new system process thread is created and used to perform related tasks in the user interaction event, the system framework layer also marks these threads as ux threads. For example, SystemUI threads. Among them, the second preset thread can also be determined by analyzing the actual jamming scene. For example, in the test, if an application jam occurs in a certain user interaction scene, and the jamming phenomenon is found to be caused by a system-level thread processing task too slowly through the analysis of the scene, it can be considered that the system-level thread is used to perform related tasks in the user interaction event, and the operation of the system-level thread is closely related to the user experience, and the system-level thread can be used as the second preset thread. The electronic device stores the relevant information of these second preset threads, and if it is detected that the system has created these threads, they are marked as ux threads.

[0071] For the second preset threads at the system level, even if the foreground and background switching of the process occurs, these threads are always related to the user experience, so they always retain the ux label.

[0072] In another embodiment, during the running of the foreground process, when it is detected that a new thread is created, it is determined whether the newly created thread is used to execute related tasks in the user interaction event; when the newly created thread is used to execute related tasks in the user interaction event, the newly created thread is marked as a ux thread.

[0073] When a foreground process is running, if a user interaction event occurs, in addition to the first preset thread at the application level and the second preset thread at the system level, there may be some temporarily created task threads. The operation of these task threads will also directly affect whether there will be user-perceivable lag in the user's interaction interface with the process. Therefore, the application framework layer will also mark these threads as ux threads to optimize the system's resource allocation to the threads.

[0074] Among them, the electronic device determines the user interaction event that occurs based on the detected user instruction. A user interaction event generally refers to a situation where after a user triggers a certain instruction, the electronic device needs to respond to the instruction immediately, perform some processing and display the processing result on the interface. For example, users use electronic devices to watch videos, edit text messages, use chat software, use game software, control the switching of electronic device interfaces, use browsing to browse web pages, etc., all of which are user interaction events. For example, a user uses chat software to chat with a friend, the user enters text in the dialog box, and the electronic device sends the text entered by the user to the friend's electronic device through the server. In this process, the electronic device needs to schedule multiple threads to complete this user interaction event. From the start to the completion of the user interaction event, the threads created by the process to complete this user interaction event can be considered as threads related to user experience.

[0075] The task thread temporarily created in the user interaction event will be destroyed after completing the corresponding task, and it will naturally lose the ux tag.

[0076] It should be noted that the above-mentioned ux threads are only examples and are not limited to them. As long as it is a thread that directly executes tasks related to user interaction events and its operation directly affects the user experience, it can be marked as a ux thread. For the application framework layer, when it is detected that the newly created thread is used to execute user interaction events, or when it is detected that some resident system-level threads are used to process user interaction events, these threads are added with ux tags to mark them as ux threads.

[0077] There are also some threads that do not directly execute tasks related to user interaction events, but the operation of these threads will also affect the operation of ux threads, and then indirectly affect the execution of tasks related to user interaction events. In other words, these threads are not always related to user experience, but these threads may be associated with ux threads through resource constraints during a certain period of time during the execution process. Therefore, in some embodiments, in order to further reduce the jamming phenomenon in the interactive scenario, the kernel layer also marks these threads with constraints between ux threads as ux threads. Once this constraint relationship ends, the thread will be restored to a non-ux thread. Among them, the specific constraint relationship includes but is not limited to inter-process communication, inter-thread communication, or holding critical resources. For example, ordinary threads requested by ux threads through inter-process communication, ordinary threads holding critical resources such as waiting semaphores, read-write semaphores, and mutexes required by ux threads, etc., in the embodiments of the present application, such threads are also marked as ux threads.

[0078] Based on this, in some embodiments, the method also includes: detecting the running state of the first type of thread; when it is detected that the first type of thread has entered a blocked state, determining an associated thread that has a constraint relationship with the first type of thread that has entered the blocked state; and adding a preset label to the associated thread to mark the associated thread as a first type of thread.

[0079] In some embodiments, after marking the associated thread as a first-category thread, the method further includes: when it is detected that the constraint relationship is released, deleting the preset label of the associated thread.

[0080] Among them, regarding the blocking state of a thread, it is generally divided into D state (Uninterruptable sleep state) and S state (interruptable sleep state) at the kernel level. For example, if a thread initiates an IO request but is not satisfied, it enters the D state; if a thread initiates a synchronous Binder request, it enters the S state. Threads generally enter these states because they need to actively or passively give up CPU resources due to some reasons or logic during the execution of the thread task.

[0081] In this embodiment, the kernel layer detects the state of the ux thread. When it is detected that the ux thread enters a blocked state, the kernel layer determines the associated threads that have a constraint relationship with the ux thread that enters the blocked state. If these associated threads are not allocated resources in time, such as IO resources, resulting in operation obstruction, the slow operation of the associated threads will cause the ux thread to be in a blocked state for a long time. Therefore, in order to avoid the ux thread being in a blocked state for a long time, the kernel layer will also mark the identified associated threads as ux threads to improve their IO processing efficiency and ensure their timely execution, thereby quickly releasing the blocked state of the ux thread.

[0082] In 203, multiple task linked lists of the target processor unit are traversed in order of priority from high to low, until a task linked list with a non-zero number of threads is obtained as the target task linked list.

[0083] The scheme of the embodiment of the present application is explained by taking the scheduling of RT threads as an example. RT threads adopt a priority-based scheduling strategy. Common scheduling strategies include FIFO (First In First Out), RR (Round Robin), etc. Regardless of the FIFO scheduling strategy or the RR scheduling strategy, when the thread priorities are different, they are scheduled in order from high to low according to the thread priorities, and the thread with the highest priority will be processed first. When the threads have the same priority, the FIFO scheduling strategy, the first thread to arrive will get the processor resources first, and will occupy the resources until the thread enters the sleep state. For the RR scheduler, threads with the same priority will share processor resources in a round-robin manner. When a thread starts running, if the thread will not be blocked, then the thread will run until the time slice allocated to the thread expires. When the time slice is used up, the thread will be placed at the end of the task list.

[0084] In addition, the embodiments of the present application can be applied to multi-core processors. The embodiments of the present application do not specifically limit the number of cores of the processor. If the processor of the electronic device is a multi-core processor, each processor core can be used as an independent processing unit. For example, if the electronic device is an eight-core processor, each core is an independent processing unit.

[0085] Each processor unit maintains a run queue. When a thread is ready to be executed, it will be mounted on the run queue of the corresponding target processor unit. The run queue maintains these threads to be executed through the structure of the task list. The run queue includes multiple task lists. Different task lists correspond to different priorities. Threads of the same priority are mounted on the same task list, and threads of different priorities are mounted on different task lists. Newly created threads will also be mounted on the task list of the corresponding priority according to their priority.

[0086] For the run queue of a processor unit, the threads in the run queue use the processor unit resources together. At each moment, only one thread is running, and the thread adopts a priority-based scheduling strategy. Therefore, when the target processor unit selects the thread to be executed, it will traverse the multiple task lists of the target processor unit in order from high to low priority until a task list with a non-zero number of threads is obtained as the target task list. In other words, the target processor unit searches for a task list with a non-zero number of threads in order from high to low priority of the task list, as the target task list. The target task list is the task list with the highest priority and a non-empty number of threads in all current task lists. Among them, when there are threads to be scheduled for execution in the run queue of a processor unit, the processor unit is used as the target processor unit, and the threads in its run queue are scheduled for execution according to the scheme proposed in the embodiment of the present application.

[0087] For example, there are currently five task lists of different priorities: Table 1, Table 2, Table 3, Table 4, Table 5, and the order of the priorities of the task lists from high to low is: Table 1, Table 2, Table 3, Table 4, Table 5. When the target processor selects the thread to be executed, it will start from Table 1 to determine whether the number of threads is not zero. If there are threads in Table 1, Table 1 will be used as the target task list, and Table 2, Table 3, Table 4, and Table 5 will not be searched further. That is, Table 1 is the task list with the current number of threads not being zero and the highest priority. If there are currently no threads in Table 1, Table 2 will be searched further. If there are currently threads in Table 2, Table 2 will be used as the target task list, and Table 3, Table 4, and Table 5 will not be searched further. That is, Table 2 is the task list with the current number of threads not being zero and the highest priority.

[0088] In 204, it is detected whether there is a first type thread in the target task linked list.

[0089] In the embodiment of the present application, when scheduling threads, the target processor unit first obtains a target task list whose current thread quantity is not zero and has the highest priority; then, detects whether there is a first-class thread in the target task list.

[0090] In the embodiment of the present application, a second target thread for executing a related task in a user interaction event has been determined, and a preset tag has been added to the second target thread to mark the second target thread as a first-class thread. Therefore, to detect whether there is a first-class thread in the target task linked list, it is possible to determine whether there is a first-class thread in the target task linked list by detecting whether each thread in the target task linked list has a preset tag, wherein the thread with the preset tag is determined as the first-class thread. If at least one thread in the target task linked list has a preset tag, there is a first-class thread in the target task linked list; if all threads in the target task linked list do not have a preset tag, there is no first-class thread in the target task linked list.

[0091] In 205, when there are first-class threads in the target task linked list, a first-class thread with the longest waiting time is determined from the target task linked list as the first target thread.

[0092] The threads in the target task list all have the same priority, that is, the first-class threads and the second-class threads in the target task list all have the same priority. The first-class threads are closely related to the user experience. Whether the first-class threads can run smoothly determines whether user-perceivable jams will occur in user interaction events. In the embodiment of the present application, threads other than the first-class threads are recorded as second-class threads. The operation of the second-class threads generally does not affect the user experience, or has little impact on the user experience.

[0093] Therefore, in the embodiment of the present application, from the perspective of whether the running status of the thread will affect the user experience, when the target processor unit selects the thread to be executed, the target processor unit will give priority to scheduling the first-class threads that directly or indirectly affect the user experience. That is, when there are both first-class threads and second-class threads in the target task linked list, the target processor unit will determine the first-class thread with the longest waiting time, that is, determine the first-class thread that is first mounted to the target task linked list, and it will be scheduled first as the first target thread.

[0094] Among them, when the threads in the target task linked list are arranged in a first-in-first-out order, the closer the thread is to the head position of the target task linked list, the longer the waiting time is. Therefore, it is possible to detect whether the threads in the target task linked list are first-class threads in sequence starting from the head position of the target task linked list until a first-class thread is detected, thereby determining the first-class thread with the longest waiting time from the target task linked list and using it as the first target thread.

[0095] When the threads in the target task list are arranged in other ways, all the threads in the target task list can be traversed to obtain all the first-class threads in the target task list and the waiting time of each first-class thread, and then the waiting time of all the first-class threads is compared to determine the first-class thread with the longest waiting time and use it as the first target thread.

[0096] In addition, in one embodiment, before determining the first-class thread with the longest waiting time from the target task list, the type information of each first-class thread in the target task list can also be obtained; and the arrangement order of multiple first-class threads on the target task list is adjusted according to the type information. For example, if there are UI (user interface) threads and Render threads with the same priority on the target task list, the UI thread and the Render thread both belong to the first-class threads, but have different type information. According to the system operation requirements, if the UI thread needs to be executed faster than the Render thread, so that the user is less likely to perceive the jam during the interaction process, then when the newly generated UI thread is mounted on the target task list, the arrangement order of the UI thread can be adjusted, for example, it can be inserted before the Render thread with the longest waiting time, so that the UI thread is closer to the header position of the target task list, or the waiting time of the UI thread can be adjusted to make the waiting time of the UI thread longer, so that it can be executed faster.

[0097] In 206, when there is no first-class thread in the target task linked list, a second-class thread with the longest waiting time is determined from the target task linked list as the first target thread, wherein threads other than the first-class thread in the target task linked list are used as second-class threads.

[0098] In the embodiment of the present application, threads other than the first type of threads are regarded as second type of threads. The running status of the second type of threads generally does not affect the user experience, or has little impact on the user experience.

[0099] If all threads in the target task linked list do not have a preset label, there are no first-category threads in the target task linked list, and there are only second-category threads in the target task linked list.

[0100] The threads in the target task list all have the same priority, that is, the first-class threads and the second-class threads in the target task list all have the same priority. Although the second-class threads have less impact on the user experience, the second-class threads in the target task list are also important threads with the highest current priority.

[0101] The target processor unit determines the second-class thread with the longest waiting time from the target task list based on the priority scheduling strategy, that is, determines the second-class thread first mounted to the target task list, and schedules it as the first target thread first.

[0102] When the threads in the target task linked list are arranged in a first-in-first-out order, the closer the thread is to the head position of the target task linked list, the longer the waiting time is. Therefore, it can be determined that the second type of thread at the head position of the target task linked list is the first target thread.

[0103] When the threads in the target task linked list are arranged in other ways, all the second-class threads in the target task linked list and the waiting time of each second-class thread can be traversed, and then the waiting time of all the second-class threads can be compared to determine the second-class thread with the longest waiting time and use it as the first target thread.

[0104] In 207, the first target thread is executed based on the target processor unit.

[0105] When there is a first-class thread closely related to the user experience in the target task linked list, the first-class thread with the longest waiting time is determined from the target task linked list as the first target thread; when there is no first-class thread in the target task linked list, but only second-class threads, the second-class thread with the longest waiting time is determined from the target task linked list as the first target thread.

[0106] The target processor unit determines a first target thread from the target task linked list, and executes the first target thread.

[0107] The thread scheduling method provided in the embodiment of the present application determines a second target thread for executing tasks related to user interaction events, and adds a preset label to the second target thread to mark the second target thread as a first-class thread. When the target processor unit selects the thread to be executed, it traverses the multiple task lists of the target processor unit in order from high to low priority until a target task list with a non-zero number of threads and the highest priority is obtained. By detecting whether each thread in the target task list has a preset label, it is determined whether there is a first-class thread in the target task list. In the embodiment of the present application, if there is a first-class thread on the target task list, the target processor unit will give priority to the first-class thread, so that the first-class thread that executes tasks related to the user interaction event can be executed in time, shortening its waiting time, thereby reducing the jamming phenomenon in the user interaction scenario and improving the user experience.

[0108] In addition, in one embodiment, before detecting whether there is a first-class thread in the target task list, it also includes: obtaining the waiting time of each second-class thread in the target task list; if the waiting time of at least one second-class thread exceeds the preset time, the second-class process with the longest waiting time is used as the first target process. The first-class threads and the second-class threads in the target task list have the same priority. Although the second-class threads have less impact on the user experience, the second-class threads in the target task list are also important threads with the highest current priority. If the second-class threads cannot be executed for a long time, it may also affect the performance or operation of the system. Therefore, the preset time can be set according to the specific system performance or system operation needs. If the waiting time of the second-class threads exceeds the preset time, the second-class threads with a waiting time exceeding the preset time can also be executed preferentially.

[0109] It should be noted that the "first category" and "second category" in the first category threads and the second category threads here are only to distinguish whether the threads have the ux label, rather than to divide the threads in the system into only these two categories.

[0110] See also Figure 3 , Figure 3 It is a scenario diagram of the thread scheduling method provided in an embodiment of the present application.

[0111] Whether the thread that executes the relevant tasks in the user interaction event can run smoothly determines whether the user-perceivable lag will occur in the user interaction event. Therefore, in the embodiment of the present application, the thread that executes the relevant tasks in the user interaction event is determined, and these threads that are closely related to the user experience are recorded as ux threads (user experience), that is, the second target thread. Please refer to the above embodiment for the specific second target thread, which will not be repeated here.

[0112] A preset tag is added to the second target thread to mark the second target thread as a first-class thread. Figure 3 As shown, for example, the first type of threads closely related to user experience are: A1, A2, A3.

[0113] In the embodiment of the present application, threads other than the first type of threads are regarded as second type of threads. The operation of the second type of threads generally does not affect the user experience, or has little impact on the user experience. Figure 3 As shown, for example, the second type of threads are: B1, B2, B3, B4, B5.

[0114] Each processor unit maintains a run queue. When a thread is ready to be executed, it will be mounted on the run queue of the corresponding target processor unit. The run queue maintains these threads to be executed through the structure of the task list. The run queue includes multiple task lists. Different task lists correspond to different priorities. Threads of the same priority are mounted on the same task list. Figure 3 As shown, for example, the running queue includes a first priority task list, a second priority task list and other task lists, among which the first priority task list has the highest priority.

[0115] When the target processor unit selects a thread to be executed, it traverses multiple task lists of the target processor unit in descending order of priority until it obtains a target task list with a non-zero number of threads and the highest priority. Figure 3 As shown, for example, if the first priority task list has the highest priority and the number of threads in the first priority task list is not zero, then the first priority task list is the target task list and no further searches are made for other task lists.

[0116] Detect whether there is a first-class thread in the target task linked list. Since the second target thread that executes the relevant task in the user interaction event has been determined in the embodiment of the present application, and a preset label is added to the second target thread to mark the second target thread as a first-class thread. Among them, the preset label can be a ux label. Therefore, to detect whether there is a first-class thread in the target task linked list, it can be determined whether there is a first-class thread in the target task linked list by detecting whether each thread in the target task linked list has a preset label. Among them, the thread with the preset label is determined as the first-class thread. If at least one thread in the target task linked list has a preset label, there is a first-class thread in the target task linked list; if all threads in the target task linked list do not have a preset label, there is no first-class thread in the target task linked list. Figure 3 As shown, for example, the first priority task list is the target task list, and threads A1 and A2 on the first priority task list have preset tags, so the first priority task list has first-class threads: A1 and A2.

[0117] When there is a first-class thread in the target task linked list, the first-class thread with the longest waiting time is determined from the target task linked list as the first target thread; when the threads in the target task linked list are arranged in first-in-first-out order, the thread closest to the head position of the target task linked list has a longer waiting time, so the first-class thread closest to the head position of the target task linked list is used as the first target thread. Figure 3As shown, for example, the first class thread A1 in the first priority task list is closest to the head of the target task list, that is, the first class thread with the longest waiting time, so the first class thread A1 is used as the first target thread.

[0118] It should be noted that, when there is no first-category thread in the target task linked list, a second-category thread with the longest waiting time is determined from the target task linked list as the first target thread.

[0119] Execute the first target thread based on the target processor unit. In the embodiment of the present application, if there is a first-class thread on the target task linked list, the target processor unit will give priority to processing the first-class thread, so that the first-class thread that executes the task related to the user interaction event can be executed in time, shortening its waiting time, thereby reducing the jamming phenomenon in the user interaction scenario and improving the user experience.

[0120] See also Figure 4 , Figure 4 The structural diagram of the thread scheduling device provided in the embodiment of the present application is shown in FIG. The thread scheduling device can be applied to electronic devices. The thread scheduling device 300 can include: an acquisition module 301 , a detection module 302 , a determination module 303 , and a processing module 304 .

[0121] The acquisition module 301 is used to: traverse multiple task linked lists of the target processor unit in order of priority from high to low, until a task linked list with a non-zero number of threads is obtained as the target task linked list;

[0122] The detection module 302 is used to: detect whether there is a first type of thread in the target task list, wherein the first type of thread is a thread that executes a task related to a user interaction event;

[0123] The determination module 303 is used to: when there is the first type of thread in the target task linked list, determine the first type of thread with the longest waiting time from the target task linked list as the first target thread;

[0124] The processing module 304 is configured to execute the first target thread based on the target processor unit.

[0125] In one implementation, after detecting whether there is a first-class thread in the target task linked list, the determination module 303 may be used to:

[0126] When there is no first-category thread in the target task linked list, a second-category thread with the longest waiting time is determined from the target task linked list as the first target thread, wherein threads other than the first-category thread are used as the second-category threads.

[0127] In one implementation, the detection module 302 may be used to:

[0128] It is detected whether each thread on the target task linked list has a preset tag to determine whether the target task linked list has the first type of thread, wherein the thread with the preset tag is determined as the first type of thread.

[0129] In one implementation, the detection module 302 may be used to:

[0130] Determine a second target thread for executing tasks related to the user interaction event;

[0131] The preset tag is added to the second target thread to mark the second target thread as the first type of thread.

[0132] In one implementation, the detection module 302 may be used to:

[0133] When it is detected that a process is switched to the foreground, the foreground process is determined;

[0134] A first preset thread for executing relevant tasks in the user interaction event is identified from the threads of the foreground process, and the first preset thread is used as the second target thread.

[0135] In one implementation, the detection module 302 may be used to:

[0136] When it is detected that a second preset thread is created, the created second preset thread is used as the second target thread, wherein the second preset thread is a system-level thread.

[0137] In one implementation, after marking the second target thread as a first-category thread, the detection module 302 may be used to:

[0138] Detecting the running status of the first type of threads;

[0139] When it is detected that the first-type thread enters a blocked state, determining an associated thread having a constraint relationship with the first-type thread entering the blocked state;

[0140] The preset tag is added to the associated thread to mark the associated thread as the first type of thread.

[0141] The application embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed on a computer, the computer executes the process in the thread scheduling method provided in this embodiment.

[0142] An embodiment of the present application also provides an electronic device, including a memory and a processor, wherein the processor is used to execute the process in the thread scheduling method provided in this embodiment by calling a computer program stored in the memory.

[0143] For example, the electronic device may be a mobile terminal such as a tablet computer or a smart phone. Figure 5 , Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0144] The electronic device 400 may include components such as a memory 402 and a processor 401. Those skilled in the art will appreciate that Figure 5 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0145] The memory 402 may be used to store applications and data. The applications stored in the memory 402 include executable codes. The applications may be composed of various functional modules. The processor 401 executes various functional applications and data processing by running the applications stored in the memory 402. The processor 401 is electrically connected to the memory 402.

[0146] The processor 401 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or executing applications stored in the memory 402 and calling data stored in the memory 402, thereby monitoring the electronic device as a whole.

[0147] In this embodiment, the processor 401 in the electronic device loads the executable code corresponding to the process of one or more application programs into the memory 402 according to the following instructions, and the processor 401 runs the application program stored in the memory 402, thereby executing:

[0148] Traversing multiple task linked lists of the target processor unit in descending order of priority until a task linked list with a non-zero number of threads is obtained as the target task linked list;

[0149] Detecting whether there is a first type of thread in the target task linked list, wherein the first type of thread is a thread that executes a task related to a user interaction event;

[0150] When there are threads of the first type in the target task linked list, determining the thread of the first type with the longest waiting time from the target task linked list as the first target thread;

[0151] The first target thread is executed based on the target processor unit.

[0152] See also Figure 6 , Figure 6 A second structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 400 further includes components such as a radio frequency circuit 403, a display screen 404, a control circuit 405, an input unit 406, an audio circuit 407, a sensor 408, and a power supply 409. The processor 401 is electrically connected to the radio frequency circuit 403, the display screen 404, the control circuit 405, the input unit 406, the audio circuit 407, the sensor 408, and the power supply 409, respectively.

[0153] The radio frequency circuit 403 is used to send and receive radio frequency signals to communicate with network devices or other electronic devices through wireless communication.

[0154] The display screen 404 may be used to display information input by a user or information provided to a user and various graphical user interfaces of the electronic device. These graphical user interfaces may be composed of images, texts, icons, videos and any combination thereof.

[0155] The control circuit 405 is electrically connected to the display screen 404 and is used to control the display screen 404 to display information.

[0156] The input unit 406 can be used to receive input numbers, character information or user feature information (such as fingerprints), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. The input unit 406 can include a fingerprint recognition module.

[0157] The audio circuit 407 can provide an audio interface between the user and the electronic device through a speaker and a microphone. The audio circuit 407 includes a microphone. The microphone is electrically connected to the processor 401. The microphone is used to receive voice information input by the user.

[0158] The sensor 408 is used to collect external environment information. The sensor 408 may include one or more sensors such as an environment brightness sensor, an acceleration sensor, and a gyroscope.

[0159] The power supply 409 is used to supply power to various components of the electronic device 400. In some embodiments, the power supply 409 may be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, power consumption, and other functions.

[0160] Although not shown in the figure, the electronic device 400 may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0161] In this embodiment, the processor 401 in the electronic device 400 will load the executable code corresponding to the process of one or more applications into the memory 402 according to the following instructions, and the processor 401 will run the application stored in the memory 402 to execute:

[0162] Traversing multiple task linked lists of the target processor unit in descending order of priority until a task linked list with a non-zero number of threads is obtained as the target task linked list;

[0163] Detecting whether there is a first type of thread in the target task linked list, wherein the first type of thread is a thread that executes a task related to a user interaction event;

[0164] When there are the first-category threads in the target task linked list, determining the first-category thread with the longest waiting time from the target task linked list as the first target thread;

[0165] The first target thread is executed based on the target processor unit.

[0166] In one embodiment, after detecting whether there is a first-class thread in the target task linked list, the processor 401 performs, when there is no first-class thread in the target task linked list, determining a second-class thread with the longest waiting time from the target task linked list as the first target thread, wherein threads other than the first-class thread are used as the second-class thread;

[0167] The first target thread is executed based on the target processor unit.

[0168] In one embodiment, in the detecting whether there is a first type of thread in the target task linked list, the processor 401 executes the detection whether each thread on the target task linked list has a preset label to determine whether there is a first type of thread in the target task linked list, wherein the thread with the preset label is determined as the first type of thread.

[0169] In one implementation, the processor 401 determines a second target thread for executing a task related to the user interaction event;

[0170] The preset tag is added to the second target thread to mark the second target thread as the first type of thread.

[0171] In one embodiment, in the second target thread determined to execute the relevant task in the user interaction event, the processor 401 determines the foreground process when detecting that a process switches to the foreground to run;

[0172] A first preset thread for executing relevant tasks in the user interaction event is identified from the threads of the foreground process, and the first preset thread is used as the second target thread.

[0173] In one embodiment, in the second target thread determined to execute related tasks in the user interaction event, the processor 401 executes, when it is detected that a second preset thread is created, using the created second preset thread as the second target thread, wherein the second preset thread is a system-level thread.

[0174] In one implementation, after marking the second target thread as a first-category thread, the processor 401 performs detection of the running state of the first-category thread;

[0175] When it is detected that the first-type thread enters a blocked state, determining an associated thread having a constraint relationship with the first-type thread entering the blocked state;

[0176] The preset tag is added to the associated thread to mark the associated thread as the first type of thread.

[0177] In the above embodiments, the description of each embodiment has its own emphasis. For the part that is not described in detail in a certain embodiment, please refer to the detailed description of the thread scheduling method above, which will not be repeated here.

[0178] The thread scheduling device provided in the embodiment of the present application belongs to the same concept as the thread scheduling method in the above embodiment. Any method provided in the thread scheduling method embodiment can be run on the thread scheduling device. The specific implementation process is detailed in the thread scheduling method embodiment and will not be repeated here.

[0179] It should be noted that, for the thread scheduling method described in the embodiment of the present application, ordinary technicians in this field can understand that all or part of the process of implementing the thread scheduling method described in the embodiment of the present application can be completed by controlling the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, such as stored in a memory, and executed by at least one processor, and the execution process may include the process of the embodiment of the thread scheduling method. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), etc.

[0180] For the thread scheduling device of the embodiment of the present application, each functional module can be integrated into a processing chip, or each module can exist physically separately, or two or more modules can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk.

[0181] The thread scheduling method, device, storage medium and electronic device provided in the embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A thread scheduling method, characterized in that: The method comprises: Traverse multiple task linked lists of the target processor unit in descending order of priority until a task linked list with a non-zero number of threads is obtained as the target task linked list, and threads of the same priority are mounted on the same task linked list; Obtaining the waiting time of each second-class thread in the target task linked list; if the waiting time of at least one of the second-class threads exceeds a preset time, taking the second-class process with the longest waiting time as the first target process; If the waiting time of the second-category thread does not exceed the preset time, then detecting whether there is a first-category thread in the target task linked list, wherein the first-category thread is a thread that executes a task related to the user interaction event, and the first-category thread includes an application-level first preset thread in the thread of the foreground process for executing a task related to the user interaction event, a system-level second preset thread for executing a task related to the user interaction event, and an associated thread that has a constraint relationship with the first-category thread; When there are threads of the first category in the target task chain list, obtaining type information of each thread of the first category, adjusting the arrangement order of multiple threads of the first category in the target task chain according to the type information, and determining the thread of the first category with the longest waiting time from the target task chain list as the first target thread; The first target thread is executed based on the target processor unit.

2. The thread scheduling method according to claim 1, characterized in that: After detecting whether there is a first-class thread in the target task linked list, the method further includes: When there is no first-class thread in the target task linked list, determining a second-class thread with the longest waiting time from the target task linked list as the first target thread, wherein threads other than the first-class thread are used as the second-class thread; The first target thread is executed based on the target processor unit.

3. The thread scheduling method according to claim 1 or 2, characterized in that: The detecting whether there is a first type of thread in the target task linked list comprises: It is detected whether each thread on the target task linked list has a preset tag to determine whether the target task linked list has the first type of thread, wherein the thread with the preset tag is determined as the first type of thread.

4. The thread scheduling method according to claim 3, characterized in that: Also includes: Determine a second target thread for executing tasks related to the user interaction event; The preset tag is added to the second target thread to mark the second target thread as the first type of thread.

5. The thread scheduling method according to claim 4, characterized in that: The step of determining a second target thread for executing a task related to the user interaction event includes: When it is detected that a process is switched to the foreground, the foreground process is determined; A first preset thread for executing relevant tasks in the user interaction event is identified from the threads of the foreground process, and the first preset thread is used as the second target thread.

6. The thread scheduling method according to claim 4, characterized in that: The step of determining a second target thread for executing a task related to the user interaction event further includes: When it is detected that a second preset thread is created, the created second preset thread is used as the second target thread, wherein the second preset thread is a system-level thread.

7. The thread scheduling method according to claim 4, characterized in that: After marking the second target thread as the first type of thread, the method further includes: Detecting the running status of the first type of threads; When it is detected that the first-type thread enters a blocked state, determining an associated thread having a constraint relationship with the first-type thread entering the blocked state; The preset tag is added to the associated thread to mark the associated thread as the first type of thread.

8. A thread scheduling device, characterized in that: The device comprises: An acquisition module is used to traverse multiple task lists of the target processor unit in order of priority from high to low, until a task list with a non-zero number of threads is obtained as the target task list, and threads of the same priority are mounted on the same task list; A detection module, used for obtaining the waiting time of each second-class thread in the target task linked list; if the waiting time of at least one second-class thread exceeds a preset time, the second-class process with the longest waiting time is used as the first target process; if the waiting time of the second-class threads does not exceed the preset time, then detecting whether there is a first-class thread in the target task linked list, the first-class thread is a thread that executes relevant tasks in a user interaction event, the first-class thread includes an application-level first preset thread in the thread of the foreground process for executing relevant tasks in the user interaction event, a system-level second preset thread for executing relevant tasks in the user interaction event, and an associated thread that has a constraint relationship with the first-class thread; a determination module, configured to obtain type information of each of the first-class threads when there are the first-class threads in the target task chain list, adjust the arrangement order of the plurality of the first-class threads on the target task chain according to the type information, and determine the first-class thread with the longest waiting time from the target task chain list as the first target thread; A processing module is configured to execute the first target thread based on the target processor unit.

9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 7.

10. An electronic device, comprising a memory and a processor, characterized in that: The processor is configured to execute the method according to any one of claims 1 to 7 by calling the computer program stored in the memory.