Task management method and apparatus, and electronic device and medium

By managing the permissions and running time of background tasks on the CPU of the electronic device, the problem of foreground tasks being blocked by background tasks is solved, and the running fluency of foreground tasks and the utilization efficiency of system resources are improved.

WO2024222658A1PCT designated stage expired Publication Date: 2024-10-31VIVO MOBILE COMM CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/089241
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-28
Filing Date
2024-04-23
Publication Date
2024-10-31

AI Technical Summary

Technical Problem

In electronic devices, as the number of applications increases, foreground tasks are easily blocked by background tasks, causing foreground tasks to freeze and respond slowly, affecting running smoothness.

Method used

Determine whether the background task has the permission to access critical resources during the management cycle of running it on the CPU. If it has the permission, it will continue to run until it is released. If it does not have the permission and the running time exceeds a certain time, the background task will be suspended to avoid the foreground task waiting for the background. Tasks release resources.

Benefits of technology

It reduces the blocking of foreground tasks, improves the running fluency of foreground tasks, limits the occupation of CPU resources by background tasks, and ensures that foreground tasks can be scheduled and executed as soon as possible.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024089241_31102024_PF_FP_ABST
    Figure CN2024089241_31102024_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application are a task management method and apparatus, and an electronic device and a medium. The task management method comprises: within a first management period of running a first task on a CPU, determining whether the first task has first permission, wherein the first task is a background task run by the CPU, and the first permission is permission to access a critical resource of an electronic device; and when the first task has the first permission, maintaining the running of the first task on the CPU within the first management period until the first task releases the first permission; or suspending the running of the first task on the CPU when the first task does not have the first permission and the duration of running the first task on the CPU within the first management period is greater than or equal to a first duration.
Need to check novelty before this filing date? Find Prior Art

Description

Task management method, device, electronic device and medium

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to Chinese patent application No. 202310489051.4 filed in China on April 28, 2023, the entire contents of which are incorporated herein by reference. Technical Field

[0003] The present application belongs to the field of terminal technology, and specifically relates to a task management method, device, electronic device and medium. Background Art

[0004] Generally, as the number of applications installed on electronic devices increases, the tasks that electronic devices need to handle become more and more complex and onerous. In order to ensure the smooth operation of foreground applications, the scheduler of the Central Processing Unit (CPU) generally uses a bandwidth control mechanism under the scheduling of the Completely Fair Scheduler (CFS) algorithm to control the applications running in the background.

[0005] However, even with the bandwidth control mechanism, there is still a problem where the foreground task is blocked by the background task, which in turn causes the foreground task to become stuck and respond slowly.

[0006] Therefore, how to reduce the blocking of foreground tasks and improve the smoothness of foreground task operation is an urgent problem that needs to be solved.

[0007] Summary of the Invention

[0008] One of the purposes of the embodiments of the present application is to provide a task management method that can reduce the blocking of foreground tasks and improve the smoothness of foreground task operation.

[0009] In a first aspect, an embodiment of the present application provides a task management method, the method comprising: determining whether a first task has a first permission within a first management cycle of running a first task on a CPU; the first task is a background task run by the CPU; the first permission is the permission to access critical resources of an electronic device; if the first task has the first permission, keeping the first task running on the CPU within the first management cycle until the first task releases the first permission; or, if the first task does not have the first permission and the duration of running the first task on the CPU within the first management cycle is greater than or equal to the first duration, suspending running the first task on the CPU.

[0010] In the second aspect, an embodiment of the present application provides a task processing device, which includes: a determination module and an operation management module. The determination module is used to determine whether the first task has the first permission during the first management cycle of running the first task on the CPU, the first task is a background task run by the CPU, and the first permission is the permission to access the critical resources of the task management device. The operation management module is used to keep running the first task on the CPU during the first management cycle when the determination module determines that the first task has the first permission until the first task releases the first permission; or, when the determination module determines that the first task does not have the first permission and the time length for running the first task on the CPU during the first management cycle is greater than or equal to the first time length, suspend running the first task on the CPU.

[0011] In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.

[0012] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0013] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the method described in the first aspect.

[0014] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the method described in the first aspect.

[0015] In an embodiment of the present application, during the first management cycle of running a first task on the CPU of an electronic device (the first task is a background task run by the CPU), it is determined whether the first task has the first permission (the first permission is the permission to access the critical resources of the electronic device). If the first task has the first permission, the first task is kept running on the CPU during the first management cycle until the first task releases the first permission, thereby avoiding the need for the foreground task run by the CPU to wait for the background task to pass the sleep time and release the first permission before it can access the critical resource, so that the foreground task can be scheduled for execution as early as possible, reducing the blocking of the foreground task and improving the smoothness of the foreground task. Alternatively, when the first task does not have the first permission and the duration of running the first task on the CPU during the first management cycle is greater than or equal to the first duration, the first task is suspended from running on the CPU, thereby limiting the running time of the background task, reducing the occupation of CPU resources by the background task, and further improving the smoothness of the foreground task. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] FIG1 is a flowchart of a task management method according to an embodiment of the present invention;

[0017] FIG2 is a second flow chart of the task management method provided in an embodiment of the present application;

[0018] FIG3 is a third flow chart of the task management method provided in an embodiment of the present application;

[0019] FIG4 is a schematic diagram of a task running on a CPU according to an embodiment of the present application;

[0020] FIG5 is a second schematic diagram of a task running on a CPU provided by an embodiment of the present application;

[0021] FIG6 is a fourth flow chart of the task management method provided in an embodiment of the present application;

