Thread scheduling method, device, storage medium and electronic device

By identifying and marking the threads that execute interactive events as preset types, optimizing their insertion position in the waiting queue, the system lag caused by critical resource competition in electronic devices is solved, and the efficiency and user experience of interactive events are improved.

CN111831413BActive Publication Date: 2024-12-03GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010627316.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-01
Publication Date
2024-12-03
Estimated Expiration
2040-07-01

AI Technical Summary

Technical Problem

Electronic devices are prone to system stuttering when running multiple applications, especially in user interaction scenarios. Traditional thread scheduling mechanisms are difficult to effectively manage the competition for critical resources, resulting in inefficiency of interactive events.

Method used

By identifying and marking threads related to executing interactive events as preset-type threads, different scheduling classes and waiting queue management methods are used to insert these threads into the position before the non-preset-type threads, thereby optimizing resource acquisition and shortening waiting time.

Benefits of technology

It improves the execution efficiency of interactive events, reduces the occurrence of system lags, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111831413B_ABST
    Figure CN111831413B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a thread scheduling method, device, storage medium and electronic device, wherein, when it is detected that the required resources of a thread are critical resources and the critical resources are held by other threads, the thread is used as the first target thread; if the first target thread belongs to a preset type of thread, the target scheduling class to which the first target thread belongs is determined; the target position is determined from the previous position of the non-preset type thread in the waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position, based on which, compared with the non-preset type of threads, the preset type of threads can obtain the required critical resources faster, shorten the waiting time of these threads, thereby speeding up the execution efficiency of interactive events and reducing the jamming phenomenon.
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 many applications in the foreground and background, which easily causes 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 system lag.

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

[0005] When it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, the thread is used as the first target thread, wherein the thread of the preset type is a thread that executes related tasks in the interactive event;

[0006] If the first target thread belongs to a preset type of thread, determining a target scheduling class to which the first target thread belongs, wherein the preset type of thread is a thread that executes a related task in an interactive event;

[0007] A target position is determined from previous positions of threads of a non-preset type in a waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position.

[0008] In a second aspect, an embodiment of the present application further provides a thread scheduling device, including:

[0009] A thread detection module, configured to use the thread as a first target thread when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, wherein the preset type of thread is a thread that executes related tasks in the interactive event;

[0010] a scheduling class determination module, configured to determine a target scheduling class to which the first target thread belongs if the first target thread belongs to a preset type of thread, wherein the preset type of thread is a thread that executes a related task in an interactive event;

[0011] The queue management module is used to determine a target position from the previous positions of threads of non-preset types in the waiting queue corresponding to the target scheduling class, and add the first target thread to the target position.

[0012] In a third aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is run on a computer, the computer executes a thread scheduling method provided in any embodiment of the present application.

[0013] In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a processor and a memory, wherein the memory has a computer program, and the processor executes a thread scheduling method provided in any embodiment of the present application by calling the computer program.

[0014] The technical solution provided by the embodiment of the present application is as follows: when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, the thread is used as the first target thread; if the first target thread belongs to a preset type of thread, the target scheduling class to which the first target thread belongs is determined; the target position is determined from the position before the non-preset type thread in the waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position; wherein the preset type of thread is a thread that executes related tasks in an interactive event, in this way, when the preset type of thread enters the waiting queue because the requested critical resource is held by other threads, the preset type of thread is inserted before the non-preset type of thread in the waiting queue, and when the critical resource is released, the preset type of thread can obtain the required critical resource faster than the non-preset type of thread, shortening the waiting time of these threads, thereby speeding up the execution efficiency of the interactive event and reducing the jamming phenomenon. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0016] Figure 1 A first flow chart of a thread scheduling method provided in an embodiment of the present application.

[0017] Figure 2 A schematic diagram of a waiting queue of a thread scheduling method provided in an embodiment of the present application.

[0018] Figure 3 A schematic diagram of the structure of a thread scheduling device provided in an embodiment of the present application.

[0019] Figure 4 A first structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0020] Figure 5A second structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0022] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0023] The embodiment of the present application provides a thread scheduling method, and the execution subject of the thread scheduling method can be a thread scheduling device provided in the embodiment of the present application, or an electronic device integrated with the thread scheduling device, wherein the thread scheduling device can be implemented in hardware or software. The electronic device can be a smart phone, a tablet computer, a PDA, a laptop computer, or a desktop computer.

