[go: up one dir, main page]

CN111597044A - Task scheduling method and device, storage medium and electronic equipment - Google Patents

Task scheduling method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN111597044A
CN111597044A CN202010409028.6A CN202010409028A CN111597044A CN 111597044 A CN111597044 A CN 111597044A CN 202010409028 A CN202010409028 A CN 202010409028A CN 111597044 A CN111597044 A CN 111597044A
Authority
CN
China
Prior art keywords
task
time
cpu
cpus
scheduling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010409028.6A
Other languages
Chinese (zh)
Inventor
崔晓刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202010409028.6A priority Critical patent/CN111597044A/en
Publication of CN111597044A publication Critical patent/CN111597044A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/484Precedence
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5021Priority

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the application discloses a task scheduling method, a task scheduling device, a storage medium and electronic equipment, wherein the method comprises the following steps: when a first CPU in a plurality of CPUs in a system enters an idle state to trigger load balancing, acquiring task switching time of each task on other CPUs except the first CPU in the CPUs; and acquiring the farthest time from the current time in the task switching time, and scheduling the target task indicated by the farthest time from the current time to other CPUs except the CPU where the target task is currently located to run. Therefore, by adopting the embodiment of the application, the scheduling delay can be reduced while the load balance is realized.

Description

任务调度方法、装置、存储介质及电子设备Task scheduling method, device, storage medium and electronic device

技术领域technical field

本申请涉及计算机技术领域,尤其涉及一种任务调度方法、装置、存储介质及电子设备。The present application relates to the field of computer technology, and in particular, to a task scheduling method, device, storage medium and electronic device.

背景技术Background technique

任务唤醒或者任务被创建时,选择运行的CPU的时侯要考虑系统包含的多个CPU中每一个CPU的当前负载量以维持负载均衡,以及,基于CPU空闲 (IDLE)的负载均衡,在CPU之间出现负载不均衡时,将一些任务从负载高的 CPU上转移到负载较低的CPU上去。When a task wakes up or a task is created, when selecting a running CPU, consider the current load of each of the multiple CPUs included in the system to maintain load balancing, and, based on CPU idle (IDLE) load balancing, in the CPU When there is a load imbalance between them, some tasks are shifted from the CPU with high load to the CPU with lower load.

通过上述操作大体保证了CPU上的负载均衡,但是负载均衡不一定代表任务可以得到及时的执行。在Linux系统中,部分操作(如原子锁、软中断及硬件中断等等)会关闭任务抢占,即不允许进行任务的调度。在这种情况下,即使任务被唤醒,而且其虚拟时间(vruntime)最低,但也获取不到CPU资源,而一直处于等待的状态,直到上述操作(原子锁等)完成才可以获得CPU资源。The above operations generally ensure load balancing on the CPU, but load balancing does not necessarily mean that tasks can be executed in a timely manner. In the Linux system, some operations (such as atomic locks, soft interrupts, hardware interrupts, etc.) will disable task preemption, that is, task scheduling is not allowed. In this case, even if the task is woken up and its virtual time (vruntime) is the lowest, it cannot obtain CPU resources, and it has been in a waiting state until the above operations (atomic locks, etc.) are completed to obtain CPU resources.

发明内容SUMMARY OF THE INVENTION

本申请实施例提供了一种任务调度方法、装置、存储介质及电子设备,可以在实现负载均衡的同时还可以降低调度延迟。所述技术方案如下:Embodiments of the present application provide a task scheduling method, apparatus, storage medium, and electronic device, which can reduce scheduling delay while achieving load balancing. The technical solution is as follows:

第一方面,本申请实施例提供了一种任务调度方法,所述方法包括:In a first aspect, an embodiment of the present application provides a task scheduling method, the method comprising:

在系统包含的多个中央处理器CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间;When the first CPU of the plurality of central processing units (CPUs) included in the system enters an idle state to trigger load balancing, obtain the task switching time of each task on the remaining CPUs in the plurality of CPUs except the first CPU;

获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余 CPU上运行。Obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to run on other CPUs other than the CPU where the target task is currently located.

第二方面,本申请实施例提供了一种任务调度装置,所述装置包括:In a second aspect, an embodiment of the present application provides a task scheduling apparatus, and the apparatus includes:

时间获取模块,用于在系统包含的多个中央处理器CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余 CPU上各任务的任务切换时间;A time acquisition module, configured to acquire tasks on other CPUs in the multiple CPUs except the first CPU when the first CPU of the multiple central processing units (CPUs) included in the system enters an idle state and triggers load balancing task switching time;

任务调度模块,用于获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。A task scheduling module, configured to obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to the remaining CPUs other than the CPU where the target task is currently located run on.

第三方面,本申请实施例提供一种计算机存储介质,所述计算机存储介质存储有多条指令,所述指令适于由处理器加载并执行上述的方法步骤。In a third aspect, an embodiment of the present application provides a computer storage medium, where the computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the above method steps.

第四方面,本申请实施例提供一种电子设备,可包括:处理器和存储器;其中,所述存储器存储有计算机程序,所述计算机程序适于由所述处理器加载并执行上述的方法步骤。In a fourth aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded by the processor and execute the above method steps .

本申请一些实施例提供的技术方案带来的有益效果至少包括:The beneficial effects brought by the technical solutions provided by some embodiments of the present application include at least:

在本申请实施例中,在系统包含的多个CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间,进而获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。以CPU进入空闲状态触发负载均衡为触发时机,根据每个任务的任务切换时间,从而可以将由于某些原因长时间没有得到运行的任务调度到其余的CPU上,从而可以在实现负载均衡的同时还可以降低调度延迟。In this embodiment of the present application, when the first CPU among the multiple CPUs included in the system enters an idle state and triggers load balancing, the tasks of the tasks on the remaining CPUs in the multiple CPUs except the first CPU are obtained Switching time, and then obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to run on the remaining CPUs other than the CPU where the target task is currently located. . When the CPU enters the idle state to trigger the load balancing, according to the task switching time of each task, the tasks that have not been run for a long time for some reasons can be scheduled to the remaining CPUs, so that the load balancing can be achieved at the same time. Scheduling delays can also be reduced.

附图说明Description of drawings

为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without any creative effort.

图1是本申请实施例提供的一种任务调度方法的流程示意图;1 is a schematic flowchart of a task scheduling method provided by an embodiment of the present application;

图2是本申请实施例提供的一种多任务系统的结构示意图;2 is a schematic structural diagram of a multitasking system provided by an embodiment of the present application;

图3是本申请实施例提供的一种任务调度的时间关系的举例示意图;FIG. 3 is an exemplary schematic diagram of a time relationship of task scheduling provided by an embodiment of the present application;

图4是本申请实施例提供的一种任务调度方法的流程示意图;4 is a schematic flowchart of a task scheduling method provided by an embodiment of the present application;

图5是本申请实施例提供的一种任务调度装置的结构示意图;FIG. 5 is a schematic structural diagram of a task scheduling apparatus provided by an embodiment of the present application;

图6是本申请实施例提供的一种任务调度装置的结构示意图;6 is a schematic structural diagram of a task scheduling apparatus provided by an embodiment of the present application;

图7是本申请实施例提供的一种电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.

具体实施方式Detailed ways

为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施例方式作进一步地详细描述。In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be described in further detail below with reference to the accompanying drawings.

下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是如所附权利要求书中所详述的、本申请的一些方面相一致的装置和方法的例子。Where the following description refers to the drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the illustrative examples below are not intended to represent all implementations consistent with this application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application, as recited in the appended claims.