[0022] FIG7 is a fifth flowchart of the task management method provided in an embodiment of the present application;

[0023] FIG8 is a sixth flowchart of the task management method provided in an embodiment of the present application;

[0024] FIG9 is a schematic diagram of the structure of a task management device provided in an embodiment of the present application;

[0025] FIG10 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;

[0026] FIG11 is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field are within the scope of protection of this application.

[0028] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.

[0029] The task management method, device, electronic device, and medium provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.

[0030] The execution subject of the task management method provided in the embodiment of the present application can be an electronic device, or it can be a functional module and / or functional entity in the electronic device that can implement the task management method. The technical solution provided in the embodiment of the present application will be explained below using an electronic device as an example.

[0031] Figure 1 shows a flowchart of a task management method provided by an embodiment of the present application. As shown in Figure 1 , a task management method provided by an embodiment of the present application may include the following steps 101 to 103 .

[0032] Step 101: During a first management period in which a first task is executed on a CPU of an electronic device, the electronic device determines whether the first task has a first permission.

[0033] In the embodiment of the present application, the above-mentioned first task is a background task run by the CPU.

[0034] Optionally, in an embodiment of the present application, when multiple applications are running simultaneously on an electronic device, since the program instructions that the CPU of the electronic device can process per unit time are limited, when the electronic device runs too many applications, the CPU will be unable to process the program instructions in a timely manner, thereby causing the CPU load to be too high, and then causing the application to run jammed.

[0035] Optionally, in an embodiment of the present application, when a large number of first tasks are running on the CPU of an electronic device, a large amount of system resources, such as memory and CPU computing power, will be occupied. This may cause the program running in the foreground to freeze. To limit the first task's occupation of system resources such as the CPU, the electronic device may force the first task to enter a sleep state if the first task does not have the first permission and has been running on the CPU for more than a certain period of time.

[0036] It should be noted that the above-mentioned forcing the first task to enter the sleep state can be understood as: even if the first task is ready to run, the system does not allocate CPU resources to the first task.

[0037] In the embodiment of the present application, the period from the end of the last sleep state to the end of the next sleep state of the first task is called a management cycle, and a management cycle may include a running time period and a sleeping time period.

[0038] Optionally, in an embodiment of the present application, in a management cycle, after the electronic device continues to run the first task on the CPU during the running time period, the system does not allocate CPU resources to the first task during the sleep time period, even if the first task is in a state ready to run. The duration of the sleep time period is fixed, while the duration of the running time period is not fixed, and the duration of the running time period is related to whether the first task has the first permission during the management cycle. This will be explained in detail in the embodiments of the present application below and will not be repeated here.

[0039] Optionally, in an embodiment of the present application, the total running time of the first task running on the CPU includes at least one management cycle, and the first management cycle is any one of the at least one management cycle. The total running time of the first task running on the CPU can be understood as the total survival time of the first task.

[0040] It should be noted that the total execution time of the first task on the CPU includes the sum of the time the first task is executed on the CPU and the time the first task is in a sleep state, that is, the survival time of the first task on the CPU. The total execution time of the first task on the CPU may include at least one management cycle.

[0041] For example, assuming that the total running time of the first task on the CPU is 100ms, and a management cycle is preset to be every 20ms, then the running time of the first task on the CPU includes 5 management cycles. In one management cycle, the electronic device keeps running the first task on the CPU for 10ms and then limits the running of the first task on the CPU to 10ms; in another management cycle, the electronic device keeps running the first task on the CPU for 15ms and then limits the running of the first task on the CPU to 10ms; in another management cycle, the electronic device keeps running the first task on the CPU for 5ms and then limits the running of the first task on the CPU to 10ms.

[0042] In the embodiment of the present application, the first permission is the permission to access critical resources of the electronic device.

[0043] It is understandable that there are many different types of resources in the system of an electronic device. Some of these resources cannot be preempted and need to be accessed using a mutually exclusive access method. These resources are critical resources, such as printers, data files, semaphores, etc. To ensure data consistency and security, these critical resources must be accessed by only one task at a time.

[0044] Optionally, in an embodiment of the present application, the electronic device may determine whether the first task has permission to access a critical resource of the electronic device. The critical resource needs to be accessible to only one task at a time. Specifically, the first permission may be a resource lock.

[0045] The following specifically describes the prerequisites for determining whether the first task has the first permission.

[0046] Optionally, in the embodiment of the present application, in combination with FIG1 , as shown in FIG2 , the above step 101 can be specifically implemented through the following step 101a.

[0047] Step 101a: When the electronic device runs a first task and a second task on a CPU, a load parameter of the CPU is greater than or equal to a preset threshold, and there is no dependency between the first task and the second task, determine whether the first task has the first permission within a first management cycle of running the first task on the CPU.

[0048] In the embodiment of the present application, the above-mentioned load parameter is used to indicate the load condition of the CPU, and the above-mentioned second task is the foreground task running by the CPU.

[0049] Optionally, in an embodiment of the present application, the electronic device can determine the load condition of its own CPU by obtaining the CPU load parameters. The CPU load parameters can be a physical load parameter, such as: CPU power load, CPU operating temperature, etc.; it can also be a logical load, such as: CPU average load, CPU usage rate, etc.

[0050] Optionally, in an embodiment of the present application, the preset threshold may be a CPU load parameter when the CPU of the electronic device cannot smoothly process program instructions of the application.

