Task scheduling method and device, equipment, and storage medium
By selecting a global distribution queue and performing global task selection based on scheduling delay parameters during task scheduling, the problem of high power consumption during task scheduling is solved, achieving more efficient task scheduling and reduced power consumption.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHENGDU OPPO TELECOMM TECH CORP LTD
- Filing Date
- 2024-12-09
- Publication Date
- 2026-06-09
AI Technical Summary
Existing technologies suffer from high power consumption during task scheduling, especially in multi-task scheduling where the kernel scheduling overhead is significant due to local decision-making.
By selecting the target global distribution queue based on the task's scheduling latency parameters while the task is in the pending task wake-up state, and selecting the task for processing from a global perspective, the time spent selecting and mounting the global distribution queue is reduced, thereby lowering the overhead related to kernel scheduling.
This effectively reduces the time required for tasks to select and mount the global distribution queue, lowers the proportion of kernel scheduling overhead, and thus reduces power consumption.
Smart Images

Figure CN122173214A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and to, but is not limited to, a task scheduling method, apparatus, device, and storage medium. Background Technology
[0002] With the continuous development of internet technology, the amount of data and tasks that need to be processed by computer technology is increasing, placing ever higher demands on server processing capabilities. After receiving a task request instruction, the server submits the corresponding task to an abstract queue, accumulating the tasks, and then selects one or more specific tasks from the queue and triggers their execution through some scheduling strategies.
[0003] However, scheduling multiple tasks can lead to high power consumption due to significant scheduling overhead. Therefore, reducing power consumption during task scheduling is an urgent problem to be solved. Summary of the Invention
[0004] In view of this, the task scheduling method, apparatus, device, and storage medium provided in the embodiments of this application can reduce the time required for tasks to select a global distribution queue, reduce the proportion of kernel scheduling-related overhead, and thus reduce power consumption. The task scheduling method, apparatus, device, and storage medium provided in the embodiments of this application are implemented as follows:
[0005] In a first aspect, embodiments of this application provide a task scheduling method, including:
[0006] When a task to be processed is in an awake state, a first target global distribution queue corresponding to the task to be processed is determined according to the first scheduling delay parameter corresponding to the task to be processed. The task to be processed is added to the first target global distribution queue. The first target global distribution queue is one of multiple global distribution queues. The second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. Each global distribution queue is used to mount unprocessed tasks. The first scheduling delay parameter is used to indicate the maximum delay time that the task to be processed can accept. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0007] Select a target task from the multiple global distribution queues for processing.
[0008] Secondly, embodiments of this application provide a task scheduling device, comprising:
[0009] The determination module is used to determine the first target global distribution queue corresponding to the task to be processed based on the first scheduling delay parameter corresponding to the task to be processed when the task to be processed is in the wake-up state, and to add the task to the first target global distribution queue. The first target global distribution queue is one of multiple global distribution queues. The second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. Each global distribution queue is used to mount unprocessed tasks. The first scheduling delay parameter is used to indicate the maximum delay time that the task to be processed can accept. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0010] The processing module is used to select a target task from the multiple global distribution queues for processing.
[0011] Thirdly, embodiments of this application provide a computer device, including a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the program to implement the method described in embodiments of this application.
[0012] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods described in embodiments of this application.
[0013] The task scheduling method, apparatus, computer device, and computer-readable storage medium provided in this application, while the task to be processed is in a wake-up state, determine a first target global distribution queue corresponding to the task to be processed based on a first scheduling delay parameter corresponding to the task to be processed, and add the task to the first target global distribution queue; subsequently, select a target task from multiple global distribution queues used to mount unprocessed tasks for processing to complete task scheduling. The first target global distribution queue to which the task to be processed is added is one of multiple global distribution queues, and the second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. The first scheduling delay parameter indicates the maximum acceptable delay time for the task to be processed, and the first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0014] In this way, when a task is to be processed selects the first target global distribution queue to join from multiple global distribution queues, it only needs to determine the task's scheduling delay parameter and the global distribution queue's scheduling delay parameter, without having to consider other factors. This reduces the time required for the task to select the global distribution queue to be attached, reduces the proportion of kernel scheduling-related overhead, and reduces power consumption. Attached Figure Description
[0015] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.
[0016] Figure 1 A schematic diagram illustrating a method for implementing task scheduling in a related technology provided in this application embodiment;
[0017] Figure 2 A schematic diagram of a scheduling implementation provided in an embodiment of this application;
[0018] Figure 3 This is another schematic diagram of a scheduling implementation provided in an embodiment of this application;
[0019] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;
[0020] Figure 5 A schematic diagram illustrating the implementation flow of the task scheduling method provided in this application embodiment;
[0021] Figure 6 A schematic diagram illustrating the implementation process of determining the target task provided in this application embodiment;
[0022] Figure 7 A schematic diagram of the overall flow of the task scheduling method provided in the embodiments of this application;
[0023] Figure 8 This is a schematic diagram of the structure of the task scheduling device provided in the embodiments of this application;
[0024] Figure 9 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.
[0026] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0027] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0028] It should be noted that the terms "first, second, third" used in the embodiments of this application are used to distinguish similar or different objects and do not represent a specific order of objects. It can be understood that "first, second, third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0029] Before introducing the relevant solutions of the embodiments of this application, the technical terms involved in the embodiments of this application will be explained:
[0030] The `task struct` is an abstract structure for system tasks within the kernel, maintaining all information about a task. It describes the state of a process (or thread) within the kernel. This structure contains various information about the process, such as the process identifier (PID), memory management information, scheduling information, file descriptor table, and signal status.
[0031] Scheduling class: Each task belongs to its own scheduling class. Different scheduling classes have different priorities and implement different scheduling strategies. Scheduling refers to the process of allocating resources based on the characteristics and constraints of a task so that the task can be completed in a predetermined order and time. This process includes task allocation, sequencing, resource allocation, and schedule control.
[0032] Scheduling Entity: Each task corresponds to one scheduling entity, which is used to record the scheduling data of that task. When group scheduling is enabled, it can also represent a set of task schedules.
[0033] Group scheduling: Group scheduling is a feature provided by the Linux kernel that allows a group of processes to be organized together and subject to unified resource management and restrictions. In Android, processes are divided into different groups based on their priority and type. Through the group scheduling mechanism, Android can implement different resource allocation strategies for processes in different groups to ensure system stability and performance.
[0034] The Completely Fair Scheduler (CFS) is part of the Linux kernel and is responsible for allocating CPU resources to running processes, aiming to maximize program interaction performance and overall CPU utilization. CFS achieves fair scheduling by ensuring that all processes receive CPU time fairly, making it suitable for various workloads, including interactive and batch applications. It is an algorithm based on weighted fair allocation of time slices.
[0035] Earliest Eligible Virtual Deadline First (EEVDF) is a scheduling algorithm based on virtual deadlines, designed to improve upon the CFS scheduler. It calculates the virtual deadline for each task and prioritizes tasks with the earliest virtual deadlines for execution, ensuring that latency-sensitive tasks receive CPU time promptly. The algorithm calculates virtual deadlines based on task weights and time requests.
[0036] First-In-First-Out (FIFO) principle: Tasks that arrive first are scheduled for execution first, while tasks that arrive later wait in a queue. The FIFO scheduling algorithm does not consider task priority, execution time, or any other attributes; it only focuses on the order in which tasks arrive.
[0037] Dispatch queue (DSQ): Used to attach tasks that are in a ready state.
[0038] The scheduler is a key component in the operating system kernel, responsible for managing and scheduling the execution of various tasks in the system. One of the scheduler's main tasks is to allocate core processor resources to each task. In a multitasking operating system, core processor resources are precious, and the scheduler needs to ensure that each task receives the necessary processor time fairly. The scheduler selects appropriate tasks from the ready queue for execution based on factors such as task priority, weight, and status, to ensure the fair, efficient, and rational use of system resources.
[0039] Scheduling point: A specific point in time that may be triggered by various events, such as process creation, process exit, process blocking, I / O interrupt, etc. At these scheduling points, the scheduler selects a process from the ready queue according to a certain algorithm and strategy and allocates it to the core processor for execution.
[0040] With the continuous development of internet technology, the amount of data and tasks requiring computer processing is increasing, placing ever higher demands on server processing capabilities. Upon receiving a task request instruction, the server has various strategies to select and trigger the execution of certain tasks.
[0041] Figure 1 This paper presents an implementation method for task scheduling in related technologies.
[0042] like Figure 1 As shown, in a certain electronic device platform, each system task is abstracted into a task_struct structure in the kernel. This structure maintains a sched_entity member, which represents the basic unit of scheduling by the kernel scheduler.
[0043] When a task is awakened for execution, it needs to be added to the ready queue first. At this time, the task changes from a blocked or dormant state to a ready state.
[0044] Since a typical electronic device platform has N core processors (CPUs), there are a total of N ready queues in the kernel, one for each core processor, called the ready (per-CPU) queue. Therefore, the number of ready queues equals the number of core processors (CPUs).
[0045] The system can classify tasks into real-time scheduling and normal scheduling. Therefore, each per-CPU queue also has sub-queues corresponding to different scheduling classes, such as real-time queues and normal queues. The real-time queue is a priority linked list, and real-time tasks are added to the tail of the corresponding priority linked list according to their task priorities. The normal queue is a red-black tree, and normal tasks are added to the child nodes of the red-black tree according to their virtual runtime.
[0046] Once a task is added to the per-CPU queue and is in a ready state, the scheduler needs to consider how to allocate CPU resources to it. Real-time tasks in the per-CPU queue that are in a ready state will be allocated CPU resources in order of priority, and by default there is almost no share limit. This share limit usually refers to the proportion of resources or time slices allocated to a task. That is, only after a high-priority real-time task finishes execution and voluntarily yields the CPU will it be the turn of the next real-time task to execute.
[0047] For ordinary tasks, prior to kernel version A, the CFS scheduling strategy was typically used, allocating CPU resources according to task weight within a specific scheduling cycle. In kernel version B, the EEVDF scheduling strategy is used, selecting the earliest expiring task from the qualified tasks for execution. Each task has its own requested time share. When the share cannot be satisfied, it is in a qualified state; when it obtains resources exceeding its requested share, it is in an unqualified state.
[0048] The core idea of the EEVDF scheduling strategy is to select the earliest expiring task (i.e., the earliest virtual deadline) from the qualified tasks for execution. Each task has its own requested time share, and its qualification status is determined based on these shares and the execution status of the task.
[0049] The virtual deadline is calculated based on the task's requested time share and actual execution time. When a task is selected for execution, its actual execution time is recorded and compared with the requested time share. If the actual execution time is less than the requested time share, the task remains in a qualified state; if the actual execution time exceeds the requested time share, the task becomes unqualified.
[0050] Furthermore, Android systems with kernel version C and later can enable group scheduling. Tasks within the same scheduling group form a set, where `sched_entity` can represent either a single task or a set. CPU resources are first allocated to the set, and then the set allocates resources to each task below it, i.e., allocated hierarchically to different sets. When a task is running, it also needs to report its resource usage back to its respective set layer by layer. By default, Android's scheduling groups are divided based on the foreground / background state of the application process, into top-app group, foreground task group, background task group, etc.
[0051] In the kernel, there are two types of preemption paths. The first type is wake-up preemption, where a high-priority scheduler can unconditionally preempt a low-priority scheduler when it has an execution requirement.
[0052] For real-time scheduling, high-priority real-time tasks can preempt low-priority real-time tasks; for regular scheduling, the decision on whether to preempt is made based on the difference in virtual runtime. Therefore, high-priority regular tasks still have a significant preemption advantage.
[0053] The second type is periodic interrupt preemption. The period depends on the configuration of the Hertz (Hz) number. For example, the Android system can fix it at 250Hz, which is once every 4ms. After the interrupt arrives, the normal task will switch tasks according to the allocation logic described above, depending on whether the currently executing task has exhausted its quota or is in an unqualified state.
[0054] However, for the above technical solution, on the one hand, since it uses a per-CPU ready queue, the core selection during task wake-up and execution needs to be based on certain rules. For example, based on the task load and the current load of each ready queue, and on the basis of load balancing, factors such as energy consumption, cache, and the priority of the currently executing task are considered to determine which ready queue to place the task in. Such logic will increase additional kernel overhead in scenarios where tasks are frequently woken up.
[0055] On the other hand, after a task selects a ready queue, it usually waits on that queue for the scheduling point to arrive and be selected by the scheduler for execution. However, for the scheduler, since the scheduling selection is performed on each ready queue separately, each ready queue can only see the task status of its own queue and cannot select from a global perspective. Therefore, the result of its selection is "local optimum" rather than "global optimum".
[0056] In other words, in real-world systems, due to various limitations (such as hardware architecture, operating system design, and security considerations), the scheduler may not be able to simultaneously obtain task information from all ready queues. This forces the scheduler to make decisions based on local information. That is, when the scheduler selects tasks for each ready queue individually, it can only make decisions based on the task information within that queue. This perspective is local because it does not take into account the task situation in other queues.
[0057] Because the scheduler only sees local information, it may choose the task that seems optimal in the current queue for execution. However, this choice may not be optimal for the entire system. For example, a task in one queue may have a high priority, but if there are more urgent or important tasks in other queues, then this locally optimal choice may not be globally optimal.
[0058] This is related to the fact that the number of user threads and the amount of computation in the Android system are not very stable. It is not enough to consider balancing only when selecting the core processor. Therefore, the scheduler often needs to rely on idle or periodic load balancing to adjust the core processor corresponding to the task.
[0059] For example, Figure 2 A schematic diagram of a scheduling implementation is provided. For example... Figure 2 As shown, at time A, placing task T3 into core processor 1 is feasible from a load balancing perspective. However, at time B, the running time of T2 is significantly longer than expected, leading to an increase in the scheduling delay of T3. At this point, the core scheduler's choice is to promptly pull T3 to core processor 0 for execution at a suitable trigger point, such as after T0 finishes execution.
[0060] On the other hand, the Android system utilizes the group scheduling mechanism provided by the kernel. Group scheduling is a feature provided by the Linux kernel that allows a group of processes to be organized together and subject to unified resource management and restrictions. Grouping by process is not reasonable because, in reality, the tasks involved in the entire user interaction chain within a process are distributed across various processes.
[0061] Group scheduling is a feature provided by the Linux kernel that allows a group of processes to be organized together and subject to unified resource management and restrictions. In the Android system, processes are divided into different groups, which can be based on process type and foreground / background state. Through the group scheduling mechanism, the Android system can implement different resource allocation strategies for processes in different groups to ensure system stability and performance.
[0062] On the other hand, due to the preemption of high-priority tasks and the continuous addition of tasks in the dynamic system, the scheduling delay of tasks is difficult to guarantee, the task execution time is severely fragmented, and the periodic interruption period is too long, which is not conducive to timely task switching.
[0063] For example, Figure 3 A schematic diagram of a scheduling implementation is provided. For example... Figure 3 As shown, T0 is expected to execute in 1ms, but due to its low priority, it is frequently woken up and preempted by higher priority T1-T4, which increases the scheduling delay during task execution and prevents it from completing as expected.
[0064] In view of this, embodiments of this application provide a task scheduling method, which is applied to an electronic device. The electronic device may include, but is not limited to, mobile phones, wearable devices (such as smartwatches, smart bracelets, smart glasses, etc.), tablet computers, laptops, in-vehicle terminals, PCs (Personal Computers), etc. The functions implemented by this method can be achieved by the processor in the electronic device calling program code. Of course, the program code can be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.
[0065] For example, such as Figure 4 As shown, the electronic device 40 may include a processor 401, an external memory interface 402, an internal memory 403, and a universal serial bus (USB) interface 404.
[0066] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 40. In other embodiments of this application, the electronic device 40 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0067] Processor 401 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). These different processing units may be independent devices or integrated into one or more processors. For example, processor 401 may be a smart terminal CPU, such as a Snapdragon series processor. In some embodiments, processor 401 may include one or more interfaces. Interfaces may include inter-integrated circuit (I2C) interfaces, inter-integrated circuit sound (I2S) interfaces, pulse code modulation (PCM) interfaces, universal asynchronous receiver / transmitter (UART) interfaces, mobile industry processor interfaces (MIPI) interfaces, general purpose input / output (GPIO) interfaces, subscriber identity module (SIM) interfaces, and / or universal serial bus (USB) interfaces, etc.
[0068] The external storage interface 402 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 40. The external memory card communicates with the processor 401 through the external storage interface 402 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0069] Internal memory 403 can be used to store computer executable program code, which includes instructions. Internal memory 403 may include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc. The data storage area may store data created during the use of electronic device 40 (such as audio data, phone book, etc.).
[0070] In addition, the electronic devices involved in the embodiments of this application may also be equipped with an operating system, on which applications can be installed and run. The embodiments of this application do not limit this.
[0071] Figure 5 This is a schematic diagram illustrating the implementation flow of the task scheduling method provided in an embodiment of this application. For example... Figure 5 As shown, the method may include the following steps 501 to 502:
[0072] Step 501: When the task to be processed is in the wake-up state, determine the first target global distribution queue corresponding to the task to be processed according to the first scheduling delay parameter corresponding to the task to be processed, and add the task to be processed to the first target global distribution queue.
[0073] In the embodiments of this application, when a task to be processed is awakened from a blocked state or a dormant state, that is, when the task is awakened, the task to be processed will select a queue to join in order to wait for the subsequent scheduler to perform scheduling processing.
[0074] In this embodiment, when a task is in a wake-up state, the selection of the first target global distribution queue to join is determined based on the first scheduling delay parameter corresponding to the task. Here, the first scheduling delay parameter indicates the maximum acceptable delay time for the task, i.e., the maximum waiting time the task can wait for the scheduler to allocate processing resources after joining the first target global distribution queue. The scheduling delay parameter varies depending on the type of task.
[0075] In some embodiments, the scheduling delay parameter corresponding to the task to be processed can be predefined. When configuring, it can be configured according to user needs or according to task type, and can be configured in accordance with the second scheduling delay parameter configured in the global distribution queue.
[0076] For example, if the task to be processed is an audio task, since audio tasks have high requirements for response speed, the scheduling delay parameter corresponding to the task to be processed can be set to 1ms.
[0077] In this embodiment, multiple global distribution queues can be defined, each used to load unprocessed tasks. In some embodiments, a global distribution queue may also be referred to as a global distribution queue. Thus, the first target global distribution queue to which the task to be processed is selected is one of multiple global distribution queues.
[0078] Furthermore, in this embodiment, the tasks added to the global distribution queue are maintained in a FIFO (First-In, First-Out) queue format. That is, tasks added earlier are selected for execution first, and tasks added later are selected for execution later.
[0079] In this embodiment of the application, the global distribution queue is pre-created, and there is no limitation on the method of creating the global distribution queue.
[0080] In some embodiments, a global distribution queue can be created for each business group, with different business groups belonging to different scenario types. That is, a global distribution queue can be created for each business group based on the pre-defined business groups belonging to different scenario types.
[0081] In some embodiments, the business group may include multiple core business groups and multiple non-core business groups. The so-called core business group may be a business group whose scenario type has a short task latency requirement, such as audio group, touch group, display group, network group, etc. The tasks in the core business group are the participation tasks of various key modules of the Android system in actual user scenarios (such as short videos, games, map navigation, etc.).
[0082] Non-core business groups are those whose scenario types require longer task latency, such as top-app groups, foreground task groups, system service groups, kernel task groups, default groups, and background task groups. These business groups do not have high requirements for task response time.
[0083] Furthermore, in this embodiment, the minimum scheduling delay parameter for non-core business groups cannot be lower than the maximum scheduling delay parameter for core business groups. That is, the scheduling delay parameters corresponding to core business groups are all less than the scheduling delay parameters corresponding to non-core business groups.
[0084] In this embodiment of the application, after the business groups are divided, a corresponding global distribution queue can be created for each business group, and a corresponding second scheduling delay parameter can be assigned to each global distribution queue. The second scheduling delay parameter corresponding to the global distribution queue is used to represent the maximum waiting time that the global distribution queue can accept.
[0085] When allocating the corresponding second scheduling delay parameter to each global distribution queue, the configuration can be based on the user's experience or on the specific task latency requirements of the business group.
[0086] For example, a second scheduling delay parameter of 2ms can be configured for global distribution queue 1 corresponding to the audio group, and a second scheduling delay parameter of 128ms can be configured for global distribution queue 2 corresponding to the background task group.
[0087] Furthermore, in this embodiment of the application, the first scheduling delay parameter corresponding to the task attached to each global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0088] For example, for global distribution queue 2, there may be multiple tasks to be processed. The first scheduling delay parameter corresponding to each task to be processed may be different, but the first scheduling delay parameter corresponding to each task to be processed is less than or equal to the second scheduling delay parameter corresponding to global distribution queue 2.
[0089] Alternatively, in other embodiments, the grouping can be determined based on the task utilization rate, and a corresponding global distribution queue can be created for each group.
[0090] Task utilization can be used to determine the workload level of a task. In some stable load scenarios, the computational load of tasks is constant; for example, task A executes for 1ms every 100ms, and task B executes for 10ms every 100ms. In this case, executing task A first and then task B minimizes the total latency of the two tasks; if task B is executed first and then task A, task A may need to wait 10ms.
[0091] When grouping tasks based on task utilization, it can be assumed that the physical time of tasks running on different cores and frequency bands, after normalization, is between 0 and 1024, and tasks are grouped at intervals of 100 utilization.
[0092] For example, in some embodiments, when task utilization is in the range of 0-100%, because the task computation is relatively small, a lower second scheduling delay parameter can be set so that these tasks can be completed first. For instance, in some stable load scenarios, the task computation is stable; for example, task A executes for 1ms every 100ms, and task B executes for 10ms every 100ms. Thus, if task A is executed first and then task B, the total latency of the two tasks is minimized; if task B is executed first and then task A, task A may need to wait 10ms.
[0093] When the task utilization rate is in the range of 101-500, the corresponding second scheduling delay parameter gradually increases as the task computation increases; when the task utilization rate is in the range of 501-1024, the task computation is large, so the corresponding second scheduling delay parameter can be set to be relatively large.
[0094] This allows for the division of multiple global distribution queues based on task utilization, and the configuration of a corresponding second scheduling delay parameter for each global distribution queue.
[0095] In this embodiment of the application, when the task to be processed selects a first target global distribution queue to join from multiple global distribution queues, the second scheduling delay parameter corresponding to the selected first target global distribution queue is matched with its own first scheduling delay parameter.
[0096] In other words, when a task is selected from multiple global distribution queues to join, only the scheduling latency parameter is considered, without considering other factors. This effectively reduces the time required to select the global distribution queue to be mounted, lowers the proportion of kernel scheduling-related overhead, and reduces power consumption.
[0097] In this embodiment of the application, the method for determining the corresponding first target global distribution queue for the task to be processed based on the first scheduling delay parameter is not limited.
[0098] In some embodiments, the first target global distribution queue corresponding to the task to be processed can be determined according to the mapping relationship between the task to be processed and the global distribution queue. The mapping relationship is the mapping relationship between the first scheduling delay parameter corresponding to the task and the second scheduling delay parameter corresponding to the global distribution queue.
[0099] That is, the mapping relationship between tasks and global distribution queues can be pre-configured. This mapping relationship includes the first scheduling delay parameter corresponding to the task and the second scheduling delay parameter corresponding to the global distribution queue. In this way, after obtaining the first scheduling delay parameter corresponding to the task to be processed, the matching second scheduling delay parameter can be determined from the mapping relationship, thereby determining which global distribution queue corresponds to the second scheduling delay parameter, and using it as the first target global distribution queue.
[0100] For example, if the first scheduling delay parameter corresponding to the task to be processed is A, the second scheduling delay parameter corresponding to global distribution queue 1 is B1, the second scheduling delay parameter corresponding to global distribution queue 2 is B2, the second scheduling delay parameter corresponding to global distribution queue 3 is B3, and so on, the task to be processed can select the closest second scheduling delay parameter from multiple second scheduling delay parameters B1, B2, and B3 based on its corresponding first scheduling delay parameter A, and use its corresponding global distribution queue as the first target global distribution queue.
[0101] Alternatively, in some embodiments, the mapping relationship can directly record the target global distribution queues corresponding to different types of tasks to be processed. For example, if the task to be processed is an audio task, the first target global distribution queue corresponding to the task to be processed can be directly determined as global distribution queue 1 based on the mapping relationship, and the service group to which global distribution queue 1 belongs is the audio service group.
[0102] Step 502: Select the target task from multiple global distribution queues for processing.
[0103] In this embodiment of the application, after the task to be processed is added to the corresponding first target global distribution queue, the scheduler can select the target task from multiple global distribution queues for processing.
[0104] The method for selecting the target task from multiple global distribution queues is not limited. For example, in some embodiments, the target task can be selected from multiple global distribution queues for processing based on the second scheduling delay parameter corresponding to each global distribution queue.
[0105] For example, in some embodiments, the target task can be determined by performing the following steps 601 to 602:
[0106] Step 601: Determine the second target global distribution queue from multiple global distribution queues. The second scheduling delay parameter corresponding to the second target global distribution queue is the smallest parameter among the second scheduling delay parameters corresponding to multiple global distribution queues.
[0107] Understandably, the smaller the second scheduling delay parameter corresponding to the global distribution queue, the shorter the waiting time allowed by the global distribution queue, meaning that the tasks in the global distribution queue may be tasks that require immediate response.
[0108] Therefore, in this embodiment of the application, when selecting a target task for processing, the global distribution queue corresponding to the smallest second scheduling delay parameter can be selected by comparing the second scheduling delay parameter corresponding to each global distribution queue, and this global distribution queue can be used as the second target global distribution queue.
[0109] In other words, multiple global distribution queues can be sorted in ascending order of the second scheduling delay parameter, and the global distribution queue with the lowest second scheduling delay parameter can be selected as the second target global distribution queue.
[0110] Step 602: Determine the first task in the second target global distribution queue as the target task.
[0111] In this embodiment of the application, since the global distribution queue is maintained according to the first-in-first-out principle, after the second target global distribution queue is determined, the task ranked first in it can be taken as the target task and processing resources can be allocated to it for processing.
[0112] As can be seen, in this embodiment, when selecting a task for execution, it is not limited to a single global distribution queue, but rather selects from multiple global distribution queues. This is a global consideration, and the selected target task is globally optimal, rather than locally optimal. In this way, when selecting a target task for execution, the global characteristics of the global distribution queue are used to ensure the load balance of each core processor, thereby balancing overhead and reducing the proportion of scheduling overhead related to the scheduling kernel.
[0113] In the embodiments of this application, different core processors select target tasks from a global perspective, that is, they select target tasks from multiple global distribution queues, which can effectively prevent different core processors from selecting the same target task for processing.
[0114] Furthermore, in some embodiments, the number of accesses to multiple global distribution queues can be reduced, such as reducing the frequency of scheduling points, so as to effectively prevent different core processors from selecting the same target task for processing.
[0115] Understandably, during task scheduling, tasks in the global distribution queue with lower second scheduling delay parameters may be prioritized for processing, while tasks in the global distribution queue with higher second scheduling delay parameters may remain waiting to be scheduled. For example, the lowest second scheduling delay parameter might be 1ms, while the highest might be 128ms, a significant difference. This could lead to tasks in the global distribution queue with higher second scheduling delay parameters continuing to wait for processing even after exceeding their corresponding first scheduling delay parameter, resulting in an imbalance in resource allocation.
[0116] Based on this, in some embodiments, a detection point can be set, and if a third target global distribution queue is detected among multiple global distribution queues, the first task in the third target global distribution queue is taken as the target task for the next execution, and the waiting time corresponding to the first task in the third target global distribution queue is greater than the second scheduling delay parameter corresponding to the third target global distribution queue.
[0117] In other words, if the waiting time of the first task in the third target global distribution queue exceeds the second scheduling delay parameter corresponding to that queue (e.g., the second scheduling delay parameter is 128ms, and the waiting time of the first task in that queue has exceeded 128ms), then the next target task will be selected from that queue. When selecting a task from the third target global distribution queue, the first-in-first-out (FIFO) maintenance principle is also followed, selecting the first task as the next target task.
[0118] This ensures that pending tasks do not have to wait too long, thus guaranteeing a balanced allocation of resources.
[0119] In some embodiments, where multiple core processors exist, different core processors can select tasks from different global distribution queues based on their varying computing power. For example, a core processor with weaker computing power can select a target task from a global distribution queue with a higher second scheduling latency parameter. This reduces the computational demands on the core processor due to the higher second scheduling latency parameter, thus avoiding overloading the core processor.
[0120] Understandably, during the execution of the target task, other scheduling conditions may arise, which will interrupt the execution of the target task. The processor will then execute the task corresponding to the scheduling condition, thus failing to guarantee that the target task will be completed as expected.
[0121] Therefore, in this embodiment, all scheduling conditions except for the necessary ones are cancelled. This unifies the scheduling class, avoids the preemption of high-priority scheduling classes, thereby reducing the overhead of task switching and avoiding the overhead of maintaining the hierarchical organization of the original CFS scheduling class.
[0122] In some embodiments, necessary scheduling conditions may include a clock interruption or a task voluntarily relinquishing processing resources.
[0123] In this context, "task voluntarily relinquishing processing resources" means that a running task (or process, thread) voluntarily relinquishes its access to core processors or other critical resources before completing its work, allowing other tasks to acquire these resources and continue execution. This mechanism is typically based on task cooperation and scheduling strategies to ensure the fair allocation and efficient utilization of system resources.
[0124] Clock interrupts, also known as periodic interrupt preemption, have a periodic interrupt preemption period that depends on the Hertz frequency configuration. The Hertz frequency determines the period of the system clock interrupt. For example, a Hertz frequency of 100 means 100 clock hardware interrupts per second, with each interrupt spaced 10 milliseconds apart. This periodic interrupt provides a time base for the system, enabling it to perform periodic tasks or checks at predetermined time intervals.
[0125] Periodic interrupt preemption refers to the preemptive scheduling of tasks or threads triggered by periodic interrupts generated by timers in an operating system. This mechanism ensures that the system can switch tasks or threads at predetermined time intervals, thereby improving system responsiveness and fairness. A timer is a hardware component that generates interrupt signals at preset time intervals. When the timer reaches its set time, it sends an interrupt signal to the core processor, requesting the core processor to suspend the currently executing task or thread and jump to the interrupt handler for execution.
[0126] An interrupt handler is a piece of code in the operating system kernel that handles interrupts generated by timers. Within the interrupt handler, the operating system checks whether the current task has completed its scheduled time slice or should be preempted. If the current task's time slice has expired or it should be preempted, the interrupt handler saves the current task's context and proceeds to handle the new task.
[0127] Context switching refers to the process by which the operating system saves the context of the current task (such as the program counter, register contents, etc.) and loads the context of the next task when switching tasks. Context switching is one of the key steps in preemptive multitasking, ensuring seamless switching between tasks or threads.
[0128] In this way, when selecting a target task from multiple loading queues for processing, the target task will only be stopped and the task corresponding to the scheduling condition will be switched to be processed when the necessary scheduling condition is met.
[0129] Of course, in some embodiments, after the task corresponding to the scheduling condition has been processed, the process can be switched back to continue processing the target task to ensure the successful completion of the target task.
[0130] When switching back to continue processing the target task, processing can continue based on the previously saved context of the target task (such as the program counter, register contents, etc.) to avoid repeating tasks that have already been processed by the target task.
[0131] In this embodiment of the application, by reducing scheduling conditions, the target task can be effectively prevented from being frequently interrupted during processing, ensuring that the target task can be completed as expected.
[0132] In this embodiment, when the task to be processed is in an awakened state, a first target global distribution queue corresponding to the task to be processed is determined according to the first scheduling delay parameter corresponding to the task to be processed, and the task to be processed is added to the first target global distribution queue. Subsequently, a target task is selected from multiple global distribution queues used to mount unprocessed tasks for processing to complete the task scheduling. The first target global distribution queue to which the task to be processed is added is one of multiple global distribution queues, and the second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. The first scheduling delay parameter indicates the maximum acceptable delay time for the task to be processed. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0133] In this way, when a task is to be processed selects the first target global distribution queue to join from multiple global distribution queues, it only needs to determine the task's scheduling delay parameter and the global distribution queue's scheduling delay parameter, without having to consider other factors. This reduces the time required for the task to select the global distribution queue to be attached, reduces the proportion of kernel scheduling-related overhead, and reduces power consumption.
[0134] The following describes an exemplary application of the embodiments of this application in a real-world application scenario.
[0135] Figure 7 The overall flow of the task scheduling method provided in the embodiments of this application is as follows. Figure 7 As shown, the method includes the following:
[0136] In this embodiment, based on the native grouping of the Android system, two main categories are divided according to key business types. One category is the core business group, and the other is the non-core business group.
[0137] The core business group may include audio, touch, display, and network groups, and the tasks within it are the participation tasks of various key modules in the Android system in real user scenarios (such as short videos, games, map navigation, etc.).
[0138] The non-core business groups include the native Android system groups, namely: top-app group, foreground task group, system service group, kernel task group, default group, and background task group.
[0139] Here, each group of tasks no longer maintains a set state or hierarchical data in the internal core processor.
[0140] Based on the grouping logic described above, a corresponding scheduling delay parameter is set for each group. The scheduling delay parameter for non-core business groups is adjustable, while the scheduling delay parameter for core business groups is specified by the kernel. Furthermore, the minimum scheduling delay parameter for non-core business groups cannot be lower than the maximum scheduling delay parameter for core business groups. In other words, the task latency requirements for core business groups are all higher than those for non-core business groups, with the audio group within the core business groups having the lowest scheduling delay setting.
[0141] In addition, within the kernel, a global dispatch queue is built for each group. Each global dispatch queue has its own scheduling latency parameter and is maintained in a FIFO (First-In, First-Out) queue format. Because there are multiple service groups, the system no longer uses a single-core processor-corresponding ready queue (percpu-rq), but instead adopts a multi-global dispatch queue format (multi-global dsq). Tasks will be enqueued and scheduled according to the new rules.
[0142] For the entire system, all tasks except the original high-priority stop scheduling class will be switched to the new scheduling class. The new scheduling class also has the sched_entity scheduling entity, but adds a scheduling delay request parameter.
[0143] In this way, when a task is in the awakened state, it can select the global distribution queue corresponding to the business group whose scheduling delay parameter is closest to its own, and place it into that global distribution queue. That is, the task is placed into the global distribution queue corresponding to the business group whose scheduling delay parameter is closest to the task's scheduling delay parameter.
[0144] Here, the scheduling delay parameters for the tasks can be configured according to user needs, or they can follow the scheduling delay parameters configured by the business group according to the grouping logic. When a task needs to be executed, after being woken up from a blocked or dormant state, it does not need to execute the original wake-up core selection logic, but is directly added to the global distribution queue corresponding to its task group, thereby reducing the additional overhead caused by core selection.
[0145] In this embodiment, all scheduling points except for periodic interrupts and task voluntary relinquishment are cancelled. Thus, when a scheduling point arrives (such as a periodic interrupt or task relinquishment), the corresponding core processor no longer focuses solely on tasks in its own single queue, but instead, from a global perspective, selects the first task in each of multiple global distribution queues based on queue scheduling latency from low to high for execution.
[0146] Meanwhile, the scheduling follows these rules: core processors with weaker computing power only select tasks from the global distribution queues corresponding to non-core business groups. Furthermore, a detection point is set during task distribution. When an overdue task is detected in another global distribution queue (i.e., the scheduling delay parameter of the first task in that global queue has exceeded the current global queue's set scheduling delay parameter), the overdue task in that global distribution queue will be prioritized for distribution in the next task distribution.
[0147] This implementation modifies the kernel scheduling method by removing task wake-up logic and hierarchical maintenance logic, while also reducing scheduling points. This significantly reduces the proportion of kernel scheduling overhead, thus lowering power consumption; furthermore, it ensures minimal task scheduling latency.
[0148] Implementing this embodiment involves setting up a global task distribution queue on electronic devices, abandoning traditional time-slice allocation scheduling, and adopting a scheduling latency-based approach for global task distribution. Simultaneously, to ensure the accuracy of global distribution, tasks throughout the system are finely grouped, and appropriate scheduling latency parameters are configured for scenario-based service-based groups.
[0149] It should be understood that although the steps in the above flowcharts are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the above flowcharts may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0150] Based on the foregoing embodiments, this application provides a task scheduling device, which includes various modules and units included in each module, and can be implemented by a processor; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.
[0151] Figure 8 This is a schematic diagram of the structure of the task scheduling device provided in the embodiments of this application, as shown below. Figure 8 As shown, the device 800 includes a determining module 801 and a processing module 802, wherein:
[0152] The determining module 801 is configured to, when the task to be processed is in a wake-up state, determine the first target global distribution queue corresponding to the task to be processed based on the first scheduling delay parameter corresponding to the task to be processed, and add the task to the first target global distribution queue. The first target global distribution queue is one of multiple global distribution queues. The second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. Each global distribution queue is used to mount unprocessed tasks. The first scheduling delay parameter is used to indicate the maximum delay time that the task to be processed can accept. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs.
[0153] The processing module 802 is used to select a target task from the multiple global distribution queues for processing.
[0154] In some embodiments, the determining module 801 is specifically used to determine the first target global distribution queue corresponding to the task to be processed based on the mapping relationship between the task to be processed and the global distribution queue, wherein the mapping relationship is the mapping relationship between the first scheduling delay parameter corresponding to the task and the second scheduling delay parameter corresponding to the global distribution queue.
[0155] In some embodiments, the processing module 802 is specifically configured to select a target task from a plurality of global distribution queues for processing based on the second scheduling delay parameter corresponding to each of the global distribution queues.
[0156] In some embodiments, the processing module 802 includes a first processing submodule and a second processing submodule;
[0157] The first processing submodule is configured to determine a second target global distribution queue from a plurality of global distribution queues, wherein the second scheduling delay parameter corresponding to the second target global distribution queue is the smallest parameter among the second scheduling delay parameters corresponding to the plurality of global distribution queues;
[0158] The second processing submodule is used to determine the first task in the second target global distribution queue as the target task.
[0159] In some embodiments, the device further includes a detection module;
[0160] The detection module is used to, when a third target global distribution queue is detected among the multiple global distribution queues, take the first task in the third target global distribution queue as the target task to be executed next, wherein the waiting time corresponding to the first task in the third target global distribution queue is greater than the second scheduling delay parameter corresponding to the third target global distribution queue.
[0161] In some embodiments, the apparatus further includes a creation module;
[0162] The creation module is used to create a global distribution queue corresponding to each business group. Different business groups belong to different scenario types.
[0163] In some embodiments, the service group includes multiple core service groups and multiple non-core service groups, and the scheduling delay parameters corresponding to the core service groups are all smaller than the scheduling delay parameters corresponding to the non-core service groups.
[0164] In some embodiments, the processing module 802 is further configured to stop running the target task when a scheduling condition occurs, and switch to the task corresponding to the scheduling condition for processing. The scheduling condition includes the arrival of a clock interrupt or the task actively relinquishing processing resources.
[0165] The descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0166] It should be noted that, in the embodiments of this application... Figure 8 The module division of the task scheduling device shown is illustrative and represents only one logical functional division; in actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, exist as separate physical units, or be integrated into one unit by two or more units. The integrated units can be implemented in hardware, as software functional units, or a combination of both.
[0167] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0168] This application provides a computer device, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements the methods described above.
[0169] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in the above embodiments.
[0170] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the method provided in the above-described method embodiments.
[0171] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0172] In one embodiment, the task scheduling device provided in this application can be implemented as a computer program, and the computer program can be implemented as follows: Figure 9The device operates on the computer device shown. The memory of the computer device can store the various program modules that make up the above-described apparatus. The computer program, composed of the various program modules, causes the processor to execute the steps of the methods in the various embodiments of this application described in this specification.
[0173] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0174] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" mentioned throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.
[0175] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.
[0176] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0177] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or modules can be electrical, mechanical, or other forms.
[0178] The modules described above as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.
[0179] In addition, each functional module in the various embodiments of this application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the integrated modules can be implemented in hardware or in the form of hardware plus software functional units.
[0180] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0181] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0182] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0183] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0184] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0185] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A task scheduling method, characterized in that, The method includes: When a task to be processed is in an awake state, a first target global distribution queue corresponding to the task to be processed is determined according to the first scheduling delay parameter corresponding to the task to be processed. The task to be processed is added to the first target global distribution queue. The first target global distribution queue is one of multiple global distribution queues. The second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. Each global distribution queue is used to mount unprocessed tasks. The first scheduling delay parameter is used to indicate the maximum delay time that the task to be processed can accept. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs. Select a target task from the multiple global distribution queues for processing.
2. The method according to claim 1, characterized in that, The step of determining the first target global distribution queue corresponding to the task to be processed based on the first scheduling delay parameter corresponding to the task to be processed includes: Based on the mapping relationship between the task to be processed and the global distribution queue, the first target global distribution queue corresponding to the task to be processed is determined. The mapping relationship is the mapping relationship between the first scheduling delay parameter corresponding to the task and the second scheduling delay parameter corresponding to the global distribution queue.
3. The method according to claim 1, characterized in that, The step of selecting a target task from the multiple global distribution queues for processing includes: Based on the second scheduling delay parameter corresponding to each of the global distribution queues, a target task is selected from the plurality of global distribution queues for processing.
4. The method according to claim 3, characterized in that, The step of selecting a target task for processing from multiple global distribution queues based on the second scheduling delay parameter corresponding to each of the global distribution queues includes: A second target global distribution queue is determined from the plurality of global distribution queues, wherein the second scheduling delay parameter corresponding to the second target global distribution queue is the smallest parameter among the second scheduling delay parameters corresponding to the plurality of global distribution queues; The first task in the second target global distribution queue is determined as the target task.
5. The method according to claim 1, characterized in that, The method further includes: If a third target global distribution queue is detected among multiple global distribution queues, the first task in the third target global distribution queue is taken as the target task for the next execution, and the waiting time corresponding to the first task in the third target global distribution queue is greater than the second scheduling delay parameter corresponding to the third target global distribution queue.
6. The method according to claim 1, characterized in that, Before determining the first target global distribution queue corresponding to the task to be processed, the method further includes: Create a global distribution queue for each business group, with different business groups belonging to different scenario types.
7. The method according to claim 6, characterized in that, The business group includes multiple core business groups and multiple non-core business groups, and the scheduling delay parameters corresponding to the core business groups are all smaller than the scheduling delay parameters corresponding to the non-core business groups.
8. The method according to claim 3, characterized in that, In the process of selecting a target task from the plurality of mounting queues for processing, the method further includes: When a scheduling condition occurs, the target task is stopped and the task corresponding to the scheduling condition is switched to handle the task. The scheduling condition includes the arrival of a clock interrupt or the task actively relinquishing processing resources.
9. A task scheduling device, characterized in that, include: The determination module is used to determine the first target global distribution queue corresponding to the task to be processed based on the first scheduling delay parameter corresponding to the task to be processed when the task to be processed is in the wake-up state, and to add the task to the first target global distribution queue. The first target global distribution queue is one of multiple global distribution queues. The second scheduling delay parameter corresponding to the first target global distribution queue matches the first scheduling delay parameter. Each global distribution queue is used to mount unprocessed tasks. The first scheduling delay parameter is used to indicate the maximum delay time that the task to be processed can accept. The first scheduling delay parameter corresponding to any task in any global distribution queue is less than or equal to the second scheduling delay parameter corresponding to the global distribution queue to which it belongs. The processing module is used to select a target task from the multiple global distribution queues for processing.
10. A computer device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 8.