在本申请的描述中,需要理解的是,术语“第一”、“第二”等仅用于描述目的,而不能理解为指示或暗示相对重要性。对于本领域的普通技术人员而言,可以具体情况理解上述术语在本申请中的具体含义。此外,在本申请的描述中,除非另有说明,“多个”是指两个或两个以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。字符“/”一般表示前后关联对象是一种“或”的关系。In the description of the present application, it should be understood that the terms "first", "second" and the like are used for descriptive purposes only, and should not be construed as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood in specific situations. Also, in the description of the present application, unless otherwise specified, "a plurality" means two or more. "And/or", which describes the association relationship of the associated objects, means that there can be three kinds of relationships, for example, A and/or B, which can mean that A exists alone, A and B exist at the same time, and B exists alone. The character "/" generally indicates that the associated objects are an "or" relationship.

下面将结合附图1-附图4,对本申请实施例提供的任务调度方法进行详细介绍。该方法可依赖于计算机程序实现,可运行于基于冯诺依曼体系的任务调度装置上。该计算机程序可集成在应用中,也可作为独立的工具类应用运行。其中,本申请实施例中的任务调度装置可以为用户终端,所述用户终端包括但不限于:智能手机、个人电脑、平板电脑、手持设备、车载设备、可穿戴设备、计算设备或连接到无线调制解调器的其它处理设备等。The task scheduling method provided by the embodiment of the present application will be described in detail below with reference to FIG. 1 to FIG. 4 . The method can be implemented by relying on a computer program, and can be run on a task scheduling device based on the von Neumann system. The computer program can be integrated into an application or run as a stand-alone utility application. Wherein, the task scheduling apparatus in this embodiment of the present application may be a user terminal, and the user terminal includes but is not limited to: a smart phone, a personal computer, a tablet computer, a handheld device, a vehicle-mounted device, a wearable device, a computing device, or a device connected to a wireless Other processing equipment of the modem, etc.

请参见图1,为本申请实施例提供的一种任务调度方法的流程示意图。如图 1所示,本申请实施例的所述方法可以包括以下步骤:Please refer to FIG. 1 , which is a schematic flowchart of a task scheduling method provided by an embodiment of the present application. As shown in FIG. 1, the method of the embodiment of the present application may include the following steps:

S101,在系统包含的多个中央处理器CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间;S101 , when a first CPU among the multiple central processing units (CPUs) included in the system enters an idle state and triggers load balancing, obtain the task switching time of each task on the remaining CPUs in the multiple CPUs except the first CPU ;

本申请实施例应用在多中央处理器(Central Processing Unit,CPU)系统中,包含有多个CPU。The embodiments of the present application are applied in a multi-central processing unit (Central Processing Unit, CPU) system, which includes multiple CPUs.

其中,CPU是一个计算机的运算核心和控制核心,是信息处理、程序运行的最终执行单元。CPU包含运算逻辑部件、寄存器部件和控制部件等,并具有处理指令、执行操作、控制时间、处理数据等功能。Among them, the CPU is the computing core and control core of a computer, and is the final execution unit for information processing and program operation. The CPU includes arithmetic logic components, register components, control components, etc., and has functions such as processing instructions, executing operations, controlling time, and processing data.

CPU的性能主要体现在其运行程序的速度上。影响运行速度的性能指标包括CPU的工作频率、Cache容量、指令系统和逻辑结构等参数。CPU负载就是 CPU使用率,当CPU使用率较大时,导致CPU运行速度慢,可通过CPU调频限制CPU的使用。The performance of the CPU is mainly reflected in the speed at which it runs programs. The performance indicators that affect the running speed include parameters such as the operating frequency of the CPU, Cache capacity, instruction system and logical structure. The CPU load is the CPU usage rate. When the CPU usage rate is high, the CPU runs slowly, and the CPU usage can be limited by CPU frequency modulation.

多CPU系统通常包括四种不同的形式,即多处理器系统(MultiprocessorSystems)、多计算机系统(Multicomputer Systems)、网络系统(Network Systems) 和分布式系统(Distributed Systems)。Multi-CPU systems generally include four different forms, namely, Multiprocessor Systems, Multicomputer Systems, Network Systems, and Distributed Systems.

多处理器系统是指包含两台或多台功能相近的处理器,处理器之间彼此可以交换数据,所有处理器共享内存,I/O设备,控制器,及外部设备,整个硬件系统由统一的操作系统控制,在处理器和程序之间实现作业、任务、程序、数组极其元素各级的全面并行。A multi-processor system refers to two or more processors with similar functions. The processors can exchange data with each other. All processors share memory, I/O devices, controllers, and external devices. The entire hardware system consists of a unified system. It realizes full parallelism at all levels of jobs, tasks, programs, arrays and even elements between processors and programs.

例如,如图2所示为一种多CPU系统的结构示意图,系统包括多个CPU,这多个CPU共享内存。所述系统可以是SMP系统,也可以是HMP系统。For example, FIG. 2 is a schematic structural diagram of a multi-CPU system. The system includes multiple CPUs, and the multiple CPUs share memory. The system may be an SMP system or an HMP system.

SMP和HMP系统的区别在于,SMP系统的多个CPU性能相同,而HMP 系统的多个CPU性能不相同。The difference between the SMP and the HMP system is that the multiple CPUs of the SMP system have the same performance, while the multiple CPUs of the HMP system have different performances.

需要说明的是,每个CPU有不同的计算能力,即使在每个CPU计算能力相同的情况下,由于在不同时刻,每个CPU上运行不同的任务,也会存在剩余计算能力不同。所述剩余计算能力是指在某个时刻,除了CPU上运行的任务所占用的CPU资源外,剩余CPU资源可供计算的能力。It should be noted that each CPU has different computing capabilities. Even if the computing capabilities of each CPU are the same, due to different tasks running on each CPU at different times, there will be differences in the remaining computing capabilities. The remaining computing capacity refers to the capacity of the remaining CPU resources available for computing at a certain moment in addition to the CPU resources occupied by tasks running on the CPU.

当某个CPU(第一CPU)进入空闲(IDLE)状态触发负载均衡时,或者发生tick触发负载均衡时,表明该第一CPU有足够的资源可供某个或者某些任务运行,因此,为了保持系统负载均衡,则需要检测其余CPU上任务队列中等待较长时间而未分配到CPU资源的任务。负载均衡就是将任务分摊到多个操作单元上进行执行,例如Web服务器、FTP服务器、企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任务。在本申请实施例中,是指将任务调度到其他CPU上运行以实现负载均衡。When a certain CPU (the first CPU) enters the idle (IDLE) state to trigger load balancing, or when a tick triggers load balancing, it indicates that the first CPU has enough resources for one or some tasks to run. Therefore, in order to To maintain system load balance, it is necessary to detect tasks in the task queues on the remaining CPUs that have been waiting for a long time and have not been allocated CPU resources. Load balancing is to distribute tasks to multiple operating units for execution, such as Web servers, FTP servers, enterprise key application servers and other mission-critical servers, so as to complete work tasks together. In this embodiment of the present application, it refers to scheduling tasks to run on other CPUs to achieve load balancing.

具体的,需要获取各任务的任务切换时间last_sched_ts,所述任务切换时间last_sched_ts是指一个任务被唤醒的时间或者因时间片耗完被强制调度出去的时间。即任务切换时间与当前时间的差值即为获取CPU资源之前的延迟时间,当last_sched_ts越小,表明距离当前时间越远,也就是获取CPU资源之前的延迟时间越长。Specifically, the task switching time last_sched_ts of each task needs to be acquired, and the task switching time last_sched_ts refers to the time when a task is awakened or the time that is forcibly scheduled because the time slice is exhausted. That is, the difference between the task switching time and the current time is the delay time before obtaining CPU resources. When last_sched_ts is smaller, it indicates that the distance from the current time is farther, that is, the delay time before obtaining CPU resources is longer.

