Process control method, electronic equipment and readable storage medium

By detecting the foreground event, the process queue time slice is adjusted, and the foreground lag caused by excessive backend load of electronic devices is solved, and the stability of the foreground application and the extension of the device life is achieved.

CN120448045APending Publication Date: 2025-08-08HUAWEI TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410176395.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-02-07
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

The excessive backend load of electronic devices leads to insufficient resources of the foreground process, causing the front-end to stutter and affecting the service life of the equipment.

Method used

By detecting foreground events, adjust the time slice allocated by the processor to different process queues, increase the time of the foreground process queue, reduce the time of the background process queue, and realize dynamic scheduling to reduce resource usage.

Benefits of technology

Effectively reduce front-end lag, avoid excessive back-end load, and ensure the stability of front-end applications and equipment life.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448045A_ABST
    Figure CN120448045A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of electronic equipment, and discloses a process control method, electronic equipment and a readable storage medium. According to the electronic equipment, when the foreground event is detected, the time for allowing all the process queues to run in the single scheduling period allocated by the processor to different process queues can be adjusted in time. For example, the first process queue comprises the to-be-run processes related to the foreground application, and the second process queue comprises the to-be-run processes related to the background application, so that the time allocated to the first process queue is increased, more to-be-run processes related to the foreground application can have enough running time, and foreground jamming is reduced. And moreover, the time allocated to the second process queue is shortened, the to-be-run processes related to the background application are suppressed, and the situation that the processes occupy too much resources during running, and consequently the background load is too large can be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] As electronic devices improve in performance, more and more applications (APPs) are installed on them, and the background load of these devices is also increasing. Background load refers to the resources occupied by background processes, including processor (central processing unit, CPU) resources, memory resources, etc.

[0003] Because electronic devices have limited CPU and memory resources, excessive background load not only reduces available resources for foreground processes, causing foreground lag, but also causes electronic devices to overheat, shortening their lifespan. Therefore, it's necessary to manage background processes to avoid excessive background loads on electronic devices. Summary of the Invention

[0004] In order to solve the above technical problems, the embodiments of the present application provide a process control method, an electronic device and a readable storage medium.

[0005] In the first aspect, an embodiment of the present application provides a process control method, which is applied to an electronic device, and the method includes: detecting a foreground event, obtaining a first time allocated to a first process queue and a second time allocated to a second process queue within a current scheduling cycle of the processor; the first process queue includes to-be-run processes related to foreground applications, and the second process queue includes to-be-run processes related to background applications; determining a third time allocated to the first process queue and a fourth time allocated to the second process queue within the next scheduling cycle of the processor; wherein the third time is greater than the first time, and the fourth time is less than the second time.

[0006] Based on the above solution, when a foreground event is detected, the electronic device can promptly adjust the time allowed for each process queue to run within a single scheduling cycle allocated by the processor to different process queues. For example, the first process queue includes pending processes related to the foreground application, and the second process queue includes pending processes related to the background application. Therefore, increasing the time allocated to the first process queue can ensure that more pending processes related to the foreground application have sufficient running time, reducing foreground lag. In addition, reducing the time allocated to the second process queue can suppress pending processes related to the background application, preventing these processes from occupying too many resources when running, resulting in excessive background load.

[0007] In some embodiments of the first aspect above, the first process queue includes a first process related to a first foreground event, and the method further includes: detecting a first foreground event triggered by a foreground application and creating a first process; wherein the first foreground event includes any one of user operation, foreground application startup, and automatic playback of multimedia content.

[0008] It can be understood that the first process is created based on the first foreground event, and therefore, the first process may be the foreground process mentioned in this application.

[0009] In some embodiments of the first aspect above, the first process queue corresponds to the first group, and the processes in the first group wait to run in the first process queue when they are scheduled; the second process queue corresponds to the second group, and the processes in the second group wait to run in the second process queue when they are scheduled.

[0010] It can be understood that the electronic device of the present application can manage all processes in groups, and processes in the same group will be placed in the same process queue waiting to be run.

[0011] In some embodiments of the first aspect above, the first group includes the foreground processes of the foreground applications, or the first group includes the foreground processes and the first type of system processes associated with the foreground processes; the second group includes the first type of background processes of the background applications, and the first type of background processes belong to background services whose service importance is lower than the first importance.

[0012] It can be understood that the processes of this application can be roughly divided into foreground processes, background processes, and system processes. When performing group management, they are divided according to the services provided by each process. Among them, the system process can include a first type of system process, which can provide foreground-related services. For example, foreground-related services can include communication services, positioning services, etc. Background processes can include a first type of background process, which is mainly used to provide background unimportant tasks.

[0013] It can be understood that all background services involved in actual scenarios are divided into levels according to the importance of the services. This application does not limit the number of levels, and the first level of importance can correspond to any level.

[0014] In some embodiments of the first aspect above, it also includes: detecting that there is a second process in the first process queue accessing the critical section; during the running time of the second process queue, moving the third process in the second process queue that carries the critical section label to the head position of the second process queue, and the third process accesses the critical section before the second process; during the running time of the first process queue, moving the third process from the head position to the first process queue.

[0015] It can be understood that by setting a critical section label for the background process associated with the foreground, or in other words, the background process that accesses the same critical resource as the foreground process, the kernel of the electronic device can quickly release the suppression of the background process when it detects the critical section label, thereby avoiding blocking the foreground process and preventing the foreground application from freezing.

[0016] In some embodiments of the first aspect above, the method further includes: determining, within each scheduling cycle of the processor, the time allocated to the third process queue based on the overall load or overall temperature of the electronic device; wherein the third process queue corresponds to a third group, the third group includes the second type of system processes, and the second type of system processes belong to system resident services.

[0017] The system process may further include a second type of system process, which may provide system resident services. For example, the system resident services may include security detection services, time synchronization services, and the like.

[0018] It can be understood that the present application can adopt a dynamic quota control scheduling strategy for the third group, that is, the electronic device can dynamically adjust the time quota of the third group according to the whole machine load and / or the whole machine temperature, so that when the whole machine load or the whole machine temperature is high, the whole machine load or the whole machine temperature can be effectively reduced without affecting the foreground application.

[0019] In some embodiments of the first aspect above, it also includes: within each scheduling cycle of the processor, based on a fixed weight, determining the time allocated to the fourth process queue; wherein the fourth process queue corresponds to a fourth group, the fourth group includes third-class system processes and second-class background processes, the third-class system processes belong to delayable system services, and the second-class background processes belong to delayable background services.

[0020] The system process may further include a third type of system process, which may provide deferred system services, such as system version update services and system data synchronization. The background process may further include a second type of background process, which is used to provide deferred background services, such as application data upload, download, and synchronization services.

[0021] It can be understood that the present application can adopt a scheduling strategy of persistent quota control for the fourth group, that is, the electronic device can set the weight of the fourth group to a fixed weight, and the fixed weight is relatively small. In this way, the fourth group can be persistently suppressed within multiple scheduling cycles to avoid the occurrence of high load caused by delayed services.

[0022] In some embodiments of the first aspect above, the method also includes: detecting upload and download events of background applications, executing acquisition of the first time allocated to the first process queue and the second time allocated to the second process queue within the current scheduling cycle of the processor, and determining the third time allocated to the first process queue and the fourth time allocated to the second process queue within the next scheduling cycle of the processor.

