Task scheduling method and device, terminal equipment and storage medium

By setting up a task scheduling queue in the terminal device, foreground tasks are processed first according to the execution priority of task type and queue order, which solves the problem of excessive latency of foreground tasks when the terminal device is under high load of background tasks, and improves the smoothness of the system.

CN114489986BActive Publication Date: 2026-02-03HUIZHOU TCL MOBILE COMM CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210099278.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-25
Publication Date
2026-02-03
Estimated Expiration
2042-01-25

AI Technical Summary

Technical Problem

When the terminal device is under high load of background tasks, the latency of the tasks waiting to be executed in the foreground is too high, causing the system to lag.

Method used

By setting up several task scheduling queues, based on the execution priority of task type and queue scheduling order, foreground tasks to be executed are prioritized and scheduled to the task execution queue. The queue depth and target number of tasks to be executed are controlled, and tasks are processed in a FIFO manner.

Benefits of technology

It effectively reduces the latency of tasks waiting to be executed in the foreground, improves system smoothness, and avoids the possibility of excessive latency in foreground tasks when the background tasks are under high load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114489986B_ABST
    Figure CN114489986B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a task scheduling method and device, terminal equipment and storage medium. A plurality of task scheduling queues for storing to-be-executed tasks can be set. When a terminal generates a to-be-executed task, the to-be-executed task is stored in a task scheduling queue first. The terminal determines a queue scheduling order of each task scheduling queue according to an execution priority level of a task type of the to-be-executed task when scheduling the to-be-executed task to a task execution queue, thereby avoiding queuing and executing each to-be-executed task in the task execution queue according to the generation order of the to-be-executed task, and determining the arrangement order of to-be-executed tasks of various task types in the task execution queue according to the queue scheduling order. When the to-be-executed tasks that can be added to the task execution queue, the terminal can preferentially add a foreground to-be-executed task generated by the terminal and user interaction to the task execution queue, so that the terminal can preferentially process the foreground to-be-executed task, and effectively reduce the processing delay of the foreground to-be-executed task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, specifically to a task scheduling method, apparatus, terminal device, and storage medium. Background Technology

[0002] During operation, a terminal generates multiple I / O (Input / Output) tasks. To ensure that these tasks are executed in an orderly manner, the terminal's memory (such as EMMC 5.1, UFS, etc.) can have a Native Command Queue (NCQ) to store the tasks to be executed. The NCQ allows multiple tasks to be executed simultaneously on the device. Therefore, when background applications are downloading or installing, there will be a large number of background tasks waiting in the NCQ. Meanwhile, foreground tasks generated by user interaction are queued after the background tasks in the NCQ. This can lead to excessive latency in foreground tasks when the background tasks are under high load, causing system lag. Summary of the Invention

[0003] This application provides a task scheduling method, apparatus, terminal device, and storage medium, which can effectively control the latency of tasks to be executed on the terminal, reduce the possibility of excessive latency of tasks to be executed in the foreground when there is a high load of background tasks, and improve system smoothness.

[0004] This application provides a task scheduling method, including:

[0005] Obtain several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed;

[0006] Based on the execution priority level of each task type, determine the queue scheduling order of each task scheduling queue when scheduling tasks to be executed into the task execution queue;

[0007] Obtain a task execution queue, the task execution queue including tasks to be executed extracted from the task scheduling queue;

[0008] If the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue, calculate the target number of tasks that can be added to the task execution queue.

[0009] Based on the queue scheduling order and the target quantity, select tasks to be executed from the task scheduling queue and add them to the task execution queue;

[0010] Retrieve tasks to be executed from the task execution queue and process them.

[0011] Accordingly, embodiments of this application also provide a task scheduling device, including:

[0012] The scheduling queue acquisition unit is used to acquire several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed.

[0013] The scheduling order determination unit is used to determine the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of each task type.

[0014] An execution queue acquisition unit is used to acquire a task execution queue, wherein the task execution queue includes tasks to be executed extracted from the task scheduling queue;

[0015] The calculation unit is used to calculate the target number of tasks that can be added to the task execution queue when the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue.

[0016] The selection unit is used to select tasks to be executed from the task scheduling queue and add them to the task execution queue according to the queue scheduling order and the target quantity;

[0017] The processing unit is used to retrieve tasks to be executed from the task execution queue and process them.

[0018] Optionally, the scheduling queue acquisition unit is further configured to:

[0019] Create the task scheduling queues described above;

[0020] When the terminal generates the task to be executed, the task type of the task to be executed is determined;

[0021] Based on the task type of the task to be executed, the generated task to be executed is stored in the corresponding task scheduling queue.

[0022] Optionally, the selection unit is further configured to:

[0023] According to the queue scheduling order and the target number, tasks to be executed are selected from at least one task scheduling queue, wherein the number of tasks to be executed selected from each task scheduling queue does not exceed the maximum number of tasks extracted in a single time corresponding to the task scheduling queue, and the total number of all selected tasks to be executed does not exceed the target number.

[0024] The selected tasks to be executed are extracted from the task scheduling queue and added to the task execution queue.

[0025] Optionally, the selection unit is further configured to:

[0026] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0027] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the target number of tasks to be executed is selected from the current task scheduling queue as the selected tasks to be executed.

[0028] If the target number exceeds the maximum number of tasks that can be extracted at one time in the current task scheduling queue, and the sum of the number of tasks that have been extracted from the current task scheduling queue to the task execution queue and the target number exceeds the maximum number of tasks that can be extracted in the current task scheduling queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0029] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks already extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the step of selecting the target number of tasks to be executed from the current task scheduling queue continues until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0030] Optionally, the selection unit is further configured to:

[0031] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0032] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, calculate the first difference between the number of tasks in existence in the current task scheduling queue and the maximum number of tasks in existence. Determine the smaller value from the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue, and use the next task scheduling queue as the current task scheduling queue according to the queue scheduling order.

[0033] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks that have been extracted from the current task scheduling queue to the task execution queue is greater than or equal to the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0034] Obtain a second difference between the target quantity and the extracted quantity, and update the target quantity to the second difference;