其中,一个任务可以看做一个线程。通常在一个进程中可以包含至少一个线程。线程可以利用进程所拥有的资源,在引入线程的操作系统中,通常都是把进程作为分配资源的基本单位,而把线程作为独立运行和独立调度的基本单位。由于线程比进程更小,基本上不拥有系统资源,故对它的调度所付出的开销就会小得多,能更高效的提高系统多个程序间并发执行的程度。Among them, a task can be regarded as a thread. Usually a process can contain at least one thread. Threads can utilize the resources owned by processes. In operating systems that introduce threads, processes are usually used as the basic unit for allocating resources, and threads are used as the basic unit for independent operation and independent scheduling. Since a thread is smaller than a process and basically does not own system resources, the overhead for its scheduling will be much smaller, which can more efficiently improve the degree of concurrent execution among multiple programs in the system.

通常,一个进程具有以下三种基本状态:就绪(Ready)态、执行(Running) 态和阻塞(Blocked)态。Generally, a process has the following three basic states: ready (Ready) state, executing (Running) state and blocking (Blocked) state.

其中,当进程具备运行条件(已分配到除CPU以外的所有必要的资源)时,只要获得CPU资源便可立即执行,这时的进程状态称为就绪态。Among them, when the process has the running conditions (all necessary resources except the CPU have been allocated), it can be executed immediately as long as the CPU resources are obtained, and the process state at this time is called the ready state.

当进程已获得CPU,其程序正在CPU上执行,此时的进程状态称为执行态。When the process has obtained the CPU and its program is being executed on the CPU, the process state at this time is called the execution state.

正在执行的进程,由于等待某个事件发生而无法执行时,便放弃CPU而处于阻塞状态。引起进程阻塞的事件可有多种,例如,等待I/O完成、申请缓冲区不能满足、等待信号等。When a process that is executing cannot be executed due to waiting for an event to occur, it will give up the CPU and be in a blocking state. There can be various events that cause a process to block, for example, waiting for I/O to complete, requesting a buffer that cannot be satisfied, waiting for a signal, and so on.

对于每个任务,其运行状态与所属进程的运行状态相同。在本申请实施例中,所针对的各任务是指运行状态为就绪态的认为。例如,该任务可以是被唤醒任务或因时间片耗完被强制调度出去的时间,还可以是新创建任务。总之,是从Ready到需要获得CPU资源的任务。For each task, its running state is the same as the running state of the owning process. In the embodiments of the present application, the targeted tasks refer to the assumption that the running state is the ready state. For example, the task can be a wake-up task or a time that is forcibly scheduled because the time slice runs out, or a newly created task. In short, it is from Ready to tasks that need to obtain CPU resources.

S102,获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。S102: Acquire the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to run on other CPUs other than the CPU where the target task is currently located.

可以理解的是,每当CPU上发生任务切换时,都需要更新任务的任务切换时间last_sched_ts。如果该任务是主动放弃CPU资源的话,将该任务的 last_sched_ts设置该字段为0,如果是因为时间片用完而被强制切换出去或者被唤醒的话,将该任务的last_sched_ts设置为任务切换发生的时间。此过程在实时或者周期性持续着,因此,所记录的last_sched_ts均为在当前时间之前的时间。It can be understood that whenever a task switch occurs on the CPU, the task switch time last_sched_ts of the task needs to be updated. If the task is actively giving up CPU resources, set the last_sched_ts of the task to 0. If it is forced to switch out or wake up because the time slice is used up, set the last_sched_ts of the task to the time when the task switch occurs. . This process continues in real time or periodically, so the recorded last_sched_ts are all times before the current time.

需要说明的是,当前时间是指本轮获取各CPU上各任务的任务切换时间的时间。It should be noted that the current time refers to the time when the task switching time of each task on each CPU is obtained in this round.

例如,如图3所示,每次在系统包含的多个CPU中的任一CPU进入空闲状态而触发负载均衡需要进行任务调度,或者系统每间隔预设周期检测触发任务调度时,就需要执行一轮本方案。若当前时刻为t1,也就是本轮执行本方案的触发时刻,上一轮执行本方案的触发时刻为t0,下一轮执行本方案的触发时刻为t2,那么需要统计在t0~t1时段内,各任务的任务切换时间,例如记录为ta、 tb、tc,则需要计算t1-ta、t1-tb、t1-tc,差值最大,表明距离当前时间最远,任务等待分配CPU资源的时间最长,因此,需要将该任务优先进行调度以获得CPU 资源,具体为调度至所述目标任务当前所在的CPU之外的其余CPU上运行。For example, as shown in Figure 3, every time any CPU among the multiple CPUs included in the system enters an idle state to trigger load balancing, task scheduling needs to be performed, or when the system detects and triggers task scheduling every preset period, it needs to execute round of this program. If the current time is t1, that is, the trigger time of the current round of execution of this scheme, the trigger time of the previous round of execution of this scheme is t0, and the trigger time of the next round of execution of this scheme is t2, then the statistics need to be within the period of t0 to t1. , the task switching time of each task, for example, recorded as ta, tb, tc, you need to calculate t1-ta, t1-tb, t1-tc, the difference is the largest, indicating that it is the farthest from the current time, and the task waits for the time to allocate CPU resources Therefore, the task needs to be scheduled preferentially to obtain CPU resources, specifically, scheduling to run on other CPUs other than the CPU where the target task is currently located.

例如,系统包括CPU A、CPU B、CPU C和CPU D,目标任务当前在CPU A上运行,CPU B为第一CPU,则可将目标任务调度到CPU B上运行,也可以调度到CPU B、CPU C和CPU D中负载小且任务切换时间较大的某个CPU上运行,还可以是CPU B、CPU C和CPU D中剩余计算能力最大的CPU。For example, if the system includes CPU A, CPU B, CPU C, and CPU D, and the target task is currently running on CPU A, and CPU B is the first CPU, the target task can be scheduled to run on CPU B or on CPU B. , CPU C and CPU D run on a CPU with a small load and a large task switching time, and it can also be the CPU with the largest remaining computing power among CPU B, CPU C, and CPU D.

当然,目标任务可以包括一个或多个。当目标任务包括多个时,可将这多个任务添加至栈或队列中,并依次进行调度。Of course, the target task can include one or more. When the target task includes multiple tasks, the multiple tasks can be added to the stack or queue and scheduled in sequence.

在本申请实施例中,在系统包含的多个CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间,进而获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。以CPU进入空闲状态触发负载均衡为触发时机,根据每个任务的任务切换时间,从而可以将由于某些原因长时间没有得到运行的任务调度到其余的CPU上,从而可以在实现负载均衡的同时还可以降低调度延迟。In this embodiment of the present application, when the first CPU among the multiple CPUs included in the system enters an idle state and triggers load balancing, the tasks of the tasks on the remaining CPUs in the multiple CPUs except the first CPU are obtained Switching time, and then obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to run on the remaining CPUs other than the CPU where the target task is currently located. . When the CPU enters the idle state to trigger the load balancing, according to the task switching time of each task, the tasks that have not been run for a long time for some reasons can be scheduled to the remaining CPUs, so that the load balancing can be achieved at the same time. Scheduling delays can also be reduced.

