Task scheduling method, storage medium and intelligent equipment

By establishing a resource dependency chain in the Android operating system and scheduling based on this chain, the performance problems caused by priority flip in task scheduling are solved, and timely resource release and system fluency are achieved.

CN120104263APending Publication Date: 2025-06-06WEILAI MOBILE TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311672200.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-06
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

In Android operating systems, competing access to shared resources between tasks may lead to priority flips, which in turn affects system performance.

Method used

By establishing a resource dependency chain, tasks waiting for the CPU to run are arranged in a chain according to their waiting resources and holding resources, and tasks are scheduled based on this chain. If priority flip occurs, obtain the importance level of tasks at each level of the chain for scheduling.

Benefits of technology

It effectively reduces the possibility of priority flip during task scheduling, ensures timely release of resources, eliminates system lag, and improves system fluency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120104263A_ABST
    Figure CN120104263A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer information processing, and particularly provides a task scheduling method, a storage medium and intelligent equipment. The method and the device aim at solving the problem of poor performance caused by priority overturning in the task scheduling process. In order to achieve the purpose, the task scheduling method comprises the steps that in response to the situation that shared resources to be accessed by a target task are held by other tasks, the tasks waiting for CPU operation are arranged in a chain mode according to waiting resources and held resources of the tasks, and a resource dependency chain is established; and performing task scheduling based on the resource dependency chain. By establishing the resource dependency chain and performing task scheduling based on the resource dependency chain, the possibility of priority overturning in the task scheduling process is greatly reduced; and for possible priority upset, task scheduling is carried out through further importance levels of the tasks on each layer on the resource dependency chain, so that resources can be released as soon as possible, performance problems such as system jamming can be eliminated, and system fluency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer information processing, and specifically provides a task scheduling method, a storage medium and an intelligent device. Background Art

[0002] In the current mobile device environment, the Android operating system, as a multi-tasking operating system, provides a variety of cross-process communication mechanisms, which inevitably leads to the problem of competing for shared resources among tasks. The so-called shared resources include but are not limited to global variables, file descriptors, socket descriptors and other software or hardware resources that can be shared between multiple tasks.

[0003] Currently, an effective measure to resolve contention for access to shared resources is to use a lock mechanism to access shared resources, so that access to shared resources becomes orderly and presents consistent results.

[0004] However, this lock mechanism may lead to priority inversion, that is, when a low-priority task accesses a shared resource, a high-priority task may have to wait for the high-priority task to release the lock due to lock protection. Currently, there is no effective and universal mechanism to effectively solve the priority inversion problem in the task scheduling process.

[0005] Accordingly, the art needs a new task scheduling solution to solve the above problems. Summary of the invention

[0006] In order to overcome the above-mentioned defects, the present application is proposed to provide a task scheduling method, a storage medium and an intelligent device to solve or at least partially solve the problem of poor performance caused by priority flipping in the task scheduling process.

[0007] In a first aspect, the present application provides a task scheduling method, comprising:

[0008] In response to a shared resource that the target task is waiting to access being held by other tasks, the tasks waiting for CPU execution are arranged in a chain according to the waiting resources and held resources of the tasks to establish a resource dependency chain;

[0009] Task scheduling is performed based on the resource dependency chain.

[0010] In a technical solution of the above task scheduling method, the tasks waiting for CPU execution are linked and sorted according to the waiting resources and held resources of the tasks to establish a resource dependency chain, including:

[0011] S1, taking the target task as the bottom task of the resource dependency chain, and obtaining the waiting resources of the bottom task;

[0012] S2, obtaining a task at an upper layer, wherein the holding resource of the task at an upper layer is the same as the waiting resource of the task at an underlying layer;

[0013] S3, obtaining the waiting resources of the upper layer task;

[0014] S4. Replace the bottom-level task in step S2 with the n-th-level task, replace the upper-level task in step S2 and step S3 with the n-1-th-level task, and execute step S2-step S3 in a loop, obtaining each level of tasks on the resource dependency chain layer by layer, until a task that does not need to wait for resources is obtained, and the task that does not need to wait for resources is the top-level task of the resource dependency chain; wherein n is a positive integer greater than 1.

[0015] In a technical solution of the above task scheduling method, the task scheduling is performed based on the resource dependency chain using a completely fair scheduling algorithm, including:

[0016] Obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler;

[0017] Determining whether priority flipping occurs in the resource dependency chain based on the acquired priority;

[0018] If no priority inversion occurs, performing task scheduling based on the resource dependency chain;

[0019] If a priority reversal occurs, the importance level of each layer of the task on the resource dependency chain is obtained, and the task scheduling is performed based on the resource dependency chain and the importance level.

