Thread scheduling method and electronic device
By combining multiple threads of collaborative tasks and monitoring device status in real time, and adjusting the scheduling method, the problem of unbalanced scheduling of foreground and background processes in electronic devices is solved, thereby improving task execution speed and device stability.
Patent Information
- Application Number
- PCT/CN2025/142178
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-05-07
- Filing Date
- 2025-12-12
- Publication Date
- 2026-11-12
AI Technical Summary
In existing technologies, when electronic devices schedule multiple application processes, foreground processes are scheduled first, while background processes are scheduled later, which slows down task execution and fails to effectively monitor device status, potentially leading to overheating and abnormal memory bandwidth usage.
By grouping multiple threads that collaborate to complete the same task into the first thread group, monitoring the device status in real time, and adjusting the scheduling method in case of abnormalities, we can ensure that multiple threads are scheduled at the same time and reduce the probability of abnormal problems.
It achieves unified scheduling of multiple threads, ensuring task completion speed, reducing the probability of abnormal device temperature, abnormal memory bandwidth usage, and abnormal task load, and improving the operational stability of electronic devices.
Smart Images

Figure CN2025142178_12112026_PF_FP_ABST
Abstract
Description
A thread scheduling method and electronic device
[0001] This application claims priority to Chinese Patent Application No. 202510590502.2, filed on May 7, 2025, entitled "A Thread Scheduling Method and Electronic Device", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of terminal technology, and in particular to a thread scheduling method and an electronic device. Background Technology
[0003] During the operation of an electronic device, multiple applications (or application processes) need to collaborate to complete a designated task. For example, when an electronic device performs a "call summary" task, the system's call application implements the device's call function and records the call content as text in real time. Based on this, the AI processing module analyzes the text content, extracts the core information, and generates a summary of the call. Therefore, in this scenario, the call application and the AI processing module need to collaborate to extract the call summary.
[0004] However, when scheduling application processes on electronic devices, the scheduling is based solely on the foreground / background state of the applications. Foreground applications are scheduled first, followed by those running in the background. Therefore, for tasks requiring multiple applications to collaborate, the differences in their running states (foreground or background) mean that foreground applications may be scheduled first, while background applications may be scheduled later. This later scheduling of background applications slows down task execution. Summary of the Invention
[0005] This application provides a thread scheduling method and an electronic device. During the operation of the electronic device, by uniformly scheduling multiple threads that complete the same task, the multiple threads involved in the task can be scheduled simultaneously to ensure the completion speed of the task.
[0006] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:
[0007] Firstly, this application provides a thread scheduling method applied to an electronic device. The electronic device includes a first thread group; the first thread group includes at least two threads that cross processes; the at least two threads include the first thread, and the at least two threads collaborate to complete the same task. Firstly, during operation, the electronic device schedules the first thread group in a first operating mode. This enables unified scheduling of multiple threads, thereby ensuring the completion speed of tasks coordinated by multiple threads. Secondly, when the electronic device is in an abnormal state, it obtains first information about the first thread group. Finally, based on the first information, the electronic device schedules the first thread group in a second operating mode. This allows for timely adjustment of the scheduling mode of the first thread group when the electronic device experiences operational abnormalities, mitigating these problems and reducing the probability of issues such as abnormal temperature, abnormal memory bandwidth usage, and abnormal task load on the first thread group.
[0008] In one possible implementation of the first aspect, the first operating mode is used to indicate a first scheduling priority and / or a first scheduling frequency when at least one processor of an electronic device schedules at least two threads; the at least one processor includes at least one of the following: a central processing unit, a graphics processing unit, and a neural network processor.
[0009] In one possible implementation of the first aspect, the thread state corresponding to the first thread in the first thread group includes at least one of the following: foreground focus state, foreground non-focus state, background sensed state, and background non-sensed state.
[0010] In one possible implementation of the first aspect, the first thread group includes a second thread. When limiting the runtime quota of the first thread group, firstly, the electronic device obtains the scheduling time of the first thread group in the first scheduling cycle. Secondly, when the scheduling time of the first thread group in the first scheduling cycle exceeds a first time threshold, the second thread in the first thread group is scheduled in a third running mode. In this way, even when the electronic device is not in an abnormal state, the running mode of the threads in the first thread group can still be adjusted in a timely manner, reducing the problem of "malicious" creation of RT threads and preemption of processor memory bandwidth.
[0011] Among them, the first time threshold is positively correlated with the memory bandwidth of the electronic device; the scheduling priority of the second thread in the first running mode is greater than the scheduling priority of the second thread in the third running mode; and / or, the scheduling frequency of the second thread in the first running mode is greater than the scheduling frequency of the second thread in the third running mode.
[0012] In one possible implementation of the first aspect, the second thread is a real-time thread.
[0013] In one possible implementation of the first aspect, during the scheduling of the second thread in the third running mode, after the first thread group enters the second scheduling cycle, the running mode of the first thread group is restored to the first running mode, and multiple threads in the first thread group are scheduled in the first running mode. That is, when the running time of the first thread group reaches a first time threshold, the execution of threads in the first thread group is restricted. This restriction continues until the start of the next scheduling cycle (the second scheduling cycle), at which point the threads in the first thread group are restricted again. This prevents the second thread in the first thread group from "maliciously" creating RT threads and preempting processor memory bandwidth.
[0014] In one possible implementation of the first aspect, during the scheduling of the second thread in the first thread group in the third running mode, firstly, the scheduling time of the first thread group in the first scheduling cycle is obtained from the electronic device. Secondly, when the scheduling time of the first thread group in the first scheduling cycle is greater than a second time threshold, the third thread in the first thread group is scheduled in the fourth running mode. In this way, even when the electronic device is not in an abnormal state, the running mode of the threads in the first thread group can still be adjusted in a timely manner, reducing the problem of "malicious" creation of RT threads that preempt processor memory bandwidth.
[0015] In one possible implementation of the first aspect, the third thread is an exempted thread.
[0016] In one possible implementation of the first aspect, during the scheduling of the third thread in the fourth running mode, after the first thread group enters the second scheduling cycle, the running mode of the first thread group is restored to the first running mode, and multiple threads in the first thread group are scheduled in the first running mode. That is, when the running time of the first thread group reaches the second time threshold, the execution of threads in the first thread group is restricted. This restriction is re-imposed at the start of the second scheduling cycle. This prevents the second thread in the first thread group from "maliciously" creating RT threads and preempting processor memory bandwidth.
[0017] In one possible implementation of the first aspect, the electronic device allows the creation of a second thread group only if certain conditions are met before the second thread group is created. This allows the device to restrict the creation of the second thread group by using verification conditions, ensuring that the creation is only permitted if certain conditions are met, thus flexibly controlling the creation permissions of at least one thread group. Furthermore, this reduces the probability of users maliciously creating thread groups.
[0018] In one possible implementation of the first aspect, the electronic device further includes a second thread group. First, during operation, the electronic device schedules the first thread group in a first operating mode while simultaneously scheduling the second thread group in a fifth operating mode. This allows for scheduling multiple threads within each thread group using its appropriate operating mode, ensuring that each thread group is scheduled in a suitable manner. Second, in the event of an abnormal state, the electronic device acquires first information about the first thread group and second information about the second thread group. Finally, based on the first information, the electronic device schedules the first thread group in the second operating mode while simultaneously scheduling the second thread group in a sixth operating mode based on the second information. This allows for adjustments to the scheduling modes of the first and second thread groups when operational anomalies occur, mitigating the problems and reducing the probability of issues such as abnormal temperature, abnormal memory bandwidth usage, or abnormal task load in the first thread group. Simultaneously, it ensures that each thread group is scheduled in a suitable operating mode.
[0019] In one possible implementation of the first aspect, when the first thread is an extended thread, the thread state of the first thread is the window state of the application to which the host process belongs.
[0020] In one possible implementation of the first aspect, when the first thread is a thread in a multi-process application, the thread state of the first thread is the window state of the application to which the main process of the first thread belongs, and the multi-process includes the main process.
[0021] In one possible implementation of the first aspect, the first thread group is dissolved after the first thread exits the first thread group, so as to avoid the first thread group occupying the computing resources of the electronic device.
[0022] In one possible implementation of the first aspect, after the first thread exits the first thread group, third information about the first thread group is obtained. Then, based on the third information, the first thread group is scheduled using a seventh running mode. This allows for timely adjustment of the scheduling mode of the first thread group when the number of threads in the first thread group changes, thus determining a more suitable running mode for the first thread group.
[0023] In one possible implementation of the first aspect, the abnormal state of the electronic device includes at least one of the following: the memory bandwidth usage of the electronic device exceeds the bandwidth usage threshold, the device temperature of the electronic device exceeds the temperature threshold, and the task load of the first thread group exceeds the load threshold.
[0024] In a second aspect, an electronic device is provided, the electronic device including a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs a thread scheduling method as described in the first aspect and any of its implementations.
[0025] Thirdly, a computer-readable storage medium is provided, including computer instructions that, when executed on an electronic device, cause the electronic device to perform a thread scheduling method as described in the first aspect and any implementation thereof.
[0026] Fourthly, a computer program product is provided that, when the computer program product is run on an electronic device, causes the electronic device to execute the thread scheduling method as described in the first aspect and any of its implementations.
[0027] The beneficial effects that the electronic equipment provided in the second aspect, the computer-readable storage medium provided in the third aspect, and the computer program product provided in the fourth aspect can achieve can be referred to the beneficial effects that can be achieved in the first aspect and any of its implementations, and will not be repeated here. Attached Figure Description
[0028] Figure 1 shows a schematic diagram of the state changes of an electronic device provided in an embodiment of this application;
[0029] Figure 2 shows a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0030] Figure 3 shows a schematic diagram of the software structure of an electronic device provided in an embodiment of this application;
[0031] Figure 4 shows a flowchart of a thread scheduling method provided in an embodiment of this application;
[0032] Figure 5 illustrates a schematic diagram of dimension grouping provided in an embodiment of this application;
[0033] Figure 6 illustrates a thread scheduling process provided in an embodiment of this application;
[0034] Figure 7 illustrates a thread creation process provided in an embodiment of this application.
[0035] Figure 8 illustrates a module interaction process provided in an embodiment of this application.
[0036] Figure 9 shows a schematic diagram of the hardware structure of another electronic device provided in an embodiment of this application. Detailed Implementation
[0037] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of this application, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can represent A or B. "And / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone, where A and B can be singular or plural. Furthermore, in the description of this application, unless otherwise stated, "multiple" refers to two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple. Furthermore, to facilitate a clear description of the technical solutions in the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that "first" and "second" are not necessarily different. Meanwhile, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is being used as an example, illustration, or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0038] Furthermore, the business scenarios described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the emergence of new business scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0039] As electronic devices become increasingly sophisticated, they are increasingly capable of performing more complex tasks. These complex tasks require collaboration between multiple applications (or application processes). For example, when an electronic device performs a "call summary" task, the system's call application acquires the call content in real time during the call. Based on this, the AI processing module analyzes the call content, extracts the core information, and generates a summary of the call. Therefore, in this case, the call application and the AI processing module need to collaborate to complete the "call summary" task. As another example, when an electronic device performs a "speech-to-text" task, the social media application installed in the system acquires the voice information. Based on this, a deep learning model converts the acquired voice information into text. Again, in this case, the social media application and the deep learning model need to collaborate to complete the "speech-to-text" task.
[0040] Currently, electronic devices can only complete relatively complex tasks by scheduling multiple applications (or multiple application processes) one by one based on their foreground or background status. Therefore, for tasks requiring the collaboration of multiple application processes, the differences in their running states (foreground or background) mean that some foreground applications are prioritized for scheduling, while those running in the background are scheduled later. This later scheduling of background applications slows down task execution.
[0041] Taking the complex task of "call summarization" as an example, the "call summarization" task specifically involves a call task and a summary extraction task. The call task is completed by the "call application," while the summary extraction task is completed by the "AI processing module." During a call, because the call application runs in the foreground of the electronic device and the AI processing module runs in the background, the electronic device prioritizes scheduling the call application's process (thread) to complete the call task. However, because the AI processing module runs in the background, it is scheduled later and therefore cannot extract the summary content in a timely manner during the call, resulting in the "call summarization" task not being completed in a timely manner.
[0042] Furthermore, scheduling applications (or application processes) solely based on their foreground or background states means that electronic devices do not pay attention to their own device status during the application process scheduling. If an electronic device is "fully loaded," the chips (e.g., neural network processors) and / or the device's casing are prone to overheating and excessive memory bandwidth usage, which will further slow down the execution speed of tasks.
[0043] For example, when an electronic device is under "full load," the temperature of the neural network processing unit (NPU) casing (including the front and back of the casing) shows a significant upward trend, as shown in Figure 1(a). In this situation, the excessively high temperature of the electronic device reduces its operating speed, thereby slowing down the execution speed of tasks within the device.
[0044] Regarding memory bandwidth usage, taking the "call summary" task as an example, the "call summary" task involves at least two stages. Assume the first stage is the "call content acquisition" stage, and the second stage is the "summary content extraction" stage. In the first stage, the electronic device needs to run in a "high bandwidth" mode for 3.5 seconds. During this "high bandwidth" stage, the memory bandwidth usage of the electronic device can reach a maximum of 45738 MB / s. Even in the second stage, which runs in a "low bandwidth" mode (3.1 seconds), the memory bandwidth usage of the electronic device is as high as 25719 MB / s, as shown in Figure 1(b). It is evident that the "call summary" task alone consumes a significant amount of memory bandwidth from the electronic device, which may prevent other tasks from running normally and slow down their execution progress.
[0045] Based on the above, this application provides a thread scheduling method. First, multiple threads that collaboratively complete the same task across processes are grouped into a first thread group to achieve unified scheduling of multiple threads. Second, during the operation of the electronic device, the first thread group is scheduled in a first operating mode. Then, the electronic device monitors its own operating status in real time, and when the electronic device is in an abnormal state, it obtains the first information of the first thread group. Finally, the electronic device schedules the first thread group in a second operating mode based on the first information of the first thread group. In this way, during the operation of the electronic device, when an abnormal operation occurs, the scheduling mode of the first thread group can be adjusted in a timely manner to alleviate the abnormal operation of the electronic device and reduce the probability of problems such as abnormal temperature, abnormal memory bandwidth usage, and abnormal task load of the first thread group. Furthermore, by uniformly scheduling multiple threads that complete the same task, multiple threads involved in the task can be scheduled simultaneously to ensure the completion speed of the task.
[0046] The thread scheduling method provided in this application embodiment involves an electronic device 100, as shown in Figure 2. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, antenna 1, antenna 2, a mobile communication module 150, a wireless communication module 160, a sensor module 170, etc. The sensor module 170 may include a temperature sensor 170A, a system-on-chip (SOC) sensor 170B, etc.
[0047] 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.
[0048] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, central processing unit (CPU), and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0049] 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 directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0050] The processor includes n cores, such as n equal to 2, 4, 8, or 16. Optionally, each core runs at least one thread independently, and threads on different cores can run in parallel. For each thread within a core, the task it executes goes through stages such as fetch, decode, execute, read, and store.
[0051] When scheduling threads and / or processes, the processor 110 allocates scheduling time through a scheduler, determining which thread and / or process will have the opportunity to execute and for how long. During the process of the processor 110 implementing tasks by scheduling threads and / or processes, a higher scheduling frequency (or operating frequency) may lead to increased processor temperature and excessive memory bandwidth utilization. In some embodiments, when the processor 110 overheats or memory bandwidth utilization is too high, the processor 110's operating frequency may be reduced to alleviate heat generation and reduce memory bandwidth usage.
[0052] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0053] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, supplying power to the processor 110, internal memory 121, external memory (not shown in Figure 2), and wireless communication module 160. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be housed in the same device.
[0054] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0055] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.
[0056] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation.
[0057] A modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor.
[0058] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0059] Electronic device 100 implements display functions through GPUs, etc. A GPU is a microprocessor for image processing, connected to the display screen and the application processor. The GPU performs mathematical and geometric calculations and is used for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0060] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0061] The CPU, or Central Processing Unit, is responsible for the core functions of instruction interpretation, data processing, and hardware control, and is often referred to as the "brain" of a computer. Its core components include: the Arithmetic Logic Unit (ALU), which performs arithmetic and logical operations and includes the ALU and accumulator registers; the Control Unit, which coordinates the instruction execution flow and includes instruction control logic and timing control modules; and storage units, which temporarily store data, such as registers and caches.
[0062] The external storage interface 120 can be used to connect an external storage card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external storage card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, files such as music, videos, first information of the first thread group, and the operating status of the electronic device can be stored on the external storage card.
[0063] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook entries, first information of the first thread group, the operating status of the electronic device, etc.).
[0064] Temperature sensor 170A is used to detect temperature. In some embodiments, electronic device 100 uses temperature sensor 170A to detect the temperature inside and / or inside the electronic device and executes temperature handling strategies. For example, when the temperature reported by temperature sensor 170A exceeds a threshold, electronic device 100 can adjust the operation mode of the first thread group to reduce the performance of the processor located near temperature sensor 170A in order to reduce power consumption and implement thermal protection.
[0065] The SOC Sensor 170B is used to detect the memory bandwidth of sensors. The SOC Sensor 170B integrates the functionality of the entire system on a single chip, including processor cores (such as CPU, GPU, DSP, NPU, etc.), memory (such as RAM, ROM), peripheral interfaces (such as USB, I2C, SPI, etc.), and network interfaces (such as Wi-Fi, Bluetooth, Ethernet). This design not only reduces the number of components and connection complexity but also significantly improves the overall performance and reliability of the system.
[0066] The electronic device provided in this application embodiment can run an operating system (OS). This operating system can be various operating systems used in the industry, such as an operating system based on OpenHarmony, like HarmonyOS; or other operating systems such as Android. TM An operating system can refer to the iOS mobile operating system; it can also refer to various open-source operating systems or their derivatives, such as Linux OS and other embedded operating systems; or it can refer to future new operating systems, such as AI operating systems based on artificial intelligence. An operating system is a set of interconnected system software programs that manage and control the operation of electronic devices, utilize and run hardware and software resources, and provide public services to organize user interactions. In electronic devices, the operating system connects downwards to the physical devices at the hardware layer and upwards to provide a runtime environment for application software.
[0067] An operating system typically includes a kernel layer, a middleware layer, and an application layer. The application layer includes applications, which can include system applications and third-party applications, as shown in Figure 3. The middleware layer includes a series of software providing various services to application developers, or frameworks providing services such as databases, multimedia, and graphics, or capabilities such as distributed scheduling and system expansion. For example, the middleware layer may include a framework layer and / or a system service layer. The framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The system service layer includes the core capabilities of the system, providing services to applications through the framework layer. The kernel layer is the layer between hardware and software. The kernel layer may include hardware drivers and the operating system kernel. In addition to providing hardware drivers, the kernel layer also supports functions such as memory management and system process management.
[0068] The electronic devices we use in our daily lives come in various types and forms, and are applied in a wide range of scenarios. Therefore, based on the different forms and functions of electronic devices, different application scenarios, and different user needs, the operating systems used in these devices may also differ. The basic functions implemented by the electronic device provided in this application can be implemented using a general-purpose operating system or a dedicated operating system. To more clearly illustrate the implementation of the embodiments of this application under a specific operating system, the architecture of HarmonyOS is shown below. Those skilled in the art can deduce the implementation of the embodiments of this application under other specific operating systems, such as Android. TM Implementation under operating systems, etc.
[0069] The software architecture of electronic devices can be divided into several layers. In some embodiments, from bottom to top, these layers are: kernel layer, system service layer, framework layer, and application layer. Layers communicate with each other through software interfaces. System functions can be tailored, added, or combined at the subsystem level depending on the deployment scenario of different device forms. Each subsystem can also be tailored, added, or combined at the functional level.
[0070] The kernel layer includes, but is not limited to: the kernel abstract layer (KAL), the kernel subsystem, and the driver subsystem.
[0071] Kernel Abstraction Layer: By shielding the differences between multiple kernels, it provides basic kernel capabilities to the upper layers, including but not limited to process / thread management, memory management, file system, network management, and peripheral device management.
[0072] Kernel Subsystem: Supports the selection of a suitable OS kernel for different resource-constrained devices, including but not limited to Linux kernel, HarmonyOS kernel, LiteOS (Lite Operating System), etc.
[0073] Driver Subsystem: The driver framework is the foundation for the open system hardware ecosystem, providing unified peripheral access capabilities and a framework for driver development and management. The driver framework includes: display drivers, camera drivers, audio drivers, Bluetooth drivers, sensor drivers, etc.
[0074] The system service layer comprises the core capabilities of the system, providing services to applications through the framework layer. This layer involves multiple subsystem sets, including but not limited to: basic system capability subsystem set, basic software service subsystem set, enhanced software service subsystem set, and hardware service subsystem set.
[0075] The system's basic capability subsystem set provides fundamental capabilities for the operation, scheduling, and migration of distributed applications across multiple devices. This set may include distributed soft bus, distributed data management, distributed task scheduling, and Ark multi-language runtime; it may also include multi-modal input subsystem, graphics subsystem, security subsystem, and AI business subsystem.
[0076] Basic software service subsystem set: provides public and general software services; the basic software service subsystem set may include event notification subsystem, telephone service subsystem, multimedia subsystem, etc.
[0077] Enhanced software service subsystem suite: Provides differentiated enhanced software services for different devices; the enhanced software service subsystem suite may include smart screen proprietary business subsystem, wearable proprietary business subsystem, IoT proprietary business subsystem, etc.
[0078] Hardware service subsystem set: Provides hardware services; the hardware service subsystem set may include location service subsystem, user IAM (Identity and Access Management) subsystem, wearable proprietary hardware service subsystem, biometric identification, IoT proprietary hardware service subsystem, etc.
[0079] Distributed task scheduling enables distributed service management (discovery, synchronization, registration, and scheduling), supporting remote startup, remote scheduling, remote connection, and migration of applications across devices.
[0080] Distributed data management enables data synchronization, data storage, data sharing, and data access across all scenarios and devices.
[0081] The distributed soft bus provides communication-related capabilities for seamless interconnection between multiple devices, including: WLAN service capabilities, Bluetooth service capabilities, soft bus, inter-process communication RPC (Remote Procedure Call), and StarFlash communication capabilities.
[0082] Ark Multilingual Runtime is a unified compilation runtime platform designed to support the joint compilation and execution of multiple programming languages and multiple chip platforms.
[0083] The framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The framework layer includes: the ArkUI framework (which provides a complete infrastructure for UI development of system applications, including UI functions such as components, layouts, animations, and interactive events, as well as a real-time interface preview tool), the user application framework, and the Ability framework (an Ability is a lightweight application; the Ability framework schedules and manages the operation and lifecycle of Abilities). Different devices may have different operating systems, and the APIs they support may also differ.
[0084] The HarmonyOS API is a series of open capabilities provided to support HarmonyOS application development. The HarmonyOS API can be set at the framework layer or independently of the framework layer. The HarmonyOS API includes the Audio API (audio service), Push API (push service), and Account API (account service), among others.
[0085] Applications can include system apps and extended / third-party apps. System apps can include the desktop, control bar, settings, contacts, phone, camera, etc., while extended / third-party apps can include social apps, travel apps, etc.
[0086] The electronic device also includes a graphics subsystem (not shown in Figure 3), which mainly comprises UI components, layout, animation, fonts, input events, window management, rendering, and drawing modules. The graphics service provides graphics rendering and display output functions, and internally, through the rational utilization of system hardware resources, it provides a smooth and efficient display experience. The window management module is used to record the thread state of threads.
[0087] The application management module can be used to record the type and awareness status of an application (or its threads), such as an audio application or a multi-process application.
[0088] The decision module is used to determine the second running mode of the first thread group based on the first information of the first thread group.
[0089] The thread scheduling method provided in this application can be applied to smart devices such as mobile phones, tablets, laptops, and desktop computers. Alternatively, the electronic devices can also include wearable devices such as head-mounted displays (e.g., virtual reality devices, augmented reality devices, mixed reality devices), smartwatches, smart bracelets, and smart glasses. Furthermore, the electronic devices can also include smart home devices (such as televisions) and in-vehicle systems (such as vehicle terminals). The mobile phone can be a foldable screen phone or a non-foldable screen phone.
[0090] Currently, electronic devices typically use "processes" as the unit, scheduling multiple processes to complete a specified task. During process scheduling, multiple threads within that process are also scheduled. However, in this embodiment, the electronic device schedules threads as the unit. At least one thread group is created within the electronic device, and all threads within the same thread group are scheduled using the same running mode. The running mode used by the electronic device when scheduling each thread group can be different. The running mode indicates the scheduling parameters used by at least one processor of the electronic device when calling each thread group. The scheduling parameters include at least scheduling priority and / or scheduling frequency. The at least one processor can include a CPU, GPU, NPU, etc.
[0091] Here, scheduling priority determines the scheduling order of thread groups. When the processor is a CPU, the scheduling priority includes at least real-time priority, medium-priority non-real-time priority, and low-priority non-real-time priority. Specifically, the scheduling order of threads under real-time priority is > the scheduling order of threads under medium-priority non-real-time priority is > the scheduling order of threads under low-priority non-real-time priority.
[0092] In this context, real-time priority refers to the immediate scheduling of threads by the electronic device. Non-real-time medium priority means the electronic device will schedule threads after a first waiting period. Non-real-time low priority means the electronic device will schedule threads after a second waiting period, where the first waiting period is shorter than the second.
[0093] When the processor is an NPU, the scheduling priority includes at least the highest priority, high priority, medium priority, and low priority. Specifically, the scheduling order of threads at the highest priority is: > the scheduling order of threads at high priority > the scheduling order of threads at medium priority > the scheduling order of threads at low priority.
[0094] When the processor is a GPU, the scheduling priority includes at least the highest priority, high priority, medium priority, and low priority. Specifically, the scheduling order of threads at the highest priority is: highest priority > high priority > medium priority > low priority.
[0095] The scheduling frequency determines the operating frequency of the processor when scheduling thread groups. When the processor is an NPU, the scheduling frequency includes at least the highest frequency, high frequency, medium frequency, and lowest frequency. Specifically, the scheduling frequency of a thread at the highest frequency > the scheduling frequency of a thread at the high frequency > the scheduling frequency of a thread at the medium frequency > the scheduling frequency of a thread at the lowest frequency.
[0096] When the processor is a GPU, the scheduling frequency includes at least the highest frequency, high frequency, medium frequency, and lowest frequency. Specifically, the scheduling frequency of a thread at the highest frequency > the scheduling frequency of a thread at the high frequency > the scheduling frequency of a thread at the medium frequency > the scheduling frequency of a thread at the lowest frequency.
[0097] A thread group comprises multiple threads that work together to execute the same task. These threads can belong to different processes; in other words, a thread group includes multiple threads that span multiple processes.
[0098] Here, various common methods can be used to create thread groups, and this application does not specifically limit them. For example, Method 1, grouping by Session, refers to dividing multiple thread groups based on user session data (Session data) recorded in the electronic device during development. Method 2, grouping by whitelist, refers to assigning threads in the whitelist to the same thread group. Method 3, developer-defined grouping, refers to developers dividing thread groups using custom methods. Method 4, grouping by Cgroup, refers to identifying system-defined Cgroup groups (that is, system-defined process groups) as thread groups.
[0099] During the scheduling of thread groups in an electronic device, it is necessary to determine the operating mode of the thread group by combining the information of the thread group. This information includes the memory bandwidth of the electronic device, the device temperature, the thread state of the main thread in the thread group, and the task load of the thread group.
[0100] A thread group must contain at least one main thread, also known as the first thread. The first thread is the thread that created the thread group. When the first thread exits the thread group, another main thread, or third thread, needs to be determined from the remaining threads in the group. Specifically, the other main thread can be determined based on the developer's settings. For example, if the developer specifies multiple main threads when creating the thread group—a first thread, a third thread, etc.—the first thread is the main thread while it is still in the thread group, and the third thread becomes the main thread after it exits. Alternatively, the other main thread can be determined based on the running status of the remaining threads. For example, the thread in the "foreground focus" state can be designated as the other main thread.
[0101] The following describes a thread scheduling method provided by an embodiment of this application. This method is applied to an electronic device, and is illustrated using an example where the electronic device includes a first thread group, the first thread group includes multiple threads across processes, and the multiple threads include the first thread. As shown in Figure 4, the method may include the following steps S401 to S403.
[0102] S401. During operation, the electronic device schedules the first thread group in the first operating mode. This enables unified scheduling of multiple threads, thereby ensuring the completion speed of tasks coordinated by multiple threads.
[0103] In the process of scheduling multiple threads in the first thread group in the first running mode, different processors use different first scheduling parameters, including different first scheduling priorities and / or different first scheduling frequencies.
[0104] For example, taking a processor including a CPU and an NPU as an example, when scheduling the first thread group in the first running mode, the CPU schedules multiple threads in the first thread group with "non-real-time low priority"; while the NPU schedules multiple threads in the first thread group with "low priority" and "low frequency".
[0105] For another example, taking a processor including a CPU, GPU, and NPU as an example, when scheduling the first thread group in the first running mode, the CPU schedules multiple threads in the first thread group with "non-real-time low priority"; the NPU schedules multiple threads in the first thread group with "low priority" and "low frequency"; and the GPU schedules multiple threads in the first thread group with "low priority" and "low frequency".
[0106] Here, when scheduling the first thread group in the first running mode, each thread in the first thread group is scheduled with the same scheduling priority and / or scheduling frequency. For example, the first thread group includes thread 1 and thread 2, and the first running mode instructs the CPU to schedule thread 1 with a "non-real-time low priority" and the GPU to schedule thread 1 with a "low frequency." Similarly, the CPU also schedules thread 2 with a "non-real-time low priority," and the GPU also schedules thread 2 with a "low frequency."
[0107] In this system, multiple threads within the first thread group collaborate to execute the same task. These threads can belong to the same process or application, or they can belong to different processes or applications. For example, taking the "call summary" task as an example, the "call summary" task specifically involves a "call content acquisition" stage and a "summary content extraction" stage. The "call content acquisition" stage is completed by the "call application," and the "summary content extraction" stage is completed by the "AI processing module." Therefore, the first thread group includes the threads involved in the "call application" and the threads involved in the "AI processing module."
[0108] S402. When the electronic device is in an abnormal state, it obtains the first information of the first thread group.
[0109] The first information of the first thread group includes at least one of the following: the memory bandwidth of the electronic device, the device temperature of the electronic device (including the casing temperature, chip temperature, etc.), the thread state of the first thread in the first thread group, and the task load of the first thread group.
[0110] In some implementations, the thread state of a thread refers to the window state of the application to which the thread belongs. The window state includes at least one of the following: foreground focus state, foreground non-focus state, background visible state, and background invisible state. Specifically, the foreground focus state means that the display window of the application to which the thread belongs is running in the foreground of the electronic device and is the focus window in the foreground. The foreground non-focus state means that the display window of the application to which the thread belongs is running in the foreground of the electronic device and is visible to the user, but is not the focus window in the foreground. The background visible state means that the display window of the application to which the thread belongs is running in the background of the electronic device and is perceptible, such as an application accessing an audio device or an application with long-term background running permissions. The background invisible state means that the display window of the application to which the thread belongs is running in the background of the electronic device and is not perceptible.
[0111] In some examples, the first thread can include a regular thread, a background-aware thread, an extended thread, and a thread within a multi-process application. A background-aware thread refers to a thread running in the background of an electronic device but invoked by a foreground application, such as threads related to an audio device. An extended thread is a thread used to invoke services within the host process of the first application. These invoked services can include implementing functions of a second application, implementing functions of a background application, implementing database calls, implementing SDK capabilities, etc. For example, an extended thread can include a UI extension thread, which can be used to display the interface of the second application. A thread within a multi-process application refers to a thread running in multiple processes running simultaneously within an application.
[0112] The methods used to determine the thread state of different first threads are different:
[0113] In some examples, when the first thread is a normal thread in the first application, the window state of the first application can be determined based on the window types of the multiple display windows included in the window management module and the association between the application and the windows.
[0114] Specifically, firstly, based on the relationship between applications and windows, the display window of the first application is determined from multiple foreground display windows. Secondly, the window type of the first application's display window is determined from multiple window types. Finally, the window state of the first application is determined based on its window type. Here, when the window type indicates that the first application's display window is a focused window in the foreground, the window state of the first application is determined to be foreground focused. When the window type indicates that the first application's display window is a non-focused window in the foreground, the window state of the first application is determined to be foreground non-focused. When the window type indicates that the first application's display window is a "no-drawing window," the window state of the first application is determined to be background invisible.
[0115] In this context, a focused window is the window that the user is currently interacting with. A non-focused window is a window that is currently displayed in the foreground of the electronic device, but the user is not interacting with it. A non-drawing window is one that does not display any graphics or content, or whose drawing functions are not working properly.
[0116] In other examples, when the first thread is a background-aware thread in the first application, the window state of the first application can be determined based on the running permissions of the first application and / or the devices accessed.
[0117] Specifically, when the first application requests access to the audio device, or when the first application has long-term background running permissions, the window state of the first application is determined to be foreground focus state. Conversely, when the first application neither requests access to the audio device nor has long-term background running permissions, the window state of the first application is determined to be background-sensible state.
[0118] In other examples, when the first thread is an extended thread, the window state of the application to which the host process belongs can be used to determine the thread state of the first thread. Here, when the first thread is an extended thread, the method for determining the window state of the application to which the host process belongs is the same as the method for determining the running state of the first application when the first thread is a normal thread.
[0119] For example, taking the first application as a "social application," when a user opens the gallery interface of the photo application within the social application, the running process of the "social application" can be considered the host process, and the thread executing the action of "opening the gallery interface of the photo application" can be considered an extended thread. Since the thread executing the action of "opening the gallery interface of the photo application" is an extended thread of the social application, the thread state of the thread executing the action of "opening the gallery interface of the photo application" (that is, the extended process) is the window state of the "social application" (that is, the application to which the host process belongs).
[0120] In some implementations, when the first thread is an extended thread, the host process information of the extended thread can be directly obtained when determining its host process. Specifically, the host process information includes the process's package name, process ID, process type, and other information.
[0121] In other examples, when the first thread is a thread within a multi-process application, the window state of the application to which the main process belongs can be used to determine the thread state of the first thread. Here, when the first thread is a thread within a multi-process application, the method for determining the window state of the application to which the main process belongs is the same as the method for determining the window state of the first application when the first thread is a regular thread.
[0122] For example, taking the first application as a "browser", when a user opens multiple browsing pages in the browser, the running process of the "browser" can be regarded as the main process, and the running thread of each "browser page" can be regarded as a thread under the multi-process application. Since the running thread of the "browser page" is a thread under the running process of the "browser", the window thread state of the running thread of the "browser page" (that is, any thread under the multi-process application) is the window state of the "browser" (that is, the application to which the main process belongs).
[0123] In some implementations, when the first thread is a thread within a multi-process application, determining the main process of the first thread involves first identifying the first application to which the first thread belongs based on the thread information of the first thread. Secondly, the main process information of the first thread is obtained based on the application reporting information or PID Cgroup information of the first application.
[0124] The thread information for the first thread is recorded when it is created, and includes details such as the thread's package name, thread ID, and thread type. The process information for the main process is recorded when the main thread is created, and includes details such as the process's package name, process ID, and process type.
[0125] The following section describes the thread states of different first threads in conjunction with Table 1.
[0126] Table 1 Thread State Table
[0127] Specifically, for ordinary threads, there are at least three thread states: foreground focus state, foreground non-focus state, and background imperceptible state; for background-aware threads, there are at least two thread states: foreground focus state and background-aware state; for extended threads, the thread state is based on the window state of the host process; for threads in multi-process applications, the thread state is based on the window state of the application to which the main process belongs.
[0128] Here, "abnormal state of electronic device" can refer to an abnormal device status, such as excessively high casing temperature or excessively high temperature of chips (e.g., processor chips). It can also refer to an abnormal operating state of the electronic device, such as the electronic device being unable to complete the scheduling of the first thread group within the expected deadline; that is, the electronic device being unable to complete the tasks involved in the first thread group within the expected deadline.
[0129] Specifically, an abnormal state of an electronic device includes at least one of the following:
[0130] First, the electronic device's memory bandwidth usage exceeds the bandwidth usage threshold. Here, the double data rate SDRAM (DDR) in the electronic device periodically acquires information about the processor's memory bandwidth usage and the upper limit of bandwidth usage (i.e., the bandwidth usage threshold). When the electronic device's memory bandwidth usage exceeds the bandwidth usage threshold, it is determined that the electronic device is in an abnormal state.
[0131] Second, the device temperature of the electronic device exceeds a temperature threshold. Here, the temperature sensor and the SOC sensor in the electronic device are used to monitor the device temperature. The temperature sensor and the SOC sensor are used to periodically acquire the casing temperature and the chip temperature of the electronic device, respectively. When the casing temperature and / or the chip temperature of the electronic device exceed the temperature threshold, it is determined that the electronic device is in an abnormal state.
[0132] Third, the task load of the first thread group exceeds the load threshold. Here, the task completed collaboratively by multiple threads in the first thread group has an expected deadline; that is, the task needs to be completed within a specified time. When the task load of the first thread group exceeds the load threshold (i.e., the predicted load), if scheduling continues according to the current method, the task may not be able to be completed within the expected deadline. Therefore, when the task load of the first thread group exceeds the load threshold, the electronic device is determined to be in an abnormal state.
[0133] The predicted load is the upper limit of the task load that the first thread group can complete within the expected deadline, determined according to the current operating mode of the first thread group.
[0134] S403. The electronic device schedules the first thread group according to the first information and in the second operating mode. In this way, when the electronic device has an operational abnormality, the scheduling mode of the first thread group can be adjusted in a timely manner to alleviate the operational abnormality of the electronic device and reduce the probability of problems such as abnormal temperature, abnormal memory bandwidth usage, and abnormal task load of the first thread group.
[0135] In the process of scheduling multiple threads in the first thread group in the second operating mode of the electronic device, the scheduling parameters such as scheduling priority and / or scheduling frequency used by different processors in the electronic device are different.
[0136] For example, taking a processor including a CPU and an NPU as an example, when scheduling the first thread group in the second running mode, the CPU schedules multiple threads in the first thread group with "non-real-time medium priority"; while the NPU schedules multiple threads in the first thread group with "medium priority" and "lowest frequency".
[0137] For another example, taking a processor including a CPU, GPU, and NPU as an example, when scheduling the first thread group in the second running mode, the CPU schedules multiple threads in the first thread group with "non-real-time medium priority"; the NPU schedules multiple threads in the first thread group with "medium priority" and "lowest frequency"; and the GPU schedules multiple threads in the first thread group with "medium priority" and "lowest frequency".
[0138] Here, when scheduling the first thread group in the second running mode, each thread in the first thread group uses the same scheduling priority and / or scheduling frequency. For example, the first thread group includes thread 1 and thread 2, and the second running mode instructs the CPU to schedule thread 1 with "non-real-time medium priority" and the GPU to schedule thread 1 with "lowest frequency". Similarly, the CPU also schedules thread 2 with "non-real-time medium priority" and the GPU also schedules thread 2 with "lowest frequency".
[0139] In some implementations, when determining the second operating mode based on the first information, firstly, the operating speed of the electronic device is determined based on the memory bandwidth and device temperature in the first information. Secondly, the second operating mode of the electronic device is determined based on the thread state of the first thread in the first information and the operating speed of the electronic device.
[0140] The operating speed includes high speed, reduced speed, and pause. High speed means the processor processes data and performs operations at a higher speed; reduced speed means the processor processes data and performs operations at a lower speed; pause means the processor pauses data processing and operation.
[0141] In some implementations, when determining the operating speed of an electronic device based on the memory bandwidth and device temperature in the first information, the operating speed of the electronic device is determined to be "high speed" when the temperature of the electronic device is below a first temperature threshold and the memory bandwidth is below a first bandwidth occupancy threshold. The operating speed of the electronic device is determined to be "reduced speed" when the temperature of the electronic device is below a second temperature threshold and the memory bandwidth is below a second bandwidth occupancy threshold. The operating speed of the electronic device is determined to be "paused" when the temperature of the electronic device is above the second temperature threshold or the memory bandwidth is above the second bandwidth occupancy threshold.
[0142] The following section explains the correspondence between thread state, running speed, and running mode, in conjunction with Table 2.
[0143] Table 2 shows the correspondence between thread state, running speed, and running mode.
[0144] For example, when the thread state of the first thread in the first thread group is the foreground focus state and the electronic device is running at high speed, the second running mode corresponding to the first thread group includes the CPU scheduling multiple threads in the first thread group with "real-time priority", the NPU scheduling multiple threads in the first thread group with "highest priority" and "highest frequency", and the GPU scheduling multiple threads in the first thread group with "highest priority" and "highest frequency".
[0145] When the thread state of the first thread in the first thread group is in the foreground non-focus state, and the electronic device is running at high speed, the second running mode corresponding to the first thread group includes the CPU scheduling multiple threads in the first thread group with "non-real-time medium priority", the NPU scheduling multiple threads in the first thread group with "medium priority" and "medium frequency", and the GPU scheduling multiple threads in the first thread group with "medium priority" and "medium frequency".
[0146] When the first thread in the first thread group is in the foreground focus state and the electronic device is running at reduced speed, the second running mode corresponding to the first thread group includes the CPU scheduling multiple threads in the first thread group with "real-time priority", the NPU scheduling multiple threads in the first thread group with "highest priority" and "medium frequency", and the GPU scheduling multiple threads in the first thread group with "highest priority" and "medium frequency".
[0147] When the thread state of the first thread in the first thread group is in the foreground non-focus state, and the electronic device is running at reduced speed, the second running mode corresponding to the first thread group includes the CPU scheduling multiple threads in the first thread group with "non-real-time medium priority", the NPU scheduling multiple threads in the first thread group with "medium priority" and "lowest frequency", and the GPU scheduling multiple threads in the first thread group with "medium priority" and "lowest frequency".
[0148] In other implementations, when determining the second operating mode based on the first information, firstly, the thread state of the first thread is determined. Secondly, based on the task load of the first thread group, the thread state of the first thread is adjusted so that the call priority and call frequency corresponding to the adjusted thread state are higher than those corresponding to the thread state before adjustment. Then, the operating speed of the electronic device is determined based on the memory bandwidth and device temperature. Afterwards, based on the task load of the first thread group, the operating speed of the electronic device is adjusted so that the adjusted operating speed is higher than the original operating speed. Finally, the second operating mode of the electronic device is determined based on the adjusted thread state and the adjusted operating speed.
[0149] In some implementations, when adjusting the thread state of the first thread group based on its task load, the call priority and call frequency corresponding to the adjusted thread state are higher than those corresponding to the thread state before adjustment. For example, if the task load of the first thread group is large and it cannot complete the task execution within the expected deadline, the task load pressure on the first thread group can be alleviated by adjusting its thread state, thereby increasing the scheduling priority and scheduling frequency, and enabling the first thread group to complete the task execution within the expected deadline. For instance, the thread state of the first thread can be adjusted from "background aware state" to "foreground non-focus state".
[0150] In other implementations, when adjusting the operating speed of the electronic device based on the task load of the first thread group, the adjusted operating speed is higher than the original operating speed. If the task load of the first thread group is too large to complete the task execution within the expected deadline, the task load pressure on the first thread group can be alleviated by increasing the operating speed of the electronic device, allowing the first thread group to complete the task execution within the expected deadline. For example, the operating speed of the electronic device can be adjusted from "reduced" to "high speed".
[0151] During the operation of an electronic device, if a second operating mode suitable for the first thread group is determined temporarily through calculation after obtaining the initial information of the first thread group, the calculation process will not only consume the computing resources of the electronic device but also delay the time for adjusting the operating mode of the first thread group. Therefore, in order to determine the operating mode of the first thread group more quickly during the operation of the electronic device, multiple operating levels can be pre-defined, each corresponding to a specific operating mode. In this case, only the operating level corresponding to the first thread group needs to be determined to quickly identify the appropriate operating mode for the first thread group.
[0152] In some implementations, when scheduling the first thread group in a second operating mode based on the first information, firstly, the operating level corresponding to the first thread group is determined based on the first information of the first thread group. Secondly, based on the operating level corresponding to the first thread group, the second operating mode of the first thread group is obtained, and the first thread group is scheduled in the second operating mode.
[0153] The following section, in conjunction with Table 3, explains the correspondence between thread state, running speed, and running mode.
[0154] Table 3. Correspondence between thread state, running speed, and running level
[0155] The following section, in conjunction with Table 4, explains the correspondence between operating gears and operating modes.
[0156] Table 4. Correspondence between operating gear and operating mode
[0157] During the scheduling process of the first thread group, multiple threads within the first thread group can exit the first thread group after scheduling is complete. In some implementations, the first thread group is disbanded after a thread exits.
[0158] In some other implementations, the first thread group is not disbanded after the first thread leaves the first thread group. In this case, if the first thread in the first thread group leaves the first thread group, it is necessary to redetermine the operation mode of the first thread group to ensure that the operation mode of the first thread group is suitable for the multiple threads included in the first thread group.
[0159] In some implementations, when it is necessary to redetermine the operating mode of the first thread group, firstly, after the first thread exits the first thread group, a third thread is determined from the multiple remaining threads in the first thread group. Secondly, based on the third thread, third information about the first thread group is obtained. Finally, based on the third information, the first thread group is scheduled using a seventh operating mode. In this way, the scheduling mode of the first thread group can be adjusted in a timely manner when the number of threads in the first thread group changes, so as to determine a more suitable operating mode for the first thread group.
[0160] The third piece of information includes at least one of the following: the memory bandwidth of the electronic device, the device temperature of the electronic device (including the casing temperature, chip temperature, etc.), the thread state corresponding to the fifth thread in the first thread group, and the task load of the first thread group.
[0161] After the first thread exits the first thread group, the fifth thread is considered the main thread in the first thread group. The fifth thread can be a thread specified by the developer during the creation of the first thread group according to the grouping method. The fifth thread can also be determined based on the thread state of the remaining threads. For example, a thread with the "foreground focus state" can be designated as the fifth thread.
[0162] When an electronic device includes multiple thread groups, the operating modes of these thread groups can be adjusted simultaneously. In some implementations, the electronic device also includes a second thread group. First, during operation, the electronic device schedules the first thread group using a first operating mode while simultaneously scheduling the second thread group using a fifth operating mode. This allows for scheduling multiple threads within each thread group using its appropriate operating mode, ensuring that each thread group is scheduled in a suitable manner. Second, in case of an abnormal state, the electronic device obtains first information about the first thread group and second information about the second thread group. Finally, based on the first information, the electronic device schedules the first thread group using a second operating mode while simultaneously scheduling the second thread group using a sixth operating mode based on the second information. This allows for adjustments to the scheduling modes of the first and second thread groups when operational anomalies occur, mitigating the problems and reducing the probability of issues such as abnormal temperature, abnormal memory bandwidth usage, or abnormal workload of the first thread group. Simultaneously, it ensures that each thread group is scheduled in a suitable operating mode.
[0163] The second information includes at least one of the following: when the electronic device is in an abnormal state, the memory bandwidth of the electronic device, the device temperature of the electronic device (including the casing temperature, chip temperature, etc.), the thread state of the fourth thread in the first thread group, and the task load of the first thread group.
[0164] As mentioned above, the fourth thread is the main thread that requests the creation of the second thread group. The thread requesting the creation of the second thread group is the thread specified by the developer during the process of creating the second thread group according to the four grouping methods described above. In other words, the fourth thread in the second thread group is the thread specified by the developer when creating the second thread group.
[0165] In some examples, the method used to determine the thread state of the fourth thread is the same as that used to determine the thread state of the first thread, which will not be repeated here.
[0166] During the operation of electronic devices, some applications may "maliciously" create real-time (RT) threads to "seize" processor bandwidth. In order to reduce the probability of "maliciously" creating RT threads, this application embodiment supports the use of multiple management strategies at the dimensions of "thread group" and "Cgroup group" to adjust the running mode of threads and processes running in electronic devices.
[0167] As shown in Figure 5, when managing multiple threads at the "thread group" level, the threads can be divided into different thread groups. For example, the first thread group includes thread 1 and thread 2, and the second thread group includes threads 3 through 5. The same or different memory bandwidths can be set for different thread groups. Similarly, when managing multiple processes at the "process group" level, the threads can be divided into different process groups (i.e., Cgroups). For example, the first process group includes process 1 and process 2, and the second process group includes processes 3 through 5. The same or different memory bandwidths can be set for different process groups.
[0168] Here, there can be a one-to-one correspondence between threads and thread groups, or a one-to-many relationship. When the correspondence between threads and thread groups is one-to-many, the electronic device is prone to conflicts in the execution mode when adjusting the thread's execution mode (for example, thread 1 is simultaneously in the first thread group and the second thread group, the execution mode of the first thread group is to increase the CPU scheduling priority, while the execution mode of the second thread group is to decrease the CPU scheduling priority). Therefore, in this application, the correspondence between threads and thread groups is preferably set to a one-to-one correspondence.
[0169] When the relationship between threads and thread groups is preferably set to a one-to-many relationship, if conflicts arise in the execution modes of multiple thread groups, the thread group with the earliest execution time can be prioritized and scheduled according to its corresponding execution mode. Alternatively, the thread group with the highest task load can be prioritized and scheduled according to its corresponding execution mode.
[0170] Based on this, in order to solve the problem of applications "maliciously" creating RT threads, in addition to changing the running mode of the first thread group during the scheduling process, the running time quota of the first thread group can also be limited, and the running mode of multiple threads in the first thread group can be further adjusted, for example, limiting the CPU memory bandwidth that the first thread group can use.
[0171] Here, each thread group has at least two variables: one is the scheduling period, which refers to the period of time during which the thread group is scheduled; the other is the runtime, which refers to the time limit during which the thread group can occupy the processor (e.g., CPU) within a period.
[0172] In some implementations, the first thread group includes a second thread, and the second thread includes the first thread. When limiting the runtime quota of the first thread group, firstly, the electronic device obtains the scheduling time of the first thread group in the first scheduling cycle. Secondly, when the scheduling time of the first thread group in the first scheduling cycle exceeds a first time threshold, the second thread (RT thread) in the first thread group is scheduled in a third running mode. In this way, even if the electronic device does not experience any abnormalities, the running mode of the threads in the first thread group can still be adjusted in a timely manner, reducing the problem of "malicious" creation of RT threads and preemption of processor memory bandwidth. Finally, after the first thread group enters the second scheduling cycle, the running mode of the first thread group is restored to the first running mode, and multiple threads in the first thread group are scheduled in the first running mode. That is, when the runtime of the first thread group exceeds the first time threshold (e.g., 80% of memory bandwidth), the running of the threads in the first thread group is limited (e.g., THROTTLE or downgraded). Until the start of the next scheduling cycle (the second scheduling cycle), the threads in the first thread group will be limited again (e.g., UNTHROTTLE or upgraded). This prevents the second thread in the first thread group from creating an RT thread "maliciously" and preempting processor memory bandwidth.
[0173] The first time threshold is preset and can be set according to the memory bandwidth of the electronic device. The first time threshold is positively correlated with the memory bandwidth of the electronic device. That is, the larger the memory bandwidth of the electronic device, the larger the first time threshold; conversely, the smaller the memory bandwidth of the electronic device, the smaller the first time threshold.
[0174] In some examples, the second thread in the first thread group can be changed to a third running mode by adjusting its thread type to a thread scheduled by the CFS scheduler (CFS thread). This reduces the scheduling priority and frequency of the second thread, thereby avoiding the second thread from always running as an RT thread and occupying the processor's memory bandwidth for a long time.
[0175] Here, the first thread group also includes a third thread. The third thread refers to an exempted thread. An exempted thread is a RT thread with special execution privileges. When adjusting the execution mode of the second thread in the first thread group based on its scheduling time relative to the first thread group, the third thread is not subject to the first time threshold. That is, if the scheduling time of the first thread group exceeds the first time threshold, there is no need to adjust the execution mode of the third thread. However, the third thread is subject to a second time threshold (e.g., 95% of the system's global quota for electronic devices), and its execution mode is adjusted when the scheduling time of the first thread group exceeds the second time threshold.
[0176] In some implementations, when scheduling the third thread in the first thread group using the third running mode, the electronic device first obtains the scheduling time of the first thread group in the first scheduling cycle. Secondly, if the scheduling time of the first thread group in the first scheduling cycle exceeds a second time threshold, the third thread in the first thread group is scheduled using the fourth running mode. This way, even if the electronic device is not experiencing any abnormalities, the running mode of the threads in the first thread group can still be adjusted in a timely manner, reducing the risk of "malicious" creation of RT threads that preempt processor memory bandwidth. Finally, after the first thread group enters the second scheduling cycle, the running mode of the first thread group is restored to the first running mode, and multiple threads in the first thread group are scheduled using the first running mode. In other words, when the running time of the first thread group exceeds the second time threshold, the execution of the threads in the first thread group is restricted (e.g., limiting the scheduling priority and / or scheduling frequency (THROTTLE) of the second thread, or changing the type of the second thread). Until the start of the next scheduling cycle (the second scheduling cycle), the threads in the first thread group will be re-restricted (for example, the scheduling priority and / or scheduling frequency (UNTHROTTLE) of the second thread will be unrestricted, or the type of the second thread will be changed). This is to prevent the second thread in the first thread group from "maliciously" creating RT threads and preempting processor memory bandwidth.
[0177] The second time threshold is preset and can be set based on the memory bandwidth of the electronic device. The second time threshold is positively correlated with the memory bandwidth of the electronic device; that is, the larger the memory bandwidth of the electronic device, the larger the second time threshold; conversely, the smaller the memory bandwidth of the electronic device, the smaller the second time threshold. The second time threshold can also be set based on the system's global quota, for example, 95% of the electronic device's system's global quota.
[0178] In some examples, the third thread in the first thread group can be changed to a fourth running mode by adjusting its thread type to a thread scheduled by the CFS scheduler (CFS thread). This reduces the scheduling priority and frequency of the third thread, thereby avoiding the third thread from always running as an RT thread and occupying the processor's memory bandwidth for a long time.
[0179] The fourth operating mode can be the same as or different from the third operating mode.
[0180] For example, as shown in Figure 6, the first thread group includes RT threads (thread 1, thread 2, and thread 3) and a third thread (thread 4). In the first scheduling cycle, threads 1 through 4 are scheduled as RT threads for 30ms, 20ms, 30ms, and 30ms respectively (scheduled twice, the first time for 10ms and the second time for 20ms). When the scheduling time of the first thread group exceeds a first time threshold, threads 1 through 3 are changed from RT threads to CFS threads and continue to be scheduled within the first scheduling cycle (since thread 1 has already been scheduled, it is no longer scheduled). Threads 2 and 3 are rescheduled as CFS threads for 20ms and 30ms respectively. When the scheduling time of the first thread group exceeds a second time threshold (for example, after the first thread group has been scheduled for 95ms), thread 4 is changed from an RT thread to a CFS thread. After the first thread group enters the second scheduling cycle, threads 1 through 4 are changed from CFS threads back to RT threads.
[0181] In some implementations, the electronic device allows the creation of a second thread group under certain conditions. This allows the device to restrict the creation of thread groups by specifying conditions, allowing users (or applications) to create thread groups only when verification conditions are met, thus flexibly controlling the creation permissions of at least one thread group. Furthermore, this reduces the probability of users maliciously creating thread groups.
[0182] Among them, at least one thread group includes a first thread group, a second thread group, etc. The verification conditions include at least one of the following: the user who creates at least one thread group is an authorized user; the application that creates at least one thread group is an authorized application; the user who creates at least one thread group is a whitelisted user; the application that creates at least one thread group is a whitelisted application.
[0183] In other words, a user is only allowed to create a thread group if the user requesting the creation of at least one thread group is an authorized user or a whitelisted user. Alternatively, the creation of a thread group for an application is only allowed if the application requesting the creation of at least one thread group is an authorized application or a whitelisted application.
[0184] The creation process of the second thread group is explained below with reference to Figure 7. When there is a need to create a second thread group, when the electronic device receives a request to create a second thread group, it verifies whether the user and application requesting the creation of the second thread group meet the conditions. First, it determines whether the user requesting the creation of the second thread group is an authorized user. If so, the creation of the second thread group is allowed. If not, it determines whether the application requesting the creation of the second thread group is an authorized application. If so, the creation of at least one thread group is allowed. If not, it can also be combined with whitelisted users and whitelisted applications to determine whether the user requesting the creation of the second application is a whitelisted user or whether the application requesting the creation of the second application is a whitelisted application. If so, the creation of the second thread group is allowed, and according to the memory bandwidth of the electronic device, parameters such as the runtime quota of the second thread group (including the first time threshold and the second time threshold) and at least two variables involved in the second thread group (including the scheduling cycle and runtime of the second thread group) are set during the scheduling process of the second thread group. If not, the creation of the second thread group ends.
[0185] The following, with reference to Figure 8, describes the collaboration process between various modules during the adjustment of the operation mode of the first thread group. The temperature sensor detects the device temperature of the electronic device (including the casing temperature and / or chip temperature) and reports the obtained device temperature to the decision module. The SOC sensor detects the memory bandwidth of the electronic device and reports the obtained memory bandwidth to the decision module. The window management module obtains the thread status corresponding to the first thread and reports the obtained thread status to the decision module. The application management module obtains the type and perception status of the application (or threads under the application) and reports the obtained application type and perception status to the decision module. The load module obtains the expected deadline and task load of the task to be completed collaboratively by multiple threads in the first thread group and reports the obtained expected deadline and task load to the decision module.
[0186] The decision module determines the operating mode of the first thread group based on at least one of the following: device temperature, memory bandwidth, thread state, application type and perception state, expected deadline and task load (at least one of these), and reports this information to the kernel of the electronic device. The kernel of the electronic device schedules the first thread group according to the operating mode.
[0187] In some solutions, multiple embodiments of this application can be combined, and the combined solution can be implemented. Optionally, some operations in the processes of each method embodiment may be combined, and / or the order of some operations may be changed. Furthermore, the execution order between the steps of each process is merely exemplary and does not constitute a limitation on the execution order between steps; other execution orders are also possible. It is not intended to indicate that the execution order is the only possible order in which these operations can be performed. Those skilled in the art will conceive of various ways to reorder the operations described in the embodiments of this application. In addition, it should be noted that the process details involved in one embodiment of this application are also applicable to other embodiments in a similar manner, or different embodiments may be combined.
[0188] Furthermore, some steps in the method embodiments can be equivalently replaced with other possible steps. Alternatively, some steps in the method embodiments may be optional and can be deleted in certain use cases. Or, other possible steps may be added to the method embodiments. Moreover, the various method embodiments can be implemented individually or in combination.
[0189] It is understood that, in order to achieve the above functions, the aforementioned electronic device includes hardware and / or software modules corresponding to perform each function. Based on the algorithmic steps of the various examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.
[0190] This application embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0191] This application also provides an electronic device, as shown in FIG9, which may include one or more processors 901, a memory 902, and a communication interface 903. The memory 902 and the communication interface 903 are coupled to the processor 901. For example, the memory 902, the communication interface 903, and the processor 901 may be coupled together via a bus 904. The communication interface 903 is used for data transmission with other devices. The memory 902 stores computer program code. The computer program code includes computer instructions, which, when executed by the processor 901, cause the electronic device to perform the thread scheduling method described in this application embodiment.
[0192] The processor 901 can be a processor or controller, such as a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with this disclosure. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0193] The bus 904 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus 904 can be categorized as an address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in Figure 9, but this does not indicate that there is only one bus or one type of bus.
[0194] This application also provides a computer-readable storage medium storing computer program code. When the processor executes the computer program code, the electronic device performs the relevant method steps in the above method embodiments. This application also provides a chip including a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, which includes computer instructions. When the computer instructions are executed by the processor, the chip performs the relevant method steps in the above method embodiments. The electronic device, computer storage medium, and chip provided in this application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here. Through the description of the above embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0195] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units 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 device, or some features may be ignored or not executed. Furthermore, the mutual 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, mechanical, or other forms.
[0196] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units, meaning it can be located in one place or distributed across multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs. 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 units described above can be implemented in hardware or as software functional units.
[0197] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, in essence, or the part that contributes, or all or part of the technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0198] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A thread scheduling method, characterized in that, The method is applied to an electronic device, the electronic device including a first thread group; the first thread group includes at least two threads that cross processes; the at least two threads include the first thread, and the at least two threads cooperate to complete the same task; the method includes: During the operation of the electronic device, the first thread group is scheduled in a first operating mode; When the electronic device is in an abnormal state, first information of the first thread group is obtained; the first information includes at least one of the following: memory bandwidth of the electronic device in an abnormal state, device temperature, thread state corresponding to the first thread in the first thread group, and task load of the first thread group; Based on the first information, the first thread group is scheduled in the second operating mode.
2. The method according to claim 1, characterized in that, The electronic device includes at least one processor, and the first operating mode is used to indicate the scheduling priority and / or scheduling frequency when the at least one processor schedules the at least two threads in the first thread group; the at least one processor includes at least one of the following: a central processing unit, a graphics processing unit, and a neural network processor.
3. The method according to claim 1, characterized in that, The abnormal state of the electronic device includes at least one of the following: the memory bandwidth usage of the electronic device exceeds the bandwidth usage threshold, the device temperature of the electronic device exceeds the temperature threshold, and the task load of the first thread group exceeds the load threshold.
4. The method according to any one of claims 1-3, characterized in that, The first thread group includes a second thread. During the scheduling of the first thread group in a first running mode, the method further includes: When the scheduling time of the first thread group in the first scheduling cycle is greater than the first time threshold, the second thread in the first thread group is scheduled in the third running mode. Wherein, the first time threshold is positively correlated with the memory bandwidth of the electronic device; the scheduling priority of the second thread in the first running mode is greater than the scheduling priority of the second thread in the third running mode; and / or, the scheduling frequency of the second thread in the first running mode is greater than the scheduling frequency of the second thread in the third running mode.
5. The method according to claim 4, characterized in that, In the process of scheduling the second thread in the third operating mode, the method further includes: When the first thread group enters the second scheduling cycle, the second thread in the first thread group is scheduled in the first running mode.
6. The method according to claim 4, characterized in that, The first thread group also includes a third thread. During the scheduling of the second thread in the first thread group in a third running mode, the method further includes: When the scheduling time of the first thread group in the first scheduling cycle is greater than the second time threshold, the third thread in the first thread group is scheduled in the fourth running mode. Wherein, the second time threshold is positively correlated with the memory bandwidth of the electronic device, or the second time threshold is positively correlated with the system global quota of the electronic device; the first time threshold is less than the second time threshold; the scheduling priority of the third thread in the first running mode is greater than the scheduling priority in the fourth running mode, and / or the scheduling frequency in the first running mode is greater than the scheduling frequency in the fourth running mode.
7. The method according to claim 6, characterized in that, In the process of scheduling the third thread in the fourth running mode, the method further includes: When the first thread group enters the second scheduling cycle, the third thread in the first thread group is scheduled in the first running mode.
8. The method according to any one of claims 1-7, characterized in that, The method further includes: A second thread group is created if the following conditions are met: the user creating the second thread group is an authorized user, the application creating the second thread group is an authorized application, the user creating the second thread group is a whitelisted user, or the application creating the second thread group is a whitelisted application.
9. The method according to any one of claims 1-7, characterized in that, The electronic device further includes a second thread group scheduled in a fifth operating mode, and the method further includes: When the electronic device is in the abnormal state, the second information of the second thread group is obtained; the second information includes at least one of the following: the memory bandwidth of the electronic device in the abnormal state, the device temperature, the thread state corresponding to the fourth thread in the second thread group, and the task load of the second thread group; Based on the second information, the second thread group is scheduled in the sixth operating mode.
10. The method according to any one of claims 1-9, characterized in that, When the first thread is an extended thread, the thread state of the first thread is the window state of the application to which the host process belongs.
11. The method according to any one of claims 1-10, characterized in that, When the first thread is a thread in a multi-process application, the thread state corresponding to the first thread is the window state of the application to which the main process of the first thread belongs, and the multi-process includes the main process.
12. The method according to any one of claims 1-11, characterized in that, The method further includes: After the first thread exits the first thread group, the first thread group is disbanded.
13. The method according to any one of claims 1-12, characterized in that, The thread state of the first thread in the first thread group includes at least one of the following: foreground focus state, foreground non-focus state, background sensed state, and background non-sensed state.
14. An electronic device, characterized in that, The device includes a memory and one or more processors; the memory is coupled to the processors; the memory stores computer program code, the computer program code including computer instructions, which, when executed by the processor, cause the electronic device to perform the thread scheduling method as described in any one of claims 1-13.
15. A computer-readable storage medium, characterized in that, Includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the thread scheduling method as described in any one of claims 1-13.
16. A computer program product, characterized in that, When the computer program product is run on an electronic device, the electronic device performs the thread scheduling method as described in any one of claims 1-13.