[0035] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks currently in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks currently in existence that can be extracted from the current task scheduling queue to the task execution queue, calculate a first difference between the number of tasks currently in existence in the current task scheduling queue and the maximum number of tasks currently in existence. Determine the smaller value between the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue. Continue the process of using the next task scheduling queue as the current task scheduling queue according to the queue scheduling order until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0036] Optionally, the device is also used for:

[0037] The actual processing delay of each of the tasks to be executed is detected, wherein the actual processing delay is the difference between the time when the task to be executed is added to the task scheduling queue and the time when the task to be executed is completed;

[0038] Obtain the expected processing latency for each task scheduling queue;

[0039] Update the maximum number of tasks in each task scheduling queue based on the actual processing delay and the expected processing delay.

[0040] Optionally, the device is also used for:

[0041] Set the maximum processing delay of each task scheduling queue according to the expected processing delay of each task scheduling queue;

[0042] Determine the number of timeout tasks corresponding to each of the scheduling task queues in the latest monitoring period. The timeout task is a task whose actual processing delay exceeds the maximum processing delay of the scheduling task queue.

[0043] Determine the target task scheduling queue with an execution priority level greater than the preset level;

[0044] If the ratio of the number of tasks in the target scheduling task queue to the total number of all pending tasks from the target scheduling task queue that have been processed and completed in the latest monitoring period exceeds a preset maximum ratio, then the maximum number of tasks in storage corresponding to the target task scheduling queue is increased, wherein the increased maximum number of tasks in storage does not exceed the maximum number of tasks extracted in a single instance corresponding to the target task scheduling queue.

[0045] Similarly, embodiments of this application also provide a terminal device, including:

[0046] Memory, used to store computer programs;

[0047] A processor for performing any of the steps of the task scheduling method.

[0048] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the steps of the task scheduling method.

[0049] This application provides a task scheduling method, apparatus, terminal device, and storage medium. It can set up several task scheduling queues to store tasks to be executed. When a terminal generates a task to be executed, it first stores it in the task scheduling queue. The terminal determines the queue scheduling order of the task scheduling queues based on the execution priority level of the task type. This avoids queuing tasks in the task execution queue according to their generation order, instead determining the order of various task types in the task execution queue based on the queue scheduling order. When there are available tasks to be executed in the task execution queue, foreground tasks generated by the terminal's interaction with the user can be added first, allowing the terminal to prioritize processing foreground tasks. This effectively reduces the processing latency of foreground tasks, lowers the possibility of excessive latency in foreground tasks when there is a high load of background tasks, and improves system smoothness. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings required in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 This is a system schematic diagram of the task scheduling device provided in the embodiments of this application;

[0052] Figure 2 This is a flowchart illustrating the task scheduling method provided in an embodiment of this application;

[0053] Figure 3 This is a schematic diagram of the structure of the task scheduling device provided in the embodiments of this application;

[0054] Figure 4 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0055] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0056] This application provides a task scheduling method, apparatus, terminal device, and storage medium. Specifically, the task scheduling method of this application can be executed by a terminal device, which can be a terminal or a server, etc. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), etc. The terminal can also include a client, which can be a game application client, a browser client carrying a game program, or an instant messaging client, etc. The server can be an independent physical server, a server cluster composed of multiple physical servers, or a distributed system. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network services, and big data and artificial intelligence platforms.

[0057] Please see Figure 1 , Figure 1 This is a schematic diagram of a task scheduling device provided in an embodiment of this application. The system may include at least one terminal, which is used to acquire several task scheduling queues of its own. Each task scheduling queue corresponds to storing tasks of a certain type to be executed in the terminal, and different task scheduling queues store tasks of different types. Based on the execution priority level of each task type, the system determines the queue scheduling order of each task scheduling queue when scheduling tasks to be executed into the task execution queue. The system acquires the task execution queue, which includes tasks to be executed extracted from the task scheduling queue. If the current queue depth of the task execution queue is less than the maximum queue depth, the system calculates the target number of tasks to be executed that can be added to the task execution queue. Based on the queue scheduling order and the target number, the system selects tasks to be executed from the task scheduling queue and adds them to the task execution queue. Finally, the system retrieves tasks to be executed from the task execution queue for processing.

[0058] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.

[0059] This embodiment will be described from the perspective of a task scheduling device, which can be integrated into a terminal device, such as a smartphone, laptop, tablet, or personal computer.

[0060] This application provides a task scheduling method, which can be executed by the processor of a terminal, such as... Figure 2As shown, the specific process of this task scheduling method mainly includes steps 201 to 206, which are explained in detail below:

[0061] Step 201: Obtain several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed.

[0062] In the embodiments of this application, a task refers to a basic work element completed by the terminal, which is one or more instruction sequences processed by a program or a set of programs. For example, a terminal's read task, write task, etc. A task to be executed refers to a task that the terminal has not yet completed.

[0063] In the embodiments of this application, the task type of the task to be executed can be divided according to factors such as the source of the task and the purpose of the task. For example, the source of the task to be executed on the terminal can be a foreground task generated by the user interacting with the terminal, or a background task processed by a program in the terminal that is not directly accessible to the user. The task to be executed can be divided into read tasks and write tasks according to the different purposes of reading or writing data.

[0064] In this embodiment of the application, it is necessary to pre-create a task scheduling queue. Specifically, before "obtaining several task scheduling queues of this terminal" in step 201 above, the following steps are also included:

[0065] Create the task scheduling queues described above;

[0066] When the terminal generates the task to be executed, the task type of the task to be executed is determined;

[0067] Based on the task type of the task to be executed, the generated task to be executed is stored in the corresponding task scheduling queue.

[0068] In this embodiment of the application, when creating a task scheduling queue, a task scheduling queue can be set up to store tasks to be executed for a specific task type. For example, a task scheduling queue can be created to store foreground read tasks, a task scheduling queue can be created to store foreground write tasks, a task scheduling queue can be created to store background read tasks, and a task scheduling queue can be created to store background write tasks, etc. When a foreground read task is generated, the generated foreground read task is stored in the task scheduling queue used to store foreground read tasks.

[0069] In this embodiment of the application, in order to control the queue depth of each task scheduling queue, a maximum queue depth can be set for each task scheduling queue, thereby determining whether a generated task to be executed can be immediately added to the corresponding task scheduling queue. The above step "storing the generated task to be executed to the corresponding task scheduling queue according to the task type of the task to be executed" includes:

[0070] Based on the task type of the task to be executed, determine the target task scheduling queue corresponding to the generated task to be executed;

[0071] Based on the number of tasks to be executed already stored in the target task scheduling queue, it is determined that the current queue depth of the target task scheduling queue is less than the maximum queue depth of the target task scheduling queue.

[0072] The generated tasks to be executed are stored in the corresponding target task scheduling queue.

[0073] In one embodiment of this application, the task scheduling queue adopts a FIFO (First Input First Output) scheduling method to process the stored tasks to be executed. That is, when extracting tasks to be executed from the task scheduling queue and adding them to the task execution queue, the tasks to be executed that entered the task scheduling queue first are extracted and added to the task execution queue.

[0074] Step 202: Determine the queue scheduling order of each task scheduling queue when scheduling the tasks to be executed into the task execution queue according to the execution priority level of each task type.

[0075] In this embodiment of the application, since foreground tasks are tasks generated through user interaction, in order to avoid users waiting too long for task processing, the execution priority of foreground tasks can be set to be higher and the execution priority of background tasks to be lower.

[0076] In this embodiment, to ensure that tasks with higher execution priority are retrieved from the task execution queue for execution first, and given that the task execution queue operates on a first-in, first-out (FIFO) mechanism, tasks with higher execution priority need to be added to the task execution queue first. Therefore, when scheduling tasks to be executed into the task execution queue, the process can be configured such that tasks are first retrieved from the task scheduling queue storing tasks with higher execution priority and added to the task execution queue, and then tasks are retrieved from the task scheduling queue storing tasks with lower execution priority and added to the task execution queue. In other words, the queue scheduling order is the order in which tasks are retrieved from different task scheduling queues.

[0077] Step 203: Obtain the task execution queue, which includes tasks to be executed extracted from the task scheduling queue.

[0078] In this embodiment of the application, the task execution queue is the command queue NCQ (Native Command Queue) in the terminal's memory (such as EMMC 5.1, UFS, etc.), which is used to store tasks to be executed generated by the terminal. The NCQ allows multiple tasks to be executed to be queued at the device at the same time, and the terminal processes them in sequence according to the order of arrangement.

[0079] Step 204: If the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue, calculate the target number of tasks that can be added to the task execution queue.

[0080] In this embodiment, the queue depth is the number of tasks waiting to be processed in the task execution queue. The current queue depth is the current number of tasks waiting to be processed in the task execution queue, and the maximum queue depth is the maximum number of tasks that can be stored in the task execution queue. Furthermore, the target number is the difference between the maximum queue depth and the current queue depth.

[0081] Step 205: Select tasks to be executed from the task scheduling queue and add them to the task execution queue according to the queue scheduling order and the target quantity.

[0082] In this embodiment of the application, step 205 above, "selecting tasks to be executed from the task scheduling queue and adding them to the task execution queue according to the queue scheduling order and the target quantity," can be:

[0083] According to the queue scheduling order and the target number, tasks to be executed are selected from at least one task scheduling queue, wherein the number of tasks to be executed selected from each task scheduling queue does not exceed the maximum number of tasks extracted in a single time corresponding to the task scheduling queue, and the total number of all selected tasks to be executed does not exceed the target number.

[0084] The selected tasks to be executed are extracted from the task scheduling queue and added to the task execution queue.

[0085] In this embodiment of the application, in order to control the execution priority of tasks of various task types and the queue depth of task execution queues, a maximum number of tasks to be extracted from each task scheduling queue at one time can be set for each task scheduling queue, that is, each task scheduling queue corresponds to a maximum number of tasks to be extracted at one time.

[0086] In this embodiment of the application, the required tasks to be executed in the task execution queue can be extracted from a task scheduling queue at one time. In this case, the above step "selecting tasks to be executed from at least one task scheduling queue according to the queue scheduling order and the target quantity" can be:

[0087] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0088] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the target number of tasks to be executed is selected from the current task scheduling queue as the selected tasks to be executed.

[0089] If the target number exceeds the maximum number of tasks that can be extracted at one time in the current task scheduling queue, and the sum of the number of tasks that have been extracted from the current task scheduling queue to the task execution queue and the target number exceeds the maximum number of tasks that can be extracted in the current task scheduling queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0090] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks already extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the step of selecting the target number of tasks to be executed from the current task scheduling queue continues until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0091] In this embodiment of the application, when tasks to be executed can be added to the task execution queue, the tasks to be executed required by the task execution queue can be extracted from multiple task scheduling queues. At this time, the above step "selecting tasks to be executed from at least one task scheduling queue according to the queue scheduling order and the target number" can be:

[0092] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0093] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, calculate the first difference between the number of tasks in existence in the current task scheduling queue and the maximum number of tasks in existence. Determine the smaller value from the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue, and use the next task scheduling queue as the current task scheduling queue according to the queue scheduling order.

[0094] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks that have been extracted from the current task scheduling queue to the task execution queue is greater than or equal to the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0095] Obtain a second difference between the target quantity and the extracted quantity, and update the target quantity to the second difference;

[0096] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks currently in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks currently in existence that can be extracted from the current task scheduling queue to the task execution queue, calculate a first difference between the number of tasks currently in existence in the current task scheduling queue and the maximum number of tasks currently in existence. Determine the smaller value between the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue. Continue the process of using the next task scheduling queue as the current task scheduling queue according to the queue scheduling order until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0097] In this embodiment of the application, to further control the processing latency of tasks to be executed for each task type, the maximum number of tasks in storage corresponding to each task scheduling queue can be adjusted in real time. Specifically, the method for adjusting the maximum number of tasks in storage can be:

[0098] The actual processing delay of each of the tasks to be executed is detected, wherein the actual processing delay is the difference between the time when the task to be executed is added to the task scheduling queue and the time when the task to be executed is completed;

[0099] Obtain the expected processing latency for each task scheduling queue;

[0100] Update the maximum number of tasks in each task scheduling queue based on the actual processing delay and the expected processing delay.

[0101] In this embodiment of the application, the expected processing latency corresponding to each task scheduling queue is the preset processing latency of the tasks to be executed stored in each task scheduling queue.

[0102] In this embodiment of the application, the above step "updating the maximum number of tasks in existence corresponding to each task scheduling queue based on the actual processing delay and the expected processing delay corresponding to each task scheduling queue" can be:

[0103] Set the maximum processing delay of each task scheduling queue according to the expected processing delay of each task scheduling queue;

[0104] Determine the number of timeout tasks corresponding to each of the scheduling task queues in the latest monitoring period. The timeout task is a task whose actual processing delay exceeds the maximum processing delay of the scheduling task queue.

[0105] Determine the target task scheduling queue with an execution priority level greater than the preset level;

[0106] If the ratio of the number of tasks in the target scheduling task queue to the total number of all pending tasks from the target scheduling task queue that have been processed and completed in the latest monitoring period exceeds a preset maximum ratio, then the maximum number of tasks in storage corresponding to the target task scheduling queue is increased, wherein the increased maximum number of tasks in storage does not exceed the maximum number of tasks extracted in a single instance corresponding to the target task scheduling queue.

[0107] The maximum processing latency of each task scheduling queue is the maximum processing latency of the tasks to be executed stored in each task scheduling queue. The maximum processing latency can be obtained by calculating the expected processing latency. For example, the maximum processing latency can be n times the expected processing latency.

[0108] The monitoring period can be set flexibly according to actual needs, with no restrictions on its length. Similarly, the preset maximum ratio can be set flexibly according to actual needs. The preset maximum ratios for each task scheduling queue can be different, partially the same, or all the same.

[0109] In this embodiment of the application, the tasks to be executed stored in the target task scheduling queue are tasks with higher execution priority. If the ratio calculated by the target task scheduling queue exceeds the preset maximum ratio, it indicates that the processing delay of the tasks with higher execution priority is large, which is prone to system lag. In order to speed up the processing speed of the tasks to be executed stored in the target task scheduling queue, the number of tasks to be executed extracted from the target task scheduling queue and added to the task execution queue can be increased.

[0110] In one embodiment of this application, a candidate task scheduling queue with the largest total number of tasks completed within a monitoring period can be obtained. This means the number of tasks completed within the latest monitoring period in the candidate task scheduling queue is greater than the number of tasks completed within the latest monitoring period in other task scheduling queues. If the execution priority of tasks in the candidate task scheduling queue is lower than a preset priority, and the processing latency of tasks in the target task scheduling queue with a higher execution priority is large within the latest monitoring period, the maximum number of tasks in the candidate task scheduling queue can be reduced to indirectly reduce the processing latency of tasks in the target task scheduling queue. Furthermore, the reduced maximum number of tasks in the candidate task scheduling queue does not exceed the maximum number of tasks extracted in a single instance from the candidate task scheduling queue.

[0111] Step 206: Retrieve the tasks to be executed from the task execution queue and process them.

[0112] In this embodiment of the application, the task execution queue adopts the FIFO (First Input First Output) scheduling method to process the stored tasks to be executed. That is, when the terminal extracts the tasks to be executed from the task execution queue for processing, the tasks to be executed that were added to the task execution queue first will be extracted and processed first.

[0113] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.

[0114] The task scheduling method provided in this application embodiment can set up several task scheduling queues to store tasks to be executed. When a terminal generates a task to be executed, it will first store it in the task scheduling queue. The terminal determines the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of the task type. This can avoid the task to be executed being queued in the task execution queue according to the order in which the task to be executed is generated. Instead, the order of the task to be executed of various task types in the task execution queue is determined according to the queue scheduling order. When there are enough tasks to be executed in the task execution queue, the foreground tasks to be executed generated by the interaction between the terminal and the user can be added to the task execution queue first. This allows the terminal to process the foreground tasks to be executed first, thereby effectively reducing the processing latency of the foreground tasks to be executed, reducing the possibility of excessive latency of the foreground tasks to be executed when the background tasks are under high load, and improving system smoothness.

[0115] For example, if the task to be executed is an I / O request for this terminal, the specific implementation process of the task scheduling method in this embodiment of the application is as follows:

[0116] Step 1: Create 5 I / O scheduler queues in the I / O scheduler to classify I / O requests from terminals. Details are as follows:

[0117] FG READ queue: Receives read IO requests from the foreground application, queues them in a FIFO manner, and inserts the later IO requests into the tail of the queue. The IO dispatcher selects IO requests from the head of the queue and adds them to the NCQ in sequence.

[0118] FG WRITE queue: Receives write IO requests from the foreground application, queues them in a FIFO manner, and inserts the later IO requests into the tail of the queue. The IO dispatcher selects IO requests from the head of the queue and adds them to the NCQ in sequence.

[0119] BG READ queue: Receives read IO requests from background applications, queues them in a FIFO manner, and inserts the latest IO request into the tail of the queue. The IO dispatcher selects IO requests from the head of the queue and adds them to the NCQ in sequence.

[0120] Discard queue: Receives discard (operation cancellation) requests from the file system layer, queues them in a FIFO manner, inserts the later IO requests into the tail of the queue, and the IO dispatcher selects IO requests from the head of the queue and adds them to the NCQ in sequence.

[0121] Others queue: Receives other IO requests, such as background write IO requests, flush (data clearing) requests, etc. They are queued in a FIFO manner, with the latest IO request inserted at the end of the queue. The IO dispatcher selects IO requests from the head of the queue and adds them to the NCQ sequentially.

[0122] Step 2: Configure the latency and dispatch parameters for different I / O scheduler queues, as follows:

[0123] exp_latency: Expected I / O processing latency. Generally, FG READ has the highest latency requirement, so you can set FG READ to have the shortest latency. Other I / O scheduler queues can be adjusted according to actual needs. For example, FG READ can be set to 1ms, FG WRITE to 10ms, BG READ to 5ms, DISCARD to 20ms, and OTHERS to 100ms.

[0124] `max_queue`: The maximum number of I / O requests allowed into this I / O scheduling queue. Since the number of requests in the block device I / O request queue is limited (typically 128), if a large number of background I / O requests exhaust all I / O requests, foreground I / O may experience high latency due to waiting for requests to become available. Therefore, it is necessary to limit the queue depth of each I / O scheduler. For example, you can set `FG READ` to 128, `FG WRITE` to 64, `BG READ` to 64, `DISCARD` to 32, and `OTHERS` to 32.