[0020] In a technical solution of the above task scheduling method, obtaining the importance level of each layer of the task on the resource dependency chain includes:

[0021] Classify tasks waiting for CPU execution based on control groups at the application layer;

[0022] Obtaining the initial importance level of each layer of tasks on the resource dependency chain based on the control group classification of the tasks;

[0023] Based on the initial importance level, the importance level of the tasks at each layer is obtained.

[0024] In a technical solution of the above task scheduling method, the classification of tasks waiting for CPU execution based on control groups at the application layer includes:

[0025] The tasks waiting for CPU execution are divided into different control groups based on the visibility of the tasks. The control groups include at least top tasks, foreground tasks and background tasks.

[0026] In a technical solution of the above task scheduling method, the task-based control group classification obtains the initial importance level of each layer of the task on the resource dependency chain, including:

[0027] In the resource dependency chain, based on the control groups to which the tasks in two adjacent layers belong respectively, the initial importance level of the upper layer task is obtained; wherein, the greater the initial importance level of the task, the lower its importance:

[0028] When the upper-layer task is a background task and the lower-layer task is a top task or a foreground task, the initial importance level of the upper-layer task is 1 or 2 respectively;

[0029] When the upper-layer task is a foreground task and the lower-layer task is a top task or a background task, the initial importance level of the upper-layer task is level 3 or level 4 respectively;

[0030] When the upper-layer task is a top task and the lower-layer task is a foreground task or a background task, the initial importance level of the upper-layer task is level 5 or level 6, respectively.

[0031] In a technical solution of the above task scheduling method, obtaining the importance level of the tasks at each layer based on the initial importance level includes:

[0032] In the resource dependency chain of layer m, based on the initial importance level of the tasks of layer m-1, search upward along the resource dependency chain to determine whether there is a task with an initial importance level greater than that of layer m-1;

[0033] If not, the initial importance level of each layer of the task on the resource dependency chain is used as the importance level;

[0034] If it exists, obtain the k-th layer task whose initial importance level is greater than the m-1-th layer, and obtain the importance level based on the initial importance level of the k-th layer task;

[0035] The importance level of each layer of tasks is obtained from bottom to top along the resource dependency chain, wherein the importance level of the upper layer tasks is not greater than that of the lower layer tasks; wherein m is a positive integer greater than 1; when obtaining the kth layer task, k is a positive integer, and m-1>k.

[0036] In a technical solution of the above task scheduling method, after obtaining the importance level of the tasks at each layer, the method further includes:

[0037] Get multiple resource dependency chains based on the tasks waiting for the CPU to run;

[0038] Obtain the importance level of the top-level tasks of each resource dependency chain respectively;

[0039] Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.

[0040] In a technical solution of the above task scheduling method, the task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain, including:

[0041] Obtain the resource dependency chain with the smallest importance level of the top-level task in each resource dependency chain;

[0042] Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.

[0043] In a technical solution of the above task scheduling method, the task scheduling based on the resource dependency chain includes:

[0044] A completely fair scheduling algorithm is used for task scheduling.

[0045] In a second aspect, the present application provides a computer-readable storage medium storing a plurality of program codes, wherein the program codes are suitable for being loaded and run by a processor to execute the task scheduling method described in any one of the technical solutions of the above-mentioned task scheduling method.

[0046] In a third aspect, the present application provides a smart device, including:

[0047] at least one processor;

[0048] and, a memory communicatively coupled to the at least one processor;

[0049] Wherein, a computer program is stored in the memory, and when the computer program is executed by the at least one processor, the task scheduling method described in any one of the technical solutions of the above-mentioned task scheduling method is implemented.

[0050] Solution 1. A task scheduling method, characterized by comprising:

[0051] In response to a shared resource that the target task is waiting to access being held by other tasks, the tasks waiting for CPU execution are arranged in a chain according to the waiting resources and held resources of the tasks to establish a resource dependency chain;

[0052] Task scheduling is performed based on the resource dependency chain.

[0053] Solution 2. The method according to Solution 1 is characterized in that the tasks waiting for the CPU to run are linked and sorted according to the waiting resources and held resources of the tasks to establish a resource dependency chain, including:

[0054] S1, taking the target task as the bottom task of the resource dependency chain, and obtaining the waiting resources of the bottom task;

[0055] S2, obtaining a task at an upper layer, wherein the holding resource of the task at an upper layer is the same as the waiting resource of the task at an underlying layer;

[0056] S3, obtaining the waiting resources of the upper layer task;

[0057] S4. Replace the bottom-level task in step S2 with the n-th-level task, replace the upper-level task in step S2 and step S3 with the n-1-th-level task, and execute step S2-step S3 in a loop, obtaining each layer of tasks on the resource dependency chain layer by layer, until a task that does not need to wait for resources is obtained, and the task that does not need to wait for resources is the top-level task of the resource dependency chain; wherein n is a positive integer greater than 1.