[0051] Further optionally, in an embodiment of the present application, when a large number of tasks are running or waiting to be run on the CPU of an electronic device, these tasks cannot be scheduled by the CPU in a timely manner, resulting in a freeze in the application program. In this case, a preset threshold value can be determined based on the current CPU operating state. Specifically, the operating temperature and power consumption when the CPU load is high can be counted, and parameters such as the average CPU load and CPU usage can also be counted to determine the preset threshold value.

[0052] It should be noted that the above-mentioned “average CPU load” can be understood as: the average number of tasks in the system that are in an operational state (using the CPU or waiting for the CPU) and an uninterruptible state per unit time.

[0053] It can be understood that by comparing the load parameters of the CPU of the electronic device at a certain moment with the preset threshold to determine whether the current CPU load is too high, the background tasks running on the CPU can be optimized so that the CPU can smoothly process the program instructions of the foreground application.

[0054] In one example, assuming the preset threshold is: CPU operating temperature: 35°C, when the electronic device obtains through the temperature sensor that the CPU operating temperature is 45°C at this time, since the CPU operating temperature at this time is greater than the preset threshold, it is determined that the CPU load of the electronic device is high at this time.

[0055] In another example, assuming the preset threshold is: average CPU load: the average load for 1 minute is 0.7. When the electronic device uses the top command and the uptime command to query that the average CPU load at this time is: the average load for 1 minute is 1.2, since the average CPU load at this time is greater than the preset threshold, it is determined that the CPU load of the electronic device at this time is high.

[0056] Optionally, in an embodiment of the present application, when the CPU of the electronic device is a multi-core processor, the electronic device preferentially assigns the first task and the second task to different CPU cores for processing.

[0057] It should be noted that the "dependency between the first and second tasks" mentioned above can be understood as whether the execution of the first task provides support for the execution of the second task, that is, whether the background task running on the CPU provides data support for the foreground task running on the CPU. For example, if the background task is a task that loads and caches video data, and the foreground task needs to call the video data provided by the background task to play the video, then the background task and the foreground task are considered to have a dependency relationship. If the background task is restricted at this time, the execution of the foreground task will be affected.

[0058] Optionally, in an embodiment of the present application, when a dependency relationship exists between a first task and a second task, the electronic device does not force the first task to enter a sleep state, so that the second task can normally call the data provided by the first task.

[0059] Optionally, in an embodiment of the present application, when there is no dependency between the first task and the second task, in order to ensure the fluency and responsiveness of the foreground application, the electronic device may restrict and optimize the first task.

[0060] It can be seen that since the electronic device can decide whether to impose system resource restrictions on the background task by determining whether the background task has the first permission when the CPU load parameter is greater than or equal to the preset threshold and there is no dependency between the foreground task and the background task, the background task can be restricted in a high-load scenario to ensure that the foreground task can run smoothly.

[0061] The electronic device may set a time to determine whether the first task has the first permission, which is described in detail below.

[0062] Optionally, in the embodiment of the present application, in combination with FIG1 , as shown in FIG3 , the above step 101 can also be specifically implemented through the following step 101b.

[0063] Step 101b: At time T1 of the first management cycle of the first task running on the CPU, the electronic device determines whether the first task has the first permission.

[0064] Optionally, in an embodiment of the present application, the above-mentioned T1 moment is related to the target duration, which can be determined based on the CPU load and computing power, or based on the duration of the running time period of the first task running on the CPU in the previous management cycle of the first management cycle.

[0065] Further optionally, in an embodiment of the present application, the electronic device may determine the target duration based on the application scenario load of the currently running foreground application, or may determine the target duration based on the performance parameters of the CPU.

[0066] In one example, if the application scenario of the currently running foreground application is an application scenario that requires the use of more CPU resources, such as: game scenarios, image processing and other scenarios, the target duration can be set to a shorter duration, for example: setting the target duration to 5ms; if the application scenario of the currently running foreground application is an application scenario that requires the use of fewer CPU resources, such as: conversation scenarios, text reading and other scenarios, the target duration can be set to a longer duration, for example: setting the target duration to 10ms.

[0067] In another example, if the performance parameters of the CPU of the electronic device are better, for example, the CPU has multiple cores and the CPU's main frequency is 6GHz, the target duration can be set to a longer duration, for example, the target duration is 10ms; if the performance parameters of the CPU of the electronic device are worse, for example, the CPU has a single core and the CPU's main frequency is 2GHz, the target duration can be set to a shorter duration, for example, the target duration is 5ms.

[0068] Optionally, in the embodiment of the present application, the above-mentioned time T1 may be a time after a target duration has passed since the start time of the first management cycle.

[0069] For example, as shown in Figure 4, assume that the first task is Task A, which is a background task running on the CPU with a target duration set to 10ms. The total running time of Task A on the CPU includes N management cycles, each of which includes a running period and a sleep period. Assume that the first management cycle is the first of the N management cycles, and the time 10ms after the target duration has elapsed from the start of the first management cycle is time t1 (i.e., time T1). Since the first task did not hold the resource lock before time t1, at time t1, the electronic device determines that the first task does not have the first permission. Assume that the first management cycle is the second of the N management cycles, and the time 10ms after the target duration has elapsed from the start of the second management cycle is time t2 (i.e., time T1). Since the first task held the resource lock at time t3 before time t2, i.e., the first task already had the first permission at time t3, the electronic device determines that the first task has the first permission at time t2.

[0070] Optionally, in the embodiment of the present application, the electronic device may further determine the time T1 according to the duration of the running time period of the first task running on the CPU in the previous management cycle of the first management cycle.