[0024] See also Figure 1 , Figure 1 This is a schematic diagram of the first process of the thread scheduling method provided in the embodiment of the present application. The specific process of the thread scheduling method provided in the embodiment of the present application can be as follows:

[0025] In 101 , when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, the thread is taken as the first target thread.

[0026] In 102, if the first target thread belongs to a preset type of thread, the target scheduling class to which the first target thread belongs is determined, wherein the preset type of thread is a thread that executes related tasks in an interactive event.

[0027] The Android system is one of the most mainstream mobile operating systems for electronic devices such as smartphones and tablets. Its underlying implementation is Linux. Taking smartphones as an example, each thread running on a smartphone follows the lock competition rules of the Linux kernel. There are various shared resources in the system. In order to prevent the contention problems caused by concurrent access of threads to shared resources, the kernel provides various lock mechanisms, such as mutex locks, semaphores, read-write semaphores, etc., to protect critical sections.

[0028] Among them, critical resources are shared resources that are only allowed to be used by one thread at a time. The code section that accesses critical resources in each process is called a critical section. Only one thread is allowed to enter the critical section at a time. After entering, other threads are not allowed to enter until the thread releases the critical resource. The scheme in the embodiment of the present application can be applied to various lock mechanism schemes involving the protection of critical resources, and is not limited to the several listed above.

[0029] As the Android ecosystem continues to expand, the number of threads is increasing when the system is running, and the concurrent access and contention for shared resources are becoming more and more serious. The traditional Linux lock competition mechanism is prone to cause system freezes when scheduling threads.

[0030] This solution identifies and marks threads that affect the user interaction scene from a system perspective. For example, if some threads are used to perform tasks related to interactive events, the smoothness of these threads determines whether there will be lags in the user interaction scene. Therefore, these threads are closely related to the user experience, so these threads are marked as ux (user experience) threads, that is, threads of the preset type. Threads of non-preset types are non-ux threads.

[0031] When the ux thread requests critical resources, different methods are used to add the ux thread and non-ux thread to the waiting queue. Then, different scheduling methods are used to schedule the ux thread and non-ux thread, so that the ux thread can obtain the required critical resources faster and avoid jamming.

[0032] Among them, the method of identifying and marking ux threads is as follows:

[0033] Threads in the system are divided into system threads and application threads. Application threads refer to threads created by an application process that only affect the operation of the application, such as UI threads and Render threads created by an application process, while system threads refer to threads at the operating system level that serve the operation of the entire system, such as Surfaceflinger threads (layer synthesis threads) and SystemUI (system interface) threads. ux threads include some system threads and some application threads.

[0034] 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 framework layer and the kernel layer. For example, the application framework layer adds preset labels to some threads that directly execute related tasks in interactive events to mark these threads as ux threads.

[0035] For example, in one embodiment, the method further includes: determining a third target thread for executing related tasks in the interactive event, and marking the third target thread as a thread of a preset type.

[0036] For example, in one embodiment, "determining a third target thread for executing related tasks in the interactive event, and marking the third target thread as a preset type of thread" includes: when a process switched to the foreground is detected, determining the foreground process; identifying a first preset thread for executing related tasks in the interactive event from the threads of the foreground process, using the first preset thread as the third target thread, and adding a preset label to it to mark it as a thread of a preset type.

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

[0038] 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.

[0039] For example, the first preset thread includes some threads created when the process is running and used to directly execute tasks related to interactive events, such as UI (user interface) thread, Render thread, GL thread, user input event distribution thread, user input event detection thread, etc., where the GL thread is the rendering thread of OGL (Open Graphics Library). Whether these threads can run smoothly determines whether user-perceivable lag will occur in the interactive interface between the user and the process.

[0040] 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 interactive 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 interactive event. The operation of each thread requires the system to allocate resources for it. Therefore, when the chat software is detected to be running in the foreground, these threads are identified and marked as ux threads.

[0041] 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.

[0042] In another embodiment, "determining a third target thread for executing related tasks in the interactive event" also includes: when a created second preset thread is detected, using the created second preset thread as the third target thread, wherein the second preset thread is a system-level thread for executing related tasks in the interactive event.

