Periodic task scheduling method and device, storage medium and program product

By introducing a decentralized architecture into the distributed system, each scheduling node independently calculates the scheduling moment of the periodic task, solving the problems of task scheduling delay and jitter in the centralized architecture, realizing the periodic alignment and collaborative startup of the tasks, and improving the performance of the on-board operating system.

CN119759527APending Publication Date: 2025-04-04ZHEJIANG ZEEKR INTELLIGENT TECH CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411894563.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

In the centralized distributed architecture, the scheduling of vehicle tasks has high latency and jitter, which cannot effectively ensure that the tasks are started together across nodes, affecting the performance of the on-board operating system.

Method used

By introducing a decentralized architecture into the distributed system, each scheduling node deploys a scheduling engine, uses reference moments to adjust the local time, determine the public cycle and target scheduling start time, independently calculate the scheduling time of each period task, and realize the periodic alignment and coordinated start of the task.

Benefits of technology

It significantly reduces the delay and jitter of task scheduling, improves the certainty and real-time nature of task co-starting across nodes, and improves the performance of the on-board operating system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759527A_ABST
    Figure CN119759527A_ABST
Patent Text Reader

Abstract

The invention provides a periodic task scheduling method and device, a storage medium and a program product. The method is applied to a target scheduling engine in a distributed system, the distributed system comprises at least two scheduling nodes, at least one scheduling engine is deployed on each scheduling node, the target scheduling engine is any one of the at least two scheduling engines, and the method can comprise the steps of obtaining a reference moment, and adjusting the local moment of the target scheduling engine according to the reference moment. And determining a common period according to the task execution duration of the periodic tasks respectively configured on each scheduling engine in the at least two scheduling engines, and calculating the period starting moment of the next common period according to the current moment and the predefined moment. And according to the period starting moment of the next common period and task scheduling moment information maintained by the target scheduling engine, determining a target scheduling starting moment of each period task configured on the target scheduling engine. According to the technical scheme, task cross-node collaborative starting can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present application relate to the technical field of task scheduling, and in particular, to a method, device, storage medium, and program product for scheduling periodic tasks. Background Art

[0002] With the rapid development of automobile technology, a large number of vehicle tasks are deployed in the vehicle operating system with limited hardware resources, waiting to be scheduled for execution. The determinism and real-time performance of vehicle tasks are the basic conditions to ensure the security and high reliability of the vehicle operating system.

[0003] In the related art, deterministic scheduling middleware technology is usually used to ensure the determinism and real-time performance of vehicle tasks. Deterministic scheduling middleware technology relies on a centralized distributed architecture, which usually includes a scheduling center node and several scheduling sub-nodes. The scheduling sub-node is responsible for receiving instructions from the scheduling center node and controlling the execution of user tasks according to the content of the instructions. Among them, for vehicle tasks that have dependencies on each other, such as event-triggered tasks, if these vehicle tasks are assigned to different scheduling sub-nodes, these vehicle tasks are often required to be started collaboratively across nodes to ensure the determinism and real-time performance of the scheduling of each task. However, in the aforementioned centralized distributed architecture, the collaborative start of tasks between different nodes depends on the communication of control instructions between nodes, which easily leads to high latency and jitter in the scheduling of vehicle tasks, and cannot effectively ensure the collaborative start of tasks across nodes. Summary of the invention

[0004] The present application provides a scheduling method, device, storage medium and program product for periodic tasks to address deficiencies in related technologies.

[0005] According to a first aspect of one or more embodiments of the present application, a method for scheduling periodic tasks is provided. The method is applied to a target scheduling engine in a distributed system. The distributed system includes at least two scheduling nodes. At least one scheduling engine is deployed on each scheduling node. The target scheduling engine is any one of the at least two scheduling engines. The method includes:

[0006] Obtaining a reference time, and adjusting the local time of the target scheduling engine according to the reference time;

[0007] Determine a common cycle according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate a cycle start time of the next common cycle according to a current time and a predefined time, wherein the predefined time is earlier than the current time;

[0008] According to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, the target scheduling start time of each periodic task configured on the target scheduling engine is determined, so as to schedule each periodic task according to the determined target scheduling start time.

[0009] Optionally, the common period is determined based on the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, including: when the task execution durations of the periodic tasks respectively configured on the each scheduling engine are the same, the common period is equal to the task execution duration; when the task execution durations of the periodic tasks respectively configured on the each scheduling engine are different, the common period is equal to the target period negotiated by the each scheduling engine.

[0010] Optionally, the target period includes: the least common multiple of the task execution durations of the periodic tasks respectively configured on the scheduling engines.

[0011] Optionally, the calculation of the cycle start time of the next common cycle based on the current moment and the predefined moment includes: calculating the number of executed cycles of the common cycle from the predefined moment to the current moment; adding 1 to the executed number to obtain the target number of common cycles; and determining the moment from the predefined moment to the moment after the target number of common cycles has passed as the cycle start time of the next common cycle.

[0012] Optionally, it also includes: when the number of executions indicates that the current common cycle has not ended, filtering out the unscheduled periodic tasks on the target scheduling engine within the current common cycle according to the task scheduling time information and the current time; determining the cycle start time of the current common cycle, and determining the scheduling start time of the unscheduled periodic tasks according to the cycle start time and the task scheduling time information.

[0013] Optionally, the task scheduling time information includes: information on relative scheduling start times of each periodic task configured on the target scheduling engine within a common period.

[0014] Optionally, after the start of the next common cycle, it also includes: for any periodic task configured on the target scheduling engine, if the time interval between the actual scheduling start time of the periodic task and the target scheduling start time is greater than a first preset interval threshold, canceling the execution of the periodic task; or, for any target periodic task configured on the target scheduling engine, if the time interval between the actual execution end time of the target periodic task and the actual scheduling start time is greater than a second preset interval threshold, recording the execution error information of the target periodic task; the target periodic task is a periodic task that has been executed and completed within the next common cycle.