[0071] Further optionally, in an embodiment of the present application, if the duration of running the first task on the CPU in the previous management cycle of the first management cycle is a first target duration, and the first target duration is greater than the target duration, then the duration of running the first task on the CPU in the first management cycle is a second target duration, and the second target duration is less than the target duration, then time T1 is the time after the second target duration has elapsed from the start time of the first management cycle. Optionally, the average of the first target duration and the second target duration is equal to the target duration.

[0072] It should be noted that the process of determining the second target duration based on the first target duration will be specifically described in the following embodiments and will not be repeated here.

[0073] For example, in conjunction with Figure 4, it is assumed that the first task is task A, which is a background task running on the CPU, and the target duration is set to 10ms. The total running time of task A on the CPU includes N management cycles. It is also assumed that the first management cycle is the third management cycle among the N management cycles. In the second management cycle, the first target duration T2 for running the first task on the CPU is 15ms. Then, in the third management cycle, the second target duration T3 for running the first task on the CPU is 5ms, and the moment after the second target duration of 5ms from the start moment of the third management cycle is moment t4 (i.e., moment T1). Since the first task did not hold the resource lock before moment t4, at moment t4, the electronic device determines that the first task does not have the first permission.

[0074] It can be seen that since the electronic device determines whether the first task has the first permission at time T1 of each management cycle, the duration of running the first task on the CPU within the management cycle is determined, thereby ensuring that the first task will not enter a restricted state when it has the first permission.

[0075] Step 102 : When the first task has the first permission, the electronic device keeps running the first task on the CPU within a first management period until the first task releases the first permission.

[0076] Optionally, in an embodiment of the present application, the first task starts running from the start time of the first management cycle. If, at time T1 of the first management cycle, it is determined that the first task has the first permission, the electronic device continues to keep the first task running on the CPU for a period of time until the first task releases the first permission.

[0077] It can be understood that after the first task runs on the CPU for the target time, if the first task still has the first permission at time T1, the electronic device keeps the first task running on the CPU, that is, in the first management cycle, the time for running the first task on the CPU can be greater than the target time.

[0078] In an embodiment of the present application, when the first task has the first permission, the electronic device will not set a quota for the running time of the first task, but will keep running the first task on the CPU until the first permission is released, so that the foreground task does not need to wait during the sleep period of the first task, and can obtain the first permission as early as possible to access critical resources.

[0079] For example, as shown in Figure 5, assume that the first task is Task A, Task A is a background task running on the CPU, and Task B is a foreground task running on the CPU. In the nth management cycle, when Task A runs to time t1, it holds the resource lock and begins to access critical resources. At time t2, Task B also needs to access the critical resource and applies for the resource lock. The electronic device continues to run Task A on the CPU until the resource lock is released at time t3, and Task A is restricted from running. At the same time, Task B holds the resource lock at time t3 and accesses critical resources, shortening the waiting time for the resource lock.

[0080] Step 103: The electronic device suspends the execution of the first task on the CPU if the first task does not have the first permission and the execution time of the first task on the CPU during the first management period is greater than or equal to the first execution time.

[0081] Optionally, in the embodiment of the present application, the first duration may be the duration between the start time of the first management period and time T1.

[0082] In one example, within the first management cycle, the T1 moment is the moment after the target duration has passed from the start moment of the first management cycle, that is, the first duration is equal to the target duration. If the time for the first task to run on the CPU is greater than or equal to the target duration, and the first task releases the first permission at this time, the first task is suspended from running on the CPU for a period of time, that is, the third duration in the following embodiment. Among them, the third duration is a fixed duration, and the electronic device can determine the third duration based on the application scenario load of the currently running foreground application, or it can determine the third duration based on the performance parameters of the CPU.

[0083] It should be noted that when the application scenario load of the foreground application is large, the third time length can be set to a longer time length; if the performance parameters of the CPU of the electronic device are better, the third time length can be set to a shorter time length. The specific process of determining the third time length can refer to the above-mentioned target time length determination process, which will not be repeated here.

[0084] For example, as shown in Figure 4, assume that the first task is Task A, which is a background task running on the CPU, with the target duration T4 set to 10ms and the third duration T5 being 10ms. The total running duration of Task A on the CPU includes N management cycles, the first management cycle being the first of the N management cycles, and the target duration T4 passing from the start time of the first management cycle to the time t1. Since the first task does not have the first permission at time t1, and the duration of running the first task on the CPU is equal to the target duration (i.e., the first duration), the electronic device suspends running the first task on the CPU within the third duration T5. Assume that the first management cycle is the second management cycle among N management cycles. 15 ms after the start of the second management cycle, time t5 arrives. Since the first task releases the resource lock at time t5, that is, the first task does not have the first permission at time t5, and the duration of running the first task on the CPU is greater than the target duration T4 (i.e., the first duration), the electronic device suspends running the first task on the CPU for a third duration T5. The third duration T5 can be the duration between time t5 and the end of the second management cycle.

[0085] In another example, within the first management cycle, time T1 is the time after the second target duration has passed since the start time of the first management cycle. Since the second target duration is less than the target duration, the first duration is less than the target duration. If the first task runs on the CPU for the second target duration and releases the first permission at this time, the first task is suspended from running on the CPU for a period of time.

[0086] For example, as shown in FIG4 , assume that the first task is Task A, which is a background task running on the CPU with a target duration set to 10ms. The total duration of Task A running on the CPU includes N management cycles. Furthermore, assume that the first management cycle is the third of the N management cycles. In the second management cycle, the first target duration T2 for running the first task on the CPU is 15ms. Then, in the third management cycle, the second target duration T3 for running the first task on the CPU is 5ms. From the start of the third management cycle, after the second target duration T3, at time t4, since the first task does not have the first permission at time t4, and the duration of running the first task on the CPU is greater than the second target duration T3 (i.e., the first duration), the electronic device suspends running the first task on the CPU for the third duration T5. The third duration T5 can be the duration between time t4 and the end of the third management cycle.