[0058] Solution 3. The method according to Solution 2 is characterized in that the task scheduling based on the resource dependency chain includes:

[0059] Obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler;

[0060] Determining whether priority flipping occurs in the resource dependency chain based on the acquired priority;

[0061] If no priority inversion occurs, performing task scheduling based on the resource dependency chain;

[0062] If a priority reversal occurs, the importance level of each layer of the task on the resource dependency chain is obtained, and the task scheduling is performed based on the resource dependency chain and the importance level.

[0063] Solution 4. The method according to Solution 3 is characterized in that the step of obtaining the importance level of each layer of the task on the resource dependency chain comprises:

[0064] Classify tasks waiting for CPU execution based on control groups at the application layer;

[0065] Acquire the initial importance level of each layer of tasks on the resource dependency chain based on the control group classification of the tasks;

[0066] Based on the initial importance level, the importance level of the tasks at each layer is obtained.

[0067] Solution 5. The method according to Solution 4 is characterized in that the classification of tasks waiting for CPU execution based on control groups at the application layer includes:

[0068] The tasks waiting for CPU execution are divided into different control groups based on the visibility of the tasks. The control groups include at least top tasks, foreground tasks and background tasks.

[0069] Solution 6. The method according to Solution 5 is characterized in that the task-based control group classification obtains the initial importance level of each layer of the task on the resource dependency chain, including:

[0070] In the resource dependency chain, based on the control groups to which the tasks in two adjacent layers belong respectively, the initial importance level of the upper layer task is obtained; wherein, the greater the initial importance level of the task, the lower its importance:

[0071] When the upper-layer task is a background task and the lower-layer task is a top task or a foreground task, the initial importance level of the upper-layer task is 1 or 2 respectively;

[0072] When the upper-layer task is a foreground task and the lower-layer task is a top task or a background task, the initial importance level of the upper-layer task is level 3 or level 4 respectively;

[0073] When the upper-layer task is a top task and the lower-layer task is a foreground task or a background task, the initial importance level of the upper-layer task is level 5 or level 6, respectively.

[0074] Solution 7. The method according to Solution 4 is characterized in that the step of obtaining the importance level of the tasks at each layer based on the initial importance level comprises:

[0075] In the resource dependency chain of layer m, based on the initial importance level of the tasks of layer m-1, search upward along the resource dependency chain to determine whether there is a task with an initial importance level greater than that of layer m-1;

[0076] If not, the initial importance level of each layer of the task on the resource dependency chain is used as the importance level;

[0077] If it exists, obtain the k-th layer task whose initial importance level is greater than the m-1-th layer, and obtain the importance level based on the initial importance level of the k-th layer task;

[0078] The importance level of each layer of tasks is obtained from bottom to top along the resource dependency chain, wherein the importance level of the upper layer tasks is not greater than that of the lower layer tasks; wherein m is a positive integer greater than 1; when obtaining the kth layer task, k is a positive integer, and m-1>k.

[0079] Solution 8. The method according to any one of solutions 4 to 7, characterized in that after obtaining the importance level of the tasks at each layer, the method further comprises:

[0080] Get multiple resource dependency chains based on the tasks waiting for the CPU to run;

[0081] Obtain the importance level of the top-level tasks of each resource dependency chain respectively;

[0082] Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.

[0083] Solution 9. The method according to Solution 8 is characterized in that the task scheduling based on the importance level of the top-level tasks of each resource dependency chain includes:

[0084] Obtain the resource dependency chain with the smallest importance level of the top-level task in each resource dependency chain;

[0085] Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.

[0086] Solution 10. The method according to any one of solutions 1 to 7, characterized in that the task scheduling based on the resource dependency chain comprises:

[0087] A completely fair scheduling algorithm is used for task scheduling.

[0088] Solution 11. A computer-readable storage medium storing a plurality of program codes, wherein the program codes are suitable for being loaded and run by a processor to execute the task scheduling method described in any one of Solutions 1 to 10.

[0089] Solution 12. A smart device, comprising:

[0090] at least one processor;

[0091] and, a memory communicatively coupled to the at least one processor;

[0092] The memory stores a computer program, and when the computer program is executed by the at least one processor, the task scheduling method described in any one of Schemes 1 to 10 is implemented.

[0093] The above one or more technical solutions of this application have at least one or more of the following Beneficial effects:

[0094] In the technical solution for implementing the present application, by establishing a resource dependency chain and performing task scheduling based on the resource dependency chain, the possibility of priority reversal during task scheduling is greatly reduced; for possible priority reversal, by further scheduling tasks based on the importance level of tasks at each layer on the resource dependency chain, resources can be released as soon as possible, performance issues such as system freezes can be eliminated, and system fluency can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0095] The disclosure of the present application will become more easily understood with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present application. In addition, similar numbers in the drawings are used to represent similar components, among which:

[0096] Figure 1 It is a schematic diagram of the main steps of a task scheduling method according to an embodiment of the present application;

[0097] Figure 2 It is a detailed flowchart of the steps for task scheduling based on the resource dependency chain in this application;

[0098] Figure 3 is a detailed step flow chart of a task scheduling method according to an embodiment of the present application;

[0099] Figure 4 It is a main structural block diagram of an intelligent device for executing the task scheduling method of the present application;

[0100] Figure 5 It is a software structure diagram of a smart device in one embodiment of the present application. DETAILED DESCRIPTION

[0101] Some embodiments of the present application are described below with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are only used to explain the technical principles of the present application and are not intended to limit the protection scope of the present application.

[0102] In the description of the present application, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, memory, and may also include software parts, such as program code, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware or a combination of the two. Non-temporary computer-readable storage media include any suitable medium that can store program code, such as a disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, etc. The term "A and / or B" means all possible combinations of A and B, such as only A, only B or A and B. The term "at least one A or B" or "at least one of A and B" has a similar meaning to "A and / or B" and may include only A, only B or A and B. The singular terms "one" and "the" may also include plural forms.

[0103] The present application provides a task scheduling method. The task scheduling method can be applied to terminal devices such as mobile phones and tablet computers, and the terminal devices can use the Android system. The technical solution involved in the present application will be described using the Android system as an example.

[0104] See attached Figure 1 , Figure 1 FIG. 1 is a schematic diagram of the main steps of a task scheduling method according to an embodiment of the present application. Figure 1 As shown, the task scheduling method in the embodiment of the present application mainly includes the following steps S11-S12.

[0105] Step S11 , in response to the shared resource that the target task is waiting to access being held by other tasks, the tasks waiting for the CPU to run are arranged in a chain according to the waiting resources and held resources of the tasks to establish a resource dependency chain.

[0106] In one embodiment of the present application, the tasks waiting for the CPU to run are linked and sorted according to their waiting resources and held resources to establish a resource dependency chain, including:

[0107] S1, taking the target task as the bottom task of the resource dependency chain, and obtaining the waiting resources of the bottom task;

[0108] S2, obtaining a task at an upper layer, wherein the holding resource of the task at an upper layer is the same as the waiting resource of the task at an underlying layer;

[0109] S3, obtaining the waiting resources of the upper layer task;

[0110] S4. Replace the bottom-level task in step S2 with the n-th-level task, replace the upper-level task in step S2 and step S3 with the n-1-th-level task, and execute step S2-step S3 in a loop, obtaining each layer of tasks on the resource dependency chain layer by layer, until a task that does not need to wait for resources is obtained, and the task that does not need to wait for resources is the top-level task of the resource dependency chain; wherein n is a positive integer greater than 1.

[0111] Exemplarily, if the waiting resource of the target task A3 is L2, use it as the bottom-level task; obtain the previous-level task A2, whose holding resource is L2, and obtain the waiting resource L1 of the previous-level task A2; loop through the above steps to obtain task A1 that does not need to wait for resources, whose holding resource is L1; establish a resource dependency chain, in which the top-level task of the resource dependency chain is A1, the second-level task is A2, and the bottom-level task is A3.

[0112] Step S12: performing task scheduling based on the resource dependency chain.

[0113] In one implementation of the present application, the performing task scheduling based on the resource dependency chain includes: performing task scheduling using a completely fair scheduling algorithm.

[0114] Completely Fair Scheduler (CFS) is a scheduling algorithm in Linux system. It provides relatively fair CPU time for each task by dynamically adjusting the virtual running time and weight of the task, so as to achieve fairness and balance in a multi-tasking environment.

[0115] In one embodiment of the present application, the task scheduling is performed based on the resource dependency chain. Figure 2 .

[0116] Figure 2 This is a detailed flowchart of the steps for task scheduling based on the resource dependency chain in this application. Figure 2 As shown, it mainly includes the following steps S21-S25.

[0117] Step S21, obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler.

[0118] In a multitasking system, the priority of tasks is usually determined by the scheduler. The scheduler is responsible for deciding which task should be executed at a given time, and the priority of the task is one of the key factors in determining the scheduling order.

[0119] Step S22: determining whether priority inversion occurs in the resource dependency chain based on the acquired priority.