[0023] In some embodiments of the first aspect above, the method also includes: detecting a foreground event, and / or detecting that a load change of a foreground application satisfies a process control condition, executing acquisition of a first time allocated to the first process queue and a second time allocated to the second process queue within a current scheduling cycle of the processor, and determining a third time allocated to the first process queue and a fourth time allocated to the second process queue within a next scheduling cycle of the processor.

[0024] It is understandable that the timing for the electronic device to adjust the time quota may also include determining whether the process control conditions are met based on the load changes of the foreground application.

[0025] In some embodiments of the first aspect above, the method also includes: detecting the load rate occupied by the first group in each scheduling cycle of the processor; and determining whether the load change of the foreground application meets the process control conditions based on the load rate of the first group in each scheduling cycle.

[0026] In some embodiments of the first aspect above, the load rate of the first group in each scheduling period includes: the current load rate of the current scheduling period, and the historical load rate in the historical scheduling period; the process control conditions include at least one of the following: the current load rate of the first group in the current scheduling period is greater than the historical load rate occupied by the first group in the historical scheduling period; the increment of the current load rate compared to the historical load rate is greater than the first increment; the current load rate is greater than the first load rate threshold.

[0027] The historical scheduling period may include the previous scheduling period of the current scheduling period, or any multiple scheduling periods before the current scheduling period. Accordingly, the historical load rate occupied in the historical scheduling period may include the historical average load rate, that is, the average value of multiple historical load rates corresponding to any multiple scheduling periods before the current scheduling period. The first increment may be the preset increment mentioned in this application. The first load rate threshold may refer to the foreground load threshold mentioned in this application.

[0028] In some embodiments of the first aspect above, it also includes: in each scheduling cycle of the processor, based on the time weight of the first group, determining the time allocated to the first process queue; in each scheduling cycle of the processor, based on the time weight of the second group, determining the time allocated to the second process queue; wherein the time weight represents the time allowed for each group to run in each scheduling cycle; the time weight of the first group and the time weight of the second group change according to the load change of the foreground application.

[0029] The time weight may refer to the weight mentioned in this application. In Linux systems, the weight can be set by configuring the cpu.share parameter. The time allocated to each process queue is calculated based on the weight.

[0030] In some embodiments of the first aspect above, obtaining the first time allocated to the first process queue and the second time allocated to the second process queue within the current scheduling cycle of the processor includes: obtaining the first time weight of the first group and the second time weight of the second group within the current scheduling cycle of the processor; obtaining the first time based on the product of the first time weight and the unit scheduling cycle of the processor; and obtaining the second time based on the product of the second time weight and the unit scheduling cycle.

[0031] In some embodiments of the first aspect above, determining the third time allocated to the first process queue and the fourth time allocated to the second process queue in the next scheduling cycle of the processor includes: increasing the first time weight to obtain the third time weight of the first group in the next scheduling cycle; reducing the second time weight to obtain the fourth time weight of the second group in the next scheduling cycle; obtaining the third time based on the product of the third time weight and the unit scheduling cycle; and obtaining the fourth time based on the product of the fourth time weight and the unit scheduling cycle.

[0032] In some embodiments of the first aspect above, the third time is less than the first time, and the fourth time is greater than the second time.

[0033] In some embodiments of the first aspect above, the process control conditions include at least one of the following: the current load rate of the first group in the current scheduling period is less than the historical load rate occupied by the first group in the historical scheduling period; the decrease in the current load rate compared to the historical load rate is greater than or equal to the first decrease; the current load rate is less than the second load rate threshold.

[0034] It can be understood that if the electronic device indicates a load reduction based on the load change of the foreground application, it can reduce the time allocated to the first process queue and increase the time allocated to the second process queue, so as to avoid the suppression of the background application process and the unavailability of the service without affecting the foreground application.

[0035] The first decrease amount may be the preset decrease amount mentioned in this application. The second load rate threshold may be the foreground load threshold mentioned in this application, or any value less than the foreground load threshold.

[0036] In a second aspect, an embodiment of the present application provides an electronic device comprising one or more processors and one or more memories, wherein the one or more memories store one or more programs. When the one or more programs are executed by one or more processors, the electronic device executes the process control method of the first aspect described above.

[0037] In a third aspect, an embodiment of the present application provides a readable storage medium, on which instructions are stored. When the instructions are executed on an electronic device, the electronic device executes the process control method of the first aspect mentioned above. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1A According to some embodiments of the present application, a schematic diagram of a main interface 101 on a mobile phone 10 is shown;

[0039] Figure 1B According to some embodiments of the present application, a schematic diagram of a first application interface 102 on a mobile phone 10 is shown;

[0040] Figure 1C According to some embodiments of the present application, a schematic diagram of a second application interface 103 on a mobile phone 10 is shown;

[0041] Figure 2 According to some embodiments of the present application, a schematic diagram of the hardware structure of a mobile phone 10 is shown;

[0042] Figure 3 According to some embodiments of the present application, a flowchart of a process control method is shown;

[0043] Figure 4 According to some embodiments of the present application, a schematic diagram of a CPU scheduling process is shown;

[0044] Figure 5 According to some embodiments of the present application, a process control architecture diagram is shown;

[0045] Figure 6 According to some embodiments of the present application, a flowchart of another process control method is shown;

[0046] Figure 7 According to some embodiments of the present application, another process control architecture diagram is shown;

[0047] Figure 8According to some embodiments of the present application, a schematic diagram of the gear positions of the whole machine load / whole machine temperature is shown;

[0048] Figure 9 According to some embodiments of the present application, a schematic diagram of a process control method based on a critical section is shown. DETAILED DESCRIPTION

[0049] The illustrative embodiments of the present application include, but are not limited to, a process control method.

[0050] In order to more clearly understand the solution of this application, the relevant field terms involved in this application are first explained.

[0051] Foreground application: When an application runs in the foreground of an electronic device, it is called a foreground application. In other words, when an electronic device displays an application's interface, the application is called a foreground application. Foreground applications can provide services that are visible and perceptible to the user.

[0052] Foreground process: In the process group of an application, the process related to the service that is visible and perceptible to the user (hereinafter referred to as the foreground service) is the foreground process.

[0053] Background Apps: When an application runs in the background of an electronic device, it is called a background app. In other words, even though the electronic device doesn't display the application's interface, the application can still provide related services, such as uploading and downloading data. Background apps can provide services that are invisible and intangible to the user.

[0054] Background process: In the process group of an application, the process related to services that are invisible and imperceptible to the user (hereinafter referred to as background services) is a background process.

[0055] It is understandable that when an application runs in the foreground of an electronic device, its process group may also include background processes.

[0056] System process: A process that is automatically created and run by the operating system of an electronic device when it is turned on. It can be called by foreground or background processes to provide basic services such as positioning and network access to foreground or background applications.

[0057] It can be understood that the system process is also a process running in the background. Therefore, the background running processes mentioned in this application may include the background processes of the application and the system processes.