[0043] Since in the process of executing interactive 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-class thread is created and used to perform related tasks in interactive events, 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 interactive 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.

[0044] Among them, 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 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 interactive event with the ux flag bit, so that the kernel layer can identify the task attributes of the thread. That is, the preset label can be uxflag.

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

[0046] In another embodiment, "identifying from the threads of the foreground process a first preset thread for executing related tasks in the interactive event as a third target thread" also includes: during the running of the foreground process, when a newly created thread is detected, determining whether the newly created thread is used to execute related tasks in the interactive event; when the newly created thread is used to execute related tasks in the interactive event, using the newly created thread as the third target thread.

[0047] When a foreground process is running, if an interactive event occurs, in addition to the first preset thread mentioned above, there may be some temporarily created task threads. The operation of these task threads will 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.

[0048] Among them, the electronic device determines the interactive event that occurs based on the detected user instruction. It should be noted that the interactive event in the embodiment of the present application can also be understood as a user interactive event, which generally refers to the situation that after the 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 belong to interactive 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 interactive event. From the start to the completion of the interactive event, the threads created by the process to complete this interactive event can be considered as threads related to the user experience.

[0049] In another embodiment, after adding a preset tag to the third target thread, the method further includes: if the foreground process is an application process, 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 is also reduced. 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.

[0050] In addition, for those task threads temporarily created in interactive events, they will be destroyed after completing the corresponding tasks, and they will naturally lose the ux tag. 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 tag.

[0051] Through the above method, some system threads can be dynamically set as ux threads according to the user interaction scenario.

[0052] In an embodiment of the present application, when it is detected that the required resources of a thread are critical resources and the critical resources are held by other threads, the thread is used as the first target thread for subsequent processing, and by detecting whether the thread has a preset label, for example, detecting the ux flag bit in the task_struct structure of the first target thread, it is determined whether the first target thread is a ux thread.

[0053] In 103, a target position is determined from the previous positions of threads of a non-preset type in the waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position.

[0054] If the first target thread is a ux thread, the scheduling class of the thread is first determined, and then the insertion position of the thread in the waiting queue is determined according to the scheduling class.

[0055] Among them, when the resource requested by the thread is a critical resource and the critical resource is held by other threads, the thread needs to be mounted in the waiting queue and wait for the thread holding the critical resource to release the critical resource. At the same time, the thread is at the head of the waiting queue (because there may be more than one thread waiting for the critical resource). Only then will the thread be scheduled for execution.

[0056] Generally speaking, threads in the kernel are divided into different scheduling classes. The scheduling classes are stored in the task_struct structure mentioned above. 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) and RT (RealTimescheduler) scheduling class threads (such as Surfaceflinger threads and some other core threads). Different scheduling classes have different priorities (the priority here refers to the overall priority of a scheduling class thread relative to another scheduling class thread). For example, the priority of the scheduling class is reflected in: when a multi-core CPU (central processing unit) 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. In other words, the priority of the RT scheduling class is higher than that of the CFS scheduling class. Of course, in the scheduling methods of each of these two scheduling classes, the priorities of the threads they process will be distinguished (the priority here refers to the priority of each thread within a scheduling class), such as RT priority and CFS priority.

[0057] Therefore, in the embodiment of the present application, the scheduling class of the first target thread is first determined, and then the insertion position of the thread in the waiting queue is determined according to the scheduling class.

[0058] Among them, according to the different scheduling classes, the entire waiting queue is divided into the waiting queue corresponding to the CFS scheduling class and the waiting queue corresponding to the RT scheduling class. Please refer to Figure 2 , Figure 2 A schematic diagram of a waiting queue in a thread scheduling method provided in an embodiment of the present application. The waiting queue corresponding to the CFS scheduling class is recorded as queue 1, and the waiting queue corresponding to the RT scheduling class is recorded as queue 2. Queue 1 and queue 2 together constitute the entire waiting queue.

[0059] For example, if the first target thread is a ux thread and a RT thread, the ux thread is added before the non-ux thread in queue 1; if the first target thread is a ux thread and a CFS thread, the ux thread is added before the non-ux thread in queue 2, that is, closer to the head of the queue.