[0120] Priority flipping refers to a situation where a high-priority task is blocked by a low-priority task, resulting in a delay in scheduling the high-priority task. In one embodiment of the present application, since it is necessary to schedule tasks based on the resource dependency chain, if the priority of the task in the upper layer of the resource dependency chain is lower than that of the task in the lower layer, it is considered a priority flip. In this embodiment, whether a priority flip occurs is determined by comparing the priorities of the bottom layer task and its upper layer task.

[0121] If no priority flip occurs, step S23 is executed to schedule tasks based on the resource dependency chain. In this embodiment, the task scheduling based on the resource dependency chain is to execute tasks in order from top to bottom according to the resource dependency chain to release resources; and while based on the resource dependency chain, a completely fair scheduling algorithm is adopted.

[0122] If a priority reversal occurs, step S24 is executed to obtain the importance level of each layer of tasks in the resource dependency chain.

[0123] In one embodiment of the present application, obtaining the importance level of each layer of the task on the resource dependency chain includes:

[0124] Classify tasks waiting for CPU execution based on control groups (cgroups) at the application layer;

[0125] Obtaining the initial importance level of each layer of tasks on the resource dependency chain based on the control group classification of the tasks;

[0126] Based on the initial importance level, the importance level of the tasks at each layer is obtained.

[0127] In one embodiment, the classifying the tasks waiting for CPU execution based on the control group at the application layer includes:

[0128] The tasks waiting for CPU execution are divided into different control groups based on the visibility of the tasks. The control groups include at least top tasks, foreground tasks and background tasks.

[0129] Among them, top tasks refer to services or applications that are operable, perceptible, and interactive to users, such as the browser currently being browsed by the user; foreground tasks refer to services or applications other than top tasks that are operable and perceptible to users, such as when a user switches out of the interface of a music app while listening to music (i.e., music is playing in the background), the music app is a foreground task; background tasks refer to services or applications that are not operable or perceptible to users, such as background logs.

[0130] The visibility of the tasks of the control group decreases in order of top task, foreground task, and background task.

[0131] In addition, those skilled in the art may also add other custom control group categories besides the top tasks, foreground tasks and background tasks according to needs, such as a control group related to a certain hardware feature.

[0132] Furthermore, the task-based control group classification obtains the initial importance level of each layer of tasks on the resource dependency chain, including:

[0133] In the resource dependency chain, based on the control groups to which the tasks in two adjacent layers belong respectively, the initial importance level of the upper layer task is obtained; wherein, the greater the initial importance level of the task, the lower its importance.

[0134] Please see the following initial importance ranking table, as shown in Table 1:

[0135] Table 1

[0136] When the upper-layer task is a background task and the lower-layer task is a top task or a foreground task, the initial importance level of the upper-layer task is 1 or 2 respectively;

[0137] When the upper-layer task is a foreground task and the lower-layer task is a top task or a background task, the initial importance level of the upper-layer task is level 3 or level 4 respectively;

[0138] When the upper-layer task is a top task and the lower-layer task is a foreground task or a background task, the initial importance level of the upper-layer task is level 5 or level 6, respectively.

[0139] The initial importance levels gradually increase from level 1 to level 6, and their importance levels decrease in sequence.

[0140] Further, in one embodiment, obtaining the importance level of the tasks at each layer based on the initial importance level includes:

[0141] In the resource dependency chain of layer m, based on the initial importance level of the tasks of layer m-1, search upward along the resource dependency chain to determine whether there is a task with an initial importance level greater than that of layer m-1;

[0142] If not, the initial importance level of each layer of the task on the resource dependency chain is used as the importance level;

[0143] If it exists, obtain the k-th layer task whose initial importance level is greater than the m-1-th layer, and obtain the importance level based on the initial importance level of the k-th layer task;

[0144] The importance level of each layer of tasks is obtained from bottom to top along the resource dependency chain, wherein the importance level of the upper layer tasks is not greater than that of the lower layer tasks; wherein m is a positive integer greater than 1; when obtaining the kth layer task, k is a positive integer, and m-1>k.

[0145] The number of reduction levels can be set as needed by those skilled in the art. For the same system, the step size of the number of reduction levels can be set to be consistent during the task scheduling process.

[0146] Exemplarily, if the initial importance level of the k+1th layer task is level 4 and the initial importance level of the kth layer task is level 5, when the step size of the reduction level is set to 2, the importance level of the kth layer task is level 3.

[0147] In addition, when judging whether there is a task with an initial importance level greater than that of the m-1th layer, if the initial importance levels of tasks in two consecutive layers are the same, the judgment result is that there is no task. Therefore, the importance levels of tasks in the resource dependency chain may be the same continuously, and it is sufficient to ensure that the importance level of the upper layer tasks is not greater than that of the lower layer tasks.

[0148] After obtaining the importance levels of the tasks at each layer, for the same resource dependency chain, the top-level task has the lowest importance level. Depending on the different tasks on the resource dependency chain, the importance level of the top-level task may be level 1 or greater than level 1.

