Thread management method, readable medium, electronic device and program product
By lowering the priority of high-priority threads, the thread blocking problem caused by limited processor resources is solved, ensuring the normal operation of electronic devices and user interaction experience, and avoiding improper resource allocation due to inaccurate developer marking.
Patent Information
- Application Number
- CN202410695891.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2025-09-19
AI Technical Summary
Due to the limited processor hardware resources of electronic devices, when multiple applications are running at the same time, too many high-priority threads will cause thread blocking, affecting device performance and user interaction experience.
By detecting high-priority threads that meet specific conditions, their priority is reduced from real-time priority to non-real-time priority, avoiding long-term processor resource occupation and allocating resources to other threads.
It effectively avoids thread blocking, ensures the normal operation of the device and user interaction experience, and avoids improper thread resource allocation caused by developers' inaccurate marking of QoS levels.
Smart Images

Figure CN120670100A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to a thread management method, a readable medium, an electronic device, and a program product. Background Art
[0002] When implementing various functions (such as image display and audio playback), applications on electronic devices need to execute tasks corresponding to these functions. During the application's operation, the application typically creates threads for executing these tasks, and each thread executes the corresponding task.
[0003] Since the hardware resources corresponding to the processor of an electronic device are limited, if the electronic device runs many applications at the same time, the processor (central processing unit, CPU) usually cannot execute the threads corresponding to all the tasks to be executed at the same time. Therefore, after each thread is created, the operating system of the electronic device or the developer of the application corresponding to each thread usually marks the priority of the thread. Among them, the higher the priority, the higher the demand of the thread for the hardware resources corresponding to the processor, for example, faster acquisition of processor resources, more processor time, higher processor frequency, etc. When performing thread scheduling, the electronic device will give priority to ensuring the resource supply of high-priority threads, such as allowing high-priority threads to run continuously.
[0004] However, if there are too many high-priority threads, for example, if developers of various applications mark too many high-priority threads, the electronic device may continue to run some threads marked as high-priority, causing other high-priority threads to be unable to run, resulting in thread blocking and affecting the operation of the electronic device application. Summary of the Invention
[0005] The purpose of this application is to provide a thread management method, a readable medium, an electronic device and a program product.
[0006] The first aspect of the present application provides a thread management method, which is applied to an electronic device, including: obtaining multiple first threads with a first priority that are currently running; selecting a target thread whose running time meets the first priority control condition from the multiple first threads; and downgrading the priority of the target thread from the first priority to the second priority.
[0007] In an embodiment of the present application, the first priority may be a real-time priority, the first thread may be a thread with a priority type of real-time priority, the first priority control condition may be a priority control condition, and the second priority may be a non-real-time priority.
[0008] It can be understood that the electronic device determines the target thread that meets the priority management conditions from the threads with real-time priority type, and reduces the priority type of the target thread from real-time priority to non-real-time priority. This can avoid some threads with real-time priority type from running continuously for a long time, causing other threads to be unable to run and causing thread blocking.
[0009] In a possible implementation of the first aspect above, the first priority control condition includes at least one of the following: the continuous running time of the first thread is greater than the first time threshold; the continuous running time of the first thread in the first scheduling cycle is greater than the first time threshold; there is a thread in the thread group where the first thread is located whose continuous running time is greater than the first time threshold; there is a thread in the thread group where the first thread is located whose continuous running time in the first scheduling cycle is greater than the first time threshold; the sum of the running times of each thread in the thread group where the first thread is located in the first scheduling cycle is greater than the first time threshold.
[0010] In a possible implementation of the first aspect above, the method further includes: detecting that the target thread meets the running control condition, and suspending the target thread that meets the running control condition.
[0011] In an embodiment of the present application, when the electronic device detects that the target thread meets the operation control conditions, it suspends the target thread, which can prevent some threads with real-time priority type from occupying the processor's hardware resources for a long time, resulting in the inability to allocate processor hardware resources to other threads, causing thread blocking.
[0012] In a possible implementation of the first aspect above, the operation control conditions include at least one of the following: the continuous running time of the target thread is greater than the second time threshold; the continuous running time of the target thread within the first scheduling cycle is greater than the second time threshold; there is a thread in the thread group where the target thread is located whose continuous running time is greater than the second time threshold; there is a thread in the thread group where the target thread is located whose continuous running time within the first scheduling cycle is greater than the second time threshold; the sum of the running times of each thread in the thread group where the target thread is located within the first scheduling cycle is greater than the second time threshold, wherein the second time threshold is greater than the first time threshold.
[0013] In a possible implementation of the first aspect above, the method further includes: detecting that the target thread satisfies a first control cancellation condition, and canceling the control of the target thread, wherein canceling the control of the target thread includes at least one of the following: corresponding to the target thread whose priority is reduced to the second priority, restoring the target thread to the first priority; corresponding to the suspended target thread, resuming the operation of the suspended target thread.
[0014] In an embodiment of the present application, the first control cancellation condition may be a control cancellation condition. When the electronic device detects that the control cancellation condition is met, it may cancel the control of the target thread, thereby avoiding excessive control of a thread with a real-time priority type, such as downgrading or suspending it, thereby avoiding affecting the operation of the controlled thread.
[0015] In one possible implementation of the first aspect above, the first cancellation control condition includes at least one of the following: the duration of lowering the priority of the target thread is greater than the first duration; the duration of suspending the target thread is greater than the second duration; the first scheduling cycle ends.
[0016] In one possible implementation of the first aspect above, the multiple first threads with a first priority include at least one of the following: threads running on the electronic device, threads whose quality of service (QoS) level is greater than or equal to a preset level; threads running on the electronic device, threads whose corresponding execution task type is a user interaction task.
[0017] In the embodiment of the present application, the thread corresponding to the task type executed is a user interaction task can be a key thread.
[0018] In some embodiments, by identifying user interaction operations, a thread (critical thread) is determined to be a user interaction task. Based on the critical threads, threads with a priority type of real-time priority based on QoS information mapping are screened and supplemented to obtain threads with a priority type of real-time priority after screening. This can avoid the problem that threads greater than or equal to a preset level are marked with a QoS level less than the preset level due to inaccurate marking by developers, and are then mapped to non-real-time priority, thereby avoiding affecting the user interaction experience.
[0019] In a possible implementation of the first aspect above, the multiple first threads with a first priority also include at least one of the following: among the threads running by the electronic device, among the threads whose QoS level is greater than or equal to the preset level, other threads except the preset exempted threads; among the threads running by the electronic device, among the threads whose corresponding execution type is a user interaction task, other threads except the preset exempted threads.
[0020] In a possible implementation of the first aspect above, the method also includes: detecting that a preset exempt thread running in the electronic device meets a second priority control condition, downgrading the priority of the preset exempt thread from the first priority to the second priority, wherein the second priority control condition includes at least one of the following: the continuous running time of the exempt thread is greater than a third time threshold; the continuous running time of the exempt thread in the second scheduling period is greater than the third time threshold; there is a thread in the thread group where the exempt thread is located whose continuous running time is greater than the third time threshold; there is a thread in the thread group where the exempt thread is located whose continuous running time in the second scheduling period is greater than the third time threshold; the sum of the running times of each thread in the thread group where the exempt thread is located in the second scheduling period is greater than the third time threshold.
[0021] In an embodiment of the present application, the preset exemption thread may be an exemption thread, and the second priority control condition may be an exemption priority control condition. For example, the electronic device detects that the exemption thread meets the exemption priority control condition and reduces the priority of the exemption thread from the real-time priority to the non-real-time priority.
[0022] It is understandable that since the exempted thread is highly correlated with user interaction, suspending the execution of the exempted thread may affect device performance and user experience, such as the occurrence of freezes when refreshing the interface. Therefore, if the continuous running time of the exempted thread is greater than the second time threshold, lowering the priority type of the exempted thread to a non-real-time priority can ensure the normal operation of the exempted thread. Alternatively, if the continuous running time of the exempted thread is greater than the second time threshold, lowering the priority of the threads in the thread group where the exempted thread is located can ensure the normal operation of each thread in the thread group where the exempted thread is located.
[0023] In a possible implementation of the first aspect above, the method further includes: corresponding to the preset exemption thread whose priority is reduced to the second priority meeting the second cancellation control condition, the priority of the preset exemption thread is restored to the first priority, wherein the second cancellation control condition includes at least one of the following: the duration of reducing the priority of the exemption thread is greater than the third duration; the second scheduling cycle ends.
[0024] A second aspect of the present application provides a readable medium having instructions stored thereon, which, when executed on an electronic device, causes the electronic device to execute any one of the methods described in the first aspect.
[0025] The third aspect of the present application provides an electronic device, comprising a memory for storing instructions executed by one or more processors of the electronic device, and a processor, which is one of the processors of the electronic device, for executing any one of the methods in the above-mentioned first aspect.
[0026] A fourth aspect of the present application provides a program product, which includes instructions. When the instructions are executed on an electronic device, the electronic device implements any one of the methods in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0028] Figure 1a According to an embodiment of the present application, a schematic diagram of an application scenario of a thread management method is shown;
[0029] Figure 1b A schematic diagram of a scheduling process is shown according to an embodiment of the present application;
[0030] Figure 2 According to an embodiment of the present application, a flowchart of a thread management method is shown;
[0031] Figure 3 According to an embodiment of the present application, a flow chart of a periodic thread management method is shown;
[0032] Figure 4 According to an embodiment of the present application, a flow chart of another periodic thread management method is shown;
[0033] Figure 5 A schematic diagram of thread management is shown according to an embodiment of the present application;
[0034] Figure 6 According to an embodiment of the present application, a schematic diagram of an implementation process of determining a thread with a real-time priority type is shown;
[0035] Figure 7 According to an embodiment of the present application, a schematic diagram of the running states of thread A and thread B of a first thread group is shown;
[0036] Figure 8 According to an embodiment of the present application, a schematic block diagram of a software system architecture of an electronic device 100 is shown;
[0037] Figure 9 According to an embodiment of the present application, a schematic diagram of module interaction of a software system of an electronic device 100 is shown;
[0038] Figure 10 According to an embodiment of the present application, a flowchart of another thread management method is shown;
[0039] Figure 11 A schematic structural diagram of an electronic device 100 is shown according to an embodiment of the present application. DETAILED DESCRIPTION
[0040] Illustrative embodiments of the present application include, but are not limited to, a thread management method, a readable medium, an electronic device, and a program product.
[0041] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and comprehensively described below with reference to the accompanying drawings.
[0042] The thread management method provided in the embodiment of the present application can be applied to a variety of electronic devices. The electronic devices in the embodiment of the present application can be mobile phones, smart TVs, wearable devices, tablet computers, computers with wireless transceiver functions, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, etc. Among them, a variety of applications can be run in the electronic device, and the application can include pre-installed applications in the electronic device, or applications installed in the electronic device by the user according to his or her own needs. For example, when a user needs to hold an online meeting, he or she can install online meeting-related applications in the electronic device through an application market or other channels.
[0043] In some embodiments, an application typically records the quality of service (QoS) level of the thread corresponding to the application. During the application's execution, the electronic device can determine the thread's priority type based on the QoS level of each thread, for example, determining the priority type of a thread with a QoS level greater than or equal to a preset level as real-time priority, and determining the priority type of a thread with a QoS level less than a preset level as non-real-time priority, etc. Then, when scheduling threads, the electronic device will prioritize the supply of resources for threads with a real-time priority level, for example, preferentially allocating resources (such as computing resources, memory resources, etc.) to threads with a real-time priority level, so that threads with a real-time priority level can continue to run.
[0044] In this way, if there are too many threads with real-time priority, threads with non-real-time priority (and some threads with real-time priority) may not be allocated computing resources, which in turn may cause threads that are not allocated resources to be unable to run, causing thread blocking and affecting the operation of electronic device applications.
[0045] For example, Table 1 shows a correspondence between QoS levels and application scenarios.
[0046] As shown in Table 1, threads with a QoS level of 5 correspond to user interaction tasks, such as user interface drawing and rendering. Their resource requirement is high overall supply, meaning that processor hardware and memory resources must be prioritized to threads with this QoS level to ensure the execution of their tasks. Threads with a QoS level of 4 correspond to tasks where faster execution is preferred, such as page loading. Their resource requirement is high CPU supply, meaning that processor hardware resources must be prioritized to threads with this QoS level to ensure the execution of their tasks. Threads with a QoS level of 3 correspond to user-triggered tasks with visible progress, such as document opening. Their resource requirement is high DDR supply, meaning that processor memory resources must be prioritized to threads with this QoS level to ensure the execution of their tasks. Threads with a QoS level of 2 correspond to default-level tasks, with a resource requirement of default supply. Threads with a QoS level of 1 correspond to tasks where immediate responses are not required, such as downloading or importing data. Their resource requirement is guaranteed IO supply, with all other requirements suppressed. That is, only the IO resources corresponding to threads with this QoS level need to be guaranteed. The processor's hardware resources and memory resources can be preferentially provided to threads with higher QoS levels to ensure the execution of tasks corresponding to threads with higher QoS levels. The application scenarios corresponding to tasks with QoS level 0 are user-invisible tasks, such as data synchronization and backup, and the corresponding resource requirements are low. That is, the processor's hardware resources and memory resources can be preferentially provided to threads with higher QoS levels to ensure the execution of tasks corresponding to threads with higher QoS levels.
[0047] Table 1 QoS level and application scenario correspondence table
[0048]
[0049] It will be understood that the QoS level classification and QoS level identification shown in Table 1 are merely exemplary. In other embodiments, more or fewer QoS levels than those shown in Table 1 may be included, and other identifications may be used to identify different QoS levels. For example, the QoS levels may be divided into four QoS levels: A, B, C, and D. This application does not impose any limitations on this.
[0050] In some embodiments, the electronic device determines the priority type of the thread based on the QoS level of each thread, for example, determining the priority type of the thread with a QoS level greater than or equal to a preset level as real-time priority, and determining the priority type of the thread with a QoS level less than a preset level as non-real-time priority, etc.
[0051] For example, taking the QoS levels shown in Table 1 as an example, assuming the preset level is 5, the priority type of threads with a QoS level greater than or equal to 5 is real-time priority, and the priority type of threads with a QoS level less than 5 is non-real-time priority.
[0052] In other embodiments, the electronic device determines the priority type of a thread based on the task attribute corresponding to the thread. For example, if the task attribute corresponding to the thread is foreground running, the priority type of the thread is real-time priority; if the task attribute corresponding to the thread is background running, the priority type of the thread is non-real-time priority.
[0053] Figure 1a A schematic diagram of an application scenario of thread management is shown. Figure 1a As shown, the display interface 10a of the electronic device 100 includes a user interface 101 of a video application 1031, a user interface 102 of a note application 1032, and a navigation bar 103. The navigation bar 103 includes application icons for the video application 1031 and the note application 1032. Furthermore, a user draws handwritten content on the user interface 102 of the note application 1032 using a stylus 200.
[0054] The threads corresponding to the video application 1031 include thread 1031a with a QoS level of 5, thread 1031b with a QoS level of 5, and thread 1031c with a QoS level of 5. The threads corresponding to the note application 1032 include thread 1032a with a QoS level of 5, thread 1032b with a QoS level of 4, and thread 1032c with a QoS level of 4.
[0055] When scheduling the threads corresponding to video application 1031 and note application 1032, electronic device 100 determines the priority type of each thread based on its QoS level. For example, threads 1031a, 1031b, 1031c, and 1032a, which have a QoS level of 5, have a real-time priority type, while threads 1032b and 1032c, which have a QoS level of 4, have a non-real-time priority type. When scheduling threads, electronic device 100 prioritizes the supply of resources for real-time priority.
[0056] Therefore, if Figure 1aAs shown, threads 1031a, 1031b, 1031c, and 1032a are in the running state, while threads 1032b and 1032c are in the blocked state. It is understandable that due to the excessive number of threads with real-time priority, threads with non-real-time priority cannot be allocated computing resources and are in the blocked state. If threads 1032b and 1032c of note application 1032 remain in the blocked state and cannot run, this may affect the operation of note application 1032, such as affecting the display and saving of user-drawn content, thereby affecting the user's interactive experience.
[0057] In view of this, an embodiment of the present application provides a thread management method, in which an electronic device can determine a thread (hereinafter referred to as a target thread) that meets a priority control condition (as an instance of the first priority condition) based on the running time of a thread (as an instance of the first thread) whose priority type is real-time priority (as an instance of the first priority), and reduce the priority type of the target thread from real-time priority to non-real-time priority (as an instance of the second priority).
[0058] Among them, the priority control conditions may include at least one of the following conditions: the continuous running time of the thread is greater than the first time threshold, the continuous running time of the thread in the first scheduling cycle is greater than the first time threshold, there are threads in the thread group where the thread is located whose continuous running time is greater than the first time threshold, there are threads in the thread group where the thread is located whose continuous running time in the first scheduling cycle is greater than the first time threshold, the sum of the running times of each thread in the thread group where the thread is located in the first scheduling cycle is greater than the first time threshold, etc.
[0059] In this way, it is possible to prevent some threads with real-time priority from running continuously for a long time, causing other threads to be unable to run and resulting in thread blocking.
[0060] For example, still Figure 1a Take the application scenario shown as an example. Figure 1b A schematic diagram of a scheduling process is shown according to an embodiment of the present application.
[0061] like Figure 1b As shown, threads 1031a, 1031b, 1031c, and 1032a, which have real-time priority, have corresponding resource supply high. Threads 1032b and 1032c, which have non-real-time priority, cannot be allocated computing resources and are in a blocked state.
[0062] When the continuous running time of thread 1031a exceeds the first time threshold, the electronic device lowers the priority of thread 1031a, that is, sets the priority type of thread 1031a to non-real-time priority. In this way, the resource supply corresponding to thread 1031a is reduced from high supply to low supply, and the electronic device can allocate computing resources to other threads, for example, allocate computing resources to thread 1032b, so that thread 1032b can run.
[0063] In some embodiments, threads with a real-time priority type may include threads with a QoS level greater than or equal to a preset level.
[0064] In some embodiments, the first scheduling period is a time period preset by the electronic device, representing a time slice (period) for the processor to run a thread, such as 100 milliseconds, 150 milliseconds, 200 milliseconds, etc. It should be understood that the first scheduling period may also be other durations, which are not limited here.
[0065] In some embodiments, the electronic device suspends the target thread upon detecting that the target thread meets an operation control condition. The operation control condition may include at least one of the following conditions: the target thread's continuous running time is greater than a second time threshold, the target thread's continuous running time within a first scheduling period is greater than the second time threshold, the target thread's grouping includes threads with continuous running times greater than the second time threshold, the target thread's grouping includes threads with continuous running times greater than the second time threshold, the target thread's grouping includes threads with continuous running times greater than the second time threshold within the first scheduling period, the sum of the running times of all threads within the target thread's grouping within the first scheduling period is greater than the second time threshold, etc. The second time threshold is greater than the first time threshold.
[0066] In this way, it is possible to prevent some threads with real-time priority from occupying the processor's hardware resources for a long time, resulting in an inability to allocate processor hardware resources to other threads and causing thread blocking.
[0067] For example, Figure 1b As shown, when the continuous running time of thread 1031a exceeds the second time threshold, thread 1031a is suspended, that is, thread 1031a is temporarily stopped. In this way, the state corresponding to thread 1031a becomes blocked, and the electronic device can allocate computing resources to other threads, for example, allocate computing resources to thread 1032c, so that thread 1032c can run.
[0068] In some embodiments, upon detecting that a control cancellation condition (as an example of a first control cancellation condition) is satisfied, the electronic device may cancel control of the target thread. The control cancellation condition may include at least one of the following conditions: the target thread's priority is lowered for a duration greater than a first duration, the target thread is suspended for a duration greater than a second duration, the first scheduling cycle ends, etc.
[0069] In some embodiments, the method for canceling the control of the target thread includes: corresponding to the target thread whose priority is reduced to the second priority, restoring the target thread to the first priority; corresponding to the suspended target thread, resuming the operation of the suspended target thread, and so on.
[0070] In this way, excessive control of threads with real-time priority type, such as downgrading or suspending them, can be avoided, thereby avoiding affecting the operation of the controlled threads.
[0071] For example, the electronic device may restore the priority type of the target thread to real-time priority upon detecting that the duration of lowering the priority of the target thread reaches a first duration or the first scheduling cycle ends. For another example, the electronic device may resume running the suspended target thread upon detecting that the duration of suspending the target thread reaches a second duration or the first scheduling cycle ends.
[0072] For example, Figure 1b As shown, after the end time of the scheduling period, the priority type of the recovery thread 1031a is real-time priority.
[0073] In some embodiments, threads with a real-time priority type may be periodically managed based on the aforementioned first scheduling period.
[0074] For example, the electronic device can count the continuous running time of threads with a priority type of real-time priority in the first scheduling cycle, and use the threads whose continuous running time in the first scheduling cycle is greater than the first time threshold as the target thread, and reduce the priority type of the target thread from real-time priority to non-real-time priority. If the continuous running time of the target thread in the first scheduling cycle is greater than the second time threshold, the target thread is suspended. In addition, at the end of the first scheduling cycle (that is, the control cancellation condition is met), the priority type of the target thread is restored to real-time priority, and the suspended target thread is resumed.
[0075] In some embodiments, threads with a real-time priority in an electronic device are divided into multiple thread groups. The threads in each thread group are related to each other, for example, the tasks executed by each thread in the same thread group are related. In the process of scheduling threads, the electronic device can determine the continuous running time of the threads in each thread group. If the continuous running time of any thread in a thread group is greater than a first time threshold, all threads in the thread group are determined as target threads. Then, the priority type of the target thread is reduced from real-time priority to non-real-time priority. If the continuous running time of any target thread in the thread group where the target thread is located is greater than a second time threshold, it is determined that all target threads in the thread group meet the running control conditions, and all target threads in the thread group are suspended. In addition, at the end of the first scheduling cycle (that is, the cancellation control condition is met), the priority type of the target thread is restored to real-time priority, and the suspended target thread is resumed.
[0076] In other embodiments, the electronic device may determine the sum of the running times of all threads in each thread group during the process of scheduling threads. If the sum of the running times of all threads in a thread group is greater than a first time threshold, all threads in the thread group are determined as target threads. Then, the priority type of the target thread is reduced from real-time priority to non-real-time priority. If the sum of the running times of all target threads in the thread group where the target thread is located is greater than a second time threshold, it is determined that all target threads in the thread group meet the running control conditions, and all target threads in the thread group are suspended. In addition, at the end of the first scheduling cycle (i.e., the cancellation control condition is met), the priority type of the target thread is restored to real-time priority, and the suspended target thread is resumed.
[0077] In addition, due to the subjectivity of developers when marking QoS levels, the marked QoS levels may not be accurate enough. For example, a thread with a QoS level greater than the preset level may be marked as a QoS level less than the preset level, or a thread with a QoS level less than the preset level may be marked as a QoS level greater than the preset level. Furthermore, the priority of a thread greater than the preset level may be mapped to a priority level less than the preset level. If the thread greater than the preset level is a thread related to user interaction (such as a thread related to frame drawing), due to the developer's inaccurate marking, the priority type of the thread may be mapped to a non-real-time priority, which may cause the thread to fail to run in a timely manner.
[0078] For example, taking the QoS levels shown in Table 1 as an example, the QoS level corresponding to the thread for the application scenario where the task does not need to see an immediate response should be 1. If the developer marks the QoS level of the thread for this application scenario as 5, it may cause the electronic device to continue running the threads marked with QoS level 5. This will cause other higher-priority threads to be unable to run. For example, the thread for the application scenario where the faster the task is executed, the better, with a QoS level of 4, will be unable to run, causing thread blocking and affecting the operation of the electronic device application.
[0079] Understandably, Figure 1a Taking the application scenario shown as an example, if thread 1032b and thread 1032c of the note application 1032 are threads related to the operation of the user drawing handwritten content, if they are in a blocked state, it may affect the display of the user's drawn content, thereby affecting the user's interactive experience.
[0080] Therefore, in other embodiments, the electronic device may further determine the priority type based on the application scenario corresponding to the thread. For example, if the task type executed by the thread is a user interaction task, the priority type of the thread is real-time priority; if the task type executed by the thread is not a user interaction task, the priority type of the thread is non-real-time priority. Based on this, the aforementioned threads with a real-time priority type may also include threads with a QoS level tag lower than a preset level but executing a user interaction task.
[0081] In this way, the problem of inaccurate marking of QoS levels by developers, resulting in threads with a QoS level greater than or equal to the preset level being marked with a QoS level lower than the preset level and then mapped to a non-real-time priority, can be avoided.
[0082] In order to better understand the technical solutions of the embodiments of the present application, some technical solutions of the present application are described in detail below with reference to the accompanying drawings.
[0083] First, taking the priority control conditions including the thread continuous running time being greater than the first time threshold, the existence of threads with continuous running time greater than the first time threshold in the thread group where the thread is located, the operation control conditions including the target thread continuous running time being greater than the second time threshold, the existence of threads with continuous running time greater than the second time threshold in the thread group where the target thread is located, and the cancellation control conditions including lowering the priority of the target thread for a duration greater than the first duration, and suspending the target thread for a duration greater than the second duration as an example, the technical solution of the present application is introduced.
[0084] For example, Figure 2 According to an embodiment of the present application, a flowchart of a thread management method is shown. It can be understood that Figure 2Each step of the process shown is performed by the electronic device 100. Figure 2 The execution entities of each step will not be repeatedly described in the steps of the process shown.
[0085] S201: Determine the continuous running time of a thread with a real-time priority type.
[0086] In some embodiments, the electronic device 100 collects statistics on the continuous running time of the currently running thread with the real-time priority type.
[0087] In other embodiments, the electronic device 100 counts the continuous running time of threads in each currently running thread group.
[0088] It can be understood that the priority type of the threads in each thread group is real-time priority, and the threads are associated with each other, for example, the tasks executed by the threads in the same thread group are associated with each other.
[0089] It can be understood that, in some embodiments, the thread with a real-time priority type may include a thread with a QoS level greater than or equal to a preset level among currently running threads.
[0090] In some embodiments, the thread with a real-time priority type may include a thread whose task type to be executed is a user interaction task determined by the electronic device 100 (as a critical thread).
[0091] In some embodiments, the thread with a real-time priority level may include a thread whose QoS level is less than a preset level and whose task type is determined by the electronic device 100 to be a user interaction task. The method for determining the thread whose task type is a user interaction task will be described below and will not be repeated here.
[0092] It is understandable that since some threads are highly correlated with user interaction, such as the frame drawing thread, if these threads are controlled, it may affect the execution of the threads, thereby affecting the user experience, such as the freezing phenomenon of the refresh interface. Therefore, in some embodiments, the electronic device 100 exempts some threads whose priority type is real-time priority and whose application scenario is user interaction scenario in the first scheduling period, that is, marks these threads as exempt threads (as instances of preset exempt threads).
[0093] In some embodiments, the electronic device 100 may further group the exempt threads, and the exempt threads in the same exempt thread group are associated with each other.
[0094] Therefore, in some embodiments, the threads with a real-time priority type may also include other threads except the exempted threads among the currently running threads whose QoS level is greater than or equal to the preset level.
[0095] In some embodiments, the threads with a real-time priority type may include threads other than exempted threads among threads whose task type to be executed is a user interaction task determined by the electronic device 100 .
[0096] In some embodiments, threads with a real-time priority priority type may also include threads among currently running threads whose QoS level is greater than or equal to a preset level, and threads among currently running threads whose QoS is less than a preset level, and threads whose task type to be executed is determined by the electronic device 100 to be a user interaction task, except exempted threads.
[0097] S202: Determine whether there is a thread whose continuous running time is greater than a first time threshold.
[0098] In some embodiments, if the judgment result is yes, it means that there is a thread (as the target thread) whose continuous running time is greater than the first time threshold, and the thread whose continuous running time is greater than the first time threshold needs to be managed, then step S203 is executed to lower the priority of the thread whose continuous running time is greater than the first time threshold, and / or lower the priority of the thread in the thread group where the thread whose continuous running time is greater than the first time threshold is located.
[0099] In other embodiments, if the judgment result is no, it means that there is no thread whose continuous running time is greater than the first time threshold, then it is necessary to continue to count the continuous running time of the currently running thread with a real-time priority type, and then execute step S201 to determine the continuous running time of the thread with a real-time priority type.
[0100] S203: Lowering the priority of a thread whose continuous running time is greater than a first time threshold, and / or lowering the priority of threads in a thread group where a thread whose continuous running time is greater than the first time threshold exists.
[0101] In some embodiments, if there is a thread whose continuous running time is greater than the first time threshold, the electronic device 100 can use the thread whose continuous running time is greater than the first time threshold as the target thread and set the priority type of the target thread to non-real-time priority.
[0102] In other embodiments, if there is a thread whose continuous running time is greater than the first time threshold, the electronic device 100 can use the thread in the thread group where the thread whose continuous running time is greater than the first time threshold is located as the target thread, and set the priority type of the target thread to non-real-time priority.
[0103] It can be understood that the target thread may include the thread itself whose continuous running time is greater than the first time threshold, and other threads in the thread group where the thread whose continuous running time is greater than the first time threshold belongs.
[0104] It is understood that the electronic device 100 can prevent a thread or threads within a thread group from running continuously for a long time by reducing the priority of the thread whose continuous running time is greater than the first time threshold, or by reducing the priority of each thread in the thread group containing the thread whose continuous running time is greater than the first time threshold. This can further prevent other threads from being unable to run due to the long-term continuous running of some threads, thereby avoiding thread blocking.
[0105] It is understandable that since exempted threads are closely related to user interaction, such as frame drawing threads, if these threads are controlled, it may affect the execution of the threads, thereby affecting the user experience, such as the freeze phenomenon when refreshing the interface.
[0106] Therefore, in some embodiments, if the continuous running time of the exempted thread is greater than the first time threshold, the electronic device 100 may not reduce the priority of the exempted thread to ensure the normal execution of the exempted thread. In other embodiments, if the continuous running time of the exempted thread is greater than the first time threshold, the electronic device 100 may not reduce the priority of the threads in the thread group (exempted thread group) to which the exempted thread belongs to to ensure the normal execution of each thread in the thread group to which the exempted thread belongs.
[0107] S204: Determine whether there is a thread whose continuous running time is greater than a second time threshold.
[0108] After lowering the priority of a thread whose continuous running time is greater than a first time threshold, or after lowering the priority of each thread in the thread group containing the thread whose continuous running time is greater than the first time threshold, the electronic device 100 needs to continue to determine whether there is a thread whose continuous running time is greater than a second time threshold. The second time threshold is greater than the first time threshold.
[0109] In some embodiments, if the judgment result is yes, it means that there is a thread whose continuous running time is greater than the second time threshold, and it is necessary to continue to control the thread whose continuous running time is greater than the second time threshold, then step S205 is executed to suspend the thread whose continuous running time is greater than the second time threshold, and / or the thread in the thread group where the thread whose continuous running time is greater than the second time threshold is located.
[0110] In other embodiments, if the judgment result is no, it means that there is no thread whose continuous running time is greater than the second time threshold, then it is necessary to continue to count the continuous running time of the currently running thread with a real-time priority type, and then execute step S201 to determine the continuous running time of the thread with a real-time priority type.
[0111] S205: Suspend the thread whose continuous running time is greater than the second time threshold, and / or suspend the threads in the thread group where the thread whose continuous running time is greater than the second time threshold belongs.
[0112] In some embodiments, if there is a thread whose continuous running time is greater than the second time threshold, the electronic device 100 suspends the thread whose continuous running time is greater than the second time threshold. In other words, the execution of the thread whose continuous running time is greater than the second time threshold is suspended.
[0113] In other embodiments, if a thread in a thread group has a continuous running time greater than a second time threshold, the electronic device 100 suspends each thread in the thread group containing the thread with the continuous running time greater than the second time threshold. In other words, the execution of each thread in the thread group containing the thread with the continuous running time greater than the second time threshold is suspended.
[0114] It is understood that by suspending a thread whose continuous execution time exceeds the second time threshold, or suspending each thread in the thread group containing the thread whose continuous execution time exceeds the second time threshold, the electronic device 100 can prevent the thread or each thread in the thread group from occupying the processor's hardware resources for a long time. Furthermore, this can prevent other threads from being unable to obtain the processor's hardware resources due to some threads occupying the processor's hardware resources for a long time, thereby avoiding thread blocking.
[0115] It can be understood that since the exempted thread is highly correlated with user interaction, if the execution of the exempted thread is suspended, it may affect the performance of the device and affect the user experience, such as the freeze phenomenon when refreshing the interface. Therefore, in some embodiments, if the continuous running time of the exempted thread is greater than the second time threshold, the electronic device 100 may not suspend the exempted thread, but set the priority type of the exempted thread to a non-real-time priority, that is, lower the priority of the exempted thread to ensure the normal operation of the exempted thread. In other embodiments, if the continuous running time of the exempted thread is greater than the second time threshold, the electronic device 100 may not suspend the threads in the thread group where the exempted thread is located, but lower the priority of the threads in the thread group where the exempted thread is located to ensure the normal operation of each thread in the thread group where the exempted thread is located.
[0116] S206: Determine whether there is a thread whose priority is lowered for a duration greater than the first duration.
[0117] In some embodiments, if the judgment result is yes, it means that there is a thread whose priority has been downgraded for a period longer than the first period, and the priority of the thread whose priority has been downgraded for a period longer than the first period needs to be restored, then step S207 is executed to restore the priority of the thread whose priority has been downgraded for a period longer than the first period.
[0118] In other embodiments, if the judgment result is no, it means that there is no thread whose priority is downgraded for a period longer than the first period, and it can be further determined whether there is a thread whose suspension time is longer than the second period, then step S208 is executed to determine whether there is a thread whose suspension time is longer than the second period.
[0119] S207: Restoring the priority of the thread whose priority has been downgraded for a duration greater than the first duration.
[0120] The electronic device 100 detects that there is a thread whose priority has been downgraded for a period longer than the first period, and restores the priority type of the thread whose priority has been downgraded for a period longer than the first period to the real-time priority.
[0121] It can be understood that restoring the priority of the downgraded thread can avoid excessive control of the thread with real-time priority, thereby avoiding affecting the operation of the controlled thread.
[0122] S208: Determine whether there is a thread whose suspension duration is greater than the second duration.
[0123] In some embodiments, if the judgment result is yes, it means that there is a thread whose suspension time is greater than the second time period, and the thread whose suspension time is greater than the second time period needs to be resumed, then step S209 is executed to resume the thread whose suspension time is greater than the second time period.
[0124] In other embodiments, if the judgment result is no, it means that there is no thread whose suspension time is greater than the second time length, and the continuous running time of the currently running thread with the real-time priority type can continue to be counted, and then step S201 is executed to determine the continuous running time of the thread with the real-time priority type.
[0125] S209: Resume the thread whose suspension time is greater than the second time.
[0126] The electronic device 100 detects that there is a thread whose suspension time is longer than the second time, and resumes the thread whose suspension time is longer than the second time.
[0127] It can be understood that resuming the suspended thread can avoid excessive control of the thread with the real-time priority type, thereby avoiding affecting the operation of the controlled thread.
[0128] It is understood that in some embodiments, the order of executing steps S206 and S208 can be swapped. That is, the electronic device 100 first determines whether there is a thread whose suspension duration is greater than the second duration, and then determines whether there is a thread whose priority has been degraded for a duration greater than the first duration. In some embodiments, steps S206 and S208 can also be executed in parallel. This application does not impose any restrictions on this.
[0129] It is understood that in other embodiments, according to actual needs, the above Figure 2 The steps shown can be combined, deleted or replaced with other steps that are conducive to achieving the purpose of this application, and this application does not limit this.
[0130] Below, taking the priority control conditions including the thread's continuous running time in the first scheduling cycle being greater than the first time threshold, the existence of threads in the thread group where the thread is located having a continuous running time greater than the first time threshold in the first scheduling cycle, the operation control conditions including the existence of threads in the thread group where the target thread is located having a continuous running time greater than the second time threshold, the existence of threads in the thread group where the target thread is located having a continuous running time greater than the second time threshold in the first scheduling cycle, and the cancellation control conditions including the end of the first scheduling cycle as an example, the technical solution of the present application is introduced.
[0131] Figure 3 According to an embodiment of the present application, a flow chart of a periodic thread management method is shown. It can be understood that Figure 3 Each step of the process shown is performed by the electronic device 100. Figure 3 The execution entities of each step will not be repeatedly described in the steps of the process shown.
[0132] like Figure 3 As shown, the process includes but is not limited to the following steps:
[0133] S301: Determine threads with a real-time priority type in a first scheduling period, and add the threads with a real-time priority type to a thread management queue.
[0134] In some embodiments, the electronic device 100 adds threads with a real-time priority type in the first scheduling period to a thread management queue.
[0135] In other embodiments, the electronic device 100 groups threads with a real-time priority within the first scheduling period to obtain multiple thread groups, and adds the multiple thread groups to the thread management queue. The thread grouping rule is to add related threads to the same thread group, or to add threads corresponding to the same application to the same thread group.
[0136] The first scheduling period is a preset time period, which represents a time slice for the processor to run, such as 100 milliseconds, 150 milliseconds, 200 milliseconds, etc. The present application does not impose any specific limitation on the length of the first scheduling period.
[0137] Specifically, the electronic device 100 can add a thread with a real-time priority type to the thread management queue by calling the queue adding function sched_rt_enqueue.
[0138] In some embodiments, the thread with a real-time priority type may include a thread with a QoS level greater than or equal to a preset level among currently running threads.
[0139] In some embodiments, the thread with a real-time priority type may include a thread whose task type to be executed is a user interaction task determined by the electronic device 100 (as a critical thread).
[0140] In some embodiments, threads with a real-time priority level may also include threads with a QoS level greater than or equal to a preset level among currently running threads, and threads with a QoS level less than a preset level among currently running threads, and threads whose task type of execution is determined by the electronic device 100 to be a user interaction task. The method for determining threads whose task type of execution is a user interaction task will be described below and will not be elaborated on here.
[0141] It is understandable that since some threads are highly relevant to user interaction, such as the frame drawing thread, controlling these threads may affect thread execution, thereby affecting the user experience, such as the freezing of the refresh interface. Therefore, in some embodiments, the electronic device 100 exempts some threads in the first scheduling period whose priority type is real-time priority and whose application scenario is user interaction scenario, that is, marks these threads as exempt threads.
[0142] In some embodiments, the electronic device 100 may further group the exempt threads, and the exempt threads in the same exempt thread group are associated with each other.
[0143] Therefore, in some embodiments, the threads with a real-time priority type may also include other threads except the exempted threads among the currently running threads whose QoS level is greater than or equal to the preset level.
[0144] In some embodiments, the threads with a real-time priority type may include threads other than exempted threads among threads whose task type to be executed is a user interaction task determined by the electronic device 100 .
[0145] In some embodiments, threads with a real-time priority priority type may also include threads among currently running threads whose QoS level is greater than or equal to a preset level, and threads among currently running threads whose QoS is less than a preset level, and threads whose task type to be executed is determined by the electronic device 100 to be a user interaction task, except exempted threads.
[0146] For example, refer to Figure 5 The diagram of thread management is shown in Figure 1. Figure 5 As shown, in scheduling cycle 1, the priority types of thread 1, thread 2, thread 3 and thread 4 are all real-time priorities, and thread 4 is marked as an exempt thread.
[0147] In some embodiments, thread 1, thread 2, and thread 3 are threads in the same thread group.
[0148] S302: Determine the continuous running time of each thread in the thread management queue in the first scheduling cycle.
[0149] In some embodiments, the electronic device 100 counts the continuous running time of each thread in the thread management queue in the first scheduling period to obtain the continuous running time of each thread in the first scheduling period.
[0150] In other embodiments, the electronic device 100 counts the continuous running time of threads in each thread group in the thread management queue during the first scheduling period to obtain the continuous running time of each thread in each thread group during the first scheduling period.
[0151] Specifically, the electronic device 100 can complete the statistics of the continuous running time of each thread in the thread management queue in the first scheduling period by calling the continuous running time statistics function update_curr_rt.
[0152] S303: Determine whether there is a thread in the thread management queue whose continuous running time in the first scheduling period is greater than the first time threshold.
[0153] The first time threshold may be, for example, 40 milliseconds, 60 milliseconds, 80 milliseconds, 60% of the first scheduling period, 80% of the first scheduling period, etc. This application does not limit the specific value of the first time threshold.
[0154] In some embodiments, if the judgment result is yes, it means that there is a thread (as a target thread) in the thread management queue whose continuous running time in the first scheduling cycle is greater than the first time threshold, and it is necessary to manage the thread whose continuous running time in the first scheduling cycle is greater than the first time threshold, then step S304 is executed to lower the priority of the thread whose continuous running time in the first scheduling cycle is greater than the first time threshold, and / or lower the priority of the thread in the thread group where the thread whose continuous running time in the first scheduling cycle is greater than the first time threshold is located.
[0155] In other embodiments, if the judgment result is no, it means that there is no thread in the thread management queue whose continuous running time in the first scheduling cycle is greater than the first time threshold, then it is necessary to continue to count the continuous running time of each thread in the thread management queue, and then execute step S302 to determine the continuous running time of each thread in the thread management queue in the first scheduling cycle.
[0156] Specifically, the electronic device 100 can complete the judgment of whether the continuous running time of each thread in the thread management queue exceeds the first time threshold by calling the continuous running time checking function sched_rt_runtime_exceeded.
[0157] S304: Lowering the priority of a thread whose continuous running time in the first scheduling period is greater than a first time threshold, and / or lowering the priority of a thread in a thread group containing a thread whose continuous running time in the first scheduling period is greater than the first time threshold.
[0158] In some embodiments, if there is a thread in the thread management queue whose continuous running time in the first scheduling period is greater than the first time threshold, the electronic device 100 will use the thread in the thread management queue whose continuous running time in the first scheduling period is greater than the first time threshold as the target thread, and set the priority type of the target thread to non-real-time priority.
[0159] In other embodiments, if there is a thread in the thread group in the thread management queue whose continuous running time in the first scheduling period is greater than the first time threshold, the electronic device 100 will take all threads in the thread group where the thread whose continuous running time in the first scheduling period is greater than the first time threshold is located as target threads, and set the priority type of all target threads to non-real-time priority.
[0160] It is understandable that the target thread may include the thread itself whose continuous running time in the first scheduling cycle is greater than the first time threshold, and other threads in the thread group where the thread whose continuous running time in the first scheduling cycle is greater than the first time threshold belongs.
[0161] It is understood that the electronic device 100 reduces the priority of a thread whose continuous running time in the first scheduling period is greater than the first time threshold, or reduces the priority of each thread in the thread group containing the thread whose continuous running time in the first scheduling period is greater than the first time threshold, so as to prevent the thread or each thread in the thread group from running continuously for a long time. Furthermore, the problem of other threads being unable to run due to the long-term continuous running of some threads can be avoided, thereby avoiding thread blocking.
[0162] In other alternative embodiments, if there are threads in the thread management queue whose continuous running time is greater than the first time threshold, the electronic device 100 can also set the priority type of each thread in the thread management queue to non-real-time priority, so as to avoid the situation where the thread with real-time priority type occupies the processor's hardware resources for a long time, resulting in other threads being unable to obtain the processor's hardware resources.
[0163] Specifically, the electronic device 100 can call the priority downgrade function queue_irq_work_downgrade to set the priority type of the thread with real-time priority to non-real-time priority, and add it to the downgrade linked list downgrade.
[0164] It is understandable that since exempted threads are closely related to user interaction, such as frame drawing threads, if these threads are controlled, it may affect the execution of the threads, thereby affecting the user experience, such as the freeze phenomenon when refreshing the interface.
[0165] Therefore, in some embodiments, if the continuous running time of the exempted thread in the first scheduling cycle is greater than the first time threshold, the electronic device 100 may not reduce the priority of the exempted thread to ensure the normal execution of the exempted thread. In other embodiments, if the continuous running time of the exempted thread in the first scheduling cycle is greater than the first time threshold, the electronic device 100 may not reduce the priority of the threads in the thread group (exempted thread group) to which the exempted thread belongs to, to ensure the normal execution of each thread in the thread group to which the exempted thread belongs.
[0166] S305: Determine whether there is a thread in the thread management queue whose continuous running time in the first scheduling period is greater than the second time threshold.
[0167] After the electronic device 100 lowers the priority of a thread whose continuous running time in the first scheduling cycle is greater than the first time threshold, or after lowering the priority of each thread in the thread group to which the thread whose continuous running time in the first scheduling cycle is greater than the first time threshold belongs, it is necessary to continue to determine whether the continuous running time of each thread in the thread management queue in the first scheduling cycle is greater than the second time threshold. The second time threshold is greater than the first time threshold, and the second time threshold can be, for example, 80 milliseconds, 90 milliseconds, 95 milliseconds, 90% of the time length of the first scheduling cycle, 95% of the time length of the first scheduling cycle, or other time values. This application does not limit the specific value of the second time threshold.
[0168] In some embodiments, if the judgment result is yes, it means that there is a thread in the thread management queue whose continuous running time in the first scheduling cycle is greater than the second time threshold, and it is necessary to continue to manage the thread whose continuous running time in the first scheduling cycle is greater than the second time threshold, then step S306 is executed to suspend the thread whose continuous running time in the first scheduling cycle is greater than the second time threshold, and / or the thread in the thread group where the thread whose continuous running time in the first scheduling cycle is greater than the second time threshold is located.
[0169] In other embodiments, if the judgment result is no, it means that there is no thread in the thread management queue whose continuous running time in the first scheduling cycle is greater than the second time threshold, then it is necessary to continue to count the continuous running time of each thread in the thread management queue, and then execute step S302 to determine the continuous running time of each thread in the thread management queue in the first scheduling cycle.
[0170] S306: Suspend the thread whose continuous running time in the first scheduling period is greater than the second time threshold, and / or suspend the threads in the thread group where the thread whose continuous running time in the first scheduling period is greater than the second time threshold belongs.
[0171] In some embodiments, if there is a thread in the thread management queue whose continuous running time is greater than the second time threshold, the electronic device 100 suspends the thread in the thread management queue whose continuous running time is greater than the second time threshold. In other words, the execution of the thread in the thread management queue whose continuous running time is greater than the second time threshold is suspended.
[0172] In other embodiments, if a thread in a thread group in the thread management queue has a continuous running time greater than a second time threshold, the electronic device 100 suspends each thread in the thread group containing the thread with the continuous running time greater than the second time threshold. In other words, the execution of each thread in the thread group containing the thread with the continuous running time greater than the second time threshold is suspended.
[0173] It is understood that by suspending a thread whose continuous execution time exceeds the second time threshold, or suspending each thread in the thread group containing the thread whose continuous execution time exceeds the second time threshold, the electronic device 100 can prevent the thread or each thread in the thread group from occupying the processor's hardware resources for a long time. Furthermore, this can prevent other high-priority threads from being unable to obtain the processor's hardware resources due to some threads occupying the processor's hardware resources for a long time, thereby avoiding thread blocking.
[0174] In other alternative embodiments, if there are threads in the thread management queue whose continuous running time is greater than the second time threshold, the electronic device 100 can also suspend each thread in the thread management queue to avoid the threads in the thread management queue occupying the processor's hardware resources for a long time, resulting in other threads being unable to obtain the processor's hardware resources.
[0175] It can be understood that since the exempted thread is highly correlated with user interaction, if the execution of the exempted thread is suspended, it may affect the performance of the device and affect the user experience, such as the freeze phenomenon when refreshing the interface. Therefore, in some embodiments, if the continuous running time of the exempted thread is greater than the second time threshold, the electronic device 100 may not suspend the exempted thread, but set the priority type of the exempted thread to a non-real-time priority, that is, lower the priority of the exempted thread to ensure the normal operation of the exempted thread. In other embodiments, if the continuous running time of the exempted thread is greater than the second time threshold, the electronic device 100 may not suspend the threads in the thread group where the exempted thread is located, but lower the priority of the threads in the thread group where the exempted thread is located to ensure the normal operation of each thread in the thread group where the exempted thread is located.
[0176] In some embodiments, if the priority control condition is that the sum of the running time of each thread in the thread group to which the thread belongs in the first scheduling cycle is greater than the first time threshold, and the first time threshold is 30 milliseconds. Figure 5 As shown, the continuous running time of thread 3 at 60 milliseconds is 30 milliseconds, so after 60 milliseconds, the priority type of thread 3 is set to non-real-time priority.
[0177] S307: Determine whether the first scheduling period is completed.
[0178] In some embodiments, if the judgment result is yes, it means that the first scheduling cycle has ended and the managed thread, such as a downgraded thread or a suspended thread, needs to be restored, then step S308 is executed to restore the priority of the downgraded thread and resume running the suspended thread.
[0179] In other embodiments, if the judgment result is no, it means that the first scheduling cycle has not ended and it is necessary to continue to count the continuous running time of each thread in the thread management queue, then step S302 is executed to determine the continuous running time of each thread in the thread management queue during the first scheduling cycle.
[0180] It can be understood that the start and end of the first scheduling period can be achieved by setting a timer with a preset duration, and the duration of the timer is the duration of the first scheduling period.
[0181] S308: Restore the priority of the thread with the lowered priority, and resume the suspended thread.
[0182] In some embodiments, after the first scheduling cycle ends, the electronic device 100 resumes the execution of the suspended threads in the thread management queue, restores the priority type of the threads in the thread management queue to real-time priority, and clears the thread management queue. In this way, in the next scheduling cycle, each thread managed in the first scheduling cycle can be executed normally based on the corresponding priority.
[0183] Specifically, the electronic device 100 may set the priority type of the threads in the downgrade list downgrade to real-time priority by calling the priority recovery function do_sched_rt_upgrade.
[0184] like Figure 5 As shown, at the start time of scheduling cycle 2, the priority types of thread 1, thread 2 and thread 3 are restored to real-time priority.
[0185] S309: Schedule the threads in the next scheduling cycle.
[0186] In some embodiments, after the first scheduling cycle ends, the electronic device 100 can manage the threads running in the next scheduling cycle.
[0187] Specifically, please refer to the relevant descriptions in the above steps S301 to S308, and this application will not go into details here.
[0188] Specifically, the electronic device 100 can manage the threads in the thread management queue by calling the thread management function try_start_rt_bandwidth.
[0189] It is understood that in other embodiments, according to actual needs, the above Figure 3 The steps shown can be combined, deleted or replaced with other steps that are conducive to achieving the purpose of this application. For example, the above steps S301 and S302 can be combined into one step. This application does not impose any restrictions on this.
[0190] Below, the technical solution of the present application is introduced by taking the priority control conditions including that the sum of the running time of each thread in the thread group where the thread is located in the first scheduling cycle is greater than the first time threshold, the running control conditions including that the sum of the running time of each thread in the thread group where the target thread is located in the first scheduling cycle is greater than the second time threshold, and the cancellation control conditions including the end of the first scheduling cycle as an example.
[0191] Figure 4 According to an embodiment of the present application, a flow chart of another periodic thread management method is shown. It can be understood that Figure 4 Each step of the process shown is performed by the electronic device 100. Figure 4 The execution entities of each step will not be repeatedly described in the steps of the process shown.
[0192] like Figure 4 As shown, the process includes but is not limited to the following steps:
[0193] S401: Determine threads with a real-time priority type in a first scheduling period, and add the threads with a real-time priority type to a thread management queue.
[0194] In some embodiments, the electronic device 100 groups threads with a real-time priority within the first scheduling period to obtain multiple thread groups, and adds the multiple thread groups to the thread management queue. The thread grouping rule is to add related threads to the same thread group, or to add threads corresponding to the same application to the same thread group.
[0195] Specifically, you can refer to Figure 3 The relevant description of step S301 in is not repeated here.
[0196] S402: Counting the running time of threads in each thread group in the thread management queue in the first scheduling cycle to determine the sum of the running time of threads in each thread group in the first scheduling cycle.
[0197] For example, Figure 5 As shown, within 60 milliseconds, the running time of thread 1 is 30 milliseconds, the running time of thread 2 is 20 milliseconds, and the running time of thread 3 is 30 milliseconds. The sum of the running time of thread 1, thread 2 and thread 3 is 80 milliseconds.
[0198] S403: Determine whether there is a thread group in the thread management queue whose total running time in the first scheduling period is greater than a first time threshold.
[0199] In some embodiments, if the judgment result is yes, it means that there is a thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the first time threshold, and it is necessary to manage the threads in the thread group whose sum of running time in the first scheduling cycle is greater than the first time threshold, then step S404 is executed to lower the priority of each thread in the thread group whose sum of running time in the first scheduling cycle is greater than the first time threshold.
[0200] In other embodiments, if the judgment result is no, it means that there is no thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the first time threshold, then it is necessary to continue to count the running time of threads in each thread group in the thread management queue in the first scheduling cycle, and then execute step S402 to count the running time of threads in each thread group in the thread management queue in the first scheduling cycle to determine the sum of the running time of threads in each thread group in the first scheduling cycle.
[0201] S404: Lowering the priority of each thread in the thread group whose sum of running time in the first scheduling period is greater than the first time threshold.
[0202] In some embodiments, if there is a thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the first time threshold, the electronic device 100 will take all threads in the thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the first time threshold as target threads, and set the priority type of the target thread to non-real-time priority.
[0203] It is understood that the electronic device 100 sets the priority type of all threads in the thread management queue in the thread group whose total running time in the first scheduling period is greater than the first time threshold to non-real-time priority, which can prevent the threads in the thread group from running continuously for a long time. Furthermore, it can avoid the problem of other threads being unable to run due to the long-term continuous running of some threads, thereby avoiding thread blocking.
[0204] For example, Figure 5 As shown, if the first time threshold is 80 milliseconds, since the sum of the running time of threads 1, 2, and 3 within 60 milliseconds is 80 milliseconds, which is equal to the first time threshold, after 60 milliseconds, the priority type of threads 1, 2, and 3 is set to non-real-time priority.
[0205] It is understandable that, due to the high correlation between exempted threads and user interaction, if exempted threads are controlled, it may affect the execution of the threads, thereby affecting the user experience, such as the freeze phenomenon when refreshing the interface. Therefore, in some embodiments, if the sum of the running time of the thread group where the exempted thread is located in the first scheduling cycle is greater than the first time threshold, the electronic device 100 may not downgrade the thread group where the exempted thread is located to ensure the normal execution of the exempted thread. In other words, if the sum of the running time of the thread group where the exempted thread is located in the first scheduling cycle is greater than the first time threshold, the electronic device 100 maintains the priority of the exempted thread in the thread group where the exempted thread is located.
[0206] S405: Determine whether there is a thread group in the thread management queue whose total running time in the first scheduling period is greater than a second time threshold.
[0207] After the electronic device 100 sets the priority type of all threads in the thread management queue that are in a thread group whose total running time in the first scheduling period is greater than the first time threshold to non-real-time priority, it is necessary to continue to determine whether there are thread groups in the thread management queue whose total running time in the first scheduling period is greater than the second time threshold. The second time threshold can be, for example, 90 milliseconds, 95 milliseconds, 90% of the time length of the first scheduling period, 95% of the time length of the first scheduling period, or other time value. This application does not limit the specific value of the second time threshold.
[0208] In some embodiments, if the judgment result is yes, it means that there is a thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the second time threshold, and it is necessary to continue to manage the threads in the thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the second time threshold, then step S406 is executed to suspend each thread in the thread group whose sum of running time in the first scheduling cycle is greater than the second time threshold.
[0209] In other embodiments, if the judgment result is no, it means that there is no thread group in the thread management queue whose sum of running time in the first scheduling cycle is greater than the second time threshold, then it is necessary to continue to count the running time of threads in each thread group in the thread management queue in the first scheduling cycle, and then execute step S402 to count the running time of threads in each thread group in the thread management queue in the first scheduling cycle to determine the sum of the running time of threads in each thread group in the first scheduling cycle.
[0210] S406: Suspend each thread in the thread group whose sum of running time in the first scheduling period is greater than a second time threshold.
[0211] In some embodiments, if a thread group exists in the thread management queue whose total running time in the first scheduling period is greater than a second time threshold, the electronic device 100 suspends all threads in the thread group in the thread management queue whose total running time in the first scheduling period is greater than the second time threshold. In other words, the execution of all threads in the thread group in the thread management queue whose total running time in the first scheduling period is greater than the second time threshold is suspended.
[0212] It is understood that the electronic device 100 suspends all threads in the thread group whose total running time during the first scheduling period is greater than the second time threshold, thereby preventing the thread or threads within the thread group from occupying the processor's hardware resources for a long time. Furthermore, this prevents other threads from being unable to obtain the processor's hardware resources due to some threads occupying the processor's hardware resources for a long time, thereby avoiding thread blocking.
[0213] It is understandable that, due to the high correlation between exempted threads and user interaction, suspending the execution of exempted threads may affect device performance and user experience, such as the occurrence of lag when refreshing the interface. Therefore, in some embodiments, if the sum of the running time of the thread group containing the exempted thread in the first scheduling cycle is greater than the second time threshold, the electronic device 100 may not suspend the threads in the thread group containing the exempted thread, but instead set the priority type of all exempted threads in the thread group containing the exempted thread to the priority type of all exempted threads in the thread group containing the non-real-time priority exempted thread, that is, lower the priority type to ensure the normal execution of the exempted thread.
[0214] For example, Figure 5 As shown, if the second time threshold is 40 milliseconds, since the sum of the running time of thread 4 within 95 milliseconds is 40 milliseconds, which is equal to the second time threshold, after 95 milliseconds, the priority type of thread 4 is set to non-real-time priority.
[0215] S407: Determine whether the first scheduling period is completed.
[0216] S408: Restore the priority of the thread with the lowered priority, and resume the suspended thread.
[0217] S409: Schedule the threads in the next scheduling cycle.
[0218] Specifically, steps S407 to S409 can refer to the above Figure 3 The relevant descriptions of steps S307 to S309 in the present application will not be repeated here.
[0219] It is understood that in other embodiments, according to actual needs, the above Figure 4The steps shown can be combined, deleted or replaced with other steps that are conducive to achieving the purpose of this application. For example, the above steps S401 and S402 can be combined into one step. This application does not limit this.
[0220] It is understood that since exempt threads are closely related to user interaction, the electronic device 100 can manage exempt processes separately. For example, the electronic device 100 detects that an exempt thread meets the exemption priority control condition (as an example of the second priority control condition) and lowers the priority of the exempt thread from the real-time priority to the non-real-time priority.
[0221] The exemption priority control conditions include at least one of the following conditions: the continuous running time of the exempted thread is greater than the third time threshold, the continuous running time of the exempted thread in the second scheduling period is greater than the third time threshold, there is a thread in the thread group where the exempted thread is located that has a continuous running time greater than the third time threshold, there is a thread in the thread group where the exempted thread is located that has a continuous running time greater than the third time threshold in the second scheduling period, the sum of the running times of all threads in the thread group where the thread is located in the second scheduling period is greater than the third time threshold, etc. The third time threshold is greater than the first time threshold (and the second time threshold).
[0222] It is understandable that since the exempted thread is highly correlated with user interaction, suspending the execution of the exempted thread may affect device performance and user experience, such as the occurrence of freezes when refreshing the interface. Therefore, if the continuous running time of the exempted thread is greater than the second time threshold, lowering the priority type of the exempted thread to a non-real-time priority can ensure the normal operation of the exempted thread. Alternatively, if the continuous running time of the exempted thread is greater than the second time threshold, lowering the priority of the threads in the thread group where the exempted thread is located can ensure the normal operation of each thread in the thread group where the exempted thread is located.
[0223] In some embodiments, the electronic device 100 may cancel the control of the exempted thread when detecting that the exemption control cancellation condition (as an example of the second exemption control cancellation condition) is met. The exemption control cancellation condition may include at least one of the following conditions: the duration of reducing the priority of the exempted thread is greater than the third duration, the second scheduling cycle ends, etc.
[0224] It is understood that the second scheduling period is a time period preset by the electronic device, indicating a time slice for the processor to run a thread, such as 100 milliseconds, 150 milliseconds, 200 milliseconds, etc. It is understood that the second scheduling period may also be other durations, which are not limited here.
[0225] Specifically, the management of exemptions can refer to the above Figure 2 、 Figure 3 and Figure 4 The relevant steps of managing the target thread in are not described in detail in this application.
[0226] In summary, the thread management method provided in the embodiments of the present application can manage and control the execution of threads with a real-time priority type. This prevents the situation where, in a scenario where there are too many threads with a real-time priority type, an electronic device continuously runs some threads with a real-time priority type, preventing other threads from running. This avoids thread blocking and reduces the impact on the running of applications on the electronic device.
[0227] In order to better understand the technical solution of the embodiment of the present application, the following describes a method for determining a thread with a real-time priority priority type with reference to the accompanying drawings.
[0228] For example, Figure 6 According to an embodiment of the present application, a schematic diagram of an implementation process for determining a thread with a priority type of real-time priority is shown. It can be understood that Figure 6 Each step of the process shown is performed by the electronic device 100. Figure 6 The execution entities of each step will not be repeatedly described in the steps of the process shown.
[0229] like Figure 6 As shown, the process includes but is not limited to the following steps:
[0230] S601: Acquire the QoS information marked on each thread by the developer of each application program, and map the QoS information of each thread into priority information.
[0231] It is understood that application developers can call the QoS level marking interface to mark the QoS level of threads executing various tasks of the application. The electronic device 100 can obtain the QoS level of each thread marked by the developer and map the QoS level to a priority. The higher the QoS level of a thread, the higher the priority of the corresponding thread.
[0232] In some embodiments, the electronic device determines that the priority type of a thread with a QoS level greater than or equal to a preset level is a real-time priority, and the priority type of a thread with a QoS level less than the preset level is a non-real-time priority.
[0233] For example, taking the QoS levels shown in Table 1 as an example, assuming the preset level is 5, the priority type of threads with a QoS level greater than or equal to 5 is real-time priority, and the priority type of threads with a QoS level less than 5 is non-real-time priority. Assuming the preset level is 4, the priority type of threads with a QoS level greater than or equal to 4 is real-time priority, and the priority type of threads with a QoS level less than 4 is non-real-time priority. This application does not impose specific restrictions on this.
[0234] S602: Identify threads corresponding to the running application program and determine key threads corresponding to the user interaction scenario.
[0235] In some embodiments, the electronic device 100 interactively identifies the running application and uses the thread whose application scenario is determined to be a user interaction scenario, that is, the thread whose task type is a user interaction task, as the key thread.
[0236] For example, the electronic device 100 performs an instrumentation operation in the system service of each running application to determine whether the application scenario of each thread corresponding to each running application is a user interaction scenario. For example, upon recognizing a user interaction operation such as a click or a slide, the application scenario of the corresponding thread is determined to be a user interaction scenario.
[0237] In other embodiments, the electronic device 100 first performs interaction identification on running applications to identify threads whose application scenarios are user interaction scenarios. Then, the electronic device 100 performs application identification on applications that have threads whose application scenarios are user interaction scenarios to identify threads corresponding to applications that need to ensure high supply and whose application scenarios are user interaction scenarios as key threads.
[0238] It is understood that for some applications with very low load, the performance of the applications has already met the requirements based on the default provisioning, and there is no need for full high provisioning. If the threads corresponding to these applications are fully high provisioned, the power consumption of the electronic device 100 will increase. Therefore, the electronic device 100 does not designate the threads corresponding to these applications as critical threads.
[0239] S603: Based on the key threads and the threads with priority information mapped based on the QoS information, determine a thread with a real-time priority type.
[0240] In some embodiments, the electronic device 100 filters and supplements threads with a real-time priority priority based on QoS information mapping based on key threads to obtain filtered threads with a real-time priority priority priority.
[0241] For example, based on the QoS information mapping, threads with a real-time priority type include: threads 11, 12, and 13 of application 10. Electronic device 100 determines that the critical threads are threads 11, 12, and 13 of application 10, and threads 21 and 22 of application 20. Then, electronic device 100 determines that the threads with a real-time priority type after screening are threads 11, 12, and 13 of application 10, and threads 21 and 22 of application 20.
[0242] In other embodiments, the electronic device 100 may also determine threads with a real-time priority type (i.e., managed threads) based on critical threads, threads based on priority information mapped with QoS information, and exempted threads. For example, threads with a real-time priority type based on QoS information mapping include: threads 11 and 12 of application 10. The critical threads determined by the electronic device 100 are threads 11, 12, 13, and 14 of application 10, and the exempted threads are threads 14 of application 10. Then the electronic device 100 determines that the threads with a real-time priority type after screening are threads 11, 12, and 13 of application 10.
[0243] It can be understood that by identifying the user interaction operation, it is determined that the thread (critical thread) whose task type is the user interaction task is executed. Based on the critical thread, the threads whose priority type is real-time priority based on the QoS information mapping are screened and supplemented to obtain the screened threads whose priority type is real-time priority. This can avoid the problem that due to inaccurate marking by developers, threads greater than or equal to the preset level are marked with a QoS level lower than the preset level, and then mapped to non-real-time priority, thereby avoiding affecting the user interaction experience.
[0244] It is understood that threads do not run continuously, for example, Figure 7 FIG. 1 is a schematic diagram of the running status of thread A and thread B of the first thread group.
[0245] like Figure 7 As shown, within time interval T, thread A includes frames A1, A2, and A3, and the frame length between frames A1 and A2 is frame length a1, and the frame length between frames A2 and A3 is frame length a2. The frame length end time of frame length a1 is frame length a1 end time t1, and the frame length end time of frame length a2 is frame length a2 end time t2.
[0246] Thread B includes frames B1, B2, and B3. The frame length between frames B1 and B2 is frame length b1, and the frame length between frames B2 and B3 is frame length b2. The frame length end time of frame length b1 is t3, the end time of frame length b2 is t4, the end time of frame length b2 is t4.
[0247] It can be understood that in order to improve the utilization of hardware resources, the electronic device 100 can ensure a high supply of resources only during the time interval when each thread with a real-time priority type is running.
[0248] For example, in some embodiments, the electronic device 100 obtains historical execution information of each thread in the thread management queue, such as the start and end continuous running time of each frame of each thread. Based on the historical execution information of each thread in the thread management queue, the electronic device 100 adjusts the scheduling parameters of each thread during the continuous running time period to ensure resource supply during the thread running time interval.
[0249] The scheduling parameters include, but are not limited to, the physical cores that execute the threads, and the frequencies and voltages corresponding to the physical cores.
[0250] In order to better understand the technical solutions of the embodiments of the present application, the structure of the equipment involved in the present application is introduced below with reference to the accompanying drawings.
[0251] For example, Figure 8 According to an embodiment of the present application, a schematic block diagram of a software system architecture of an electronic device 100 is shown.
[0252] The software system architecture of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the Android system with a layered architecture is used as an example to illustrate the software structure of the electronic device 100.
[0253] Figure 8 The layered architecture of the electronic device 100 shown divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other via software interfaces. In some embodiments, the Android system is divided into three layers: the application framework layer, the system library layer, and the kernel layer, from top to bottom.
[0254] like Figure 8 As shown, the application framework layer may include application programs and application frameworks.
[0255] Applications may include a series of application packages. These packages may include applications such as camera, gallery, calendar, call, map, navigation, Bluetooth, music, short message, and video. Applications may be pre-installed on electronic device 100 or installed by the user based on their needs. For example, if a user needs to conduct an online meeting, they may install online meeting-related applications on electronic device 100 through an application store or other means. In some embodiments, applications also have the function of obtaining marked threads.
[0256] The application framework may include a window manager, content provider, view system, telephony manager, resource manager, notification manager, etc.
[0257] The window manager is used to manage window programs. It can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0258] Content providers are used to store and retrieve data and make it accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0259] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0260] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering, hanging up, etc.).
[0261] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0262] The notification manager enables applications to display notification information in the status bar, which can be used to convey informational messages and disappear automatically after a short stay without user interaction.
[0263] The system library includes a QoS management module and a scene recognition module.
[0264] Among them, the QoS management module is used to obtain the QoS level information marked by the developers of each application, and send the marked QoS level information to the QoS control module of the kernel layer, which maps the QoS level.
[0265] The scene recognition module is used to obtain interaction information and application information corresponding to each running application from the application framework corresponding to the running application, and to add / delete performance scheduling groups based on the results of interaction recognition and application recognition.
[0266] For example, in some embodiments, the scenario recognition module first performs interaction recognition on running applications to identify threads whose application scenarios are user interaction scenarios. Next, it performs application recognition on applications with threads whose application scenarios are user interaction scenarios, identifies threads corresponding to applications requiring high supply and whose application scenarios are user interaction scenarios as critical threads, and adds these critical threads to the performance scheduling group.
[0267] The scene recognition module is also used to obtain the frame status information corresponding to each running application from the application framework corresponding to the running application. Based on the application recognition results and the frame status recognition results, it performs historical load prediction, adjusts scheduling parameters, and issues frame status.
[0268] For example, in some embodiments, the scene recognition module identifies running applications and determines the threads corresponding to applications that require high resource availability. It also identifies the frame state of the threads corresponding to applications that require high resource availability, obtains historical execution information for each thread in the thread management queue (performs historical load prediction), and adjusts the scheduling parameters for each thread during its continuous operation period based on the historical execution information for each thread in the thread management queue. The frame state information (or scheduling parameter adjustment information) is sent to the performance scheduling module at the kernel layer to ensure resource availability during the thread's operating time interval.
[0269] In other embodiments, the system library further includes multiple functional modules, such as a surface manager (SM), media libraries (ML), a 3D graphics processing library (e.g., OpenGL ES), a 2D graphics engine (e.g., SGL), etc.
[0270] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0271] The kernel layer is the layer between hardware and software. The kernel layer includes the QoS control module and the performance scheduling module.
[0272] Among them, the QoS control module is used to map the QoS level, determine the thread with real-time priority type based on the QoS information mapping, and send the mapped thread priority information to the performance scheduling module.
[0273] The performance scheduling module is used to screen and supplement threads with a priority type of real-time priority based on QoS information mapping based on key threads, and obtain threads with a priority type of real-time priority after screening.
[0274] The performance scheduling module is also used to adjust the scheduling parameters corresponding to the threads with real-time priority based on the frame state information, and complete the scheduling of each thread.
[0275] In other embodiments, the kernel layer also includes a display driver, a camera driver, an audio driver, a sensor driver, etc.
[0276] Specifically, Figure 9 According to an embodiment of the present application, a schematic diagram of module interaction of a software system of an electronic device 100 is shown.
[0277] like Figure 9 As shown, the application of the application framework layer will mark the thread, for example, the QoS level information marked by the developer of each application is sent to the QoS management module of the system library for QoS level marking.
[0278] The QoS management module of the system library obtains the QoS level information marked by the developers of each application, and sends the marked QoS level information to the QoS control module of the kernel layer, which maps the QoS level.
[0279] The QoS control module of the kernel layer maps the QoS levels, determines the threads with real-time priority based on the priority type mapped by the QoS information, and sends the mapped thread priority information to the performance scheduling module.
[0280] The application framework of the application framework layer sends the interaction information, application information, drawing frame status information, etc. corresponding to each running application to the scene recognition module of the system library.
[0281] The system library's scenario recognition module performs interaction recognition on running applications, identifying threads whose application scenarios are user interaction scenarios. Furthermore, it performs application recognition on applications with threads whose application scenarios are user interaction scenarios, identifying threads corresponding to applications requiring high supply and with user interaction scenarios as critical threads. These critical threads are then added to the performance scheduling group. At the same time, non-critical threads in the performance scheduling group are deleted.
[0282] The scene recognition module of the system library can also identify running applications and determine the threads corresponding to applications that need to ensure high supply. It also identifies the frame status of the threads corresponding to applications that need to ensure high supply, obtains the historical execution information of each thread in the thread management queue (performs historical load prediction), and adjusts the scheduling parameters of each thread during the continuous running time period based on the historical execution information of each thread in the thread management queue. The frame status information (or scheduling parameter adjustment information) is sent to the performance scheduling module of the kernel layer to ensure resource supply within the time interval of thread operation.
[0283] Based on key threads, the kernel layer's performance scheduling module filters and supplements real-time priority threads mapped based on QoS information, obtaining filtered real-time priority threads. For example, it adds the filtered real-time priority threads to the corresponding thread group (adding a group), or removes threads from the thread group that are not real-time priority threads (delisting a group).
[0284] The performance scheduling module of the kernel layer can also adjust the scheduling parameters corresponding to the threads with real-time priority based on the frame drawing state information, and complete the performance scheduling of each thread.
[0285] An embodiment of the present application also provides a thread management method, in which the electronic device 100 controls threads of real-time priority type whose running time meets the above conditions based on priority control conditions, running control conditions and cancellation control conditions.
[0286] For example, Figure 10 According to an embodiment of the present application, a flowchart of another thread management method is shown. It can be understood that Figure 10 Each step of the process shown is performed by the electronic device 100. Figure 10 The execution entities of each step will not be repeatedly described in the steps of the process shown.
[0287] S1001: Determine a target thread based on the running time and priority control conditions of a thread with a real-time priority type.
[0288] In some embodiments, the priority management conditions may include at least one of the following conditions: the continuous running time of the thread is greater than the first time threshold, the continuous running time of the thread in the first scheduling cycle is greater than the first time threshold, there are threads in the thread group where the thread is located whose continuous running time is greater than the first time threshold, there are threads in the thread group where the thread is located whose continuous running time in the first scheduling cycle is greater than the first time threshold, the sum of the running times of each thread in the thread group where the thread is located in the first scheduling cycle is greater than the first time threshold, etc.
[0289] For the specific method of determining the target thread, please refer to the above Figure 2 、 Figure 3 and Figure 4 The relevant description in is not repeated here.
[0290] S1002: Lower the priority of the target thread.
[0291] In some embodiments, the electronic device 100 sets the priority type of the target thread to a non-real-time priority, that is, changes the priority type from the real-time priority to the non-real-time priority.
[0292] S1003: Detecting the existence of a target thread that meets the operation control condition, suspending the target thread that meets the operation control condition.
[0293] In some embodiments, the operation control conditions may include at least one of the following conditions: the continuous running time of the thread is greater than the second time threshold, the continuous running time of the thread in the first scheduling cycle is greater than the second time threshold, there are threads in the thread group where the thread is located whose continuous running time is greater than the second time threshold, there are threads in the thread group where the thread is located whose continuous running time in the first scheduling cycle is greater than the second time threshold, the sum of the running times of each thread in the thread group where the thread is located in the first scheduling cycle is greater than the second time threshold, etc.
[0294] Specifically, please refer to the above Figure 2 、 Figure 3 and Figure 4 The relevant description in is not repeated here.
[0295] S1004: It is detected that the control cancellation condition is met, and the control of the target thread is canceled.
[0296] In some embodiments, the control cancellation conditions may include at least one of the following conditions: the duration of lowering the priority of the target thread is greater than the first duration, the duration of suspending the target thread is greater than the second duration, the end of the first scheduling cycle, etc.
[0297] Specifically, please refer to the above Figure 2 、 Figure 3 and Figure 4 The relevant description in is not repeated here.
[0298] The hardware structure of the electronic device 100 in the embodiment of the present application is described below with reference to the accompanying drawings.
[0299] For example, Figure 11 A schematic structural diagram of an electronic device 100 is shown according to an embodiment of the present application.
[0300] like Figure 11 As shown, the electronic device 100 may include a processor 110, a memory 120, an interface module 130, a power module 140, a wireless communication module 150, a mobile communication module 160, an audio module 170, a sensor module 180, a button 190, a camera 191, a display screen 192, etc.
[0301] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0302] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors. The processor 110 may be used to execute the thread management method provided in the embodiments of the present application.
[0303] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0304] The interface module 130 may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0305] The power module 140 is connected to the processor 110 and provides power to the processor 110 , the memory 120 , the camera 191 , the display screen 192 , and the mobile communication module 160 .
[0306] The wireless communication function of the electronic device 100 can be implemented through the wireless communication module 150, the mobile communication module 160, the antenna, the modem processor and the baseband processor.
[0307] The wireless communication module 150 can provide wireless communication solutions applied to the electronic device 100, including wireless local area network (such as Wi-Fi network), Bluetooth, global navigation satellite system (GNSS), frequency modulation (FM), NFC, infrared technology, etc.
[0308] The mobile communication module 160 can provide wireless communication solutions including 2G / 3G / 4G / 5G applied on the electronic device 100.
[0309] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals.
[0310] The sensor module 180 may include a pressure sensor, a gyro sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
[0311] The electronic device 100 implements the display function through a GPU, a display screen 192 , and an application processor.
[0312] Display screen 192 is used to display images, videos, and the like. Display screen 192 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a mini-LED, a micro-LED, a micro-o-LED, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or N display screens 192, where N is a positive integer greater than one.
[0313] The electronic device 100 can implement a shooting function through an ISP, a camera 191, a video codec, a GPU, a display screen 192, and an application processor.
[0314] The camera 191 is used to capture still images or videos. In some embodiments, the electronic device 100 may include 1 or N cameras 191, where N is a positive integer greater than 1.
[0315] The memory 120 can be used to store computer executable program code, which includes instructions. The memory 120 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the memory 120 and / or processing instructions stored in a memory provided in the processor.
[0316] The buttons 190 include a power button, a volume button, etc. The buttons 190 can be mechanical buttons or touch buttons.
[0317] In some embodiments, a computer-readable storage medium is also provided, in which at least one instruction, at least one program, code set or instruction set is stored. The at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the thread management method provided by the above-mentioned various method embodiments.
[0318] In some embodiments, a program product is also provided, which includes instructions. When the instructions are executed by an electronic device, the electronic device can implement the thread management method provided in the embodiments of the present application.
[0319] The various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.
[0320] Program code can be applied to input instructions to perform the functions described herein and generate output information. The output information can be applied to one or more output devices in a known manner. For purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0321] Program code can be implemented with a high-level programming language or an object-oriented programming language to communicate with the processing system. Where necessary, program code can also be implemented in assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any particular programming language. In either case, the language can be a compiled language or an interpreted language.
[0322] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, a machine-readable medium may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including but not limited to a floppy disk, an optical disk, an optical disk, a magneto-optical disk, a read-only memory (ROM), a random access memory (RAM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic card or an optical card, a flash memory, or a tangible machine-readable memory for transmitting information (e.g., a carrier wave, an infrared signal, a digital signal, etc.) using the Internet in an electrical, optical, acoustic, or other form of propagation signal. Accordingly, machine-readable media includes any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).
[0323] In the accompanying drawings, some structural or method features may be shown in a particular arrangement and / or order. However, it should be understood that such a particular arrangement and / or order may not be required. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of a structural or method feature in a particular figure does not imply that such feature is required in all embodiments, and in some embodiments, such features may not be included or may be combined with other features.
[0324] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems raised by this application. In addition, in order to highlight the innovative part of this application, the above-mentioned device embodiments of this application do not introduce units / modules that are not closely related to solving the technical problems raised by this application. This does not mean that other units / modules do not exist in the above-mentioned device embodiments.
[0325] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "including a" does not exclude the presence of other identical elements in the process, method, article or device that includes the element.
[0326] Although the present application has been shown and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the application.
Claims
1. A thread management method, applied to electronic equipment, characterized in that: include: Get a plurality of first threads currently running with a first priority; Selecting a target thread whose running time satisfies a first priority control condition from the multiple first threads; The priority level of the target thread is downgraded from a first priority level to a second priority level.
2. The method according to claim 1, characterized in that The first priority control condition includes at least one of the following: The continuous running time of the first thread is greater than a first time threshold; The continuous running time of the first thread in the first scheduling period is greater than a first time threshold; There is a thread in the thread group where the first thread belongs, whose continuous running time is greater than a first time threshold; There is a thread in the thread group where the first thread belongs, the continuous running time of which in the first scheduling period is greater than the first time threshold; The sum of the running times of the threads in the thread group where the first thread belongs in the first scheduling period is greater than a first time threshold.
3. The method according to claim 2, characterized in that The method further comprises: It is detected that the target thread meets the operation control condition, and the target thread that meets the operation control condition is suspended.
4. The method according to claim 3, characterized in that The operation control conditions include at least one of the following: The continuous running time of the target thread is greater than a second time threshold; The target thread continues to run for a time greater than a second time threshold in the first scheduling period; There exists a thread in the thread group where the target thread is located whose continuous running time is greater than a second time threshold; There exists a thread in the thread group where the target thread is located, the continuous running time of which in the first scheduling period is greater than a second time threshold; The sum of the running time of each thread in the thread group where the target thread is located in the first scheduling period is greater than a second time threshold, wherein the second time threshold is greater than the first time threshold.
5. The method according to claim 3 or 4, characterized in that The method further comprises: It is detected that the target thread meets the first control cancellation condition, and the control of the target thread is cancelled, wherein: The canceling of the control of the target thread includes at least one of the following: Corresponding to the target thread whose priority is reduced to the second priority, restoring the target thread to the first priority; Corresponding to the suspended target thread, the suspended target thread is resumed.
6. The method according to claim 5, characterized in that The first cancellation control condition includes at least one of the following: The duration of lowering the priority of the target thread is greater than the first duration; The duration of suspending the target thread is greater than the second duration; The first scheduling period ends.
7. The method according to any one of claims 1 to 6, characterized in that The plurality of first threads having a first priority include at least one of the following: Among the threads running on the electronic device, threads having a quality of service (QoS) level greater than or equal to a preset level; Among the threads running in the electronic device, the corresponding task type to be executed is a thread of a user interaction task.
8. The method according to any one of claims 1 to 6, characterized in that The plurality of first threads having the first priority further include at least one of the following: Among the threads running on the electronic device, threads with a QoS level greater than or equal to a preset level, other threads except preset exempted threads; Among the threads running in the electronic device, among the threads whose corresponding task type is a user interaction task, other threads except the preset exemption thread.
9. The method according to claim 8, characterized in that The method further comprises: Upon detecting that a preset exemption thread running in the electronic device meets a second priority control condition, the priority of the preset exemption thread is downgraded from the first priority to the second priority, wherein the second priority control condition includes at least one of the following: The continuous running time of the exempted thread is greater than a third time threshold; The continuous running time of the exempted thread in the second scheduling period is greater than a third time threshold; There is a thread in the thread group where the exempted thread is located, the continuous running time of which is greater than a third time threshold; There is a thread in the thread group where the exempted thread belongs, whose continuous running time in the second scheduling period is greater than the third time threshold; The sum of the running time of each thread in the thread group where the exempted thread is located in the second scheduling period is greater than the third time threshold.
10. The method according to claim 9, characterized in that The method further comprises: In response to the preset exempt thread whose priority is reduced to the second priority meeting a second cancellation control condition, the priority of the preset exempt thread is restored to the first priority, wherein the second cancellation control condition includes at least one of the following: The duration of lowering the priority of the exempted thread is greater than the third duration; The second scheduling period ends.
11. A readable medium, characterized in that The readable medium stores instructions, which, when executed on an electronic device, enable the electronic device to execute the method according to any one of claims 1 to 10.
12. An electronic device, characterized in that: include: a memory for storing instructions to be executed by one or more processors of the electronic device, and The processor is one of the processors of an electronic device, and is configured to execute the method according to any one of claims 1 to 10.
13. A program product, characterized in that The program product includes instructions, and when the instructions are executed on an electronic device, the electronic device implements the method according to any one of claims 1 to 10.