Periodic task processing method, apparatus, medium, and device

By acquiring the number and cycle of tasks in the central processing unit in real time, and dynamically scheduling periodic tasks to processors with lighter loads, the problem of unbalanced central processing unit load and resource waste is solved, thereby improving CPU execution efficiency.

CN113986506BActive Publication Date: 2025-10-28CHINA AUTOMOTIVE INNOVATION CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111272805.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-29
Publication Date
2025-10-28
Estimated Expiration
2041-10-29

AI Technical Summary

Technical Problem

In existing technologies, the frequent switching of periodic tasks across different CPU cores leads to increased hardware resource consumption, reduced CPU execution efficiency, and uneven CPU load, resulting in significant resource waste.

Method used

By acquiring the number of periodic tasks being processed and the execution cycle of each central processing unit in real time, the desired number can be determined, and tasks can be scheduled to processors with lighter loads to avoid frequent switching and achieve load balancing.

Benefits of technology

It improves the data processing efficiency of the central processing unit, reduces hardware resource consumption, ensures a balanced load on the central processing unit, and avoids resource waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113986506B_ABST
    Figure CN113986506B_ABST
Patent Text Reader

Abstract

This paper belongs to the field of periodic task processing technology, specifically involving periodic task processing methods, apparatus, media, and devices, including: obtaining the number of periodic tasks being processed by each central processing unit (CPU) at the current moment and the execution cycle of each periodic task; determining the expected number of periodic tasks to be processed by each CPU at the next moment based on the total number of periodic tasks being processed at the current moment and the execution cycle of each periodic task; adding periodic tasks whose number of periodic tasks being processed by each CPU at the current moment is greater than the expected number of periodic tasks to be processed by each CPU at the next moment to a task scheduling set; scheduling periodic tasks in the task scheduling set to CPUs whose number of periodic tasks being processed at the current moment is less than the expected number. The implementation of this paper can achieve detailed allocation and scheduling of periodic tasks, improving the efficiency of CPU data processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of periodic task processing technology, and in particular to a periodic task processing method, apparatus, medium and equipment. Background Technology

[0002] Existing task scheduling methods employ local scheduling, where a fixed number of tasks are assigned to each CPU before system initialization, and each CPU maintains a fixed task queue during system operation. Alternatively, CPUs can be categorized according to their function, such as scheduling CPUs and computing CPUs, slow-processing CPUs and fast-processing CPUs. Dividing CPU functions and allocating global and local task queues can alleviate CPU load and power consumption issues to some extent. However, for periodic tasks, frequently assigning the same task to different cores leads to continuous and repeated copying of memory, drastically increasing hardware resource consumption and reducing CPU efficiency. Summary of the Invention

[0003] To solve the above-mentioned technical problems, the specific technical solution presented in this paper is as follows:

[0004] On the one hand, this paper provides a method for processing periodic tasks, the method comprising:

[0005] Obtain the number of periodic tasks being processed by each central processing unit at the current moment, as well as the execution cycle of each periodic task;

[0006] The expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the total number of periodic tasks processed at the current moment and the execution cycle of each periodic task.

[0007] Periodic tasks whose number of periodic tasks currently being processed by each central processing unit is greater than the expected number of periodic tasks to be processed by each central processing unit in the next time step are added to the task scheduling set.

[0008] The number of periodic tasks scheduled from the task scheduling set to be processed at the current time is less than the expected number of central processing units.

[0009] Furthermore, when obtaining the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task, the method further includes: obtaining the number of cores of each central processing unit.

[0010] The step of determining the expected number of periodic tasks to be processed by each central processing unit in the next moment, based on the total number of periodic tasks processed at all current moments and the execution cycle of each periodic task, includes:

[0011] The expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit.

[0012] Further, the step of determining the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit includes:

[0013] Determine the number of periodic tasks executed by each core in the least common multiple of the execution cycles of each periodic task;

[0014] Determine whether the difference between the maximum and minimum number of periodic tasks executed by each core in the least common multiple period is greater than a preset task threshold.

[0015] Accordingly, the expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the number of all periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit when the difference between the maximum and minimum values ​​of the number of periodic tasks executed under the least common multiple period is greater than a preset task threshold.

[0016] Furthermore, the method also includes:

[0017] Compare the number of periodic tasks currently being processed by each central processing unit with the corresponding expected number;