请参见图4,为本申请实施例提供的一种任务调度方法的流程示意图。图4 所示实施例相对于图1所示实施例的不同之处在于,图1强调的是在触发负载均衡时获取任务切换时间以进行任务调度的思路,图4中描述了方案的具体实现,强调了从进程描述结构体中获取各任务的任务切换时间的具体方式,以及对任务切换时间进行更新及保存的方案,该任务调度方法可以包括以下步骤:Please refer to FIG. 4 , which is a schematic flowchart of a task scheduling method provided by an embodiment of the present application. The difference between the embodiment shown in Figure 4 and the embodiment shown in Figure 1 is that Figure 1 emphasizes the idea of obtaining task switching time for task scheduling when triggering load balancing, and Figure 4 describes the specific implementation of the solution , emphasizing the specific method of obtaining the task switching time of each task from the process description structure, and the scheme of updating and saving the task switching time. The task scheduling method may include the following steps:

S201,在系统包含的多个CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务对应的进程描述结构体;S201, when the first CPU of the plurality of CPUs included in the system enters an idle state and triggers load balancing, obtain the process description structure corresponding to each task on the remaining CPUs in the plurality of CPUs except the first CPU;

本申请实施例应用在多中央处理器(Central Processing Unit,CPU)系统中,包含有多个CPU。所述系统可以是SMP系统,也可以是HMP系统。The embodiments of the present application are applied in a multi-central processing unit (Central Processing Unit, CPU) system, which includes multiple CPUs. The system may be an SMP system or an HMP system.

当某个CPU(第一CPU)进入空闲(IDLE)状态触发负载均衡时,或者发生tick触发负载均衡时,表明该第一CPU有足够的资源可供某个或者某些任务运行,因此,为了保持系统负载均衡,则需要检测其余CPU上任务队列中等待较长时间而未分配到CPU资源的任务。具体的,需要获取各任务的进程描述结构体以读取任务切换时间last_sched_ts。When a certain CPU (the first CPU) enters the idle (IDLE) state to trigger load balancing, or when a tick triggers load balancing, it indicates that the first CPU has enough resources for one or some tasks to run. Therefore, in order to To maintain system load balance, it is necessary to detect tasks in the task queues on the remaining CPUs that have been waiting for a long time and have not been allocated CPU resources. Specifically, the process description structure of each task needs to be obtained to read the task switching time last_sched_ts.

当把一个程序加载到内存当中,此时,就有了进程。关于进程,有一个相关的结构叫做进程控制块(PCB),是系统为了方便进行管理进程所设置的一个数据结构,通过PCB,就可以记录进程的特征以及一些信息。内核当中使用进程描述符task_struct。When a program is loaded into memory, at this point, there is a process. Regarding the process, there is a related structure called the process control block (PCB), which is a data structure set by the system to facilitate the management of the process. Through the PCB, the characteristics of the process and some information can be recorded. The process descriptor task_struct is used in the kernel.

task_struct就是一个结构体,通过这个结构体,可以对进程所有的相关的信息进行维护,对进程进行管理,通常定义在include/linux/sched.h文件中。task_struct is a structure through which all relevant information of the process can be maintained and managed, which is usually defined in the include/linux/sched.h file.

例如,一种进程描述结构体如下:For example, a process description structure is as follows:

Figure RE-GDA0002539098450000071
Figure RE-GDA0002539098450000071

具体的,分别获取除第一CPU以外的其余CPU上各任务对应的进程描述结构体。Specifically, the process description structures corresponding to the tasks on the remaining CPUs except the first CPU are respectively obtained.

S202,获取所述各任务对应的进程描述结构体中的切换时间字段,获取各所述切换时间字段对应的任务切换时间;S202, acquiring a switching time field in a process description structure corresponding to each task, and acquiring a task switching time corresponding to each of the switching time fields;

在上述进程描述结构体中包括切换时间字段last_sched_ts。last_sched_ts是指一个任务被唤醒的时间或者因时间片耗完被强制调度出去的时间。The switching time field last_sched_ts is included in the above process description structure. last_sched_ts refers to the time when a task was woken up or the time it was forced to be scheduled out because the time slice was exhausted.

任务切换时间与当前时间的差值即为获取CPU资源之前的延迟时间,当 last_sched_ts越小,表明距离当前时间越远,也就是获取CPU资源之前的延迟时间越长。The difference between the task switching time and the current time is the delay time before obtaining CPU resources. The smaller the last_sched_ts, the farther from the current time, that is, the longer the delay time before obtaining CPU resources.

S203,获取所述任务切换时间中距离当前时间的最远时间;S203, obtaining the farthest time from the current time in the task switching time;

可以理解的是,首先确定每个CPU上对应的最小last_sched_ts,然后在其中找出最小last_sched_ts,也就是距离当前时间的最远时间。It can be understood that, first determine the corresponding minimum last_sched_ts on each CPU, and then find the minimum last_sched_ts, that is, the farthest time from the current time.

可选的,当第一CPU剩余资源较多时,也可获取任务切换时间中距离当前时间较长的多个任务,如前三个。Optionally, when there are many remaining resources of the first CPU, multiple tasks in the task switching time that are longer from the current time, such as the first three, may also be acquired.

可选的,每个任务都有相应的优先级,优先级决定它何时运行和接收多少 CPU资源。Windows系统的优先级共32级,是从0到31的数值,称为基本优先级。系统按照不同的优先级调度任务的运行,其中,0-15级是普通优先级,任务的优先级可以动态变化,高优先级任务优先运行,只有高优先级任务不运行时,才调度低优先级任务运行,优先级相同的任务按照时间片轮流运行。 16-31级是实时优先级,实时优先级与普通优先级的最大区别在于相同优先级任务的运行不按照时间片轮转,而是先运行的任务就先控制CPU,如果它不主动放弃控制,同级或低优先级的任务就无法运行。Linux系统的优先级从0-140, 0-99表示实时任务,100-140表示非实时任务,与Windows相反,Linux优先级值越小,意味着级别越高,任务优先被内核调度。Optionally, each task has a corresponding priority that determines when it runs and how much CPU resources it receives. The Windows system has a total of 32 priority levels, which are values from 0 to 31, called the basic priority. The system schedules the operation of tasks according to different priorities. Among them, levels 0-15 are common priorities. The priority of tasks can be dynamically changed. High-priority tasks run first. Only when high-priority tasks are not running, low-priority tasks are scheduled. Tasks with the same priority run in turn according to the time slice. Level 16-31 is the real-time priority. The biggest difference between the real-time priority and the ordinary priority is that the operation of the same priority task does not rotate according to the time slice, but the task that runs first will control the CPU first. If it does not voluntarily give up control, Tasks of the same or lower priority cannot run. The priority of Linux system ranges from 0-140, 0-99 represents real-time tasks, and 100-140 represents non-real-time tasks. Contrary to Windows, the smaller the Linux priority value, the higher the level, and the priority of the task to be scheduled by the kernel.

在本申请实施例中,并不限定为Windows系统或Linux系统。可以先确定出距离当前时间较长的多个任务,及等待分配CPU资源较长的多个任务,再根据每个任务的优先级,确定出一个或多个目标任务以被调度。In the embodiments of the present application, it is not limited to a Windows system or a Linux system. It is possible to first determine a plurality of tasks with a long distance from the current time, and a plurality of tasks waiting for allocation of CPU resources for a long time, and then according to the priority of each task, determine one or more target tasks to be scheduled.

