Task scheduling optimization method and device, equipment, medium and computer program product
By encapsulating task structures and calculating comprehensive priorities in real time, and combining task scheduling with max-heap data structures, the problems of resource waste and response latency in embedded real-time systems are solved, achieving efficient and flexible task scheduling.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SUZHOU ZONGWEI AUTOMATION CO LTD
- Filing Date
- 2026-02-02
- Publication Date
- 2026-05-26
AI Technical Summary
Existing task scheduling methods in embedded real-time systems suffer from high busy-wait overhead, large context switching overhead, and insufficient scheduling strategy flexibility and dynamic adaptability, resulting in low resource utilization and response latency.
By encapsulating a task structure containing multiple types of priority information, and using a weighted fusion algorithm to calculate the comprehensive priority in real time, combined with a max-heap data structure to sort tasks, a continuous response scheduling loop is formed, dynamically adjusting task priorities to adapt to business needs.
It enhances the flexibility and dynamic adaptability of scheduling strategies, ensures timely task response, reduces resource consumption, and improves system efficiency and energy efficiency.
Smart Images

Figure CN122086552A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a task scheduling optimization method, apparatus, device, medium, and computer program product. Background Technology
[0002] With the technological advancements in embedded real-time systems, industrial control, and smart terminals, the business complexity of software systems continues to increase, leading to increasingly stringent requirements for responsiveness, resource utilization, and dynamic adaptability. Task scheduling, as the core mechanism for system resource allocation, directly determines the system's operational efficiency and business adaptability.
[0003] In related technologies, task scheduling often adopts the following methods: one is polling-based active query, which achieves scheduling by continuously checking the status of each task source through the processor; the other is cooperative scheduling based on condition variables and semaphores, which relies on tasks to voluntarily relinquish processor resources.
[0004] However, the relevant scheduling methods have significant drawbacks: the busy waiting of polling scheduling leads to unnecessary consumption of computing resources, which is especially unsuitable for energy-sensitive scenarios; cooperative scheduling has high context switching overhead, making it difficult to efficiently manage a large number of concurrent tasks, and the scheduling strategy lacks flexibility and dynamic adaptability. Summary of the Invention
[0005] Therefore, it is necessary to provide a task scheduling optimization method, apparatus, equipment, medium, and computer program product that can improve the flexibility and dynamic adaptability of scheduling strategies, while reducing resource consumption and ensuring timely task response, in order to address the above-mentioned technical problems.
[0006] Firstly, this application provides a task scheduling optimization method, the method comprising:
[0007] In response to the creation of a task to be executed, the task to be executed is encapsulated into a task structure including a task identifier, task processing logic and task priority information, wherein the task priority information includes first priority information, second priority information and comprehensive priority information.
[0008] Based on the first priority information and the second priority information, the comprehensive priority information is calculated and updated in real time using a weighted fusion algorithm.
[0009] Based on the updated overall priority information, the task with the highest overall priority is selected from the ready queue using a standard scheduling algorithm based on overall priority sorting, and then executed according to the task processing logic corresponding to the selected task.
[0010] If the selected task to be executed has been completed and the scheduling termination condition is not met, the task scheduling will be repeated in response to the creation of a new task and / or changes in task priority information.
[0011] In some embodiments of the method, the method further includes:
[0012] In response to the creation of a new task and / or changes in task priority information, determine whether there is a priority adjustment request for the task to be executed;
[0013] In the absence of a priority adjustment request for the task to be executed, the default priority data of the task to be executed shall be used as the first priority information.
[0014] If a priority adjustment request for the task to be executed exists, user-defined priority data is obtained and used as the second priority information.
[0015] In some embodiments of the method, the step of calculating and updating the comprehensive priority information in real time using a weighted fusion algorithm based on the first priority information and the second priority information includes:
[0016] The first priority information is weighted with the corresponding first weight coefficient, the second priority information is weighted with the corresponding second weight coefficient, and the results of the two weighting processes are then merged to calculate and update the comprehensive priority information in real time.
[0017] Wherein, the sum of the first weighting coefficient and the second weighting coefficient is 1.
[0018] In some embodiments of the method, the ready queue is configured as a max-heap data structure. The step of selecting the task with the highest overall priority from the ready queue using a standard scheduling algorithm based on overall priority sorting, according to the updated overall priority information, and executing the task according to the task processing logic corresponding to the selected task, includes:
[0019] The max-heap data structure ensures that the task with the highest overall priority is always located at the top of the ready queue.
[0020] The task with the highest overall priority is selected from the top of the ready queue, and then executed according to the task processing logic corresponding to the selected task.
[0021] In some embodiments of the method, the method further includes:
[0022] If the ready queue is detected to be empty, the control processing unit enters a sleep state until an event of new task creation and / or task priority information change is detected.
[0023] In some embodiments of the method, the method is applied to a power supply box system with charging control, and the task to be executed includes at least one of a watchdog refresh task, an LED status refresh task, a relay charging and discharging control task, a charging chip control task, and a serial communication task.
[0024] The method further includes:
[0025] If the associated parameters of the target task to be executed do not meet the preset conditions, the priority adjustment interface is called to adjust the second priority information of the target task to be executed to the highest level.
[0026] According to a second aspect of the present disclosure, a task scheduling optimization apparatus is provided. The apparatus includes:
[0027] An encapsulation module is used to encapsulate the task to be executed into a task structure including a task identifier, task processing logic and task priority information in response to the creation of the task to be executed. The task priority information includes first priority information, second priority information and comprehensive priority information.
[0028] The processing module is used to calculate and update the comprehensive priority information in real time based on the first priority information and the second priority information using a weighted fusion algorithm;
[0029] The control module is used to select the task with the highest overall priority from the ready queue according to the updated overall priority information using a standard scheduling algorithm based on overall priority sorting, and then execute the task processing logic corresponding to the selected task.
[0030] The scheduling module is used to repeatedly execute task scheduling in response to the creation of new tasks and / or changes in task priority information, provided that the selected tasks to be executed have been completed and the scheduling termination conditions are not met.
[0031] According to a third aspect of the present disclosure, a computer device is provided. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the task scheduling optimization method described above.
[0032] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the task scheduling optimization method described above.
[0033] According to a fifth aspect of the present disclosure, a computer program product is provided. The computer program product includes a computer program that, when executed by a processor, implements the task scheduling optimization method described above.
[0034] The task scheduling optimization scheme provided in this application provides an example of a task scheduling optimization scheme that encapsulates a task structure containing multiple types of priority information and combines it with real-time calculated comprehensive priority for scheduling. This forms a continuous response scheduling loop, which can effectively improve the flexibility and dynamic adaptability of the scheduling strategy, ensuring that the system can adjust the scheduling direction in a timely manner according to changes in business needs and guaranteeing the timeliness of response for various tasks.
[0035] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0036] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0037] Figure 1 This is a flowchart illustrating a task scheduling optimization method according to an exemplary embodiment;
[0038] Figure 2 This is a schematic diagram illustrating the specific process of a task scheduling optimization method according to an exemplary embodiment;
[0039] Figure 3 This is a structural block diagram of a task scheduling optimization apparatus according to an exemplary embodiment;
[0040] Figure 4 This is a diagram illustrating the internal structure of a computer device according to an exemplary embodiment. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0042] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure. The terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in a process, method, product, or apparatus that includes said elements is not excluded. For example, the use of terms such as "first," "second," etc., to denote names does not indicate any specific order.
[0043] In some embodiments provided in this disclosure, the execution of the task scheduling optimization method can be controlled by a unified controller or by multiple controllers. These controllers may include controllers on local terminals or controllers on remote servers. In some embodiments, the controllers on local terminals and the controllers on servers may jointly assist in completing the task scheduling optimization control processing. The local terminal mentioned in this disclosure may include, but is not limited to, various robotic devices, vehicle-mounted devices, personal computers, laptops, smartphones, tablets, wearable devices, medical devices, VR (Virtual Reality) devices, etc. The server may also be a server, server cluster, distributed subsystem, cloud processing platform, server containing blockchain nodes, or a combination thereof. The controllers described in this disclosure may include various control units capable of implementing logic processing functions, including but not limited to CPU (Central Processing Unit), PLC (Programmable Logic Controller), ECU (Electronic Control Unit), MCU (Microcontroller Unit), FPGA (Field Programmable Gate Array), and CPLD (Complex Programmable Logic Device), as well as controllers composed of one or more logic function units, chips, etc.
[0044] In C-language-based system software development, such as embedded real-time systems, an efficient task scheduling mechanism is the cornerstone for building software systems that are responsive, resource-efficient, and highly predictable.
[0045] Polling-based proactive querying is a straightforward scheduling method, simple to implement but costly. This model requires the processor to continuously check the status of each task source, regardless of whether a task has occurred. In scenarios with low task occurrence rates, this busy-wait strategy leads to a large amount of CPU time being consumed by idle loops, resulting in unnecessary waste of valuable computing resources (especially battery power in energy-sensitive scenarios), fundamentally violating the principle of efficient scheduling—on-demand response. Cooperative scheduling, built using synchronization primitives such as condition variables and semaphores, allows tasks to voluntarily yield the processor while waiting for other tasks. However, this model heavily relies on the cooperation of the tasks themselves, and the overhead of context switching is not negligible. More importantly, it struggles with efficient unified management and immediate wake-up when facing a large number of concurrent task sources, easily leading to uncontrollable scheduling latency. Therefore, it usually needs to be used in conjunction with other mechanisms rather than as a standalone solution.
[0046] Beyond the inherent limitations of the aforementioned models, traditional scheduling schemes suffer from deeper shortcomings in the intelligence and adaptability of their scheduling strategies. Most lightweight or early-designed schedulers either completely lack a priority concept, employing only simple first-in-first-out or fair round-robin strategies, unable to differentiate task urgency; or they only provide static priorities fixed at compile time or initialization. This rigid priority allocation mechanism cannot perceive the dynamically changing business context and real-time load during system runtime. For example, a log writing task set as low priority during a quiet period may become critically important when system fault diagnosis information is urgently needed, but the static scheduler cannot respond to this. This rigid strategy easily leads to two typical problems: first, under conditions of continuous high load occupying resources, low-priority tasks may indefinitely be denied execution opportunities; second, high-priority tasks experience response delays. When multiple high-priority tasks arrive in quick succession, they still need to queue, unable to be adjusted based on finer-grained urgency (such as absolute deadlines), resulting in the inability to absolutely guarantee the timeliness of critical responses.
[0047] In some embodiments of this disclosure, a task scheduling optimization method is provided, such as... Figure 1 As shown, it includes the following steps:
[0048] S20. In response to the creation of the task to be executed, the task to be executed is encapsulated into a task structure including a task identifier, task processing logic and task priority information, wherein the task priority information includes first priority information, second priority information and comprehensive priority information.
[0049] Tasks to be executed typically refer to various operational tasks in software development that meet business requirements. These tasks may include data processing, equipment control, communication interaction, and other related operational tasks.
[0050] A task structure typically refers to a data carrier that encapsulates various core information of a task in a structured manner. It may include key fields such as task identifier, task processing logic, priority information of different types, and weight coefficients, providing a unified task data interface for the scheduling system.
[0051] First priority information typically refers to the pre-set priority based on the inherent importance of the task, reflecting its basic priority level at the system level. Second priority information typically refers to the priority set by the user or relevant business modules based on real-time business needs, used to adapt to dynamically changing usage scenarios. Comprehensive priority information typically refers to the final priority calculated using a specific algorithm by combining the first and second priority information, serving as the core basis for task scheduling.
[0052] In some implementations, when a new task is created, the system automatically encapsulates it into a task structure containing a task identifier, task processing logic, and task priority information. The task identifier typically refers to the identification information that distinguishes different tasks in the system, ensuring that tasks are not confused during scheduling; it is the unique identification basis for a task within the scheduling system. The task processing logic typically refers to the specific business operations that the task needs to perform and the relevant context data supporting the operation execution. It is the core content of the actual operation after the task is scheduled and can be implemented through specific functions or instruction sets. The task priority information may include the system-preset first priority information, dynamically adjustable second priority information, and subsequently calculated comprehensive priority information, providing a basis for scheduling decisions.
[0053] S22. Based on the first priority information and the second priority information, the comprehensive priority information is calculated and updated in real time using a weighted fusion algorithm.
[0054] Weighted fusion algorithms typically refer to methods that fuse two pieces of information with different priorities using a set adjustment factor, thereby balancing the influence weights of different priorities.
[0055] S24. Based on the updated comprehensive priority information, select the task with the highest comprehensive priority from the ready queue using the standard scheduling algorithm based on comprehensive priority sorting, and execute it according to the task processing logic corresponding to the selected task.
[0056] A ready queue typically refers to a storage structure that stores all tasks waiting to be scheduled for execution. Its organization enables efficient task lookup and selection.
[0057] Standard scheduling algorithms typically refer to the core algorithms in the scheduling system kernel used to select tasks to be executed. They can sort tasks based on their overall priority, select the highest priority tasks from the ready queue, and allocate resources for execution, ensuring that critical tasks are processed first.
[0058] S26. If the selected task to be executed has been completed and the scheduling termination condition is not met, the task scheduling shall be repeated in response to the creation of a new task and / or the change of task priority information.
[0059] The scheduling termination condition usually refers to the specific scenario or signal that triggers the scheduling system to stop the continuous scheduling loop. It can include the system receiving a shutdown command, all scheduled tasks having been completed, or the system experiencing a serious fault that requires it to stop running. It is the basis for determining the termination of the scheduling loop.
[0060] Task scheduling typically refers to the entire process by which a system allocates resources, adjusts the execution order, and manages the status of various tasks to be executed based on preset rules and real-time business needs. It can balance system resource utilization with business response timeliness and ensure that tasks of different importance can get reasonable execution opportunities.
[0061] In some embodiments of this disclosure, by encapsulating a task structure containing multiple types of priority information and combining it with real-time calculated comprehensive priorities for scheduling, a continuous response scheduling loop can be formed. This can effectively improve the flexibility and dynamic adaptability of the scheduling strategy, ensuring that the system can adjust the scheduling direction in a timely manner according to changes in business needs and guaranteeing the timeliness of response for various tasks.
[0062] In some embodiments of this disclosure, the method further includes:
[0063] In response to the creation of a new task and / or changes in task priority information, determine whether there is a priority adjustment request for the task to be executed;
[0064] In the absence of a priority adjustment request for the task to be executed, the default priority data of the task to be executed shall be used as the first priority information.
[0065] If a priority adjustment request for the task to be executed exists, user-defined priority data is obtained and used as the second priority information.
[0066] In some implementations, refer to Figure 2 When a new task is created or task priority information is changed, the system first checks whether there is a priority adjustment request for that task. If there is no such request, the system will use the task's default priority data as the first priority information; if there is such a request, the system will obtain the custom priority data set by the user or business module and use it as the second priority information, ensuring that the priority information obtained meets the needs of the actual use case.
[0067] In some examples, if the request does not exist, i.e. there is no external dynamic request, the system will use the default priority of the task. This default priority is usually the basic priority preset according to the type when the task is initialized, reflecting its inherent importance at the system level (e.g., interrupt service tasks are higher than ordinary computing tasks).
[0068] In other examples, if the request exists, the system can read the user-defined priority value assigned to the task from the request table. This value can be determined by business logic; for example, setting a VIP user's request task to the highest priority, or setting a background backup task to the lowest priority.
[0069] In some embodiments of this disclosure, the source of the first priority information and the second priority information can be flexibly determined based on whether there is a priority adjustment request. This not only retains the stability brought by the system's preset priority, but also fully considers the dynamic needs of users or business modules, making the priority setting more in line with actual application scenarios and improving the accuracy of scheduling decisions.
[0070] In some embodiments of this disclosure, S22 includes:
[0071] The first priority information is weighted with the corresponding first weight coefficient, the second priority information is weighted with the corresponding second weight coefficient, and the results of the two weighting processes are then merged to calculate and update the comprehensive priority information in real time.
[0072] Wherein, the sum of the first weighting coefficient and the second weighting coefficient is 1.
[0073] In some implementations, after obtaining the first and second priority information, a weighted fusion algorithm can be used for real-time calculation to update the overall priority information. This algorithm sets appropriate adjustment factors based on the needs of the actual application scenario, considering the two priority information separately before fusion. The adjustment factors can flexibly adjust the influence of the two priorities in the overall priority. When the system relies more on preset rules, the influence of the first priority information can be strengthened; when business needs dominate, the weight of the second priority information can be increased, thus achieving a smooth transition from system-preset dominance to business-demand dominance.
[0074] In some examples, the aforementioned adjustment factors may include a first weighting coefficient (e.g., α) and a second weighting coefficient (e.g., β), where α + β = 1. The first weighting coefficient can be configured to correspond to the system's preset first priority information, and the second weighting coefficient can be configured to correspond to the second priority information dynamically configured at runtime. In actual deployment, the initial values of the weighting coefficients can be set according to the system's core design goals. If the system prioritizes basic stability, the first weighting coefficient can be set to a higher value, allowing the preset basic priority to dominate the comprehensive priority calculation, ensuring that the execution priority of core system tasks is not affected by business fluctuations; if the system needs to prioritize adapting to dynamic business needs, the proportion of the second weighting coefficient can be appropriately increased, allowing user-defined priorities to influence scheduling decisions more quickly.
[0075] It is important to note that the weighting coefficients are not fixed and can be dynamically adjusted based on feedback data during system operation to form a closed-loop optimization. For example, when the system detects that a low-priority task has not been executed for a long time, the first and second weighting coefficients can be fine-tuned through the feedback mechanism to moderately increase the influence of the second weighting coefficient on this type of task, allowing its overall priority to rise slowly. When multiple high-priority tasks arrive in quick succession, causing a response delay, the proportion of the second weighting coefficient of the corresponding critical task can be temporarily increased to make it dominate the overall priority calculation, ensuring that urgent business needs are responded to first.
[0076] In other examples, a power supply box system with charging control is used as a specific application scenario for illustration. During normal system operation, the first weight coefficient remains high, allowing the basic priority of core system tasks such as safety shutdown and watchdog timer refresh to dominate scheduling. When the battery voltage is detected to be below the emergency threshold, the system can trigger a dynamic switch of the weight coefficient through the priority adjustment interface, instantly increasing the proportion of the second weight coefficient. This allows the user-defined priority of emergency tasks such as charging relay control to fully play its role, quickly improving its overall priority and ensuring timely execution of emergency protection logic. This weighted fusion algorithm based on dual weight coefficients retains the stability of the system's preset rules while providing flexible space for dynamic intervention based on business needs. It truly achieves a seamless transition from system-preset dominance to business-demand dominance, enabling the calculation of overall priority to accurately match the scheduling needs under different operating conditions.
[0077] In some embodiments of this disclosure, the influence of the two priority information can be balanced by reasonably setting adjustment factors, thereby achieving a flexible ratio of the two priorities in the comprehensive priority calculation. This enables the system to adaptively adjust the scheduling basis according to different application scenarios and key needs, further enhancing the adaptability and practicality of the scheduling strategy.
[0078] In some embodiments of this disclosure, the ready queue is configured as a max-heap data structure, and based on this, S24 includes:
[0079] The max-heap data structure ensures that the task with the highest overall priority is always located at the top of the ready queue.
[0080] The task with the highest overall priority is selected from the top of the ready queue, and then executed according to the task processing logic corresponding to the selected task.
[0081] In some implementations, the ready queue is configured as a max-heap data structure to ensure that the highest priority task is always at the top of the heap, thus making the time complexity of retrieving the task to be executed O(1). The ready queue is constructed using a specific data structure to ensure that the task with the highest overall priority is always in an easily accessible position. The system will select the task with the highest overall priority from the ready queue using a standard scheduling algorithm based on the updated overall priority information. Then, the system will call the task processing logic corresponding to the task and execute the task according to the preset business process to ensure that critical tasks can receive priority resource support.
[0082] In some examples, due to the use of a max-heap data structure, it can be simplified to retrieving the task to be executed from the top of the heap. The algorithm ensures that the highest priority task in the current queue is selected for execution, thus decoupling complex dynamic priority maintenance from efficient task dispatch.
[0083] In some embodiments of this disclosure, a max-heap data structure can be used as the specific structure of the ready queue, which can quickly locate and select the task with the highest overall priority, greatly improve the efficiency of task selection, reduce the delay in the scheduling process, ensure that high-priority tasks can be executed in a timely manner, and further guarantee the system's response speed and operating efficiency.
[0084] In some embodiments of this disclosure, the method further includes:
[0085] If the ready queue is detected to be empty, the control processing unit enters a sleep state until an event of new task creation and / or task priority information change is detected.
[0086] In some implementations, when the system detects that the ready queue is empty and there are no tasks to be executed, it will control the processing unit to enter a sleep state to reduce unnecessary resource consumption. The processing unit will only be awakened and re-enter the task scheduling process when a new task is created or the task priority information is changed, effectively improving the system's energy efficiency.
[0087] In some examples, when the system detects that the ready queue is empty and there are no tasks to be processed, the idle() function can be called to put the processing unit (such as the central processing unit) into a low-power sleep state, reducing unnecessary resource consumption. Compared with related technologies, this can solve the problem of polling consuming a lot of resources.
[0088] In some embodiments of this disclosure, the ineffective operation of processing units is avoided when the ready queue is empty, reducing unnecessary consumption of computing resources. This is especially suitable for energy-sensitive application scenarios, significantly improving the energy efficiency ratio of the system and extending the battery life of related devices.
[0089] In some embodiments of this disclosure, the method is applied to a power supply box system with charging control, and the task to be executed includes at least one of a watchdog refresh task, an LED status refresh task, a relay charging and discharging control task, a charging chip control task, and a serial communication task.
[0090] The method further includes:
[0091] If the associated parameters of the target task to be executed do not meet the preset conditions, the priority adjustment interface is called to adjust the second priority information of the target task to be executed to the highest level.
[0092] In some implementations, in a power supply box system with charging control, the tasks to be executed may include watchdog timer refresh, LED status refresh, relay charging and discharging control, charging chip control, serial communication, and other related operations. When the system detects that the associated parameters of a target task do not conform to the preset normal range, it will proactively call the priority adjustment interface to adjust the second priority information of the task to the highest level, ensuring that the task can be scheduled and executed with priority, handling abnormal situations in a timely manner, and ensuring the safe and stable operation of the system.
[0093] In some examples, the configuration of first-priority information (basic priority) can be quantitatively modeled based on the inherent importance of the task. The setting criteria typically include at least one of the task's criticality and real-time requirements. First-priority information can be configured as one of the following: highest, second-highest, medium, and low priority, or a combination of these dynamically changing levels. For example, tasks related to system survival, such as safety shutdown tasks and dog-feeding tasks, can be configured as highest priority; emergency alarm handling tasks (such as overvoltage, overcurrent, and overtemperature) and critical communication response tasks can be configured as second-highest priority; charging relay control tasks and core battery status acquisition tasks can be configured as medium priority; and routine tasks such as LED status refresh and non-critical data logging tasks can be configured as low priority.
[0094] During normal system operation, the charging relay control task has a medium basic priority. When the battery data acquisition task detects that the battery voltage is lower than the emergency threshold, it can call the `set_task_priority()` interface to set the user-defined priority of the charging task to the highest level. Based on this, the scheduler instantly calculates its new highest overall priority, allowing it to be scheduled and executed immediately, thus achieving emergency protection.
[0095] In other examples, the basic priority, i.e., the first priority information, can be eliminated, relying entirely on a single, dynamically updatable priority field that business modules can modify at any time. This sacrifices the system's default stability guarantees but achieves minimalist dynamism.
[0096] In some embodiments of this disclosure, for power supply box system application scenarios with charging control, the priority of the target task can be adjusted when the associated parameters are abnormal, which can quickly respond to abnormal situations in the system, prioritize the handling of critical protection tasks, effectively avoid system failures or safety issues caused by abnormal parameters, and ensure the stable operation and safe use of the power supply box system.
[0097] The task scheduling optimization methods disclosed herein, by encapsulating a task structure containing multiple types of priority information and combining it with real-time calculated comprehensive priorities for scheduling, and forming a continuous response scheduling loop, can effectively improve the flexibility and dynamic adaptability of scheduling strategies, ensuring that the system can adjust the scheduling direction in a timely manner according to changes in business needs, and guaranteeing the timeliness of response for various tasks.
[0098] It is understood that the various embodiments of the methods described in this specification are presented in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. Related details can be found in the descriptions of other method embodiments.
[0099] It should be understood that although the steps in the flowcharts shown in the accompanying drawings are displayed sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the accompanying drawings may include multiple steps or stages, which are not necessarily completed at the same time, but may be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but may be performed alternately or in turn with other steps or at least a portion of the steps or stages of other steps.
[0100] Based on the description of the above-described embodiments of the task scheduling optimization method, this disclosure also provides a task scheduling optimization apparatus for implementing the task scheduling optimization method involved above. The apparatus may include a system (including a distributed system), software (application), module, component, controller, server, terminal, etc., using the method described in the embodiments of this specification, combined with necessary implementation hardware. Based on the same innovative concept, the apparatuses in one or more embodiments provided in this disclosure are as described in the following embodiments. Since the implementation schemes and methods for solving the problem by the apparatus are similar, the implementation of the specific apparatus in the embodiments of this specification can refer to the implementation of the aforementioned method, and repeated details will not be repeated. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0101] Figure 3 This is a schematic block diagram illustrating a task scheduling optimization device according to an exemplary embodiment. The device can be the aforementioned terminal, a server, or a module, component, device, control unit, etc., integrated into the terminal. For details, please refer to... Figure 3The device 100 may include: an encapsulation module 120, a processing module 140, a control module 160, and a scheduling module 180. The encapsulation module 120 is used to encapsulate the task to be executed into a task structure including a task identifier, task processing logic, and task priority information in response to the creation of the task to be executed. The task priority information includes first priority information, second priority information, and comprehensive priority information. The processing module 140 is used to calculate and update the comprehensive priority information in real time using a weighted fusion algorithm based on the first priority information and the second priority information. The control module 160 is used to select the task to be executed with the highest comprehensive priority from the ready queue using a standard scheduling algorithm based on comprehensive priority sorting, and execute it according to the task processing logic corresponding to the selected task. The scheduling module 180 is used to repeatedly execute task scheduling in response to the creation of a new task and / or changes in task priority information, provided that the selected task to be executed has been completed and the scheduling termination condition is not met.
[0102] In some embodiments of the device, the scheduling module 180 is further configured to, in response to the creation of a new task and / or a change in task priority information, determine whether there is a priority adjustment request for the task to be executed; further configured to, if there is no priority adjustment request for the task to be executed, use the default priority data of the task to be executed as the first priority information; and further configured to, if there is a priority adjustment request for the task to be executed, obtain user-defined priority data and use the user-defined priority data as the second priority information.
[0103] In some embodiments of the device, the processing module 140 is further configured to perform weighted processing on the first priority information and the corresponding first weight coefficient, perform weighted processing on the second priority information and the corresponding second weight coefficient, and then merge the results of the two weighted processing to calculate and update the comprehensive priority information in real time; wherein, the sum of the first weight coefficient and the second weight coefficient is 1.
[0104] In some embodiments of the device, the ready queue is configured as a max-heap data structure, and the control module 160 is further configured to always keep the task with the highest overall priority at the top of the ready queue through the max-heap data structure; and to select the task with the highest overall priority from the top of the ready queue and execute it according to the task processing logic corresponding to the selected task.
[0105] In some embodiments of the device, the control module 160 is further configured to control the processing unit to enter a sleep state when the ready queue is detected to be empty, until an event of new task creation and / or task priority information change is detected.
[0106] In some embodiments of the device, the task scheduling optimization device 100 is also applied to a power supply box system with charging control. The tasks to be executed include at least one of a watchdog refresh task, a light-emitting diode status refresh task, a relay charging and discharging control task, a charging chip control task, and a serial communication task. The processing module 140 is further configured to, when detecting that the associated parameters corresponding to the target task to be executed do not meet preset conditions, call the priority adjustment interface to adjust the second priority information of the target task to be executed to the highest level.
[0107] Each module in the aforementioned task scheduling optimization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0108] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, communication interface, display screen, and input device connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a task scheduling optimization method.
[0109] Those skilled in the art will understand that Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0110] Based on the foregoing description of the relevant methods and apparatus embodiments, this disclosure also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, it implements the task scheduling optimization method described in any embodiment of this specification.
[0111] Based on the foregoing description of the relevant methods and apparatus embodiments, this disclosure also provides a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by the processor of a computer device, enables the computer device to implement the task scheduling optimization method as described in any embodiment of this disclosure.
[0112] Based on the foregoing description of the relevant methods and apparatus embodiments, this disclosure also provides a computer program product, including a computer program that, when executed by a processor, implements the task scheduling optimization method described in any embodiment of this specification.
[0113] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. In particular, hardware + program embodiments are relatively simple in description because they are fundamentally similar to method embodiments; relevant parts can be referred to the descriptions in the method embodiments.
[0114] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0115] It should be noted that the apparatus, computer equipment, storage medium, and computer program products described above may also include other implementation methods according to the description of the method embodiments. Specific implementation methods can be found in the description of the relevant method embodiments. Furthermore, new embodiments formed by combinations of features from various methods, apparatuses, devices, and server embodiments still fall within the scope of this disclosure and will not be elaborated upon here.
[0116] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in the same or different software and / or hardware, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of modules or units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling and communication connections between the devices or units shown or described can be implemented through direct and / or indirect coupling / connection, through standard or custom interfaces or protocols, and can be implemented electrically, mechanically, or in other forms.
[0117] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0118] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A task scheduling optimization method, characterized in that, The method includes: In response to the creation of a task to be executed, the task to be executed is encapsulated into a task structure including a task identifier, task processing logic and task priority information, wherein the task priority information includes first priority information, second priority information and comprehensive priority information. Based on the first priority information and the second priority information, the comprehensive priority information is calculated and updated in real time using a weighted fusion algorithm. Based on the updated overall priority information, the task with the highest overall priority is selected from the ready queue using a standard scheduling algorithm based on overall priority sorting, and then executed according to the task processing logic corresponding to the selected task. If the selected task to be executed has been completed and the scheduling termination condition is not met, the task scheduling will be repeated in response to the creation of a new task and / or changes in task priority information.
2. The method according to claim 1, characterized in that, The method further includes: In response to the creation of a new task and / or changes in task priority information, determine whether there is a priority adjustment request for the task to be executed; In the absence of a priority adjustment request for the task to be executed, the default priority data of the task to be executed shall be used as the first priority information. If a priority adjustment request for the task to be executed exists, user-defined priority data is obtained and used as the second priority information.
3. The method according to claim 1, characterized in that, The step of calculating and updating the comprehensive priority information in real time using a weighted fusion algorithm based on the first priority information and the second priority information includes: The first priority information is weighted with the corresponding first weight coefficient, the second priority information is weighted with the corresponding second weight coefficient, and the results of the two weighting processes are then merged to calculate and update the comprehensive priority information in real time. Wherein, the sum of the first weighting coefficient and the second weighting coefficient is 1.
4. The method according to claim 1, characterized in that, The ready queue is configured as a max-heap data structure. The step of selecting the highest-priority task from the ready queue based on the updated overall priority information using a standard scheduling algorithm that sorts tasks by overall priority, and then executing the task processing logic corresponding to the selected task, includes: The max-heap data structure ensures that the task with the highest overall priority is always located at the top of the ready queue. The task with the highest overall priority is selected from the top of the ready queue, and then executed according to the task processing logic corresponding to the selected task.
5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: If the ready queue is detected to be empty, the control processing unit enters a sleep state until an event of new task creation and / or task priority information change is detected.
6. The method according to claim 1, characterized in that, The method is applied to a power supply box system with charging control, and the task to be executed includes at least one of the following: watchdog refresh task, LED status refresh task, relay charging and discharging control task, charging chip control task, and serial communication task. The method further includes: If the associated parameters of the target task to be executed do not meet the preset conditions, the priority adjustment interface is called to adjust the second priority information of the target task to be executed to the highest level.
7. A task scheduling optimization device, characterized in that, The device includes: An encapsulation module is used to encapsulate the task to be executed into a task structure including a task identifier, task processing logic and task priority information in response to the creation of the task to be executed. The task priority information includes first priority information, second priority information and comprehensive priority information. The processing module is used to calculate and update the comprehensive priority information in real time based on the first priority information and the second priority information using a weighted fusion algorithm; The control module is used to select the task with the highest overall priority from the ready queue according to the updated overall priority information using a standard scheduling algorithm based on overall priority sorting, and then execute the task processing logic corresponding to the selected task. The scheduling module is used to repeatedly execute task scheduling in response to the creation of new tasks and / or changes in task priority information, provided that the selected tasks to be executed have been completed and the scheduling termination conditions are not met.
8. A computer device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, It stores a computer program thereon, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1 to 6.