[0018] Based on the comparison results, a status label is added to the central processing unit whose current number of periodic tasks is different from the corresponding expected number. The status label includes a receiving status label or a broadcast status label. The receiving status label indicates that the current number of periodic tasks is less than the corresponding expected number, and the broadcast status label indicates that the current number of periodic tasks is greater than the corresponding expected number.

[0019] Accordingly, the step of scheduling the number of periodic tasks in the task scheduling set to be processed at the current time to be less than the expected number of central processing units includes:

[0020] The periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

[0021] Further, scheduling the periodic tasks in the task scheduling set to the central processing unit corresponding to the received state tag includes:

[0022] Obtain the historical tags of multiple historical moments consecutive to the current moment from the central processing unit corresponding to the received state tag;

[0023] When the historical tags of multiple historical periods corresponding to the central processing unit corresponding to the receiving state tag are all receiving state tags, the periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

[0024] Furthermore, the number of periodic tasks currently being processed by each central processing unit and the execution cycle of each periodic task are obtained when the periodic tasks of one or more central processing units change.

[0025] On the other hand, this document provides a periodic task processing apparatus, the apparatus comprising:

[0026] The data acquisition module is used to acquire the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task;

[0027] The expected quantity determination module is used to determine the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment and the execution cycle of each periodic task.

[0028] The scheduling set determination module is used to add periodic tasks whose number of periodic tasks currently being processed by each central processing unit is greater than the expected number of periodic tasks to be processed by each central processing unit in the next moment to the task scheduling set.

[0029] The scheduling module is used to schedule periodic tasks from the task scheduling set to the central processing unit where the number of periodic tasks being processed at the current time is less than the expected number.

[0030] Furthermore, the data acquisition module is also used to acquire the number of cores of each central processing unit;

[0031] The expected quantity determination module is further configured to determine the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit.

[0032] In another aspect, this document provides a computer-readable storage medium storing at least one instruction or at least one program, which is loaded and executed by a processor to implement the periodic task processing method described above.

[0033] In another aspect, this article provides a periodic task processing electronic device, including at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements the periodic task processing method described above by executing the instructions stored in the memory.

[0034] By adopting the above technical solution, the periodic task processing method, apparatus, medium and device of this paper obtains in real time the number of periodic tasks being processed by each central processing unit (CPU) in the processor at the current moment and the execution cycle of each periodic task. This facilitates the unified allocation and scheduling of tasks and timely understanding of task changes. Then, based on the total number of periodic tasks being processed at all current moments and the execution cycle of each periodic task, the expected number of periodic tasks to be processed by each CPU at the next moment can be determined. The expected number can be understood as the number of periodic tasks to be processed by the CPU at the next moment. The expected number can provide practical support for the scheduling of periodic tasks of each CPU and avoid unreasonable allocation and scheduling, which would cause the CPU to remain in an unbalanced state. After determining the expected number, the number of periodic tasks currently being processed by each CPU can be compared with the corresponding expected number. Periodic tasks exceeding the expected number are added to the task scheduling set, achieving unified allocation and scheduling of tasks, overall planning, and improving the accuracy of periodic task processing. Periodic tasks in the task scheduling set are scheduled to CPUs where the number of periodic tasks currently being processed is less than the expected number, achieving detailed allocation and scheduling of periodic tasks. This ensures that the load on each CPU is relatively balanced, avoiding excessively high or low loads on some CPUs, which would lead to resource waste. At the same time, it avoids frequent switching of the same periodic task to run on different cores, reducing the hardware resource consumption caused by frequent switching and improving the data processing efficiency of the CPU.

[0035] To make the above and other objects, features and advantages of this document more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0036] To more clearly illustrate the technical solutions in the embodiments or prior art described herein, the accompanying drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this article. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 A schematic diagram illustrating the steps of a periodic task processing method provided in the embodiments of this article is shown.

[0038] Figure 2 A schematic diagram illustrating the steps of another periodic task processing method provided in the embodiments of this article is shown.

[0039] Figure 3 A schematic diagram illustrating the steps of another periodic task processing method provided in the embodiments of this article is shown.

[0040] Figure 4 This document illustrates a state diagram showing the state changes of a core or central processing unit as provided in an embodiment of the invention.

[0041] Figure 5 A scheduling diagram of a periodic task processing method provided in the embodiments of this article is shown;

[0042] Figure 6 A scheduling diagram of yet another periodic task processing method provided in the embodiments of this article is shown;