[0015] According to a second aspect of one or more embodiments of the present application, a scheduling device for a periodic task is provided, the device being applied to a target scheduling engine in a distributed system, the distributed system comprising at least two scheduling nodes, each scheduling node being deployed with at least one scheduling engine, the target scheduling engine being any one of the at least two scheduling engines, the device comprising:

[0016] A time adjustment unit, used to obtain a reference time and adjust the local time of the target scheduling engine according to the reference time;

[0017] a cycle determination unit, configured to determine a common cycle according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate a cycle start time of the next common cycle according to a current time and a predefined time, wherein the predefined time is earlier than the current time;

[0018] A scheduling start time determination unit is used to determine the target scheduling start time of each periodic task configured on the target scheduling engine according to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, so as to schedule each periodic task according to the determined target scheduling start time.

[0019] According to a third aspect of one or more embodiments of the present application, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method described in any embodiment of the first aspect are implemented.

[0020] According to a fourth aspect of one or more embodiments of the present application, a computer program product is provided, comprising a computer program and / or instructions, which, when executed by a processor, implement the steps of the method described in any embodiment of the first aspect above.

[0021] It can be seen from the above technical solutions that in one or more embodiments of the present application, the distributed system includes at least two scheduling nodes, each scheduling node is deployed with at least one scheduling engine, and the solution of the present application is applicable to any scheduling engine of the at least two scheduling engines. In other words, the status and role of each scheduling engine in the distributed system are equal, and no longer rely on the central node to uniformly arrange the scheduling time of each task. Any scheduling engine (hereinafter referred to as the "target scheduling engine") first adjusts its own local time according to the reference time obtained, thereby realizing time synchronization between each scheduling engine. Furthermore, the target scheduling engine determines the common cycle according to the task execution time of all periodic tasks globally, and calculates the cycle start time of the next common cycle. Then, the target scheduling engine determines the target scheduling start time of each periodic task configured by itself based on the cycle start time of the next common cycle and the task scheduling time information maintained by itself.

[0022] On the basis of the time synchronization of each scheduling engine, the common cycle of all periodic tasks is determined, and the cycle start time of the next common cycle is calculated to achieve the cycle alignment of all periodic tasks. Cycle alignment means that periodic tasks deployed on different scheduling engines can enter the next common cycle at the same time or almost at the same time. Therefore, determining the target scheduling start time of each periodic task according to the cycle start time of the next common cycle can effectively improve the accuracy of the target scheduling start time, and then scheduling the periodic tasks based on the precise target scheduling start time can significantly reduce the delay and jitter of task scheduling, and realize the coordinated start of tasks across nodes.

[0023] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0025] Figure 1 It is a schematic diagram of the architecture of a decentralized distributed system provided by an exemplary embodiment.

[0026] Figure 2 It is a flowchart of a method for scheduling periodic tasks provided by an exemplary embodiment.

[0027] Figure 3 It is a schematic diagram of a task scheduling cycle within a common period provided by an exemplary embodiment.

[0028] Figure 4aIt is a schematic diagram of the delay and jitter of task scheduling in a centralized distributed architecture provided by an exemplary embodiment.

[0029] Figure 4b It is a schematic diagram of the delay and jitter of task scheduling in a decentralized distributed architecture provided by an exemplary embodiment.

[0030] Figure 5a is a schematic diagram of a scheduling engine provided by an exemplary embodiment.

[0031] Figure 5b It is a full flow chart of task scheduling provided by an exemplary embodiment.

[0032] Figure 6 It is a schematic structural diagram of an electronic device provided by an exemplary embodiment.

[0033] Figure 7 It is a block diagram of a scheduling device for periodic tasks provided by an exemplary embodiment. DETAILED DESCRIPTION

[0034] In the related art, deterministic scheduling middleware technology is usually used to ensure the determinism and real-time performance of vehicle tasks. Deterministic scheduling middleware technology relies on a centralized distributed architecture, which usually includes a scheduling center node and several scheduling sub-nodes. The scheduling sub-node is responsible for receiving instructions from the scheduling center node, controlling the execution of user tasks according to the instruction content, and reporting task execution information to the scheduling center node. The scheduling center node is responsible for the global control of all vehicle tasks, and can send scheduling instructions to the scheduling sub-nodes to realize the scheduling and execution of each vehicle task. Among them, for vehicle tasks that have dependencies on each other, such as event-triggered tasks, if these vehicle tasks are assigned to different scheduling sub-nodes, these vehicle tasks are often required to be started collaboratively across nodes to ensure the determinism and real-time performance of each task scheduling. However, in the aforementioned centralized distributed architecture, the collaborative start of tasks between different nodes depends on the control instruction communication between nodes. The instructions between the scheduling center node and the scheduling sub-node need to be implemented through cross-process communication, and there will be a large delay error from the issuance of the instruction to the execution of the instruction. In addition, cross-node communication itself is not deterministic, which will cause large jitters at the execution time of the instruction. These delays and jitters that cannot be eliminated cannot ensure the coordinated launch of tasks across nodes, which makes it impossible to guarantee the timing, sequence and result certainty of scheduled tasks, greatly reducing the performance of the in-vehicle operating system.

[0035] In view of this, the present application proposes a scheduling method for periodic tasks, which can accurately calculate the target scheduling start time of each task, and schedule the periodic tasks based on the precise target scheduling start time, which can significantly reduce the delay and jitter of task scheduling, thereby realizing cross-node collaborative startup of tasks.

