CN114528080A - Multi-task scheduling method and device - Google Patents
Multi-task scheduling method and device Download PDFInfo
- Publication number
- CN114528080A CN114528080A CN202210120020.7A CN202210120020A CN114528080A CN 114528080 A CN114528080 A CN 114528080A CN 202210120020 A CN202210120020 A CN 202210120020A CN 114528080 A CN114528080 A CN 114528080A
- Authority
- CN
- China
- Prior art keywords
- task
- target
- scheduling
- data
- target task
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3017—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is implementing multitasking
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3051—Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Quality & Reliability (AREA)
- Mathematical Physics (AREA)
- Debugging And Monitoring (AREA)
Abstract
Description
技术领域technical field
本发明涉及计算机技术领域,具体而言,涉及一种多任务调度方法及装置。The present invention relates to the field of computer technology, and in particular, to a multitask scheduling method and device.
背景技术Background technique
随着计算机技术的深入发展,多任务操作系统应用越来越普遍,多任务操作系统例如Windows、Linux、QNX(Quick UNIX)等,在多任务操作系统中往往会同时运行着多个任务进程。现有技术中多个任务通常是独立启动和独立运行,例如,当需要启动多个任务时,无论是通过手动方式,还是命令脚本方式,都需要逐一启动每个任务执行,操作比较费时,特别是需要同时启动大量任务时,给维护人员带来了不便。另外各任务之间无法进行协调,若某一任务出现异常,不能及时调整和控制其他相关任务的执行状态。如何在多任务操作系统中对多个任务进行统一调配和管理,是多任务操作系统应用领域需要解决的问题。With the in-depth development of computer technology, the application of multitasking operating systems is becoming more and more common. Multitasking operating systems such as Windows, Linux, QNX (Quick UNIX), etc., often run multiple task processes at the same time in multitasking operating systems. In the prior art, multiple tasks are usually started and run independently. For example, when multiple tasks need to be started, whether by manual method or command script method, each task needs to be started one by one. The operation is time-consuming, especially. It is inconvenient for maintenance personnel when a large number of tasks need to be started at the same time. In addition, there is no coordination between tasks. If a task is abnormal, the execution status of other related tasks cannot be adjusted and controlled in time. How to uniformly allocate and manage multiple tasks in a multitasking operating system is a problem that needs to be solved in the application field of the multitasking operating system.
发明内容SUMMARY OF THE INVENTION
本发明提供了一种多任务调度方法及装置,以实现对多任务的统一调度。具体的技术方案如下:The invention provides a multi-task scheduling method and device to realize unified scheduling of multi-tasks. The specific technical solutions are as follows:
第一方面,本发明实施例提供了一种多任务调度方法,方法包括:In a first aspect, an embodiment of the present invention provides a multitask scheduling method, including:
获取任务配置文件,其中,任务配置文件包含多个目标任务的配置信息,配置信息包括任务调度周期、任务调度顺序;Obtain a task configuration file, wherein the task configuration file includes configuration information of multiple target tasks, and the configuration information includes a task scheduling period and a task scheduling sequence;
基于任务配置文件,利用守护进程对多个目标任务进行调度和任务状态监控,其中,守护进程的任务调度时钟根据任务调度周期和任务调度顺序确定,每一目标任务对应一个任务调度时钟,守护进程对应的共享内存用于各目标任务之间的数据交换以及用于存储第一任务状态信息,第一任务状态信息是各目标任务在执行调度过程中,生成的任务状态信息。Based on the task configuration file, the daemon process is used to schedule and monitor the task status of multiple target tasks. The task scheduling clock of the daemon process is determined according to the task scheduling cycle and task scheduling sequence. Each target task corresponds to a task scheduling clock. The corresponding shared memory is used for data exchange between each target task and for storing first task state information, where the first task state information is task state information generated by each target task during the execution and scheduling process.
可选的,基于任务配置文件,利用守护进程对多个目标任务进行调度和监控之前,包括:Optionally, based on the task configuration file, before using the daemon to schedule and monitor multiple target tasks, including:
针对每一目标任务,根据每一目标任务的任务调度周期和关联目标任务的任务调度顺序,确定任务调度时钟,其中,多个目标任务对应的多个任务调度时钟具有同一时钟源;For each target task, a task scheduling clock is determined according to the task scheduling period of each target task and the task scheduling order of the associated target task, wherein multiple task scheduling clocks corresponding to multiple target tasks have the same clock source;
根据任务间数据信息和第二任务状态信息,确定共享内存,共享内存的容量对应任务间数据信息和第二任务状态信息容量的总和;Determine the shared memory according to the inter-task data information and the second task state information, and the capacity of the shared memory corresponds to the sum of the inter-task data information and the capacity of the second task state information;
针对每一目标任务,根据每一目标任务对应的配置信息确定任务进程,且将初始化后的任务进程关联至共享内存。For each target task, the task process is determined according to the configuration information corresponding to each target task, and the initialized task process is associated with the shared memory.
可选的,针对每一目标任务,根据每一目标任务的任务调度周期和关联目标任务的任务调度顺序,确定任务调度时钟,包括:Optionally, for each target task, according to the task scheduling period of each target task and the task scheduling sequence of the associated target task, determine the task scheduling clock, including:
根据多个目标任务的任务调度周期,确定任务调度基准时钟,其中,任务调度基准时钟对应多个目标任务的任务调度周期的最大公约数;Determine the task scheduling reference clock according to the task scheduling periods of the multiple target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling periods of the multiple target tasks;
根据任务调度基准时钟和每一目标任务的任务调度周期,确定该目标任务的调度周期计数值,其中,调度周期计数值为任务调度基准时钟对应的N个基准时间,N为正整数;Determine the scheduling cycle count value of the target task according to the task scheduling reference clock and the task scheduling cycle of each target task, wherein the scheduling cycle count value is N reference times corresponding to the task scheduling reference clock, and N is a positive integer;
根据任务调度顺序,确定每一目标任务的计数偏移值;Determine the count offset value of each target task according to the task scheduling sequence;
根据任务调度顺序,确定每一目标任务的任务执行方式,其中,According to the task scheduling sequence, determine the task execution mode of each target task, wherein,
当目标任务的任务执行方式为串行执行时,则该目标任务的任务调度时钟对应该目标任务的周期计数值与该目标任务的计数偏移值之和;When the task execution mode of the target task is serial execution, the task scheduling clock of the target task corresponds to the sum of the period count value of the target task and the count offset value of the target task;
当目标任务的任务执行方式为并行执行时,则并行执行的多个目标任务的任务调度时钟相同,并行执行的多个目标任务的任务调度时钟对应并行执行任务中每一目标任务的周期计数值与自身目标任务的计数偏移值之和。When the task execution mode of the target task is parallel execution, the task scheduling clocks of multiple target tasks executed in parallel are the same, and the task scheduling clocks of multiple target tasks executed in parallel correspond to the cycle count value of each target task in the parallel execution tasks Sum of count offsets from own target task.
可选的,针对每一目标任务,根据每一目标任务的任务调度周期和关联目标任务的任务调度顺序,确定任务调度时钟,还包括:Optionally, for each target task, the task scheduling clock is determined according to the task scheduling period of each target task and the task scheduling sequence associated with the target task, and further includes:
根据任务调度基准时钟,确定系统定时器,系统定时器为所有任务调度的最小时钟片,定时器用于实现多个目标任务基于同一时钟源的同步调度。According to the task scheduling reference clock, the system timer is determined. The system timer is the smallest clock slice for all task scheduling. The timer is used to realize the synchronous scheduling of multiple target tasks based on the same clock source.
可选的,共享内存基于系统进程锁进行数据读写。Optionally, the shared memory performs data reading and writing based on system process locks.
可选的,基于任务配置文件,利用目标守护进程对多个目标任务进行调度和监控,包括:Optionally, based on the task configuration file, use the target daemon to schedule and monitor multiple target tasks, including:
根据目标任务的任务调度时钟触发该目标任务;Trigger the target task according to the task scheduling clock of the target task;
基于每一关联目标任务的数据偏移地址,获取存储于共享内存中关联目标任务的第一数据,其中,第一数据是关联目标任务待发送给目标任务的数据;Based on the data offset address of each associated target task, obtain the first data associated with the target task stored in the shared memory, wherein the first data is the data associated with the target task to be sent to the target task;
基于第一数据,执行目标任务,并确定第二数据,其中,第二数据与目标任务执行结果相对应,第二数据包括第三数据和第四数据,第三数据是关联目标任务待接收的数据,第四数据是目标任务执行任务后确定的状态信息数据;Based on the first data, the target task is executed, and second data is determined, wherein the second data corresponds to the execution result of the target task, the second data includes third data and fourth data, and the third data is to be received associated with the target task data, the fourth data is the state information data determined after the target task executes the task;
根据第四数据,对目标任务及其关联目标任务进行监控。According to the fourth data, the target task and its associated target task are monitored.
可选的,根据第四数据,对目标任务及其关联目标任务进行监控,包括:Optionally, monitor the target task and its associated target task according to the fourth data, including:
获取第四数据;get the fourth data;
根据第四数据,判断目标任务执行结果是否报错和/或目标任务是否异常退出;According to the fourth data, determine whether the execution result of the target task reports an error and/or whether the target task exits abnormally;
响应于目标任务执行结果报错和/或目标任务异常退出,根据预先设置的错误等级向关联目标任务下发相应控制指令。In response to an error report of the execution result of the target task and/or the abnormal exit of the target task, a corresponding control instruction is issued to the associated target task according to a preset error level.
可选的,任务配置信息还包括任务名称、任务核绑定信息、任务优先级、第二任务状态信息、任务间数据信息中的至少一种,其中,第二任务状态信息为每一目标任务原始的任务状态信息。Optionally, the task configuration information also includes at least one of the task name, task core binding information, task priority, second task status information, and inter-task data information, where the second task status information is each target task. Raw task status information.
第二方面,本发明实施例提供了一种多任务调度装置,装置包括;In a second aspect, an embodiment of the present invention provides a multi-task scheduling apparatus, the apparatus includes:
获取模块,用于获取任务配置文件,其中,任务配置文件包含多个目标任务的配置信息,配置信息包括任务调度周期、任务调度顺序;an acquisition module, configured to acquire a task configuration file, wherein the task configuration file includes configuration information of multiple target tasks, and the configuration information includes a task scheduling period and a task scheduling sequence;
调度模块,用于基于任务配置文件,利用守护进程对多个目标任务进行调度和任务状态监控,其中,守护进程的任务调度时钟根据任务调度周期和任务调度顺序确定,每一目标任务对应一个任务调度时钟,守护进程对应的共享内存用于各目标任务之间的数据交换以及用于存储第一任务状态信息,第一任务状态信息是各目标任务在执行调度过程中,生成的任务状态信息。The scheduling module is used to schedule multiple target tasks and monitor task status by using the daemon process based on the task configuration file. The task scheduling clock of the daemon process is determined according to the task scheduling period and task scheduling sequence, and each target task corresponds to a task The scheduling clock and the shared memory corresponding to the daemon process are used for data exchange between target tasks and for storing first task status information, which is task status information generated by each target task during the scheduling process.
可选的,装置还包括:Optionally, the device further includes:
第一确定模块,用于针对每一目标任务,根据每一目标任务的任务调度周期和关联目标任务的任务调度顺序,确定任务调度时钟,其中,多个目标任务对应的多个任务调度时钟具有同一时钟源。The first determination module is configured to, for each target task, determine the task scheduling clock according to the task scheduling period of each target task and the task scheduling sequence of the associated target task, wherein the multiple task scheduling clocks corresponding to the multiple target tasks have the same clock source.
第二确定模块,用于根据任务间数据信息和第二任务状态信息,确定共享内存,共享内存的容量对应任务间数据信息和第二任务状态信息容量的总和。The second determining module is configured to determine the shared memory according to the inter-task data information and the second task state information, and the capacity of the shared memory corresponds to the sum of the inter-task data information and the capacity of the second task state information.
第三确定模块,用于针对每一目标任务,根据每一目标任务对应的配置信息确定任务进程,且将初始化后的任务进程关联至共享内存。The third determining module is configured to, for each target task, determine the task process according to the configuration information corresponding to each target task, and associate the initialized task process with the shared memory.
可选的,第一确定模块,还可以包括:Optionally, the first determining module may further include:
第一确定单元,用于根据多个目标任务的任务调度周期,确定任务调度基准时钟,其中,任务调度基准时钟对应多个目标任务的任务调度周期的最大公约数。The first determining unit is configured to determine the task scheduling reference clock according to the task scheduling cycles of the multiple target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling cycles of the multiple target tasks.
第二确定单元,用于根据任务调度基准时钟和每一目标任务的任务调度周期,确定该目标任务的调度周期计数值,其中,调度周期计数值为任务调度基准时钟对应的N个基准时间,N为正整数。The second determining unit is configured to determine the scheduling cycle count value of the target task according to the task scheduling reference clock and the task scheduling cycle of each target task, wherein the scheduling cycle count value is N reference times corresponding to the task scheduling reference clock, N is a positive integer.
第三确定单元,用于根据任务调度顺序,确定每一目标任务的计数偏移值。The third determining unit is configured to determine the count offset value of each target task according to the task scheduling sequence.
第四确定单元,用于根据任务调度顺序,确定每一目标任务的任务执行方式,其中,当目标任务的任务执行方式为串行执行时,则该目标任务的任务调度时钟对应该目标任务的周期计数值与该目标任务的计数偏移值之和;当目标任务的任务执行方式为并行执行时,则并行执行的多个目标任务的任务调度时钟相同,并行执行的多个目标任务的任务调度时钟对应并行执行任务中每一目标任务的周期计数值与自身目标任务的计数偏移值之和。The fourth determination unit is used to determine the task execution mode of each target task according to the task scheduling sequence, wherein, when the task execution mode of the target task is serial execution, the task scheduling clock of the target task corresponds to the target task's The sum of the cycle count value and the count offset value of the target task; when the task execution mode of the target task is parallel execution, the task scheduling clock of multiple target tasks executed in parallel is the same, and the tasks of multiple target tasks executed in parallel The scheduling clock corresponds to the sum of the cycle count value of each target task in the parallel execution tasks and the count offset value of its own target task.
可选的,第一确定模块,还可以包括:Optionally, the first determining module may further include:
第二确定单元,用于根据任务调度基准时钟,确定系统定时器,系统定时器为所有任务调度的最小时钟片,定时器用于实现多个目标任务基于同一时钟源的同步调度。The second determining unit is used for determining a system timer according to the task scheduling reference clock. The system timer is the smallest clock slice for all task scheduling, and the timer is used to realize synchronous scheduling of multiple target tasks based on the same clock source.
在一个可选的实施例中,共享内存基于系统进程锁进行数据读写。In an optional embodiment, the shared memory performs data reading and writing based on system process locks.
在一个可选的实施例中,任务配置信息还包括任务名称、任务核绑定信息、任务优先级、第二任务状态信息、任务间数据信息中的至少一种,其中,第二任务状态信息为每一目标任务原始的任务状态信息。In an optional embodiment, the task configuration information further includes at least one of a task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the second task status information Raw task status information for each target task.
可选的,调度模块,可以包括:Optionally, the scheduling module can include:
第一触发单元,用于根据目标任务的任务调度时钟触发该目标任务。The first triggering unit is configured to trigger the target task according to the task scheduling clock of the target task.
第一获取单元,用于基于每一关联目标任务的数据偏移地址,获取存储于共享内存中关联目标任务的第一数据,其中,第一数据是关联目标任务待发送给目标任务的数据。The first obtaining unit is configured to obtain the first data of the associated target task stored in the shared memory based on the data offset address of each associated target task, where the first data is data to be sent to the target task by the associated target task.
第一确定单元,用于基于第一数据,执行目标任务,并确定第二数据,其中,第二数据与目标任务执行结果相对应,第二数据包括第三数据和第四数据,第三数据是关联目标任务待接收的数据,第四数据是目标任务执行任务后确定的状态信息数据。a first determining unit, configured to execute the target task based on the first data, and determine second data, wherein the second data corresponds to the execution result of the target task, the second data includes third data and fourth data, and the third data is the data to be received by the associated target task, and the fourth data is the state information data determined after the target task executes the task.
第一监控单元,用于根据第四数据,对目标任务及其关联目标任务进行监控。The first monitoring unit is configured to monitor the target task and its associated target task according to the fourth data.
可选的,第一监控单元,可以包括:Optionally, the first monitoring unit may include:
第一获取子单元,用于获取第四数据。The first obtaining subunit is used to obtain fourth data.
第一判断子单元,用于根据第四数据,判断目标任务执行结果是否报错和/或目标任务是否异常退出。The first judging subunit is used for judging whether the execution result of the target task reports an error and/or whether the target task exits abnormally according to the fourth data.
第一响应子单元,用于响应于目标任务执行结果报错和/或目标任务异常退出,根据预先设置的错误等级向关联目标任务下发相应控制指令。The first response subunit is configured to issue a corresponding control instruction to the associated target task according to a preset error level in response to an error report of the execution result of the target task and/or the abnormal exit of the target task.
由上述内容可知,本发明实施例提供的一种多任务调度方法及装置,获取任务配置文件,其中,任务配置文件包含多个目标任务的配置信息,配置信息包括任务调度周期、任务调度顺序;基于任务配置文件,利用守护进程对多个目标任务进行调度和任务状态监控,其中,守护进程的任务调度时钟根据任务调度周期和任务调度顺序确定,每一目标任务对应一个任务调度时钟,守护进程对应的共享内存用于各目标任务之间的数据交换以及用于存储第一任务状态信息,第一任务状态信息是各目标任务在执行调度过程中,生成的任务状态信息。As can be seen from the above, a multi-task scheduling method and device provided by the embodiments of the present invention obtain a task configuration file, wherein the task configuration file includes configuration information of multiple target tasks, and the configuration information includes a task scheduling period and a task scheduling sequence; Based on the task configuration file, the daemon process is used to schedule and monitor the task status of multiple target tasks. The task scheduling clock of the daemon process is determined according to the task scheduling cycle and task scheduling sequence. Each target task corresponds to a task scheduling clock. The corresponding shared memory is used for data exchange between each target task and for storing first task state information, where the first task state information is task state information generated by each target task during the execution and scheduling process.
应用本发明实施例,可以对多任务进行统一调度和实时监控。当然,实施本发明的任一产品或方法并不一定需要同时达到以上所述的所有优点。By applying the embodiments of the present invention, unified scheduling and real-time monitoring of multiple tasks can be performed. Of course, it is not necessary for any product or method of the present invention to achieve all of the advantages described above at the same time.
本发明实施例的技术效果包括:The technical effects of the embodiments of the present invention include:
1、现有技术中在多任务操作系统中各任务是分别启动,并独立运行的,本发明实施例利用守护进程对多任务进行统一调度,可以提高多任务启动效率,实时调控多个任务。本发明实施例在多任务操作系统中增加了统一调配和管理多任务的角色。1. In the prior art, each task in a multitasking operating system is started separately and runs independently. The embodiment of the present invention utilizes a daemon process to perform unified scheduling of multitasking, which can improve the efficiency of multitasking startup and control multiple tasks in real time. The embodiment of the present invention adds the role of unified allocation and management of multitasking in the multitasking operating system.
2、本发明实施例通过守护进程可配置的方式对多个任务进行调度,守护进程根据获取到的任务配置文件中的各目标任务配置信息,生成基于同一时钟源的各目标任务对应的任务调度时钟,通过任务调度时钟触发相应目标任务,实现了各目标任务间的时钟同步。2. In the embodiment of the present invention, multiple tasks are scheduled in a configurable manner by a daemon process, and the daemon process generates a task schedule corresponding to each target task based on the same clock source according to the configuration information of each target task in the obtained task configuration file. The clock triggers the corresponding target task through the task scheduling clock, and realizes the clock synchronization between the target tasks.
3、在复杂工程应用中,多任务之间需要协同作业,例如多核分布式系统应用,各任务之间需要数据通信,本发明实施例中的目标任务与关联目标任务利用共享内存进行数据交换,实现了工程应用中各目标任务的联合应用。3. In complex engineering applications, multi-tasks need to work collaboratively. For example, in multi-core distributed system applications, data communication is required between tasks. In the embodiment of the present invention, the target task and the associated target task use shared memory for data exchange, The joint application of each target task in engineering application is realized.
4、本发明实施例中的目标任务每执行一次任务调度,将生成的任务状态信息写入共享内存相应的位置,守护进程可通过获取目标任务存储在共享内存中的任务状态信息,对目标任务进行监控,并根据目标任务的任务状态信息实时控制相应的关联目标任务,以实现各目标任务的实时监控和管理。4. Each time the target task in the embodiment of the present invention performs task scheduling, the generated task status information is written into the corresponding position of the shared memory. Monitor and control the corresponding associated target tasks in real time according to the task status information of the target tasks, so as to realize the real-time monitoring and management of each target task.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单介绍。显而易见地,下面描述中的附图仅仅是本发明的一些实施例。对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that are required in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.
图1为本发明实施例提供的多任务调度方法的一种流程示意图;1 is a schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention;
图2为本发明实施例提供的多任务调度方法的另一种流程示意图;FIG. 2 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention;
图3为本发明实施例提供的多任务调度方法的又一种流程示意图;FIG. 3 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention;
图4为本发明实施例提供的多任务调度方法的又一种流程示意图;FIG. 4 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention;
图5为本发明实施例提供的多任务调度装置的一种结构示意图。FIG. 5 is a schematic structural diagram of a multitask scheduling apparatus provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整的描述。显然,所描述的实施例仅仅是本发明的一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, but not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
需要说明的是,本发明实施例及附图中的术语“包括”和“具有”以及它们的任何变形,意图在于覆盖不排他的包含。例如包含的一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其他步骤或单元。It should be noted that the terms "comprising" and "having" and any modifications thereof in the embodiments of the present invention and the accompanying drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the steps or units listed, but optionally also includes steps or units not listed, or optionally also includes For other steps or units inherent to these processes, methods, products or devices.
本发明提供了一种多任务调度方法及装置。下面对本发明实施例进行详细说明。The present invention provides a multitask scheduling method and device. The embodiments of the present invention will be described in detail below.
图1为本发明实施例提供的多任务调度方法的一种流程示意图。该方法可以包括如下步骤:FIG. 1 is a schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention. The method may include the following steps:
S101:获取任务配置文件,其中,所述任务配置文件包含多个目标任务的配置信息,所述配置信息包括任务调度周期、任务调度顺序。S101: Acquire a task configuration file, wherein the task configuration file includes configuration information of multiple target tasks, and the configuration information includes a task scheduling period and a task scheduling sequence.
任务配置文件是一个预先定义的配置文件,任务配置文件中描述了各个工程应用中各个任务的进程配置信息。其中,每一个工程应用中可以包括多个任务,每一个任务可以和其他多个任务存在关联。The task configuration file is a predefined configuration file, and the task configuration file describes the process configuration information of each task in each engineering application. Wherein, each engineering application may include multiple tasks, and each task may be associated with multiple other tasks.
任务调度周期是指各个目标任务的调度周期,也就是触发调度一次目标任务的时间间隔,每个目标任务对应着一个任务调度周期。任务调度顺序是指调度各个目标任务的顺序,任务调度顺序分为两类,一类是并行调度,一类是串行调度,并行调度的各个任务调度顺序相同,串行调度的各个任务调度顺序有先后。The task scheduling period refers to the scheduling period of each target task, that is, the time interval for triggering the scheduling of a target task, and each target task corresponds to a task scheduling period. The task scheduling order refers to the order in which each target task is scheduled. The task scheduling order is divided into two categories, one is parallel scheduling, and the other is serial scheduling. The scheduling order of each task in parallel scheduling is the same, and the scheduling order of each task in serial scheduling is the same. There is a sequence.
S102:基于所述任务配置文件,利用守护进程对多个目标任务进行调度和任务状态监控,其中,所述守护进程的任务调度时钟根据所述任务调度周期和所述任务调度顺序确定,每一目标任务对应一个任务调度时钟,所述守护进程对应的共享内存用于各目标任务之间的数据交换以及用于存储第一任务状态信息,所述第一任务状态信息是各目标任务在执行调度过程中,生成的任务状态信息。S102: Based on the task configuration file, use a daemon process to schedule multiple target tasks and monitor task status, wherein the task scheduling clock of the daemon process is determined according to the task scheduling period and the task scheduling order, and each The target task corresponds to a task scheduling clock, and the shared memory corresponding to the daemon process is used for data exchange between each target task and for storing first task status information, where the first task status information is the execution schedule of each target task. During the process, the task status information is generated.
本发明实施例利用守护进程对每一个目标任务进行动态调度和实时任务状态的监控,守护进程在多任务操作系统启动时自动启动,在操作系统关闭时自动退出。在每次启动守护进程后,可以读取一次任务配置文件,根据读取到的任务配置文件,调度多个目标任务。本发明实施例中的守护进程是基于任务配置文件创建的,所以守护进程的任务调度时钟可以根据任务配置文件中每个目标任务的任务调度周期和任务调度顺序创建,串行调度的每个目标任务的任务调度时钟不同,并行调度的多个任务的任务调度时钟相同。与守护进程相对应的还设有共享内存,共享内存用于储存各目标任务执行任务后,生成的数据通信信息和第一任务状态信息,并且利用共享内存进行各目标任务之间的数据交换。The embodiment of the present invention utilizes a daemon process to dynamically schedule each target task and monitor the real-time task status. The daemon process is automatically started when the multitasking operating system is started, and automatically exits when the operating system is shut down. After each start of the daemon process, the task configuration file can be read once, and multiple target tasks can be scheduled according to the read task configuration file. The daemon process in the embodiment of the present invention is created based on the task configuration file, so the task scheduling clock of the daemon process can be created according to the task scheduling period and task scheduling sequence of each target task in the task configuration file. The task scheduling clocks of tasks are different, and the task scheduling clocks of multiple tasks scheduled in parallel are the same. Corresponding to the daemon process, there is also a shared memory. The shared memory is used to store the data communication information and the first task state information generated after each target task executes the task, and use the shared memory to exchange data between the target tasks.
现有技术中,多任务操作系统中缺少一个任务配置和管理监控的角色,很难做到多个任务间的协调和同步,应用本发明实施例可以实现多任务的统一调度,可以在守护进程启动后,同时挂起多个任务,等待任务调度时钟的触发,可以根据触发目标任务后生成的任务执行结果,实时监控自身目标任务和控制关联目标任务。In the prior art, the multitasking operating system lacks a role of task configuration and management monitoring, and it is difficult to achieve coordination and synchronization among multiple tasks. By applying the embodiments of the present invention, unified scheduling of multitasking can be realized, and the daemon process can be implemented. After startup, suspend multiple tasks at the same time and wait for the trigger of the task scheduling clock. According to the task execution result generated after triggering the target task, it can monitor its own target task and control the associated target task in real time.
在一个可选的实施例中,所述任务配置信息还包括任务名称、任务核绑定信息、任务优先级、第二任务状态信息、任务间数据信息中的至少一种,其中,所述第二任务状态信息为每一目标任务原始的任务状态信息。In an optional embodiment, the task configuration information further includes at least one of a task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the first The second task state information is the original task state information of each target task.
任务名称是指各个工程应用中各个目标任务的名称。任务核绑定信息是指定每个目标任务绑定到处理器的某一个核上执行的信息,本发明实施例中,可以将目标任务指定到具体核,也可以缺省不指定,由操作系统自动分配,这都是可以的。任务优先级是指定各目标任务进程的优先级。可以指定到操作系统进程优先级0-255范围内,也可以缺省不指定,继承守护进程优先级,在此不做限定。第二任务状态信息是指在应用本发明实施例中的守护进行调度各个目标任务之前,各目标任务对应的任务状态反馈信息,包括但不限于原始的状态数据的偏移地址等。任务间数据信息表示各个目标任务之间交互的数据信息,包括但不限于读写的数据偏移地址,数据长度等。The task name refers to the name of each target task in each engineering application. The task core binding information is information specifying that each target task is bound to be executed on a certain core of the processor. In this embodiment of the present invention, the target task may be specified to a specific core, or it may not be specified by default. Automatic allocation, that's all possible. The task priority is to specify the priority of each target task process. It can be specified within the operating system process priority range of 0-255, or it can be not specified by default and inherit the daemon process priority, which is not limited here. The second task status information refers to task status feedback information corresponding to each target task before applying the guardian in the embodiment of the present invention to schedule each target task, including but not limited to the offset address of the original status data. The inter-task data information represents the data information exchanged between each target task, including but not limited to the read and write data offset addresses, data lengths, and the like.
图2为本发明实施例提供的多任务调度方法的另一种流程示意图。在上述实施例的基础上,所述基于所述任务配置文件,利用守护进程对多个目标任务进行调度和监控之前,如图2所示,还可以包括:FIG. 2 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention. On the basis of the above embodiment, before using the daemon process to schedule and monitor multiple target tasks based on the task configuration file, as shown in FIG. 2 , it may further include:
S201:针对每一目标任务,根据每一目标任务的所述任务调度周期和关联目标任务的所述任务调度顺序,确定所述任务调度时钟,其中,多个目标任务对应的多个所述任务调度时钟具有同一时钟源。S201: For each target task, determine the task scheduling clock according to the task scheduling period of each target task and the task scheduling sequence associated with the target task, wherein a plurality of the tasks corresponding to the plurality of target tasks Scheduled clocks have the same clock source.
每一个目标任务有一个与自身对应的任务调度时钟,所有的任务调度时钟都基于同一时钟源,所以实现了各个目标任务之间的时钟同步。需要说明的是目标任务的任务调度时钟的生成,不但依据目标任务的任务调度周期和关联目标任务的任务调度顺序,同时还依据目标任务的任务调度顺序。本发明实施例中的关联目标任务指的是一个或多个与目标任务相关联的任务。Each target task has a task scheduling clock corresponding to itself, and all task scheduling clocks are based on the same clock source, so the clock synchronization between each target task is realized. It should be noted that the generation of the task scheduling clock of the target task is not only based on the task scheduling period of the target task and the task scheduling order associated with the target task, but also according to the task scheduling order of the target task. The associated target task in the embodiment of the present invention refers to one or more tasks associated with the target task.
S202:根据所述任务间数据信息和所述第二任务状态信息,确定所述共享内存,所述共享内存的容量对应所述任务间数据信息和所述第二任务状态信息容量的总和。。S202: Determine the shared memory according to the inter-task data information and the second task state information, where the capacity of the shared memory corresponds to the sum of the inter-task data information and the capacity of the second task state information. .
本发明实施例中需要创建一块各个目标任务共用的共享内存,以便各个目标任务根据共享内存中的偏移地址进行数据交换,同时,也用于守护进程监控和管理各个目标任务的运行状态信息。所以共享内存的大小可以根据任务配置文件中的任务间数据信息和第二任务状态信息的容量大小总和确定。In the embodiment of the present invention, a shared memory shared by each target task needs to be created, so that each target task can exchange data according to the offset address in the shared memory, and at the same time, it is also used for the daemon process to monitor and manage the running status information of each target task. Therefore, the size of the shared memory can be determined according to the total capacity of the inter-task data information and the second task state information in the task configuration file.
S203:针对每一目标任务,根据每一目标任务对应的所述配置信息确定任务进程,且将初始化后的所述任务进程关联至所述共享内存。S203: For each target task, determine a task process according to the configuration information corresponding to each target task, and associate the initialized task process with the shared memory.
在对各目标任务进行调度之前,需要创建各目标任务的进程。可以根据任务配置文件中每个目标任务的配置信息创建对应的任务进程。在一种可实现的方式中,首先根据配置信息中的任务名称,找到目标任务对应的任务可执行文件;接着,根据配置信息中的核绑定信息,调用系统命令绑定目标任务到处理器核;然后根据配置信息中任务优先级,设置任务进程运行的优先级,在任务创建完成后,进行任务内部初始化,并连接到创建的共享内存上,挂起目标任务等待时钟触发信号。当收到守护进程发过来的时钟触发信号后,执行一次调度,执行完成后,又处于挂起等待状态,等待守护进程下一次时钟触发信号的到来,以此来实现守护进程对各个目标任务调度的控制。Before scheduling each target task, the process of each target task needs to be created. The corresponding task process can be created according to the configuration information of each target task in the task configuration file. In an achievable manner, first, according to the task name in the configuration information, find the task executable file corresponding to the target task; then, according to the core binding information in the configuration information, call a system command to bind the target task to the processor Then, according to the task priority in the configuration information, set the priority of the task process. After the task is created, the internal initialization of the task is performed, and it is connected to the created shared memory, and the target task is suspended to wait for the clock trigger signal. After receiving the clock trigger signal sent by the daemon process, execute a scheduling, after the execution is completed, it is in a suspended waiting state again, waiting for the arrival of the next clock trigger signal of the daemon process, so as to realize the daemon process scheduling each target task control.
在一个可选的实施例中,所述共享内存基于系统进程锁进行数据读写。In an optional embodiment, the shared memory performs data reading and writing based on system process locks.
本发明实施例中应用系统进程锁协调各个目标任务的数据读写操作,防止共享内存数据读写冲突,从而保障数据的一致性。In the embodiment of the present invention, the application system process lock coordinates the data read and write operations of each target task, prevents the read and write conflict of the shared memory data, and thus ensures the consistency of the data.
守护进程的创建主要包括三方面,任务调度时钟的创建、对应共享内存的创建以及各个目标任务进程的创建,守护进程在初始化阶段,读取已生成的任务配置文件,将各个目标任务的配置信息读取到内存结构数组中存储,以便后续使用。根据存储的任务配置信息,创建任务调度时钟、共享内存及创建各目标任务进行。在运行过程中,当守护进程启动后,各目标任务通过相应的任务进程挂起各目标任务等待触发,在通过任务调度时钟触发后,将执行结果存储与共享内存中,并且通过共享内存进行各目标任务之间的数据交换,最后根据存储在共享内存中的任务状态信息,监控和控制各目标任务。The creation of the daemon process mainly includes three aspects: the creation of the task scheduling clock, the creation of the corresponding shared memory, and the creation of each target task process. During the initialization phase, the daemon process reads the generated task configuration file and stores the configuration information of each target task. Read into an array of memory structures and store them for subsequent use. According to the stored task configuration information, create a task scheduling clock, share memory, and create each target task. During the running process, when the daemon process is started, each target task suspends each target task through the corresponding task process and waits for triggering. After being triggered by the task scheduling clock, the execution result is stored in the shared memory, and each target task is executed through the shared memory. Data exchange between target tasks, and finally monitor and control each target task according to the task status information stored in the shared memory.
应用本发明实施例创建的守护进程可以对多任务进行统一调度,实时监控各目标任务,根据各目标任务的状态信息,管理控制各目标任务,并且实现了各目标任务之间的时钟同步,更有利于对关联目标任务的实时控制。The daemon process created by the application of the embodiment of the present invention can perform unified scheduling of multiple tasks, monitor each target task in real time, manage and control each target task according to the state information of each target task, and realize clock synchronization between each target task, and more Conducive to real-time control of associated target tasks.
图3为本发明实施例提供的多任务调度方法的又一种流程示意图。在上述实施例的基础上,具体的,所述针对每一目标任务,根据每一目标任务的所述任务调度周期和关联目标任务的所述任务调度顺序,生成所述任务调度时钟,如图3所示,还可以包括:FIG. 3 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention. On the basis of the above embodiment, specifically, for each target task, the task scheduling clock is generated according to the task scheduling period of each target task and the task scheduling sequence associated with the target task, as shown in FIG. 3, can also include:
S301:根据多个目标任务的所述任务调度周期,确定任务调度基准时钟,其中,所述任务调度基准时钟对应多个目标任务的所述任务调度周期的最大公约数。S301: Determine a task scheduling reference clock according to the task scheduling periods of multiple target tasks, where the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling periods of the multiple target tasks.
在确定每个目标任务的任务调度时钟之前,首先要确定任务调度基准时钟,任务调度基准时钟可以为所有目标任务的任务调度周期的最大公约数,取最大公约数而不是任意一个公约数,更有利于简化计时程序。Before determining the task scheduling clock of each target task, first determine the task scheduling reference clock. The task scheduling reference clock can be the greatest common divisor of the task scheduling cycles of all target tasks, and the greatest common divisor is taken instead of any common divisor. Conducive to simplifying the timing procedure.
S302:根据所述任务调度基准时钟和每一目标任务的所述任务调度周期,确定该目标任务的调度周期计数值,其中,所述调度周期计数值为所述任务调度基准时钟对应的N个基准时间,N为正整数。S302: Determine a scheduling period count value of the target task according to the task scheduling reference clock and the task scheduling period of each target task, where the scheduling period count value is N corresponding to the task scheduling reference clock Base time, N is a positive integer.
因为目标任务的一个任务调度周期为基准时钟对应的N个基准时间,而任务调度周期计数值是单个任务调度周期的数值,所以调度周期计数值为N个基准时间。Because one task scheduling cycle of the target task is N reference times corresponding to the reference clock, and the task scheduling cycle count value is the value of a single task scheduling cycle, the scheduling cycle count value is N reference times.
S303:根据所述任务调度顺序,确定每一目标任务的计数偏移值。S303: Determine a count offset value of each target task according to the task scheduling sequence.
根据各个目标任务的调度顺序要求不同,计算计数偏移值。计数偏移值用于区分每一目标任务在单次任务调度触发循环中的顺序位置。每个目标任务的任务调度时钟是由在该目标任务的任务调度周期的基础上加上该目标任务的调度顺序对应的计数偏移值得到的。例如三个串行任务(a/b/c)都是10ms调度一次,但a任务的计数偏移值是1ms,b任务的计数偏移值是3ms,c任务的计数偏移值是7ms,则a/b/c任务调度时钟分别可以是11ms/13ms/17ms、21ms/23ms/27ms、31ms/33ms/37ms……;又如三个并行任务(d/e/f)都是10ms调度一次,d/e/f任务计数偏移值都是5ms,则d/e/f任务调度时钟都分别可以是15ms/15ms/15ms、25ms/25ms/25ms、35ms/35ms/35ms……。Calculate the count offset value according to the different scheduling sequence requirements of each target task. The count offset value is used to distinguish the sequential position of each target task in a single task scheduling trigger cycle. The task scheduling clock of each target task is obtained by adding a count offset value corresponding to the scheduling sequence of the target task on the basis of the task scheduling period of the target task. For example, three serial tasks (a/b/c) are scheduled once every 10ms, but the count offset value of task a is 1ms, the count offset value of task b is 3ms, and the count offset value of task c is 7ms, Then the a/b/c task scheduling clocks can be 11ms/13ms/17ms, 21ms/23ms/27ms, 31ms/33ms/37ms...; for another example, three parallel tasks (d/e/f) are scheduled once every 10ms , d/e/f task count offset values are all 5ms, then the d/e/f task scheduling clocks can be 15ms/15ms/15ms, 25ms/25ms/25ms, 35ms/35ms/35ms... respectively.
S304:根据所述任务调度顺序,确定每一目标任务的任务执行方式,其中,当目标任务的任务执行方式为串行执行时,则该目标任务的任务调度时钟对应该目标任务的所述周期计数值与该目标任务的计数偏移值之和;当目标任务的任务执行方式为并行执行时,则并行执行的多个目标任务的所述任务调度时钟相同,所述并行执行的多个目标任务的所述任务调度时钟对应并行执行任务中每一目标任务的所述周期计数值与自身目标任务的所述计数偏移值之和。S304: Determine the task execution mode of each target task according to the task scheduling sequence, wherein, when the task execution mode of the target task is serial execution, the task scheduling clock of the target task corresponds to the period of the target task The sum of the count value and the count offset value of the target task; when the task execution mode of the target task is parallel execution, the task scheduling clocks of the multiple target tasks executed in parallel are the same, and the multiple targets executed in parallel have the same task scheduling clock. The task scheduling clock of a task corresponds to the sum of the cycle count value of each target task in the parallel execution tasks and the count offset value of its own target task.
任务调度顺序分为两种串行调度、并行调度。如果某几个目标任务有串行执行要求,那么在需要在各个目标任务的任务周期计数值上加相应的计数偏移值。从而根据周期计数值+计数偏移值来控制时钟触发信号的发送时机,也就控制了任务执行的顺序,实现多任务的串行执行;如果某几个目标任务是并行执行的,那么这几个目标任务的周期计数值+计数偏移值是相同的,即并行执行的多个任务的任务触发时钟是相同的。上述中的时钟触发信号也是在创建任务调度时钟过程中定义的,任务配置文件中的配置信息也还可以包括任务序号,根据任务序号定义每个目标任务的时钟触发信号。根据每个目标任务的任务调度时钟,发送相应的时钟触发信号给目标任务,唤醒目标任务执行一次任务。每个目标任务的时钟触发信号都不相同。Task scheduling sequence is divided into two kinds of serial scheduling, parallel scheduling. If some target tasks have serial execution requirements, then a corresponding count offset value needs to be added to the task cycle count value of each target task. Therefore, the timing of sending the clock trigger signal is controlled according to the cycle count value + the count offset value, which controls the order of task execution and realizes the serial execution of multiple tasks; if some target tasks are executed in parallel, then these The cycle count value + the count offset value of the target tasks are the same, that is, the task trigger clocks of multiple tasks executed in parallel are the same. The clock trigger signal in the above is also defined in the process of creating the task scheduling clock. The configuration information in the task configuration file may also include a task sequence number, and the clock trigger signal of each target task is defined according to the task sequence number. According to the task scheduling clock of each target task, the corresponding clock trigger signal is sent to the target task, and the target task is awakened to execute the task once. The clock trigger signal for each target task is different.
在一个可选的实施例中,所述针对每一目标任务,根据每一目标任务的所述任务调度周期和关联目标任务的所述任务调度顺序,生成所述任务调度时钟,还可以包括:In an optional embodiment, for each target task, generating the task scheduling clock according to the task scheduling period of each target task and the task scheduling sequence associated with the target task may further include:
根据所述任务调度基准时钟,生成系统定时器,所述系统定时器为所有任务调度的最小时钟片,所述定时器用于实现多个目标任务基于同一时钟源的同步调度。According to the task scheduling reference clock, a system timer is generated, where the system timer is the smallest clock slice for all task scheduling, and the timer is used to implement synchronous scheduling of multiple target tasks based on the same clock source.
守护进程调度的所有目标任务都基于同一个时钟源,即所有目标任务依托同一个系统定时器计时,当达到某一目标任务的周期计数值时,再加上相应的计数偏移值的时间,触发一次该目标任务时钟触发信号,发送给响应的任务。各个目标任务进程创建并启动后,目标任务处于挂起等待触发信号的状态,当某一目标任务收到守护进程发送来的时钟触发信号时,执行一次任务调度。All target tasks scheduled by the daemon are based on the same clock source, that is, all target tasks rely on the same system timer for timing. When the period count value of a target task is reached, add the time of the corresponding count offset value, Trigger the clock trigger signal of the target task once and send it to the responding task. After each target task process is created and started, the target task is in a state of suspending and waiting for a trigger signal. When a target task receives a clock trigger signal sent by the daemon process, a task scheduling is performed.
图4为本发明实施例提供的多任务调度方法的又一种流程示意图。在上述实施例的基础上,具体的,所述基于所述任务配置文件,利用目标守护进程对多个目标任务进行调度和监控,如图4所示,还可以包括:FIG. 4 is another schematic flowchart of a multitask scheduling method provided by an embodiment of the present invention. On the basis of the above embodiment, specifically, based on the task configuration file, the target daemon process is used to schedule and monitor multiple target tasks, as shown in FIG. 4 , may also include:
S401:根据目标任务的所述任务调度时钟触发该目标任务。S401: Trigger the target task according to the task scheduling clock of the target task.
守护进程周期性的调度每一个目标任务,在每一次调度中,首先守护进程根据目标任务的任务调度时钟向目标任务发出时钟触发信号,以便触发该目标任务。The daemon periodically schedules each target task. In each scheduling, first the daemon sends a clock trigger signal to the target task according to the task scheduling clock of the target task, so as to trigger the target task.
S402:基于每一关联目标任务的数据偏移地址,获取存储于所述共享内存中关联目标任务的第一数据,其中,所述第一数据是关联目标任务待发送给目标任务的数据。S402: Based on the data offset address of each associated target task, obtain first data of the associated target task stored in the shared memory, where the first data is data to be sent to the target task by the associated target task.
当目标任务接收到触发信号后,首先从共享内存中读取其关联任务存储在共享内存中第一数据。每一目标任务在执行任务后,将需要关联目标任务读取的数据存储在共享内存中,需要关联目标任务读取的这部分数据为第一数据,即各关联目标任务之间通信数据。第一数据存储在每个关联目标任务对应的位置,可以通过每个关联目标任务相应的数据偏移地址获取第一数据。When the target task receives the trigger signal, it first reads the first data stored in the shared memory by its associated task from the shared memory. After each target task executes the task, the data that needs to be read by the associated target task is stored in the shared memory, and the part of the data that needs to be read by the associated target task is the first data, that is, the communication data between the associated target tasks. The first data is stored in a position corresponding to each associated target task, and the first data can be acquired through a data offset address corresponding to each associated target task.
S403:基于所述第一数据,执行目标任务,并确定第二数据,其中,所述第二数据与目标任务执行结果相对应,所述第二数据包括第三数据和第四数据,所述第三数据是关联目标任务待接收的数据,第四数据是目标任务执行任务后确定的状态信息数据。S403: Execute the target task based on the first data, and determine second data, wherein the second data corresponds to the execution result of the target task, the second data includes third data and fourth data, and the The third data is data to be received by the associated target task, and the fourth data is state information data determined after the target task executes the task.
在获取各关联目标任务通信数据之后,执行目标任务,并生成执行结果的数据,即第二数据。第三数据为需要关联目标任务在下次触发后,在执行任务之前,读取的与目标任务有关的通信数据。本发明实施例中利用共享内存进行各目标任务之间的数据交换,提高了各目标任务间数据交换效率。After the communication data of each associated target task is acquired, the target task is executed, and the data of the execution result, that is, the second data, is generated. The third data is the communication data related to the target task that needs to be read after the associated target task is triggered next time and before the task is executed. In the embodiment of the present invention, the shared memory is used to perform data exchange among the target tasks, thereby improving the data exchange efficiency among the target tasks.
S404:根据所述第四数据,对目标任务及其关联目标任务进行监控。S404: Monitor the target task and its associated target task according to the fourth data.
守护进程通过获取存储在共享内存中的第四数据,可以监控目标任务的实时状态,并针对获取到的目标任务的实时状态信息,确定目标任务相关联的多个任务的控制指令。The daemon process can monitor the real-time status of the target task by acquiring the fourth data stored in the shared memory, and determine control instructions of multiple tasks associated with the target task according to the acquired real-time status information of the target task.
在一个可选的实施例中,所述根据所述第四数据,对目标任务及其关联目标任务进行监控,还可以包括:In an optional embodiment, the monitoring of the target task and its associated target task according to the fourth data may further include:
S501:获取所述第四数据。S501: Acquire the fourth data.
每执行一次任务调度,各个目标任务把自己的执行状态写入到共享内存中相应的位置。守护进程可以从共享内存中获取各个目标任务的实时执行状态信息,以便监控各个目标任务。Each time a task scheduling is performed, each target task writes its own execution state to the corresponding location in the shared memory. The daemon can obtain real-time execution status information of each target task from the shared memory, so as to monitor each target task.
S502:根据所述第四数据,判断目标任务执行结果是否报错和/或目标任务是否异常退出。S502: According to the fourth data, determine whether the execution result of the target task reports an error and/or whether the target task exits abnormally.
守护进程可以从获取到任务状态信息中得知执行结果是否报错,任务执行中断,异常退出等情况。The daemon process can know whether the execution result reports an error, the task execution is interrupted, and the abnormal exit occurs from the obtained task status information.
S503:响应于目标任务执行结果报错和/或目标任务异常退出,根据预先设置的错误等级向关联目标任务下发相应控制指令。S503: In response to an error report of the execution result of the target task and/or the abnormal exit of the target task, issue a corresponding control instruction to the associated target task according to a preset error level.
守护进程可以根据预先定义的错误等级控制与目标任务关联的其它目标任务的执行。例如,需要串行执行的A任务和B任务,串行执行方式为先执行A任务,再执行B任务,如果在调度A任务后,A任务的执行结果显示A任务异常退出,这时若再接着触发B任务则没有意义,所以守护进程可以下发指令,停止触发B任务。本发明实施例中的守护进程实现了多任务之间的协同管理。The daemon can control the execution of other target tasks associated with the target task according to a predefined error level. For example, if task A and task B need to be executed serially, the serial execution method is to execute task A first, and then execute task B. If after scheduling task A, the execution result of task A shows that task A has exited abnormally. Then triggering task B is meaningless, so the daemon can issue an instruction to stop triggering task B. The daemon process in the embodiment of the present invention realizes collaborative management among multiple tasks.
相应于上述方法实施例,本发明实施例提供了一种多任务调度装置。Corresponding to the above method embodiments, the embodiments of the present invention provide a multi-task scheduling apparatus.
图5为本发明实施例提供的多任务调度装置的一种结构示意图,如图5所示,所述装置可以包括:FIG. 5 is a schematic structural diagram of a multitask scheduling apparatus provided by an embodiment of the present invention. As shown in FIG. 5 , the apparatus may include:
获取模块501,用于获取任务配置文件,其中,所述任务配置文件包含多个目标任务的配置信息,所述配置信息包括任务调度周期、任务调度顺序;an obtaining
调度模块502,用于基于所述任务配置文件,利用守护进程对多个目标任务进行调度和任务状态监控,其中,所述守护进程的任务调度时钟根据所述任务调度周期和所述任务调度顺序确定,每一目标任务对应一个任务调度时钟,所述守护进程对应的共享内存用于各目标任务之间的数据交换以及用于存储第一任务状态信息,所述第一任务状态信息是各目标任务在执行调度过程中,生成的任务状态信息。The
在一个可选的实施例中,所述任务配置信息还包括任务名称、任务核绑定信息、任务优先级、第二任务状态信息、任务间数据信息中的至少一种,其中,所述第二任务状态信息为每一目标任务原始的任务状态信息。In an optional embodiment, the task configuration information further includes at least one of a task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the first The second task state information is the original task state information of each target task.
在一个可选的实施例中,所述装置还包括:In an optional embodiment, the apparatus further includes:
第一确定模块,用于针对每一目标任务,根据每一目标任务的所述任务调度周期和关联目标任务的所述任务调度顺序,确定所述任务调度时钟,其中,多个目标任务对应的多个所述任务调度时钟具有同一时钟源。The first determining module is configured to, for each target task, determine the task scheduling clock according to the task scheduling period of each target task and the task scheduling sequence associated with the target task, wherein the corresponding A plurality of the task scheduling clocks have the same clock source.
第二确定模块,用于根据所述任务间数据信息和所述第二任务状态信息,确定所述共享内存,所述共享内存的容量对应所述任务间数据信息和所述第二任务状态信息容量的总和。A second determining module, configured to determine the shared memory according to the inter-task data information and the second task status information, where the capacity of the shared memory corresponds to the inter-task data information and the second task status information the sum of the capacity.
第三确定模块,用于针对每一目标任务,根据每一目标任务对应的所述配置信息确定任务进程,且将初始化后的所述任务进程关联至所述共享内存。The third determining module is configured to, for each target task, determine a task process according to the configuration information corresponding to each target task, and associate the initialized task process with the shared memory.
在一个可选的实施例中,所述第一确定模块,还可以包括:In an optional embodiment, the first determining module may further include:
第一确定单元,用于根据多个目标任务的所述任务调度周期,确定任务调度基准时钟,其中,所述任务调度基准时钟对应多个目标任务的所述任务调度周期的最大公约数。The first determining unit is configured to determine a task scheduling reference clock according to the task scheduling periods of multiple target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling periods of the multiple target tasks.
第二确定单元,用于根据所述任务调度基准时钟和每一目标任务的所述任务调度周期,确定该目标任务的调度周期计数值,其中,所述调度周期计数值为所述任务调度基准时钟对应的N个基准时间,N为正整数。a second determining unit, configured to determine the scheduling cycle count value of the target task according to the task scheduling reference clock and the task scheduling cycle of each target task, wherein the scheduling cycle count value is the task scheduling reference N reference times corresponding to the clock, where N is a positive integer.
第三确定单元,用于根据所述任务调度顺序,确定每一目标任务的计数偏移值。The third determining unit is configured to determine the count offset value of each target task according to the task scheduling sequence.
第四确定单元,用于根据所述任务调度顺序,确定每一目标任务的任务执行方式,其中,当目标任务的任务执行方式为串行执行时,则该目标任务的任务调度时钟对应该目标任务的所述周期计数值与该目标任务的计数偏移值之和;当目标任务的任务执行方式为并行执行时,则并行执行的多个目标任务的所述任务调度时钟相同,所述并行执行的多个目标任务的所述任务调度时钟对应并行执行任务中每一目标任务的所述周期计数值与自身目标任务的所述计数偏移值之和。The fourth determination unit is configured to determine the task execution mode of each target task according to the task scheduling sequence, wherein, when the task execution mode of the target task is serial execution, the task scheduling clock of the target task corresponds to the target task The sum of the cycle count value of the task and the count offset value of the target task; when the task execution mode of the target task is parallel execution, the task scheduling clocks of multiple target tasks executed in parallel are the same, and the parallel The task scheduling clock of the executed multiple target tasks corresponds to the sum of the cycle count value of each target task in the parallel execution tasks and the count offset value of its own target task.
在一个可选的实施例中,所述第一确定模块,还可以包括:In an optional embodiment, the first determining module may further include:
第二确定单元,用于根据所述任务调度基准时钟,确定系统定时器,所述系统定时器为所有任务调度的最小时钟片,所述定时器用于实现多个目标任务基于同一时钟源的同步调度。The second determination unit is configured to determine a system timer according to the task scheduling reference clock, where the system timer is the smallest clock slice scheduled by all tasks, and the timer is used to realize synchronization of multiple target tasks based on the same clock source schedule.
在一个可选的实施例中,所述共享内存基于系统进程锁进行数据读写。In an optional embodiment, the shared memory performs data reading and writing based on system process locks.
在一个可选的实施例中,所述调度模块,可以包括:In an optional embodiment, the scheduling module may include:
第一触发单元,用于根据目标任务的所述任务调度时钟触发该目标任务。The first triggering unit is configured to trigger the target task according to the task scheduling clock of the target task.
第一获取单元,用于基于每一关联目标任务的数据偏移地址,获取存储于所述共享内存中关联目标任务的第一数据,其中,所述第一数据是关联目标任务待发送给目标任务的数据。a first obtaining unit, configured to obtain the first data of the associated target task stored in the shared memory based on the data offset address of each associated target task, wherein the first data is the associated target task to be sent to the target task data.
第一确定单元,用于基于所述第一数据,执行目标任务,并确定第二数据,其中,所述第二数据与目标任务执行结果相对应,所述第二数据包括第三数据和第四数据,所述第三数据是关联目标任务待接收的数据,第四数据是目标任务执行任务后确定的状态信息数据。The first determining unit is configured to execute the target task based on the first data, and determine second data, wherein the second data corresponds to the execution result of the target task, and the second data includes the third data and the first data. Four data, the third data is data to be received associated with the target task, and the fourth data is state information data determined after the target task executes the task.
第一监控单元,用于根据所述第四数据,对目标任务及其关联目标任务进行监控。The first monitoring unit is configured to monitor the target task and its associated target task according to the fourth data.
在一个可选的实施例中,所述第一监控单元,可以包括:In an optional embodiment, the first monitoring unit may include:
第一获取子单元,用于获取所述第四数据。The first obtaining subunit is used to obtain the fourth data.
第一判断子单元,用于根据所述第四数据,判断目标任务执行结果是否报错和/或目标任务是否异常退出。The first judging subunit is used for judging whether the execution result of the target task reports an error and/or whether the target task exits abnormally according to the fourth data.
第一响应子单元,用于响应于目标任务执行结果报错和/或目标任务异常退出,根据预先设置的错误等级向关联目标任务下发相应控制指令。The first response subunit is configured to issue a corresponding control instruction to the associated target task according to a preset error level in response to an error report of the execution result of the target task and/or the abnormal exit of the target task.
相应于上述方法实施例,本发明实施例提供了一种计算机可读存储介质,用于保存计算机程序,其中,所述计算机程序被处理器执行时实现如上述方法实施例中的多任务调度方法。Corresponding to the foregoing method embodiments, embodiments of the present invention provide a computer-readable storage medium for storing a computer program, wherein, when the computer program is executed by a processor, the multi-task scheduling method in the foregoing method embodiments is implemented .
上述系统、装置实施例与系统实施例相对应,与该方法实施例具有同样的技术效果,具体说明参见方法实施例。装置实施例是基于方法实施例得到的,具体的说明可以参见方法实施例部分,此处不再赘述。本领域普通技术人员可以理解:附图只是一个实施例的示意图,附图中的模块或流程并不一定是实施本发明所必须的。The foregoing system and device embodiments correspond to the system embodiments, and have the same technical effects as the method embodiments. For specific descriptions, refer to the method embodiments. The apparatus embodiment is obtained based on the method embodiment, and the specific description can refer to the method embodiment section, which will not be repeated here. Those of ordinary skill in the art can understand that the accompanying drawing is only a schematic diagram of an embodiment, and the modules or processes in the accompanying drawing are not necessarily necessary to implement the present invention.
本领域普通技术人员可以理解:实施例中的装置中的模块可以按照实施例描述分布于实施例的装置中,也可以进行相应变化位于不同于本实施例的一个或多个装置中。上述实施例的模块可以合并为一个模块,也可以进一步拆分成多个子模块。Those skilled in the art may understand that: the modules in the apparatus in the embodiment may be distributed in the apparatus in the embodiment according to the description of the embodiment, and may also be located in one or more apparatuses different from this embodiment with corresponding changes. The modules in the foregoing embodiments may be combined into one module, or may be further split into multiple sub-modules.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that it can still be The technical solutions described in the foregoing embodiments are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210120020.7A CN114528080A (en) | 2022-02-07 | 2022-02-07 | Multi-task scheduling method and device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210120020.7A CN114528080A (en) | 2022-02-07 | 2022-02-07 | Multi-task scheduling method and device |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN114528080A true CN114528080A (en) | 2022-05-24 |
Family
ID=81623190
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210120020.7A Pending CN114528080A (en) | 2022-02-07 | 2022-02-07 | Multi-task scheduling method and device |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114528080A (en) |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050131865A1 (en) * | 2003-11-14 | 2005-06-16 | The Regents Of The University Of California | Parallel-aware, dedicated job co-scheduling method and system |
| CN101777012A (en) * | 2009-12-31 | 2010-07-14 | 深圳市蓝韵实业有限公司 | Three-dimensional image server multi-task managing and scheduling method |
| CN113485814A (en) * | 2021-07-27 | 2021-10-08 | 中国银行股份有限公司 | Batch task scheduling method and device |
-
2022
- 2022-02-07 CN CN202210120020.7A patent/CN114528080A/en active Pending
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050131865A1 (en) * | 2003-11-14 | 2005-06-16 | The Regents Of The University Of California | Parallel-aware, dedicated job co-scheduling method and system |
| CN101777012A (en) * | 2009-12-31 | 2010-07-14 | 深圳市蓝韵实业有限公司 | Three-dimensional image server multi-task managing and scheduling method |
| CN113485814A (en) * | 2021-07-27 | 2021-10-08 | 中国银行股份有限公司 | Batch task scheduling method and device |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| Jensen | Asynchronous decentralized realtime computer systems | |
| JP7101127B2 (en) | Industrial server microkernel architecture control system and industrial server | |
| Merzky et al. | Design and performance characterization of radical-pilot on leadership-class platforms | |
| CN112445598B (en) | Task scheduling method and device based on quartz, electronic equipment and medium | |
| KR20070075957A (en) | Task based robot control system for multi-tasking | |
| GB2425628A (en) | Programming distributed system using data flow diagrams | |
| CN110431806A (en) | System and method for local scheduling of low-latency nodes in distributed resource management | |
| TW202102952A (en) | Robotic resource task cycle management and control method and apparatus | |
| US8225320B2 (en) | Processing data using continuous processing task and binary routine | |
| US9015517B2 (en) | Information processing apparatus and time-of-day control method | |
| WO2013145199A1 (en) | Virtual computer schedule method | |
| CN114528080A (en) | Multi-task scheduling method and device | |
| Jiang et al. | Suspension-based locking protocols for parallel real-time tasks | |
| Zhang et al. | Fast and live model auto scaling with O (1) host caching | |
| Becker et al. | On the QNX IPC: Assessing predictability for local and distributed real-time systems | |
| JP5387083B2 (en) | Job management system and method | |
| CN116339911A (en) | K8S-based elastic simulation Modelica model method, system, equipment and medium | |
| Sousa et al. | Implementing slot-based task-splitting multiprocessor scheduling | |
| Thibodeaux | The specification and implementation of a model of computation | |
| CN111638942A (en) | Application start-stop control method, cloud platform, equipment and readable storage medium | |
| CN119166291B (en) | Database thread pool control method and device, electronic device, and computer medium | |
| Berg et al. | Evaluating distributed MPI checkpoint and restore using docker containers and CRIU | |
| CN120705109A (en) | State synchronization method, device, chip and equipment of multi-core processor | |
| CN119293120A (en) | IEC task data consistency synchronization method, device, electronic device and storage medium | |
| CN117785699A (en) | Regression testing methods, electronic equipment and storage media |
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 |