[0060] For example, in one embodiment, if the first target thread is a ux thread and a CFS thread, the ux thread is added before the non-ux thread and after the ux thread in queue 2.

[0061] Alternatively, in another embodiment, the priority of the first target thread is determined; the threads in the waiting queue are traversed from the head of the waiting queue until a second target thread with a priority lower than that of the first target thread is accessed, wherein the second target thread belongs to a preset type of thread; the adjacent position before the second target thread is used as the target position; when the priorities of the preset type of threads in the waiting queue are all greater than the priority of the first target thread, the adjacent position after the preset type of thread with the lowest priority in the waiting queue is used as the target position. After determining the target position, the first target thread is added to the target position. For example, if the first target thread is a ux thread and a CFS thread, the CFS priority of the first target thread is first determined, and the thread is added to the non-ux thread in queue 2 according to the CFS priority, that is, the position of the first target thread in multiple ux threads of queue 2 is determined according to the CFS priority of the first target thread, so that the ux threads in the waiting queue are arranged in descending order according to the CFS priority from the head of the queue. After being sorted in this way, the ux threads in queue 2 are also sorted according to their CFS priorities, which can ensure that those threads that are both ux threads and have higher CFS priorities can be scheduled preferentially.

[0062] Wherein, in one embodiment, after taking the thread as the first target thread, the method further comprises: if the first target thread does not belong to the preset type of thread, adding the first target thread to the waiting queue according to the priority of the first target thread.

[0063] If the first target thread does not belong to the ux thread, it is added to the non-ux position of the waiting queue of the corresponding scheduling class only according to the priority of the thread. For example, according to the priority of the first target thread, the first target thread is added to the waiting queue, including: determining the priority of the first target thread; traversing the threads in the waiting queue from the tail of the waiting queue until accessing the fourth target thread whose priority is greater than the priority of the first target thread, wherein the fourth target thread does not belong to the preset type of thread; adding the first target thread to the adjacent position after the fourth target thread; when the priorities of the non-preset type threads in the waiting queue are all less than the priority of the first target thread, the first target thread is added to the adjacent position before the non-preset type thread with the highest priority in the waiting queue. For example, if the first target thread is a CFS thread but not a ux thread, its target position in the CFS thread part in queue 2 is determined according to the CFS priority of the thread, such as traversing from the tail of queue 2 until accessing a thread whose CFS priority is greater than the CFS priority of the first target thread, as the second target thread, and adding the first target thread to the adjacent position after the second target thread.

[0064] like Figure 2As shown, when the thread in the kernel enters the slow path and is placed in the waiting queue because it cannot obtain critical section resources, after managing the position of the first target thread in the waiting queue according to the above scheme, the RT class ux thread is inserted in front of the RT class non-Ux thread, the CFS class ux thread is inserted in front of the CFS class non-ux thread, and the non-ux threads continue to be sorted from high to low according to their priority. The threads in the waiting queue are finally arranged in the following order: RT class ux thread, RT class non-Ux thread, CFS class ux thread, CFS class non-ux thread. In this way, while ensuring that the ux thread obtains the priority of shared resources, it can also ensure that the thread with higher priority obtains the priority of shared resources.

[0065] In the above embodiment, the waiting queue composed of CFS scheduling class threads and RT scheduling class threads is used as an example for description. If there are other scheduling classes in the system, the waiting queue is managed according to the priority of the scheduling class according to the same principle, which will not be described one by one here.

[0066] In one embodiment, in order to further shorten the waiting time of the ux thread, after 103, the method further includes: marking the thread holding the critical resource as a thread of a preset type.

[0067] Since the length of time that the thread holding the critical resource required by the first target thread holds the critical resource affects the length of time the first target thread waits, if other resources required by the thread holding the critical resource required by the first target thread are also critical resources and the critical resource is held by another thread, the thread holding the critical resource required by the first target thread also needs to wait in the waiting queue. In addition, multiple threads may form a waiting chain due to the above-mentioned relationship of holding critical resources. For example, thread A waits in the waiting queue because the critical resource it needs is held by thread B, thread B waits in the waiting queue because the critical resource it needs is held by thread C, and even thread C may also wait in the waiting queue because the critical resource it needs is held by thread D.