[0058] For example, the electronic device is a mobile phone. Figure 1A As shown in the main interface 101 of the mobile phone 10, APP1 to APP8 are installed in the mobile phone 10. When the user clicks APP1, the mobile phone 10 starts APP1. Figure 1BAs shown, APP1 can be an application market. During the launch of APP1, mobile phone 10 creates and runs process group 1 for APP1. This process group 1 may include process P11, which launches APP1, and process P12, which loads the first application interface 102 of the application market. After running processes P11 and P12, mobile phone 10 displays first application interface 102. At this point, the application market is the foreground application.

[0059] It is understandable that the user can operate the first application interface 102. For example, if the user clicks the download control 1021 of APP9, a new process P13 for downloading APP9 will be added to process group 1. Since the download process is not visible, process P13 belongs to the background process. For another example, when the user clicks the control 1022 of the photography category in the first application interface 102, Figure 1C As shown, the mobile phone 10 needs to jump from the first application interface 102 to the second application interface 103 corresponding to the control 1022. At this time, a new process P14 for loading the second application interface 103 is added to the process group 1. Since the second application interface 103 is visible to the user, the process P14 belongs to the foreground process. For another example, when the user clicks the control 1031 to return to the main interface 101 in the second application interface 103, the mobile phone 10 returns to the foreground process. Figure 1A In the main interface 101 shown, the application market now becomes a background application.

[0060] As mentioned above, electronic devices need to manage and control background processes to avoid excessive background loads that can cause foreground lag or even device overheating. For example, when a user clicks on the control 1021 for downloading APP9 in the first application interface 102, and also clicks on the controls for downloading APP10, APP11, or even more apps, multiple background processes for downloading apps will be running on the phone 10, which can easily lead to excessive background load and affect the phone 10's response to the user clicking on the control 1022, i.e., the jump speed from the first application interface 102 to the first application interface 103 will be slow.

[0061] In some embodiments, the electronic device monitors the background load in real time and clears the background processes when the background load is too high or the background load increases too much over a period of time. However, this approach has a lag effect. If the background load is too high and control is performed only after it has occurred, the foreground may have already been sluggish. Furthermore, if a large number of background processes are not cleared in a timely manner, it can easily cause a system crash and render the service unavailable.

[0062] In other embodiments, when an application switches from the foreground to the background, the electronic device freezes or intercepts the application's process group. For example, in an electronic device running a Linux operating system, a freeze instruction is used to suspend the entire process group. However, this will result in the application's background process having no chance to run, making it unable to provide background services, and causing the application to become inoperative.

[0063] In some other embodiments, the electronic device controls the execution time of some background processes (such as log printing), and postpones some background processes to run when the electronic device is idle (for example, when the screen is off or charging). However, this control method is not complete and cannot be applied to all background processes. Background processes such as downloading apps, uploading and downloading data, and synchronizing data in the cloud cannot wait until the electronic device is idle to run.

[0064] Based on this, an embodiment of the present application provides a process control method. When an electronic device detects that the load of a foreground application meets a process control condition (for example, the load of the foreground application increases), different time slices are allocated to the foreground process, background process, and system process to be scheduled in the next scheduling cycle of the CPU. For example, the time slice of the foreground process and the system process associated with the foreground process is increased, and the time slice of the background process and other system processes is reduced. The time slice represents the processing time allocated to the process in a single scheduling cycle, that is, the time allowed for the process to run. It can be understood that before being scheduled by the CPU, the process is in a ready state and does not occupy CPU resources and memory resources. After being scheduled by the CPU, it is in a running state and occupies CPU resources and memory resources. In this way, when the load of the foreground application increases, the electronic device can promptly reduce the time allowed for the background process and other system processes to run in the next scheduling cycle of the CPU. By reducing the time slices of these processes, the CPU resources occupied by these processes when they are running are reduced, so that when the CPU schedules these processes in the next scheduling cycle, the running of these processes will not cause excessive background load, thus avoiding the occurrence of excessive background load. In addition, increasing the time slice of the foreground process and its associated system process can ensure the service stability of the foreground application.

[0065] The scheduling period refers to the division of continuous CPU processing time into periodic CPU processing time. Generally, a single scheduling period can be 100 milliseconds. Within each scheduling period, different processes or process groups occupy the same or different time slices. For example, if two processes occupy the same time slice, they can each be allocated 50ms of scheduling time.

[0066] Before describing the process control method according to the embodiment of the present application in detail, the electronic devices mentioned in the embodiment of the present application will be described below. It is understood that the electronic devices in the embodiment of the present application can be mobile phones, tablet computers, desktop computers, laptop computers, handheld computers, netbooks, augmented reality (AR) / virtual reality (VR) devices, smart TVs, smart watches, and other electronic devices, without limitation.

[0067] Taking a mobile phone as an example, the following is a schematic diagram of the hardware structure of the mobile phone 10 capable of implementing the method of the present application.

[0068] like Figure 2 As shown, the mobile phone 10 may include a processor 201, a wireless communication module 202, a mobile communication module 203, a power module 204, an audio module 205, an interface module 206, a camera 207, a memory 208, a sensor module 209, a button 210 and a display screen 211, etc.

[0069] The processor 201 may include one or more processing units, for example, a processing module or processing circuit including a CPU, a graphics processing unit (GPU), a digital signal processor (DSP), a microprocessor (MCU), an artificial intelligence (AI) processor, or a programmable logic device (FPGA). Different processing units may be independent devices or integrated into one or more processors. A storage unit may be provided in the processor 201 for storing instructions and data. In some embodiments, the storage unit in the processor 201 is a cache memory. In some embodiments of the present application, the processor 201 may be used to execute the process control method mentioned in the present application.

[0070] The wireless communication module 202 may include an antenna and transmit and receive electromagnetic waves via the antenna. The wireless communication module 202 may provide wireless communication solutions for the mobile phone 10, 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), infrared (IR), and the like. The mobile phone 10 may communicate with the network and other devices through wireless communication technologies.

[0071] The mobile communication module 203 may include, but is not limited to, an antenna, a power amplifier, a filter, a low noise amplifier (LNA), etc. The mobile communication module 203 may provide a solution for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the mobile phone 10 .

[0072] In some embodiments, the mobile communication module 203 and the wireless communication module 202 of the mobile phone 10 may also be located in the same module.

[0073] The audio module 205 is used to convert digital audio information into analog audio signal output, or convert analog audio input into digital audio signal. The audio module 205 can also be used for audio signal encoding and decoding. In certain embodiments, the audio module 205 can include a loudspeaker, an earpiece, a microphone, and an earphone jack.

[0074] Interface module 206 includes an external memory interface, a universal serial bus (USB) interface, and a subscriber identification module (SIM) card interface. The external memory interface can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of mobile phone 10. The external memory card communicates with processor 201 via the external memory interface to implement data storage. The USB interface allows mobile phone 10 to communicate with other electronic devices.

[0075] Camera 207 is used to capture still images or video. The lens generates an optical image of an object and projects it onto a photosensitive element. The photosensitive element converts the optical signal into an electrical signal, which is then passed to an image signal processor (ISP) to be converted into a digital image signal. Mobile phone 10 implements its camera function through the ISP, camera 207, video codec, GPU, display 211, and application processor.

[0076] The memory 208 may store relevant instructions for executing the process control method mentioned in this application.