[0125] `max_dispatch`: The maximum number of I / O requests that can be dispatched to the NCQ in a single I / O scheduling queue. It controls I / O priority and the NCQ queue depth. Generally, there is no limit to `FG READ`, but certain limits are imposed on other I / O queues. For example, for a device with an NCQ queue depth of 32, you can set `FG READ` to 32, `FG WRITE` to 24, `BG READ` to 24, `DISCARD` to 16, and `OTHERS` to 8.

[0126] io_window: The monitoring period for IO latency statistics, e.g., 100ms

[0127] Step 3: Monitor the latency of the I / O stored in each I / O scheduling queue, and adjust the number of I / Os allowed to queue in the NCQ queue for that queue, denoted as max_inflight. The specific method is as follows:

[0128] Step 3.1: Initialize the max_inflight value of each IO scheduler queue to the user-defined max_dispatch value.

[0129] Step 3.2: The IO latency of each IO scheduling queue is divided into 8 intervals according to the user-defined exp_latency for statistical analysis, namely [0, 0.25)exp_latency, [0.25, 0.5)exp_latency, [0.5, 0.75)exp_latency, [0.75, 1)exp_latency, [1, 1.25)exp_latency, [1.25, 1.5)exp_latency, [1.5, 1.75)exp_latency, [1.75, 2)exp_latency, [2, infinity)exp_latency. The number of IOs falling into each interval is initialized to 0, and the start time of the monitoring period, window_start, is recorded as the current system time.

[0130] Step 3.3 Monitor the IO latency stored in each task scheduling queue within the latest cycle. The time an IO request is inserted into the IO scheduler queue is denoted as t0, and the completion time of the IO is denoted as t1. The latency of this IO is then latency = t1 - t0.

[0131] Step 3.4: When the IO is completed, update the latency statistics of the IO queue according to the latency interval in which the IO latency falls, i.e., increment the corresponding IO count by 1, and determine the interval between the current system time and the start time of the monitoring period (window_start). If it exceeds the window size (io_window), update max_inflight based on the IO latency statistics of the previous window, and reinitialize the IO record count and window_start for each interval. The update rules for max_inflight are as follows: Steps 3.5 to 3.9:

[0132] Step 3.5: Calculate the 99% maximum latency of IOs on each IO scheduler queue. For example, if the exp_latency of the IO scheduler queue is set to 2ms, the monitoring period is 1s, and 500 IOs were processed in the latest monitoring period, with actual processing latency of 0.1ms for 400 IOs, 0.5ms for 50 IOs, 1ms for 20 IOs, 1.5ms for 10 IOs, 2ms for 10 IOs, 3ms for 5 IOs, and 5ms for 5 IOs, then the maximum processing latency for 99% of the IOs (i.e., 495 IOs) is 3ms, which falls within the interval [1.5, 1.75) of exp_latency. Therefore, the maximum latency for 99% of the IOs is 1.75exp_latency.

[0133] Step 3.6: Traverse the 5 I / O scheduler queues and find the queue with the highest latency requirement (i.e., the smallest user-defined exp_latency) and 99% of the maximum latency exceeds twice the exp_latency. This queue is denoted as Q1. For example, here we find the FG READ queue.

[0134] Step 3.7: Traverse the 5 IO scheduler queues and find the IO scheduler queue with the highest latency requirement (Q1) (judged by the size of exp_latency, i.e., exp_latency is greater than the exp_latency of Q1) and the largest number of IOs processed in the latest monitoring period. This queue is denoted as Q2. For example, the OTHERS queue was found here.

[0135] Step 3.8: If both Q1 and Q2 exist, halve the max_inflight of Q2, ensuring that the halved max_inflight does not exceed the max_dispatch of Q2, i.e., it is limited to the range [1, max_dispatch]. This reduces the I / O latency of Q1 by decreasing the throughput of Q2. Furthermore, if the halved max_inflight of Q2 does not fall within [1, max_dispatch], then Q2's max_inflight can be set to max(1, min(max_inflight / 2, max_dispatch)).

[0136] Step 3.9: If only Q1 exists, double Q1's max_inflight, ensuring the doubled max_inflight does not exceed Q1's corresponding max_dispatch, limiting it to the range [1, max_dispatch] to improve Q1's IO throughput. Alternatively, if Q1's doubled max_inflight does not fall within [1, max_dispatch], then Q1's max_inflight can also be set to max(1, min(max_inflight*2, max_dispatch)).

[0137] Step 4: The IO dispatcher is responsible for selecting IO requests from the 5 IO scheduler queues and sending them to the NCQ queue. The specific rules are as follows:

[0138] Step 4.1: Initialize the number of I / O dispatches in this round for each I / O scheduler queue to 0.

[0139] Step 4.2: If an available slot is to be obtained in the NCQ queue, and the current NCQ queue is full, then an IO operation must be completed before an available slot can be obtained.

[0140] Step 4.3: If the FG READ queue is not empty, and the number of IO requests dispatched from this queue in this round, nr_dispatch, does not exceed max_dispatch, and the sum of the number of FG READ requests queued in NCQ, nr_inflight, and the available empty slots in the NCQ queue does not exceed max_inflight, then select a READ request from the head of the FG READ queue and send it to the NCQ queue for queuing. At the same time, increment nr_inflight and nr_dispatch by 1; then return to step 4.2.

[0141] Step 4.4: If no IO dispatch was selected in Step 4.3 (the queue is empty or the number of dispatched IOs exceeds the limit), then consider selecting an IO dispatch from the FG WRITE queue. Similarly, if the FG WRITE queue is not empty, and the number of IO requests dispatched from this queue in this round, nr_dispatch, does not exceed max_dispatch, and the sum of the number of FG WRITE requests queued in NCQ, nr_inflight, and the available empty slots in the NCQ queue does not exceed max_inflight, then select a WRITE request from the head of the FG WRITE queue and dispatch it to the NCQ queue, while incrementing nr_inflight and nr_dispatch by 1; then repeat Step 4.2.

[0142] Step 4.5: If no IO request was selected in Step 4.4 (the queue is empty or the number of IO requests sent exceeds the limit), then consider selecting an IO request from the BG READ queue. Similarly, if the BG READ queue is not empty, and the number of IO requests dispatched from this queue in this round, nr_dispatch, does not exceed max_dispatch, and the sum of the number of BG READ requests queued in NCQ, nr_inflight, and the available slots in the NCQ queue does not exceed max_inflight, then select a READ request from the head of the BG READ queue and send it to the NCQ queue for queuing. Simultaneously, increment nr_inflight and nr_dispatch by 1. Then return to Step 4.2.