[0087] In an embodiment of the present application, when the first task does not have the first permission, the electronic device will force the first task to enter a sleep state after the first task runs on the CPU for a period of time, thereby limiting the running time of the background task, reducing the occupation of CPU resources by the background task, and further improving the smoothness of the foreground task operation.

[0088] In the task processing method provided in the embodiment of the present application, during the first management cycle of running a first task on the CPU of an electronic device (the first task is a background task run by the CPU), it is determined whether the first task has the first permission (the first permission is the permission to access the critical resources of the electronic device). If the first task has the first permission, the first task is kept running on the CPU during the first management cycle until the first task releases the first permission, thereby avoiding the need for the foreground task run by the CPU to wait for the background task to pass the sleep time and release the first permission before it can access the critical resource, so that the foreground task can be scheduled for execution as early as possible, reducing the blocking of the foreground task and improving the smoothness of the foreground task operation. Alternatively, when the first task does not have the first permission and the duration of running the first task on the CPU during the first management cycle is greater than or equal to the first duration, the first task is suspended from running on the CPU, thereby limiting the running time of the background task, reducing the occupation of CPU resources by the background task, and further improving the smoothness of the foreground task operation.

[0089] The following specifically describes how the electronic device limits the running time of the background task on the CPU within two consecutive management cycles.

[0090] Optionally, in an embodiment of the present application, in combination with Figure 1, as shown in Figure 6, the above step 102 can be specifically implemented through the following step 102a. After the above step 102a, the task management method provided in the embodiment of the present application can also include the following step 201.

[0091] Step 102a: The electronic device keeps running the first task on the CPU during the second duration of the first management cycle.

[0092] In the embodiment of the present application, the second duration is the duration between the start time of the first management cycle and the time when the first permission is released.

[0093] Optionally, in an embodiment of the present application, the first task starts running from the start time of the first management cycle. If, within the first management cycle, the first task runs on the CPU for a target period of time, if the first task still has the first permission at time T1, the electronic device continues to keep the first task running on the CPU for a fifth period of time until the first task releases the first permission.

[0094] It can be understood that if the first task still has the first permission after running the target time on the CPU, the electronic device will keep the first task running on the CPU without forcing the first task to enter the sleep state, that is, in the first management cycle, the time for running the first task on the CPU can be greater than the target time.

[0095] For example, as shown in Figure 4, assume that the first task is Task A, which is a background task running on the CPU, and the target duration is set to 10ms. The total running time of Task A on the CPU includes N management cycles, and the first management cycle is the second management cycle among the N management cycles. Starting from the starting time t6 of the second management cycle, after the duration of running the first task on the CPU reaches the target duration of 10ms, at time t2, the first task still has the first permission, then the electronic device continues to keep the first task running on the CPU for the fifth duration T6, and the fifth duration T6 is 5ms, until the first task releases the first permission at time t5. Among them, the second duration is 15ms, that is, the duration between the starting time t6 of the second management cycle and the time t5.

[0096] Step 201: The electronic device suspends running the first task on the CPU within the third duration of the first management cycle.

[0097] In the embodiment of the present application, the third duration is the duration between the time when the first permission is released and the end time of the first management period.

[0098] Optionally, in an embodiment of the present application, after the first task runs on the CPU for a second period of time, it enters a sleep state within a third period of time. When the first task is in the sleep state, the first task waits for the system to allocate CPU resources.

[0099] The third duration in any one of the at least one management period is fixed.

[0100] For example, in conjunction with Figure 4, it is assumed that the first task is Task A, which is a background task running on the CPU, with the target duration set to 10ms and the third duration T5 set to 10ms. It is also assumed that the total running duration of Task A on the CPU includes N management cycles, and the first management cycle is the second management cycle among the N management cycles. In the second management cycle, the second duration of running the first task on the CPU is: starting from the starting time t6 of the second management cycle, until the first task releases the first permission at time t5. After time t5, Task A maintains a restricted running state within the third duration T5 until the end time t7 of the first management cycle. Among them, the third duration is 10ms, that is, the duration between time t5 and time t7.

[0101] It can be seen that since the electronic device can keep running the background task on the CPU from the start time of a management cycle until the first permission is released, the first task is forced to enter the sleep state to limit the running time of the background task on the CPU. That is, even if the first task is ready to continue running after releasing the first permission, resources will not continue to be allocated to the first task, thereby reducing the absolute proportion of the running time of the background task on the CPU, thereby providing more CPU computing power for the foreground task.

[0102] Optionally, in the embodiment of the present application, in combination with FIG6 , as shown in FIG7 , after the above step 201 , the task management method provided in the embodiment of the present application may further include the following step 301 .

[0103] Step 301: The electronic device keeps running the first task on the CPU during the fourth duration of the second management cycle.

[0104] In the embodiment of the present application, the fourth duration is shorter than the second duration; the second management period is the next management period of the first management period, and the first task does not have the first permission during the second management period.

[0105] Optionally, in an embodiment of the present application, in the first management cycle, if the second time duration that the electronic device maintains running the first task on the CPU exceeds the target time duration, then in the next management cycle of the first management cycle, the electronic device shortens the time duration for running the first task on the CPU, so that in at least one management cycle, the average running time of the first task is equal, and the average running time is the target time duration.