[0068] Therefore, in this embodiment, the thread holding the critical resources required by the first target thread is also marked as a ux thread. In this way, thread D, thread C, and thread B in the above example will all be marked as ux threads, so that they also have the priority of lock competition, which speeds up the scheduling of thread D, thread C, and thread B, and further speeds up the process of the overall ux thread recovering from a blocked state to a running state.

[0069] Through the above solution, the core thread that affects the user experience is marked as a ux thread. When the thread enters the slow path waiting due to failure to obtain resources, the ux thread is placed at the head of the waiting queue to increase the priority of the ux thread in obtaining the lock. When multiple threads compete for public resources, it can ensure that the ux thread obtains resources as soon as the lock is released, avoiding the core thread that affects the user experience from being blocked for a long time, thereby effectively avoiding such system freezes caused by waiting for a long time for the lock.

[0070] In specific implementation, the present application is not limited by the execution order of the various steps described. If no conflict occurs, some steps can be performed in other orders or simultaneously.

[0071] As can be seen from the above, the thread scheduling method provided in the embodiment of the present application uses the thread as the first target thread when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads; if the first target thread belongs to a preset type of thread, the target scheduling class to which the first target thread belongs is determined; the target position is determined from the position before the non-preset type thread in the waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position; wherein the preset type of thread is a thread that executes related tasks in an interactive event. In this way, when the preset type of thread enters the waiting queue because the requested critical resource is held by other threads, the preset type of thread is inserted before the non-preset type of thread in the waiting queue. When the critical resource is released, the preset type of thread can obtain the required critical resource faster than the non-preset type of thread, shortening the waiting time of these threads, thereby speeding up the execution efficiency of the interactive event and reducing the jamming phenomenon.

[0072] In one embodiment, a thread scheduling device is also provided. Figure 3 , Figure 3 The structural diagram of the thread scheduling device 300 provided in the embodiment of the present application is as follows: The thread scheduling device 300 is applied to an electronic device, and the thread scheduling device 300 includes a thread detection module 301, a scheduling class determination module 302, and a queue management module 303, as follows:

[0073] The thread detection module 301 is used to use the thread as the first target thread when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads;

[0074] A scheduling class determination module 302 is used to determine a target scheduling class to which the first target thread belongs if the first target thread belongs to a preset type of thread, wherein the preset type of thread is a thread that executes a related task in an interactive event;

[0075] The queue management module 303 is used to determine a target position from the previous positions of threads of non-preset types in the waiting queue corresponding to the target scheduling class, and add the first target thread to the target position.

[0076] In some embodiments, the queue management module 303 is further configured to add the first target thread to the waiting queue according to the priority of the first target thread if the first target thread does not belong to the preset type of thread.

[0077] In some embodiments, the queue management module 303 is also used to

[0078] Determining the priority of the first target thread;

[0079] Traversing the threads in the waiting queue from the head of the waiting queue until a second target thread having a priority lower than that of the first target thread is accessed, wherein the second target thread belongs to the preset type of thread;

[0080] Using the adjacent position before the second target thread as the target position;

[0081] When the priorities of the threads of the preset type in the waiting queue are all greater than the priority of the first target thread, the adjacent position after the thread of the preset type with the lowest priority in the waiting queue is used as the target position.

[0082] In some embodiments, the thread scheduling device further includes a thread marking module, and the thread marking module is used to mark the thread holding the critical resource as a thread of the preset type.

[0083] In some embodiments, the queue management module 303 is further used to determine the target position of the target thread before the threads of the non-preset type in the waiting queue according to the priority of the target thread;

[0084] The target thread is added to the target position.

[0085] In some embodiments, the thread marking module is further used to determine a third target thread for executing related tasks in the interactive event, and mark the third target thread as a thread of a preset type.

[0086] In some embodiments, the thread marking module is further used to determine the foreground process when detecting a process switched to the foreground running;

[0087] A first preset thread for executing relevant tasks in an interactive event is identified from threads of the foreground process, and a preset label is added to the first preset thread to mark the thread as a thread of a preset type.

[0088] In some embodiments, the thread marking module is further used to use the created second preset thread as the third target thread when a created second preset thread is detected, wherein the second preset thread is a system-level thread that executes related tasks in the interactive event.