[0043] Figure 7 A scheduling diagram of another periodic task processing method provided in the embodiments of this article is shown;

[0044] Figure 8 A schematic diagram of the structure of a periodic task processing device in an embodiment of this paper is shown;

[0045] Figure 9 A schematic diagram of the structure of a periodic task processing electronic device provided in the embodiments of this article is shown. Detailed Implementation

[0046] The technical solutions in the embodiments described below will be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments described herein, and not all of the embodiments. Based on the embodiments described herein, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this document.

[0047] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings herein 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 described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0048] To better understand this application, the following terms are now explained:

[0049] The Central Processing Unit (CPU) is one of the main components of an electronic computer, and its core part. Its main function is to interpret computer instructions and process data in computer software. All operations in a computer are handled by the CPU, which is responsible for reading, decoding, and executing instructions.

[0050] To address the aforementioned issues, this embodiment provides a method for processing periodic tasks. Figure 1 The diagram illustrates the steps of a periodic task processing method provided in this embodiment. Figure 1 As shown, the method can be applied to a processor or system with multiple central processing units, and the method may include the following steps:

[0051] S102. Obtain the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task.

[0052] Specifically, different systems or processors often have multiple central processing units (CPUs), and the number of periodic tasks that different CPUs can handle varies. In practical applications, the system or processor can obtain the number of periodic tasks that each CPU is currently processing and the execution cycle of each periodic task.

[0053] Specifically, a periodic task can be understood as a task that needs to be executed periodically in the CPU. Periodicity can be measured in minutes, hours, days, etc., but is not limited to these units. Periodic tasks can be system-defined periodic tasks or user-defined periodic tasks.

[0054] Specifically, a periodic task can include a corresponding execution cycle and the execution process corresponding to that cycle. For example, if the execution cycle of periodic task A is 20 seconds, then within that 20-second execution cycle, the periodic task needs to execute two steps, a and b, respectively.

[0055] It is understandable that different periodic tasks can be executed within the same or different execution cycles.

[0056] In practical applications, the number of periodic tasks processed by each central processing unit at the current moment and the execution cycle of each periodic task are obtained when the periodic tasks of one or more central processing units change.

[0057] Specifically, the periodic task changes of the central processing unit can be understood as the periodic task terminating execution, starting execution, or adding subtasks that need to be executed within the periodic task.

[0058] Understandably, the periodic tasks in each CPU are acquired in real time. When one or more periodic tasks experience the aforementioned changes (which may result in some CPUs having higher loads than others), the number of periodic tasks being processed by each CPU at that moment and the execution cycle of each periodic task can be obtained. Acquiring data only when periodic tasks change improves the timing of periodic task processing, avoiding execution when CPUs are at a relatively balanced load, thus saving system energy.

[0059] S104. Based on the number of periodic tasks processed at all current moments and the execution cycle of each periodic task, determine the expected number of periodic tasks to be processed by each central processing unit at the next moment.

[0060] Specifically, the expected number of periodic tasks that each CPU will process in the next moment can be the number of periodic tasks that each CPU will execute in the next moment when the load of each CPU reaches a relatively balanced state. The expected number for different CPUs can be the same or different. To improve the speed of periodic task scheduling, only one expected number can be set, which can be set according to the number of CPUs. For example, if the system has 3 CPUs, namely CPU D, CPU E, and CPU F, and the total number of periodic tasks for the 3 CPUs is 21, and the execution cycle of the 21 periodic tasks is 10 seconds, then the expected number for each CPU in 10 seconds can be determined by the average distribution method, which is 7. When determining the expected number corresponding to the time (1 second) for each CPU to process a single task, a positive rounding method can be used. For example, if the expected number in 1 second is 0.7, then the expected number corresponding to the time (1 second) for each CPU to process a single task is 1. The expected quantity used in the embodiments of this specification can be the expected quantity corresponding to the time (1s) of a single task processed by a central processing unit, that is, the expected quantity corresponding to a unit time core, or it can be the expected quantity corresponding to a central processing unit.

[0061] In practical applications, since the processing capabilities of different central processing units are different, the desired number can also be determined based on the configuration information of each central processing unit, the number of all periodic tasks being processed at the current moment, and the execution cycle of each periodic task.

[0062] S106. Add the periodic tasks that the number of periodic tasks processed by each central processing unit at the current moment is greater than the expected number of periodic tasks processed by each central processing unit at the next moment to the task scheduling set.