[0077] The sensor module 209 may include a proximity sensor, a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.

[0078] The buttons 210 may include a volume button, a power on / off button, and the like.

[0079] Display screen 211 is used to display human-computer interaction interfaces, images, videos, etc. Display screen 211 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED).

[0080] It should be understood that the illustrated structure of the embodiment of the present invention does not constitute a specific limitation on the mobile phone 10. In other embodiments of the present application, the mobile phone 10 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0081] Figure 3 This is a flow chart of a process control method provided by an embodiment of the present application. The process control method can be executed by an electronic device, such as Figure 3 As shown, the process control method may include:

[0082] S301: It is detected that the load change of the foreground application meets the process control condition.

[0083] In an embodiment of the present application, the electronic device can detect the load of the foreground application and determine whether the process control condition is met based on the load change of the foreground application. It can be understood that if the electronic device determines that the process control condition is met based on the load change of the foreground application, S302 to S303 and related steps are executed. If the electronic device determines that the process control condition is not met based on the load change of the foreground application, the load of the foreground application is continuously detected.

[0084] The foreground application load may include the load rate of the foreground process and the system process associated with the foreground process when running, hereinafter referred to as the foreground load rate. Accordingly, the foreground application load detection may include: detecting the foreground load rate.

[0085] In an embodiment of the present application, the electronic device manages all processes in groups and allocates time slices within each CPU scheduling cycle to different groups, i.e., the time that processes within the group are allowed to run within a single scheduling cycle. For example, the electronic device may group the foreground process and the system processes associated with the foreground process into the same group. Thus, the electronic device can determine the load rate of each group within each scheduling cycle based on a window assist load tracing (WALT) algorithm, that is, determine the foreground load rate of the group containing the foreground process and the system processes associated with the foreground process (hereinafter referred to as the foreground group).

[0086] In some embodiments, the process control condition may indicate an increase in the foreground load rate, or may indicate that an increment of the foreground load rate is greater than or equal to a preset increment. For example, the process control condition is determined to be satisfied when the foreground load rate of the CPU in the current scheduling cycle is greater than the foreground load rate in the previous scheduling cycle, or when an increment of the foreground load rate is greater than or equal to a preset increment based on the foreground load rate in the current scheduling cycle and the foreground load rate in the previous scheduling cycle.

[0087] Alternatively, in other embodiments, the process control condition may also indicate that the foreground load rate is greater than or equal to the foreground load threshold. For example, when the foreground load rate of the CPU in the current scheduling cycle is greater than or equal to the foreground load threshold, the process control condition is determined to be met.

[0088] For ease of explanation, this application refers to an increase in the foreground load rate, an increment of the foreground load rate being greater than or equal to a preset increment, and a foreground load rate being greater than or equal to a foreground load threshold as a foreground load increase.

[0089] As you can understand, when the number of foreground processes or their associated system processes increases, the foreground load increases. Before we elaborate on the process control conditions, let's first introduce several scenarios that can cause increased foreground load.

[0090] It is understood that in order to start an application, the electronic device needs to schedule the application startup process and the process of displaying the application interface of the application. After the application is started, the application becomes the foreground application. Therefore, when the electronic device starts an application, the number of foreground processes increases, that is, the foreground load increases.

[0091] It is understood that the foreground application can provide a user-visible application interface. The user's operation in the application interface, such as clicking or sliding, will cause the number of foreground processes to increase or the resources occupied to increase, and cause the display interface of the electronic device to change. Figure 1B When the control 1022 in the first application interface 102 is clicked, the mobile phone 10 will add a process P14 to load the second application interface 103, and the display interface of the mobile phone 10 changes from the first application interface 102 to the second application interface 103.

[0092] It is understood that foreground applications may include multimedia content software, such as audio and video software. In audio and video software, after playing the current audio or video, the next audio or video can be automatically played. That is, when the audio or video is switched, the electronic device automatically adds a new process to load the next audio or video. Since audio or video is perceptible to the user, the process loading the next audio or video is considered a foreground process. Therefore, switching audio and video will also increase the foreground load.

[0093] This application refers to the above-mentioned events that may cause an increase in foreground load, such as application startup, user operations such as clicks / slides, and automatic switching of multimedia content, as foreground events.

[0094] In some embodiments, S301 may include: upon detecting a foreground event, the electronic device determining that a foreground load rate has increased. Corresponding to determining that the foreground load rate has increased, the electronic device determines that a process control condition has been satisfied. Thus, upon detecting a foreground event, the electronic device can promptly control the process to ensure that the foreground event can run smoothly.

[0095] Alternatively, in other embodiments, the above S301 may include: when the electronic device detects a foreground event, it obtains the current load rate of the foreground group in the current scheduling period and the historical load rate of the foreground group in the previous scheduling period. The increment of the foreground load rate is determined based on the current load rate and the historical load rate. Based on the increment of the foreground load rate, it is determined whether the process control condition is met. If the increment corresponding to the foreground load rate is greater than or equal to the preset increment, it is determined that the process control condition is met. If the increment corresponding to the foreground load rate is less than the preset increment, it is determined that the process control condition is not met. Among them, the preset increment is set according to the actual application. For example, the preset increment can be any value such as 5%, 10% or 15%.

[0096] Specifically, determining the increment of the foreground load rate based on the current load rate and the historical load rate may include: determining the difference between the current load rate and the historical load rate as the increment of the foreground load rate.

[0097] Alternatively, in other embodiments, the above S301 may include: when the electronic device detects a foreground event, it obtains the current load rate and foreground load threshold of the foreground group in the current scheduling period. Determine whether the process control condition is met based on the size relationship between the current load rate and the foreground load threshold. Corresponding to the current load rate being greater than or equal to the foreground load threshold, it is determined that the process control condition is met. Corresponding to the current load rate being less than the foreground load threshold, it is determined that the process control condition is not met. Among them, the foreground load threshold is set according to the actual application. For example, the foreground load threshold can be any value such as 50%, 55% or 60%.

[0098] In this way, the electronic device measures whether process control is needed based on the increment of the foreground load rate or the foreground load threshold. If the foreground event does not cause a large increase in the load rate, there is no need for process control, which can reduce the frequency of process control.

[0099] S302: Obtain a first time allocated to the first process queue and a second time allocated to the second process queue in a current scheduling cycle of the CPU.

[0100] As previously mentioned, electronic devices manage all processes in groups. Consequently, processes in the same group are placed in the same process queue, ready to run. It's understood that a process queue contains processes in the ready state. The CPU can call a process from the process queue according to the process scheduling rules, and the called process enters the running state.

[0101] Specifically, an application may include multiple foreground processes and background processes. This application manages all foreground processes and background processes corresponding to all applications in a grouped manner, and mainly groups them according to whether the process belongs to a foreground process or a background process. Therefore, this application can group processes in different applications into the same group. For example, the foreground processes corresponding to two or more applications can be grouped into the same group. Thus, if the two or more applications are running in the foreground, the foreground processes corresponding to the two or more applications can be placed in the same process queue and wait for execution. In other words, there can be a one-to-many relationship between the process queue and the application.

[0102] In the embodiment of the present application, the first process queue may include processes related to the foreground application, for example, the processes in the foreground group mentioned above.