[0036] Next, one or more embodiments of the present application are described in detail.

[0037] Figure 1 The following is a schematic diagram of the architecture of a decentralized distributed system provided by an exemplary embodiment. Figure 1 As shown, the distributed system may include scheduling nodes A, B, and C, wherein scheduling engines 1-2 are deployed on scheduling node A, scheduling engines 3-4 are deployed on scheduling node B, and scheduling engine 5 is deployed on scheduling node C. Each scheduling node may be deployed on the same device or on different devices. For example, Figure 1 Scheduling nodes A and B are deployed on device 11, and scheduling node C is deployed on device 12.

[0038] exist Figure 1 In the decentralized distributed system shown in the figure, each scheduling node is equal to each other, and each scheduling engine is equal to each other. Each scheduling engine is configured with one or more periodic tasks ( Figure 1 The difference between various scheduling engines is that the configured tasks may be different and may be deployed on different devices.

[0039] The following will Figure 1 The method for scheduling periodic tasks provided in the embodiment of the present application is performed by any scheduling engine in the distributed system as an example for exemplary description. Figure 2 , Figure 2A flowchart of a scheduling method for periodic tasks provided by an exemplary embodiment. The method is applied to a target scheduling engine in a distributed system, wherein the distributed system includes at least two scheduling nodes and at least one scheduling engine is deployed on each scheduling node. The target scheduling engine can be any one of the at least two scheduling engines mentioned above. In fact, each scheduling node is equivalent to a process entity, and each scheduling engine is equivalent to an entity containing a single thread. The scheduling engine can be generated by the scheduling node according to the configuration information of the periodic task during the initialization phase. Usually, the number of scheduling engines deployed on each device is less than the number of processor cores of the device, so that each scheduling engine can be bound to the computing resources of at least one core to avoid excessive competition caused by too many scheduling engines. In addition, each scheduling engine can also set its own internal thread parameters, as well as set the real-time scheduling strategy and real-time priority of its own thread to avoid task uncertainty caused by competing with other tasks for processor cores. In addition, each scheduling engine can be bound to a specific processor core, which helps to avoid uncertainty caused by thread switching between cores.

[0040] like Figure 2 As shown, the method may include the following steps:

[0041] S201: Acquire a reference time, and adjust the local time of the target scheduling engine according to the reference time.

[0042] First of all, it should be explained that the scheduling objects of the present application scheme are mainly periodic tasks, and periodic tasks can be understood as tasks that are repeatedly executed at fixed time intervals. Exemplarily, periodic tasks may include but are not limited to: time-triggered tasks, data-triggered tasks, event-triggered tasks, and so on. A time-triggered task refers to a task that is started at a predetermined time interval or a specific time point; a data-triggered task refers to a task triggered by the arrival of specific data or a change in data; an event-triggered task refers to a task triggered by an external event. One or more periodic tasks can be configured on each scheduling engine. Multiple scheduling engines can be started in parallel and periodically schedule their own configured periodic tasks to ensure deterministic execution of periodic tasks.

[0043] In order to achieve cross-node collaborative startup of tasks, it is necessary to ensure that each scheduling engine schedules operations on the same time base. Exemplarily, each scheduling engine can obtain a reference time and adjust its own local time according to the reference time. The reference time can be obtained from a server, or a certain device can be used as a master clock, and the master clock broadcasts the reference time to the scheduling engines on other devices. When each scheduling engine adjusts its own local time to be consistent with the reference time, it can be determined that there is a unified time base between all scheduling engines. The above process of adjusting the local time of the scheduling engine can usually be implemented using time synchronization technology. Time synchronization technology is usually used to ensure that the clocks on different devices remain consistent, thereby solving the time deviation problem caused by factors such as clock drift and network delay. It should be noted that this application does not limit the specific implementation method of time synchronization technology. For example, NTP (Network Time Protocol), PTP (Precision Time Protocol) and other technologies can be used to implement the scheduling of each scheduling engine with the same time base.

[0044] S202: determine a common cycle according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate a cycle start time of the next common cycle according to a current time and a predefined time, wherein the predefined time is earlier than the current time.

[0045] As mentioned above, each scheduling engine is configured with one or more periodic tasks, and each periodic task has a task execution duration. The common cycle can be determined based on the task execution duration of the periodic tasks configured on all scheduling engines. A common cycle means that within a cycle, the periodic tasks configured on all scheduling engines will have at least one common start time, which can be called the "cycle start time of the common cycle." By determining the cycle start time of the common cycle and scheduling tasks from this cycle start time, the cycles of all scheduling engines can be aligned.

[0046] In one embodiment, when the task execution durations of the periodic tasks respectively configured on each scheduling engine are the same, the task execution durations can be determined as a common period. For example, scheduling engine 1 is configured with periodic task A, scheduling engine 2 is configured with periodic task B, and scheduling engine 3 is configured with periodic task C. The task execution durations of periodic tasks A, B, and C are all 5 milliseconds, so the common period is 5 milliseconds, which means that every 5 milliseconds, periodic tasks A, B, and C will have at least one common period start time, thereby ensuring the coordinated start of the three tasks.

[0047] When the task execution durations of the periodic tasks configured on each scheduling engine are different, each scheduling engine can negotiate to obtain a target period and use the target period as a common period. For example, scheduling engine 1 is configured with periodic task A, scheduling engine 2 is configured with periodic task B, and scheduling engine 3 is configured with periodic task C. The task execution duration of periodic task A is 1 millisecond, the task execution duration of periodic task B is 3 milliseconds, and the task execution duration of periodic task C is 5 milliseconds. Then, the target period can be obtained through communication negotiation between the scheduling engines. For example, the target period can be any value between 5 and 15 milliseconds. It should be noted that those skilled in the art can set the logic / principle of negotiating the target period of each scheduling engine according to actual needs, and this application does not specifically limit the specific values ​​of the negotiation logic and the target period.

[0048] In this embodiment, the common period is determined by the task execution duration of the periodic tasks configured on each scheduling engine, which can ensure that all periodic tasks are scheduled within a common time frame, thereby effectively reducing unnecessary idle scheduling time, making resources more efficiently utilized, and improving the real-time performance of task scheduling.

[0049] In one embodiment, when the target period negotiated by each scheduling engine is used as the common period, the target period may be the least common multiple of the task execution durations of the periodic tasks configured on each scheduling engine. In combination with the above embodiment, when the task execution duration of periodic task A is 1 millisecond, the task execution duration of periodic task B is 3 milliseconds, and the task execution duration of periodic task C is 5 milliseconds, the least common multiple of 1 millisecond, 3 milliseconds, and 5 milliseconds is 15 milliseconds. That is, the target period is 15 milliseconds.

[0050] In this embodiment, the least common multiple of the task execution durations of the periodic tasks configured on each scheduling engine is used as the common period, which can ensure that all periodic tasks on each scheduling engine have a common period point within their respective task cycles, thereby making it easier to achieve task coordination on different scheduling engines. There is no need for additional complex logic to handle the scheduling order between different periodic tasks, which effectively simplifies the scheduling logic and helps avoid scheduling conflicts in periodic tasks.

[0051] The above is the process of determining the common cycle. After determining the common cycle, the cycle start time of the next common cycle can be calculated according to the current time and the predefined time. Among them, the predefined time can be set by those skilled in the art according to actual needs, as long as the predefined time is earlier than the current time, and this application does not impose specific restrictions on this.

[0052] In one embodiment, the cycle start time of the next common cycle can be determined in the following manner: First, the target scheduling engine can calculate the number of common cycles executed from the predefined time to the current time. That is, it is calculated how many common cycles have been executed from the predefined time to the current time. Then, the number of executed cycles plus 1 is the target number of common cycles. The time from the predefined time to the time after the target number of common cycles is determined as the cycle start time of the next common cycle. The core idea in the above process can be summarized as: based on the current time, add the duration of a common cycle, which is the cycle start time of the next common cycle.

[0053] For ease of understanding, an example is given to further illustrate: assuming that the common period corresponding to periodic tasks A, B, and C is 5 seconds, the timestamp of the current moment is 1728637806, and the timestamp of the predefined moment is 1701273600. It should be noted that the timestamp involved in this specification is a Unix timestamp. The Unix timestamp represents the number of seconds that have passed from 00:00:00 on January 1, 1970 (UTC time zone) to the current moment. Of course, the Unix timestamp is only an example, and other methods can also be used to represent the timestamp, and this application does not limit this. In combination with the foregoing embodiments, the calculation principle of the number of executions of the common period can refer to the following formula (1):

[0054] T_count=(cur_time-fix_time) / circle(1)

[0055] In formula (1), T_count represents the number of public cycles that have been executed, cur_time represents the timestamp of the current moment, fix_time represents the timestamp of the predefined moment, and circle represents the duration of the public cycle. After calculation, it can be obtained that the number of public cycles that have been executed is 5472841. It can be further obtained that the target number of public cycles is 5472842. The calculation principle of the cycle start time of the next public cycle can refer to formula (2):

[0056] align_time=(fix_time+(T_count+1)*circle)(2)

[0057] In formula (2), align_time represents the start time of the next common cycle, and the meanings of fix_time, T_count and circle are the same as those in formula (1). According to formula (2), the timestamp of the start time of the next common cycle in this embodiment is 1728637810.

[0058] The above method for determining the cycle start time of the next common cycle has simple and efficient calculation logic, which can improve the efficiency and accuracy of determining the cycle start time of the next common cycle, thereby helping to improve the real-time and deterministic nature of task scheduling.

[0059] In one embodiment, after calculating the number of executed common cycles, if the total duration of the executed common cycles is equal to the time interval between the current moment and the predefined moment, it means that the current moment is exactly the end moment of the most recent common cycle, that is, the most recent common cycle ends at the current moment. This usually means that all scheduled tasks in the most recent common cycle have been executed.

[0060] If the total duration of the executed number of common cycles is less than the time interval between the current moment and the predefined moment, it means that the current moment is in a common cycle, and this common cycle can be called the "current common cycle". In combination with the above-mentioned embodiment (the common cycle corresponding to periodic tasks A, B, and C is 5 seconds, the timestamp of the current moment is 1728637806, and the timestamp of the predefined moment is 1701273600), the total duration of the executed number of common cycles is less than the time interval between the current moment and the predefined moment, which means that the current common cycle has not yet ended. Then, each scheduling engine can filter the periodic tasks configured by itself, and filter out the periodic tasks that are not scheduled in the current common cycle. Exemplarily, the cycle start time of the current common cycle can be determined according to the current moment and the duration of a common cycle, and then the unscheduled periodic tasks can be filtered out according to the cycle start time of the current common cycle and the task scheduling time information maintained on the scheduling engine. Among them, each scheduling engine can generate task scheduling time information and maintain it after determining the common cycle. The task scheduling time information maintained by any scheduling engine may include the relative scheduling start time of each periodic task configured on the scheduling engine within a common cycle, and / or the time interval between the period start time of the common cycle (hereinafter referred to as "time offset"). The relative scheduling start time of a periodic task is relative to the period start time of the common cycle. Exemplarily, the timestamp of the period start time of the common cycle is 1701273500, and the time arriving after the time offset of a certain periodic task starting from 1701273500 is the relative scheduling start time of the periodic task. For example, assuming that the time offset of periodic task P is 1 second, and the time offset of periodic task Q is 3 seconds. Then, the timestamp of the relative scheduling start time of periodic task P is 1701273501, and the timestamp of the relative scheduling start time of periodic task Q is 1701273503.

[0061] The unscheduled periodic tasks are screened out according to the period start time of the current common period and the task scheduling time information maintained on the scheduling engine. Exemplarily, assuming that the timestamp of the current time is 1701273508, and the timestamp of the period start time of the current common period is 1701273506, then the timestamp of the scheduling start time of periodic task P is 1701273507, and the timestamp of the scheduling start time of periodic task Q is 1701273509. Obviously, the scheduling start time of periodic task Q is greater than the current time, which means that at the current time, periodic task Q has not been scheduled. Then, for the periodic tasks that have not been scheduled in the current common period, the scheduling start time of each periodic task can be determined according to the period start time of the current common period and the task scheduling time information, and then, the periodic tasks that have not been scheduled in the current common period can be scheduled according to the determined scheduling start time.

[0062] In this embodiment, when it is determined that the current common cycle has not ended, the cycle start time of the current common cycle is used to determine the scheduling start time of the periodic tasks that have not yet been scheduled. The precise scheduling start time can be determined within the current common cycle, and then the unscheduled periodic tasks can be scheduled based on the precise scheduling start time. This can significantly reduce the delay and jitter of task scheduling within the current common cycle, and improve the real-time and determinism of task scheduling within the current common cycle.

[0063] S203, determining the target scheduling start time of each periodic task configured on the target scheduling engine according to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, so as to schedule each periodic task according to the determined target scheduling start time.

[0064] In one embodiment, the task scheduling time information maintained by the target scheduling engine may include the relative scheduling start time of each periodic task configured on the scheduling engine within a common cycle, and / or the time interval between the period start time of the common cycle (hereinafter referred to as "time offset"). In addition, each periodic task can also be sorted according to the relative scheduling start time or time offset of each periodic task. Therefore, the task scheduling time information can also include the execution order of each periodic task. In this way, when scheduling periodic tasks, the target scheduling engine can directly schedule the periodic tasks in sequence according to the execution order, without temporarily determining the execution order of the periodic tasks, which helps to further improve the real-time performance of task scheduling.

[0065] Figure 3 FIG. 1 is a schematic diagram of a task scheduling cycle within a common period provided by an exemplary embodiment. Figure 3As shown in the figure, the task execution time of periodic task A (deployed on scheduling engine a) is 1 millisecond, the task execution time of periodic task B (deployed on scheduling engine b) is 4 milliseconds, and the task execution time of periodic task C (deployed on scheduling engine c) is 2 milliseconds. The duration of a common cycle is 24 milliseconds. Taking the common cycle T1 as an example, its cycle start time is t0 and the cycle end time is t1 (t0<t1). In the common cycle T1, the target scheduling start time of periodic task A is t0, t1 respectively. A1 ,t A2 ; The target scheduling start time of periodic task B is t B1 ,t B2 ,t B3 The target scheduling start time of periodic task C is t C1 ,t C2 ,t C3 In the actual task scheduling process, periodic tasks A, B, and C deployed on different scheduling engines can simultaneously enter the common cycle T1 based on the cycle start time of the common cycle T1, thereby realizing the coordinated start of cross-node tasks. Specifically, after the common cycle T1 starts, that is, when the target scheduling start time t0 is reached, scheduling engine a will schedule periodic task A for execution. When the target scheduling start time t0 is reached, the scheduling engine a will schedule periodic task A for execution. C1 When the target scheduling start time t is reached, the scheduling engine c will schedule the periodic task C to execute; B1 When , the scheduling engine b will schedule periodic task B to execute. Similarly, the task scheduling corresponding to the start time of other target scheduling can be obtained.

[0066] Obviously, in the above task scheduling process, there is no need for the scheduling engines a, b, and c to communicate to obtain the scheduling start time of the periodic tasks. Each scheduling engine can independently calculate the target scheduling start time of each periodic task configured by itself, thereby greatly reducing the scheduling delay and jitter caused by cross-process communication.

[0067] In the above embodiment, the distributed system includes at least two scheduling nodes, each scheduling node is deployed with at least one scheduling engine, and the present application scheme is applicable to any scheduling engine. In other words, the status and role of each scheduling engine in the distributed system are equal, and no longer rely on the central node to uniformly arrange the scheduling time of each task. Each scheduling engine first adjusts its own local time according to the reference time obtained, thereby realizing the time synchronization between each scheduling engine. Furthermore, on the basis that the time of each scheduling engine has been synchronized, by determining the common cycle of all periodic tasks and calculating the cycle start time of the next common cycle, the cycle alignment of all periodic tasks is realized. Cycle alignment means that the periodic tasks deployed on different scheduling engines can enter the next common cycle at the same time or almost at the same time. Therefore, determining the target scheduling start time of the periodic task according to the cycle start time of the next common cycle can effectively improve the accuracy of the target scheduling start time, and then scheduling the periodic task based on the precise target scheduling start time can significantly reduce the delay and jitter of task scheduling, and realize the cross-node collaborative startup of tasks. In addition, since the dispatch center node in the related technology must exclusively use the CPU to run, and it carries the communication control with each dispatch sub-node, when the number of dispatched tasks is too large, it is easy to affect the performance of the vehicle operating system. However, the present application scheme is applied in a decentralized distributed architecture, and there is no need to set up a dispatch center node, thereby avoiding the dispatch center node from occupying system resources and effectively improving the overall system performance.

[0068] The advantages of the present application scheme are further illustrated by examples of delay and jitter in task scheduling. Figure 4a This is a schematic diagram of the delay and jitter of task scheduling in a centralized distributed architecture provided by an exemplary embodiment. Figure 4a In the example, the horizontal axis represents the number of sampling times of task scheduling, and the vertical axis represents the time when the task scheduling is triggered. In this embodiment, a 5000 microsecond timing trigger is used. Figure 4a Analysis and calculation show that the maximum error of the time when the task scheduling is triggered is 5551.00 microseconds, the minimum error is 4449.00 microseconds, the average error is 4999.99 microseconds, and the standard deviation is 116.62 microseconds. It can be seen that the centralized distributed architecture in the relevant technology is used to schedule tasks. Since the nodes in the centralized distributed architecture rely on cross-process communication to send and receive instructions to schedule tasks according to the instructions, it is easy to cause high latency and large jitter in task scheduling.

[0069] Figure 4b This is a schematic diagram of the delay and jitter of task scheduling in a decentralized distributed architecture provided by an exemplary embodiment. Figure 4bIn the example, the horizontal axis represents the sampling times of the task scheduling, and the vertical axis represents the time of triggering the task scheduling. In this embodiment, the 5000 microsecond timing trigger is also adopted. Figure 4b It means that: in a decentralized distributed architecture, the task scheduling scheme of the present application scheme is used to schedule periodic tasks. Figure 4b Analysis and calculation show that the maximum error of the time when the task scheduling is triggered is 5044.20 microseconds, the minimum error is 4935.8 microseconds, the average error is 4999.999957328797 microseconds, and the standard deviation is 2.540597052130808 microseconds. It can be seen that under the decentralized distributed architecture, the task scheduling scheme of the present application scheme is used to schedule periodic tasks, which can significantly reduce the delay and jitter of task scheduling.

[0070] In one embodiment, after the next common cycle starts, when the target scheduling engine performs task scheduling according to the target scheduling start time of each periodic task, the actual scheduling start time of the periodic task may deviate. Therefore, the target scheduling engine can maintain a first preset interval threshold, which is used to define the maximum allowable error between the actual scheduling start time and the target scheduling start time of the periodic task. For example, the first preset interval threshold is ±2 milliseconds, indicating that the time interval between the actual scheduling start time and the target scheduling start time of the periodic task cannot exceed ±2 milliseconds.

[0071] After the next common cycle starts, the target scheduling engine can obtain the actual scheduling start time of the periodic task for any periodic task configured by itself. Then, compare the actual scheduling start time of the periodic task with the target scheduling start time. If the time interval between these two times is greater than the first preset interval threshold, it means that the actual scheduling start time of the periodic task has exceeded the latest allowed time, and the scheduling of the periodic task is invalid. In this case, there is no need to execute the periodic task. If the time interval between the actual scheduling start time of the periodic task and the target scheduling start time is not greater than the first preset interval threshold, it means that the scheduling of the periodic task is valid and the periodic task can be executed.

[0072] In the above method, setting the first preset interval threshold can ensure that the periodic task is completed within the specified time, thereby ensuring the real-time nature of task scheduling. When the time interval between the actual scheduling start time of the periodic task and the target scheduling start time exceeds the first preset interval threshold, the periodic task is not executed. This method can avoid the invalid execution of the periodic task and save system resources at the same time. Because when the first preset interval threshold is exceeded, it means that the actual scheduling start time of the periodic task has missed the latest scheduling time. At this time, executing the periodic task may not achieve the expected effect and will also cause a waste of system resources.

[0073] In addition, after the next common cycle begins, during the process of executing the periodic task by the target scheduling engine, the actual execution duration of the periodic task may deviate from the task execution duration predefined in the configuration information. Therefore, the target scheduling engine can maintain a second preset interval threshold, which is used to define the maximum allowable error between the actual execution duration of the periodic task and the predefined task execution duration. For example, the second preset interval threshold is ±5 milliseconds, indicating that the error between the actual execution duration of the periodic task and the predefined task execution duration cannot exceed ±5 milliseconds.

[0074] After the next common cycle starts, the target scheduling engine obtains the actual scheduling start time and the actual execution end time of any target cycle task configured by itself. Among them, the target cycle task refers to the cycle task that has been executed and completed in the next common cycle. The time interval between the actual execution end time and the actual scheduling start time of any target cycle task is the actual execution duration of the target cycle task. If the actual execution duration of any target cycle task is greater than the second preset interval threshold, it means that the actual execution duration of the target cycle task exceeds the maximum allowable error, indicating that an abnormality has occurred in the execution of the cycle task. In this case, it is necessary to record the execution error information of the cycle task with the abnormal execution, so as to summarize and analyze the task scheduling data and troubleshoot the cause of the abnormality. If the actual execution duration of any target cycle task is not greater than the second preset interval threshold, it means that the target cycle task is executed normally.

[0075] In the above method, by monitoring the actual execution time of the periodic tasks, real-time monitoring of the task execution status can be achieved, which helps to promptly discover abnormalities in task execution, thereby improving the reliability and performance of the vehicle operating system.

[0076] In the actual implementation of the present application solution, a timer can be deployed in the scheduling engine to use the timer to schedule periodic tasks at the target scheduling start time. Figure 5a ,by Figure 1 Taking the scheduling engine 5 in the example, a high-precision timer can be deployed in the scheduling engine 5, and the scheduling engine 5 is an entity containing a single real-time thread. It should be noted that the high-precision timer is only an example, and the application does not specifically limit the type of timer. Figure 5b This is a full flow chart of a task scheduling provided by an exemplary embodiment. Figure 5b , the whole process is executed by any scheduling engine and can include the following steps:

[0077] S501: Adjust the local time of the scheduling engine.

[0078] Exemplarily, a reference time may be obtained, and the local time may be adjusted according to the reference time.

[0079] S502: Determine the cycle start time of the next common cycle.

[0080] For example, the common cycle is determined according to the task execution duration of the periodic tasks configured on each scheduling engine, and the cycle start time of the next common cycle is calculated according to the current time and the predefined time. Figure 2 The embodiments shown will not be described in detail here.

[0081] S503: Start the high-precision timer and sleep until the start time of the next common cycle.

[0082] S504: The timer times out and wakes up the scheduling engine, entering the scheduling cycle of the next common period.

[0083] When the timer times out and wakes up the scheduling engine, it indicates that the start time of the next common cycle has arrived. At this time, the aforementioned "next common cycle" can be regarded as the current round of common cycle.

[0084] S505: Obtain the next scheduled periodic task from the task scheduling time information maintained by itself.

[0085] The task scheduling time information maintained by any scheduling engine records the various periodic tasks configured on the scheduling engine and the relative scheduling start time of each periodic task in a common period. Exemplarily, the task scheduling time information can be maintained in a table form, and the periodic tasks can be sorted in order from early to late (or small to large) according to the relative scheduling start time, see Table 1:

[0086] Table 1

[0087]

[0088] The next scheduled periodic task can be obtained from the task scheduling time information in sequence according to the order shown in Table 1.

[0089] S506: Calculate the target scheduling start time of the current periodic task according to the period start time of the current public period and the relative scheduling start time of the currently acquired periodic task (hereinafter referred to as the "current periodic task").

[0090] S507: Start the high-precision timer and sleep until the target scheduling start time of the current periodic task.

[0091] S508: The timer times out and wakes up the scheduling engine to prepare for executing the current periodic task.

[0092] When the timer times out and wakes up the scheduling engine, it indicates that the target scheduling start time of the current periodic task has arrived.

[0093] S509: Acquire the actual scheduling start time of the current periodic task, and determine whether the time interval between the actual scheduling start time and the target scheduling start time of the current periodic task is greater than a first preset interval threshold.

[0094] If yes, it indicates that the current periodic task scheduling is invalid, and the process jumps to S510 to cancel the execution of the current periodic task. If no, the process jumps to S511 to execute the current periodic task normally.

[0095] S510: Cancel the execution of the current periodic task.

[0096] S511: Execute the current periodic task normally.

[0097] S512: When the current periodic task is executed, the actual execution end time of the current periodic task is obtained, and it is determined whether the time interval between the actual execution end time of the current periodic task and the actual scheduling start time is greater than a second preset interval threshold.

[0098] If yes, then jump to S513 to record the information of the current periodic task execution error. If no, then jump to S514.

[0099] S513: Record the information of the execution error of the current periodic task.

[0100] S514: Determine whether the current periodic task is the last unscheduled periodic task in the task scheduling time information.

[0101] If yes, the process jumps to S515 to determine whether an instruction to exit task scheduling is received; if no, the process jumps to S505 to continue the scheduling cycle of this round of public period.

[0102] S515: Determine whether an instruction to exit task scheduling is received.

[0103] If yes, exit; if no, jump to S501 to start a new public cycle scheduling cycle. Figure 3 , Figure 3 2 shows the scheduling cycle of two rounds of common cycles, wherein in any round of common cycles, periodic tasks A, B, and C are scheduled three times respectively.

[0104] Figure 6 is a schematic diagram of the structure of an electronic device according to an exemplary embodiment of the present application. Figure 6At the hardware level, the electronic device includes a processor 602, an internal bus 604, a network interface 606, a memory 608, and a non-volatile memory 610, and may also include hardware required for other services. The processor 602 reads the corresponding computer program from the non-volatile memory 610 into the memory 608 and then runs it. Of course, in addition to the software implementation, this application does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0105] Corresponding to the above method embodiment, the present application also provides an embodiment of a scheduling device for periodic tasks.