[0063] Specifically, the task scheduling set can be pre-set and stored in the system or process to store periodic tasks that need to be scheduled in a unified manner.

[0064] After determining the expected number for each central processing unit (CPU), the expected number for each CPU can be compared with the number of periodic tasks currently being processed by each CPU. Periodic tasks whose number of periodic tasks currently being processed by each CPU is greater than the expected number of periodic tasks to be processed by each CPU in the next time step are added to the task scheduling set.

[0065] In the specific implementation process, when there are multiple periodic tasks in the central processing unit, the execution cycle of each periodic task can be compared, and the periodic task with the longer execution cycle can be added to the task scheduling set.

[0066] For example, if the expected number of CPUs D is 2 and the number of periodic tasks being processed at the current moment is 3, then it can be determined that there is 1 periodic task in CPU D that needs to be added to the task scheduling set.

[0067] S108. Schedule the periodic tasks in the task scheduling set to the central processing unit where the number of periodic tasks being processed at the current time is less than the expected number.

[0068] Specifically, while determining the periodic tasks that need to be scheduled in the task scheduling set, it is also possible to determine the central processing unit that can receive and process the periodic tasks in the task scheduling set, as well as the number of corresponding periodic tasks.

[0069] In practical applications, the system or processor can schedule periodic tasks from the task scheduling set to the corresponding central processing units (CPUs) according to the number of periodic tasks that the CPUs can receive and process, thereby achieving load balancing among the CPUs in the system or processor. It is understood that when the number or type of current tasks remains unchanged, the system or processor can execute the adjustment method described above.

[0070] The embodiment of this specification provides a periodic task processing method that obtains in real time the number of periodic tasks being processed by each central processing unit (CPU) in the processor at the current moment and the execution cycle of each periodic task. This facilitates unified task allocation and scheduling and timely understanding of task changes. Then, based on the total number of periodic tasks being processed at all current moments and the execution cycle of each periodic task, the expected number of periodic tasks to be processed by each CPU at the next moment can be determined. The expected number can be understood as the number of periodic tasks to be processed by the CPU at the next moment. The expected number can provide practical support for the scheduling of periodic tasks of each CPU and avoid unreasonable allocation and scheduling, which would cause the CPU to remain in an unbalanced state. After determining the expected number, the number of periodic tasks currently being processed by each CPU can be compared with the corresponding expected number. Periodic tasks exceeding the expected number are added to the task scheduling set, achieving unified allocation and scheduling of tasks, overall planning, and improving the accuracy of periodic task processing. Periodic tasks in the task scheduling set are scheduled to CPUs where the number of periodic tasks currently being processed is less than the expected number, achieving detailed allocation and scheduling of periodic tasks. This ensures that the load on each CPU is relatively balanced, avoiding excessively high or low loads on some CPUs, which would lead to resource waste. At the same time, it avoids frequent switching of the same periodic task to run on different cores, reducing the hardware resource consumption caused by frequent switching and improving the data processing efficiency of the CPU.

[0071] Based on the above embodiments, in one embodiment of this specification, when obtaining the number of periodic tasks processed by each central processing unit at the current moment and the execution cycle of each periodic task, the method further includes: obtaining the number of cores of each central processing unit.

[0072] Specifically, a CPU core is a component that processes periodic tasks, and the number of cores can vary between different CPUs. A CPU can have 4, 8, or 16 cores, etc. Each core can process the same or different number of periodic tasks.

[0073] In practical applications, the system or processor can obtain the configuration information of each central processing unit, which may include the number of cores of the corresponding central processing unit.

[0074] The step of determining the expected number of periodic tasks to be processed by each central processing unit in the next moment, based on the total number of periodic tasks processed at all current moments and the execution cycle of each periodic task, includes:

[0075] The expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit.

[0076] Specifically, since different central processing units (CPUs) are configured with the same or different numbers of cores, meaning that the processing capabilities of different CPUs may be different, the desired number can also be determined based on the number of cores of each CPU, the total number of periodic tasks being processed at the current moment, and the execution cycle of each periodic task.

[0077] In practical applications, the sum of the periodic tasks being processed by all cores can be obtained to get the total number of periodic tasks. Dividing the total number of periodic tasks by the total number of cores gives the desired number of tasks. When the sum of all periodic tasks is not divisible by the number of cores, the remainder is rounded down and incremented by one to obtain the desired number of tasks for each core. Based on the desired number of tasks for each core, the desired number of tasks for each CPU can be calculated.