S204,当所述距离当前时间的最远时间大于或者等于预设阈值时,将所述距离当前时间的最远时间指示的目标任务调度至所述第一CPU上运行,或者将所述距离当前时间的最远时间指示的目标任务调度至第二CPU上运行,所述第二CPU为所述多个CPU中负载小于负载阈值的CPU且所述CPU对应的任务切换时间距离当前时间最近;S204, when the farthest time from the current time is greater than or equal to a preset threshold, schedule the target task indicated by the farthest time from the current time to run on the first CPU, or schedule the target task indicated by the farthest time from the current time to run on the first CPU. The target task indicated by the farthest time in time is scheduled to run on a second CPU, where the second CPU is a CPU with a load less than a load threshold among the plurality of CPUs, and the task switching time corresponding to the CPU is the closest to the current time;

可以理解的是,当所述距离当前时间的最远时间小于预设阈值时,表明该最远时间指示的目标任务等待分配CPU资源的时间不长,而无需调度到其余 CPU上,继续等待即可。此时相对调度到其他CPU上而言,反而增加了计算量。因此,当所述距离当前时间的最远时间大于或者等于预设阈值时,表明该最远时间指示的目标任务等待分配CPU资源的时间较长,而需要进行调度。It can be understood that when the farthest time from the current time is less than the preset threshold, it indicates that the target task indicated by the farthest time has not waited for a long time to allocate CPU resources, and does not need to be scheduled to the remaining CPUs, and continue to wait. Can. At this time, compared to scheduling on other CPUs, the amount of calculation is increased. Therefore, when the farthest time from the current time is greater than or equal to the preset threshold, it indicates that the target task indicated by the farthest time waits for a long time to allocate CPU resources and needs to be scheduled.

由于第一CPU进入空闲状态,有剩余足够的CPU资源而无任务进行处理,因此,可优先将目标任务调度至第一CPU,从而可快速为目标任务分配CPU资源而运行。Since the first CPU enters an idle state, there are enough CPU resources left and no task to process, therefore, the target task can be preferentially scheduled to the first CPU, so that the target task can be quickly allocated CPU resources for running.

或者,除第一CPU以外,还有第二CPU剩余计算能力大,负载低,且没有等待较长的任务待运行,则可以将目标任务调度至第二CPU上运行。Alternatively, in addition to the first CPU, there is a second CPU with large remaining computing capacity and a low load, and there is no waiting for a long task to be executed, the target task can be scheduled to run on the second CPU.

当然,若目标任务数量较多时,也可以将这多个目标任务分别调度至第一 CPU和第二CPU上,从而可满足多个任务的调度及运行。Of course, if the number of target tasks is large, the plurality of target tasks can also be scheduled to the first CPU and the second CPU respectively, so that the scheduling and running of multiple tasks can be satisfied.

S205,当检测到所述多个CPU中至少一个CPU上发生任务切换事件时,对所述多个CPU上各任务的任务切换时间进行更新。S205 , when detecting that a task switching event occurs on at least one of the multiple CPUs, update the task switching time of each task on the multiple CPUs.

在到达下一轮任务调度时间之前(如图3中t1~t2时间段之间),若检测到某个CPU或者多个CPU上发生任务切换事件(如任务被唤醒或者被强制调度等),则对该CPU上的任务的任务切换时间last_sched_ts进行更新,并更新为发生任务切换事件的时间。若有多个任务均发生任务切换事件时,则分别进行更新。Before reaching the next round of task scheduling time (between t1 and t2 in Figure 3), if a task switching event (such as a task being woken up or forced to be scheduled, etc.) is detected on a certain CPU or multiple CPUs, Then, the task switching time last_sched_ts of the task on the CPU is updated, and updated to the time when the task switching event occurs. If a task switching event occurs in multiple tasks, they are updated respectively.

具体的,确定所述任务切换事件对应的切换状态为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为当前时间,确定所述任务切换事件对应的切换状态不为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为零。Specifically, when it is determined that the switching state corresponding to the task switching event is the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to the current time, and the task switching event corresponding to the task switching event is determined. When the switching state is not the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to zero.

进一步的,确定所述任务切换对应的切换状态为被唤醒状态或被强制调度状态时,按照所述任务切换时间的先后顺序(如红黑树形式)保存所述任务切换时间,从而方便在下一轮任务调度时基于所保存任务切换时间进行任务调度。Further, when it is determined that the switching state corresponding to the task switching is the awakened state or the forced scheduling state, the task switching time is saved according to the order of the task switching time (such as in the form of a red-black tree), so as to facilitate the next time. During round task scheduling, task scheduling is performed based on the saved task switching time.

需要说明的是,还可以在系统包含的多个中央处理器CPU中的第一CPU进入空闲状态而触发负载均衡之前(如图3中t0~t1时间段),当检测到所述多个 CPU中至少一个CPU上发生任务切换事件时,对所述多个CPU上各任务的任务切换时间进行更新。It should be noted that, before the first CPU among the multiple central processing units (CPUs) included in the system enters an idle state and triggers load balancing (in the time period from t0 to t1 in FIG. 3 ), when the multiple CPUs are detected When a task switching event occurs on at least one of the CPUs, the task switching time of each task on the multiple CPUs is updated.

具体的,确定所述任务切换事件对应的切换状态为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为当前时间;确定所述任务切换事件对应的切换状态不为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为零。Specifically, when it is determined that the switching state corresponding to the task switching event is the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to the current time; the task switching time corresponding to the task switching event is determined. When the switching state is not the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to zero.

确定所述任务切换对应的切换状态为被唤醒状态或被强制调度状态时,按照所述任务切换时间的先后顺序保存所述任务切换时间。When it is determined that the switching state corresponding to the task switching is the awakened state or the forced scheduling state, the task switching time is saved according to the order of the task switching time.

在本申请实施例中,以CPU进入空闲状态触发负载均衡为触发时机,根据每个任务的任务切换时间计算调度延迟,从而可以将调度延迟较大的任务调度到空闲的第一CPU上或者负载低且调度延迟小的第二CPU上运行,从而可以在实现负载均衡的同时还可以降低调度延迟,提升系统性能,提升用户体验。此外,在进行调度前或者调度后,及时对任务的任务切换时间进行更新及保存,可以确保在任务调度时得到的任务调度时间准确有效,进而可以提高任务调度的准确性。In the embodiment of the present application, the triggering timing of load balancing is triggered by the CPU entering the idle state, and the scheduling delay is calculated according to the task switching time of each task, so that the task with a larger scheduling delay can be scheduled to the idle first CPU or the load It runs on the second CPU with low scheduling delay and low scheduling delay, so that load balancing can be achieved while scheduling delay can be reduced, system performance can be improved, and user experience can be improved. In addition, before or after scheduling, updating and saving the task switching time of the task in time can ensure that the task scheduling time obtained during task scheduling is accurate and effective, thereby improving the accuracy of task scheduling.

下述为本申请装置实施例,可以用于执行本申请方法实施例。对于本申请装置实施例中未披露的细节,请参照本申请方法实施例。The following are apparatus embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

请参见图5,其示出了本申请一个示例性实施例提供的任务调度装置的结构示意图。该任务调度装置可以通过软件、硬件或者两者的结合实现成为电子设备的全部或一部分。该装置1包括时间获取模块10和任务调度模块20。Please refer to FIG. 5 , which shows a schematic structural diagram of a task scheduling apparatus provided by an exemplary embodiment of the present application. The task scheduling apparatus can be implemented as a whole or a part of the electronic device through software, hardware or a combination of the two. The device 1 includes a time acquisition module 10 and a task scheduling module 20 .