[0106] Figure 7 The block diagram of a scheduling device for periodic tasks according to an exemplary embodiment of the present application is shown. The device can be applied to a target scheduling engine in a distributed system. The distributed system includes at least two scheduling nodes and at least one scheduling engine is deployed on each scheduling node. The target scheduling engine is any one of the at least two scheduling engines. Figure 7 The device includes a time adjustment unit 701, a period determination unit 702 and a scheduling start time determination unit 703, wherein:

[0107] The time adjustment unit 701 is configured to obtain a reference time and adjust the local time of the target scheduling engine according to the reference time;

[0108] The cycle determination unit 702 is configured to determine a common cycle according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate the cycle start time of the next common cycle according to the current time and the predefined time, wherein the predefined time is earlier than the current time;

[0109] The scheduling start time determination unit 703 is configured to determine the target scheduling start time of each periodic task configured on the target scheduling engine according to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, so as to schedule each periodic task according to the determined target scheduling start time.

[0110] Optionally, the period determination unit 702 is specifically used to: when the task execution durations of the periodic tasks respectively configured on the respective scheduling engines are the same, the common period is equal to the task execution duration; when the task execution durations of the periodic tasks respectively configured on the respective scheduling engines are different, the common period is equal to the target period negotiated by the respective scheduling engines.

