Task scheduling method, storage medium, and intelligent device
By establishing a resource dependency chain and scheduling based on a fully fair scheduling algorithm, the poor performance problem caused by priority flip in the task scheduling process is solved, and system fluency and performance improvement is achieved.
Patent Information
- Application Number
- PCT/CN2024/127022
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-06
- Filing Date
- 2024-10-24
- Publication Date
- 2025-06-12
AI Technical Summary
The prior art lacks an effective solution mechanism when dealing with priority flip problems in task scheduling, resulting in poor performance.
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 a completely fair scheduling algorithm. If priority flip occurs, the resource dependency level of the task on each layer of the chain is scheduled to release resources as soon as possible.
This greatly reduces the possibility of priority flip during task scheduling, improves system fluency, and eliminates performance problems such as system lag.
Smart Images

Figure CN2024127022_12062025_PF_FP_ABST
Abstract
Description
Task scheduling method, storage medium and intelligent device
[0001] This application claims priority to Chinese patent application No. 202311672200.7, filed on December 6, 2023, with the invention name “Task Scheduling Method, Storage Medium and Intelligent Device”. The entire contents of the above Chinese patent application are incorporated into this application by reference. Technical Field
[0002] The present application relates to the field of computer information processing technology, and specifically provides a task scheduling method, a storage medium, and an intelligent device. Background Art
[0003] In today's mobile device environment, the Android operating system, as a multi-tasking operating system, provides a variety of cross-process communication mechanisms. This inevitably leads to contention for shared resources between tasks. These 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.
[0004] 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.
[0005] However, this locking mechanism can lead to priority inversion. That is, when a low-priority task accesses a shared resource, the high-priority task may have to wait for the high-priority task to release the lock due to the lock protection. Currently, there is no effective and universal mechanism to effectively solve the priority inversion problem in the task scheduling process.
[0006] Accordingly, a new task scheduling solution is needed in this field to solve the above problems.
[0007] Summary of the Invention
[0008] 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 during task scheduling.
[0009] In a first aspect, the present application provides a task scheduling method, comprising:
[0010] 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;
[0011] Task scheduling is performed based on the resource dependency chain.
[0012] In one 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:
[0013] S1. Taking the target task as the bottom task of the resource dependency chain and obtaining the waiting resources of the bottom task;
[0014] S2. Obtain the upper-level task, where the held resources of the upper-level task are the same as the waiting resources of the lower-level task;
[0015] S3, obtaining the waiting resources of the upper layer task;
[0016] 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 steps S2-S3 in a loop, obtaining tasks of each level on the resource dependency chain layer by layer until a task that does not need to wait for resources is obtained. 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.
[0017] In a technical solution of the above task scheduling method, the task scheduling is performed using a completely fair scheduling algorithm based on the resource dependency chain, including:
[0018] Obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler;
[0019] Determining whether priority inversion occurs in the resource dependency chain based on the acquired priority;
[0020] If priority inversion does not occur, performing task scheduling based on the resource dependency chain;
[0021] If priority inversion occurs, the importance level of each layer of the task on the resource dependency chain is obtained, and task scheduling is performed based on the resource dependency chain and the importance level.
[0022] In one technical solution of the above task scheduling method, obtaining the importance level of each task in the resource dependency chain includes:
[0023] Classify tasks waiting for CPU execution based on control groups at the application layer;
[0024] Obtaining initial importance levels of tasks at each layer of the resource dependency chain based on the control group classification of the tasks;
[0025] Based on the initial importance level, the importance level of the tasks at each layer is obtained.
[0026] In one 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:
[0027] The tasks waiting for CPU execution are divided into different control groups based on task visibility. The control groups include at least top tasks, foreground tasks, and background tasks.
[0028] In one technical solution of the above task scheduling method, the task-based control group classification to obtain the initial importance level of each layer of the task in the resource dependency chain includes:
[0029] In the resource dependency chain, based on the control groups to which the tasks in two adjacent layers belong, the initial importance level of the upper layer task is obtained; wherein, the larger the initial importance level of a task, the lower its importance:
[0030] 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 level 1 or level 2 respectively;
[0031] 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;
[0032] When the upper-layer task is a top task and the lower-layer tasks are respectively foreground tasks or background tasks, the initial importance levels of the upper-layer tasks are respectively level 5 or level 6.
[0033] 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:
[0034] In the resource dependency chain of layer m, based on the initial importance level of the tasks in 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;
[0035] If it does not exist, the initial importance level of each layer of the task in the resource dependency chain is used as the importance level;
[0036] 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;
[0037] 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 k-th layer task, k is a positive integer, and m-1>k.
[0038] In one technical solution of the above task scheduling method, after obtaining the importance levels of the tasks at each layer, the method further includes:
[0039] Get multiple resource dependency chains based on tasks waiting for CPU execution;
[0040] Obtain the importance level of the top-level tasks of each resource dependency chain respectively;
[0041] Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.
[0042] In one technical solution of the above task scheduling method, the task scheduling based on the importance level of the top-level tasks of each resource dependency chain includes:
[0043] Obtain the resource dependency chain with the lowest importance level of the top-level task in each resource dependency chain;
[0044] Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.
[0045] In a technical solution of the above task scheduling method, the task scheduling based on the resource dependency chain includes:
[0046] A completely fair scheduling algorithm is used for task scheduling.
[0047] 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.
[0048] In a third aspect, the present application provides a smart device, comprising:
[0049] at least one processor;
[0050] and, a memory communicatively coupled to the at least one processor;
[0051] 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.
[0052] The above one or more technical solutions of this application have at least one or more of the following beneficial effects:
[0053] In implementing the technical solution of 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, task scheduling is performed by further considering the importance level of tasks at each layer on the resource dependency chain, which can release resources as soon as possible, eliminate performance issues such as system freezes, and improve system smoothness. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The disclosure of this application will be more easily understood with reference to the accompanying drawings. Those skilled in the art will readily appreciate that these drawings are for illustrative purposes only and are not intended to limit the scope of protection of this application. Furthermore, similar numbers in the figures represent similar components, where:
[0055] FIG1 is a schematic diagram of the main steps of a task scheduling method according to an embodiment of the present application;
[0056] FIG2 is a flowchart of the detailed steps of task scheduling based on the resource dependency chain in this application;
[0057] FIG3 is a flowchart of the detailed steps of a task scheduling method according to an embodiment of the present application;
[0058] FIG4 is a main structural block diagram of an intelligent device for executing the task scheduling method of the present application;
[0059] FIG5 is a diagram of a software structure of a smart device in one embodiment of the present application. DETAILED DESCRIPTION
[0060] 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 scope of protection of the present application.
[0061] In the description of this application, "module" and "processor" may include hardware, software, or a combination of both. A module may include hardware circuitry, various suitable sensors, communication ports, and memory. It may also include software components, such as program code, or a combination of software and hardware. A processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. A processor has data and / or signal processing capabilities. A processor may be implemented in software, hardware, or a combination of both. Non-transitory computer-readable storage media include any suitable medium capable of storing program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, etc. The term "A and / or B" refers to all possible combinations of A and B, such as only A, only B, or both A and B. The terms "at least one of A or B" or "at least one of A and B" have similar meanings to "A and / or B" and may include only A, only B, or both A and B. The singular forms "a" and "the" may also include the plural forms.
[0062] 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 solutions involved in this application will be described using the Android system as an example.
[0063] Please refer to Figure 1, which is a schematic diagram of the main steps of a task scheduling method according to an embodiment of the present application. As shown in Figure 1, the task scheduling method according to the embodiment of the present application mainly includes the following steps S11 to S12.
[0064] Step S11 , 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.
[0065] In one embodiment of the present application, linking and sorting the tasks waiting for CPU execution according to their waiting resources and held resources to establish a resource dependency chain includes:
[0066] S1. Taking the target task as the bottom task of the resource dependency chain and obtaining the waiting resources of the bottom task;
[0067] S2. Obtain the upper-level task, where the held resources of the upper-level task are the same as the waiting resources of the lower-level task;
[0068] S3, obtaining the waiting resources of the upper layer task;
[0069] 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 steps S2-S3 in a loop, obtaining tasks of each level on the resource dependency chain layer by layer until a task that does not need to wait for resources is obtained. 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.
[0070] For example, if the waiting resource of the target task A3 is L2, it is used as the bottom task; the upper-layer task A2 is obtained, the holding resource of the upper-layer task A2 is L2, and the waiting resource L1 of the upper-layer task A2 is obtained; the above steps are repeated to obtain the task A1 that does not need to wait for resources, and its holding resource is L1; a resource dependency chain is established, the top-level task of the resource dependency chain is A1, the second-level task is A2, and the bottom-level task is A3.
[0071] Step S12: performing task scheduling based on the resource dependency chain.
[0072] In one embodiment of the present application, the performing task scheduling based on the resource dependency chain includes: performing task scheduling using a completely fair scheduling algorithm.
[0073] The Completely Fair Scheduler (CFS) is a scheduling algorithm in the Linux system. It provides each task with relatively fair CPU time by dynamically adjusting the virtual running time and weight of the task, so as to achieve fairness and balance in a multi-tasking environment.
[0074] In one embodiment of the present application, the task scheduling is performed based on the resource dependency chain, see FIG. 2 .
[0075] Figure 2 is a detailed flowchart of the steps for task scheduling based on the resource dependency chain in this application. As shown in Figure 2, it mainly includes the following steps S21 to S25.
[0076] Step S21 : obtaining the priorities of the bottom layer task and the upper layer task respectively based on the scheduler.
[0077] 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.
[0078] Step S22: determining whether priority inversion occurs in the resource dependency chain based on the obtained priority.
[0079] 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 task scheduling is based on the resource dependency chain, if a task in the upper layer of the resource dependency chain has a lower priority than a task in the lower layer, this is considered a priority flip. In this embodiment, whether a priority flip has occurred is determined by comparing the priorities of the bottom-level task and the task in the upper layer.
[0080] 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 scheduling based on the resource dependency chain, a completely fair scheduling algorithm is adopted.
[0081] If a priority reversal occurs, step S24 is executed to obtain the importance level of each layer of tasks in the resource dependency chain.
[0082] In one embodiment of the present application, obtaining the importance level of tasks at each layer in the resource dependency chain includes:
[0083] Classify tasks waiting for CPU execution based on control groups (cgroups) at the application layer;
[0084] Obtaining initial importance levels of tasks at each layer of the resource dependency chain based on the control group classification of the tasks;
[0085] Based on the initial importance level, the importance level of the tasks at each layer is obtained.
[0086] In one embodiment, classifying tasks waiting for CPU execution based on control groups at the application layer includes:
[0087] The tasks waiting for CPU execution are divided into different control groups based on task visibility. The control groups include at least top tasks, foreground tasks, and background tasks.
[0088] Among them, top tasks refer to services or applications that are operable, perceptible, and currently being interacted with by 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 the user, such as when a user switches out of the interface of a music app while listening to music (i.e., playing music in the background), the music app is a foreground task; background tasks refer to services or applications that are not operable or perceptible to the user, such as background logs.
[0089] The visibility of the tasks of the control group decreases in order of top task, foreground task, and background task.
[0090] In addition, those skilled in the art may also add other custom control group categories besides the top tasks, foreground tasks, and background tasks as needed, such as a control group related to a certain hardware feature.
[0091] Furthermore, the task-based control group classification obtains the initial importance level of each layer of tasks on the resource dependency chain, including:
[0092] In the resource dependency chain, the initial importance level of the upper-layer task is obtained based on the control groups to which the tasks in two adjacent layers belong respectively; wherein, the greater the initial importance level of a task, the lower its importance.
[0093] Please see the following initial importance ranking table, as shown in Table 1:
[0094]
[0095] Table 1
[0096] 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 level 1 or level 2 respectively;
[0097] 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;
[0098] When the upper-layer task is a top task and the lower-layer tasks are respectively foreground tasks or background tasks, the initial importance levels of the upper-layer tasks are respectively level 5 or level 6.
[0099] The initial importance levels gradually increase from level 1 to level 6, and their importance decreases in sequence.
[0100] Furthermore, in one embodiment, obtaining the importance level of each layer of tasks based on the initial importance level includes:
[0101] In the resource dependency chain of layer m, based on the initial importance level of the tasks in 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;
[0102] If it does not exist, the initial importance level of each layer of the task in the resource dependency chain is used as the importance level;
[0103] 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;
[0104] 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 k-th layer task, k is a positive integer, and m-1>k.
[0105] The number of reduction stages can be set as needed by those skilled in the art. For the same system, the step size of the number of reduction stages can be set to be consistent during the task scheduling process.
[0106] For example, 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 reduced level is set to 2, the importance level of the kth layer task is level 3.
[0107] Furthermore, when determining whether there are tasks with an initial importance level greater than that of the m-1th level, if two consecutive levels of tasks have the same initial importance level, the result is that no task exists. Therefore, the importance levels of tasks in the resource dependency chain may be consecutively the same. It is sufficient to ensure that the importance level of any upper-level task is no greater than that of the lower-level task.
[0108] 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 in the resource dependency chain, the importance level of the top-level task may be level 1 or greater than level 1.
[0109] After step S24 is completed, step S25 is continued to be executed to schedule tasks based on the resource dependency chain and the importance level.
[0110] In one embodiment, after obtaining the importance levels of the tasks at each layer, the method further includes:
[0111] Get multiple resource dependency chains based on tasks waiting for CPU execution;
[0112] Obtain the importance level of the top-level tasks of each resource dependency chain respectively;
[0113] Task scheduling is performed based on the importance level of the top-level tasks of each resource dependency chain.
[0114] Furthermore, the task scheduling based on the importance level of the top-level tasks of each resource dependency chain includes:
[0115] Obtain the resource dependency chain with the lowest importance level of the top-level task in each resource dependency chain;
[0116] Task migration is performed on the top-level task of the acquired resource dependency chain to accelerate the release of resources.
[0117] Specifically, the task migration path can be determined based on a 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.
[0118] Among them, since the top 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 resource holding task.
[0119] The task scheduling ends when the target task releases resources.
[0120] 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 reversal during task scheduling is greatly reduced; for possible priority reversals, 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 smoothness can be improved.
[0121] This application also provides an embodiment, please refer to Figure 3.
[0122] FIG3 is a detailed flowchart of a task scheduling method according to an embodiment of the present application, including the following steps S301 to S309 .
[0123] Step S301, the target task accesses the shared resource;
[0124] Step S302, determining whether the shared resource is held by other tasks; if so, executing step S303; if not, the task scheduling ends;
[0125] Step S303: establishing a resource dependency chain;
[0126] Step S304, determining whether priority flipping occurs in the resource dependency chain; if so, executing step S305; if not, the task scheduling ends;
[0127] Step S305, searching for the initial importance level based on the initial importance level table;
[0128] Step S306, determining whether there is a task with an initial importance level greater than the second-to-last level; if so, executing step S307; if not, the task scheduling ends;
[0129] Step S307, obtaining the importance level of each layer of tasks from bottom to top along the resource dependency chain;
[0130] Step S308, scheduling the top-level task of the resource dependency chain;
[0131] Step S309: Release resources.
[0132] After the tasks on the resource dependency chain release resources, task scheduling ends.
[0133] 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 will understand that in order to achieve the effect of the present application, different steps do not have to be performed in such an order. They can be performed simultaneously (in parallel) or in other orders. These changes are within the scope of protection of the present application.
[0134] All of the above optional technical solutions can be combined in any way to form optional embodiments of the present application, and will not be described in detail here.
[0135] Furthermore, the present application also provides a computer-readable storage medium. In one embodiment of the computer-readable storage medium 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-described method embodiment. The program may be loaded and executed by a processor to implement the above-described task scheduling method.
[0136] 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 section 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-transitory computer-readable storage medium.
[0137] Another aspect of the present application further provides an intelligent device. Please refer to Figure 4, which is a main structural block diagram of the intelligent device used to execute the task scheduling method of the present application.
[0138] As shown in Figure 4, 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, it implements the method described in any of the above embodiments.
[0139] The smart device described in this application can 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 to each other via a bus communication.
[0140] 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. For example, 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.
[0141] Illustratively, 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 any conventional processor, etc.
[0142] Memory 402 can be an internal storage unit of smart device 400, such as a hard drive or memory of smart device 400. Memory 402 can also be an external storage device of smart device 400, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped on smart device 400. Furthermore, memory 402 can include both an internal storage unit of smart device 400 and an external storage device. Memory 402 is used to store computer programs and other programs and data required by smart device 400. Memory 402 can also be used to temporarily store data that has been output or is about to be output.
[0143] 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 subroutines, 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 subroutine may be stored in a different memory 402, and each processor 401 may be configured to execute the program 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.
[0144] The multiple processors 401 may be processors deployed on the same device. For example, the smart device may be a high-performance device composed of multiple processors, and the multiple processors 401 may be processors configured on the high-performance device. Furthermore, the multiple processors 401 may be processors deployed on different devices. For example, the smart device may be a server cluster, and the multiple processors 401 may be processors on different servers in the server cluster.
[0145] Smart device 400 may be any of the aforementioned terminal devices and cloud servers. 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 FIG4 is merely an example of smart device 400 and does not limit smart device 400. Smart device 400 may include more or fewer components than shown, or a combination of certain components, or different components. For example, a smart device may also include input / output devices, network access devices, buses, and the like.
[0146] The software system of the terminal device applying the resource adjustment method can adopt a layered architecture, an event-driven architecture, a micro-kernel 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.
[0147] Please refer to FIG5 , which is a software structure diagram of a smart device in one embodiment of the present application.
[0148] As shown in FIG5 , in the embodiment of the present application, the Android system includes, from top to bottom, an application layer, an application framework layer, a native library layer, and a kernel layer.
[0149] The application layer can include a series of application packages. Application packages can include system applications. System applications refer to applications that are installed in the electronic device before leaving the factory. For example, system applications may include programs such as camera, gallery, calendar, map, music, short message, and call. Application packages can also include third-party applications, which are applications that users install by downloading the installation package from an application store (or application market).
[0150] In this embodiment, the application layer includes applications such as Home, Dialer, Instant Messenger (IM), Browser, Camera, Alarm, Contacts, Voice Dial, Email, Calendar, and Albums. At the application layer, tasks waiting for CPU execution are categorized based on control groups.
[0151] The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes predefined functions. The application framework layer can include a window manager, content provider, telephony manager, notification manager, view system, resource manager, display decision module, and camera decision module. The resource manager includes predefined control group classification information, such as top tasks, foreground tasks, and background tasks.
[0152] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine performs functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0153] 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 and audio processing. 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 (Runtime Libraries), 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 group information.
[0154] The kernel layer is the lowest layer 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.
[0155] 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.
[0156] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0157] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments of this 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 this application.
[0158] In the embodiments provided in this 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 merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. Multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, which may be electrical, mechanical or other forms.
[0159] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0160] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0161] 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 process 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 when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. The computer program may include computer program code, which 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, USB flash drive, 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, computer-readable media do not include electric carrier signals and telecommunication signals.
[0162] 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, and 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.
[0163] The user personal information processed by this application will vary depending on the specific product / service scenario and must be based on the specific scenario in which the user uses the product / service. This 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.
[0164] This application attaches great importance to the security of user personal information and has taken reasonable and feasible security protection measures that comply with industry standards to protect user information and prevent personal information from being accessed, disclosed, used, modified, damaged or lost without authorization.
[0165] So far, the technical solution of the present application has been described in conjunction with the preferred embodiments shown in the accompanying drawings.
[0166] It is easy for those skilled in the art to understand that the scope of protection of this application is obviously not limited to these specific embodiments. Without departing from the principles of this application, those skilled in the art may make equivalent changes or substitutions to the relevant technical features, and the technical solutions after such changes or substitutions will fall within the scope of protection of this application.
Claims
1. A task scheduling method, 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, 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, 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, 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, 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, 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, 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, get the kth layer whose initial importance level is greater than the m-1th layer Tasks, based on the initial importance level of the k-th layer tasks, are reduced to obtain importance levels; 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, 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, 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, characterized in that The task scheduling based on the resource dependency chain includes: A completely fair scheduling algorithm is used for task scheduling.
11. A computer-readable storage medium storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by a processor to execute the task scheduling method according to any one of claims 1 to 10.
12. A smart device, characterized in that: include: at least one processor; and, a memory communicatively coupled to the at least one processor; The memory stores a computer program, and when the computer program is executed by the at least one processor, the task scheduling method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Shared resource access method and device
CN111506438A
Method and device for dynamically adjusting priority
CN114510327A
Task exclusive control method and task exclusive control device
JP2004127039A
Hand-off scheduling
US20160357600A1