时间获取模块10,用于在系统包含的多个中央处理器CPU中的第一CPU 进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间;The time acquisition module 10 is configured to acquire, when the first CPU of the plurality of central processing units (CPUs) included in the system enters an idle state and triggers load balancing, obtain the time acquisition module 10 of each of the remaining CPUs of the plurality of CPUs except the first CPU. The task switching time of the task;

任务调度模块20,用于获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。The task scheduling module 20 is used to obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to the rest of the CPU where the target task is currently located. run on the CPU.

可选的,所述时间获取模块10,具体用于:Optionally, the time acquisition module 10 is specifically used for:

获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务对应的进程描述结构体;Obtain the process description structure corresponding to each task on the remaining CPUs except the first CPU in the plurality of CPUs;

获取所述各任务对应的进程描述结构体中的切换时间字段,获取各所述切换时间字段对应的任务切换时间。The switching time field in the process description structure corresponding to each task is acquired, and the task switching time corresponding to each switching time field is acquired.

可选的,所述任务调度模块20,具体用于:Optionally, the task scheduling module 20 is specifically used for:

当所述距离当前时间的最远时间大于或者等于预设阈值时,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。When the farthest time from the current time is greater than or equal to a preset threshold, the target task indicated by the farthest time from the current time is scheduled to run on other CPUs other than the CPU where the target task currently resides.

可选的,所述任务调度模块20,具体用于:Optionally, the task scheduling module 20 is specifically used for:

将所述距离当前时间的最远时间指示的目标任务调度至所述第一CPU上运行,或者将所述距离当前时间的最远时间指示的目标任务调度至第二CPU上运行,所述第二CPU为所述多个CPU中负载小于负载阈值的CPU且所述CPU对应的任务切换时间距离当前时间最近。The target task indicated by the farthest time from the current time is scheduled to run on the first CPU, or the target task indicated by the farthest time from the current time is scheduled to run on the second CPU. The second CPU is a CPU whose load is less than a load threshold among the plurality of CPUs, and the task switching time corresponding to the CPU is the closest to the current time.

可选的,如图6所示,所述装置还包括时间更新模块30,用于:Optionally, as shown in FIG. 6 , the device further includes a time update module 30 for:

当检测到所述多个CPU中至少一个CPU上发生任务切换事件时,对所述多个CPU上各任务的任务切换时间进行更新。When it is detected that a task switching event occurs on at least one of the multiple CPUs, the task switching time of each task on the multiple CPUs is updated.

可选的,所述时间更新模块30,具体用于:Optionally, the time update module 30 is specifically used for:

确定所述任务切换事件对应的切换状态为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为当前时间;When it is determined that the switching state corresponding to the task switching event is the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to the current time;

确定所述任务切换事件对应的切换状态不为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为零。When it is determined that the switching state corresponding to the task switching event is not the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to zero.

可选的,如图6所示,所述装置还包括时间保存模块40,用于:Optionally, as shown in FIG. 6 , the device further includes a time saving module 40 for:

确定所述任务切换对应的切换状态为被唤醒状态或被强制调度状态时,按照所述任务切换时间的先后顺序保存所述任务切换时间。When it is determined that the switching state corresponding to the task switching is the awakened state or the forced scheduling state, the task switching time is saved according to the order of the task switching time.

需要说明的是,上述实施例提供的任务调度装置在执行任务调度方法时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将设备的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的任务调度装置与任务调度方法实施例属于同一构思,其体现实现过程详见方法实施例,这里不再赘述。It should be noted that, when the task scheduling apparatus provided in the above embodiments executes the task scheduling method, only the division of the above functional modules is used as an example for illustration. In practical applications, the above functions may be allocated to different functional modules as required. , that is, dividing the internal structure of the device into different functional modules to complete all or part of the functions described above. In addition, the task scheduling apparatus and the task scheduling method embodiments provided by the above embodiments belong to the same concept, and the implementation process of the embodiment is described in the method embodiments, which will not be repeated here.

上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The above-mentioned serial numbers of the embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.

在本申请实施例中,以CPU进入空闲状态触发负载均衡为触发时机,根据每个任务的任务切换时间计算调度延迟,从而可以将调度延迟较大的任务调度到空闲的第一CPU上或者负载低且调度延迟小的第二CPU上运行,从而可以在实现负载均衡的同时还可以降低调度延迟,提升用户体验。此外,在进行调度前或者调度后,及时对任务的任务切换时间进行更新及保存,可以确保在任务调度时得到的任务调度时间准确有效,进而可以提高任务调度的准确性。In the embodiment of the present application, the triggering timing of load balancing is triggered by the CPU entering the idle state, and the scheduling delay is calculated according to the task switching time of each task, so that the task with a larger scheduling delay can be scheduled to the idle first CPU or the load It runs on the second CPU with low scheduling delay and low scheduling delay, so that load balancing can be achieved while scheduling delay can be reduced and user experience can be improved. In addition, before or after scheduling, updating and saving the task switching time of the task in time can ensure that the task scheduling time obtained during task scheduling is accurate and effective, thereby improving the accuracy of task scheduling.

本申请实施例还提供了一种计算机存储介质,所述计算机存储介质可以存储有多条指令,所述指令适于由处理器加载并执行如上述图1-图4所示实施例的方法步骤,具体执行过程可以参见图1-图4所示实施例的具体说明,在此不进行赘述。An embodiment of the present application further provides a computer storage medium, where the computer storage medium can store multiple instructions, and the instructions are suitable for being loaded by a processor and executing the method steps of the embodiments shown in FIG. 1 to FIG. 4 above. , and the specific execution process may refer to the specific description of the embodiments shown in FIG. 1 to FIG. 4 , which will not be repeated here.

请参见图7,为本申请实施例提供的一种电子设备的结构示意图。如图7所示,所述电子设备1000可以包括:至少一个处理器1001,至少一个网络接口 1004,用户接口1003,存储器1005,至少一个通信总线1002。Please refer to FIG. 7 , which is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in FIG. 7 , the electronic device 1000 may include: at least one processor 1001 , at least one network interface 1004 , user interface 1003 , memory 1005 , and at least one communication bus 1002 .

其中,通信总线1002用于实现这些组件之间的连接通信。Among them, the communication bus 1002 is used to realize the connection and communication between these components.

其中,用户接口1003可以包括显示屏(Display)、摄像头(Camera),可选用户接口1003还可以包括标准的有线接口、无线接口。The user interface 1003 may include a display screen (Display) and a camera (Camera), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.

其中,网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI 接口)。Wherein, the network interface 1004 may optionally include a standard wired interface and a wireless interface (eg, a WI-FI interface).

其中,处理器1001可以包括一个或者多个处理核心。处理器1001利用各种借口和线路连接整个电子设备1000内的各个部分,通过运行或执行存储在存储器1005内的指令、程序、代码集或指令集,以及调用存储在存储器1005内的数据,执行电子设备1000的各种功能和处理数据。可选的,处理器1001可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列 (Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器1001可集成中央处理器 (Central Processing Unit,CPU)、图像处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责显示屏所需要显示的内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器1001中,单独通过一块芯片进行实现。The processor 1001 may include one or more processing cores. The processor 1001 uses various excuses and lines to connect various parts of the entire electronic device 1000, and executes by running or executing the instructions, programs, code sets or instruction sets stored in the memory 1005, and calling the data stored in the memory 1005. Various functions of the electronic device 1000 and processing data. Optionally, the processor 1001 may employ at least one of a digital signal processing (Digital Signal Processing, DSP), a Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), and a Programmable Logic Array (Programmable Logic Array, PLA). A hardware form is implemented. The processor 1001 may integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU), a modem, and the like. Among them, the CPU mainly handles the operating system, user interface, and application programs; the GPU is used to render and draw the content that needs to be displayed on the display screen; the modem is used to handle wireless communication. It can be understood that, the above-mentioned modem may not be integrated into the processor 1001, but is implemented by a single chip.