[0149] After step S24 is completed, step S25 is continued to be executed to perform task scheduling based on the resource dependency chain and the importance level.

[0150] In one embodiment, after obtaining the importance levels of the tasks at each layer, the method further includes:

[0151] Get multiple resource dependency chains based on the tasks waiting for the CPU to run;

[0152] Obtain the importance level of the top-level tasks of each resource dependency chain respectively;

[0153] Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.

[0154] Furthermore, the task scheduling based on the importance level of the top-level tasks of each resource dependency chain includes:

[0155] Obtain the resource dependency chain with the smallest importance level of the top-level task in each resource dependency chain;

[0156] Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.

[0157] Specifically, the task migration path can be determined based on comprehensive consideration of the load balancing and performance characteristics of multiple CPUs, and a CPU with a smaller load and better performance characteristics can be selected for waiting, so as to release resources as soon as possible.

[0158] Among them, since the top-level task of the resource dependency chain is the current resource holding task, the scheduling of the entire resource dependency chain is completed by scheduling the top-level resource holding task.

[0159] The task scheduling ends when the target task releases resources.

[0160] Based on the above steps S11 and S12, by establishing a resource dependency chain and performing task scheduling based on the resource dependency chain, the possibility of priority flipping during task scheduling is greatly reduced; for possible priority flipping, by further scheduling tasks based on the importance level of tasks at each layer on the resource dependency chain, resources can be released as soon as possible, performance issues such as system freezes can be eliminated, and system fluency can be improved.

[0161] This application also provides an embodiment, please refer to the attached Figure 3 .

[0162] Figure 3 It is a detailed step flow chart of a task scheduling method according to an embodiment of the present application, including the following steps S301 to S309.

[0163] Step S301, the target task accesses the shared resource;

[0164] Step S302, determining whether the shared resource is held by other tasks; if so, executing step S303; if not, the task scheduling ends;

[0165] Step S303, establishing a resource dependency chain;

[0166] Step S304, determining whether the resource dependency chain has priority flipping; if so, executing step S305; if not, the task scheduling ends;

[0167] Step S305, searching for the initial importance level based on the initial importance level table;

[0168] Step S306, determining whether there is a task whose initial importance level is greater than the second-to-last level; if so, executing step S307; if not, the task scheduling ends;

[0169] Step S307, obtaining the importance level of each layer of tasks from bottom to top along the resource dependency chain;

[0170] Step S308, scheduling the top-level task of the resource dependency chain;

[0171] Step S309, releasing resources.

[0172] After the tasks on the resource dependency chain release resources, task scheduling ends.

[0173] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art can understand that in order to achieve the effect of the present application, different steps do not have to be executed in such an order. They can be executed simultaneously (in parallel) or in other orders. These changes are within the scope of protection of the present application.

[0174] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0175] Furthermore, the present application also provides a computer-readable storage medium. In a computer-readable storage medium embodiment according to the present application, the computer-readable storage medium may be configured to store a program for executing the task scheduling method of the above method embodiment. The program may be loaded and run by a processor to implement the above task scheduling method.

[0176] For ease of explanation, only the parts related to the embodiments of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiments of the present application. The computer-readable storage medium can be a storage device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiments of the present application is a non-temporary computer-readable storage medium.

[0177] Another aspect of the present application also provides a smart device, see the attached Figure 4 , Figure 4 It is a main structural block diagram of an intelligent device used to execute the task scheduling method of the present application.

[0178] like Figure 4 As shown, the smart device 400 may include at least one processor 401; and a memory 402 that is communicatively connected to the at least one processor 401; wherein the memory 402 stores a computer program 403, and when the computer program 403 is executed by the at least one processor 401, the method described in any of the above embodiments is implemented.

[0179] The smart device described in the present application may be a terminal device such as a smart phone, a wearable device, a tablet computer, a desktop computer, a laptop computer, a PDA, etc. Exemplarily, the memory 402 and the processor 401 are connected in communication via a bus.

[0180] In some embodiments of the present application, the smart device further includes at least one sensor for sensing information. The sensor is communicatively connected to any type of processor mentioned in the present application. Exemplarily, the sensor may be a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.

[0181] Exemplarily, the processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0182] The memory 402 may be an internal storage unit of the smart device 400, for example, a hard disk or memory of the smart device 400; the memory 402 may also be an external storage device of the smart device 400, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the smart device 400. Further, the memory 402 may also include both an internal storage unit of the smart device 400 and an external storage device. The memory 402 is used to store computer programs and other programs and data required by the smart device 400. The memory 402 may also be used to temporarily store data that has been output or is to be output.