[0089] It should be noted that 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 implemented through the thread scheduling device. The specific implementation process is detailed in the thread scheduling method embodiment, which will not be repeated here.

[0090] As can be seen from the above, the thread scheduling device proposed in the embodiment of the present application, when it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, uses the thread as the first target thread; if the first target thread belongs to a preset type of thread, the target scheduling class to which the first target thread belongs is determined; the target position is determined from the position before the non-preset type thread in the waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position; wherein the preset type of thread is a thread that executes related tasks in an interactive event. In this way, when the preset type of thread enters the waiting queue because the requested critical resource is held by other threads, the preset type of thread is inserted before the non-preset type of thread in the waiting queue. When the critical resource is released, the preset type of thread can obtain the required critical resource faster than the non-preset type of thread, shortening the waiting time of these threads, thereby speeding up the execution efficiency of the interactive event and reducing the jamming phenomenon.

[0091] The present application also provides an electronic device. The electronic device may be a smart phone, a tablet computer, or other device. Figure 4 , Figure 4 The first structural diagram of the electronic device provided in the embodiment of the present application is as follows: The electronic device 400 includes a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.

[0092] The processor 401 is the control center of the electronic device 400. 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 calling computer programs stored in the memory 402, and calling data stored in the memory 402, thereby monitoring the electronic device as a whole.

[0093] The memory 402 may be used to store computer programs and data. The computer programs stored in the memory 402 include instructions that can be executed in the processor. The computer programs may constitute various functional modules. The processor 401 executes various functional applications and data processing by calling the computer programs stored in the memory 402.

[0094] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:

[0095] When it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, taking the thread as the first target thread;

[0096] If the first target thread belongs to a preset type of thread, determining a target scheduling class to which the first target thread belongs, wherein the preset type of thread is a thread that executes a related task in an interactive event;

[0097] A target position is determined from previous positions of threads of a non-preset type in a waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position.

[0098] In some embodiments, see Figure 5 , Figure 5 A second structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 400 further includes: 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.

[0099] 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.

[0100] 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.

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

[0102] 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.

[0103] 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.

[0104] 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.

[0105] 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.

[0106] 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.

[0107] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:

[0108] When it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, taking the thread as the first target thread;

[0109] If the first target thread belongs to a preset type of thread, determining a target scheduling class to which the first target thread belongs, wherein the preset type of thread is a thread that executes a related task in an interactive event;

[0110] A target position is determined from previous positions of threads of a non-preset type in a waiting queue corresponding to the target scheduling class, and the first target thread is added to the target position.

[0111] As can be seen from the above, an embodiment of the present application provides an electronic device, which, when detecting that a required resource of a thread is a critical resource and the critical resource is held by other threads, uses the thread as a first target thread; if the first target thread belongs to a preset type of thread, determines the target scheduling class to which the first target thread belongs; determines the target position from the position before the non-preset type thread in the waiting queue corresponding to the target scheduling class, and adds the first target thread to the target position; wherein the preset type of thread is a thread that executes related tasks in an interactive event, in this way, when the preset type of thread enters the waiting queue because the requested critical resource is held by other threads, the preset type of thread is inserted before the non-preset type of thread in the waiting queue, and when the critical resource is released, the preset type of thread can obtain the required critical resource faster than the non-preset type of thread, shortens the waiting time of these threads, thereby speeding up the execution efficiency of the interactive event and reducing the jamming phenomenon.

[0112] An embodiment of the present application further provides a storage medium, in which a computer program is stored. When the computer program runs on a computer, the computer executes the thread scheduling method described in any of the above embodiments.

[0113] It should be noted that, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the storage medium can include but is not limited to: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0114] In addition, the terms "first", "second", and "third" in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments also include steps or modules that are not listed, or some embodiments also include other steps or modules inherent to these processes, methods, products, or devices.

[0115] The thread scheduling method, device, storage medium and electronic device provided in the embodiments of the present application are described in detail above. Specific examples are used herein 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 and core idea of ​​the present application. At the same time, for those skilled in the art, 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 limiting the present application.

Claims