其中,存储器1005可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory)。可选的,该存储器1005包括非瞬时性计算机可读介质(non-transitory computer-readable storage medium)。存储器1005可用于存储指令、程序、代码、代码集或指令集。存储器1005可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现上述各个方法实施例的指令等;存储数据区可存储上面各个方法实施例中涉及到的数据等。存储器1005可选的还可以是至少一个位于远离前述处理器1001的存储装置。如图7所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及任务调度应用程序。The memory 1005 may include random access memory (Random Access Memory, RAM), or may include read-only memory (Read-Only Memory). Optionally, the memory 1005 includes a non-transitory computer-readable storage medium. Memory 1005 may be used to store instructions, programs, codes, sets of codes, or sets of instructions. The memory 1005 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), Instructions and the like used to implement the above method embodiments; the storage data area may store the data and the like involved in the above method embodiments. Optionally, the memory 1005 may also be at least one storage device located away from the aforementioned processor 1001 . As shown in FIG. 7 , the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a task scheduling application program.

在图7所示的电子设备1000中,用户接口1003主要用于为用户提供输入的接口,获取用户输入的数据;而处理器1001可以用于调用存储器1005中存储的任务调度应用程序,并具体执行以下操作:In the electronic device 1000 shown in FIG. 7 , the user interface 1003 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 1001 can be used to call the task scheduling application program stored in the memory 1005, and specifically Do the following:

在系统包含的多个中央处理器CPU中的第一CPU进入空闲状态而触发负载均衡时,获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间;When the first CPU of the plurality of central processing units (CPUs) included in the system enters an idle state to trigger load balancing, obtain the task switching time of each task on the remaining CPUs in the plurality of CPUs except the first CPU;

获取所述任务切换时间中距离当前时间的最远时间,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余 CPU上运行。Obtain the farthest time from the current time in the task switching time, and schedule the target task indicated by the farthest time from the current time to run on other CPUs other than the CPU where the target task is currently located.

在一个实施例中,所述处理器1001在执行获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务的任务切换时间时,具体执行以下操作:In one embodiment, the processor 1001 specifically performs the following operations when acquiring the task switching time of each task on the remaining CPUs in the plurality of CPUs except the first CPU:

获取所述多个CPU中除所述第一CPU以外的其余CPU上各任务对应的进程描述结构体;Obtain the process description structure corresponding to each task on the remaining CPUs except the first CPU in the plurality of CPUs;

获取所述各任务对应的进程描述结构体中的切换时间字段,获取各所述切换时间字段对应的任务切换时间。The switching time field in the process description structure corresponding to each task is acquired, and the task switching time corresponding to each switching time field is acquired.

在一个实施例中,所述处理器1001在执行将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行时,具体执行以下操作:In one embodiment, when the processor 1001 executes scheduling the target task indicated by the farthest time from the current time to run on other CPUs other than the CPU where the target task is currently located, the processor 1001 specifically performs the following operations :

当所述距离当前时间的最远时间大于或者等于预设阈值时,将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行。When the farthest time from the current time is greater than or equal to a preset threshold, the target task indicated by the farthest time from the current time is scheduled to run on other CPUs other than the CPU where the target task currently resides.

在一个实施例中,所述处理器1001在执行将所述距离当前时间的最远时间指示的目标任务调度至所述目标任务当前所在的CPU之外的其余CPU上运行时,具体执行以下操作:In one embodiment, when the processor 1001 executes scheduling the target task indicated by the farthest time from the current time to run on other CPUs other than the CPU where the target task is currently located, the processor 1001 specifically performs the following operations :

将所述距离当前时间的最远时间指示的目标任务调度至所述第一CPU上运行,或者将所述距离当前时间的最远时间指示的目标任务调度至第二CPU上运行,所述第二CPU为所述多个CPU中负载小于负载阈值的CPU且所述CPU对应的任务切换时间距离当前时间最近。The target task indicated by the farthest time from the current time is scheduled to run on the first CPU, or the target task indicated by the farthest time from the current time is scheduled to run on the second CPU. The second CPU is a CPU whose load is less than a load threshold among the plurality of CPUs, and the task switching time corresponding to the CPU is the closest to the current time.

在一个实施例中,所述处理器1001还执行以下操作:In one embodiment, the processor 1001 further performs the following operations:

当检测到所述多个CPU中至少一个CPU上发生任务切换事件时,对所述多个CPU上各任务的任务切换时间进行更新。When it is detected that a task switching event occurs on at least one of the multiple CPUs, the task switching time of each task on the multiple CPUs is updated.

在一个实施例中,所述处理器1001在执行对所述多个CPU上各任务的任务切换时间进行更新时,具体执行以下操作:In one embodiment, the processor 1001 specifically performs the following operations when updating the task switching time of each task on the multiple CPUs:

确定所述任务切换事件对应的切换状态为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为当前时间;When it is determined that the switching state corresponding to the task switching event is the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to the current time;

确定所述任务切换事件对应的切换状态不为被唤醒状态或被强制调度状态时,将所述多个CPU上各任务的任务切换时间设置为零。When it is determined that the switching state corresponding to the task switching event is not the awakened state or the forced scheduling state, the task switching time of each task on the multiple CPUs is set to zero.

在一个实施例中,所述处理器1001还执行以下操作:In one embodiment, the processor 1001 further performs the following operations:

确定所述任务切换对应的切换状态为被唤醒状态或被强制调度状态时,按照所述任务切换时间的先后顺序保存所述任务切换时间。When it is determined that the switching state corresponding to the task switching is the awakened state or the forced scheduling state, the task switching time is saved according to the order of the task switching time.

在本申请实施例中,以CPU进入空闲状态触发负载均衡为触发时机,根据每个任务的任务切换时间计算调度延迟,从而可以将调度延迟较大的任务调度到空闲的第一CPU上或者负载低且调度延迟小的第二CPU上运行,从而可以在实现负载均衡的同时还可以降低调度延迟,提升用户体验。此外,在进行调度前或者调度后,及时对任务的任务切换时间进行更新及保存,可以确保在任务调度时得到的任务调度时间准确有效,进而可以提高任务调度的准确性。In this embodiment of the present application, the triggering timing is when the CPU enters an idle state to trigger load balancing, and the scheduling delay is calculated according to the task switching time of each task, so that a task with a larger scheduling delay can be scheduled to the idle first CPU or load It runs on the second CPU with low scheduling delay and low scheduling delay, so that load balancing can be achieved while scheduling delay can be reduced and user experience can be improved. In addition, before or after scheduling, updating and saving the task switching time of the task in time can ensure that the task scheduling time obtained during task scheduling is accurate and effective, thereby improving the accuracy of task scheduling.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体或随机存储记忆体等。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. During execution, the processes of the embodiments of the above-mentioned methods may be included. Wherein, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, or a random storage memory, and the like.

以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。The above disclosures are only the preferred embodiments of the present application, and of course, the scope of the rights of the present application cannot be limited by this. Therefore, equivalent changes made according to the claims of the present application are still within the scope of the present application.

Claims (10)