[0111] Optionally, the target period includes: the least common multiple of the task execution durations of the periodic tasks respectively configured on the scheduling engines.

[0112] Optionally, the cycle determination unit 702 is specifically used to: calculate the number of executed common cycles from the predefined moment to the current moment; add 1 to the executed number to obtain the target number of common cycles; and determine the moment from the predefined moment to the moment after the target number of common cycles has passed as the cycle start time of the next common cycle.

[0113] Optionally, the device further comprises:

[0114] The periodic task screening unit 704 is configured to screen out the periodic tasks that are not scheduled on the target scheduling engine within the current common cycle according to the task scheduling time information and the current time when the number of executed tasks indicates that the current common cycle has not ended; determine the cycle start time of the current common cycle, and determine the scheduling start time of the unscheduled periodic tasks according to the cycle start time and the task scheduling time information.

[0115] Optionally, the task scheduling time information includes: information on relative scheduling start times of each periodic task configured on the target scheduling engine within a common period.

[0116] Optionally, the device further comprises:

[0117] The time interval comparison unit 705 is configured to, after the start of the next common cycle, cancel the execution of any periodic task configured on the target scheduling engine if the time interval between the actual scheduling start time of the periodic task and the target scheduling start time is greater than a first preset interval threshold; or, for any target periodic task configured on the target scheduling engine, record the execution error information of the target periodic task if the time interval between the actual execution end time of the target periodic task and the actual scheduling start time is greater than a second preset interval threshold; the target periodic task is a periodic task that has been executed and completed within the next common cycle.

