A multitasking scheduling method and device
By introducing a daemon process into a multitasking operating system to uniformly schedule and monitor tasks, and by using task configuration files to generate task scheduling clocks and shared memory, the problems of time-consuming startup and difficult coordination in multitasking systems are solved, and efficient task management and status monitoring are achieved.
Patent Information
- Application Number
- CN202210120020.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-07
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2042-02-07
AI Technical Summary
In multitasking operating systems, existing technologies typically involve multiple tasks starting and running independently, which leads to time-consuming startups and an inability to coordinate and control them in a timely manner. This is especially inconvenient for maintenance personnel when a large number of tasks need to be started simultaneously, and the tasks cannot be coordinated with each other.
A daemon process is used to uniformly schedule and monitor multiple tasks. The task scheduling clock is generated using the scheduling cycle and order in the task configuration file. Data exchange and status monitoring are performed through shared memory to achieve clock synchronization and coordination between tasks.
It improves the efficiency of multi-task startup, realizes unified scheduling and real-time monitoring of multiple tasks, ensures collaborative operation and data communication between tasks, and enhances real-time management and control of task status.
Smart Images

Figure CN114528080B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically, to a multi-task scheduling method and apparatus. Background Technology
[0002] With the rapid development of computer technology, multitasking operating systems are becoming increasingly common. Multitasking operating systems, such as Windows, Linux, and QNX (Quick UNIX), often run multiple task processes simultaneously. In current technology, these tasks are typically started and run independently. For example, when starting multiple tasks, whether manually or via command scripts, each task must be started and executed one by one, which is time-consuming, especially when starting a large number of tasks simultaneously, causing inconvenience for maintenance personnel. Furthermore, the tasks cannot be coordinated; if one task malfunctions, the execution status of other related tasks cannot be adjusted and controlled in a timely manner. 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 multitasking operating systems. Summary of the Invention
[0003] This invention provides a multi-task scheduling method and apparatus to achieve unified scheduling of multiple tasks. The specific technical solution is as follows:
[0004] In a first aspect, embodiments of the present invention provide a multi-task scheduling method, the method comprising:
[0005] Obtain the task configuration file, which contains configuration information for multiple target tasks, including the task scheduling cycle and task scheduling order.
[0006] Based on the task configuration file, a daemon process is used to schedule and monitor the status of multiple target tasks. The task scheduling clock of the daemon process is determined according to the task scheduling cycle and task scheduling order. Each target task corresponds to a task scheduling clock. The shared memory of the daemon process is used for data exchange between target tasks and for storing the first task status information, which is the task status information generated by each target task during the execution scheduling process.
[0007] Optionally, before scheduling and monitoring multiple target tasks using a daemon process based on task configuration files, the following steps are included:
[0008] For each target task, a task scheduling clock is determined based on the task scheduling cycle of each target task and the task scheduling order of associated target tasks. Multiple task scheduling clocks corresponding to multiple target tasks have the same clock source.
[0009] Based on the inter-task data information and the second task status information, the shared memory is determined, and the capacity of the shared memory corresponds to the sum of the capacities of the inter-task data information and the second task status information.
[0010] For each target task, the task process is determined based on the configuration information corresponding to each target task, and the initialized task process is associated with shared memory.
[0011] Optionally, for each target task, a task scheduling clock is determined based on the task scheduling cycle of each target task and the task scheduling order of associated target tasks, including:
[0012] Based on the task scheduling cycles of multiple target tasks, a task scheduling reference clock is determined, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling cycles of multiple target tasks.
[0013] Based on the task scheduling reference clock and the task scheduling cycle of each target task, determine the scheduling cycle count value of the target task, where the scheduling cycle count value is N reference times corresponding to the task scheduling reference clock, and N is a positive integer;
[0014] Determine the count offset value for each target task based on the task scheduling order;
[0015] Based on the task scheduling order, the execution method for each target task is determined, wherein...
[0016] When the target task is executed serially, the task scheduling clock of the target task corresponds to the sum of the target task's cycle count value and the target task's count offset value;
[0017] When the target task is executed in parallel, the task scheduling clocks of the multiple target tasks executed in parallel are the same. The task scheduling clocks of the multiple target tasks executed in parallel correspond to the sum of the cycle count value of each target task in the parallel execution task and the count offset value of its own target task.
[0018] Optionally, for each target task, a task scheduling clock is determined based on the task scheduling cycle of each target task and the task scheduling order of related target tasks, further including:
[0019] Based on 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.
[0020] Optionally, shared memory can be used for data reading and writing based on system process locks.
[0021] Optionally, based on task configuration files, multiple target tasks can be scheduled and monitored using a target daemon, including:
[0022] The target task is triggered according to the task scheduling clock of the target task;
[0023] Based on the data offset address of each associated target task, the first data of the associated target task stored in the shared memory is obtained, wherein the first data is the data of the associated target task to be sent to the target task;
[0024] Based on the first data, the target task is executed, and the second data is determined. The second data corresponds to the result of the target task execution. The second data includes the third data and the fourth data. The third data is the data to be received associated with the target task, and the fourth data is the status information data determined after the target task is executed.
[0025] Based on the fourth data, the target task and its related target tasks are monitored.
[0026] Optionally, based on the fourth set of data, the target task and its associated target tasks are monitored, including:
[0027] Obtain the fourth data;
[0028] Based on the fourth data, determine whether the target task execution result reports an error and / or whether the target task exits abnormally;
[0029] In response to errors in the execution result of the target task and / or abnormal exit of the target task, corresponding control commands are issued to the associated target task according to the pre-set error level.
[0030] Optionally, the task configuration information may also include at least one of the following: task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the second task status information is the original task status information of each target task.
[0031] Secondly, embodiments of the present invention provide a multi-task scheduling device, the device comprising:
[0032] The acquisition module is used to acquire the task configuration file, which contains configuration information for multiple target tasks, including the task scheduling cycle and the task scheduling order.
[0033] The scheduling module is used to schedule and monitor the status of multiple target tasks based on task configuration files using a daemon process. The task scheduling clock of the daemon process is determined according to the task scheduling cycle and task scheduling order. Each target task corresponds to a task scheduling clock. The shared memory of the daemon process is used for data exchange between target tasks and for storing the first task status information, which is the task status information generated by each target task during the execution scheduling process.
[0034] Optionally, the device also includes:
[0035] The first determining module is used to determine the task scheduling clock for each target task based on the task scheduling cycle of each target task and the task scheduling order of associated target tasks, wherein multiple task scheduling clocks corresponding to multiple target tasks have the same clock source.
[0036] The second determining module is used to determine the shared memory based on the inter-task data information and the second task status information. The capacity of the shared memory corresponds to the sum of the capacities of the inter-task data information and the second task status information.
[0037] The third determination module is used to determine the task process for each target task based on the configuration information corresponding to each target task, and associate the initialized task process with shared memory.
[0038] Optionally, the first determining module may also include:
[0039] The first determining unit is used to determine the task scheduling reference clock based on the task scheduling cycle of multiple target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling cycles of multiple target tasks.
[0040] The second determining unit is used to determine the scheduling cycle count value of the target task based on 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.
[0041] The third determining unit is used to determine the count offset value of each target task according to the task scheduling order.
[0042] The fourth determining unit is used to determine the task execution mode of each target task according to the task scheduling order. 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 the multiple target tasks executed in parallel are the same, and the task scheduling clocks of the multiple target tasks executed in parallel correspond to the sum of the period count value of each target task in the parallel execution task and the count offset value of its own target task.
[0043] Optionally, the first determining module may also include:
[0044] The second determining unit is used to determine the system timer based on the task scheduling reference clock. The system timer is the smallest clock slice for all task scheduling and is used to realize the synchronous scheduling of multiple target tasks based on the same clock source.
[0045] In an optional embodiment, shared memory is used for data reading and writing based on system process locks.
[0046] In an optional embodiment, the task configuration information further includes at least one of the following: task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the second task status information is the original task status information of each target task.
[0047] Optionally, the scheduling module may include:
[0048] The first triggering unit is used to trigger the target task according to the target task's task scheduling clock.
[0049] The first acquisition unit is used to acquire 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 data of the associated target task to be sent to the target task.
[0050] The first determining unit is used to execute the target task based on the first data and determine the second data, wherein the second data corresponds to the execution result of the target task and includes the third data and the fourth data. The third data is the data to be received associated with the target task, and the fourth data is the status information data determined after the target task is executed.
[0051] The first monitoring unit is used to monitor the target task and its associated target tasks based on the fourth data.
[0052] Optionally, the first monitoring unit may include:
[0053] The first acquisition subunit is used to acquire the fourth data.
[0054] The first judgment subunit is used to determine, based on the fourth data, whether the target task execution result reports an error and / or whether the target task exits abnormally.
[0055] The first response subunit is used to issue corresponding control commands to the associated target task in response to errors in the target task execution result and / or abnormal exit of the target task, based on the pre-set error level.
[0056] As can be seen from the above, the multi-task scheduling method and apparatus provided by the embodiments of the present invention obtains a task configuration file, wherein the task configuration file contains configuration information of multiple target tasks, and the configuration information includes a task scheduling cycle and a task scheduling order; based on the task configuration file, a daemon process is used to schedule and monitor the task status of multiple target tasks, wherein the task scheduling clock of the daemon process is determined according to the task scheduling cycle and the task scheduling order, each target task corresponds to a task scheduling clock, and the shared memory corresponding to the daemon process is used for data exchange between target tasks and for storing first task status information, which is the task status information generated by each target task during the execution scheduling process.
[0057] By applying the embodiments of the present invention, multiple tasks can be uniformly scheduled and monitored in real time. Of course, implementing any product or method of the present invention does not necessarily require achieving all the advantages described above simultaneously.
[0058] The technical effects of the embodiments of the present invention include:
[0059] 1. In existing multitasking operating systems, each task is started separately and runs independently. This invention utilizes a daemon process for unified scheduling of multiple tasks, improving multitasking startup efficiency and enabling real-time control of multiple tasks. This invention adds a role for unified allocation and management of multiple tasks to the multitasking operating system.
[0060] 2. In this embodiment of the invention, multiple tasks are scheduled in a configurable manner through a daemon process. The daemon process generates a task scheduling clock for each target task based on the target task configuration information in the obtained task configuration file. The corresponding target task is triggered by the task scheduling clock, thereby realizing clock synchronization between target tasks.
[0061] 3. In complex engineering applications, multiple tasks need to work together. For example, in multi-core distributed system applications, data communication is required between tasks. In the embodiments of this invention, the target task and related target tasks exchange data using shared memory, realizing the joint application of various target tasks in engineering applications.
[0062] 4. In each instance of the present invention, the target task executes task scheduling and writes the generated task status information to the corresponding location in the shared memory. The daemon process can monitor the target task by obtaining the task status information stored in the shared memory and control the corresponding associated target tasks in real time according to the task status information of the target task, so as to realize the real-time monitoring and management of each target task. Attached Figure Description
[0063] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.
[0064] Figure 1 This is a flowchart illustrating a multi-task scheduling method provided in an embodiment of the present invention;
[0065] Figure 2 This is another flowchart illustrating the multi-task scheduling method provided in an embodiment of the present invention;
[0066] Figure 3 This is another flowchart illustrating the multi-task scheduling method provided in an embodiment of the present invention;
[0067] Figure 4 This is another flowchart illustrating the multi-task scheduling method provided in an embodiment of the present invention;
[0068] Figure 5 This is a schematic diagram of a multi-task scheduling device provided in an embodiment of the present invention. Detailed Implementation
[0069] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0070] It should be noted that the terms "comprising" and "having," and any variations thereof, in the embodiments and drawings of this invention 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 may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0071] This invention provides a multi-task scheduling method and apparatus. The embodiments of this invention are described in detail below.
[0072] Figure 1 This is a flowchart illustrating a multi-task scheduling method provided in an embodiment of the present invention. The method may include the following steps:
[0073] S101: Obtain the task configuration file, wherein the task configuration file contains configuration information for multiple target tasks, and the configuration information includes the task scheduling cycle and the task scheduling order.
[0074] A task configuration file is a predefined configuration file that describes the process configuration information of each task in a project application. Each project application can include multiple tasks, and each task can be associated with multiple other tasks.
[0075] The task scheduling cycle refers to the scheduling period of each target task, that is, the time interval between triggering the scheduling of a target task. Each target task corresponds to one task scheduling cycle. The task scheduling order refers to the order in which the target tasks are scheduled. There are two types of task scheduling order: parallel scheduling and serial scheduling. In parallel scheduling, the scheduling order of each task is the same, while in serial scheduling, the scheduling order of each task is sequential.
[0076] S102: Based on the task configuration file, a 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 the task scheduling order. Each target task corresponds to a task scheduling clock. The shared memory corresponding to the daemon process is used for data exchange between target tasks and for storing first task status information. The first task status information is the task status information generated by each target task during the execution scheduling process.
[0077] This invention utilizes a daemon process to dynamically schedule and monitor the real-time task status of each target task. The daemon process automatically starts when the multi-tasking operating system boots and automatically exits when the operating system shuts down. Each time the daemon process starts, it reads the task configuration file once and schedules multiple target tasks based on the read configuration file. Since the daemon process in this invention is created based on the task configuration file, its task scheduling clock can be created according to the task scheduling cycle and order of each target task in the configuration file. The task scheduling clock is different for each target task scheduled serially, while the task scheduling clock is the same for multiple tasks scheduled in parallel. Corresponding to the daemon process, a shared memory is also provided. The shared memory is used to store the data communication information and first task status information generated after each target task executes its task, and data exchange between the target tasks is also performed using the shared memory.
[0078] In the existing technology, multi-tasking operating systems lack a task configuration, management, and monitoring role, making it difficult to coordinate and synchronize multiple tasks. The embodiments of this invention can realize unified scheduling of multiple tasks. After the daemon process starts, multiple tasks can be suspended simultaneously, waiting for the task scheduling clock to be triggered. Based on the task execution results generated after the target task is triggered, the system can monitor its own target task and control related target tasks in real time.
[0079] In an optional embodiment, the task configuration information further includes at least one of the following: task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the second task status information is the original task status information of each target task.
[0080] The task name refers to the name of each target task in each engineering application. Task core binding information specifies which processor core each target task is bound to for execution. In this embodiment, the target task can be assigned to a specific core, or it can be left unspecified and automatically allocated by the operating system; both are acceptable. Task priority specifies the priority of each target task process. It can be specified to the operating system process priority range of 0-255, or it can be left unspecified and inherited from the daemon process priority; no limitation is made here. Second task status information refers to the task status feedback information corresponding to each target task before the daemon in this embodiment schedules each target task, including but not limited to the offset address of the original status data. Inter-task data information represents the data information exchanged between each target task, including but not limited to the data offset address for reading and writing, data length, etc.
[0081] Figure 2 This is another flowchart illustrating the multi-task scheduling method provided in an embodiment of the present invention. Based on the above embodiments, before scheduling and monitoring multiple target tasks using a daemon process based on the task configuration file, as follows... Figure 2 As shown, it may also include:
[0082] S201: For each target task, the task scheduling clock is determined according to the task scheduling cycle of each target task and the task scheduling order of the associated target tasks, wherein the multiple task scheduling clocks corresponding to multiple target tasks have the same clock source.
[0083] Each target task has its own corresponding task scheduling clock, and all task scheduling clocks are based on the same clock source, thus achieving clock synchronization among the target tasks. It should be noted that the generation of the target task's task scheduling clock is based not only on the target task's task scheduling cycle and the task scheduling order of associated target tasks, but also on the task scheduling order of the target tasks themselves. In this embodiment of the invention, associated target tasks refer to one or more tasks related to the target task.
[0084] S202: Based on the inter-task data information and the second task status information, determine the shared memory, wherein the capacity of the shared memory corresponds to the sum of the capacities of the inter-task data information and the second task status information.
[0085] In this embodiment of the invention, a shared memory is needed for all target tasks to exchange data based on the offset addresses in the shared memory. Simultaneously, it is also used by 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 by the sum of the capacity of the inter-task data information and the second task status information in the task configuration file.
[0086] S203: 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.
[0087] Before scheduling each target task, a process for each target task needs to be created. This can be done by creating a corresponding task process based on the configuration information of each target task in the task configuration file. In one possible approach, first, the executable file corresponding to the target task is located based on the task name in the configuration information; then, based on the core binding information in the configuration information, a system command is invoked to bind the target task to the processor core; next, based on the task priority in the configuration information, the task process's running priority is set; after task creation, internal task initialization is performed, and the task is connected to the created shared memory, suspending the target task to wait for a clock trigger signal. Upon receiving a clock trigger signal from the daemon process, a scheduling operation is performed. After execution, the task returns to a suspended waiting state, awaiting the next clock trigger signal from the daemon process. This process allows the daemon process to control the scheduling of each target task.
[0088] In an optional embodiment, the shared memory performs data read and write operations based on system process locks.
[0089] In this embodiment of the invention, a system process lock is used to coordinate the data read and write operations of various target tasks, prevent data read and write conflicts in shared memory, and thus ensure data consistency.
[0090] The creation of the daemon process mainly involves three aspects: the creation of the task scheduling clock, the creation of 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 in a memory structure array for later use. Based on the stored task configuration information, it creates the task scheduling clock, shared memory, and each target task. During operation, after the daemon process starts, each target task suspends itself through its corresponding task process, waiting to be triggered. After being triggered by the task scheduling clock, the execution results are stored in the shared memory, and data exchange between target tasks is performed through the shared memory. Finally, based on the task status information stored in the shared memory, the daemon process monitors and controls each target task.
[0091] The daemon process created using the embodiments 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 status information of each target task, and realize clock synchronization between each target task, which is more conducive to real-time control of related target tasks.
[0092] Figure 3 This is another flowchart illustrating a multi-task scheduling method provided in an embodiment of the present invention. Specifically, based on the above embodiments, for each target task, a task scheduling clock is generated according to the task scheduling period of each target task and the task scheduling order of associated target tasks, such as... Figure 3 As shown, it may also include:
[0093] S301: Determine a task scheduling reference clock based on the task scheduling cycles of multiple target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling cycles of multiple target tasks.
[0094] Before determining the task scheduling clock for each target task, the task scheduling reference clock must first be determined. The task scheduling reference clock can be the greatest common divisor of the task scheduling cycles of all target tasks. Taking the greatest common divisor instead of any arbitrary common divisor is more conducive to simplifying the timing procedure.
[0095] S302: Determine the scheduling cycle count value of the target task based on 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.
[0096] Since one task scheduling cycle of the target task is N reference times corresponding to the reference clock, and the task scheduling cycle count is the value of a single task scheduling cycle, the scheduling cycle count is N reference times.
[0097] S303: Determine the count offset value for each target task according to the task scheduling order.
[0098] The counting offset is calculated based on the different scheduling order requirements of each target task. The counting offset is used to distinguish the sequential position of each target task in a single task scheduling trigger loop. The task scheduling clock of each target task is obtained by adding the counting offset corresponding to the scheduling order of the target task to the task scheduling cycle of that target task. For example, three serial tasks (a / b / c) are all scheduled once every 10ms, but the counting offset of task a is 1ms, the counting offset of task b is 3ms, and the counting offset of task c is 7ms. Then the scheduling clocks of tasks a / b / c can be 11ms / 13ms / 17ms, 21ms / 23ms / 27ms, 31ms / 33ms / 37ms, etc., respectively. Similarly, three parallel tasks (d / e / f) are all scheduled once every 10ms, and the counting offsets of tasks d / e / f are all 5ms. Then the scheduling clocks of tasks d / e / f can be 15ms / 15ms / 15ms, 25ms / 25ms / 25ms, 35ms / 35ms / 35ms, etc., respectively.
[0099] S304: Based on the task scheduling order, determine the task execution mode of each target task. When the task execution mode of a target task is serial execution, the task scheduling clock of the target task corresponds to the sum of the period count value and the count offset value of the target task. When the task execution mode of a target task is parallel execution, the task scheduling clocks of the multiple target tasks executed in parallel are the same, and the task scheduling clocks of the multiple target tasks executed in parallel correspond to the sum of the period count value and the count offset value of each target task in the parallel execution task.
[0100] Task scheduling is divided into two types: serial scheduling and parallel scheduling. If several target tasks require serial execution, a corresponding count offset value needs to be added to the task cycle count value of each target task. This count offset value controls the timing of the clock trigger signal transmission, thus controlling the task execution order and enabling serial execution of multiple tasks. If several target tasks are executed in parallel, their count offset values are the same, meaning the task trigger clocks for the parallel tasks are identical. The clock trigger signal mentioned above is defined during the creation of the task scheduling clock. The configuration information in the task configuration file can also include the task sequence number, and the clock trigger signal for each target task is defined based on the task sequence number. According to the task scheduling clock of each target task, a corresponding clock trigger signal is sent to the target task, waking it up to execute the task once. Each target task has a unique clock trigger signal.
[0101] In an optional embodiment, generating the task scheduling clock for each target task, based on the task scheduling period of each target task and the task scheduling order of associated target tasks, may further include:
[0102] A system timer is generated based on the task scheduling reference clock. The system timer is the smallest clock slice for all task scheduling and is used to achieve synchronous scheduling of multiple target tasks based on the same clock source.
[0103] All target tasks scheduled by the daemon process 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, plus the corresponding count offset, a clock trigger signal for that target task is triggered and sent to the corresponding task. After each target task process is created and started, the target task is in a suspended state waiting for the trigger signal. When a target task receives the clock trigger signal sent by the daemon process, it performs a task scheduling.
[0104] Figure 4 This is another flowchart illustrating a multi-task scheduling method provided in an embodiment of the present invention. Specifically, based on the above embodiments, the step of scheduling and monitoring multiple target tasks using a target daemon process based on the task configuration file is as follows: Figure 4 As shown, it may also include:
[0105] S401: Trigger the target task according to the task scheduling clock of the target task.
[0106] The daemon process periodically schedules each target task. In each scheduling, the daemon process first sends a clock trigger signal to the target task according to the target task's task scheduling clock, so as to trigger the target task.
[0107] S402: Based on the data offset address of each associated target task, obtain the first data of the associated target task stored in the shared memory, wherein the first data is the data of the associated target task to be sent to the target task.
[0108] When a target task receives a trigger signal, it first reads the first data stored in the shared memory by its associated task. After each target task executes its task, it stores the data that its associated target tasks need to read in the shared memory. This data that the associated target tasks need to read is the first data, which is the communication data between the associated target tasks. The first data is stored at the location corresponding to each associated target task and can be obtained through the corresponding data offset address of each associated target task.
[0109] S403: Based on the first data, execute the target task and determine the second data, wherein the second data corresponds to the target task execution result, and the second data includes the third data and the fourth data. The third data is the data to be received associated with the target task, and the fourth data is the status information data determined after the target task is executed.
[0110] After acquiring the communication data of each associated target task, the target task is executed, and the execution result data is generated, i.e., the second data. The third data consists of the communication data related to the target task that needs to be read after the next triggering of the associated target task and before the task is executed. In this embodiment of the invention, shared memory is used for data exchange between target tasks, which improves the efficiency of data exchange between target tasks.
[0111] S404: Based on the fourth data, monitor the target task and its associated target tasks.
[0112] The daemon process can monitor the real-time status of the target task by obtaining fourth data stored in shared memory, and determine the control instructions of multiple tasks associated with the target task based on the obtained real-time status information of the target task.
[0113] In an optional embodiment, the monitoring of the target task and its associated target tasks based on the fourth data may further include:
[0114] S501: Obtain the fourth data.
[0115] Each time a task scheduling operation is executed, each target task writes its execution status to the corresponding location in shared memory. The daemon process can then retrieve the real-time execution status information of each target task from the shared memory to monitor the task.
[0116] S502: Based on the fourth data, determine whether the target task execution result reports an error and / or whether the target task exits abnormally.
[0117] The daemon process can learn from the task status information whether the execution result is incorrect, the task execution is interrupted, or the abnormal exit occurs.
[0118] S503: In response to an error in the execution result of the target task and / or the abnormal exit of the target task, issue corresponding control commands to the associated target task according to the pre-set error level.
[0119] The daemon process can control the execution of other target tasks associated with the target task based on predefined error levels. For example, tasks A and B need to be executed sequentially, with task A executed first and then task B. If task A exits abnormally after scheduling, triggering task B would be meaningless. Therefore, the daemon process can issue an instruction to stop triggering task B. The daemon process in this embodiment of the invention implements collaborative management between multiple tasks.
[0120] Corresponding to the above method embodiments, this invention provides a multi-task scheduling device.
[0121] Figure 5 This is a schematic diagram of a multi-task scheduling device provided in an embodiment of the present invention, such as... Figure 5 As shown, the device may include:
[0122] The acquisition module 501 is used to acquire a task configuration file, wherein the task configuration file contains configuration information for multiple target tasks, and the configuration information includes a task scheduling cycle and a task scheduling order.
[0123] The scheduling module 502 is used to schedule and monitor the status of multiple target tasks using a daemon process based on the task configuration file. The task scheduling clock of the daemon process is determined according to the task scheduling cycle and the task scheduling order. Each target task corresponds to a task scheduling clock. The shared memory corresponding to the daemon process is used for data exchange between the target tasks and for storing first task status information, which is the task status information generated by each target task during the execution scheduling process.
[0124] In an optional embodiment, the task configuration information further includes at least one of the following: task name, task core binding information, task priority, second task status information, and inter-task data information, wherein the second task status information is the original task status information of each target task.
[0125] In an optional embodiment, the device further includes:
[0126] The first determining module is used to determine the task scheduling clock for each target task based on the task scheduling cycle of each target task and the task scheduling order of associated target tasks, wherein the multiple task scheduling clocks corresponding to multiple target tasks have the same clock source.
[0127] The second determining module is used to determine the shared memory based on the inter-task data information and the second task status information, wherein the capacity of the shared memory corresponds to the sum of the capacities of the inter-task data information and the second task status information.
[0128] The third determining module is used to determine the task process for each target task based on the configuration information corresponding to each target task, and to associate the initialized task process with the shared memory.
[0129] In an optional embodiment, the first determining module may further include:
[0130] The first determining unit is configured to determine a task scheduling reference clock based on the task scheduling cycles of 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.
[0131] The second determining unit is used to determine the scheduling cycle count value of the target task based on 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.
[0132] The third determining unit is used to determine the count offset value of each target task according to the task scheduling order.
[0133] The fourth determining unit is used to determine the task execution mode of each target task according to the task scheduling order. 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 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 task scheduling clocks of the multiple target tasks executed in parallel correspond to the sum of the period count value and the count offset value of each target task in the parallel execution task.
[0134] In an optional embodiment, the first determining module may further include:
[0135] The second determining unit is used to determine a system timer based on the task scheduling reference clock. The system timer is the smallest clock slice for all task scheduling and is used to realize the synchronous scheduling of multiple target tasks based on the same clock source.
[0136] In an optional embodiment, the shared memory performs data read and write operations based on system process locks.
[0137] In an optional embodiment, the scheduling module may include:
[0138] The first triggering unit is used to trigger the target task according to the task scheduling clock of the target task.
[0139] The first acquisition unit is used to acquire 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 data of the associated target task to be sent to the target task.
[0140] The first determining unit is used to execute a target task based on the first data and determine second data, wherein the second data corresponds to the target task execution result, and the second data includes third data and fourth data, wherein the third data is data to be received associated with the target task, and the fourth data is status information data determined after the target task is executed.
[0141] The first monitoring unit is used to monitor the target task and its associated target tasks based on the fourth data.
[0142] In an optional embodiment, the first monitoring unit may include:
[0143] The first acquisition subunit is used to acquire the fourth data.
[0144] The first judgment subunit is used to determine, based on the fourth data, whether the target task execution result reports an error and / or whether the target task exits abnormally.
[0145] The first response subunit is used to issue corresponding control commands to the associated target task in response to errors in the target task execution result and / or abnormal exit of the target task, based on the pre-set error level.
[0146] Corresponding to the above method embodiments, this invention provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the multi-task scheduling method as described in the above method embodiments.
[0147] The above-described system and device embodiments correspond to the system embodiments and have the same technical effects as the method embodiments. For detailed descriptions, please refer to the method embodiments. The device embodiments are derived based on the method embodiments; detailed descriptions can be found in the method embodiments section, and will not be repeated here. Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of one embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing the present invention.
[0148] Those skilled in the art will understand that the modules in the apparatus of the embodiments can be distributed in the apparatus of the embodiments as described in the embodiments, or they can be located in one or more devices different from this embodiment with corresponding changes. The modules of the above embodiments can be combined into one module, or they can be further divided into multiple sub-modules.
[0149] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A multitasking scheduling method characterized by, The method comprises: obtaining a task configuration file, wherein the task configuration file contains configuration information of a plurality of target tasks, and the configuration information comprises a task scheduling period and a task scheduling sequence; for each target task, determining a 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 plurality of task scheduling clocks corresponding to the plurality of target tasks have the same clock source; based on the task configuration file, scheduling and monitoring the plurality of target tasks by using a daemon process, wherein the task scheduling clock of the daemon process is determined according to the task scheduling period and the task scheduling sequence, each target task corresponds to a task scheduling clock, and a shared memory corresponding to the daemon process is used for data exchange between target tasks and for storing first task state information, which is task state information generated by each target task during the execution of the scheduling process; wherein, for each target task, determining a task scheduling clock according to the task scheduling period of each target task and the task scheduling sequence of the associated target task comprises: determining a task scheduling reference clock according to the task scheduling period of the plurality of target tasks, wherein the task scheduling reference clock corresponds to the greatest common divisor of the task scheduling periods of the plurality of target tasks; determining a scheduling period count value of each target task according to the task scheduling reference clock and the task scheduling period of each target task, wherein the scheduling period count value is N reference times corresponding to the task scheduling reference clock, and N is a positive integer; determining a count offset value of each target task according to the task scheduling sequence; determining a task execution mode of each target task according to the task scheduling sequence, wherein when the task execution mode of a 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 a target task is parallel execution, the task scheduling clocks of a plurality of target tasks executed in parallel are the same, and the task scheduling clocks of the plurality of target tasks executed in parallel correspond to the sum of the period count value of each target task in the parallel execution task and the count offset value of the target task itself.
2. The method of claim 1, wherein, The configuration information further comprises at least one of a task name, task core binding information, a task priority, second task state information, and inter-task data information, wherein the second task state information is original task state information of each target task.
3. The method of claim 2, wherein, Before scheduling and monitoring the plurality of target tasks by using the daemon process based on the task configuration file, the method further comprises: determining the shared memory according to the inter-task data information and the second task state information, wherein the capacity of the shared memory corresponds to the sum of the capacities of the inter-task data information and the second task state information; for each target task, determining a task process according to the configuration information corresponding to each target task, and associating the initialized task process to the shared memory.
4. The method of claim 3, wherein, The task scheduling clock is determined according to the task scheduling period and the task scheduling sequence of each target task, and the method further comprises: A system timer is determined according to the task scheduling reference clock, the system timer being the smallest clock piece of all task scheduling, and the system timer being used to realize the synchronous scheduling of multiple target tasks based on the same clock source.
5. The method of claim 3, wherein, The shared memory is used for data reading and writing based on a system process lock.
6. The method of claim 1, wherein, The target daemon is used to schedule and monitor the multiple target tasks based on the task configuration file, and the method further comprises: The target task is triggered according to the task scheduling clock of the target task; First data of the associated target task stored in the shared memory is obtained based on the data offset address of each associated target task, wherein the first data is data to be sent by the associated target task to the target task; The target task is executed based on the first data, and second data is determined, wherein the second data corresponds to the execution result of the target task, and the second data comprises third data and fourth data, the third data being data to be received by the associated target task, and the fourth data being state information data determined after the target task executes the task; The target task and the associated target task are monitored according to the fourth data.
7. The method of claim 6, wherein, The monitoring of the target task and the associated target task according to the fourth data comprises: The fourth data is obtained; It is judged whether the execution result of the target task is erroneous and / or the target task is abnormally exited according to the fourth data; In response to the erroneous execution result of the target task and / or the abnormal exit of the target task, corresponding control instructions are issued to the associated target task according to a pre-set error level.
8. A multitasking scheduling apparatus characterized by comprising: The device comprises: An obtaining module is configured to obtain a task configuration file, wherein the task configuration file contains configuration information of multiple target tasks, and the configuration information comprises a task scheduling period and a task scheduling sequence; A first determining module is configured to determine, for each target task, a 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; A scheduling module is configured to schedule and monitor the task states of the multiple target tasks by using a daemon based on the task configuration file, wherein the task scheduling clock of the daemon is determined according to the task scheduling period and the task scheduling sequence, each target task corresponds to a task scheduling clock, and a shared memory corresponding to the daemon is used for data exchange between the target tasks and for storing first task state information, the first task state information being task state information generated in the execution scheduling process of the target tasks. The first determining module comprises: A first determining unit is configured to determine a 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. A second determining unit is configured to determine a scheduling period count value of each target task according to the task scheduling reference clock and the task scheduling period of each target task, wherein the scheduling period count value is N reference times corresponding to the task scheduling reference clock, and N is a positive integer; A third determining unit is configured to determine a count offset value of each target task according to the task scheduling sequence; A fourth determining unit is configured to determine a task execution mode of each target task according to the task scheduling sequence, wherein when the task execution mode of a target task is serial execution, a task scheduling clock of the target task corresponds to a 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 a target task is parallel execution, the task scheduling clocks of a plurality of target tasks in parallel execution are the same, and the task scheduling clocks of the plurality of target tasks in parallel execution correspond to a sum of the period count value of each target task in parallel execution and the count offset value of the target task itself.
9. The apparatus of claim 8, wherein, The apparatus further comprises: A second determining module is configured to determine the shared memory according to the inter-task data information and the second task state information, wherein a capacity of the shared memory corresponds to a sum of capacities of the inter-task data information and the second task state information; A third determining module is configured to determine, for each target task, a task process according to the configuration information corresponding to each target task, and associate the initialized task process to the shared memory.
Citation Information
Patent Citations
Three-dimensional image server multi-task managing and scheduling method
CN101777012A
Batch task scheduling method and device
CN113485814A