[0103] In some embodiments, the electronic device may set a group for background processes and system processes unrelated to the foreground application, so that the second process queue may include background processes or system processes unrelated to the foreground application.

[0104] Alternatively, in some other embodiments, the electronic device may set a group for background processes, referred to as the background group, and set another group for system processes unrelated to the foreground application, referred to as the system group. Thus, the second process queue may include processes in the background group, or the second process queue may include processes in the system group.

[0105] It is understood that when electronic devices manage processes in groups, they can assign a weight to each group. The weight of each group then determines the time each group is allowed to run within a single CPU scheduling cycle. Specifically, the product of the group's weight and the scheduling cycle is the time the group is allowed to run within a single scheduling cycle. It is understood that the greater the weight, the longer the group can run.

[0106] Therefore, S302 may include obtaining a current weight of the first process queue and a current weight of the second process queue within the current scheduling period, obtaining a first time based on the product of the current weight of the first process queue and the scheduling period, and obtaining a second time based on the product of the current weight of the second process queue and the scheduling period.

[0107] In some embodiments, the electronic device can set the same initial weight for each process group based on the number of groups. That is, a single scheduling cycle is evenly distributed to each group. In some embodiments, the current weight of the first process queue and the current weight of the second process queue can both be initial weights, so that the weight ratio of the current weight of the first process queue to the current weight of the second process queue can be 1:1.

[0108] In some embodiments, the electronic device detects an increase in foreground load, increases the weight of the first process queue, and decreases the weight of the second process queue, that is, increases the time quota (time slice) of the first process queue within a single scheduling cycle, and decreases the time quota of the second process queue within a single scheduling cycle.

[0109] S303: Determine a third time allocated to the first process queue and a fourth time allocated to the second process queue in the next scheduling cycle of the CPU.

[0110] As previously described, in some embodiments, the electronic device detects an increase in foreground load and increases the weight of the first process queue while decreasing the weight of the second process queue. Furthermore, based on the increased weight of the first process queue, the electronic device can determine a third time period, which is the time period during which the first process queue is allowed to run in the next scheduling cycle. It is understood that the third time period is greater than the first time period. Furthermore, based on the decreased weight of the second process queue, the electronic device can determine a fourth time period, which is the time period during which the second process queue is allowed to run in the next scheduling cycle. It is understood that the fourth time period is less than the second time period.

[0111] For example, it is assumed that the electronic device divides all processes into two groups, for example, a foreground group and a background group. Figure 4 As shown, the first process queue corresponds to the foreground group, and the second process queue corresponds to the background group. Within the current scheduling cycle, the current weights of the foreground group and the background group are both initial weights. Thus, the first time and the second time are both half of the current scheduling cycle. When an increase in the foreground load is detected, the weight of the foreground group is increased, causing the time quota of the first process queue in the next scheduling cycle to change to the third time, and the time quota of the second process queue in the next scheduling cycle to change to the fourth time.

[0112] In this way, the CPU can reserve more processing time for the first process queue, so that the foreground processes waiting to run in the first process queue can be processed first, and the processing time of the second process queue is compressed, slowing down the processing speed of the background processes in the second process queue, thereby avoiding the increase of background load caused by the running of background processes.

[0113] It is understood that the above steps S301 to S303 and related embodiments can all be implemented based on the kernel scheduler (Completely Fair Scheduler, CFS) built into the Linux system of the electronic device. The process group management (cgroup) involved in the above process control method is also a kernel function of Linux. By calling the cgroup related interface function, defining each process group, and configuring the relevant parameters of each process group, the grouped management of the process can be achieved. For example, the foreground group is defined to include the foreground process and the system process associated with the foreground process, and the weight of the foreground group is configured as the initial weight. Specifically, the weight can be set by configuring the cpu.shares parameter.

[0114] cpu.shares is a parameter in the Linux kernel that controls CPU resource allocation. It is used to set the proportion of CPU time quota occupied by each process group, which is also the weight mentioned above. Each process group has a cpu.shares parameter value. The Linux kernel will calculate the time quota of each group based on the cpu.shares parameter value of each group. Specifically, the kernel can calculate the time quota of each group according to the following formula:

[0115] group_cpu_time=(group_cpu_shares / total_cpu_shares)*available_cpu_time

[0116] Among them, group_cpu_time represents the time quota of each group; group_cpu_shares represents the proportion of the time quota of each group, or the weight of the group; total_cpu_shares represents the sum of the cpu.shares values of all competing groups; available_cpu_time represents the scheduling period, which can also be understood as the CPU available time.

[0117] Example, combined Figure 4, assuming that the available_cpu_time of a single scheduling cycle is 100 milliseconds (ms). In the current scheduling cycle, the cpu.shares parameter value of the foreground group corresponding to the first process queue is 100, and the cpu.shares parameter value of the background group corresponding to the second process queue is 100. Then the time quota corresponding to the first process queue (first time) is 50ms, and the time quota corresponding to the second process queue (second time) is 50ms. In the next scheduling cycle, the cpu.shares parameter value of the foreground group corresponding to the first process queue increases to 150, and the cpu.shares parameter value of the background group corresponding to the second process queue is 50. At this time, the time quota corresponding to the first process queue (third time) is (3 / 4)*100ms=75ms, and the time quota corresponding to the second process queue (fourth time) is 25ms.

[0118] In some embodiments, after S303, the electronic device may adjust the time quota of the first process queue from the third time period back to the first time period, and adjust the time quota of the second process queue from the fourth time period back to the second time period after a preset scheduling period. Alternatively, the electronic device may restore the initial time quotas of the first process queue and the second process queue, i.e., the time quotas corresponding to the initial weights.

[0119] The preset scheduling period can be set according to the foreground event. If the foreground event is estimated to last for a long time, the preset scheduling period can be set to a longer period. Exemplarily, the preset scheduling period can include three, five, or other number of scheduling periods. In this way, when the foreground event ends, more time quota is released to the second process queue to avoid long-term suppression of process execution in the second process queue, resulting in service unavailability.

[0120] Alternatively, in some embodiments, when the electronic device detects that the foreground load is reduced, for example, the foreground load rate is reduced, the reduction in the foreground load rate is greater than or equal to a preset reduction amount, or the foreground load rate is less than or equal to a foreground load threshold, the initial time quota of the first process queue and the second process queue is restored, that is, the time quota corresponding to the initial weight.

[0121] It is understood that if the foreground application exits, for example, the foreground application is closed, or switched to background operation, the foreground load rate will be reduced. Therefore, in some embodiments, a foreground event indicating the exit of the foreground application is detected, and an operation of restoring the initial time quota of the first process queue and the second process queue is performed. In addition, for determining whether the foreground load rate is reduced, or determining whether the reduction in the foreground load rate is greater than or equal to a preset reduction, or whether the foreground load rate is less than or equal to the foreground load threshold, reference can be made to the above-mentioned embodiments of increasing the foreground load, which will not be repeated here.

[0122] In some of the above embodiments, for the convenience of description, when the electronic device manages all processes in groups, the foreground process and the system process associated with the foreground application are divided into the foreground group, and the background process and the system process unrelated to the foreground application are divided into the background group. It can be understood that in actual applications, since the foreground application, background application and system services involve thousands of processes, the foreground application, background application and system services can be subdivided to determine multiple groups for easy management and control. Figure 5 Introduces a process grouping scheme. Figure 5 This is a process control architecture diagram provided in an embodiment of the present application.