[0183] In some possible implementations, the smart device 400 may include multiple processors 401 and memories 402. The computer program 403 for executing the task scheduling method of the above method embodiment may be divided into multiple subprograms, each of which may be loaded and run by the processor 401 to execute different steps of the task scheduling method of the above method embodiment. Specifically, each subprogram may be stored in different memories 402, and each processor 401 may be configured to execute programs in one or more memories 402 to jointly implement the task scheduling method of the above method embodiment, that is, each processor 401 executes different steps of the task scheduling method of the above method embodiment to jointly implement the task scheduling method of the above method embodiment.

[0184] The above-mentioned multiple processors 401 may be processors deployed on the same device. For example, the above-mentioned smart device may be a high-performance device composed of multiple processors, and the above-mentioned multiple processors 401 may be processors configured on the high-performance device. In addition, the above-mentioned multiple processors 401 may also be processors deployed on different devices. For example, the above-mentioned smart device may be a server cluster, and the above-mentioned multiple processors 401 may be processors on different servers in the server cluster.

[0185] The smart device 400 may be a terminal device, a cloud server, or other smart device as described above. The smart device 400 may include, but is not limited to, a processor 401 and a memory 402. Those skilled in the art will appreciate that Figure 4 It is only an example of the smart device 400 and does not constitute a limitation of the smart device 400. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the smart device may also include input and output devices, network access devices, buses, etc.

[0186] The software system of the terminal device using the resource adjustment method can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to illustrate the software structure of the smart device.

[0187] Please refer to the attached Figure 5 , Figure 5 It is a software structure diagram of a smart device in one embodiment of the present application.

[0188] like Figure 5 As shown, in the embodiment of the present application, the Android system includes an application layer, an application framework layer, a native library layer and a kernel layer from top to bottom.

[0189] The application layer may include a series of application packages. The application package may include system applications. Among them, system applications refer to applications set in the electronic device before leaving the factory. Exemplary, system applications may include programs such as camera, gallery, calendar, map, music, short message and call. The application package may also include third-party applications, which refer to applications that users install after downloading the installation package from the application store (or application market).

[0190] The application layer in this embodiment includes: home screen (Home), dialer (Dialer), instant messaging (IM), browser (Browser), camera (Camera), alarm clock (Alarm), address book (Contacts), voice dial (Voice Dial), email (Email), calendar (Calendar), album (Albums) and other applications. At the application layer, the tasks waiting for CPU execution are classified based on the control group.

[0191] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions. The application framework layer may include a window manager, a content provider, a phone manager, a notification manager, a view system, a resource manager, a display decision module, and a camera decision module. The resource manager includes preset control group classification information such as top tasks, foreground tasks, and background tasks.

[0192] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0193] The native library layer includes native libraries used by the Android system, some of which are written in C / C++. These libraries provide some underlying system functions, such as graphics processing, audio processing, etc. They work with the Java virtual machine to provide underlying support for the Android system. The native library layer in Android also includes runtime libraries (RuntimeLibraries), such as libbionic, which are used to provide support for standard C library functions. This embodiment also includes a custom Libprocess_group to provide support for operation grouping information.

[0194] The kernel layer is at the bottom of the Android system. The Android kernel is a variant of the Linux kernel and also belongs to the software layer. The kernel is responsible for managing hardware resources, handling interrupts, providing process scheduling, file system management and other core operating system functions.

[0195] In this embodiment, the kernel layer includes mutex locks, read-write locks, and other types of lock mechanisms; a priority inversion processing module for implementing dependency chain management, priority strategy, scheduling strategy, and function instrumentation; and a scheduler module for implementing task scheduling.

[0196] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0197] Those skilled in the art will appreciate that the units and algorithm steps of each example described in the embodiments of the present application can be implemented with electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.

[0198] In the embodiments provided in the present application, it should be understood that the disclosed electronic devices and methods can be implemented in other ways. For example, the electronic device embodiments described above are only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. Multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0199] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0200] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0201] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.

[0202] The relevant user personal information that may be involved in the various embodiments of this application is strictly in accordance with the requirements of laws and regulations, following the principles of legality, legitimacy and necessity, based on the reasonable purposes of business scenarios, to process the personal information that users actively provide during the use of products / services or generated due to the use of products / services, as well as the personal information obtained with the user's authorization.

[0203] The user personal information processed by this application will vary depending on the specific product / service scenario, and shall be based on the specific scenario in which the user uses the product / service, and may involve the user's account information, device information, driving information, vehicle information or other related information. This application will treat the user's personal information and its processing with a high degree of diligence.

[0204] This application attaches great importance to the security of user personal information and has taken reasonable and feasible security protection measures that meet industry standards to protect user information and prevent personal information from being accessed, disclosed, used, modified, damaged or lost without authorization.

