Task scheduling method, system, electronic device and storage medium
By setting up a task scheduler and a task executor in the distributed centralized control system of electronic devices, the task release operation is reasonably controlled, and the resource competition problem between tasks is solved, and the rapid response to key tasks and efficient operation of the system is achieved.
Patent Information
- Application Number
- CN202411238556.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-09-05
AI Technical Summary
The complex resource competition between tasks in electronic devices, resulting in equipment failure and safety issues. How to reasonably control task release operations to avoid resource competition?
In the main control module of the distributed centralized control system, the task scheduler and the task executor are set up. By receiving task execution requests, the working status of the task scheduler is determined, the task priority is judged, and the task scheduler is controlled to stop or continue to issue tasks Prioritize high priority tasks.
It effectively avoids resource competition among multiple tasks, ensures rapid response and completion of critical tasks, and improves the overall efficiency and security of the system.
Smart Images

Figure CN118760508B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of resource management technology, and in particular to a task scheduling method, system, electronic device and storage medium. Background Art
[0002] With the development of science and technology, the functions that electronic devices need to realize are becoming more diversified. The various tasks that electronic devices need to handle are in competition with each other for the execution resources of the whole machine, and some special tasks require exclusive rights to the resources of the whole machine and cannot be interrupted, making the management of the whole machine tasks complicated and prone to errors, leading to equipment failures and even safety issues.
[0003] Therefore, how to reasonably control the task release operation and avoid resource competition among multiple tasks is a technical problem that technical personnel in this field currently need to solve. Summary of the invention
[0004] The purpose of this application is to provide a task scheduling method, system, electronic device and storage medium, which can reasonably control the task release operation and avoid resource competition among multiple tasks.
[0005] In order to solve the above technical problems, the present application provides a task scheduling method, which is applied to a main control module of a distributed centralized control system, wherein the distributed centralized control system also includes a slave control module, wherein both the main control module and the slave control module are provided with a task executor, and the main control module is also provided with a task scheduler, wherein the task scheduling method includes:
[0006] Receive a task execution request and determine the current working state of the task scheduler; wherein the working state of the task scheduler includes a non-idle state and an idle state, the non-idle state is the state in which the task scheduler starts the task publishing process, and the idle state is the state in which the task scheduler exits the task publishing process; the task executor is used to execute the task when the current task published by the task scheduler is a preset task;
[0007] If the number of the task execution requests is greater than 1 and the task scheduler is in a non-idle state, determining an alternative task corresponding to each of the task execution requests, and setting the alternative task with the highest execution priority as the target task;
[0008] Determine whether the preemption priority of the target task is higher than the preemption priority of the original task; wherein the original task is the current task issued by the task scheduler to the task executor;
[0009] If yes, control the task scheduler to stop issuing the original task, and control the task scheduler to issue the target task to all the task executors;
[0010] If not, controlling the task scheduler to continue issuing the original task to all the task executors;
[0011] If a task exit request sent by the task executor is received and the task scheduler is in a non-idle state, parsing the task exit request to obtain a task identifier;
[0012] Determine whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, control the task scheduler to stop publishing the original task; if they are inconsistent, control the task scheduler to continue publishing the original task to all the task executors.
[0013] Optionally, after receiving the task execution request and determining the current working state of the task scheduler, the method further includes:
[0014] If the number of the task execution requests is greater than 1 and the task scheduler is in an idle state, determining an alternative task corresponding to each of the task execution requests, and setting the alternative task with the highest execution priority as the target task;
[0015] The task scheduler is controlled to issue the target task to all the task executors.
[0016] Optionally, after receiving the task execution request and determining the current working state of the task scheduler, the method further includes:
[0017] If the number of the task execution requests is equal to 1 and the task scheduler is in a non-idle state, setting the task corresponding to the task execution request as the target task;
[0018] Determine whether the preemption priority of the target task is higher than the preemption priority of the original task;
[0019] If yes, control the task scheduler to stop issuing the original task, and control the task scheduler to issue the target task to all the task executors;
[0020] If not, the task scheduler is controlled to continue issuing the original task to all the task executors.
[0021] Optionally, after receiving the task execution request and determining the current working state of the task scheduler, the method further includes:
[0022] If the number of the task execution requests is equal to 1 and the task scheduler is in an idle state, the task corresponding to the task execution request is set as the target task, and the task scheduler is controlled to publish the target task to all the task executors.
[0023] Optionally, after setting the candidate task with the highest execution priority as the target task, the following further includes:
[0024] Other candidate tasks except the target task are cleared.
[0025] Optionally, receiving a task execution request includes:
[0026] receiving the task execution request sent by the slave control module;
[0027] And / or, receiving the task execution request sent by the user through the human-computer interaction system.
[0028] Optionally, controlling the task scheduler to publish the target task to all the task executors includes:
[0029] Controlling the task scheduler to publish the target task to all the task executors according to a first preset period;
[0030] Accordingly, controlling the task scheduler to continue issuing the original task to all the task executors includes:
[0031] The task scheduler is controlled to continue issuing the original task to all the task executors according to a second preset period.
[0032] The present application also provides a task scheduling system, comprising: a main control module and a slave control module; wherein the main control module and the slave control module are both provided with a task executor, and the main control module is also provided with a task scheduler;
[0033] The main control module comprises:
[0034] An information determination unit, configured to receive a task execution request and determine the current working state of the task scheduler; wherein the working state of the task scheduler includes a non-idle state and an idle state, the non-idle state being a state in which the task scheduler starts a task publishing process, and the idle state being a state in which the task scheduler exits a task publishing process; the task executor is configured to execute a task when the current task published by the task scheduler is a preset task;
[0035] a target task determining unit, configured to determine, if the number of the task execution requests is greater than 1 and the task scheduler is in a non-idle state, an alternative task corresponding to each of the task execution requests, and set the alternative task with the highest execution priority as the target task;
[0036] A preemption priority comparison unit, used to determine whether the preemption priority of the target task is higher than the preemption priority of the original task; wherein the original task is the current task issued by the task scheduler to the task executor;
[0037] The task scheduler control unit is used to control the task scheduler to stop issuing the original task when the preemption priority of the target task is higher than the preemption priority of the original task, and control the task scheduler to issue the target task to all the task executors; the task scheduler control unit is also used to control the task scheduler to continue issuing the original task to all the task executors when the preemption priority of the target task is lower than or equal to the preemption priority of the original task;
[0038] The task scheduler control unit is also used to parse the task exit request to obtain the task identifier if a task exit request sent by the task executor is received and the task scheduler is in a non-idle state; the task scheduler control unit is also used to determine whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, control the task scheduler to stop publishing the original task; if they are inconsistent, control the task scheduler to continue publishing the original task to all the task executors.
[0039] The present application also provides a storage medium on which a computer program is stored. When the computer program is executed, the steps of executing the above-mentioned task scheduling method are implemented.
[0040] The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor calls the computer program in the memory, the steps of executing the above-mentioned task scheduling method are implemented.
[0041] The present application provides a task scheduling method, which is applied to the main control module of a distributed centralized control system, and the distributed centralized control system also includes a slave control module. The main control module is provided with a task executor and a task scheduler, and after receiving a task execution request, the current working state of the task scheduler can be determined. In the present application, the candidate task corresponding to the task execution request has an execution priority and a preemption priority. When the main control module receives multiple task execution requests, the target task can be determined based on the execution priority; when the task scheduler is in a non-idle state, it can be determined based on the preemption priority whether to stop publishing the original task and publish the target task. Through the above-mentioned method, it can be ensured that tasks with higher execution priority and / or higher preemption priority are published first, which effectively solves the problem of resource competition and ensures the rapid response and completion of key tasks. The present application also determines whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task when receiving a task exit request sent by the task executor and the task scheduler is in a non-idle state; if they are consistent, the task scheduler is controlled to stop publishing the original task; if they are inconsistent, the task scheduler is controlled to continue publishing the original task to all the task executors. In the above process, the task scheduler of the main control module can reasonably control the task release operation, and the task scheduler considers the resource allocation problem from the whole system level, so as to realize the reasonable allocation of resources in the multi-task scenario and effectively avoid the resource competition among multiple tasks. The present application also provides a task scheduling system, a storage medium and an electronic device, which have the above beneficial effects and are not described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0043] Figure 1 A flowchart of a task scheduling method provided in an embodiment of the present application;
[0044] Figure 2 A schematic diagram of the structure of a distributed centralized control system provided in an embodiment of the present application;
[0045] Figure 3 A flowchart of an execution of a task scheduling method provided in an embodiment of the present application;
[0046] Figure 4 A decision flow chart of a task scheduler provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0048] See below Figure 1 , Figure 1 A flowchart of a task scheduling method provided in an embodiment of the present application.
[0049] Specific steps may include:
[0050] S101: receiving a task execution request and determining the current working state of the task scheduler;
[0051] Among them, this embodiment can be applied to the main control module of a distributed centralized control system, and the distributed centralized control system also includes a slave control module. Both the main control module and the slave control module are provided with a task executor, and the main control module is also provided with a task scheduler.
[0052] See also Figure 2 , Figure 2 A structural diagram of a distributed centralized control system provided in an embodiment of the present application, the distributed centralized control system includes a master control module and multiple slave control modules. The master control module includes a task executor and a task scheduler, and the slave control module includes a task executor. The master control module can execute a task release operation to the slave control module, and the slave control module can transmit an internal task request to the master control module. The master control module is connected to the human-computer interaction system and the working component, and the human-computer interaction system can transmit an external task request to the master control module. The slave control module is also connected to the working component corresponding to itself. The above-mentioned internal task request may include a task execution request, and may also include a task exit request; the above-mentioned external task request may include a task execution request, and may also include a task exit request.
[0053] The working state of the above-mentioned task scheduler includes a non-idle state and an idle state, that is, the current working state of the task scheduler can be a non-idle state or an idle state. The non-idle state is the state in which the task scheduler starts the task release process, and the idle state is the state in which the task scheduler exits the task release process. The state of starting the task release process is the state of being in the task release process. The task release process refers to the operational process in which the task scheduler of the main control module releases tasks to the task executor of the main control module and the task executor of the slave control module. After starting the task release process, the task scheduler has a current task (i.e., the original task) that needs to be released, and during the period of starting the task release process, the task scheduler can release tasks to the task executor at preset time intervals. After exiting the task release process, the task scheduler does not have a current task that needs to be released, and during the period of exiting the task release process, the task scheduler does not release tasks to the task executor.
[0054] The main control module and the slave control module are both provided with corresponding task executors, each of which may have its corresponding preset task, and each task executor is used to execute a task when the current task issued by the task scheduler is a preset task. A task scheduler in a non-idle state may issue tasks to all task executors, and the task executor may compare the received tasks with its corresponding preset tasks; if the task issued by the task scheduler is the preset task corresponding to the task executor itself, the task executor may execute the task issued by the task scheduler. Specifically, the task executor may execute the task issued by the task scheduler by calling the corresponding working component.
[0055] In this step, the task caller can receive the task execution request sent from the control module, and can also receive the task execution request sent by the user through the human-computer interaction system. After receiving the task execution request, the current working state of the task scheduler can be determined. If the task scheduler has tasks that need to be released, the task executor is in a non-idle state; if the task scheduler does not have tasks that need to be released, the task executor is in an idle state. The number of task execution requests received in this step can be 1 or more.
[0056] S102: If the number of task execution requests is greater than 1 and the task scheduler is in a non-idle state, determining an alternative task corresponding to each task execution request, and setting the alternative task with the highest execution priority as a target task;
[0057] Among them, the task execution request includes an execution priority and a preemption priority, and the alternative task corresponding to the task execution request has the same execution priority and preemption priority as the corresponding task execution request. This step is based on the fact that the number of received task execution requests is greater than 1 and the task scheduler is in a non-idle state, and the alternative task corresponding to each of the task execution requests can be determined, and then the alternative task with the highest execution priority among all the alternative tasks is set as the target task. This embodiment can also clear other alternative tasks except the target task to reduce the occupation of storage resources.
[0058] The corresponding scenario of this step is: the main control module receives multiple task requests at the same time, and the task scheduler has tasks to be released. For each task execution request received, the task scheduler generates a corresponding candidate task. Among all the candidate tasks, the task scheduler will select the candidate task with the highest execution priority as the target task.
[0059] The above method can ensure that the distributed centralized control system responds to the most urgent or important task requests, and optimizes resource allocation as much as possible even when resources are limited, avoiding inefficient or invalid task execution, thereby improving the overall system efficiency and responsiveness.
[0060] S103: Determine whether the preemption priority of the target task is higher than the preemption priority of the original task; if so, proceed to S104; if not, proceed to S105;
[0061] Among them, the original task is the current task released by the task scheduler to the task executor. In task scheduling, each task is assigned a preemption priority, and the preemption priority determines whether a task can interrupt another task being released. If the preemption priority of the target task determined by S102 is higher than the preemption priority of the original task currently being released, the main control module will interrupt the original task and release the target task instead. Through the above scheme, the main control module can dynamically adjust the currently released tasks when resources are limited, so as to better meet the needs of different tasks and improve the overall system performance and user experience.
[0062] S104: Control the task scheduler to stop issuing the original task, and control the task scheduler to issue the target task to all the task executors;
[0063] Among them, this step is based on the fact that the preemption priority of the target task is higher than the preemption priority of the original task. It can control the task scheduler to stop publishing the original task and control the task scheduler to publish the target task to all the task executors. At this time, the task scheduler is still in a non-idle state, and the task publishing process currently started by the task scheduler is used to publish the target task.
[0064] S105: Control the task scheduler to continue issuing the original task to all the task executors.
[0065] Among them, this step is based on the fact that the preemption priority of the target task is lower than or equal to the preemption priority of the original task. At this time, the task scheduler is still in a non-idle state, and the task release process currently started by the task scheduler is used to release the original task, that is, the main control module can control the task scheduler to continue to release the original task to all the task executors. Since the preemption priority of the target task is lower than or equal to the preemption priority of the original task, the above target task can be cleared at this time.
[0066] Furthermore, each task executor may send a task exit request to the main control module. The task exit request carries a task identifier. If the task identifier of the task currently issued by the main control module is consistent with the task identifier carried in the task exit request, the main control module stops issuing the current task.
[0067] Specifically, the main control module can determine whether a task exit request sent by the task executor is received, and the main control module's processing flow for the task exit request includes the following steps: if a task exit request sent by the task executor is received and the task scheduler is in a non-idle state, the task exit request is parsed to obtain a task identifier; whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, the task scheduler is controlled to stop publishing the original task; if they are inconsistent, the task scheduler is controlled to continue publishing the original task to all the task executors.
[0068] The above-mentioned processing flow of the task exit request can be executed after receiving the task exit request, so as to decide whether to continue to publish the original task according to the comparison of the task identifier. In the processing flow of the task exit request, the main control module compares the task identifier corresponding to the task exit request with the task identifier of the current task (i.e., the original task) published by the task scheduler. If they are consistent, the task scheduler is controlled to stop publishing the current task; if they are inconsistent, the task scheduler is controlled to continue to publish the current task to all the task executors.
[0069] If the main control module receives a task exit request and a task execution request, the corresponding operation is performed according to the order in which the requests are received. For example, if the main control module receives a task exit request and a task execution request in sequence, the processing flow of the task exit request is first executed, and then the processing flow of the task execution request described in S101~S105 is executed; for another example, if the main control module receives a task execution request and a task exit request in sequence, the processing flow of the task execution request described in S101~S105 is first executed, and then the processing flow of the task exit request is executed.
[0070] The scheme provided in this embodiment is applied to the main control module of the distributed centralized control system, and the distributed centralized control system also includes a slave control module. The main control module is provided with a task executor and a task scheduler. After receiving a task execution request, the current working state of the task scheduler can be determined. In this embodiment, the candidate task corresponding to the task execution request has an execution priority and a preemption priority. When the main control module receives multiple task execution requests, the target task can be determined based on the execution priority; when the task scheduler is in a non-idle state, it can be determined based on the preemption priority whether to stop publishing the original task and publish the target task. Through the above-mentioned method, it can be ensured that tasks with higher execution priority and / or higher preemption priority are published first, which effectively solves the problem of resource competition and ensures the rapid response and completion of key tasks. In this embodiment, when a task exit request sent by a task executor is received and the task scheduler is in a non-idle state, it is determined whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, the task scheduler is controlled to stop publishing the original task; if they are inconsistent, the task scheduler is controlled to continue publishing the original task to all the task executors. In the above process, the task scheduler of the main control module can reasonably control the task release operation. The task scheduler considers the resource allocation problem from the whole system level, so as to realize the reasonable allocation of resources in the multi-task scenario and effectively avoid the resource competition among multiple tasks.
[0071] As for Figure 1 Further introduction to the corresponding embodiment: after receiving a task execution request and determining the current working status of the task scheduler, if the number of the task execution requests is greater than 1 and the task scheduler is in an idle state, then determine the alternative tasks corresponding to each of the task execution requests, and set the alternative tasks with the highest execution priority as the target task; control the task scheduler to publish the target task to all the task executors.
[0072] When the task scheduler is in an idle state, the task scheduler currently has no tasks to be released. At this time, the candidate task with the highest execution priority can be set as the target task. Therefore, after determining the target task, the task scheduler can be directly controlled to release the target task to all the task executors, so that the task scheduler starts the task release process for releasing the target task, and the task scheduler changes from an idle state to a non-idle state.
[0073] As for Figure 1 Further introduction to the corresponding embodiment: after receiving a task execution request and determining the current working status of the task scheduler, if the number of task execution requests is equal to 1 and the task scheduler is in a non-idle state, the task corresponding to the task execution request is set as the target task; determine whether the preemption priority of the target task is higher than the preemption priority of the original task; if so, control the task scheduler to stop publishing the original task, and control the task scheduler to publish the target task to all the task executors; if not, control the task scheduler to continue to publish the original task to all the task executors.
[0074] When the number of task execution requests is equal to 1, the task corresponding to the task execution request can be directly set as the target task. When the task scheduler is in a non-idle state, the task scheduler does not have the original task to be released. After determining the target task, the preemption priority of the target task can be compared with the preemption priority of the original task. If the preemption priority of the target task is higher than the preemption priority of the original task, the task scheduler can be controlled to release the target task; if the preemption priority of the target task is lower than or equal to the preemption priority of the original task, the task scheduler can be controlled to continue to release the original task and clear the target task.
[0075] As for Figure 1 Further introduction to the corresponding embodiment, after receiving a task execution request and determining the current working status of the task scheduler, if the number of task execution requests is equal to 1 and the task scheduler is in an idle state, the task corresponding to the task execution request is set as the target task, and the task scheduler is controlled to publish the target task to all the task executors.
[0076] When the task scheduler is in an idle state, the task scheduler currently does not have any tasks to be released; when the number of task execution requests is equal to 1, the task corresponding to the task execution request can be directly set as the target task. In the above case, this embodiment can directly control the task scheduler to release the task corresponding to the task execution request to all the task executors without comparing the execution priority and the preemption priority, so that the task scheduler starts the task release process for releasing the target task, and the task scheduler changes from an idle state to a non-idle state.
[0077] As for Figure 1 Further introduction to the corresponding embodiment: when publishing a target task, the task scheduler can be controlled to publish the target task to all the task executors according to a first preset period; when publishing an original task, the task scheduler can be controlled to continue to publish the original task to all the task executors according to a second preset period.
[0078] The following uses the example of the task scheduler issuing tasks to the task executor according to the period to illustrate the non-idle state and idle state of the task scheduler:
[0079] The non-idle state refers to the state in which the task scheduler starts the task publishing process, and there are tasks that need to be published. After the task scheduler starts the task publishing process, it publishes the original task to the task executor once in each cycle. In this embodiment, the state in which the original task is published to the task executor once in each cycle is called a non-idle state. Correspondingly, if the received original task is the preset task corresponding to the task executor, the task executor executes the above original task within this cycle.
[0080] The idle state refers to the state in which the task scheduler exits the task publishing process, and there are no tasks to be published in this state. After the task scheduler exits the task publishing process, it no longer publishes the original task to the task executor. In this embodiment, the state in which the original task is not published in each cycle according to the task exit request is called the idle state. Correspondingly, if the task executor does not receive the original task in this cycle, it will not execute the original task.
[0081] If the preset cycle is 10s, the task scheduler publishes the original task at 0s, 10s, and 20s, receives a task exit request at 21s, receives a new task execution request at 60s, and publishes the target task at the same time. In the above process, the task scheduler is in a non-idle state from 0s to 21s, and in an idle state from 21s to 65s.
[0082] The process described in the above embodiment is explained below through an embodiment in actual application.
[0083] As agricultural machinery and construction machinery become larger and more intelligent, the functions that need to be realized tend to be more diversified. There is a competition between tasks for the execution resources of the whole machine, and some special tasks require exclusive rights to the resources of the whole machine and cannot be interrupted, making the management of the whole machine tasks complex and prone to errors, leading to equipment failures and even safety problems.
[0084] This embodiment provides a task scheduling method and a distributed centralized control system, which solves the problem of competition and release of system resources among various tasks in a distributed centralized control system with multi-task scenarios, realizes efficient coordination of overall machine resources, and improves system security and reliability.
[0085] The distributed centralized control system provided in this embodiment includes but is not limited to a human-machine interaction system, working components and a control module. The human-machine interaction system and the control module are electrically connected via a communication bus, and the working components and the control module are electrically connected. In this embodiment, any control module can be designated as a master control module, and the remaining control modules can be designated as slave control modules.
[0086] Based on the above distributed centralized control system, this embodiment provides a task scheduling method. Figure 3 , Figure 3 The execution flow chart of a task scheduling method provided in the embodiment of the present application specifically includes the following steps: task request, task decision, task release, task execution, and task exit. The above-mentioned task scheduling method includes task coding rules, a task scheduler, and multiple task executors, wherein the task scheduler runs in the main control module, and each slave control module runs a task executor.
[0087] This embodiment can encode and manage the tasks involved in the distributed centralized control system. The task codes are formulated and stored in the main control module and each slave control module in advance. The user sends a task execution request to the main control module through the human-computer interaction system, each slave control module sends a task execution request to the main control module, and each slave control module sends a task exit request to the main control module. The task execution request is a piece of data in a specific format containing the task code. After receiving the above task execution request, the main control module makes a task decision through the task scheduler in the main control module, decides the next task to be executed, and publishes the above task to each slave control module through the system communication bus. The content of the task release is a piece of data in a specific format containing the task code. Each slave control module parses and judges the task released by the main control module after receiving it. When the code of the received task is related to the current executor (that is, when the current task released by the task scheduler is a preset task), the task is executed; at the same time, any of the task executors can send a task exit request to the task scheduler, and the task exit request will be responded to by the task scheduler first. The task code is pre-compiled and stored in the main control module and the slave control module.
[0088] This embodiment can encode the tasks that the whole machine may execute, and the encoding includes but is not limited to execution priority, preemption priority, and task number (i.e., task identifier). The above-mentioned execution priority includes multiple priority codes, and the priority levels are arranged in positive or reverse order according to the coding numbers. As a feasible implementation method, in this embodiment, the lower the priority code, the higher the execution priority. The above-mentioned preemption priority includes multiple priority codes, and the priority levels are arranged in positive or reverse order according to the coding numbers. As a feasible implementation method, in this embodiment, the lower the priority code, the higher the preemption priority. The above-mentioned task number is used to number the preset tasks.
[0089] The user can initiate a task execution request through the human-computer interaction system, which includes but is not limited to a display screen, a handle, an armrest box, an operation panel, etc. The slave control module in the distributed control system can also actively initiate a task execution request and a task exit request.
[0090] See also Figure 4 , Figure 4 A decision flow chart of a task scheduler provided in an embodiment of the present application, the process is as follows:
[0091] Determine whether there is a new task request (including a task execution request and / or a task exit request).
[0092] If there is a new task request, it is determined whether the task scheduler is in an idle state; if the task scheduler is in an idle state, it is determined whether there are multiple task requests; if there are multiple task requests, the task with a high execution priority is released; if there are no multiple task requests, the task is released directly; if the task scheduler is not in an idle state, the task with a high preemption priority is released. If the corresponding task exit request is received, the current task is stopped from being released, and the task scheduler enters an idle state. If the corresponding task exit request is not received, the step of determining whether there is a new task request is entered.
[0093] If there is no new task request, determine whether the task scheduler is in an idle state; if the task scheduler is in an idle state, end the process and determine whether there is a new task request again; if the task scheduler is in a non-idle state, directly publish the task. If the corresponding task exit request is received, stop publishing the current task and the task scheduler enters an idle state. If the corresponding task exit request is not received, enter the step of determining whether there is a new task request.
[0094] When the task scheduler does not receive one or more new task requests, it continues to issue the current task or remains in an idle state; when the task scheduler receives a new task request, it enters a priority comparison process.
[0095] In the priority comparison process, if the task scheduler is currently in an idle state; when the number of task requests is 1, the task scheduler publishes the above task to the system; when the number of task requests received by the task scheduler is multiple, the task scheduler sorts the execution priorities of the above multiple task requests, publishes the task with the highest execution priority, and clears the current task request at the same time.
[0096] In the priority comparison process, if the task scheduler is currently in a non-idle state (there are tasks being issued); when the number of task requests is 1, the task scheduler compares the preemption priority of the requested task and the task currently being issued. When the preemption priority of the newly requested task is higher than the preemption priority of the task currently being issued, the task scheduler issues a new task, otherwise the currently issued task remains unchanged and the currently received task request is cleared.
[0097] In the priority comparison process, if the task scheduler is currently in a non-idle state (there are already tasks being released); when there are multiple task requests, the task scheduler compares the execution priority of the newly requested task, the preemption priority of the task request with the highest execution priority and the preemption priority of the currently released task. When the preemption priority of the newly requested task is higher than the preemption priority of the currently released task, the task scheduler releases the new task, otherwise the currently released task remains unchanged. At the same time, the currently received task request is cleared.
[0098] The task decision is executed by the task scheduler. When the task scheduler receives a task exit instruction, it compares the task number of the task exit instruction with the number of the task currently issued by the task scheduler. If they match, the task scheduler stops issuing the current task and enters an idle state.
[0099] In the process of task release, the task scheduler uses, but is not limited to, CAN (Controller Area Network) and RS485 communication buses to release the currently executed tasks to the distributed control system;
[0100] The task release is periodic, and the task instruction data format released by the task scheduler includes but is not limited to command control words, command content and other content. The order of command control words, command content and other content in the task instruction data format is not limited.
[0101] When the whole machine is powered on, an initial value is obtained, and the value of the command control word is set to the above initial value. Optionally, the initial value is set to zero. When the task issued by the task scheduler has the same task number as the last issued task, the command control word remains unchanged.
[0102] When the task number issued by the task scheduler is different from the task number issued last time, the command control word changes according to the corresponding rules, including but not limited to cyclic increasing and cyclic decreasing changes. Optionally, the command control word can be changed according to the cyclic increasing rule.
[0103] During the task execution process, each control module executes the corresponding task according to the task code released by the scheduler.
[0104] The description of task exit is as follows: The task executor in the slave control module can send a request to exit the current task to the task scheduler based on the task execution status. The task exit request data format includes but is not limited to command control words, request content and other content. When the whole machine is powered on, an initial value will be obtained to assign a value to the command control word. Optionally, the initial value is set to zero. When the task requested by the task executor has the same task number as the last request, the command control word remains unchanged. When the task requested by the task executor has a different task number than the last request, the command control word changes according to corresponding rules, and the rules include but are not limited to changes in cyclic increments and cyclic decrements. Optionally, the command control word can change according to cyclic increment rules.
[0105] The task scheduling scheme proposed in this embodiment solves the problem of competition for system resources between tasks when executing task switching in a distributed centralized control system with a multi-task scenario. This embodiment also proposes a priority control strategy to solve the problem of atomic execution of uninterruptible low-priority tasks, and proposes an active exit mechanism to ensure the release of machine resources for uninterruptible tasks. This enables efficient coordinated operation of machine resources.
[0106] The embodiment of the present application also provides a task scheduling system, which may include: a main control module and a slave control module; wherein the main control module and the slave control module are both provided with a task executor, and the main control module is also provided with a task scheduler;
[0107] The main control module comprises:
[0108] An information determination unit, configured to receive a task execution request and determine the current working state of the task scheduler; wherein the working state of the task scheduler includes a non-idle state and an idle state, the non-idle state being a state in which the task scheduler starts a task publishing process, and the idle state being a state in which the task scheduler exits a task publishing process; the task executor is configured to execute a task when the current task published by the task scheduler is a preset task;
[0109] a target task determining unit, configured to determine, if the number of the task execution requests is greater than 1 and the task scheduler is in a non-idle state, an alternative task corresponding to each of the task execution requests, and set the alternative task with the highest execution priority as the target task;
[0110] A preemption priority comparison unit, used to determine whether the preemption priority of the target task is higher than the preemption priority of the original task; wherein the original task is the current task issued by the task scheduler to the task executor;
[0111] The task scheduler control unit is used to control the task scheduler to stop issuing the original task when the preemption priority of the target task is higher than the preemption priority of the original task, and control the task scheduler to issue the target task to all the task executors; the task scheduler control unit is also used to control the task scheduler to continue issuing the original task to all the task executors when the preemption priority of the target task is lower than or equal to the preemption priority of the original task;
[0112] The task scheduler control unit is also used to parse the task exit request to obtain the task identifier if a task exit request sent by the task executor is received and the task scheduler is in a non-idle state; the task scheduler control unit is also used to determine whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, control the task scheduler to stop publishing the original task; if they are inconsistent, control the task scheduler to continue publishing the original task to all the task executors.
[0113] The scheme provided in this embodiment is applied to the main control module of the distributed centralized control system, and the distributed centralized control system also includes a slave control module. The main control module is provided with a task executor and a task scheduler. After receiving a task execution request, the current working state of the task scheduler can be determined. In this embodiment, the candidate task corresponding to the task execution request has an execution priority and a preemption priority. When the main control module receives multiple task execution requests, the target task can be determined based on the execution priority; when the task scheduler is in a non-idle state, it can be determined based on the preemption priority whether to stop publishing the original task and publish the target task. Through the above-mentioned method, it can be ensured that tasks with higher execution priority and / or higher preemption priority are published first, which effectively solves the problem of resource competition and ensures the rapid response and completion of key tasks. In this embodiment, when a task exit request sent by a task executor is received and the task scheduler is in a non-idle state, it is determined whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, the task scheduler is controlled to stop publishing the original task; if they are inconsistent, the task scheduler is controlled to continue publishing the original task to all the task executors. In the above process, the task scheduler of the main control module can reasonably control the task release operation. The task scheduler considers the resource allocation problem from the whole system level, so as to realize the reasonable allocation of resources in the multi-task scenario and effectively avoid the resource competition among multiple tasks.
[0114] Furthermore, the task scheduler control unit is also used to determine the alternative task corresponding to each task execution request if the number of the task execution requests is greater than 1 and the task scheduler is in an idle state, and set the alternative task with the highest execution priority as the target task; and is also used to control the task scheduler to publish the target task to all the task executors.
[0115] Furthermore, the task scheduler control unit is also used to set the task corresponding to the task execution request as the target task if the number of task execution requests is equal to 1 and the task scheduler is in a non-idle state; and is also used to determine whether the preemption priority of the target task is higher than the preemption priority of the original task; if so, control the task scheduler to stop publishing the original task, and control the task scheduler to publish the target task to all the task executors; if not, control the task scheduler to continue publishing the original task to all the task executors.
[0116] Furthermore, the task scheduler control unit is also used to set the task corresponding to the task execution request as the target task if the number of the task execution requests is equal to 1 and the task scheduler is in an idle state, and control the task scheduler to publish the target task to all the task executors.
[0117] Furthermore, the process in which the task scheduler control unit controls the task scheduler to publish the target task to all the task executors includes: controlling the task scheduler to publish the target task to all the task executors according to a first preset period;
[0118] Correspondingly, the process in which the task scheduler control unit controls the task scheduler to continue to publish the original task to all the task executors includes: controlling the task scheduler to continue to publish the original task to all the task executors according to a second preset period.
[0119] Since the embodiments of the system part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the system part, which will not be repeated here.
[0120] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps provided in the above embodiment can be implemented. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0121] The present application also provides an electronic device, which may include a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps provided in the above embodiment may be implemented. Of course, the electronic device may also include various network interfaces, power supplies and other components.
[0122] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of this application.
[0123] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A task scheduling method, characterized in that: A main control module applied to a distributed centralized control system, the distributed centralized control system also includes a slave control module, the main control module and the slave control module are both provided with a task executor, the main control module is also provided with a task scheduler, and the task scheduling method includes: Receive a task execution request and determine the current working state of the task scheduler; wherein the working state of the task scheduler includes a non-idle state and an idle state, the non-idle state is the state in which the task scheduler starts the task publishing process, and the idle state is the state in which the task scheduler exits the task publishing process; the task executor is used to execute the task when the current task published by the task scheduler is a preset task; If the number of the task execution requests is greater than 1 and the task scheduler is in a non-idle state, determining an alternative task corresponding to each of the task execution requests, and setting the alternative task with the highest execution priority as the target task; Determine whether the preemption priority of the target task is higher than the preemption priority of the original task; wherein the original task is the current task issued by the task scheduler to the task executor; If yes, control the task scheduler to stop issuing the original task, and control the task scheduler to issue the target task to all the task executors; If not, controlling the task scheduler to continue issuing the original task to all the task executors; If a task exit request sent by the task executor is received and the task scheduler is in a non-idle state, parsing the task exit request to obtain a task identifier; Determine whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, control the task scheduler to stop issuing the original task; if they are inconsistent, control the task scheduler to continue issuing the original task to all the task executors; Wherein, controlling the task scheduler to publish the target task to all the task executors includes: Controlling the task scheduler to publish the target task to all the task executors according to a first preset period; Accordingly, controlling the task scheduler to continue issuing the original task to all the task executors includes: The task scheduler is controlled to continue issuing the original task to all the task executors according to a second preset period.
2. The task scheduling method according to claim 1, characterized in that: After receiving the task execution request and determining the current working state of the task scheduler, the method further includes: If the number of the task execution requests is greater than 1 and the task scheduler is in an idle state, determining an alternative task corresponding to each of the task execution requests, and setting the alternative task with the highest execution priority as the target task; The task scheduler is controlled to issue the target task to all the task executors.
3. The task scheduling method according to claim 1, characterized in that: After receiving the task execution request and determining the current working state of the task scheduler, the method further includes: If the number of the task execution requests is equal to 1 and the task scheduler is in a non-idle state, setting the task corresponding to the task execution request as the target task; Determine whether the preemption priority of the target task is higher than the preemption priority of the original task; If yes, control the task scheduler to stop issuing the original task, and control the task scheduler to issue the target task to all the task executors; If not, the task scheduler is controlled to continue issuing the original task to all the task executors.
4. The task scheduling method according to claim 1, characterized in that: After receiving the task execution request and determining the current working state of the task scheduler, the method further includes: If the number of the task execution requests is equal to 1 and the task scheduler is in an idle state, the task corresponding to the task execution request is set as the target task, and the task scheduler is controlled to publish the target task to all the task executors.
5. The task scheduling method according to claim 1, characterized in that: After setting the candidate task with the highest execution priority as the target task, it also includes: Other candidate tasks except the target task are cleared.
6. The task scheduling method according to claim 1, characterized in that: Receiving a task execution request includes: receiving the task execution request sent by the slave control module; And / or, receiving the task execution request sent by the user through the human-computer interaction system.
7. A task scheduling system, characterized in that: include: A main control module and a slave control module; wherein both the main control module and the slave control module are provided with a task executor, and the main control module is also provided with a task scheduler; The main control module comprises: An information determination unit, configured to receive a task execution request and determine the current working state of the task scheduler; wherein the working state of the task scheduler includes a non-idle state and an idle state, the non-idle state being a state in which the task scheduler starts a task publishing process, and the idle state being a state in which the task scheduler exits a task publishing process; the task executor is configured to execute a task when the current task published by the task scheduler is a preset task; a target task determining unit, configured to determine, if the number of the task execution requests is greater than 1 and the task scheduler is in a non-idle state, an alternative task corresponding to each of the task execution requests, and set the alternative task with the highest execution priority as the target task; A preemption priority comparison unit, used to determine whether the preemption priority of the target task is higher than the preemption priority of the original task; wherein the original task is the current task issued by the task scheduler to the task executor; The task scheduler control unit is used to control the task scheduler to stop issuing the original task when the preemption priority of the target task is higher than the preemption priority of the original task, and control the task scheduler to issue the target task to all the task executors; the task scheduler control unit is also used to control the task scheduler to continue issuing the original task to all the task executors when the preemption priority of the target task is lower than or equal to the preemption priority of the original task; The task scheduler control unit is further used to parse the task exit request to obtain a task identifier if a task exit request sent by the task executor is received and the task scheduler is in a non-idle state; the task scheduler control unit is further used to determine whether the task identifier corresponding to the task exit request is consistent with the task identifier of the original task; if they are consistent, control the task scheduler to stop publishing the original task; if they are inconsistent, control the task scheduler to continue publishing the original task to all the task executors; The process in which the task scheduler control unit controls the task scheduler to publish the target task to all the task executors includes: controlling the task scheduler to publish the target task to all the task executors according to a first preset period; Correspondingly, the process in which the task scheduler control unit controls the task scheduler to continue to publish the original task to all the task executors includes: controlling the task scheduler to continue to publish the original task to all the task executors according to a second preset period.
8. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the task scheduling method according to any one of claims 1 to 6 when calling the computer program in the memory.
9. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the steps of the task scheduling method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Task scheduling method and related equipment
CN113467901A
Data writing method and device, computer equipment and storage medium
CN118069598A