[0123] like Figure 5 As shown, the present application divides services into foreground applications, system services, and background applications. For example, foreground applications can provide foreground services, system services can include foreground-related services, system resident services, and system delayable services, and background applications can provide background delayable services and unimportant background tasks. Among them, foreground-related services in system services can include communication services, positioning services, etc., system resident services can include security detection services, time synchronization services, etc., and system delayable services can include system version update services, system data synchronization, etc. Background delayable services can include services such as application data upload, download, and synchronization. In some embodiments, different background services can be divided into different levels according to the importance of the service. This application does not limit the number of levels, which is determined based on actual business. For example, background services are divided into two levels. Application data upload, download, and synchronization are both relatively important services and can be set to the higher first level, while application data log printing is a less important service and can be set to the lower second level. Therefore, the above-mentioned unimportant background tasks can include log printing services with a lower service importance level.

[0124] Then, when setting the CPU grouping (process grouping), set the corresponding grouping according to the services split above. For example, the processes that implement foreground services among the more than 230 threads (processes) involved in the foreground application are divided into group 1, the processes used to implement foreground-related services among the more than 2,500 processes involved in the system service (that is, the system processes associated with the foreground application as mentioned above) are divided into group 2, the processes related to resident services among the more than 2,500 processes involved in the system service are divided into group 3, the processes related to deferred services among the more than 2,500 processes involved in the system service and the processes related to deferred services among the more than 1,800 processes involved in the background application are divided into group 4, and the processes of unimportant background tasks (such as log printing) among the more than 1,800 processes involved in the background application are divided into group 5.

[0125] Continue to refer to Figure 5, the electronic device can adopt a group control scheduling strategy for the above-mentioned group 1, group 2, group 3 and group 5. That is, within each scheduling cycle, the electronic device can dynamically adjust the weights of the above-mentioned group 1, group 2, group 3 and group 5 to adjust the time quota of the process queue corresponding to each group. For example, when it is detected that the foreground load increases, the weights of group 1 and group 2 can be increased, and the weights of group 3 and group 5 can be reduced, so as to reserve more running time for the processes of foreground services in the process queue corresponding to group 1 and the processes of foreground-related services in the process queue corresponding to group 2. At the same time, the running time of the processes related to resident services in the process queue corresponding to group 3 and the processes of unimportant background tasks in the process queue corresponding to group 5 can be reduced, so that the computing power of the CPU is tilted towards the foreground as a whole, ensuring that the foreground process has sufficient available resources and avoiding the occurrence of excessive background load.

[0126] Continue to refer to Figure 5 , the electronic device can adopt a real-time preemptive scheduling strategy for group 1. That is, the electronic device prioritizes scheduling the processes in the process queue corresponding to group 1 to ensure a fast response of the foreground service.

[0127] Furthermore, the electronic device can also adopt a quota-controlled scheduling strategy for group 4, that is, separately controlling the time quota of the process queue corresponding to group 4. Since all processes in group 4 are processes with delayed services, the weight of group 4 can be set to a fixed weight with a small fixed weight. This way, group 4 can be consistently suppressed over multiple scheduling cycles, avoiding high loads caused by delayed services.

[0128] It is understandable that in some embodiments, a quota control strategy may also be adopted for group 3 and group 5. The quota control for group 3, group 4, and group 5 will be described in detail below and will not be elaborated here.

[0129] The following is based on Figure 5 The grouping scheme shown in the architecture diagram, combined with Figure 6 The process control method of the embodiment of the present application is introduced.

[0130] In S601, the electronic device initializes the weights of each group.

[0131] For example, the electronic device may set the same initial weight for the above-mentioned group 1, group 2, group 3 and group 5.

[0132] In S602 , the electronic device detects a foreground event.

[0133] Among them, foreground events can include user operations, such as clicks and slides, and can also include application behaviors, such as launching an application, exiting an application, and switching between audio and video in multimedia content software applications.

[0134] In S603, the electronic device determines whether a foreground event is triggered.

[0135] It can be understood that the electronic device can determine whether the foreground event is triggered by judging whether a related interface of the foreground event is called.

[0136] If the foreground event is triggered, the process goes to step S604. If the foreground event is not triggered, the process goes back to step S602 and continues to detect foreground events.

[0137] In S604, the electronic device calculates the foreground group load rate.

[0138] Here, the foreground group may include the foreground group 1. The foreground group load rate is the resources occupied by the process in the process queue corresponding to the foreground group 1 when the process is running. Specifically, the electronic device may determine the load rate of the group 1 in a single scheduling cycle based on WALT.

[0139] In S605 , the electronic device determines whether the foreground load rate increases / decreases by a preset percentage.

[0140] The preset percentage may be a preset increment or a preset decrease.

[0141] If the foreground load rate is increased by a preset increment or decreased by a preset decrement, S606 is executed.

[0142] If the foreground load rate does not increase by the preset increment and does not decrease by the preset decrement, S607 is executed. Meanwhile, S604 is also executed to continue calculating the foreground packet load rate in the next few scheduling cycles.

[0143] In S606 , the electronic device adjusts the foreground group weight year-on-year.

[0144] For example, corresponding to the electronic device determining that the foreground load rate increases by a preset increment, the initial weight of group 1 is increased, and the initial weight of group 3 is decreased by the same amount.

[0145] In S607 , the electronic device determines whether the foreground event ends.

[0146] If the foreground event ends, the process goes to S608. If the foreground event does not end, the process goes back to S602 and loops through S602 to S606 or S602 to S605.

[0147] In some embodiments, corresponding to the preset increment of the foreground load rate, the initial weight of group 1 is increased in S606, and the initial weight of group 3 is decreased year on year. For example, the weight of group 1 is adjusted to weight 1, and the weight of group 3 is adjusted to weight 2, where weight 1 is greater than the initial weight and weight 2 is less than the initial weight. Accordingly, in S607, if it is determined that the event has not ended, when S605 is executed again after returning to S602, if S605 indicates that the foreground load rate is reduced by the preset reduction amount, then when S606 is executed again, the weight 1 of group 1 is reduced and the weight 2 of group 3 is increased. For example, the weight of group 1 is adjusted to weight 3, and the weight of group 3 is adjusted to weight 4, where weight 3 is less than weight 1 but greater than the initial weight, and weight 4 is greater than weight 2 but less than the initial weight. In this way, when it is detected that the foreground load rate is reduced, the time quota of group 3 is gradually released.

[0148] In S608, the electronic device restores the weight of each group

[0149] It is understood that, corresponding to the end of the foreground event, the electronic device can restore the initial weights of each group. For example, in the above embodiment, after adjusting the weight of group 1 to weight 3 and the weight of group 3 to weight 4 in S606, it is determined in S607 that the event has ended, the weight of group 1 is restored to the initial weight of 3, and the weight of group 3 is also restored to the initial weight of 4.

[0150] The following combination Figure 7 This section explains the quota control scheduling strategy mentioned above. Figure 7 This is another process control architecture diagram provided in an embodiment of the present application.