[0205] So far, the technical solution of the present application has been described in conjunction with the preferred embodiments shown in the accompanying drawings.

[0206] It is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific implementations. Without departing from the principles of the present application, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present application.

Claims

1. A task scheduling method, It is characterized in that include: In response to a shared resource that the target task is waiting to access being held by other tasks, the tasks waiting for CPU execution are arranged in a chain according to the waiting resources and held resources of the tasks to establish a resource dependency chain; Task scheduling is performed based on the resource dependency chain.

2. The method according to claim 1, It is characterized in that The step of linking and sorting the tasks waiting for the CPU to run according to the waiting resources and the held resources of the tasks to establish a resource dependency chain includes: S1, taking the target task as the bottom task of the resource dependency chain, and obtaining the waiting resources of the bottom task; S2, obtaining a task at an upper layer, wherein the holding resource of the task at an upper layer is the same as the waiting resource of the task at an underlying layer; S3, obtaining the waiting resources of the upper layer task; S4. Replace the bottom-level task in step S2 with the n-th-level task, replace the upper-level task in step S2 and step S3 with the n-1-th-level task, and execute step S2-step S3 in a loop, obtaining each layer of tasks on the resource dependency chain layer by layer, until a task that does not need to wait for resources is obtained, and the task that does not need to wait for resources is the top-level task of the resource dependency chain; wherein n is a positive integer greater than 1.

3. The method according to claim 2, It is characterized in that The performing task scheduling based on the resource dependency chain includes: Obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler; Determining whether priority flipping occurs in the resource dependency chain based on the acquired priority; If no priority inversion occurs, performing task scheduling based on the resource dependency chain; If a priority reversal occurs, the importance level of each layer of the task on the resource dependency chain is obtained, and the task scheduling is performed based on the resource dependency chain and the importance level.

4. The method according to claim 3, It is characterized in that The obtaining of the importance level of each layer of the task on the resource dependency chain includes: Classify tasks waiting for CPU execution based on control groups at the application layer; Obtaining the initial importance level of each layer of tasks on the resource dependency chain based on the control group classification of the tasks; Based on the initial importance level, the importance level of the tasks at each layer is obtained.

5. The method according to claim 4, It is characterized in that The classifying of tasks waiting for CPU execution based on control groups at the application layer includes: The tasks waiting for CPU execution are divided into different control groups based on the visibility of the tasks. The control groups include at least top tasks, foreground tasks and background tasks.

6. The method according to claim 5, It is characterized in that The task-based control group classification obtains the initial importance level of each layer of the task on the resource dependency chain, including: In the resource dependency chain, based on the control groups to which the tasks in two adjacent layers belong respectively, the initial importance level of the upper layer task is obtained; wherein, the greater the initial importance level of the task, the lower its importance: When the upper-layer task is a background task and the lower-layer task is a top task or a foreground task, the initial importance level of the upper-layer task is 1 or 2 respectively; When the upper-layer task is a foreground task and the lower-layer task is a top task or a background task, the initial importance level of the upper-layer task is level 3 or level 4 respectively; When the upper-layer task is a top task and the lower-layer task is a foreground task or a background task, the initial importance level of the upper-layer task is level 5 or level 6, respectively.

7. The method according to claim 4, It is characterized in that The obtaining the importance level of each layer of tasks based on the initial importance level includes: In the resource dependency chain of layer m, based on the initial importance level of the tasks of layer m-1, search upward along the resource dependency chain to determine whether there is a task with an initial importance level greater than that of layer m-1; If not, the initial importance level of each layer of the task on the resource dependency chain is used as the importance level; If it exists, obtain the k-th layer task whose initial importance level is greater than the m-1-th layer, and obtain the importance level based on the initial importance level of the k-th layer task; The importance level of each layer of tasks is obtained from bottom to top along the resource dependency chain, wherein the importance level of the upper layer tasks is not greater than that of the lower layer tasks; wherein m is a positive integer greater than 1; when obtaining the kth layer task, k is a positive integer, and m-1>k.

8. The method according to any one of claims 4 to 7, It is characterized in that After obtaining the importance levels of the tasks at each layer, the method further includes: Get multiple resource dependency chains based on the tasks waiting for the CPU to run; Obtain the importance level of the top-level tasks of each resource dependency chain respectively; Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.

9. The method according to claim 8, It is characterized in that The task scheduling based on the importance level of the top-level tasks of each resource dependency chain includes: Obtain the resource dependency chain with the smallest importance level of the top-level task in each resource dependency chain; Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.

10. The method according to any one of claims 1 to 7, It is characterized in that The task scheduling based on the resource dependency chain includes: A completely fair scheduling algorithm is used for task scheduling.