[0118] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0119] The devices or modules described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0120] In a typical configuration, a computer includes one or more processors, including a central processing unit (CPU) and a graphics processing unit (GPU), an input / output interface, a network interface, and a memory. The CPU is used for computing simulations, and the GPU is used for outputting high-quality 3D images.

[0121] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0122] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0123] Corresponding to the embodiments of the aforementioned method, the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of any embodiment of the aforementioned method are implemented.

[0124] Corresponding to the embodiments of the aforementioned method, the present application also provides a computer program product, including a computer program and / or instructions, which implement the steps of any embodiment of the aforementioned method when executed by a processor.

[0125] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A method for scheduling periodic tasks, characterized in that: The method is applied to a target scheduling engine in a distributed system, wherein the distributed system includes at least two scheduling nodes, each scheduling node is deployed with at least one scheduling engine, and the target scheduling engine is any one of the at least two scheduling engines. The method includes: Obtaining a reference time, and adjusting the local time of the target scheduling engine according to the reference time; Determine a common cycle according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate a cycle start time of the next common cycle according to a current time and a predefined time, wherein the predefined time is earlier than the current time; According to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, the target scheduling start time of each periodic task configured on the target scheduling engine is determined, so as to schedule each periodic task according to the determined target scheduling start time.

2. The method according to claim 1, characterized in that: The determining of the common period according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines comprises: In the case where the task execution durations of the periodic tasks respectively configured on the scheduling engines are the same, the common period is equal to the task execution duration; In the case where the task execution durations of the periodic tasks respectively configured on the scheduling engines are different, the common period is equal to the target period obtained through negotiation by the scheduling engines.