1. A thread scheduling method, characterized in that: include: When it is detected that the required resource of the thread is a critical resource and the critical resource is held by other threads, taking the thread as the first target thread; Detecting whether the task_struct structure of the first target thread has a preset tag; If yes, determining that the first target thread belongs to a thread of a preset type; If not, determining that the first target thread does not belong to the preset type of thread; If the first target thread belongs to a preset type of thread, determining a target scheduling class to which the first target thread belongs, wherein the preset type of thread is a thread that executes a related task in an interactive event; Determining the priority of the first target thread; Traversing the threads in the waiting queue from the head of the waiting queue corresponding to the target scheduling class until a second target thread having a priority lower than that of the first target thread is accessed, wherein the second target thread belongs to a thread of the preset type, and different scheduling classes correspond to different waiting queues; Using the adjacent position before the second target thread as the target position; When the priorities of the threads of the preset type in the waiting queue are all greater than the priority of the first target thread, the adjacent position after the thread of the preset type with the lowest priority in the waiting queue is used as the target position; Adding the first target thread to the target position, and waiting for the other threads to release the critical resources; If the first target thread does not belong to the preset type of thread, determine the priority of the first target thread, and traverse the threads in the waiting queue from the end of the waiting queue corresponding to the target scheduling class until a fourth target thread having a priority greater than the priority of the first target thread is accessed, wherein the fourth target thread does not belong to the preset type of thread; Adding the first target thread to an adjacent position after the fourth target thread; When the priorities of the non-preset type threads in the waiting queue are all lower than the priority of the first target thread, the first target thread is added to an adjacent position before the non-preset type thread with the highest priority in the waiting queue.

2. The thread scheduling method according to claim 1, characterized in that: After adding the first target thread to the target position, the method further includes: The thread holding the critical resource is marked as a thread of the preset type.

3. The thread scheduling method according to any one of claims 1 to 2, characterized in that: The method further comprises: A third target thread for executing related tasks in the interactive event is determined, and the third target thread is marked as a thread of a preset type.

4. The thread scheduling method according to claim 3, characterized in that: The step of determining a third target thread for executing a related task in the interactive event includes: When a process running in the foreground is detected, the foreground process is determined; A first preset thread for executing related tasks in the interactive event is identified from the threads of the foreground process, and the identified first preset thread is used as the third target thread.

5. The thread scheduling method according to claim 3, characterized in that: The step of determining a third target thread for executing a task related to the interactive event further includes: When a created second preset thread is detected, the created second preset thread is used as a third target thread, wherein the second preset thread is a system-level thread that executes related tasks in the interactive event.

6. A thread scheduling device, characterized in that: include: A thread detection module, configured to use the thread as a first target thread when it is detected that a required resource of the thread is a critical resource and the critical resource is held by other threads; Detecting whether the task_struct structure of the first target thread has a preset tag; if so, determining that the first target thread belongs to a thread of a preset type; if not, determining that the first target thread does not belong to a thread of the preset type; a scheduling class determination module, configured to determine a target scheduling class to which the first target thread belongs if the first target thread belongs to a preset type of thread, wherein the preset type of thread is a thread that executes a related task in an interactive event; A queue management module, used to determine the priority of the first target thread; traverse the threads in the waiting queue from the head of the waiting queue corresponding to the target scheduling class until a second target thread with a priority lower than that of the first target thread is accessed, wherein the second target thread belongs to the preset type of thread, and the waiting queues corresponding to different scheduling classes are different; take the adjacent position before the second target thread as the target position; when the priorities of the preset type of threads in the waiting queue are all greater than the priority of the first target thread, take the adjacent position after the preset type of thread with the lowest priority in the waiting queue as the target position; add the first target thread to the target position, and wait for the other other threads release the critical resource; if the first target thread does not belong to the preset type of thread, determine the priority of the first target thread, traverse the threads in the waiting queue from the end of the waiting queue corresponding to the target scheduling class, until accessing a fourth target thread whose priority is greater than the priority of the first target thread, wherein the fourth target thread does not belong to the preset type of thread; add the first target thread to the adjacent position after the fourth target thread; when the priorities of the non-preset type threads in the waiting queue are all less than the priority of the first target thread, add the first target thread to the adjacent position before the highest priority non-preset type thread in the waiting queue.

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

8. An electronic device comprising a processor and a memory, wherein the memory stores a computer program, characterized in that: The processor is used to execute the thread scheduling method according to any one of claims 1 to 5 by calling the computer program.