[0143] Step 4.6: If no IO dispatch was selected in Step 4.5 (the queue is empty or the number of dispatched IOs exceeds the limit), then consider selecting an IO dispatch from the DISCARD queue. Similarly, if the DISCARD queue is not empty, and the number of IO requests dispatched from this queue in this round, nr_dispatch, does not exceed max_dispatch, and the sum of the number of BG READ requests queued in NCQ, nr_inflight, and the available empty slots in the NCQ queue does not exceed max_inflight, then select a DISCARD request from the head of the DISCARD queue and dispatch it to the NCQ queue for queuing. At the same time, nr_inflight and nr_dispatch are incremented by 1. Then return to Step 4.2.

[0144] Step 4.7: If no IO request was selected in Step 4.6 (the queue is empty or the number of IO requests sent exceeds the limit), then consider selecting an IO request from the OTHERS queue. Similarly, if the OTHERS queue is not empty, and the number of IO requests dispatched from this queue in this round, nr_dispatch, does not exceed max_dispatch, and the sum of the number of other IO requests queued in NCQ, nr_inflight, and the available space in the NCQ queue does not exceed max_inflight, then select an IO request from the head of the OTHERS queue and send it to the NCQ queue for queuing. At the same time, increment nr_inflight and nr_dispatch by 1. Then return to Step 4.2.

[0145] Step 4.8: Return to step 4.1 and begin a new round of IO dispatch.

[0146] Step 4.9: When the IO is completed, update the nr_inflight of the corresponding IO scheduler queue according to the type of the IO (e.g., FG READ), that is, decrement nr_inflight by 1.

[0147] To facilitate better implementation of the task scheduling method of this application, this application also provides a task scheduling apparatus. Please refer to... Figure 3 , Figure 3 This is a schematic diagram of the structure of a task scheduling device provided in an embodiment of this application. The task scheduling device may include a scheduling queue acquisition unit 301, a scheduling order determination unit 302, an execution queue acquisition unit 303, a calculation unit 304, a selection unit 305, and a processing unit 306.

[0148] The scheduling queue acquisition unit 301 is used to acquire several task scheduling queues of this terminal. Each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal. Different task scheduling queues store different task types of tasks to be executed.

[0149] The scheduling order determination unit 302 is used to determine the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of each task type.

[0150] The execution queue acquisition unit 303 is used to acquire a task execution queue, wherein the task execution queue includes tasks to be executed extracted from the task scheduling queue;

[0151] The calculation unit 304 is used to calculate the target number of tasks to be executed that can be added to the task execution queue when the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue.

[0152] Selection unit 305 is used to select tasks to be executed from the task scheduling queue and add them to the task execution queue according to the queue scheduling order and the target quantity;

[0153] The processing unit 306 is used to retrieve tasks to be executed from the task execution queue and process them.

[0154] Optionally, the scheduling queue acquisition unit 301 is further configured to:

[0155] Create the task scheduling queues described above;

[0156] When the terminal generates the task to be executed, the task type of the task to be executed is determined;

[0157] Based on the task type of the task to be executed, the generated task to be executed is stored in the corresponding task scheduling queue.

[0158] Optionally, the selection unit 305 is further configured to:

[0159] According to the queue scheduling order and the target number, tasks to be executed are selected from at least one task scheduling queue, wherein the number of tasks to be executed selected from each task scheduling queue does not exceed the maximum number of tasks extracted in a single time corresponding to the task scheduling queue, and the total number of all selected tasks to be executed does not exceed the target number.

[0160] The selected tasks to be executed are extracted from the task scheduling queue and added to the task execution queue.

[0161] Optionally, the selection unit 305 is further configured to:

[0162] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0163] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the target number of tasks to be executed is selected from the current task scheduling queue as the selected tasks to be executed.

[0164] If the target number exceeds the maximum number of tasks that can be extracted at one time in the current task scheduling queue, and the sum of the number of tasks that have been extracted from the current task scheduling queue to the task execution queue and the target number exceeds the maximum number of tasks that can be extracted in the current task scheduling queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0165] If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks already extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the step of selecting the target number of tasks to be executed from the current task scheduling queue continues until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0166] Optionally, the selection unit 305 is further configured to:

[0167] Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue;

[0168] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, calculate the first difference between the number of tasks in existence in the current task scheduling queue and the maximum number of tasks in existence. Determine the smaller value from the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue, and use the next task scheduling queue as the current task scheduling queue according to the queue scheduling order.

[0169] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks that have been extracted from the current task scheduling queue to the task execution queue is greater than or equal to the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order.

[0170] Obtain a second difference between the target quantity and the extracted quantity, and update the target quantity to the second difference;

[0171] If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks currently in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks currently in existence that can be extracted from the current task scheduling queue to the task execution queue, calculate a first difference between the number of tasks currently in existence in the current task scheduling queue and the maximum number of tasks currently in existence. Determine the smaller value between the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue. Continue the process of using the next task scheduling queue as the current task scheduling queue according to the queue scheduling order until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

[0172] Optionally, the device is also used for:

[0173] The actual processing delay of each of the tasks to be executed is detected, wherein the actual processing delay is the difference between the time when the task to be executed is added to the task scheduling queue and the time when the task to be executed is completed;

[0174] Obtain the expected processing latency for each task scheduling queue;

[0175] Update the maximum number of tasks in each task scheduling queue based on the actual processing delay and the expected processing delay.

[0176] Optionally, the device is also used for:

[0177] Set the maximum processing delay of each task scheduling queue according to the expected processing delay of each task scheduling queue;

[0178] Determine the number of timeout tasks corresponding to each of the scheduling task queues in the latest monitoring period. The timeout task is a task whose actual processing delay exceeds the maximum processing delay of the scheduling task queue.

[0179] Determine the target task scheduling queue with an execution priority level greater than the preset level;