[0078] Specifically, Figure 2 This document illustrates the steps of another periodic task processing method provided in this embodiment, as shown below. Figure 2 As shown, before determining the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit, the method may include:

[0079] S202. Determine the number of periodic tasks executed by each core under the least common multiple of the execution cycles of each periodic task.

[0080] Specifically, the system or processor can determine the least common multiple (LCM) period based on the execution cycles of the acquired periodic tasks. The LCM period represents the completion of all currently processed periodic tasks once. For example, if the execution cycles of the periodic tasks processed in CPU D are 1s and 2s, and the execution cycles of the periodic tasks processed in CPU E are 1s and 3s, then the LCM period can be determined to be 6s. Correspondingly, the number of periodic tasks executed under the LCM period can be determined. For instance, CPU D executes 9 periodic tasks under the LCM period, and CPU E executes 8 periodic tasks under the LCM period. It is understandable that some periodic tasks may be executed repeatedly within the LCM period.

[0081] It is understandable that the steps of each periodic task in its corresponding execution cycle are deterministic. For example, if the execution cycle is 1 second, it means that the corresponding periodic task is executed once every 1 second, and if the execution cycle is 2 seconds, it is executed once every 2 seconds.

[0082] In practical applications, the number of periodic tasks executed by each core in the same central processing unit (CPU) under the least common multiple of the execution cycles of each periodic task can be determined by averaging the total number of periodic tasks executed by the CPU under the least common multiple of the execution cycles. The average value is taken as the number of periodic tasks executed by each core in the CPU under the least common multiple of the execution cycles of each periodic task. For example, if CPU D executes 9 periodic tasks under the least common multiple of the execution cycles of each periodic task (6s), and the number of cores is 5, then the number of periodic tasks executed by each core in CPU D under the least common multiple of the execution cycles of each periodic task is 2. That is, when the number of periodic tasks executed by the CPU under the least common multiple of the execution cycles of each periodic task is not divisible by the number of corresponding cores, a positive rounding method can be used to determine the number. S204. Determine whether the difference between the maximum and minimum values ​​of the number of periodic tasks executed by each core under the least common multiple of the execution cycles of each periodic task is greater than a preset task threshold.

[0083] Specifically, it can be compared whether the difference between the maximum and minimum number of periodic tasks executed by each core under the least common multiple period is greater than a preset task threshold. The preset task threshold is not specifically limited in the embodiments of this specification, and can be set according to actual needs.

[0084] Accordingly, the expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the number of all periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit when the difference between the maximum and minimum values ​​of the number of periodic tasks executed under the least common multiple period is greater than a preset task threshold.

[0085] Specifically, for example, when the maximum value of a periodic task processed by a core exceeds the minimum value of a periodic task processed by a core and is greater than or equal to 2, it indicates that the periodic task in the core corresponding to the maximum value of a periodic task processed by a core can be adjusted. The periodic task with the longest execution cycle among the periodic tasks processed by the core can be adjusted. Then, based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit, the expected number of periodic tasks processed by each central processing unit at the next moment can be determined.

[0086] When the difference between the maximum and minimum values ​​of the number of periodic tasks executed under the least common multiple period is not greater than the preset task threshold, it indicates that the system or processor is in a relatively balanced state.

[0087] Based on the above embodiments, in one embodiment of this specification, Figure 3 This document illustrates the steps of another periodic task processing method provided in the embodiments herein, such as... Figure 3 As shown, the method further includes:

[0088] S302. Compare the number of periodic tasks processed by each central processing unit at the current moment with the corresponding expected number.

[0089] S304. Based on the comparison results, add a status label to the central processing unit whose current number of periodic tasks is different from the corresponding expected number. The status label includes a receiving status label or a broadcast status label. The receiving status label indicates that the current number of periodic tasks is less than the corresponding expected number, and the broadcast status label indicates that the current number of periodic tasks is greater than the corresponding expected number.

[0090] Specifically, Figure 4 This document illustrates a state diagram of a core or central processing unit state change as provided in an embodiment of the invention, such as... Figure 4As shown, different states characterize the state of the periodic tasks processed by the central processing unit (CPU). The states of a periodic task can include running, balanced, broadcast, and receiving states. The balanced state indicates that the CPU is operating normally and the load is balanced. The broadcast state indicates that the CPU's load has exceeded that of other CPUs. The receiving state indicates that the CPU's load is lower than that of other CPUs. The running state is a transitional state between the balanced and broadcast states, and also a transitional state between the receiving and balanced states.