[0106] It should be noted that the above-mentioned “average running time” can be understood as the running time obtained by dividing the sum of the durations of all running time periods of at least one management cycle by the number of management cycles of at least one management cycle.

[0107] It can be seen that since the electronic device can control the average running time of the first task in at least one management cycle to be the target time, the absolute proportion of the background task running time on the CPU can be reduced, further improving the smoothness of the foreground task running.

[0108] The following describes in detail the process of determining the fourth duration.

[0109] Optionally, in an embodiment of the present application, in combination with FIG. 7 , as shown in FIG. 8 , before the above step 301 , the task management method provided in the embodiment of the present application may further include the following steps 401 and 402 .

[0110] Step 401: The electronic device determines a fifth duration according to the difference between the second duration and the target duration.

[0111] Optionally, in an embodiment of the present application, after the first management cycle, the electronic device can record the second duration within the first management cycle, and subtract the second duration from the target duration to obtain the difference between the second duration and the target duration, which is the fifth duration.

[0112] Step 402: The electronic device determines a fourth duration according to the target duration and the fifth duration.

[0113] Optionally, in an embodiment of the present application, before the second management period starts, the electronic device may subtract the target duration from the fifth duration based on the fifth duration to obtain the difference between the target duration and the fifth duration, which is the fourth duration.

[0114] In one example, the electronic device subtracts the target duration from the fifth duration, and the value of the fourth duration is 0. That is, when the second duration in the first management cycle is twice the target duration, the first task does not run in the second management cycle and directly enters the restricted state until the end of the second management cycle after the third duration.

[0115] In another example, the electronic device subtracts the target duration from the fifth duration, and the value of the fourth duration is a positive value. Then, during the second management cycle, the first task runs on the CPU for the fourth duration and then enters a restricted state after the third duration until the end of the second management cycle.

[0116] For example, in conjunction with Figure 4, it is assumed that the first task is Task A, which is a background task running on the CPU, the target duration T4 is set to 10ms, and the third duration T5 is 10ms. The total running time of Task A on the CPU includes N management cycles. It is also assumed that the first management cycle is the second management cycle among the N management cycles. In the second management cycle, the second duration of running the first task on the CPU is T2, and T2 is 15ms. Before the start of the third management cycle (i.e., the second management cycle), the electronic device determines the fourth duration to be 5ms based on the difference between the second duration T2 and the target duration T4. Starting from the third management cycle, after running the first task on the CPU for 5ms, it reaches time t4, and the first task does not have the first permission at time t4. Then, within the third duration T5, the electronic device suspends running the first task on the CPU.

[0117] It can be seen that if the electronic device runs the first task on the CPU for a long time in the first management cycle, then the time for running the first task on the CPU will be shortened in the next management cycle of the first management cycle, thereby reducing the absolute proportion of the running time of the background task on the CPU and improving the smoothness of the foreground task running.

[0118] The method provided in the embodiment of the present application can be executed by a task management device. In the embodiment of the present application, the task management device provided in the embodiment of the present application is described by taking the task management device executing the task management method as an example.

[0119] Figure 9 shows a task management device 60 involved in the above embodiment, which includes: a determination module 61 and an operation management module 62. The determination module 61 is used to determine whether the first task has the first permission during the first management cycle of running the first task on the CPU. The first task is a background task run by the CPU, and the first permission is the permission to access the critical resources of the electronic device. The operation management module 62 is used to keep running the first task on the CPU during the first management cycle when the determination module determines that the first task has the first permission until the first task releases the first permission; or, when the determination module determines that the first task does not have the first permission and the time length for running the first task on the CPU during the first management cycle is greater than or equal to the first time length, suspend running the first task on the CPU.

[0120] In a possible implementation, the total running time of the first task on the CPU includes at least one management cycle, and the first management cycle is any one of the at least one management cycle.

[0121] In a possible implementation, the determination module is specifically configured to determine whether the first task has the first permission at time T1 of the first management cycle of the first task running on the CPU.

[0122] In one possible implementation, the operation management module is specifically configured to maintain execution of the first task on the CPU during a second duration of the first management cycle, where the second duration is the duration between the start time of the first management cycle and the time when the first permission is released. The operation management module is further configured to suspend execution of the first task on the CPU during a third duration of the first management cycle, where the third duration is the duration between the time when the first permission is released and the end time of the first management cycle.

[0123] In one possible implementation, the operation management module is further configured to keep the first task running on the CPU during a fourth duration of the second management cycle, where the fourth duration is less than the second duration. The second management cycle is a management cycle subsequent to the first management cycle, and the first task does not have the first permission during the second management cycle.

[0124] In one possible implementation, the above-mentioned determination module is also specifically used to determine whether the first task has the first permission within the first management cycle of running the first task on the CPU when the first task and the second task are running on the CPU, the load parameter of the CPU is greater than or equal to a preset threshold, and there is no dependency relationship between the first task and the second task. The load parameter is used to indicate the load condition of the CPU, and the second task is the foreground task running on the CPU.

[0125] The task management device provided by the embodiment of the present application determines whether the first task has the first permission (the first permission is the permission to access the critical resources of the electronic device) during the first management cycle of running the first task (the first task is a background task run by the CPU) on the CPU of the task management device. If the first task has the first permission, the first task is kept running on the CPU during the first management cycle until the first task releases the first permission, thereby avoiding the need for the foreground task run by the CPU to wait for the background task to pass the sleep time and release the first permission before it can access the critical resource, so that the foreground task can be scheduled for execution as early as possible, reducing the blocking of the foreground task and improving the smoothness of the foreground task operation. Alternatively, if the first task does not have the first permission and the duration of running the first task on the CPU during the first management cycle is greater than or equal to the first duration, the first task is suspended from running on the CPU, thereby limiting the running time of the background task, reducing the occupation of CPU resources by the background task, and further improving the smoothness of the foreground task operation.