3. The method according to claim 2, characterized in that The target period includes: the least common multiple of the task execution durations of the periodic tasks respectively configured on the scheduling engines.

4. The method according to claim 1, characterized in that: The step of calculating the cycle start time of the next common cycle according to the current time and the predefined time includes: Calculating the number of executed common cycles from the predefined time to the current time; Add 1 to the executed quantity to obtain the target quantity of the common cycle; The time point that starts from the predefined time point and ends after the target number of common cycles has passed is determined as the cycle start time point of the next common cycle.

5. The method according to claim 4, characterized in that Also includes: When the executed number indicates that the current common cycle has not ended, filtering out the periodic tasks that have not been scheduled on the target scheduling engine in the current common cycle according to the task scheduling time information and the current time; The cycle start time of the current common cycle is determined, and the scheduling start time of the unscheduled periodic task is determined according to the cycle start time and the task scheduling time information.

6. The method according to claim 1, characterized in that The task scheduling time information includes: information about the relative scheduling start time of each periodic task configured on the target scheduling engine within a common period.

7. The method according to claim 1, characterized in that After the next common cycle starts, the method further includes: For any periodic task configured on the target scheduling engine, if the time interval between the actual scheduling start time of the periodic task and the target scheduling start time is greater than a first preset interval threshold, cancel the execution of the periodic task; or, For any target periodic task configured on the target scheduling engine, if the time interval between the actual execution end time of the target periodic task and the actual scheduling start time is greater than the second preset interval threshold, the information of the target periodic task execution error is recorded. The target periodic task is a periodic task that has been executed and completed within the next common cycle.