1. A method for task scheduling, the method comprising:
when a first CPU in a plurality of CPUs in a system enters an idle state to trigger load balancing, acquiring task switching time of each task on other CPUs except the first CPU in the CPUs;
and acquiring the farthest time from the current time in the task switching time, and scheduling the target task indicated by the farthest time from the current time to other CPUs except the CPU where the target task is currently located to run.
2. The method according to claim 1, wherein the obtaining of the task switching time of each task on the remaining CPUs, except the first CPU, of the plurality of CPUs includes:
acquiring a process description structure corresponding to each task on the rest CPUs except the first CPU in the CPUs;
and acquiring switching time fields in the process description structure body corresponding to the tasks, and acquiring task switching time corresponding to the switching time fields.
3. The method of claim 1, wherein the scheduling the target task indicated by the farthest time from the current time to be executed on other CPUs other than the CPU where the target task is currently located comprises:
and when the farthest time from the current time is greater than or equal to a preset threshold value, scheduling the target task indicated by the farthest time from the current time to other CPUs except the CPU where the target task is currently located to run.
4. The method of claim 3, wherein the scheduling the target task indicated by the farthest time from the current time to be executed on other CPUs than the CPU where the target task is currently located comprises:
and scheduling the target task indicated by the farthest time from the current time to the first CPU for running, or scheduling the target task indicated by the farthest time from the current time to a second CPU for running, wherein the second CPU is a CPU of which the load is smaller than a load threshold value and the task switching time corresponding to the CPU is closest to the current time.
5. The method of claim 1, further comprising:
and when detecting that a task switching event occurs on at least one of the CPUs, updating the task switching time of each task on the CPUs.
6. The method of claim 5, wherein updating the task switch time for each task on the plurality of CPUs comprises:
when the switching state corresponding to the task switching event is determined to be an awakened state or a forced scheduling state, setting the task switching time of each task on the CPUs as the current time;
and when determining that the switching state corresponding to the task switching event is not in the awakened state or the forced scheduling state, setting the task switching time of each task on the CPUs to be zero.
7. The method of claim 6, further comprising:
and when the switching state corresponding to the task switching is determined to be the awakened state or the forced scheduling state, storing the task switching time according to the sequence of the task switching time.
8. A task scheduling apparatus, characterized in that the apparatus comprises:
the system comprises a time acquisition module, a load balancing module and a load balancing module, wherein the time acquisition module is used for acquiring task switching time of each task on other CPUs except a first CPU in a plurality of CPUs (central processing units) contained in the system when the first CPU enters an idle state to trigger load balancing;
and the task scheduling module is used for acquiring the farthest time from the current time in the task switching time and scheduling the target task indicated by the farthest time from the current time to other CPUs except the CPU where the target task is currently located to run.
9. A computer storage medium, characterized in that it stores a plurality of instructions adapted to be loaded by a processor and to carry out the method steps according to any one of claims 1 to 7.
10. An electronic device, comprising: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to perform the method steps of any of claims 1 to 7.
CN202010409028.6A 2020-05-14 2020-05-14 Task scheduling method and device, storage medium and electronic equipment Pending CN111597044A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010409028.6A CN111597044A (en) 2020-05-14 2020-05-14 Task scheduling method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010409028.6A CN111597044A (en) 2020-05-14 2020-05-14 Task scheduling method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN111597044A true CN111597044A (en) 2020-08-28

Family

ID=72185641

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010409028.6A Pending CN111597044A (en) 2020-05-14 2020-05-14 Task scheduling method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111597044A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035236A (en) * 2020-09-08 2020-12-04 深圳天源迪科信息技术股份有限公司 Task scheduling method, device and storage medium based on multi-factor cooperation
CN114880102A (en) * 2022-07-04 2022-08-09 北京智芯半导体科技有限公司 Security chip, multitask scheduling method and device thereof, and storage medium
CN116450306A (en) * 2022-09-26 2023-07-18 宁德时代新能源科技股份有限公司 Task scheduling method, device, equipment, storage medium and product

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2001350639A (en) * 2000-06-06 2001-12-21 Atr Adaptive Communications Res Lab Scheduling method in soft real-time
CN109144696A (en) * 2018-08-30 2019-01-04 百度在线网络技术(北京)有限公司 A kind of method for scheduling task, device, electronic equipment and storage medium
CN109766180A (en) * 2017-11-09 2019-05-17 阿里巴巴集团控股有限公司 Load-balancing method and device, calculate equipment and computing system at storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2001350639A (en) * 2000-06-06 2001-12-21 Atr Adaptive Communications Res Lab Scheduling method in soft real-time
CN109766180A (en) * 2017-11-09 2019-05-17 阿里巴巴集团控股有限公司 Load-balancing method and device, calculate equipment and computing system at storage medium
CN109144696A (en) * 2018-08-30 2019-01-04 百度在线网络技术(北京)有限公司 A kind of method for scheduling task, device, electronic equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
李其昌: "基于等待时间的多任务调度算法的研究与设计" *
覃中: "基于多核系统的线程调度" *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035236A (en) * 2020-09-08 2020-12-04 深圳天源迪科信息技术股份有限公司 Task scheduling method, device and storage medium based on multi-factor cooperation
CN114880102A (en) * 2022-07-04 2022-08-09 北京智芯半导体科技有限公司 Security chip, multitask scheduling method and device thereof, and storage medium
CN114880102B (en) * 2022-07-04 2022-10-25 北京智芯半导体科技有限公司 Security chip and multitask scheduling method and device thereof, and storage medium
CN116450306A (en) * 2022-09-26 2023-07-18 宁德时代新能源科技股份有限公司 Task scheduling method, device, equipment, storage medium and product
CN116450306B (en) * 2022-09-26 2023-12-26 宁德时代新能源科技股份有限公司 Task scheduling method, device, equipment, storage medium and product

Similar Documents

Publication Publication Date Title
US12131186B2 (en) Hardware accelerated dynamic work creation on a graphics processing unit
US8219993B2 (en) Frequency scaling of processing unit based on aggregate thread CPI metric
CN108549574B (en) Thread scheduling management method, apparatus, computer equipment and storage medium
US10552213B2 (en) Thread pool and task queuing method and system
US9411649B2 (en) Resource allocation method
JP2018533122A (en) Efficient scheduling of multiversion tasks
US20120297216A1 (en) Dynamically selecting active polling or timed waits
CN105955809B (en) Thread scheduling method and system
CN112925616A (en) Task allocation method and device, storage medium and electronic equipment
CN111897637B (en) Job scheduling method, device, host and storage medium
CN111597044A (en) Task scheduling method and device, storage medium and electronic equipment
EP2613257B1 (en) Systems and methods for use in performing one or more tasks
CN112764904A (en) Method for preventing starvation of low priority tasks in multitask-based system
US20200379804A1 (en) Multi-level scheduling
CN103729242B (en) Spin lock preemptive scheduling algorithm selecting method and device
TW202101211A (en) A system and a method for handling an interrupt
CN110795323A (en) Load statistical method, device, storage medium and electronic equipment
CN103677997A (en) Multi-core device and multi-thread scheduling method thereof
US12204774B2 (en) Allocation of resources when processing at memory level through memory request scheduling
Wang et al. Adaptive scheduling of multiprogrammed dynamic-multithreading applications
CN114968500A (en) Task scheduling method, device, equipment and storage medium
CN114461365A (en) Process scheduling processing method, device, equipment and storage medium
US11061730B2 (en) Efficient scheduling for hyper-threaded CPUs using memory monitoring
CN116841751B (en) Policy configuration method, device and storage medium for multi-task thread pool
CN113138909A (en) Load statistical method, device, storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
AD01 Patent right deemed abandoned

Effective date of abandoning: 20241008

AD01 Patent right deemed abandoned