[0091] Understandably, the aforementioned status labels can also be added to the corresponding cores. Accordingly, the number of periodic tasks currently processed by each central processing unit can be compared with the corresponding expected number. This can be done by comparing the number of periodic tasks currently processed by each core with the corresponding expected number, and adding status labels to the cores based on the comparison results.

[0092] Accordingly, the step of scheduling the number of periodic tasks in the task scheduling set to be processed at the current time to be less than the expected number of central processing units includes:

[0093] The periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

[0094] Specifically, periodic tasks in the task scheduling set can be scheduled to the core corresponding to the receiving state tag and processed by the core corresponding to the receiving state tag.

[0095] In an optional embodiment, the receive state tag may carry an identifier corresponding to the number of periodic tasks that can be received. When scheduling periodic tasks in the task scheduling set, the corresponding number of periodic tasks can be scheduled directly according to the quantity identifier carried by the receive state tag. The quantity identifier can be the result of comparing the number of periodic tasks currently being processed by each core with the corresponding expected number. For example, if core G is currently processing 5 periodic tasks and the corresponding expected number is 6, a receive state tag representing the number of periodic tasks that can be received can be added to the core.

[0096] Specifically, scheduling periodic tasks from the task scheduling set to the central processing unit corresponding to the receiving state tag may include:

[0097] Obtain the historical tags of multiple historical moments consecutive to the current moment from the central processing unit corresponding to the received state tag;

[0098] When the historical tags of multiple historical periods corresponding to the central processing unit corresponding to the receiving state tag are all receiving state tags, the periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

[0099] Example Figure 5 This document illustrates a scheduling diagram of a periodic task processing method provided in an embodiment of the invention. Figure 5 As shown, taking a 3-core CPU as an example, at time T0, core 0 has two periodic tasks running, TASK A and TASK B, core 1 has one periodic task running, TASK D, and core 2 also has one periodic task running, TASK E. At this time, all three cores of the CPU are in an equilibrium state.

[0100] At time T1, core 0 restarted the periodic task TASK C. At this point, the load on the three CPU cores became unbalanced: core 0 had three periodic tasks, core 1 had one, and core 2 also had one. All three cores then transitioned from a balanced state to a running state. When this continued until time T3, core 0 transitioned from a running state to a broadcast state, while cores 1 and 2 transitioned from a running state to a receiving state.

[0101] According to the scheduling process described above, Core_Expect (the expected number of cores) is 2 at this point. At time T4, the periodic task TASK C running in core 0 is scheduled to continue running on core 1. At this point, TASK A and TASK B are running in core 0, TASK C and TASK D are running in core 1, and TASK E is running in core 2.

[0102] After time T4, all three cores of the CPU transition to an equilibrium state. At this point, the CPU load is balanced.

[0103] Figure 6 This document illustrates a scheduling diagram of yet another periodic task processing method provided in this embodiment, such as... Figure 6 As shown, taking a 3-core CPU as an example. At time T0, core 0 has one periodic task running, TASK A, core 1 has one periodic task running, TASK B, and core 2 has no task running. At this time, all three cores of the CPU are in an equilibrium state.

[0104] At time T1, core 1 started three more periodic tasks: TASK C, TASK D, and TASK E. At this point, the load on the three CPU cores became unbalanced: core 0 had one periodic task, core 1 had four periodic tasks, and core 2 had no tasks. All three cores then transitioned from a balanced state to a running state. When this continued until time T3, core 1 changed from a running state to a broadcast state, while cores 2 and 0 changed from a running state to a receiving state.

[0105] According to the scheduling process of the periodic tasks described above, Core_Expect (the expected number of cores) is 2 at this time. At time T4, the periodic task TASK D running in core 1 is scheduled to continue running on core 0, and TASK E is scheduled to continue running on core 2. At this point, TASK A and TASK D are running in core 0, TASK C and TASK B are running in core 1, and TASK E is running in core 2.

[0106] After time T4, all three cores of the CPU transition to an equilibrium state. At this point, the CPU load is balanced.

[0107] Figure 7 This document illustrates a scheduling diagram of another periodic task processing method provided in the embodiments herein, such as... Figure 7 As shown, taking a 3-core CPU as an example, at time T0, core 0 has a periodic task running, TASK A; core 1 has a periodic task running, TASK D; and core 2 has a task running, TASK E. At this time, all three cores of the CPU are in a balanced state.

