Thread priority adjustment method and related device
By identifying and adjusting the priority of associated threads of child processes, the problem of the inability to reasonably adjust the priority of child process threads in terminal devices was solved, improving system response speed and performance, and enhancing user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2024-05-30
- Publication Date
- 2026-05-26
Smart Images

Figure CN119917280B_ABST
Abstract
Description
[0001] This application is a divisional application. The original application has the application number 202410700693.9 and the original application date is May 30, 2024. The entire contents of the original application are incorporated herein by reference. Technical Field
[0002] This application relates to the field of smart terminal technology, and in particular to thread priority adjustment methods and related devices. Background Technology
[0003] In current terminal scenarios, there are numerous applications (APPs). When a terminal device runs the main process of an APP, it creates one or more child processes to work in conjunction with the main process and provide services to the APP. Since a process can include multiple threads, each thread has different user interaction relationships, meaning users have different expected response times. For example, the UI thread for user interaction tasks needs to complete promptly, the thread for page loading tasks needs to be as fast as possible, and the thread for downloading and backup-related tasks can be postponed to a later time. Therefore, different threads have different priorities. It is necessary to allocate thread priorities reasonably according to user needs. Setting threads for important tasks as higher priorities can ensure that these tasks are processed in a timely manner, thereby improving the system's response speed and performance. Summary of the Invention
[0004] This application provides a thread priority adjustment method and related devices, which can improve the system's response speed and performance, thereby enhancing the user experience.
[0005] In a first aspect, embodiments of this application provide a thread priority adjustment method applied to an electronic device. The method includes: running a first application; a first process of the first application including multiple first threads; identifying associated threads of the first threads from the threads of a second process; the second process being a process running on the electronic device other than the first process and resident processes, and providing services to the first application; detecting a change in the running state of the first application, adjusting the priority of the first threads, and adjusting the priority of the associated threads, wherein the priority adjustment trend of the associated threads is consistent with the priority adjustment trend of the first threads.
[0006] In this embodiment, when the electronic device runs the main process (i.e., the first process) of the first application, it also runs one or more child processes (i.e., the second process) to work in conjunction with the main process and provide services to the first application. Since a process can include multiple threads, each thread has a different user interaction relationship, meaning the user expects different response times. Therefore, different threads have different priorities, and the thread priorities need to be adjusted reasonably according to user needs. Setting threads for important tasks to higher priorities ensures that these tasks are processed in a timely manner. The application can adjust the priority of each first thread in the main process according to the application scenario requirements. However, for multiple child processes, which are system-launched processes, the application cannot perceive the threads of the child processes and therefore cannot adjust the thread priorities of the child processes, resulting in the inability to reasonably adjust the thread priorities of the child processes according to user needs. In this application, by identifying the associated threads of the first thread from the threads of one or more child processes, and then detecting a change in the running state of the first application (which can be understood as a change in user needs), the associated threads adjust their priorities according to the first thread. For multiple threads within the same subprocess, each thread may be associated with a different first thread. Therefore, when a change in the running state of the first application is detected, the priority adjustment trend of multiple threads within the same subprocess is determined by the associated first thread and can be different. This avoids the application being unaware of the threads in the subprocess, which would prevent it from adjusting the thread priority of the subprocess reasonably according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0007] In some embodiments, when the second process is created by the first process and the first thread is the main thread of the first process, identifying the associated thread of the first thread includes: identifying the main thread of the second process as the associated thread of the first thread.
[0008] In this embodiment, when the second process (i.e., the child process) is created by the first process (i.e., the main process), the main thread of the child process will inherit the main thread of the main process. The main thread of the child process usually performs tasks similar to those of the main thread of the main process. Therefore, the main thread of the main process and the main thread of the child process can be identified as related threads. The related threads can then follow the first thread for priority adjustment. Thread scheduling can be performed according to this priority, which can ensure that important tasks can be processed in a timely manner, thereby improving the system's response speed and performance, and enhancing the user experience.
[0009] In some embodiments, identifying the associated thread of the first thread includes: identifying from the threads of the second process a thread that has the same task as the first thread as the associated thread of the first thread.
[0010] In this embodiment, from the threads of one or more subprocesses (i.e., the second threads), the threads that have the same task as the first thread are identified as associated threads of the first thread. The associated threads can then follow the first thread for priority adjustment and be scheduled according to the priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, which can ensure that the task is responded to faster, thereby improving the system's response speed and performance and enhancing the user experience.
[0011] In some embodiments, the first thread communicates with the first module, and the method further includes: determining the thread in the second process that communicates with the first module as the thread with the same task as the first thread.
[0012] In this embodiment, when multiple threads communicate with the same module (i.e., the first module), these threads are all executing the same code logic and may be performing the same tasks. Therefore, these threads can be associated, and the associated threads can follow the first thread for priority adjustment. Thread scheduling is performed according to the priority, and all threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, which can ensure that the task is responded to faster, thereby improving the system's response speed and performance and enhancing the user experience.
[0013] In some embodiments, the first module is a rendering module running on an electronic device; or, the first module is a window management module running on an electronic device; or, the first module is a component management module running on an electronic device.
[0014] In this embodiment, when the first thread accesses the rendering module, other threads interacting with the rendering module can be identified as associated threads of the first thread, all of which are performing the same or similar rendering tasks. When the first thread accesses the window management module, other threads interacting with the window management module can be identified as associated threads of the first thread, all of which are performing the same or similar window drawing tasks. When the first thread accesses the component management module, other threads interacting with the component management module can be identified as associated threads of the first thread, all of which are performing the same or similar drawing tasks. Furthermore, associated threads can follow the first thread in priority adjustment, and thread scheduling is performed according to this priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, ensuring that tasks are responded to faster, thereby improving the system's response speed and performance, and enhancing the user experience.
[0015] In some embodiments, when the first module is a window management module, determining the thread in the second process that communicates with the first module as the thread with the same task as the first thread includes: determining the thread in the second process that communicates with the window management module and performs the same window drawing task as the first thread as the thread with the same task as the first thread.
[0016] In this embodiment, multiple threads communicating with the window management module may be drawing the same window or different windows. To more accurately identify the associated threads of the first thread, threads performing the same window drawing task as the first thread are identified as threads with the same task as the first thread, thus associating threads drawing the same window. Furthermore, associated threads can follow the first thread in priority adjustment, and thread scheduling is performed based on this priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, ensuring faster task response, thereby improving system response speed and performance, and enhancing user experience.
[0017] In some embodiments, before identifying the associated thread of the first thread, the method further includes: setting the priority of the first thread based on a first mapping table and user interaction relationship values of the first thread; the first mapping table includes a mapping relationship between user interaction relationship values and priorities.
[0018] In this embodiment, the first process may include multiple first threads, each capable of executing different tasks. In different application scenarios, the application can set user interaction relationship values for the first threads as needed. Then, the electronic device can set the priority of the first threads based on the first mapping table and the user interaction relationship values of the first threads. This allows for the reasonable configuration of first thread priorities according to user needs. Setting threads for important tasks with higher priorities ensures these tasks are processed promptly, improving the user experience.
[0019] In some embodiments, after identifying the associated thread of the first thread, the method further includes: setting the priority of the associated thread based on the priority of the first thread.
[0020] In this embodiment, the priority of associated threads can be adjusted based on the priority of the main process's threads, where the priority of the main process's threads is set based on user requirements. Since the priority of associated threads is determined by the priority of the main process's threads, the priority of associated threads can also meet user needs, avoiding the application's inability to perceive the threads of child processes, which would prevent the reasonable configuration of child process thread priorities according to user needs, thereby improving system response speed and performance, and enhancing user experience.
[0021] In some embodiments, the method further includes: detecting a change in the running state of the first application and modifying the user interaction relationship value of the first thread.
[0022] In this embodiment of the application, when a change in the running state of the first application is detected, i.e., a change in user needs, the first application can adjust the priority of the first thread by modifying the user interaction relationship value of the first thread, thereby adjusting the thread priority of the first process according to user needs and improving the user experience.
[0023] In some embodiments, detecting a change in the running state of the first application and adjusting the priority of the first thread and the priority of the associated thread includes: detecting a change in the running state of the first application and adjusting the priority of the first thread and the priority of the associated thread based on the modified user interaction relationship value of the first thread and the first mapping table.
[0024] In this embodiment, when a change in the running state of the first application is detected, i.e., a change in user needs, the first application can adjust the priority of the first thread based on the modified user interaction relationship value of the first thread. Furthermore, associated threads can follow the first thread in priority adjustment, preventing the application from being unaware of the threads of its child processes, which could prevent the application from reasonably adjusting the thread priorities of child processes according to user needs. This improves system response speed and performance, and enhances user experience.
[0025] In some embodiments, a larger user interaction relationship value in the first mapping table indicates a higher priority for the corresponding thread; when the running state of the first application changes from a foreground state to a background state or a frozen state, the user interaction relationship value of the first thread decreases, and the priority of the first thread and the priority of the associated thread decrease; when the running state of the first application changes from a background state or a frozen state to a foreground state, the user interaction relationship value of the first thread increases, and the priority of the first thread and the priority of the associated thread increase.
[0026] In this embodiment, when the first application switches from the foreground state to the background state or the frozen state, the priority of the first thread and the priority of the associated thread can be reduced to ensure that the foreground application of the current electronic device can respond faster; when the first application switches from the background state or the frozen state to the foreground state, the priority of the first thread and the priority of the associated thread can be increased to ensure that the first application can respond faster, thereby improving the user experience.
[0027] In some embodiments, the electronic device includes a processor, and the method further includes: determining the aggregated load of a first thread and an associated thread, the aggregated load being the product of the processor's current frequency and a first duty cycle; the first duty cycle being the percentage of the total duration of the first thread and the associated thread in the processor's frequency modulation cycle; and adjusting the processor's main frequency based on the aggregated load.
[0028] In this embodiment, when a thread is scheduled to run on the processor, the aggregated load can be calculated based on the total running duration of the thread and its associated threads. Then, the processor's clock frequency can be adjusted based on the calculated aggregated load, thereby ensuring the thread's running speed while saving energy and improving the user experience.
[0029] In some embodiments, adjusting the processor's clock frequency based on aggregated load includes: determining whether the aggregated load is greater than a first threshold; if the aggregated load is greater than the first threshold and if the aggregated load is greater than a second threshold, then increasing the processor's clock frequency; if the aggregated load is greater than the first threshold and the aggregated load is less than or equal to the second threshold, then decreasing or not adjusting the processor's clock frequency.
[0030] In this embodiment, the first threshold can be a user-preset value or an empirical value, representing the frequency point corresponding to the energy consumption the system can accept. When the aggregated load is greater than the first threshold, it indicates that the first thread and its associated threads correspond to a high-load task. High-load tasks are generally important tasks, so the system will be more inclined to ensure the performance of the first thread and its associated threads, and thus can adjust the processor's main frequency point based on the aggregated load. Furthermore, when the aggregated load is greater than the second threshold, it indicates that the processor is currently running the first thread and its associated threads most of the time, so the processor's main frequency point can be increased, allowing the processor to run the first thread and its associated threads more quickly; when the aggregated load is less than or equal to the second threshold, it indicates that the processor has a lot of spare time after running the first thread and its associated threads, so the processor's main frequency point can be decreased or not adjusted to save processor energy.
[0031] In some embodiments, the method further includes: if the aggregated load is less than or equal to a first threshold, determining a first load of the first thread, wherein the first load is the product of the current frequency of the processor and a second duty cycle; the second duty cycle is the proportion of the duration of the first thread in the frequency adjustment cycle of the processor; and adjusting the main frequency of the processor based on the first load.
[0032] In this embodiment of the application, when the aggregated load is less than or equal to the first threshold, it indicates that the first thread and its associated threads correspond to a low-load task. Low-load tasks are generally ordinary tasks. In this case, the system will be more inclined to save processor power consumption. The first load can be calculated based on the duration of the first thread's operation, and the processor's main frequency can be adjusted based on the calculated first load, thereby saving processor power consumption and improving user experience.
[0033] Secondly, a frequency modulation method is provided, applied to an electronic device, the electronic device including a processor. The method includes: running a first application; a first process of the first application including multiple first threads; identifying associated threads of the first threads from the threads of a second process; the second process being a process running on the electronic device other than the first process and resident processes, and providing services to the first application; determining the aggregated load of the first threads and associated threads, the aggregated load being the product of the processor's current frequency and a first duty cycle; the first duty cycle being the proportion of the total duration of the first threads and associated threads in the processor's frequency modulation cycle; and adjusting the processor's main frequency based on the aggregated load.
[0034] In this embodiment, when a thread is scheduled to run on the processor, the aggregated load can be calculated based on the total running duration of the thread and its associated threads. Then, the processor's main frequency can be adjusted based on the calculated aggregated load. That is, the frequency adjustment is performed by comprehensively considering the running status of the first thread and its associated threads, thereby ensuring the running speed of the thread while saving energy and improving the user experience.
[0035] In some embodiments, adjusting the processor's clock frequency based on aggregated load includes: determining whether the aggregated load is greater than a first threshold; if the aggregated load is greater than the first threshold, then adjusting the processor's clock frequency based on the aggregated load.
[0036] In some embodiments, adjusting the processor's clock frequency based on the aggregated load includes: increasing the processor's clock frequency when the aggregated load is greater than a second threshold; and decreasing or not adjusting the processor's clock frequency when the aggregated load is less than or equal to the second threshold.
[0037] In some embodiments, the method further includes: if the aggregated load is less than or equal to a first threshold, determining a first load of the first thread, wherein the first load is the product of the current frequency of the processor and a second duty cycle; the second duty cycle is the proportion of the duration of the first thread in the frequency adjustment cycle of the processor; and adjusting the main frequency of the processor based on the first load.
[0038] Thirdly, a thread priority adjustment method is provided, applied to an electronic device. The method includes: running a first application; the interface of the first application includes a first window corresponding to a first process and a second window corresponding to a second process, the second window being nested within the first window; the first process is the process of the first application; the second process is either the process of the first application or the process of the second application; the UI thread of the second process is an associated thread of the UI thread of the first process; detecting a change in the running state of the first application, adjusting the priority of the UI thread of the first process, and adjusting the priority of the associated thread, the priority adjustment trend of the associated thread being consistent with the priority adjustment trend of the UI thread of the first process.
[0039] In this embodiment, the interface of the first application may include multiple windows, such as a first window and a second window, wherein the second window is nested within the first window. Since the first window and the second window need to be rendered simultaneously, the UI thread corresponding to the first window and the UI thread corresponding to the second window can be associated. That is, the UI thread of the second process is used as the associated thread of the UI thread of the first process. Therefore, when a change in the running state of the first application is detected, which can be understood as a change in user needs, the UI thread of the second process adjusts its priority according to the UI thread of the first process. This avoids the application being unaware of the thread of the second process, thus preventing it from being unable to reasonably adjust the thread priority of the second process according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0040] In some embodiments, the component tree of the second process is mounted within the component tree of the first process. For example, the component tree of the first process has node identifiers used to mount the component tree of the second process. Thus, the electronic device can nest the interface of the second process within the interface of the first process.
[0041] In some implementations, the second process and the first process can belong to different applications.
[0042] In some implementations, the second process can be the process of an application that does not require installation.
[0043] In some implementations, the thread priority adjustment method provided by the third aspect can also execute some of the methods provided by the first aspect. For example, implementations related to priority or user interaction values, or implementations related to aggregated load.
[0044] Fourthly, a thread priority adjustment method is provided, applied to an electronic device. The method includes: running a first application; a first process of the first application includes multiple first threads; identifying associated threads of the first threads from the threads of a second process; wherein the first threads and associated threads are used to jointly render the interface of the first application; detecting a change in the running state of the first application, adjusting the priority of the first threads, and adjusting the priority of the associated threads, wherein the priority adjustment trend of the associated threads is consistent with the priority adjustment trend of the first threads.
[0045] In this embodiment, since the threads rendering the interface of the first application are performing similar tasks, threads in different processes that render the interface of the first application can be associated. That is, the threads in the second process that jointly render the interface of the first application with the first thread are identified as associated threads. Then, when a change in the running state of the first application is detected, which can be understood as a change in user needs, the associated threads follow the first thread to adjust their priorities. This avoids the application being unaware of the threads of the child processes, which would prevent the application from reasonably adjusting the thread priorities of the child processes according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0046] In some embodiments, both the first thread and the associated thread are used to send rendering instructions to the rendering module.
[0047] In some implementations, the second process can be a rendering process based on the web kernel.
[0048] In some implementations, the second process and the first process can belong to the same application.
[0049] In some implementations, the application can use frameworks such as Flutter, Vue, or React.
[0050] In some implementations, the thread priority adjustment method provided in the fourth aspect can also execute some of the methods in the embodiments provided in the first aspect. For example, embodiments related to priority or user interaction relationship values, or embodiments related to aggregated load.
[0051] Fifthly, an electronic device is provided, comprising: a memory and one or more processors; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, and the one or more processors calling the computer instructions to cause the electronic device to perform a method as described in the first aspect or any embodiment of the first aspect, perform a method as described in the second aspect or any embodiment of the second aspect, perform a method as described in the third aspect or any embodiment of the third aspect, or perform a method as described in the fourth aspect or any embodiment of the fourth aspect.
[0052] A sixth aspect provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform a method as described in the first aspect or any embodiment of the first aspect, or to perform a method as described in the second aspect or any embodiment of the second aspect, or to perform a method as described in the third aspect or any embodiment of the third aspect, or to perform a method as described in the fourth aspect or any embodiment of the fourth aspect.
[0053] In a seventh aspect, a computer program product is provided that, when the computer program product is run on a computer, causes the computer to perform the method as described in the first aspect or any one of the embodiments of the first aspect, or to perform the method as described in the second aspect or any one of the embodiments of the second aspect, or to perform the method as described in the third aspect or any one of the embodiments of the third aspect, or to perform the method as described in the fourth aspect or any one of the embodiments of the fourth aspect.
[0054] Eighthly, a chip system is provided, the chip system including at least one processor for implementing the method of the first aspect or any embodiment of the first aspect, or the method of the second aspect or any embodiment of the second aspect, performing the method of the third aspect or any embodiment of the third aspect, or performing the method of the fourth aspect or any embodiment of the fourth aspect. Attached Figure Description
[0055] Figure 1a This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0056] Figure 1b This is a software structure block diagram of the electronic device 100 according to an embodiment of this application.
[0057] Figure 2 This is a flowchart illustrating a thread priority adjustment method provided in an embodiment of this application.
[0058] Figure 3 This is a schematic diagram of the QoS value of the interaction between a first thread and a user, provided in an embodiment of this application.
[0059] Figure 4 This is a schematic diagram of a first mapping table provided in an embodiment of this application.
[0060] Figure 5 This is a schematic diagram of the main process and child processes of a first application provided in an embodiment of this application.
[0061] Figure 6 This is a schematic diagram illustrating the identification of associated threads, provided as an embodiment of this application.
[0062] Figure 7This is a schematic diagram illustrating another method for identifying associated threads, as provided in an embodiment of this application.
[0063] Figure 8 This is a schematic diagram illustrating another method for identifying associated threads, provided in an embodiment of this application.
[0064] Figure 9 This is a schematic diagram illustrating the adjustment of thread priority in a subprocess, as provided in an embodiment of this application.
[0065] Figure 10 This is a schematic diagram illustrating the adjustment of the priority of a first thread and associated threads, provided as an embodiment of this application.
[0066] Figure 11 This is a schematic diagram of a first threshold provided for this application.
[0067] Figure 12 This is a schematic diagram of a thread priority scheduling method provided in an embodiment of this application.
[0068] Figure 13 This is a flowchart illustrating a frequency modulation method provided in an embodiment of this application.
[0069] Figure 14 This is a flowchart illustrating a thread priority adjustment method provided in an embodiment of this application.
[0070] Figure 15 This is a schematic diagram of the interface of a first application provided in an embodiment of this application. Detailed Implementation
[0071] The embodiments of this application will now be described with reference to the accompanying drawings.
[0072] The terms "first," "second," "third," and "fourth," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0073] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0074] This application provides a thread priority adjustment method, which can be applied to electronic devices. Examples of electronic devices currently include: smartphones, tablets, laptops, PDAs, mobile internet devices (MIDs), wearable devices (such as smartwatches), virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving vehicles, 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, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to wireless modems, in-vehicle devices, wearable devices, terminal devices in 5G networks, or future public land mobile communication networks. Terminal devices in a network (PLMN), etc., are not limited to this in the embodiments of this application.
[0075] Before describing in detail the methods provided in the embodiments of this application, let’s first introduce the electronic devices provided in the embodiments of this application.
[0076] Figure 1a A schematic diagram of the structure of the electronic device 100 is shown.
[0077] Electronic device 100 may include processor 110, external memory interface 120, internal memory 121, universal serial bus (USB) interface 130, charging management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera module 193, display screen 194, and subscriber identification module (SIM) card interface 195, etc.
[0078] The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0079] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0080] Processor 110 may include one or more processing units, such as: application processor (AP), central processing unit (CPU), graphics processing unit (GPU), neural network processing unit (NPU), modem processor, image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, etc. Different processing units may be independent devices or integrated into one or more processors.
[0081] Processor 110 can load instructions or data stored in external memory (such as a disk) into internal memory 121, and retrieve instructions or data that need to be processed for computation in processor 110. After the computation is completed, processor 110 temporarily stores the result in internal memory 121, and stores instructions or data that need to be stored for a long time into external memory through the controller. Processor 110 can run different types of software such as operating systems, file systems (such as the flash file system F2FS), or applications to control multiple hardware or software components connected to processor 110, and can process various data and perform operations.
[0082] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the electronic device 100.
[0083] Display screen 194 is used to display user interfaces, images, videos, etc. Display screen 194 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 MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc.
[0084] The external memory interface 120 can be used to connect external storage devices, such as external memory cards, like Micro SD cards, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to perform data storage functions.
[0085] The internal memory 121 can be used to store one or more computer programs, which include instructions. The processor 110 can execute the instructions stored in the internal memory 121, thereby causing the electronic device 100 to perform the thread priority adjustment method provided in some embodiments of this application, as well as various functional applications and data processing. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system; it may also store one or more applications (such as Huawei Video, Contacts, etc.). The data storage area may store data created during the use of the electronic device 100 (such as user configuration and user interaction information). Furthermore, the internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0086] Understandable Figure 1a The electronic device structures described are merely some exemplary implementations provided in the embodiments of the present invention. The electronic devices in the embodiments of the present invention include, but are not limited to, the above implementations.
[0087] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses a layered mobile operating system as an example to exemplify the software structure of electronic device 100. The software system in this application can also be HarmonyOS, Android, iOS, or other similar systems.
[0088] Figure 1b This is a software structure block diagram of the electronic device 100 according to an embodiment of this application.
[0089] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the mobile operating system is divided into four layers, from top to bottom: the application layer, the framework layer, the system service layer, and the kernel layer.
[0090] The application layer can include a series of applications.
[0091] like Figure 1b As shown, the application package may include application 1 (APP1 can be a third-party application or a system application), gallery, calendar, call, navigation, WLAN, Bluetooth, music, video, SMS and other applications.
[0092] When the electronic device 100 is running the main process of APP1, one or more sub-processes running on the electronic device 100 work in conjunction with the main process to provide services for APP1. Since a process can include multiple threads, each thread corresponds to a different user interaction relationship, that is, the user expects different response latency. For example, the UI thread for user interaction tasks needs to be completed in a timely manner, the thread for page loading tasks needs to be as fast as possible, and the thread for downloading and backup-related tasks can be executed later. Therefore, different threads have different priorities. It is necessary to reasonably allocate thread priorities according to user needs. Setting the threads of important tasks to higher priorities can ensure that these tasks are processed in a timely manner, thereby improving the system's response speed and performance.
[0093] In some embodiments, the application (or user) can configure corresponding user interaction relationships for each thread of the main process of APP1 according to the application scenario requirements, and then determine the thread priority of the main process based on the user interaction relationships.
[0094] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0095] like Figure 1b As shown, the application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
[0096] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0097] It should be noted that there is a parent-child relationship between window programs and applications (APPs), meaning that an application can contain one or more window programs. A window program is the basic unit of an application, used to display information and receive user input. Window programs are managed by a window manager, while an application is a container for window programs, and can contain multiple window programs to implement different functions and interactive interfaces.
[0098] In some embodiments, the window manager can be used to manage window drawing tasks, which can be tasks for drawing window 1, window 2, window 3, etc. The window manager can record thread call information for each window. For example, the thread call information for drawing window 1 includes information about all threads required to draw window 1, the thread call information for drawing window 2 includes information about all threads required to draw window 2, and the thread call information for drawing window 3 includes information about all threads required to draw window 3.
[0099] Content providers store and retrieve data, making that data accessible to applications. This data may include user vital signs, images, videos, audio, phone calls made and received, browsing history and bookmarks, phone books, etc.
[0100] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0101] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).
[0102] The file explorer provides applications with various resources, such as localized images, strings, icons, layout files, video files, and more.
[0103] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0104] The system service layer can include multiple functional modules. For example: a rendering module, system services, a Quality of Service (QoS) management module, and... Figure 1b The components not shown include the surface manager, media libraries, 3D engine modules (e.g., OpenGL ES), and 2D graphics engines (e.g., SGL, Vulkan).
[0105] The rendering module can be used to determine how to transform, color, and draw an image or mesh of particles, and to overlay them with other particles.
[0106] In some embodiments, the rendering module may record thread access information within a preset time period. The thread access information includes thread information that has accessed the rendering module within the preset time period, such as thread identifiers.
[0107] System services are software modules that manage and execute system-level functions, such as surface managers, media libraries, 3D engine modules, and 2D graphics engines. These system services are typically used to process specific types of data or perform specific types of operations to support the functionality and performance of applications.
[0108] In some embodiments, when the electronic device 100 is running the main process of APP1, the system service can launch one or more child processes to work in conjunction with the main process to provide services for APP1.
[0109] In some embodiments, the system service can identify one or more child processes that work in conjunction with the main process of APP1 based on system information.
[0110] Optionally, the child processes in this application embodiment may not include resident processes started by system services, such as OpenGL ES.
[0111] The QoS management module can be used to manage user interaction relationship information corresponding to multiple threads of the application's main process. In this application, the QoS management module can also interact with system services to obtain information about one or more child processes that work in conjunction with the main process of APP1.
[0112] In some embodiments, the QoS management module can interact with the priority management module in the kernel layer, sending the user interaction relationship corresponding to each thread of the main process to the priority management module, so that the priority management module can determine the thread priority based on the user interaction relationship.
[0113] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0114] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, G.264, MP3, AAC, and AMR.
[0115] The 3D engine module is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0116] A 2D graphics engine is a graphics engine for 2D drawing.
[0117] The kernel layer is the layer between hardware and software. At a minimum, the kernel layer includes a priority management module, an associated thread identification module, a load aggregation and statistics module, and a frequency adjustment module.
[0118] The associated thread identification module, a new addition to the thread priority adjustment method in this application, is used to identify associated threads of the main process from threads in one or more child processes. This allows for subsequent adjustment of associated thread priorities based on the main process's threads, preventing the application's main process from being unaware of child process threads and unable to assign user interaction relationships to multiple child process threads. This avoids issues where child process thread priorities cannot be reasonably allocated according to user needs, impacting system response speed and performance, thus improving system response speed and performance, and enhancing user experience. The method for identifying associated threads of the main process will be explained in detail later; it will not be elaborated upon here.
[0119] The priority management module can store the mapping relationship between user interaction relationships and priorities, and can determine the priority of a thread based on the user interaction relationship corresponding to the thread. This will be explained in detail later; the thread priority adjustment method provided in this application will not be elaborated upon here.
[0120] The load aggregation and statistics module is a new module added to this application, which can be used to calculate the aggregated load of threads. How to perform aggregated load calculation will be explained in detail later; it will not be elaborated upon here.
[0121] The frequency modulation module can be used to adjust the main frequency of the processor in electronic device 100. How to adjust the processor's main frequency will be explained in detail later; it will not be elaborated upon here.
[0122] Understandable Figure 1b The software architecture described above is merely an exemplary implementation provided in this embodiment of the invention. The software architecture in this embodiment includes, but is not limited to, the above implementation methods.
[0123] The architecture of the embodiments of this application has been described above. The methods of the embodiments of this application will be described in detail below.
[0124] Please refer to Figure 2 As shown, Figure 2 This is a flowchart illustrating a thread priority adjustment method provided in an embodiment of this application. Optionally, this method can be applied to the aforementioned electronic device 100. Figure 2The thread priority adjustment method shown may include steps S201-S206. It should be understood that this application describes the process in the order of steps S201-S206 for ease of description, and is not intended to limit the execution to this specific order. This application does not limit the order of execution, execution time, or number of executions of one or more of the above steps. The following description uses a smartphone as an example to illustrate the execution of steps S201-S206 of the thread priority adjustment method; however, this application is also applicable to other execution entities such as servers and other electronic devices. Steps S201-S206 are detailed below:
[0125] Step S201: Run the first application.
[0126] Specifically, the first process of the first application includes multiple first threads. The first application can be an application that comes pre-installed on the phone or an application downloaded by the user, such as Huawei Connect. The first process is the main process of the first application. Multiple first threads are the execution units of the first process; multiple first threads can execute different tasks or the same task. For example, ... Figure 3 As shown, Figure 3 This is a schematic diagram of the QoS value of the interaction between a first thread and the user, provided in an embodiment of this application. Multiple first threads may include a UI thread, a page loading thread, a document opening thread, a download thread, a backup thread, etc.
[0127] Optionally, step S202: Based on the first mapping table and the user interaction relationship value of the first function provided for the first application, set the priority of the first thread corresponding to the first function.
[0128] Specifically, the first application can provide multiple functions, such as rendering, page loading, document opening, downloading, and backup. The first function can be one of these multiple functions. The first thread corresponding to the first function can be one or more threads from a set of first threads. The user interaction relationship value can indicate the user's expected response latency. Different first threads may correspond to different user interaction relationship values.
[0129] It should be noted that the user interaction relationship value in this application can be represented by the Quality of Service (QOS) value.
[0130] In some embodiments, the lower the user expects the response latency, the higher the QoS value.
[0131] For example, such as Figure 3As shown, multiple first threads can include a UI thread, a page loading thread, a document opening thread, a download thread, and a backup thread. Among them, the UI thread represents a user interaction task, where users expect low response latency; therefore, the UI thread has the highest QoS value. The page loading thread represents a user interaction task where faster response is better, and users expect low response latency; therefore, the page loading thread has a lower QoS value than the UI thread. The document opening thread represents a user interaction task where progress is visible; therefore, the document opening thread has a lower QoS value than the page loading thread. The download thread represents a user interaction task where immediate response is not required; therefore, the download thread has a lower QoS value than the document opening thread. The backup thread represents a user interaction task where the user interaction is invisible; therefore, the backup thread has a lower QoS value than the download thread.
[0132] In other embodiments, the user can expect a lower response latency and a smaller QoS value.
[0133] The first mapping table includes the mapping relationship between QoS values and priorities.
[0134] Optionally, a higher QoS value indicates that the user expects lower response latency and a higher priority. For example, ... Figure 4 As shown, Figure 4 This is a schematic diagram of a first mapping table provided in an embodiment of this application. In this example, only six QoS values are shown: 0, 1, 2, 3, 4, and 5. The priority value is 1 for a QoS value of 0, 10 for a QoS value of 1, 20 for a QoS value of 2, 30 for a QoS value of 3, 40 for a QoS value of 4, and 50 for a QoS value of 5. It should be noted that in this example, a larger priority value indicates a higher priority.
[0135] In this embodiment, the first process may include multiple first threads, each capable of executing different tasks. In different application scenarios, the application can set the QoS value of the user interaction relationship for a first function provided by the first application according to its needs. Then, the electronic device can set the priority of the first thread corresponding to the first function based on the first mapping table and the QoS value of the user interaction relationship for the first function. This allows for the reasonable configuration of the first thread's priority according to user needs. Setting threads for important tasks with higher priority ensures that these tasks are processed promptly, improving the user experience.
[0136] In some embodiments, the priority of a first thread is set based on a first mapping table and the user interaction relationship value corresponding to each first thread among a plurality of first threads.
[0137] Step S203: Identify the associated thread of the first thread from the threads of the second process.
[0138] Specifically, the second process is a process running on the electronic device other than the first process, which provides services to the first application.
[0139] Optionally, the child processes in this embodiment may not include resident processes started by system services, such as OpenGL ES. A resident process can be understood as a process that runs continuously and resides in memory, typically starting when the system boots up and continuing to run until the system shuts down. In some embodiments, the resident process is automatically started when the electronic device boots up, and the operating system (OS) does not actively kill the resident process; even if the resident process is killed, the operating system will restart it.
[0140] For example, such as Figure 5 As shown, Figure 5 This is a schematic diagram of the main process and child processes of a first application provided in an embodiment of this application. When the electronic device runs the first process (i.e., the main process) of the first application, the electronic device will create one or more child processes for it to work together with the main process to provide services for the first application.
[0141] Optionally, multiple first threads of the main process and one or more child process threads can be set with default priorities in the initial state. The default priorities of different threads can be the same or different.
[0142] For example, Figure 5The default priority of each of the main process's multiple first threads and one or more child process threads is 20. Applications can configure QoS values for the main process's multiple first threads based on user needs and a first mapping table. For example, assuming the main process includes three threads: thread 1, thread 2, and thread 3, with thread 1 having a QoS value of 5, thread 2 a QoS value of 2, and thread 3 a QoS value of 4, the electronic device can update the priorities of the main process's threads based on the first mapping table and QoS values. For instance, thread 1 might have a priority of 50, thread 2 a priority of 20, and thread 3 a priority of 40. However, for child processes, such as child process 1 and child process 2, since these processes are started by system services, the application cannot perceive the child process threads and therefore cannot adjust their priorities. This prevents the child process threads from being adjusted appropriately according to user needs. Therefore, in some examples of this application, by identifying the associated threads of the first thread from the threads of one or more child processes, the associated threads can follow the first thread in priority adjustment. For multiple threads within the same subprocess, the first thread associated with each thread may be different. Therefore, the priority adjustment trend of multiple threads within the same subprocess is determined by the first thread associated with them, and they can be different. This avoids the application being unaware of the threads in the subprocess, which would prevent the application from reasonably adjusting the thread priority of the subprocess according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0143] In some embodiments, when the second process is created by the first process and the first thread is the main thread of the first process, identifying the associated thread of the first thread includes: identifying the main thread of the second process as the associated thread of the first thread.
[0144] Specifically, the main process can call system functions, such as the fork() function, to create a new child process. When the second process (i.e., the child process) is created by the first process (i.e., the main process), the child process's main thread will inherit the main process's main thread. The child process's main thread usually performs similar tasks to the main process. Therefore, the child process's main thread can be identified as an associated thread of the main process's main thread. Consequently, associated threads can follow the first thread in priority adjustment, and thread scheduling can be performed based on this priority. This ensures that important tasks are processed in a timely manner, thereby improving system responsiveness and performance, and enhancing the user experience.
[0145] For example, such as Figure 6 As shown, Figure 6This is a schematic diagram of identifying associated threads provided in an embodiment of this application. Assuming that the main process creates a child process 1, the main thread of the child process 1 (i.e., thread 4) can be identified as an associated thread of the main thread of the main process (i.e., thread 1). Thread 4 can then follow thread 1 in priority adjustment, so that the priority of thread 4 is adjusted to 50. Thread scheduling based on this priority can ensure that important tasks are processed in a timely manner, thereby improving the system's response speed and performance, and enhancing the user experience.
[0146] Optionally, the main thread of the child process can be determined from the threads of the child process by reading the thread identifier.
[0147] In some embodiments, identifying the associated thread of the first thread includes: identifying from the threads of the second process a thread that has the same task as the first thread as the associated thread of the first thread.
[0148] Specifically, from the threads of one or more child processes (i.e., the second threads), threads that have the same task as the first thread are identified as associated threads of the first thread. The associated threads can then follow the first thread in priority adjustment and be scheduled according to the priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, which can ensure that the task is responded to faster, thereby improving the system's response speed and performance, and enhancing the user experience.
[0149] In some embodiments, the first thread communicates with the first module, and the method further includes: determining the thread in the second process that communicates with the first module as the thread with the same task as the first thread.
[0150] Specifically, when multiple threads communicate with the same module (i.e., the first module), these threads are all executing the same code logic and may be performing the same tasks. Therefore, these threads can be associated, and the associated threads can follow the first thread for priority adjustment. Thread scheduling is performed according to this priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, which can ensure that the task is responded to faster, thereby improving the system's response speed and performance, and enhancing the user experience.
[0151] For example, such as Figure 7 As shown, Figure 7 This is another schematic diagram illustrating the identification of associated threads provided in an embodiment of this application. When the first module is a rendering module running on an electronic device, multiple threads can interact with the rendering module within a preset time period, such as thread 1, thread 4, and thread 6. These threads work together to complete a rendering task. Threads can interact with the rendering module through the interface provided by the rendering module.
[0152] Optionally, the rendering module can record thread access information within a preset time period. This information includes details about the threads that accessed the rendering module during that period, such as thread identifiers. Furthermore, based on this recorded information, the modules can identify threads that accessed the module within that time period, such as threads 1, 4, and 6. These threads execute the same code logic and may perform the same rendering tasks. Therefore, these threads can be associated, and the associated threads (threads 4 and 6) can follow the first thread (thread 1) in priority adjustment. Thread scheduling is then performed based on this priority, ensuring that all threads corresponding to the same rendering task are scheduled to run on the processor at the same or similar times. This guarantees faster response times for rendering tasks, improving system responsiveness and performance, and enhancing the user experience.
[0153] In some embodiments, the first module is a rendering module running on an electronic device; or, the first module is a window management module running on an electronic device; or, the first module is a component management module running on an electronic device.
[0154] Specifically, the rendering module can be as described above. Figure 1b The rendering module described above; the window management module can be the above. Figure 1b The window manager described in the document. In this embodiment, when the first thread accesses the rendering module, other threads interacting with the rendering module can be identified as associated threads of the first thread, all of which are performing the same or identical rendering task. When the first thread accesses the window management module, other threads interacting with the window management module can be identified as associated threads of the first thread, all of which are performing the same or identical window drawing task. When the first thread accesses the component management module, other threads interacting with the component management module can be identified as associated threads of the first thread, all of which are performing the same or identical drawing task. Furthermore, associated threads can follow the first thread in priority adjustment, and thread scheduling is performed according to this priority. All threads corresponding to the same task can be scheduled to run on the processor at the same or similar time, ensuring that tasks can be responded to faster, thereby improving the system's response speed and performance, and enhancing the user experience.
[0155] In some embodiments, when the first module is a window management module, determining the thread in the second process that communicates with the first module as the thread with the same task as the first thread includes: determining the thread in the second process that communicates with the window management module and performs the same window drawing task as the first thread as the thread with the same task as the first thread.
[0156] Specifically, multiple threads interacting with the window management module may be drawing the same window, or they may be drawing different windows. For example, Figure 8 As shown, Figure 8 This is a schematic diagram illustrating another method for identifying associated threads, provided in an embodiment of this application. Figure 8 Assume an electronic device displays a user interface 1 on its screen. This user interface 1 actually includes multiple windows, such as window 1, window 2, and window 3. These windows may be drawn simultaneously or within a short timeframe. To more accurately identify the associated threads of the first thread, threads that perform the drawing task of the same window as the first thread are identified as threads with the same task as the first thread. For example, if threads 3, 5, and 7 need to perform the drawing task of window 1, then threads 3, 5, and 7 can be associated. Thread 3 is designated as the first thread, and threads 5 and 7 as associated threads. Furthermore, associated threads can follow the priority adjustment of the first thread. Thread scheduling is performed based on this priority, ensuring that all threads corresponding to the same task can be scheduled to run on the processor at the same or similar time. This ensures faster task response, thereby improving system responsiveness and performance, and enhancing the user experience.
[0157] Optionally, the window management module can record the thread call information corresponding to each window. For example, the thread call information for drawing window 1 includes information about all threads required to draw window 1; the thread call information for drawing window 2 includes information about all threads required to draw window 2; and the thread call information for drawing window 3 includes information about all threads required to draw window 3. Furthermore, multiple threads drawing the same window can be determined based on the thread call information.
[0158] Step S204: Set the priority of the associated threads based on the priority of the first thread.
[0159] Specifically, after identifying the associated threads of the first thread, the priorities of the associated threads can be adjusted based on the priority of the first thread, which is set according to user requirements. Since the priority of the associated threads is determined by the priority of the first thread, the priority of the associated threads can also meet user needs, avoiding situations where the application is unaware of the threads of the child processes, thus preventing the inability to reasonably configure the thread priorities of the child processes according to user needs. This improves system response speed and performance, and enhances user experience.
[0160] For example, such as Figure 9 As shown, Figure 9This diagram illustrates an embodiment of adjusting the thread priority of a subprocess. For example, after executing steps S201-S203, it can be determined that the associated threads of thread 1 are threads 4 and 6, and the associated threads of thread 3 are threads 5 and 7. Since the QoS value of thread 1 is 5, the QoS values of threads 4 and 6 can be set to 5, thereby updating the priority of thread 4 to 50 and the priority of thread 6 to 50. Similarly, since the QoS value of thread 3 is 4, the QoS values of threads 5 and 7 can be set to 4, thereby updating the priority of thread 5 to 40 and the priority of thread 7 to 40.
[0161] In some embodiments, a first interface can be created for each thread of the second process, through which a QoS value can be configured for the threads of the second process. For example, based on the QoS value of the first thread, the QoS value of an associated thread can be configured through the first interface, thereby updating the priority of the associated thread. The first interface can be setThreadQos().
[0162] Step S205: Detect a change in the running state of the first application, adjust the priority of the first thread, and adjust the priority of the associated threads.
[0163] Specifically, the priority adjustment trend of associated threads is consistent with that of the first thread. This consistency includes: if the priority of the first thread is increased, the priority of associated threads is increased; or if the priority of the first thread is decreased, the priority of associated threads is decreased; or if the QoS value of the first thread changes, the priority of associated threads also changes accordingly to the priority corresponding to the changed QoS value of the first thread.
[0164] In some embodiments, the method further includes: detecting a change in the running state of the first application and modifying the QoS value of the first thread.
[0165] Specifically, when a change in the running state of the first application is detected, i.e., a change in user needs, the first application can adjust the priority of the first thread by modifying the QoS value of the first thread. This allows the application to adjust the thread priority of the first process according to user needs, thereby improving the user experience.
[0166] In some embodiments, detecting a change in the running state of the first application, adjusting the priority of the first thread, and adjusting the priority of the associated thread include: detecting a change in the running state of the first application, adjusting the priority of the first thread and the priority of the associated thread based on the modified QoS value of the first thread and the first mapping table.
[0167] In this embodiment, when a change in the running state of the first application is detected, i.e., a change in user needs, the first application can modify the QoS value of the first thread according to the needs. For example, if the user currently wants the first application's document opening function to respond as quickly as possible, the QoS value of the first thread corresponding to this function can be modified to a higher value. Based on the modified QoS value of the first thread and the first mapping table, the priority of the first thread and the priority of associated threads can be adjusted. That is, associated threads follow the priority adjustment of the first thread, avoiding the application's inability to perceive the threads of child processes, which would prevent the application from reasonably adjusting the thread priorities of child processes according to user needs. This improves the system's response speed and performance, and enhances the user experience.
[0168] For example, such as Figure 10 As shown, Figure 10 This is a schematic diagram illustrating the adjustment of the priority of a first thread and associated threads in an embodiment of this application. Assume that the first application modifies the QoS value of the first thread of the main process, for example, modifying the QoS value of thread 1 to 4, the QoS value of thread 2 to 3, and the QoS value of thread 3 to 3. Then, the priority of thread 1 is adjusted to 40, and the priorities of associated threads (thread 4 and thread 6) are also adjusted to 40; the priority of thread 2 is adjusted to 30; the priority of thread 3 is adjusted to 30, and the priorities of associated threads (thread 5 and thread 7) are also adjusted to 30.
[0169] In some embodiments, a higher QoS value in the first mapping table indicates a higher priority for the corresponding thread. When the running state of the first application changes from a foreground state to a background state or a frozen state, the QoS value of the first thread decreases, and the priority of the first thread and the priority of associated threads decrease. When the running state of the first application changes from a background state or a frozen state to a foreground state, the QoS value of the first thread increases, and the priority of the first thread and the priority of associated threads increase.
[0170] Specifically, when the first application switches from the foreground to the background or frozen state, the priority of the first thread and the priority of associated threads can be lowered to ensure that the foreground application of the current electronic device can respond faster; when the first application switches from the background or frozen state to the foreground state, the priority of the first thread and the priority of associated threads can be increased to ensure that the first application can respond faster, thereby improving the user experience.
[0171] In some embodiments, when the first application is in the startup or background phase, the priority of the associated thread is the same as the priority of the first thread; for example, if the priority of the first thread is 50, then the priority of the associated thread is also 50. When the first application is running in the foreground, the priority of the first thread can be higher than the priority of the associated thread; for example, if the priority of the first thread is 50, the priority of the associated thread can be one level lower than the priority of the first thread, i.e., 40. Although the priorities of the first thread and the associated thread are not the same, when the running state of the first application changes, the priority adjustment trend of the associated thread is consistent with the priority adjustment trend of the first thread. If the priority of the first thread increases, the priority of the associated thread also increases; if the priority of the first thread decreases, the priority of the associated thread also decreases, thereby ensuring that the first thread can be scheduled to run on the processor in a timely manner.
[0172] Optionally, step S206: determine the aggregate load of the first thread and associated threads, and adjust the processor's clock frequency based on the aggregate load.
[0173] Specifically, electronic devices may include processors. The processor's clock speed is its operating frequency, such as 1000MHz or 2000MHz. The processor has a frequency adjustment cycle; for example, an adjustment cycle of 4 milliseconds means the processor can adjust its clock speed every 4 milliseconds. When a thread is scheduled to run on the processor, the aggregate load can be calculated based on the total runtime of the thread and its associated threads. The processor's clock speed can then be adjusted based on this calculated aggregate load. In other words, frequency adjustment comprehensively considers the running status of the first thread and its associated threads, thereby ensuring thread speed while saving energy and improving the user experience.
[0174] Optionally, the running status information of the first thread and its associated threads can be obtained by reading system information, such as trace information in the Android system.
[0175] In some embodiments, the aggregate load of the first thread and the associated thread can be determined according to Formula 1. Formula 1 is as follows:
[0176] L1 = F * C1 (Formula 1)
[0177] L1 represents the aggregated load, F represents the processor's current frequency, and C1 represents the first duty cycle. The first duty cycle is the percentage of the total duration of the first thread and associated threads within the processor's frequency adjustment cycle; the processor's main frequency is adjusted based on the aggregated load.
[0178] Optionally, the first duty cycle can be calculated based on the running status of the first thread and associated threads within one frequency modulation cycle, or it can be calculated based on the running status of the first thread and associated threads within multiple frequency modulation cycles.
[0179] In some embodiments, threads with QoS values greater than a preset value are identified, and the aggregated load of these threads is determined; the processor's clock frequency is adjusted based on the aggregated load.
[0180] In some embodiments, adjusting the processor's clock frequency based on aggregated load includes: determining whether the aggregated load is greater than a first threshold; if the aggregated load is greater than the first threshold, then adjusting the processor's clock frequency based on the aggregated load.
[0181] Specifically, such as Figure 11 As shown, Figure 11 This application provides a schematic diagram of a first threshold. The first threshold can be a preset value of the electronic device, a value updated by the electronic device from the cloud, or an empirical value obtained by the electronic device through machine learning. The first threshold can represent the frequency point corresponding to the energy consumption that the system can accept, such as 1200, 1250, 1300, 1350, 1400, or 1500 MHz. When the aggregated load exceeds the first threshold, it indicates that the first thread and its associated threads are performing a high-load task. High-load tasks are generally important tasks, so the system will prioritize ensuring the performance of the first thread and its associated threads. Therefore, the system can adjust the processor's main frequency point based on the aggregated computational load, thereby ensuring thread execution speed while saving energy and improving user experience.
[0182] In some embodiments, adjusting the processor's clock frequency based on the aggregated load includes: increasing the processor's clock frequency when the aggregated load is greater than a second threshold; and decreasing or not adjusting the processor's clock frequency when the aggregated load is less than or equal to the second threshold.
[0183] Specifically, when the aggregated load is greater than the second threshold, it means that the processor is running the first thread and related threads most of the time. In this case, the processor's clock speed can be increased so that the processor can run the first thread and related threads faster. When the aggregated load is less than or equal to the second threshold, it means that the processor has a lot of spare time after running the first thread and related threads. In this case, the processor's clock speed can be decreased or not adjusted to save processor power.
[0184] In some embodiments, the method further includes: if the aggregated load is less than or equal to a first threshold, determining a first load of the first thread, wherein the first load is the product of the current frequency of the processor and a second duty cycle; the second duty cycle is the proportion of the duration of the first thread in the frequency adjustment cycle of the processor; and adjusting the main frequency of the processor based on the first load.
[0185] Specifically, when the aggregated load is less than or equal to the first threshold, it means that the first thread and its associated threads correspond to a low-load task. Low-load tasks are generally ordinary tasks. In this case, the system will be more inclined to save processor power consumption. The first load can be calculated based on the duration of the first thread's operation, and the processor's main frequency can be adjusted based on the calculated first load, thereby saving processor power consumption and improving user experience.
[0186] Optionally, the second duty cycle can be calculated based on the operation of the first thread within one frequency modulation cycle, or it can be calculated based on the operation of the first thread within multiple frequency modulation cycles.
[0187] For example, such as Figure 12 As shown, Figure 12 This diagram illustrates a thread priority scheduling method provided in this application embodiment. The application can actively mark the user interaction level of threads and send this information to the kernel via the QoS management module. The kernel can dynamically adjust thread priorities based on the user interaction relationships of threads and the foreground / background state of the application. For multi-process collaborative application scenarios, the associated threads of the main process and child processes are identified through key module interactions such as thread creation relationships, the window state of the thread, and the interaction between the thread and rendering. The associated threads of the main process and child processes are adjusted collaboratively. During the startup phase of both the main process and child processes, the same strategy is used to ensure priority during the running phase. The priority changes of the child process are consistent with those of the main process, but in the foreground state, the priority of the child process can be lower than that of the main process. The user interaction relationships of the main process threads can be passed to the associated threads of the child threads, collaboratively improving the processor allocation for the threads. The kernel aggregates the load statistics of threads with high user interaction relationships. It aggregates the load of the distributed threads with high user interaction relationships, and uses the aggregated load to calculate the frequency point. The kernel also manages the processor computing power based on the aggregated load: if the aggregated load is lower than the first threshold, the frequency is adjusted normally so that the critical threads run at the high energy efficiency frequency point; if the aggregated load is higher than the threshold, the frequency is adjusted by aggregation so that the critical threads and their associated threads run at the high frequency point.
[0188] In summary, real-world applications of electronic devices require dynamic thread scheduling based on different user interaction relationships. Threads with high user interaction relationships should be supplied with fast and high-performance resources, while threads with low user interaction relationships should be supplied with low-power resources. The priority of related threads in multi-process collaboration should be adjusted collaboratively. During the startup phase of both the main process and child processes, the same strategy should be used to ensure priority. During the runtime phase, the priority changes of child processes should be consistent with those of the main process. However, in the foreground state, the priority of child processes can be lower than that of the main process. Load aggregation statistics of critical threads with high user interaction relationships should be used to accurately adjust the processor frequency.
[0189] Please see Figure 13 , Figure 13This is a flowchart illustrating a frequency modulation method provided in an embodiment of this application. The method is applied to an electronic device, which includes a processor. The method includes:
[0190] Step S301: Run the first application.
[0191] Specifically, the first process of the first application includes multiple first threads.
[0192] Step S302: Identify the associated thread of the first thread from the threads of the second process.
[0193] Specifically, the second process is a process running on the electronic device other than the first process, which provides services to the first application.
[0194] Step S303: Determine the aggregate load of the first thread and associated threads.
[0195] Specifically, the aggregated load is the product of the processor's current frequency and the first duty cycle; the first duty cycle is the percentage of the total duration of the first thread and associated threads in the processor's frequency adjustment cycle.
[0196] Step S304: Adjust the processor's clock frequency based on the aggregated load.
[0197] In some embodiments, adjusting the processor's clock frequency based on aggregated load includes: determining whether the aggregated load is greater than a first threshold; if the aggregated load is greater than the first threshold, then adjusting the processor's clock frequency based on the aggregated load.
[0198] In some embodiments, adjusting the processor's clock frequency based on the aggregated load includes: increasing the processor's clock frequency when the aggregated load is greater than a second threshold; and decreasing or not adjusting the processor's clock frequency when the aggregated load is less than or equal to the second threshold.
[0199] In some embodiments, the method further includes: if the aggregated load is less than or equal to a first threshold, determining a first load of the first thread, wherein the first load is the product of the current frequency of the processor and a second duty cycle; the second duty cycle is the proportion of the duration of the first thread in the frequency adjustment cycle of the processor; and adjusting the main frequency of the processor based on the first load.
[0200] In this embodiment, when a thread is scheduled to run on the processor, the aggregated load can be calculated based on the total running duration of the thread and its associated threads. Then, the processor's main frequency can be adjusted based on the calculated aggregated load. That is, the frequency adjustment is performed by comprehensively considering the running status of the first thread and its associated threads, thereby ensuring the running speed of the thread while saving energy and improving the user experience.
[0201] Please see Figure 14 , Figure 14This is a flowchart illustrating a thread priority adjustment method provided in an embodiment of this application, which is applied to an electronic device. The method includes:
[0202] Step S401: Run the first application.
[0203] Specifically, the interface of the first application includes a first window corresponding to the first process and a second window corresponding to the second process, with the second window nested within the first window; the first process is the process of the first application; the second process is either the process of the first application or the process of the second application; the UI thread of the second process is the associated thread of the UI thread of the first process.
[0204] For example, such as Figure 15 As shown, Figure 15 This is a schematic diagram of the interface of a first application provided in an embodiment of this application. Assuming the first application is a chat application, the electronic device displays a user interface 710, which is a chat dialog interface containing a document 720. The electronic device can receive and respond to a user's touch operation on the document 720 to open the document and display a user interface 711. The user interface 711 can be a document display interface, on which at least two windows can exist. The first window is rendered by the main process of the first application, and the second window is rendered by other processes of the first application (i.e., processes launched by the main process or the system). Since the first window needs to be rendered simultaneously with the second window, the UI thread corresponding to the first window and the UI thread corresponding to the second window can be associated, that is, the UI thread of the second process is used as the associated thread of the UI thread of the first process, so as to adjust thread priorities later.
[0205] Step S402: Detecting a change in the running state of the first application, adjust the priority of the UI thread of the first process, and adjust the priority of the associated threads.
[0206] Specifically, the priority adjustment trend of related threads is consistent with the priority adjustment trend of the UI thread of the first process.
[0207] In some embodiments, the component tree of the second process is mounted in the component tree of the first process.
[0208] In this embodiment, the interface of the first application may include multiple windows, such as a first window and a second window, wherein the second window is nested within the first window. Since the first window and the second window need to be rendered simultaneously, the UI thread corresponding to the first window and the UI thread corresponding to the second window can be associated. That is, the UI thread of the second process is used as the associated thread of the UI thread of the first process. Therefore, when a change in the running state of the first application is detected, which can be understood as a change in user needs, the UI thread of the second process adjusts its priority according to the UI thread of the first process. This avoids the application being unaware of the thread of the second process, thus preventing it from being unable to reasonably adjust the thread priority of the second process according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0209] This application provides a flowchart of a thread priority adjustment method, which is applied to an electronic device. The method includes: running a first application; a first process of the first application including multiple first threads; identifying associated threads of the first threads from the threads of a second process; wherein the first threads and associated threads are used to jointly render the interface of the first application; detecting a change in the running state of the first application, adjusting the priority of the first threads, and adjusting the priority of the associated threads, wherein the priority adjustment trend of the associated threads is consistent with the priority adjustment trend of the first threads.
[0210] In some embodiments, both the first thread and the associated thread are used to send rendering instructions to the rendering module.
[0211] In this scenario, the associated thread can be the main thread of the second process, the Compositor thread, or the CompositorTileW thread. The main thread can be used to measure, lay out, generate the hierarchy tree, and paint to generate drawing instructions. The Compositor thread can be used to divide the layer into smaller tiles and pass them to the raster thread for rasterization. The CompositorTileW thread can be used for image decoding, generating graphics processing unit (GPU) instructions, and prioritizing rendering of the visible area.
[0212] In this embodiment, since the threads rendering the interface of the first application are performing similar tasks, threads in different processes that render the interface of the first application can be associated. That is, the threads in the second process that jointly render the interface of the first application with the first thread are identified as associated threads. Then, when a change in the running state of the first application is detected, which can be understood as a change in user needs, the associated threads follow the first thread to adjust their priorities. This avoids the application being unaware of the threads of the child processes, which would prevent the application from reasonably adjusting the thread priorities of the child processes according to user needs, thereby improving the system's response speed and performance, and enhancing the user experience.
[0213] This application provides an electronic device, including: a memory and one or more processors; the memory is coupled to one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and one or more processors call the computer instructions to cause the electronic device to execute any of the above-described thread priority adjustment methods and any of the above-described frequency modulation methods.
[0214] This application provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform any of the above-described thread priority adjustment methods and any of the above-described frequency modulation methods.
[0215] This application provides a computer program product that, when run on a computer, causes the computer to execute any of the above-described thread priority adjustment methods and any of the above-described frequency adjustment methods.
[0216] This application provides a chip system, which includes at least one processor for implementing any of the above-described thread priority adjustment methods and executing any of the above-described frequency modulation methods.
[0217] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0218] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0219] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical or other forms.
[0220] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0221] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0222] If the integrated units described above are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which can be a personal computer, server, or network device, specifically a processor in the computer device) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium may include various media capable of storing program code, such as a USB flash drive, portable hard drive, magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM).
[0223] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A thread priority adjustment method, characterized in that, Applied to electronic devices, the method includes: Run the first application; the first process of the first application includes multiple first threads; From multiple threads of the second process, identify at least one associated thread of the first thread; wherein the second process is a process that provides services to the first application, at least one first thread includes the UI thread of the first process, the associated thread is the UI thread of the second process, and the window of the second process is nested in the window of the first process; If a change in the running state of the first application is detected, the priority of at least one of the first threads is adjusted, and the priority of the associated threads is also adjusted, wherein the priority adjustment trend of the associated threads is consistent with the priority adjustment trend of at least one of the first threads.
2. The method as described in claim 1, characterized in that, When the second process was created by the first process, and at least one of the first threads includes the main thread of the first process, identifying the associated thread of at least one of the first threads includes: The main thread of the second process is identified as the associated thread.
3. The method as described in claim 1, characterized in that, The step of identifying at least one associated thread of the first thread includes: From the threads of the second process, the threads that have the same task as at least one of the first threads are identified as the associated threads.
4. The method as described in claim 3, characterized in that, At least one of the first threads communicates with the first module, and the method further includes: The thread in the second process that communicates with the first module is identified as the thread that has the same task as at least one of the first threads.
5. The method as described in claim 4, characterized in that, The first module is a rendering module running on the electronic device; or, the first module is a window management module running on the electronic device; or, the first module is a component management module running on the electronic device.
6. The method as described in claim 5, characterized in that, When the first module is the window management module, determining the thread in the second process that communicates with the first module as a thread with the same task as at least one of the first threads includes: From the threads of the second process, the threads that communicate with the window management module and perform the same window drawing task as at least one of the first threads are identified as threads with the same task as at least one of the first threads.
7. The method according to any one of claims 1-6, characterized in that, Before identifying at least one associated thread of the first thread, the method further includes: Based on a first mapping table and user interaction relationship values of at least one of the first threads, a priority is set for at least one of the first threads; the first mapping table includes the mapping relationship between user interaction relationship values and priorities.
8. The method as described in claim 7, characterized in that, After identifying at least one associated thread of the first thread, the method further includes: The priority of the associated thread is set based on the priority of at least one of the first threads.
9. The method as described in claim 7, characterized in that, The method further includes: If a change in the running state of the first application is detected, at least one user interaction relationship value of the first thread is modified.
10. The method as described in claim 9, characterized in that, Upon detecting a change in the running state of the first application, adjusting the priority of at least one of the first threads and adjusting the priority of the associated threads includes: Upon detecting a change in the running state of the first application, the priority of at least one of the first threads and the priority of the associated threads are adjusted based on the modified user interaction relationship value of at least one of the first threads and the first mapping table.
11. The method as described in claim 9 or 10, characterized in that, The larger the user interaction relationship value in the first mapping table, the higher the priority of the corresponding thread; when the running state of the first application changes from the foreground state to the background state or the frozen state, the user interaction relationship value of at least one first thread decreases, and the priority of at least one first thread and the priority of the associated thread decrease. When the running state of the first application changes from a background or frozen state to a foreground state, the user interaction relationship value of at least one of the first threads increases, and the priority of at least one of the first threads and the priority of the associated threads increase.
12. The method according to any one of claims 1-6, characterized in that, The electronic device includes a processor, and the method further includes: The aggregated load of at least one of the first threads and the associated threads is determined, wherein the aggregated load is the product of the current frequency of the processor and a first duty cycle; the first duty cycle is the proportion of the total duration of at least one of the first threads and the associated threads in the frequency adjustment cycle of the processor. The processor's clock speed is adjusted based on the aggregated load.
13. The method as described in claim 12, characterized in that, Adjusting the processor's clock frequency based on the aggregated load includes: Determine whether the aggregated load is greater than a first threshold; When the aggregated load is greater than the first threshold, and when the aggregated load is greater than the second threshold, the processor's clock frequency is increased; When the aggregated load is greater than the first threshold and the aggregated load is less than or equal to the second threshold, the processor's main frequency is adjusted down or not adjusted.
14. The method as described in claim 13, characterized in that, The method further includes: When the aggregated load is less than or equal to the first threshold, a first load of at least one first thread is determined, wherein the first load is the product of the processor's current frequency and the second duty cycle; the second duty cycle is the proportion of the duration of at least one first thread in the processor's frequency adjustment cycle. The processor's clock frequency is adjusted based on the first load.
15. An electronic device, characterized in that, include: A memory, and one or more processors; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-14.