[0180] If the ratio of the number of tasks in the target scheduling task queue to the total number of all pending tasks from the target scheduling task queue that have been processed and completed in the latest monitoring period exceeds a preset maximum ratio, then the maximum number of tasks in storage corresponding to the target task scheduling queue is increased, wherein the increased maximum number of tasks in storage does not exceed the maximum number of tasks extracted in a single instance corresponding to the target task scheduling queue.

[0181] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.

[0182] The task scheduling device provided in this application embodiment can set up several task scheduling queues to store tasks to be executed. When the terminal generates a task to be executed, it will first store it in the task scheduling queue. The terminal determines the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of the task type. This can avoid the task to be executed being queued in the task execution queue according to the order in which the task to be executed is generated. Instead, the order of the task to be executed of various task types in the task execution queue is determined according to the queue scheduling order. When there are enough tasks to be executed in the task execution queue, the foreground tasks to be executed generated by the interaction between the terminal and the user can be added to the task execution queue first. This allows the terminal to process the foreground tasks to be executed first, thereby effectively reducing the processing latency of the foreground tasks to be executed, reducing the possibility of excessive latency of the foreground tasks to be executed when the background tasks are under high load, and improving the smoothness of the system.

[0183] Accordingly, this application also provides a terminal device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer, personal digital assistant, etc. Figure 4 As shown, Figure 4 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. The terminal device 400 includes a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, and a computer program stored in the memory 402 and executable on the processor. The processor 401 and the memory 402 are electrically connected. Those skilled in the art will understand that the terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0184] The processor 401 is the control center of the terminal device 400. It connects various parts of the terminal device 400 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, it executes various functions of the terminal device 400 and processes data, thereby performing overall monitoring of the terminal device 400.

[0185] In this embodiment, the processor 401 in the terminal device 400 loads the instructions corresponding to the processes of one or more applications into the memory 402 according to the following steps, and the processor 401 runs the applications stored in the memory 402 to achieve various functions:

[0186] Obtain several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed;

[0187] Based on the execution priority level of each task type, determine the queue scheduling order of each task scheduling queue when scheduling tasks to be executed into the task execution queue;

[0188] Obtain a task execution queue, the task execution queue including tasks to be executed extracted from the task scheduling queue;

[0189] If the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue, calculate the target number of tasks that can be added to the task execution queue.

[0190] Based on the queue scheduling order and the target quantity, select tasks to be executed from the task scheduling queue and add them to the task execution queue;

[0191] Retrieve tasks to be executed from the task execution queue and process them.

[0192] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0193] Optional, such as Figure 4 As shown, the terminal device 400 also includes: a touch display screen 403, a radio frequency circuit 404, an audio circuit 405, an input unit 406, and a power supply 407. The processor 401 is electrically connected to the touch display screen 403, the radio frequency circuit 404, the audio circuit 405, the input unit 406, and the power supply 407. Those skilled in the art will understand that... Figure 4 The terminal device structure shown does not constitute a limitation on the terminal device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0194] The touch display screen 403 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 403 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the terminal device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as the user's finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 401. It can also receive and execute commands from the processor 401. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 401 to determine the type of touch event. Subsequently, the processor 401 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 403 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 403 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 403 can also be used as part of the input unit 406 to achieve input functions.

[0195] The radio frequency circuit 404 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other terminal devices, and to transmit and receive signals with network devices or other terminal devices.

[0196] Audio circuit 405 can be used to provide an audio interface between a user and a terminal device via a speaker and a microphone. Audio circuit 405 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 405, converted back into audio data, and then processed by processor 401 before being transmitted via radio frequency circuit 404 to, for example, another terminal device, or output to memory 402 for further processing. Audio circuit 405 may also include an earphone jack to provide communication between peripheral headphones and the terminal device.

[0197] The input unit 406 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.

[0198] Power supply 407 is used to supply power to the various components of terminal device 400. Optionally, power supply 407 can be logically connected to processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 407 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0199] although Figure 4 As not shown in the diagram, the terminal device 400 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.

[0200] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0201] As can be seen from the above, the terminal device provided in this embodiment can be configured to store several task scheduling queues for tasks to be executed. When the terminal generates a task to be executed, it will first store it in the task scheduling queue. The terminal determines the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of the task type. This avoids the situation where each task to be executed is executed in a queue according to the order in which the tasks are generated. Instead, the order in which the tasks of various task types are arranged in the task execution queue is determined according to the queue scheduling order. When there are enough tasks to be executed in the task execution queue, the foreground tasks generated by the interaction between the terminal and the user can be added to the task execution queue first. This allows the terminal to process the foreground tasks to be executed first, thereby effectively reducing the processing latency of the foreground tasks to be executed and reducing the possibility of excessive latency of the foreground tasks to be executed when the background tasks are under high load, thus improving the smoothness of the system.

[0202] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0203] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of computer programs that can be loaded by a processor to execute steps in any of the task scheduling methods provided in embodiments of this application. For example, the computer program can execute the following steps:

[0204] Obtain several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed;

[0205] Based on the execution priority level of each task type, determine the queue scheduling order of each task scheduling queue when scheduling tasks to be executed into the task execution queue;

[0206] Obtain a task execution queue, the task execution queue including tasks to be executed extracted from the task scheduling queue;

[0207] If the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue, calculate the target number of tasks that can be added to the task execution queue.

[0208] Based on the queue scheduling order and the target quantity, select tasks to be executed from the task scheduling queue and add them to the task execution queue;

[0209] Retrieve tasks to be executed from the task execution queue and process them.

[0210] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0211] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0212] Since the computer program stored in the storage medium can execute the steps of any of the task scheduling methods provided in the embodiments of this application, the beneficial effects that any of the task scheduling methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0213] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0214] The foregoing has provided a detailed description of a task scheduling method, apparatus, terminal device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions and core ideas of the present invention. Those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A task scheduling method, characterized in that, include: Obtain several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed; Based on the execution priority level of each task type, determine the queue scheduling order of each task scheduling queue when scheduling tasks to be executed into the task execution queue; Obtain a task execution queue, which includes tasks to be executed extracted from the task scheduling queue, and the task execution queue is a local command queue in the terminal's memory; If the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue, calculate the target number of tasks that can be added to the task execution queue. Based on the queue scheduling order and the target quantity, select tasks to be executed from the task scheduling queue and add them to the task execution queue; Retrieve tasks to be executed from the task execution queue and process them; The step of selecting tasks to be executed from the task scheduling queue and adding them to the task execution queue according to the queue scheduling order and the target quantity includes: According to the queue scheduling order and the target number, tasks to be executed are selected from at least one task scheduling queue, wherein the number of tasks to be executed selected from each task scheduling queue does not exceed the maximum number of tasks extracted in a single time corresponding to the task scheduling queue, and the total number of all selected tasks to be executed does not exceed the target number. The selected tasks to be executed are extracted from the task scheduling queue and added to the task execution queue.