8. A scheduling device for periodic tasks, characterized in that: The device is applied to a target scheduling engine in a distributed system, the distributed system includes at least two scheduling nodes, each scheduling node is deployed with at least one scheduling engine, the target scheduling engine is any one of the at least two scheduling engines, and the device includes: A time adjustment unit, used to obtain a reference time and adjust the local time of the target scheduling engine according to the reference time; a period determination unit, configured to determine a common period according to the task execution duration of the periodic tasks respectively configured on each of the at least two scheduling engines, and calculate a period start time of the next common period according to a current time and a predefined time, wherein the predefined time is earlier than the current time; A scheduling start time determination unit is used to determine the target scheduling start time of each periodic task configured on the target scheduling engine according to the cycle start time of the next common cycle and the task scheduling time information maintained by the target scheduling engine, so as to schedule each periodic task according to the determined target scheduling start time.

9. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product, characterized in that The method comprises a computer program and / or instructions, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Software and hardware mixing real-time task scheduling method based on multi-core processor and FPGA

    CN103488531A

  • Self-adaptive task scheduling method and device for distributed rule engine and electronic equipment

    CN114327807A

  • Deterministic task scheduling and arranging method and system based on time triggering mechanism and storage medium

    CN115309519A

  • Task scheduling method and device, electronic equipment and storage medium

    CN118295778A

  • Timing task management method and device, electronic equipment and storage medium

    CN118312294A