[0126] The task management device in the embodiment of the present application can be an electronic device or a component in the electronic device, such as an integrated circuit or chip. The electronic device can be a terminal or other device other than a terminal. For example, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a mobile internet device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc. It can also be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc., and the embodiment of the present application does not specifically limit it.

[0127] The task management device in the embodiment of the present application can be a device having an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0128] The task management device provided in the embodiment of the present application can implement each process implemented in the method embodiments of Figures 1 to 8. To avoid repetition, they will not be described here.

[0129] Optionally, in an embodiment of the present application, as shown in Figure 10, an embodiment of the present application further provides an electronic device 80, including a processor 81 and a memory 82, and the memory 82 stores a program or instruction that can be run on the processor 81. When the program or instruction is executed by the processor 81, the various process steps of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0130] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0131] FIG11 is a schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.

[0132] The electronic device 100 includes but is not limited to components such as a radio frequency unit 1001 , a network module 1002 , an audio output unit 1003 , an input unit 1004 , a sensor 1005 , a display unit 1006 , a user input unit 1007 , an interface unit 1008 , a memory 1009 , and a processor 110 .

[0133] Those skilled in the art will appreciate that the electronic device 100 may further include a power source (e.g., a battery) for powering various components. The power source may be logically connected to the processor 110 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The electronic device structure shown in FIG11 does not limit the electronic device. The electronic device may include more or fewer components than shown, or may combine certain components, or have different component arrangements, which will not be described in detail here.

[0134] Among them, the processor 110 is specifically used to determine whether the first task has the first permission within the first management cycle of running the first task on the CPU; the first task is a background task run by the CPU; the first permission is the permission to access critical resources of the electronic device; if the first task has the first permission, keep running the first task on the CPU within the first management cycle until the first task releases the first permission; or, if the first task does not have the first permission and the time length for running the first task on the CPU within the first management cycle is greater than or equal to the first time length, suspend running the first task on the CPU.

[0135] The electronic device provided by the embodiment of the present application determines whether the first task has the first permission (the first permission is the permission to access the critical resources of the electronic device) during the first management cycle of the first task running on the CPU of the electronic device (the first task is a background task run by the CPU). If the first task has the first permission, the first task is kept running on the CPU during the first management cycle until the first task releases the first permission, thereby avoiding the need for the foreground task run by the CPU to wait for the background task to pass the sleep time and release the first permission before it can access the critical resource, so that the foreground task can be scheduled for execution as early as possible, reducing the blocking of the foreground task and improving the smoothness of the foreground task operation. Alternatively, if the first task does not have the first permission and the duration of the first task running on the CPU during the first management cycle is greater than or equal to the first duration, the first task is suspended from running on the CPU, thereby limiting the running time of the background task, reducing the occupation of CPU resources by the background task, and further improving the smoothness of the foreground task operation.

[0136] Optionally, in an embodiment of the present application, the processor 110 is specifically configured to determine whether the first task has the first permission at time T1 of the first management cycle of running the first task on the CPU.

[0137] It can be seen that since the electronic device determines whether the first task has the first permission at time T1 of each management cycle, the duration of running the first task on the CPU within the management cycle is determined, thereby ensuring that the first task will not enter a restricted state when it has the first permission.

[0138] Optionally, in an embodiment of the present application, the processor 110 is specifically used to keep running the first task on the CPU during the second duration of the first management cycle, where the second duration is: the duration between the start time of the first management cycle and the time when the first permission is released; and to suspend running the first task on the CPU during the third duration of the first management cycle, where the third duration is: the duration between the time when the first permission is released and the end time of the first management cycle.

[0139] It can be seen that since the electronic device can keep running background tasks on the CPU from the start time of a management cycle until the first permission is released, the first task is forced to enter a sleep state to limit the running time of the background task on the CPU, thereby reducing the absolute proportion of the running time of the background task on the CPU, thereby providing more CPU computing power for the foreground task.

[0140] Optionally, in an embodiment of the present application, the processor 110 is specifically used to keep running the first task on the CPU within a fourth duration of the second management cycle, and the fourth duration is less than the second duration; wherein the second management cycle is the next management cycle of the first management cycle, and the first task does not have the first permission within the second management cycle.

[0141] It can be seen that since the electronic device can control the average running time of the first task in at least one management cycle to be the target time, the absolute proportion of the background task running time on the CPU can be reduced, further improving the smoothness of the foreground task running.

[0142] Optionally, in an embodiment of the present application, the processor 110 is specifically used to determine whether the first task has the first permission within the first management cycle of running the first task on the CPU, when the first task and the second task are running on the CPU, the load parameter of the CPU is greater than or equal to a preset threshold, and there is no dependency relationship between the first task and the second task. The load parameter is used to indicate the load condition of the CPU, and the second task is the foreground task running on the CPU.

[0143] It can be seen that since the electronic device can decide whether to impose system resource restrictions on the background task by determining whether the background task has the first permission when the CPU load parameter is greater than or equal to the preset threshold and there is no dependency between the foreground task and the background task, the background task can be restricted in a high-load scenario to ensure that the foreground task can run smoothly.