2. The task scheduling method according to claim 1, characterized in that, Before obtaining the various task scheduling queues of this terminal, the method further includes: Create the task scheduling queues described above; When the terminal generates the task to be executed, the task type of the task to be executed is determined; Based on the task type of the task to be executed, the generated task to be executed is stored in the corresponding task scheduling queue.

3. The task scheduling method according to claim 1, characterized in that, The step of selecting tasks to be executed from at least one task scheduling queue according to the scheduling order and the target quantity includes: Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue; If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the target number of tasks to be executed is selected from the current task scheduling queue as the selected tasks to be executed. If the target number exceeds the maximum number of tasks that can be extracted at one time in the current task scheduling queue, and the sum of the number of tasks that have been extracted from the current task scheduling queue to the task execution queue and the target number exceeds the maximum number of tasks that can be extracted in the current task scheduling queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order. If the target number does not exceed the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the sum of the number of tasks already extracted from the current task scheduling queue to the task execution queue and the target number does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the step of selecting the target number of tasks to be executed from the current task scheduling queue continues until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

4. The task scheduling method according to claim 1, characterized in that, The step of selecting tasks to be executed from at least one task scheduling queue according to the scheduling order and the target quantity includes: Select the task scheduling queue that is first in the queue scheduling order as the current task scheduling queue; If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, calculate the first difference between the number of tasks in existence in the current task scheduling queue and the maximum number of tasks in existence. Determine the smaller value from the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue, and use the next task scheduling queue as the current task scheduling queue according to the queue scheduling order. If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks that have been extracted from the current task scheduling queue to the task execution queue is greater than or equal to the maximum number of tasks that can be extracted from the current task scheduling queue to the task execution queue, then the next task scheduling queue will be used as the current task scheduling queue according to the queue scheduling order. Obtain a second difference between the target quantity and the extracted quantity, and update the target quantity to the second difference; If the target number exceeds the maximum number of tasks that can be extracted in a single run from the current task scheduling queue, and the number of tasks currently in existence that have been extracted from the current task scheduling queue to the task execution queue does not exceed the maximum number of tasks currently in existence that can be extracted from the current task scheduling queue to the task execution queue, calculate a first difference between the number of tasks currently in existence in the current task scheduling queue and the maximum number of tasks currently in existence. Determine the smaller value between the first difference and the maximum number of tasks that can be extracted in a single run from the current task scheduling queue as the number of tasks to be extracted from the current task scheduling queue. Continue the process of using the next task scheduling queue as the current task scheduling queue according to the queue scheduling order until the current task scheduling queue is the last task scheduling queue in the queue scheduling order.

5. The task scheduling method according to any one of claims 3 or 4, characterized in that, Also includes: The actual processing delay of each of the tasks to be executed is detected, wherein the actual processing delay is the difference between the time when the task to be executed is added to the task scheduling queue and the time when the task to be executed is completed; Obtain the expected processing latency for each task scheduling queue; Update the maximum number of tasks in each task scheduling queue based on the actual processing delay and the expected processing delay.

6. The task scheduling method according to claim 5, characterized in that, The step of updating the maximum number of tasks in existence for each task scheduling queue based on the actual processing latency and the expected processing latency for each task scheduling queue includes: Set the maximum processing delay of each task scheduling queue according to the expected processing delay of each task scheduling queue; Determine the number of timeout tasks corresponding to each of the scheduling task queues in the latest monitoring period. The timeout task is a task whose actual processing delay exceeds the maximum processing delay of the scheduling task queue. Determine the target task scheduling queue with an execution priority level greater than the preset level; If the ratio of the number of tasks in the target scheduling task queue to the total number of all pending tasks from the target scheduling task queue that have been processed and completed in the latest monitoring period exceeds a preset maximum ratio, then the maximum number of tasks in storage corresponding to the target task scheduling queue is increased, wherein the increased maximum number of tasks in storage does not exceed the maximum number of tasks extracted in a single instance corresponding to the target task scheduling queue.

7. A task scheduling device, characterized in that, include: The scheduling queue acquisition unit is used to acquire several task scheduling queues of this terminal, wherein each task scheduling queue corresponds to storing a task of a certain type to be executed in this terminal, and different task scheduling queues store different task types of tasks to be executed. The scheduling order determination unit is used to determine the queue scheduling order of each task scheduling queue when scheduling the task to be executed into the task execution queue according to the execution priority level of each task type. An execution queue acquisition unit is used to acquire a task execution queue, wherein the task execution queue includes tasks to be executed extracted from the task scheduling queue, and the task execution queue is a local command queue in the terminal's memory; The calculation unit is used to calculate the target number of tasks that can be added to the task execution queue when the current queue depth of the task execution queue is less than the maximum queue depth of the task execution queue. The selection unit is configured to select tasks to be executed from the task scheduling queue and add them to the task execution queue according to the queue scheduling order and the target quantity; the step of selecting tasks to be executed from the task scheduling queue and adding them to the task execution queue according to the queue scheduling order and the target quantity includes: selecting tasks to be executed from at least one task scheduling queue according to the queue scheduling order and the target quantity, wherein the number of tasks to be executed selected from each task scheduling queue does not exceed the maximum single task extraction quantity corresponding to the task scheduling queue, and the total number of all selected tasks to be executed does not exceed the target quantity; and extracting the selected tasks to be executed from the task scheduling queue and adding them to the task execution queue. The processing unit is used to retrieve tasks to be executed from the task execution queue and process them.

8. A terminal device, characterized in that, include: Memory, used to store computer programs; A processor for implementing the steps of the task scheduling method as described in any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the task scheduling method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Scheduling method and device based on terminal equipment, storage medium and terminal equipment

    CN112799805A