[0108] At time T1, core 0 started three periodic tasks: TASK B, TASK C, and TASK F. Core 1 also started three periodic tasks: TASK G, TASK H, and TASK I. At this point, the load on the three CPU cores became unbalanced: core 0 had four periodic tasks, core 1 had four periodic tasks, and core 2 had one periodic task. All three cores then transitioned from a balanced state to a running state. When this continued until time T3, cores 0 and 1 changed from a running state to a broadcast state, while core 2 changed from a running state to a receiving state.

[0109] According to the scheduling process described above, Core_Expect (the expected number of cores) is 3 at this point. At time T4, the periodic task TASK F running in core 0 is scheduled to run on core 2, and the periodic task TASK I running in core 1 is also scheduled to run on core 2. The remaining tasks remain on their original cores. At this point, TASK A, TASK B, and TASK C are running in core 0, TASK H, TASK G, and TASK D are running in core 1, and TASK E, TASK I, and TASK F are running in core 2.

[0110] After time T4, all three cores of the CPU transition to an equilibrium state. At this point, the CPU load is balanced.

[0111] On the other hand, this paper provides a periodic task processing device. Figure 8A schematic diagram of the structure of a periodic task processing device in an embodiment of this paper is shown, such as... Figure 8 As shown, the device includes:

[0112] The data acquisition module 11 is used to acquire the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task;

[0113] The expected quantity determination module 12 is used to determine the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment and the execution cycle of each periodic task.

[0114] The scheduling set determination module 13 is used to add periodic tasks whose number of periodic tasks currently being processed by each central processing unit is greater than the expected number of periodic tasks to be processed by each central processing unit in the next moment to the task scheduling set.

[0115] The scheduling module 14 is used to schedule periodic tasks in the task scheduling set to a central processing unit where the number of periodic tasks being processed at the current time is less than the expected number.

[0116] Based on the above embodiments, in one embodiment of this specification, the data acquisition module is further used to acquire the number of cores of each central processing unit;

[0117] The expected quantity determination module is further configured to determine the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit.

[0118] On the other hand, this specification provides a computer-readable storage medium storing at least one instruction or at least one program, which is loaded and executed by a processor to implement the periodic task processing method described above.

[0119] Furthermore, embodiments of this specification provide an electronic device for a periodic task processing apparatus. Figure 9 This document shows a schematic diagram of the structure of an electronic device for a periodic task processing apparatus provided in an embodiment of the invention, such as... Figure 9 As shown, the device includes a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or at least one program being loaded and executed by the processor to implement the periodic task processing method as described above.

[0120] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. The testing method provided in this invention has the same implementation principle and technical effects as the aforementioned system embodiments. For the sake of brevity, any parts not mentioned in the method embodiments can be referred to the corresponding content in the aforementioned system embodiments.

[0121] It should be understood that in the various embodiments of this document, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.

[0122] It should also be understood that, in the embodiments herein, the term "and / or" is merely a description of the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following associated objects have an "or" relationship.

[0123] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.

[0124] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0125] In the embodiments provided herein, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and 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 couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, or they may be electrical, mechanical, or other forms of connection.

[0126] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments described herein, depending on actual needs.

[0127] Furthermore, the functional units in the various embodiments of this document can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0128] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this paper, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this paper. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0129] This document uses specific embodiments to illustrate the principles and implementation methods of this document. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and core ideas of this document. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this document. Therefore, the content of this specification should not be construed as a limitation of this document.

Claims

1. A method for processing periodic tasks, characterized in that, The method includes: Obtain the number of periodic tasks being processed by each central processing unit at the current moment, as well as the execution cycle of each periodic task; Based on the number of periodic tasks processed at all current moments and the execution cycle of each periodic task, the expected number of periodic tasks to be processed by each central processing unit at the next moment is determined. The expected number is: the quotient of the number of periodic tasks processed at all current moments divided by the number of central processing units, rounded up; or the ratio of the quotient of the number of periodic tasks processed at all current moments divided by the number of central processing units to the average execution cycle of each periodic task, rounded up. Periodic tasks whose number of periodic tasks currently being processed by each central processing unit is greater than the expected number of periodic tasks to be processed by each central processing unit in the next time step are added to the task scheduling set. The number of periodic tasks scheduled from the task scheduling set to be processed at the current time is less than the expected number of central processing units.