[0151] like Figure 7 As shown, the electronic device may adopt a scheduling strategy of dynamic quota control for group 3 and group 5, and adopt a scheduling strategy of persistent quota control for group 4.

[0152] First, we introduce the scheduling strategy of the electronic device for dynamic quota control of group 3 and group 5. As mentioned above, group 3 corresponds to the system resident services in the system services, and group 5 corresponds to the background unimportant tasks in the background applications.

[0153] In some embodiments, the core of the electronic device can collect the entire device load and / or the entire device temperature, and dynamically adjust the time quotas of Group 3 and Group 5 based on the entire device load and / or the entire device temperature. The entire device load can refer to the CPU usage, and the entire device temperature can be detected by a temperature sensor built into the electronic device.

[0154] Specifically, the electronic device can pre-set the corresponding relationship between the whole machine load and the time quota, as well as the corresponding relationship between the whole machine temperature and the time quota. Figure 8As shown, the entire machine load / entire machine temperature is divided into three gears: gear A, gear B, and gear C, and corresponding time quotas are set according to different gears. For example, when the entire machine load is 90%, 80%, and 60%, respectively, the corresponding time quotas can be 10ms, 30ms, and 50ms. When the entire machine temperature is 46 degrees Celsius, 42 degrees Celsius, and 38 degrees Celsius, respectively, the corresponding time quotas can be 10ms, 30ms, and 50ms. It can be understood that the higher the entire machine load or the entire machine temperature, the smaller the time quotas allocated to groups 3 and 5. Since group 3 contains system resident services and group 5 contains unimportant background tasks, compressing the time quotas of these two groups will not affect the services of foreground applications. Therefore, when the entire machine load or the entire machine temperature is high, the entire machine load or the entire machine temperature can be effectively reduced without affecting the foreground applications.

[0155] It should be noted that the time quotas of 10ms, 30ms, and 50ms are illustrative values based on a single scheduling period of 100ms. In actual applications, the specific time quota values corresponding to each gear can be determined according to the actual scheduling period using the time quota ratios of 10 / 100ms, 30 / 100ms, and 50ms / 100ms.

[0156] It can be understood that electronic devices can be dynamically controlled by grouping to control the load and temperature of the entire machine.

[0157] The following describes the scheduling strategy of the electronic device for persistent quota control of group 4. As mentioned above, group 4 corresponds to system deferrable services in system services and background deferrable services in background applications.

[0158] As mentioned above, the electronic device can set the weight of Group 4 to a fixed, relatively small value. This allows for persistent suppression of Group 4 over multiple scheduling cycles, preventing high loads caused by delayed services. For example, the electronic device can set the weight of Group 4 based on a 10 / 100ms time quota ratio. That is, if a single scheduling period is 100ms, Group 4's time quota in each scheduling period is 10ms.

[0159] Reference Figure 7 The application framework layer of the electronic device can identify whether a deferrable service exists. If so, it places the process of the deferrable service in the process queue corresponding to group 4, waiting for execution. Due to the persistent quota control strategy adopted for group 4, the process queue corresponding to group 4 has a limited running time within a single scheduling cycle. Therefore, the process queue corresponding to group 4 can be called a suppressed queue.

[0160] In some embodiments, the deferred services may include data upload and download services, media scanning services, software installation package compilation and installation, application upgrade / launch services, etc. The media scanning service involves scanning media files, such as audio and video files, in the electronic device and creating a corresponding media database.

[0161] Continue to refer to Figure 7 In some embodiments, when the application framework layer detects that the service interface of the above-mentioned deferrable service is called, it determines whether there is a deferrable service based on the foreground and background states of the application that calls the service interface.

[0162] For example, the application framework layer detects that application A is in the background state, that is, it calls the network KIT upload and download service interface when running in the background, and determines that there is a deferred service (upload and download), so that the related process of the service can be stored in the suppression queue waiting to run.

[0163] For example, the application framework layer detects that application B is in the background state and calls the dex / verify compilation Android interface, then determines that there is a deferred service (compilation and installation), so that the related process of the service can be stored in the suppression queue waiting to run.

[0164] Exemplarily, the application framework layer detects that application C is in the background state and calls the system openfile interface, then determines that there is a deferrable service (background writing file), so that the related process of the service can be stored in the suppression queue waiting to run.

[0165] It's understandable that the processes of these deferrable services require significant resources to run. However, due to the persistent quota control strategy implemented for Group 4, which means that the process queue corresponding to Group 4 can only run for a limited time within a single scheduling cycle, this prevents the deferrable services from causing excessive load. This way, since the related processes are suppressed when the deferrable service is started and remain suppressed permanently, there will be no sudden high load even if the user downloads and installs multiple applications simultaneously.

[0166] In the embodiment of the present application, considering that the foreground application and the background application are not completely isolated, the suppression of the delayable service in the background application may block the foreground process, causing the foreground to freeze, and then causing the foreground service to be unavailable.

[0167] For example, in one scenario, a user clicks on application C in an electronic device. The electronic device responds to the user's click and starts application C. Application C calls the system openfile interface to open a local file file1 and continuously (e.g., 10 seconds) writes a piece of content to file file1. If the user returns to the main interface of the electronic device from application C, application C becomes a background application, and the process of writing file file1 is added to the suppression queue, and the content writing speed slows down. If the user clicks on application D again at this time, the electronic device starts application D. At this time, application D is the foreground application, and application D also calls the system openfile interface to open the same file file1 and attempts to write content to file file1. However, because file1 is being used by application C and is in a locked state, it is necessary to wait for application C to complete the writing before file1 can be unlocked. However, the process of application C writing file1 is suppressed, which causes application D to be unable to write content to file file1 in the short term, causing the foreground application to freeze.

[0168] It's understandable that the scheduling priority of the process running in the foreground, application D, writing to file file1 (hereinafter referred to as process D), should have precedence over the scheduling priority of the process running in the background, application C, writing to file file1 (hereinafter referred to as process C). However, because application C writes to file1 first, file1 is locked and cannot be accessed by application D until application C completes its write operation. Therefore, process D must wait for process C to finish before running again, resulting in a scheduling priority inversion.

[0169] Based on this, in the process control method of the embodiment of the present application, the electronic device quickly releases the background process that the foreground process depends on from the suppression queue when the foreground process is waiting for a lock or a synchronization binder, thereby solving the problem of inversion of scheduling priorities of the foreground and background processes, thereby ensuring that the foreground process can run quickly and avoiding lag in the foreground application.

[0170] The foreground process waiting for a lock can refer to a process whose operation object is locked by another process, such as a background process, and needs to wait for the operation object to be unlocked before it can run. The foreground process waiting for a synchronization binder can refer to a process that has a communication relationship with a background process.

[0171] like Figure 9 As shown, the process control method of an embodiment of the present application may also include: in S1, when the electronic device detects that the foreground process is in a state of waiting for a lock or waiting for a synchronization binder, the background process associated with the foreground process, for example, the background process holding the binder or lock, is marked with a critical section label and passed to the kernel.

[0172] In S2, the kernel can detect processes in the suppression queue during the scheduling cycle. If a background process with a critical section label (such as process 3) is detected, process 3 is moved to the head of the queue. Specifically, when the queue uses a binary tree data structure, the position of the process in the queue is adjusted by adjusting the weights of the nodes in the binary tree.