[0144] It should be understood that in an embodiment of the present application, the input unit 1004 may include a graphics processing unit (GPU) 1041 and a microphone 1042, and the graphics processor 1041 processes image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1006 may include a display panel 1061, and the display panel 1061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 1071 and at least one of other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include two parts: a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.

[0145] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, applications or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM), and a direct rambus RAM (DRRAM). The memory 1009 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.

[0146] Processor 110 may include one or more processing units. Optionally, processor 110 integrates an application processor and a modem processor. The application processor primarily handles operations related to the operating system, user interface, and application programs, while the modem processor primarily processes wireless communication signals, such as a baseband processor. It is understood that the modem processor may not be integrated into processor 110.

[0147] It should be noted that, in this article, 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. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0148] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0149] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

Claims

1. A task management method, the method comprising: Determining, during a first management cycle of running a first task on the CPU, whether the first task has a first permission; The first task is a background task run by the CPU; The first permission is permission to access critical resources of the electronic device; In a case where the first task has the first permission, keep running the first task on the CPU during the first management period until the first task releases the first permission; or, When the first task does not have the first permission and the duration of running the first task on the CPU in the first management period is greater than or equal to a first duration, the running of the first task on the CPU is suspended.

2. The method according to claim 1, wherein: The total duration of running the first task on the CPU includes at least one management cycle, and the first management cycle is any one of the at least one management cycle.

3. The method according to claim 1, wherein: Determining whether the first task has the first permission during the first management cycle of running the first task on the CPU includes: At time T1 of the first management cycle of running the first task on the CPU, it is determined whether the first task has the first permission.

4. The method according to claim 1, wherein: The step of maintaining the first task on the CPU during the first management period until the first task releases the first permission includes: During a second duration of the first management cycle, keep running the first task on the CPU, where the second duration is: a duration from a start time of the first management cycle to a time when the first permission is released; After the CPU continues to run the first task within the second duration of the first management cycle, the method further includes: During a third duration of the first management cycle, suspending the execution of the first task on the CPU, the third duration being from the time when the first permission is released to the end of the first management cycle. The length of time between.

5. The method according to claim 4, wherein: After pausing the execution of the first task on the CPU within the third duration of the first management cycle, the method further includes: During a fourth duration of a second management cycle, the first task is kept running on the CPU, the fourth duration being shorter than the second duration; The second management cycle is a management cycle next to the first management cycle, and the first task does not have the first authority in the second management cycle.

6. The method according to claim 1, wherein: Determining whether the first task has the first permission during the first management cycle of running the first task on the CPU includes: When the first task and the second task are running on the CPU, the load parameter of the CPU is greater than or equal to a preset threshold, and there is no dependency between the first task and the second task, within a first management cycle of running the first task on the CPU, determine whether the first task has the first permission, the load parameter is used to indicate the load condition of the CPU, and the second task is a foreground task running on the CPU.

7. A task management device, comprising: Determine modules and run management modules; The determination module is used to determine whether the first task has the first permission during a first management cycle of running the first task on the CPU; The first task is a background task run by the CPU; The first permission is the permission to access the critical resources of the task management device; The operation management module is used to keep running the first task on the CPU within the first management cycle until the first task releases the first permission when the determination module determines that the first task has the first permission; or to suspend running the first task on the CPU when the determination module determines that the first task does not have the first permission and the duration of running the first task on the CPU within the first management cycle is greater than or equal to the first duration.

8. The task management device according to claim 7, wherein: The total running time of the first task on the CPU includes at least one management cycle, and the first management cycle is any one of the at least one management cycle.

9. The task management device according to claim 7, wherein: The determination module is specifically configured to determine whether the first task has the first permission at time T1 of the first management cycle of running the first task on the CPU.

10. The task management device according to claim 7, wherein: The operation management module is specifically configured to keep the first task running on the CPU within a second duration of the first management cycle, where the second duration is a duration from the start time of the first management cycle to the time when the first permission is released; The operation management module is further used to suspend the execution of the first task on the CPU within a third duration of the first management cycle, and the third duration is: the duration between the time when the first permission is released and the end time of the first management cycle.

11. The task management device according to claim 10, wherein: The operation management module is further used to keep running the first task on the CPU within a fourth duration of the second management cycle, and the fourth duration is less than the second duration; The second management cycle is a management cycle next to the first management cycle, and the first task does not have the first authority in the second management cycle.

12. The task management device according to claim 7, wherein: The determination module is specifically used to determine whether the first task has the first permission within a first management cycle of running the first task on the CPU, when the first task and the second task are running on the CPU, the load parameter of the CPU is greater than or equal to a preset threshold, and there is no dependency between the first task and the second task. The load parameter is used to indicate the load condition of the CPU, and the second task is a foreground task running on the CPU.

13. An electronic device comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the task management method according to any one of claims 1 to 6 are implemented.

14. A readable storage medium storing a program or an instruction, wherein the program or the instruction, when executed by a processor, implements the steps of the task management method according to any one of claims 1 to 6.

15. An electronic device, configured to implement the task management method according to any one of claims 1-6.

16. A chip comprising a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run a program or an instruction to implement the task management method according to any one of claims 1 to 6.

17. A computer program product, wherein when instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the task management method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method for terminal of automatically releasing resources occupied by background programs, storage medium and terminal

    CN107544847A

  • Resource allocation method and device, mobile terminal and computer readable storage medium

    CN109992400A

  • System resource adjustment method and device and readable storage medium

    CN110704187A

  • Task management method and device, electronic equipment and medium

    CN116382876A