Task scheduling method and device and storage medium
By identifying the task type and scheduling it to the corresponding processor core, it solves the problem of resource waste and low operating efficiency caused by the binding of the core and lightweight threads, and achieves more efficient task scheduling and resource utilization.
Patent Information
- Application Number
- CN202310387028.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-01
AI Technical Summary
When the processor core performs task scheduling, due to the binding relationship between the core and lightweight threads, the core cannot flexibly schedule other threads, causing the CPU to wait for a long time for IO operations, wasting resources and low overall operating efficiency.
By identifying task types and scheduling tasks to corresponding processor cores based on their characteristics, it avoids IO-intensive tasks from occupying the CPU and affects the processing of other tasks, and improves the operating efficiency of overall resources.
It effectively reduces the waste of resources caused by task blocking and improves the operating efficiency of the kernel and overall system performance.
Smart Images

Figure CN118733210A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task scheduling method, device and storage medium. Background Art
[0002] Currently, when the processor core performs task scheduling, it schedules based on the thread granularity. The processor core can also be called a kernel. Threads include kernel level threads (KLT), user level threads (ULT) and light weight processes (LWP). LWP is a user-level thread scheduled by the kernel. Each LWP is associated with one or more ULTs, and each LWP is supported by a KLT. The kernel schedules LWP to schedule one or more ULTs associated with it, thereby improving the scheduling efficiency of threads.
[0003] Each core in a multi-core processor has an independent cache space for storing process data. A process consists of one or more threads. When running threads in different processes, the kernel switches the corresponding process data in the cache space. This process is called context switch (CS). In order to avoid repeated switching of processes between different cores, increasing the number of kernel context switches and causing resource waste, LWP is currently bound to the kernel to reduce the number of context switches and improve the kernel cache hit rate.
[0004] However, when the kernel schedules LWP, one or more ULTs associated with LWP may be blocked. At this time, due to the binding relationship between the kernel and LWP, the kernel cannot call other threads, affecting the overall operating efficiency. Summary of the invention
[0005] The embodiments of the present application provide a task scheduling method, device and storage medium for improving the flexibility of task scheduling, reducing resource waste caused by task blocking, and improving the operating efficiency of the kernel.
[0006] To achieve the above objectives, the present application provides the following technical solutions:
[0007] In a first aspect, a task scheduling method is provided, comprising: obtaining a task type of a target task, the task type comprising at least a first task type and a second task type, the first task type and the second task type being processed differently in a central processing unit (CPU); and scheduling the target task to a task queue in a target processor core according to the task type of the target task, wherein the target processor core is used to run tasks of the task type.
[0008] Currently, when there are many IO-intensive tasks, the CPU has to wait for a long time for IO operations because other tasks cannot be flexibly scheduled for processing, resulting in a waste of CPU resources. Through the above method, the computing device schedules the target task to the corresponding processor core according to the task type, thereby avoiding IO-intensive tasks occupying the CPU and affecting the processing of other tasks, thereby improving the overall resource operation efficiency.
[0009] In a possible implementation manner, the task type is pre-marked, and obtaining the task type of the target task includes: identifying the task type of the target task.
[0010] This possible implementation helps the computing device to identify the task type and distinguish the target tasks.
[0011] In a possible implementation, the IO operation duration of the first task type is longer than the CPU operation duration, and the CPU operation duration of the second task type is longer than the IO operation duration.
[0012] In this possible implementation, a method for dividing task types is provided, and tasks are distinguished by the processing time in the CPU.
[0013] In one possible implementation, the task type of the target task is a first task type, and according to the task type of the target task, the target task is scheduled to a task queue in a target processor core, including: scheduling the target task to a task queue in a first processor core, and the first processor core is used to execute tasks of the first task type.
[0014] In this possible implementation, after being divided according to task type, the tasks are scheduled to the corresponding processor cores, so that the corresponding processor cores run tasks of the corresponding task types, avoiding the mixing of task types in different task queues, which affects the overall operating efficiency when blocking occurs.
[0015] In one possible implementation, the task type of the target task is a second task type, and according to the task type of the target task, the target task is scheduled to a task queue in a target processor core, including: scheduling the target task to a task queue in a second processor core, and the second processor core is used to execute tasks of the second task type.
[0016] In this possible implementation, after being divided according to task type, the tasks are scheduled to the corresponding processor cores, so that the corresponding processor cores run tasks of the corresponding task types, avoiding the mixing of task types in different task queues, which affects the overall operating efficiency when blocking occurs.
[0017] In one possible implementation, the task type also includes an unspecified task type; according to the task type of the target task, the target task is scheduled to the task queue in the target processor core, including: scheduling the target task to the task queue in the third processor core for execution, and the third processor core is used to execute tasks of the unspecified task type.
[0018] In this possible implementation, a processor core is separately configured for an unspecified task type, which helps to avoid the impact of unclear task types on the running of other tasks.
[0019] In one possible implementation, the method also includes: obtaining task characteristics of the target task, the task characteristics are used to indicate the running status of the target task in the target processor core; when the task characteristics of the target task meet the task characteristics of the first task type, scheduling the target task from the task queue in the third processor core to the task queue in the first processor core, and the first processor core is used to execute tasks of the first task type.
[0020] This possible implementation helps to monitor the task characteristics during the running process for unspecified task types, so as to perform task migration when the task type is determined.
[0021] In one possible implementation, the task characteristics of the target task include at least one of the following: the CPU waiting time for IO operations and the number of context switches of the target task. The task characteristics of the target task meet the IO-intensive task characteristics, including: the CPU waiting time for IO operations of the target task is greater than or equal to a first threshold, and / or the number of context switches is greater than or equal to a second threshold.
[0022] In this possible implementation, a specific form of task features is provided to improve the feasibility of the solution.
[0023] In one possible implementation, the method also includes: running tasks in a first processor core; obtaining the operating efficiency of the first processor core; when the operating efficiency of the first processor core is lower than a preset operating efficiency, adding at least one task queue in the first processor core and scheduling at least one task to the at least one task queue.
[0024] This possible implementation helps to dynamically adjust the task queue and improve the overall CPU operating efficiency.
[0025] In a second aspect, a task scheduling device is provided, including: a functional unit for executing any one of the methods provided in the first aspect, wherein the actions performed by each functional unit are implemented by hardware or by executing corresponding software through hardware. For example, the device may include: an acquisition unit and a scheduling unit. The acquisition unit is used to acquire the task type of the target task, wherein the task type includes at least a first task type and a second task type, and the first task type and the second task type are processed differently in the central processing unit CPU; the scheduling unit is used to schedule the target task to the task queue in the target processor core according to the task type of the target task, wherein the target processor core is used to run tasks of the task type.
[0026] In a third aspect, a task scheduling device is provided, comprising a processor; the processor is connected to a memory, the memory is used to store computer execution instructions, and the processor executes the computer execution instructions stored in the memory so that the task scheduling device executes any one of the methods provided in the first aspect.
[0027] In a fourth aspect, a chip is provided, comprising: a processor and an interface circuit; the interface circuit is used to receive code instructions and transmit them to the processor; the processor is used to run the code instructions to execute any one of the methods provided in the first aspect.
[0028] In a fifth aspect, a computer-readable storage medium is provided, comprising computer execution instructions, which, when executed on a computer, enable the computer to execute any one of the methods provided in the first aspect.
[0029] In a sixth aspect, a computer program product is provided, comprising computer execution instructions, which, when executed on a computer, cause the computer to execute any one of the methods provided in the first aspect.
[0030] The technical effects brought about by any implementation method in the second to sixth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application;
[0032] Figure 2 A schematic diagram of the relationship between a kernel and a thread provided in an embodiment of the present application;
[0033] Figure 3 A schematic diagram of the relationship between a kernel and a thread provided in an embodiment of the present application;
[0034] Figure 4 A flowchart of a multi-core task scheduling method provided in an embodiment of the present application;
[0035] Figure 5 A schematic diagram of resource configuration of a 6-core processor provided in an embodiment of the present application;
[0036] Figure 6 A flowchart of a multi-core task scheduling method provided in an embodiment of the present application;
[0037] Figure 7 A schematic diagram of a task migration scenario provided in an embodiment of the present application;
[0038] Figure 8 A flowchart of a multi-core task scheduling method provided in an embodiment of the present application;
[0039] Fig. 9 A flowchart of a multi-core task scheduling method provided in an embodiment of the present application;
[0040] Fig.10 A schematic diagram of a scenario for adjusting a task queue provided in an embodiment of the present application;
[0041] Fig.11 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different.
[0043] It should be noted that, in this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0044] The embodiment of the present application provides a task scheduling method, which is applied to a computing device including multiple processor cores. The embodiment of the present application does not impose any restrictions on the specific form of the computing device. For example, the computing device may be a terminal device or a network device. Among them, the terminal device may be referred to as: terminal, user equipment (UE), terminal equipment, access terminal, user unit, user station, mobile station, remote station, remote terminal, mobile device, user terminal, wireless communication device, user agent or user device, etc. The terminal device may be a mobile phone, augmented reality (AR) device, virtual reality (VR) device, tablet computer, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc. The network device may be a server, etc. Among them, the server may be a physical or logical server, or it may be two or more physical or logical servers that share different responsibilities and cooperate with each other to realize the functions of the server.
[0045] In terms of hardware implementation, the above computing device can be implemented as follows: Figure 1 The computing device shown is implemented as shown. Figure 1 , which is a schematic diagram of the hardware structure of a computing device 10 provided in an embodiment of the present application. The computing device 10 can be used to implement the functions of the above computing devices.
[0046] Figure 1 The computing device 10 shown may include: a processor 101 , a memory 102 , a communication interface 103 , and a bus 104 . The processor 101 , the memory 102 , and the communication interface 103 may be connected via the bus 104 .
[0047] The processor 101 is the control center of the computing device 10, including multiple general-purpose central processing units (CPUs), and may also be other general-purpose processors, etc. Among them, the general-purpose processor may be a microprocessor or any conventional processor, etc. Among them, each general-purpose processor is used to represent a processor core, and the processor core may also be called a kernel. The above processor 101 may also be called a multi-core processor.
[0048] As an example, in Figure 1 In the embodiment, the processor 101 may include CPU 0 and CPU 1. The figure is only used as an example, and more CPUs may be included in actual applications.
[0049] The memory 102 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0050] In a possible implementation, the memory 102 may exist independently of the processor 101. The memory 102 may be connected to the processor 101 via a bus 104 and used to store data, instructions, or program codes. When the processor 101 calls and executes the instructions or program codes stored in the memory 102, the task scheduling method provided in the embodiment of the present application can be implemented.
[0051] In another possible implementation, the memory 102 may also be integrated with the processor 101 .
[0052] The communication interface 103 is used for connecting the computing device 10 to other devices via a communication network, which may be Ethernet, a radio access network (RAN), a wireless local area network (WLAN), etc. The communication interface 103 may include a receiving unit for receiving data and a sending unit for sending data.
[0053] The bus 104 may be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 1 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0054] It should be pointed out that Figure 1 The structure shown in the figure does not constitute a limitation on the computing device 10, except Figure 1In addition to the components shown, computing device 10 may include more or fewer components than shown, or combine certain components, or arrange components differently.
[0055] In order to make the embodiments of the present application clearer, the concepts and some contents related to the embodiments of the present application are briefly introduced below.
[0056] 1. Threads
[0057] A thread is the smallest unit that an operating system can use to schedule operations. It is contained in a process and is the actual running unit of the process. In the embodiments provided in this application, a thread is the smallest unit of task scheduling.
[0058] Among them, threads can be divided into the following types: kernel-level threads (kernel-level treads, KLT), light weight threads (light weight process, LWP) and user level threads (user level thread, ULT).
[0059] In a computing device, each processor resource is divided into kernel resources and user resources. KLT is created by kernel resources and called by the kernel. The resources used include the kernel stack and the space for saving registers during context switching. It can compete for processor resources across the entire system. ULT is created by user resources and called by the user, that is, the kernel cannot directly call ULT. LWP is a user-level thread that supports kernel calls. Each LWP is associated with a KLT. One or more ULTs created in user resources are associated with LWP to enable unified kernel calls.
[0060] Currently, ULTs can be created and scheduled through the lightweight thread library (massive threads). In the lightweight thread library, the hardware resources of each core are abstracted as independent workers. Figure 2 As shown, the computing device includes two cores, CPU0 and CPU 1, and five KLTs are created, such as KLT 0 to KLT 4 in the figure. Among them, KLT 0, KLT 1, KLT 3 and KLT 4 support one LWP respectively. The user creates ULT 0 to ULT 4 through the lightweight thread library, and associates LWP 0 and LWP with ULT 0, ULT 1 and ULT 2, associates LWP 2 with ULT 3, and associates LWP 3 with ULT 4. When CPU 0 calls KLT 0, LWP 0 and ULT 0, ULT 1 and ULT 2 associated with LWP 0 are scheduled accordingly.
[0061] 2. Thread Scheduling
[0062] Currently, thread scheduling includes the following two methods:
[0063] Method 1: Implement thread scheduling based on lightweight threads.
[0064] In order to reduce the switching of processes between different cores, which leads to a decrease in the kernel cache hit rate, lightweight threads are bound to the core based on CPU affinity so that the execution stream (ES) managed by the lightweight thread is processed in the same core. For example, when the lightweight thread library Argobots turns on the CPU affinity state, it will bind each ES to a separate CPU and then schedule the ULT. Among them, ES is used to execute one or more threads in the process, which can also be understood as a task queue.
[0065] like Figure 3 As shown, assuming that the computing device starts process A, the processor creates ES 0 for process A to carry the ULT of the subsequent related services of the process. Among them, ES 0 is associated with LWP 0, and LWP 0 is bound to CPU 0, so that the ULT in ES 0 is scheduled by CPU 0, improving the cache hit rate of CPU 0 for the process.
[0066] However, in the above scenario, when the CPU schedules LWP 0 to execute ULT in ES 0, blocking may occur. For example, ULT 0 is used to read hard disk data. When CPU 0 executes ULT 0, it needs to wait for the data to be read. At this time, CPU 0 is in an idle state. This phenomenon can be called CPU blocking. When CPU blocking occurs, the CPU cannot call other threads to run or calculate, which affects the overall operating efficiency of the processor.
[0067] Method 2: Schedule threads based on the number of threads.
[0068] OpenMP is a multiprocessor programming scheme for shared memory parallel systems, including three scheduling strategies: static scheduling, dynamic scheduling, and guided scheduling. Among them, static scheduling is to evenly distribute tasks to each core according to the number of cores. For example, if the processor includes 16 cores, the tasks are evenly distributed to the 16 cores. Dynamic scheduling is to dynamically allocate tasks according to the core processing progress. For example, a task is scheduled for processing on each of the 16 cores, and tasks are continued to be scheduled on the core with faster processing progress according to the processing progress. Heuristic scheduling is a method that combines static scheduling and dynamic scheduling, and dynamically adjusts the allocation strategy according to the number of tasks. For example, when the number of tasks is large, some tasks are evenly distributed to each core according to the static scheduling method, and the remaining tasks are dynamically scheduled to the core with faster processing progress according to the core processing progress.
[0069] However, the above three scheduling strategies also cause CPU blocking, thereby affecting the overall operating efficiency of the processor.
[0070] In this regard, the present application provides a task scheduling method, which distinguishes tasks according to the ratio of CPU resources to IO resources used, and then schedules them to the corresponding cores, thereby improving the overall operating efficiency of the processor. Figure 4 As shown, the method includes the following steps S401-S402.
[0071] S401: The computing device obtains the task type of the target task.
[0072] The task type includes at least a first task type and a second task type, wherein the first task type and the second task type are processed differently in the CPU.
[0073] Optionally, the task type includes CPU intensive and IO intensive. CPU intensive is used to indicate tasks that use more CPU operation time than IO operation time. IO intensive is used to indicate tasks that use more IO operation time than CPU operation time.
[0074] For example, task A is to read a file stored in a computing device. Specifically, the CPU reads according to the file storage address. During the execution of this task, the CPU needs to read the hard disk or other storage components, which involves many IO operations, but no calculations are required in the CPU. Therefore, task A is an IO-intensive task. Similarly, most tasks involving networks and disks are IO-intensive tasks. For another example, task B is to calculate pi to less than one hundred decimal places. The CPU performs calculations for this task, and the process does not involve IO operations such as reading or writing data to other components of the computing device by the CPU, so task B is a CPU-intensive task.
[0075] In a possible implementation, the task type is pre-labeled, and the above step S401 specifically includes: the computing device identifies the task type of the target task. Specifically, when the target task is created, it carries a task type label, and the computing device obtains the task type by reading the label.
[0076] It is understandable that during the program development stage, technicians can label the task type. In combination with the above examples of task types, the task type label can specifically include IO intensive and CPU intensive. When the computing device creates a corresponding task based on the user's instructions, the task type is obtained by reading the task type label.
[0077] For example, for a certain application, a user can store and read files, and a technician can pre-configure the task type label as IO intensive for the program that triggers this function, so that when the program is run, the computing device creates a corresponding task and obtains the task type label as IO intensive.
[0078] It should be noted that the task type of the target task may also include an unspecified task type. For example, when the computing device cannot obtain the task type by identifying the task type tag, it may be determined as an unspecified task type.
[0079] S402: The computing device schedules the target task to a task queue in a target processor core according to a task type of the target task, wherein the target processor core is used to run tasks of the above task type.
[0080] Among them, the task queue in the target processor core can be understood as the above Figure 3 The execution flow shown. Each task queue can carry one or more tasks, which can be understood as carrying one or more ULTs in the execution flow.
[0081] The target processor core has a corresponding relationship with the task type. Exemplarily, the computing device includes at least two processor cores, and the at least two processor cores are partially used to execute CPU-intensive tasks, and the remaining part is used to execute IO-intensive tasks.
[0082] The number of processor cores that execute a specified task type may be preset in the computing device.
[0083] In one possible implementation, the computing device specifies the type of task to be performed by each core. For example, common multi-core processors include dual-core, quad-core, 8-core, 12-core, and 16-core. For a 16-core processor, 6 cores can be preset to perform IO-intensive tasks, and the remaining 10 cores can be used to perform CPU-intensive tasks.
[0084] In another possible implementation, the computing device configures the number of cores for executing different types of tasks according to a preset ratio. For example, the preset ratio of cores for IO-intensive tasks to CPU-intensive tasks is 3:5. For a 16-core processor, 6 cores are used to execute IO-intensive tasks and 10 cores are used to execute CPU-intensive tasks. The above method helps the computing device to determine the cores for executing different types of tasks according to the preset ratio, saving configuration costs.
[0085] It should be noted that, in the above step S401, when the computing device cannot determine the task type of the target task, that is, the target task is a task of unspecified task type, the computing device may also pre-configure an independent kernel for processing this type of task. Alternatively, the computing device may also schedule this type of task as a CPU-intensive task or an IO-intensive task to be processed in a corresponding kernel.
[0086] In combination with the task type in the above step S401, step S402 specifically includes the following three possible implementation methods.
[0087] In a first possible implementation, the task type of the target task is IO intensive, and the above step S402 specifically includes: the computing device schedules the target task to a task queue in a first processor core, and the first processor core is used to execute IO intensive tasks.
[0088] In a second possible implementation, the task type of the target task is CPU intensive, and the above step S402 specifically includes: the computing device schedules the target task to a task queue in the second processor core, and the second processor core is used to execute the CPU intensive task.
[0089] In a third possible implementation, the task type of the target task is an unspecified task type, and the above step S402 specifically includes: the computing device schedules the target task to a task queue in the third processor core, and the third processor core is used to execute tasks of the unspecified task type.
[0090] like Figure 5 FIG. 1 is a schematic diagram of resource configuration of a 6-core processor. Among them, CPU 0 and CPU 1 are used to perform IO-intensive tasks, and ES 0 and ES 1 are marked with (IO) in the figure. CPU 2, CPU 3, and CPU 4 are used to perform CPU-intensive tasks, and ES 2, ES 3, and ES 4 are marked with (CPU) in the figure. In addition, CPU 5 is used to perform tasks of unspecified task types, and ES 5 is marked with (unspecified) in the figure.
[0091] It should be noted that, in the above example, the CPU 5 used to execute unspecified task types can also be used to execute IO-intensive tasks or CPU-intensive tasks. In other words, there is no restriction on the kernels scheduled for tasks of unspecified task types.
[0092] It should be noted that the above-mentioned task scheduling process can be executed by any one of the multiple cores in the computing device. For example, assuming that the computing device includes 6 cores, core 1 can schedule tasks to the task queues of the remaining 5 cores. In addition, core 1 itself can also run tasks of a certain task type. For example, task queue 1 in core 1 is used for task scheduling, and the remaining task queues can be used to execute CPU-intensive tasks.
[0093] Optionally, the computing device performs task scheduling according to a round-robin dispatching strategy, wherein the round-robin dispatching strategy refers to scheduling according to the order in which the tasks are created.
[0094] Currently, when there are many IO-intensive tasks, the CPU is idle because other tasks cannot be flexibly scheduled for processing, resulting in a waste of resources. Through the above method, the computing device pre-divides the resources of the processor core according to the task type, and schedules the target task to the corresponding processor core according to the task type of the target task, so that part of the resources in the processor are always used to execute CPU-intensive tasks, thereby improving the overall resource operation efficiency.
[0095] It should be noted that the current task types are divided into IO intensive and CPU intensive, and the embodiment of the present application schedules tasks to the processor core that performs the corresponding task type based on the task type. Further, the priority of the task can also be obtained, and the task can be scheduled according to the priority of the task. For example, when the task is created, the user marks the priority of the task in advance, and when the priority of the task is higher, the task can be scheduled to the first place in the task queue.
[0096] Optionally, the above method also includes: the computing device runs the target task in the task queue in the target processor core, obtains the task characteristics of the target task, and adjusts the scheduling strategy according to the task characteristics of the target task.
[0097] Optionally, when the target processor core is the third processor core, the target task is a task of an unspecified task type, and adjusting the scheduling strategy according to the task characteristics of the target task specifically includes: the computing device runs the target task in the third processor core, obtains the task characteristics of the target task, and when the task characteristics of the target task meet the IO-intensive task characteristics, schedules the target task to the task queue in the first processor core, and the first processor core is used to execute IO-intensive tasks.
[0098] Among them, the task characteristics of the target task are used to indicate the running state of the target task in the target processor core. Specifically, the task characteristics include at least one of the following: the CPU waiting time for IO operation and the number of context switches of the target task. Among them, the CPU waiting time for IO operation can be expressed by the percentage of the CPU waiting time for IO completion (%IO wait). The task characteristics of the above-mentioned target task meet the IO-intensive task characteristics, including: the CPU waiting time for IO operation of the target task is greater than or equal to the first threshold, and / or, the number of context switches is greater than or equal to the second threshold. Among them, the first threshold and the second threshold are preset thresholds.
[0099] Optionally, the above task features are considered in order of priority. Specifically, Figure 6 As shown, steps S601-S604 are included.
[0100] S601: The computing device obtains task characteristics of a target task.
[0101] S602: Determine whether the CPU wait time for the IO operation is greater than or equal to a first threshold.
[0102] If so, execute step S603; if not, do not adjust the scheduling strategy and continue to run the target task in the current task queue.
[0103] S603: Determine whether the number of context switches is greater than or equal to a second threshold.
[0104] If yes, step S604 is executed; if no, the scheduling strategy is not adjusted and the target task continues to be executed in the current task queue.
[0105] S604: Schedule the target task to the task queue of the first processor core.
[0106] Optionally, scheduling the target task to the task queue of the first processor core includes: scheduling the target task to the end of the task queue in the first processor core; or creating a new task queue in the first processor core for executing the target task. Figure 5 The scene shown in Figure 7 In the example, when ULT 2 meets the IO-intensive task characteristics, ULT 2 can be scheduled to ES 0 or ES 1, for example, to the end of ES 1. Alternatively, a new ES can be created in CPU 0 or CPU 1 to run ULT 2. For example, a new ES 6 is created in CPU 0 and ULT 2 is scheduled to ES 6.
[0107] It can be understood that when it is determined that the CPU waiting time for IO operations exceeds the preset first threshold, it means that the current task uses less CPU resources. Further, the number of context switches of the task is judged. If the number exceeds the second threshold, it means that the task involves more IO operations and causes blocking to the CPU. Therefore, the task can be scheduled to the task queue that executes IO-intensive tasks to improve the execution efficiency of the current CPU.
[0108] It should be noted that the third processor core is used to execute tasks of unspecified task types. When the third processor core is used to execute IO-intensive tasks, a new execution flow can be created in the third processor core for the target task to run the task, or it can be scheduled to other IO-intensive task queues, such as Figure 7 When the third processor core is used to execute CPU-intensive tasks, the target task can be scheduled according to the above steps S601-S604.
[0109] Combination Figure 4 The present application also provides a task scheduling method, such as Figure 8 As shown, steps S801-S808 are included.
[0110] S801. Create a target task.
[0111] S802: Determine whether to specify a task type.
[0112] If yes, execute step S803; if no, execute step S804.
[0113] The task type of the target task is identified in step S801, including IO-intensive, CPU-intensive and unspecified task types.
[0114] For the description of the task type, please refer to the above step S401.
[0115] S803: Determine whether it is IO intensive.
[0116] If yes, execute step S805; if no, execute step S804.
[0117] S804: Schedule the target task to the task queue of the second processor core.
[0118] S805 , scheduling the target task to the task queue of the first processor core.
[0119] It can be understood that through the above steps S803-S805, IO-intensive tasks are scheduled to the first processor core, and CPU-intensive tasks and tasks of unspecified task types are scheduled to the second processor core, so that most of the IO-intensive tasks are concentrated on some cores for processing, so that the remaining cores are mainly used to process CPU-intensive tasks, so as to avoid IO-intensive tasks blocking the core and affecting the operation of other tasks.
[0120] S806: Determine whether it is CPU intensive.
[0121] The task queue of the second processor core also includes CPU-intensive tasks and tasks of unspecified task types. This step can filter out the specified CPU-intensive tasks.
[0122] If yes, the CPU-intensive task can continue to be processed on the second processor core, or can also be scheduled to the task queue of other processor cores for executing CPU-intensive tasks. If no, continue to execute step S807.
[0123] If the processor core currently performing task scheduling is used to execute CPU-intensive tasks, the CPU-intensive tasks can be scheduled to run in other task queues.
[0124] S807. Monitor task characteristics.
[0125] S808: Determine whether the IO-intensive task characteristics are met.
[0126] If yes, execute step S805; if no, continue processing in the second processor core.
[0127] Among them, through the above steps S807-S808, tasks of unspecified task types are monitored, and when the task characteristics meet the requirements of IO-intensive tasks, they can be scheduled to the task queue of the first processor core to achieve task migration, thereby helping to improve the processing efficiency of the second processor core.
[0128] pass Figure 8 In the method shown, the computing device initially schedules tasks according to the task type during the task creation stage, and adjusts the scheduling strategy in real time by monitoring the task characteristics during the execution of tasks of unknown task types, thereby avoiding IO-intensive tasks from blocking the processor core and affecting the execution of other tasks, thereby improving the overall processing efficiency of the computing device.
[0129] Optionally, during the execution of an IO-intensive task, when the target processor core is the first processor core, the target task is an IO-intensive task, and adjusting the scheduling strategy according to the task characteristics of the target task specifically includes: the computing device runs the task in the first processor core, obtaining the running status of the first processor core, and when the running status of the first processor core is lower than the preset execution efficiency, adding a task queue in the first processor core, and scheduling the task to run in the newly added task queue.
[0130] The operation status of the first processor core is used to indicate the usage of the IO resources and CPU resources of the first processor core. Specifically, the operation status of the first processor core is represented by the CPU waiting time for IO operations and / or the number of context switches within a preset time period. Lower than the preset execution efficiency is represented by exceeding the preset threshold of the CPU waiting time for IO operations and / or the number of context switches.
[0131] In a possible implementation, the priority order of the CPU waiting time for IO operation and the number of context switches is considered. Fig. 9 As shown, steps S901-S904 are included.
[0132] S901. Obtain the operating status of a first processor core.
[0133] S902: Determine whether the CPU wait time for the IO operation is greater than or equal to a third threshold.
[0134] If yes, execute step S903; if no, end the process.
[0135] S903: Determine whether the number of context switches is greater than or equal to a fourth threshold.
[0136] If yes, execute step S904; if no, end the process.
[0137] Among them, the third threshold and the fourth threshold are preset thresholds, the third threshold may be the same as or different from the above-mentioned first threshold, and the fourth threshold may be the same as or different from the above-mentioned second threshold.
[0138] S904. Add a new task queue and perform task migration.
[0139] For example, Fig.10 In the scenario shown, when the operation of CPU 0 meets the above conditions, the task queue of CPU 0 is increased from 1 to 3 to improve the execution efficiency of CPU 0.
[0140] It should be noted that the number of the newly added task queues is not limited. For example, if S903 is satisfied, one task queue is added, and the above Fig. 9step to determine whether to continue increasing, and repeat this cycle until the CPU meets the preset execution efficiency.
[0141] Optionally, the task migration includes migrating at least one task to the newly added task queue. Alternatively, tasks in the CPU are evenly distributed to each task queue according to the number of newly added task queues. Fig.10 In the example, if ES 0 has 9 tasks, after adding, each ES can include 3 tasks.
[0142] It can be understood that the above method helps to monitor the CPU status of IO-intensive tasks. When the CPU efficiency is low, a new task queue can be added to increase the number of parallel tasks to reduce the CPU waiting time during IO requests, fully utilize CPU resources, and improve CPU efficiency.
[0143] It should be noted that the above method can be applied to a computing device with a multi-core processor, and can also be applied to a computing device with multiple single-core processors, and this application does not impose any restrictions on this.
[0144] The above mainly introduces the scheme of the embodiment of the present application from the perspective of the method. It is understandable that in order to realize the above functions, the computing device includes at least one of the hardware structure and software modules corresponding to the execution of each function. It should be easily appreciated by those skilled in the art that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0145] The embodiment of the present application can divide the computing device into functional units according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0146] In the case of dividing each functional module into corresponding functional modules, Fig.11 A possible structural diagram of the computing device involved in the above embodiment is shown. Fig.11 As shown, the computing device 110 includes an acquisition unit 1101 and a scheduling unit 1102 .
[0147] The acquisition unit 1101 is used to acquire the task type of the target task, where the task type includes at least a first task type and a second task type. The first task type and the second task type are processed differently in the central processing unit CPU.
[0148] The scheduling unit 1102 is used to schedule the target task to a task queue in a target processor core according to the task type of the target task, wherein the target processor core is used to run tasks of the task type.
[0149] In an example, the task type is pre-marked, and the acquisition unit 1101 is specifically used to identify the task type of the target task.
[0150] In one example, the IO operation duration of the first task type is longer than the CPU operation duration, and the CPU operation duration of the second task type is longer than the IO operation duration.
[0151] In an example, the task type of the target task is a first task type, and the scheduling unit 1102 is specifically used to schedule the target task to a task queue in a first processor core, and the first processor core is used to execute tasks of the first task type.
[0152] In an example, the task type of the target task is a second task type, and the scheduling unit 1102 is specifically used to schedule the target task to a task queue in the second processor core, and the second processor core is used to execute tasks of the second task type.
[0153] In one example, the task type also includes an unspecified task type; the scheduling unit 1102 is specifically used to schedule the target task to the task queue in the third processor core for execution, and the third processor core is used to execute tasks of the unspecified task type.
[0154] In one example, the acquisition unit 1101 is also used to acquire task characteristics of the target task, which are used to indicate the running status of the target task in the target processor core; the scheduling unit 1102 is also used to schedule the target task from the task queue in the third processor core to the task queue in the first processor core when the task characteristics of the target task meet the task characteristics of the first task type, and the first processor core is used to execute tasks of the first task type.
[0155] In one example, the task characteristics of the target task include at least one of the following: the CPU waiting time for IO operations of the target task and the number of context switches. The task characteristics of the target task meet the task characteristics of the first task type, including: the CPU waiting time for IO operations of the target task is greater than or equal to a first threshold, and / or the number of context switches is greater than or equal to a second threshold.
[0156] In one example, the task scheduling device also includes a processing unit 1103, which is used to run tasks in the first processor core; an acquisition unit 1101, which is used to obtain the operating efficiency of the first processor core; and a scheduling unit 1102, which is also used to add at least one task queue in the first processor core and schedule at least one task to the at least one task queue when the operating efficiency of the first processor core is lower than a preset operating efficiency.
[0157] In one example, the computing device 110 further includes a storage unit 1104. The storage unit 1104 is used to store computer-executable instructions, and other units in the processor can perform corresponding actions according to the computer-executable instructions stored in the storage unit 1104.
[0158] For the detailed description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any computing device 110 provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.
[0159] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed on a computer, the computer is enabled to execute any of the methods executed by the computing devices provided above.
[0160] For the explanation of the relevant contents and description of the beneficial effects of any of the above-mentioned computer-readable storage media, reference may be made to the above-mentioned corresponding embodiments, which will not be repeated here.
[0161] The embodiment of the present application also provides a chip. The chip integrates a control circuit and one or more ports for implementing the functions of the above-mentioned computing device. Optionally, the functions supported by the chip can be referred to above and will not be repeated here. A person of ordinary skill in the art can understand that all or part of the steps of implementing the above-mentioned embodiment can be completed by instructing the relevant hardware through a program. The program can be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a random access memory, etc. The above-mentioned processing unit or processor can be a central processing unit, a general-purpose processor, an application specific integrated circuit (ASIC), a microprocessor (digital signal processor, DSP), a field programmable gate array (field programmable gatearray, FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof.
[0162] The embodiment of the present application also provides a computer program product including instructions, when the instructions are run on a computer, the computer executes any one of the methods in the above embodiments. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more servers that can be integrated with the medium. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., an SSD), etc.
[0163] It should be noted that the above-mentioned devices for storing computer instructions or computer programs provided in the embodiments of the present application, such as but not limited to the above-mentioned memories, computer-readable storage media and communication chips, etc., are all non-transitory.
[0164] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loading and executing computer program instructions on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. Computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that contains one or more servers that can be integrated with a medium. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a DVD), or a semiconductor medium (eg, a solid state disk (SSD)).
[0165] Although the present application is described herein in conjunction with various embodiments, in the process of implementing the claimed application, those skilled in the art may understand and implement other changes to the disclosed embodiments by viewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "one" or "an" does not exclude multiple situations. A single processor or other unit may implement several functions listed in the claims. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.
[0166] Although the present application has been described in conjunction with specific features and embodiments thereof, it is obvious that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely exemplary illustrations of the present application as defined by the appended claims, and are deemed to have covered any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A task scheduling method, It is characterized in that include: Acquire a task type of the target task, where the task type includes at least a first task type and a second task type, and the first task type and the second task type are processed differently in a central processing unit (CPU); According to the task type of the target task, the target task is scheduled to a task queue in a target processor core, wherein the target processor core is used to run tasks of the task type.
2. The method according to claim 1, It is characterized in that The task type is pre-marked, and the task type of the target task to be acquired includes: A task type of the target task is identified.
3. The method according to claim 1 or 2, It is characterized in that The IO operation duration of the first task type is longer than the CPU operation duration, and the CPU operation duration of the second task type is longer than the IO operation duration.
4. The method according to any one of claims 1 to 3, It is characterized in that The task type of the target task is the first task type, and scheduling the target task to a task queue in a target processor core according to the task type of the target task includes: The target task is scheduled to a task queue in a first processor core, where the first processor core is used to execute tasks of the first task type.
5. The method according to any one of claims 1 to 3, It is characterized in that The task type of the target task is the second task type, and scheduling the target task to a task queue in a target processor core according to the task type of the target task includes: The target task is scheduled to a task queue in a second processor core, and the second processor core is used to execute tasks of the second task type.
6. The method according to claim 1 or 2, It is characterized in that The task type also includes an unspecified task type; and scheduling the target task to a task queue in a target processor core according to the task type of the target task includes: The target task is scheduled to be executed in a task queue in a third processor core, and the third processor core is used to execute tasks of the unspecified task type.
7. The method according to claim 6, It is characterized in that The method further comprises: Acquire a task feature of the target task, where the task feature is used to indicate a running state of the target task in the target processor core; When the task characteristics of the target task meet the task characteristics of the first task type, the target task is scheduled from the task queue in the third processor core to the task queue in the first processor core, and the first processor core is used to execute tasks of the first task type.
8. The method according to claim 7, It is characterized in that The task characteristics of the target task include at least one of the following: the CPU waiting time for IO operation and the number of context switches of the target task. The task characteristics of the target task meet the task characteristics of the first task type, including: the CPU waiting time for IO operation of the target task is greater than or equal to a first threshold, and / or the number of context switches is greater than or equal to a second threshold.
9. The method according to claim 4, It is characterized in that The method further comprises: Running the task in the first processor core; Obtaining the operating efficiency of the first processor core; When the operating efficiency of the first processor core is lower than a preset operating efficiency, at least one task queue is added to the first processor core, and at least one task is scheduled to the at least one task queue.
10. A task scheduling device, It is characterized in that include: An acquisition unit, configured to acquire a task type of a target task, wherein the task type includes at least a first task type and a second task type, and the first task type and the second task type are processed differently in a central processing unit (CPU); A scheduling unit is used to schedule the target task to a task queue in a target processor core according to a task type of the target task, wherein the target processor core is used to run tasks of the task type.
11. The device according to claim 10, It is characterized in that The task types are pre-labeled, The acquisition unit is specifically configured to identify the task type of the target task.
12. The device according to claim 10 or 11, It is characterized in that The IO operation duration of the first task type is longer than the CPU operation duration, and the CPU operation duration of the second task type is longer than the IO operation duration.
13. The device according to any one of claims 10 to 12, It is characterized in that The task type of the target task is the first task type, The scheduling unit is specifically used to schedule the target task to a task queue in a first processor core, and the first processor core is used to execute tasks of the first task type.
14. The device according to any one of claims 10 to 12, It is characterized in that The task type of the target task is the second task type, The scheduling unit is specifically used to schedule the target task to a task queue in a second processor core, and the second processor core is used to execute tasks of the second task type.
15. The device according to claim 10 or 11, It is characterized in that The task types also include unspecified task types; The scheduling unit is specifically used to schedule the target task to a task queue in a third processor core for execution, and the third processor core is used to execute tasks of the unspecified task type.
16. The device according to claim 15, It is characterized in that The acquisition unit is further used to acquire a task feature of the target task, where the task feature is used to indicate a running state of the target task in the target processor core; The scheduling unit is also used to schedule the target task from the task queue in the third processor core to the task queue in the first processor core when the task characteristics of the target task meet the task characteristics of the first task type. The first processor core is used to execute tasks of the first task type.
17. The device according to claim 16, It is characterized in that The task characteristics of the target task include at least one of the following: the CPU waiting time for IO operation and the number of context switches of the target task. The task characteristics of the target task meet the task characteristics of the first task type, including: the CPU waiting time for IO operation of the target task is greater than or equal to a first threshold, and / or the number of context switches is greater than or equal to a second threshold.
18. The device according to claim 13, It is characterized in that The task scheduling device also includes a processing unit, The processing unit is used to run the tasks in the first processor core; The acquisition unit is used to acquire the operating efficiency of the first processor core; The scheduling unit is further configured to add at least one task queue in the first processor core and schedule at least one task to the at least one task queue when the operating efficiency of the first processor core is lower than a preset operating efficiency.
19. A task scheduling device, It is characterized in that include: processor; The processor is connected to a memory, the memory is used to store computer-executable instructions, and the processor executes the computer-executable instructions stored in the memory, so that the task scheduling device implements the method according to any one of claims 1 to 9.
20. A computer-readable storage medium, It is characterized in that Used to store computer instructions, when the computer instructions are executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 9.
Citation Information
Cited By
Task distribution method and device, electronic equipment and storage medium
CN120508375A