2. The periodic task processing method according to claim 1, characterized in that, When obtaining the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task, the method further includes: obtaining the number of cores of each central processing unit. The step of determining the expected number of periodic tasks to be processed by each central processing unit in the next moment, based on the total number of periodic tasks processed at all current moments and the execution cycle of each periodic task, includes: Based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit, the expected number of periodic tasks to be processed by each central processing unit at the next moment is determined. The expected number is the quotient of the total number of periodic tasks processed at the current moment divided by the total number of cores, rounded up.

3. The periodic task processing method according to claim 2, characterized in that, The step of determining the expected number of periodic tasks to be processed by each central processing unit in the next moment, based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit, includes the following: Determine the number of periodic tasks executed by each core in the least common multiple of the execution cycles of each periodic task; Determine whether the difference between the maximum and minimum number of periodic tasks executed by each core in the least common multiple period is greater than a preset task threshold. Accordingly, the expected number of periodic tasks to be processed by each central processing unit in the next moment is determined based on the number of all periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit when the difference between the maximum and minimum values ​​of the number of periodic tasks executed under the least common multiple period is greater than a preset task threshold.

4. The periodic task processing method according to any one of claims 1-3, characterized in that, The method further includes: Compare the number of periodic tasks currently being processed by each central processing unit with the corresponding expected number; Based on the comparison results, a status label is added to the central processing unit whose current number of periodic tasks is different from the corresponding expected number. The status label includes a receiving status label or a broadcast status label. The receiving status label indicates that the current number of periodic tasks is less than the corresponding expected number, and the broadcast status label indicates that the current number of periodic tasks is greater than the corresponding expected number. Accordingly, the step of scheduling the number of periodic tasks in the task scheduling set to be processed at the current time to be less than the expected number of central processing units includes: The periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

5. The periodic task processing method according to claim 4, characterized in that, The step of scheduling periodic tasks from the task scheduling set to the central processing unit corresponding to the receiving state tag includes: Obtain the historical tags of multiple historical moments consecutive to the current moment from the central processing unit corresponding to the received state tag; When the historical tags of multiple historical periods corresponding to the central processing unit corresponding to the receiving state tag are all receiving state tags, the periodic tasks in the task scheduling set are scheduled to the central processing unit corresponding to the receiving state tag.

6. The periodic task processing method according to claim 4, characterized in that, The number of periodic tasks currently being processed by each central processing unit and the execution cycle of each periodic task are obtained when the periodic tasks of one or more central processing units change.

7. A periodic task processing device, characterized in that, The device includes: The data acquisition module is used to acquire the number of periodic tasks being processed by each central processing unit at the current moment and the execution cycle of each periodic task; The expected quantity determination module is used to determine the expected number of periodic tasks to be processed by each central processing unit in the next moment based on the number of all periodic tasks processed at the current moment and the execution cycle of each periodic task. The expected quantity is: the quotient of the number of all periodic tasks processed at the current moment divided by the number of all central processing units, rounded up; or the ratio of the quotient of the number of all periodic tasks processed at the current moment divided by the number of all central processing units to the average execution cycle of each periodic task, rounded up. The scheduling set determination module is used to add periodic tasks whose number of periodic tasks currently being processed by each central processing unit is greater than the expected number of periodic tasks to be processed by each central processing unit in the next moment to the task scheduling set. The scheduling module is used to schedule periodic tasks from the task scheduling set to the central processing unit where the number of periodic tasks being processed at the current time is less than the expected number.

8. The periodic task processing device according to claim 7, characterized in that, The data acquisition module is also used to acquire the number of cores in each central processing unit; The expected quantity determination module is further configured to determine the expected quantity of periodic tasks to be processed by each central processing unit in the next moment based on the total number of periodic tasks processed at the current moment, the execution cycle of each periodic task, and the number of cores of each central processing unit. The expected quantity is: the quotient of the total number of periodic tasks processed at the current moment divided by the total number of cores, rounded down to the nearest integer.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the periodic task processing method as described in any one of claims 1-6.

10. A periodic task processing electronic device, characterized in that, The method includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements the periodic task processing method as described in any one of claims 1-6 by executing the instructions stored in the memory.

Citation Information

Patent Citations

  • Task scheduling method and device

    CN109086128A

  • Time-adaptive brevity code response assistant

    US10178516B1