[0173] Furthermore, in S3, during the execution time of the foreground process queue (which may be the first process queue mentioned above), process 3, which is at the head of the suppression queue and carries the critical section label, is moved to the foreground process queue. In this way, the suppression of process 3 is released, the operation of process 3 is accelerated, and blocking of the foreground process associated with it is avoided.

[0174] In S4, when the current background process releases its dependency, the critical section label of process 3 is cancelled, and process 3 is moved back to the suppression queue.

[0175] The critical section represents a code segment within a process that accesses a critical resource. Critical resources are shared resources that are only available to one process at a time, such as the aforementioned operable object file1. It is understood that when a background process contains other code segments besides the code segment accessing the critical resource, once the background process finishes executing the code segment accessing the critical resource, the foreground and background processes can be considered to be free of dependency. At this point, background process 3 can be interrupted and moved back to the suppression queue.

[0176] Therefore, in an embodiment of the present application, a critical section label is set for the background process associated with the foreground, or the background process that accesses the same critical resource as the foreground process. When the kernel of the electronic device detects the critical section label, it can quickly release the suppression of the background process, thereby avoiding blocking of the foreground process and preventing the foreground application from being stuck.

[0177] It should be noted that in the examples and description of the present application, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a" does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0178] While the present application has been shown and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the present application.

Claims

1. A process control method, characterized in that: Applied to electronic equipment, the method includes: Detecting a foreground event, obtaining a first time allocated to a first process queue and a second time allocated to a second process queue within a current scheduling cycle of the processor, wherein the first process queue includes processes to be run related to the foreground application, and the second process queue includes processes to be run related to the background application; determining a third time allocated to the first process queue and a fourth time allocated to the second process queue in a next scheduling cycle of the processor; The third time is greater than the first time, and the fourth time is less than the second time.

2. The process control method according to claim 1, characterized in that: The first process queue includes a first process associated with a first foreground event, and the method further includes: detecting the first foreground event triggered by the foreground application, and creating the first process; The first foreground event includes any one of a user operation, startup of the foreground application, and automatic playback of multimedia content.

3. The process control method according to claim 1, characterized in that: The first process queue corresponds to the first group, and processes in the first group wait for execution in the first process queue when being scheduled; The second process queue corresponds to the second group, and processes in the second group wait for execution in the second process queue when being scheduled.

4. The process control method according to claim 3, characterized in that: The first group includes the foreground process of the foreground application, or the first group includes the foreground process and a first type of system process associated with the foreground process; The second group includes a first type of background processes of the background application, where the first type of background processes belong to background services whose service importance is lower than the first importance.

5. The process control method according to claim 1, characterized in that: Also includes: detecting that a second process in the first process queue accesses a critical section; During the running time of the second process queue, a third process in the second process queue that carries the critical section tag is moved to the head of the second process queue, and the third process accesses the critical section before the second process. During the running time of the first process queue, the third process is moved from the head position to the first process queue.

6. The process control method according to claim 1, characterized in that: Also includes: Determining, within each scheduling cycle of the processor, a time allocated to a third process queue based on the entire load or entire temperature of the electronic device; The third process queue corresponds to a third group, the third group includes a second type of system processes, and the second type of system processes belong to system resident services.

7. The process control method according to claim 1, characterized in that: Also includes: determining, within each scheduling cycle of the processor, a time allocated to a fourth process queue based on a fixed weight; Among them, the fourth process queue corresponds to the fourth group, and the fourth group includes the third type of system processes and the second type of background processes. The third type of system processes belong to delayable system services, and the second type of background processes belong to delayable background services.

8. The process control method according to claim 1, characterized in that: The method further comprises: Detecting upload and download events of background applications, executing the acquisition of the first time allocated to the first process queue and the second time allocated to the second process queue within the current scheduling cycle of the processor, and determining the third time allocated to the first process queue and the fourth time allocated to the second process queue within the next scheduling cycle of the processor.

9. The process control method according to claim 3, characterized in that: The method further comprises: A foreground event is detected, and / or a load change of a foreground application is detected that meets a process control condition, and the first time allocated to the first process queue and the second time allocated to the second process queue within the current scheduling cycle of the processor are obtained, and a third time allocated to the first process queue and a fourth time allocated to the second process queue within the next scheduling cycle of the processor are determined.

10. The process control method according to claim 9, characterized in that: The method further comprises: detecting a load rate occupied by the first group in each scheduling cycle of the processor; Based on the load rate of the first group in each scheduling period, it is determined whether the load change of the foreground application meets the process control condition.

11. The process control method according to claim 10, characterized in that: The load rate of the first group in each scheduling period includes: the current load rate of the current scheduling period and the historical load rate in the historical scheduling period; The process control conditions include at least one of the following: The current load rate of the first group in the current scheduling period is greater than the historical load rate occupied by the first group in the historical scheduling period; An increment of the current load rate compared to the historical load rate is greater than a first increment; The current load rate is greater than a first load rate threshold.

12. The process control method according to claim 3, characterized in that: Also includes: determining, within each scheduling cycle of the processor, a time allocated to the first process queue based on a time weight of the first group; determining, within each scheduling cycle of the processor, a time allocated to the second process queue based on the time weight of the second group; The time weight represents the time that each group is allowed to run in each scheduling period, and the time weight of the first group and the time weight of the second group change according to the load change of the foreground application.

13. The process control method according to claim 3 or 12, characterized in that: The obtaining of the first time allocated to the first process queue and the second time allocated to the second process queue within the current scheduling cycle of the processor includes: Obtaining a first time weight of the first group and a second time weight of the second group within a current scheduling period of the processor; Obtaining the first time based on a product of the first time weight and a unit scheduling cycle of the processor; The second time is obtained based on the product of the second time weight and the unit scheduling period.

14. The process control method according to claim 3 or 12, characterized in that: The determining, in a next scheduling cycle of the processor, a third time allocated to the first process queue and a fourth time allocated to the second process queue includes: Increasing the first time weight to obtain a third time weight of the first group in the next scheduling period; reducing the second time weight to obtain a fourth time weight of the second group in the next scheduling period; Obtaining the third time based on a product of the third time weight and the unit scheduling period; The fourth time is obtained based on the product of the fourth time weight and the unit scheduling period.

15. The process control method according to claim 9 or 10, characterized in that: The third time is shorter than the first time, and the fourth time is longer than the second time.

16. The process control method according to claim 15, characterized in that: The process control conditions include at least one of the following: The current load rate of the first group in the current scheduling period is less than the historical load rate occupied by the first group in the historical scheduling period; The decrease in the current load rate compared to the historical load rate is greater than or equal to a first decrease; The current load rate is less than a second load rate threshold.

17. An electronic device, characterized in that: include: One or more processors, one or more memories, wherein the one or more memories store one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device executes the process control method described in any one of claims 1 to 16.

18. A readable storage medium, characterized in that: The readable storage medium stores instructions, and when the instructions are executed on the electronic device, the electronic device executes the process control method according to any one of claims 1 to 16.

Citation Information

Cited By

  • Task scheduling method based on coroutine and related equipment

    CN121411916A