CN117290068A - Task scheduling method, device, electronic equipment and storage medium - Google Patents

Task scheduling method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117290068A
CN117290068A CN202311257456.1A CN202311257456A CN117290068A CN 117290068 A CN117290068 A CN 117290068A CN 202311257456 A CN202311257456 A CN 202311257456A CN 117290068 A CN117290068 A CN 117290068A
Authority
CN
China
Prior art keywords
task
executed
time
frame
thread
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311257456.1A
Other languages
Chinese (zh)
Inventor
郑冰环
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Horizon Information Technology Co Ltd
Original Assignee
Beijing Horizon Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Horizon Information Technology Co Ltd filed Critical Beijing Horizon Information Technology Co Ltd
Priority to CN202311257456.1A priority Critical patent/CN117290068A/en
Publication of CN117290068A publication Critical patent/CN117290068A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/484Precedence
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5021Priority
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the disclosure discloses a task scheduling method, a device, electronic equipment and a storage medium, wherein the method comprises the following steps: reading a task schedule, wherein the task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, and the information of each task frame comprises trigger time of the task frame and execution time information of at least one task to be executed in the task frame; responding to the trigger time of a task frame reached at the current time, and synchronously waking up a plurality of threads corresponding to a plurality of time slot information; each thread in the plurality of threads after waking up executes at least one task to be executed based on the execution time information of the at least one task to be executed in one task frame in the corresponding time slot information. The embodiment of the disclosure realizes that each thread can respectively execute the task to be executed in the corresponding time slot information, reduces the delay from awakening to actually starting to execute the task for a plurality of threads, and can effectively improve the task scheduling efficiency and the instantaneity.

Description

Task scheduling method, device, electronic equipment and storage medium
Technical Field
The disclosure relates to the field of computer technology, and in particular, to a task scheduling method, a task scheduling device, electronic equipment and a storage medium.
Background
With the continuous development of computer technology, it has become a trend to use multiple threads to work in parallel to accomplish multiple tasks to increase the efficiency of a system.
In a scenario where multiple threads are used to work in parallel, it is desirable to wake up multiple dormant threads in a thread pool at the same time. Currently, in the Linux environment, a condition variable mode is generally used, for example, a notify_all () function of a C/c++ Condition Variable (CV) is called, and a plurality of dormant threads in a thread pool are awakened, so that a delay from awakening to actually starting to execute a task is large, which results in a time-consuming task execution.
Disclosure of Invention
In order to solve the technical problems described above, embodiments of the present disclosure provide a task scheduling method, apparatus, electronic device, and storage medium, so as to reduce a delay from waking up a plurality of threads to actually starting to execute a task.
According to an aspect of the embodiments of the present disclosure, there is provided a task scheduling method, including: reading a task schedule, wherein the task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, each task frame information comprises trigger time of the task frame and execution time information of at least one task to be executed in the task frame, and frame periods of the task frames corresponding to the plurality of time slot information are the same; synchronously waking up a plurality of threads corresponding to the time slot information in response to the fact that the current time reaches the trigger time of one task frame; each thread in the plurality of threads after awakening executes at least one task to be executed based on the execution time information of the task to be executed in the task frame in the corresponding time slot information.
According to another aspect of the embodiments of the present disclosure, there is provided a task scheduling device including: the task acquisition module is used for reading a task schedule, wherein the task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, the information of each task frame comprises trigger time of the task frame and execution time information of at least one task to be executed in the task frame, and frame periods of the task frames corresponding to the plurality of time slot information are the same; the thread awakening module is used for synchronously awakening a plurality of threads corresponding to the time slot information in response to the fact that the current moment reaches the trigger moment of one task frame; and the task scheduling module is used for executing the at least one task to be executed based on the execution time information of the at least one task to be executed in the corresponding task frame in the time slot information through each thread in the plurality of threads after awakening.
According to yet another aspect of the embodiments of the present disclosure, there is provided a computer-readable storage medium storing a computer program for executing the task scheduling method of any one of the above embodiments of the present disclosure.
According to still another aspect of an embodiment of the present disclosure, there is provided an electronic device including: a processor; a memory for storing the processor-executable instructions; the processor is configured to read the executable instructions from the memory and execute the instructions to implement the task scheduling method according to any one of the above embodiments of the present disclosure.
Based on the task scheduling method and device, the electronic device and the storage medium provided by the embodiments of the present disclosure, a plurality of time slot information with the same frame period of a task frame may be set in a task schedule, each time slot information includes information of at least one task frame, each task frame includes trigger time of the task frame and execution time information of at least one task to be executed in the task frame, when the trigger time of one task frame is reached, a plurality of threads corresponding to the plurality of time slot information in the task schedule are synchronously awakened by reading the task schedule, and each thread in the plurality of threads after being awakened may directly execute the at least one task to be executed based on the execution time information of the at least one task to be executed in the corresponding time slot information. Therefore, each thread can respectively execute the task to be executed in the corresponding time slot information, the delay from awakening to actually starting to execute the task of a plurality of threads is reduced, the task execution time consumption of each task frame is reduced, and the task scheduling efficiency and the instantaneity can be effectively improved; in addition, the execution time information of each task to be executed in each task frame is determined by reading the task schedule, and each thread executes the corresponding task to be executed based on the corresponding time slot information, so that each task to be executed can be effectively ensured to be executed at the expected time and not be influenced by other tasks, and the task scheduling efficiency and the real-time performance can be improved.
The technical scheme of the present disclosure is described in further detail below through the accompanying drawings and examples.
Drawings
FIG. 1 is an exemplary application scenario of an embodiment of the present disclosure;
FIG. 2 is a flow chart of a task scheduling method according to an exemplary embodiment of the present disclosure;
FIG. 3 is a diagram of one specific example of a task schedule in an embodiment of the present disclosure;
FIG. 4 is a flow chart of a task scheduling method provided by another exemplary embodiment of the present disclosure;
FIG. 5 is a flow chart of a task scheduling method provided by yet another exemplary embodiment of the present disclosure;
FIG. 6 is a flow chart of a task scheduling method provided by yet another exemplary embodiment of the present disclosure;
FIG. 7 is a flow chart of a task scheduling method provided by yet another exemplary embodiment of the present disclosure;
FIG. 8 is a schematic diagram of a task scheduler according to an exemplary embodiment of the present disclosure;
fig. 9 is a schematic structural view of a task scheduling device according to still another exemplary embodiment of the present disclosure;
fig. 10 is a block diagram of one embodiment of an electronic device of the present disclosure.
Detailed Description
For the purpose of illustrating the present disclosure, exemplary embodiments of the present disclosure will be described in detail below with reference to the drawings, it being apparent that the described embodiments are only some, but not all embodiments of the present disclosure, and it is to be understood that the present disclosure is not limited by the exemplary embodiments.
It should be noted that: the relative arrangement of the components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless it is specifically stated otherwise.
Summary of the application
In implementing the present disclosure, the inventors found through research that, when a plurality of dormant threads in a thread pool are simultaneously awakened by using a condition variable, for example, a mode of calling a notify_all () function of a C/c++ condition variable Condition_variable (CV), after the threads are awakened, a mutex is preempted, and only one thread can successfully preempt the lock, the thread with failed lock is blocked and queued on the mutex, and the resources of a central processing unit (Central Processing Unit, CPU) are yielded until the lock is successfully preempted, which results in a large delay from the awakening of the plurality of threads to the actual starting of executing the task, thereby resulting in a time-consuming increase of task execution.
Exemplary application
The embodiment of the disclosure can be applied to electronic equipment such as terminal equipment, computer systems, servers and the like, and can be used for scheduling tasks in various application scenes. For example, for the scheduling of periodic tasks of various applications in an automatic driving scenario, such as periodically acquiring raw data of sensors on a vehicle, determining the scheduling of tasks of states such as speed, acceleration, etc. of the vehicle based on the raw data, or scheduling of tasks such as tasks of periodically detecting health conditions of each sensor or other devices. In addition, the method can also be applied to the scheduling of periodic tasks or real-time tasks in any application scene according to actual requirements. The embodiments of the present disclosure do not limit specific application scenarios and task attributes (whether they belong to periodic tasks, real-time tasks, etc.).
Fig. 1 is an exemplary application scenario of an embodiment of the present disclosure.
In the embodiment of the disclosure, a task schedule may be arranged for each task to be executed, where the task schedule includes a plurality of time slot information, each time slot information includes information of at least one task frame, and frame periods of task frames corresponding to each time slot information are the same. The information of each task frame comprises the triggering time of each task frame and the execution time information of at least one task to be executed in each task frame.
As shown in fig. 1, when task scheduling is performed, a scheduler may be First constructed, a task schedule is read by the scheduler, the number of time slot information in the task schedule is obtained, a plurality of threads consistent with the number of the time slot information are created, a thread scheduling policy of each thread in the plurality of threads may be set as a First-in/First-out scheduling policy, abbreviated as sched_fifo, and a thread priority may be set as a priority 98, where the priority 98 is the highest available priority of threads other than a watchdog thread of an application layer, and by setting the thread priority as a priority 98, it may be ensured that each thread is not interrupted by other threads in the process of executing a task to be executed, thereby improving reliability and security of the system.
When the trigger time of each task frame is reached, a plurality of threads can be synchronously awakened, for example, a scheduler is started through a start () function, the plurality of threads are awakened, each thread in the plurality of threads after being awakened can directly execute at least one task to be executed based on the execution time information of the task to be executed in the task frame in corresponding time slot information, and the delay from awakening to actually starting to execute the task is reduced, so that the time consumption for executing the task in each task frame is reduced, and the task scheduling efficiency and instantaneity can be effectively improved.
In addition, by reading the task scheduling table, the execution time information of each task to be executed in each task frame is determined, and each thread executes the corresponding task to be executed based on the corresponding time slot information, so that each task to be executed can be effectively ensured to be executed at the expected time and not be influenced by other tasks, and the task scheduling efficiency and the real-time performance can be improved. After all tasks have been performed, the scheduler may be suspended by a stop () function, as shown in fig. 1.
Exemplary method
Fig. 2 is a flowchart of a task scheduling method according to an exemplary embodiment of the present disclosure, where the method shown in fig. 2 includes the steps of: s201 to S203. The steps are described separately below.
S201, reading a task schedule.
The task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, each task frame information comprises trigger time (trigger_time) of the task frame and execution time information of at least one task to be executed in the task frame, and frame periods of the task frames corresponding to the plurality of time slot information are the same.
In the embodiment of the present disclosure, the task to be executed may be a task with any task attribute, for example, may be a real-time task in a system, may be a periodic task, and the like, where the system may be an operating system such as Linux, or may be a plurality of embedded operating systems, and the embodiment of the present disclosure does not limit the task attribute and an applicable system.
The trigger time of the task frame is the start time of one task frame, and a task frame is entered from the start time, so that a wake-up thread is required to process the task in the task frame.
The execution time information of the task to be executed may include at least one of task start time and execution duration information of the task to be executed.
In the embodiment of the disclosure, the frame period of the task frame is used for representing the time length of each task unit into which the task to be executed is classified. The frame periods of the task frames of the time slot information are the same, namely the trigger time of each task unit of the time slot information is the same, and the time length between the trigger time of any two adjacent task frames in the time slot information is the same.
In some alternative embodiments, the task start time of the task to be performed may be set by the user. Alternatively, in other alternative embodiments, the task start time of the task to be performed may also be calculated according to the maximum execution duration WCET (word-case Execution Time) and the latest completion time point (loadlinetime) of the task to be performed. For example, if the latest completion time point of the task to be executed is T1 and WCET is T1, the task start time of the task to be executed is T1-T1. The WCET of the task to be executed characterizes the execution duration of the task to be executed in the worst case, namely, the thread can execute the task to be executed in the WCET under any condition; the loadlinetime of the task to be executed characterizes the latest execution end time point of the task to be executed.
Alternatively, in some of these embodiments, after the task schedule is constructed, the complete path of the task schedule may be passed into an execution body, e.g., a scheduler, of an embodiment of the task scheduling method of the present disclosure, which may load the task schedule according to the complete path of the task schedule, which may then be read directly.
S202, synchronously waking up a plurality of threads corresponding to a plurality of time slot information in response to the current moment reaching the trigger moment of one task frame.
The current time refers to the current time point of the clock in the system.
Alternatively, in some embodiments, when the current time reaches the trigger time of a task frame, a fast user-space lock (futex) mechanism may be used to wake up multiple threads synchronously.
S203, each thread in the plurality of threads after awakening executes at least one task to be executed based on the execution time information of the task to be executed in the at least one task frame in the corresponding time slot information.
In some embodiments, the above-mentioned one task frame refers to a task frame in which the current time reaches the trigger time, and for convenience of reference, the following embodiments of the present disclosure refer to this task frame as the current task frame.
After synchronously waking up each thread, each thread can execute each task to be executed according to the task starting time of each task to be executed in the corresponding time slot information.
According to the task scheduling method, when the trigger time of one task frame is reached, synchronous awakening of a plurality of threads corresponding to a plurality of time slot information in the task scheduling table can be achieved, each awakened thread can respectively execute tasks to be executed in the corresponding time slot information, delay from awakening to actual starting of executing of the tasks of the plurality of threads is reduced, therefore task execution time consumption of the task frames is reduced, and task scheduling efficiency and instantaneity can be effectively improved; in addition, by reading the task schedule table, the execution time information of each task to be executed in each task frame is determined, and each thread executes the corresponding task to be executed based on the corresponding time slot information, so that each task to be executed can be effectively ensured to be executed at the expected time without being influenced by other tasks, and the task scheduling efficiency and the real-time performance can be improved.
In the embodiment of the present disclosure, the task schedule may be generated in advance.
Optionally, in some embodiments, when each task to be executed is created, each task to be executed may be scheduled according to WCET and loadlinetime of each task to be executed, so as to generate a task schedule.
As shown in fig. 3, in an exemplary diagram of a task schedule in an embodiment of the present disclosure, 4 time slots are set in the task schedule illustrated in fig. 3, and a plurality of tasks to be executed are sequentially arranged in task frames of each time slot information, where each task to be executed arranged in each time slot information is responsible for being executed by a corresponding thread. The broken line indicated by reference numeral 31 in fig. 3 is used to indicate the trigger time of the task frame, and the trigger time of the task frame of each time slot information is the same. In fig. 3, each rectangular frame represents each task to be executed, the length of the rectangular frame on the horizontal axis represents the longest execution time of the corresponding task to be executed, and the length from the left side of the rectangular frame to the trigger time of the task frame represents the time offset of the task to be executed in the task frame, which can be used for representing the task start time of the task to be executed.
In some alternative embodiments, a blank time zone may also appear in each time slot information, such as the position indicated by the "blank time zone" in fig. 3, where a thread may actively enter a sleep state to yield CPU resources, where the blank time zone is used to characterize an area where a task to be performed is not scheduled.
Taking the time slot 3 as an example for illustration, four tasks to be executed (corresponding to four rectangular frames) are arranged in a task frame of the information of the time slot 3, and are respectively a task to be executed 3-1, a task to be executed 3-2, a task to be executed 3-3 and a task to be executed 3-4, and the four tasks to be executed are arranged in the time slot 3 in sequence and can be executed by the same thread in sequence.
Optionally, in order to synchronize execution of the task to be executed in the current task frame by each thread among the plurality of threads, in some embodiments, the number of threads in the plurality of threads that do not execute the task to be executed in the current task frame may be represented by a status value of a synchronization identifier (sync-count). And in response to the current time reaching the trigger time of the current task frame, setting the state value of the synchronous identifier to a first preset value.
Alternatively, the first preset value may be the number of the plurality of threads that wake up synchronously. For example, the task schedule includes 5 pieces of time slot information, the number of threads for executing tasks to be executed in the task schedule is 5, when the current time reaches the trigger time of the current task frame, the state value of the synchronization identifier may be set to 5, and when one thread executes the tasks to be executed in the current task frame, the state value of the synchronization identifier may be subtracted by 1, and when all threads execute the tasks to be executed in the current task frame, the state value of the synchronization identifier is updated to 0. In the implementation manner, the state value of the synchronization mark is consistent with the number of threads which do not execute the task to be executed in the current task frame, and the threads can intuitively determine whether the threads all execute the task to be executed in the current task frame and whether each thread is the last thread which executes the task to be executed in the current task frame.
Optionally, the first preset value may also be 0, which indicates that the number of threads to be executed in the current task frame after execution is 0. For example, the task schedule includes 5 pieces of time slot information, the number of threads for executing the task to be executed in the task schedule is 5, when the current time reaches the trigger time of the current task frame, the state value of the synchronization identifier may be set to 0, and when one thread completes the task to be executed in the current task frame, the self-increasing 1 operation may be executed on the state value of the synchronization identifier, and when all threads complete the task to be executed in the current task frame, the state value of the synchronization identifier is updated to 5. In the implementation manner, the state value of the synchronization mark is consistent with the number of threads for executing the task to be executed in the current task frame, and the threads can intuitively determine whether the threads all execute the task to be executed in the current task frame or not and whether each thread is the last thread for executing the task to be executed in the current task frame in the threads based on the state value of the synchronization mark.
In the following, an operation performed by each of a plurality of threads that wake up synchronously will be described by taking one thread (referred to as a current thread for convenience of description) as an example, and an implementation may be referred to for operations performed by other threads of the plurality of threads.
Fig. 4 is a flowchart illustrating a task scheduling method according to another exemplary embodiment of the present disclosure. As shown in fig. 4, in this embodiment, S203 may include:
s2031, acquiring task starting time of each task to be executed in the current task frame from the corresponding time slot information.
And S2032, executing each task to be executed according to the task starting time of each task to be executed.
In S2031 and S2032, since the time slot information includes execution time information of at least one task to be executed in each task frame, the execution time information of each task to be executed includes a task start time, and each thread may start executing a corresponding task to be executed at the task start time of each task to be executed after being awakened, thereby implementing orderly execution of each task to be executed.
S2033, updating the state value of the synchronous identification in an atomic operation mode in response to the completion of the execution of at least one task to be executed in the current task frame.
The atomic operation is an operation that is not interrupted by any other task or event before execution is completed. In the embodiment of the disclosure, the state value of the synchronous identifier is updated in an atomic operation mode, so that the state value of the synchronous identifier can be ensured not to be interrupted by a thread scheduling mechanism before the update is completed.
In some alternative embodiments, when multiple threads are synchronously awakened, the state value of the synchronization identifier may be set to the number of the multiple threads synchronously awakened. A decrementing operation can be performed on the state value of the synchronization flag every time a thread completes a task to be performed in the current task frame. For example, the task schedule includes 5 time slot information, the number of threads for executing the task to be executed in the task schedule is 5, when the current time reaches the trigger time of the current task frame, the state value of the synchronization identifier may be set to 5, the first thread executing the task to be executed in the current task frame performs the subtracting 1 operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 4, the second thread executing the task to be executed in the current task frame performs the subtracting 1 operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 3, and so on, after all the 5 threads execute the task to be executed in the current task frame, the state value of the synchronization identifier is updated to 0, at this time, each thread may determine that all the threads have executed the task to be executed in the current task frame.
In other alternative embodiments, the state value of the synchronization flag may be set to 0 when multiple threads are simultaneously awakened. Every time a thread completes executing a task to be executed in the current task frame, a 1-up operation may be performed on the state value of the synchronization identifier. For example, the task schedule includes 5 time slot information, the number of threads for executing the task to be executed in the task schedule is 5, when the current time reaches the trigger time of the current task frame, the state value of the synchronization identifier may be set to 0, the first thread executing the task to be executed in the current task frame may execute the increment operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 1, the second thread executing the task to be executed in the current task frame may execute the increment operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 2, and so on, after all the 5 threads execute the task to be executed in the current task frame, the state value of the synchronization identifier is updated to 5, at this time, each thread may determine that all the threads have executed the task to be executed in the current task frame.
S2034, synchronizing the updated status value of the synchronization identifier to the plurality of threads.
In some embodiments, synchronizing the updated state value of the synchronization identifier to the plurality of threads may ensure consistency of the state value of the synchronization identifier among the plurality of threads.
In some embodiments, the state value of the synchronization identifier may be set and updated by an atomic operation, and after the state value of the synchronization identifier is set and updated, the state value of the synchronization identifier sync_count may be synchronously visible to other threads by executing a memory write barrier.
Based on the embodiment of the disclosure, after each thread is awakened, each task to be executed can be orderly executed according to the task starting time of each task to be executed, which is set in the task schedule; and by adopting a synchronous identification variable, the thread number of the task to be executed of the current task frame can be intuitively determined by each thread.
Fig. 5 is a flowchart of a task scheduling method according to another exemplary embodiment of the present disclosure. As shown in fig. 5, after step S2033, on the basis of the embodiment shown in fig. 4, it may further include:
s2035, determining whether the current thread is the last thread based on whether the updated status value of the synchronization identifier is the second preset value.
The last thread is the last thread which is used for executing the task to be executed in the current task frame in the plurality of threads.
Optionally, in some embodiments, the size of the second preset value is related to the size of the first preset value and the number of the plurality of threads in the thread pool.
The current thread here is the thread that is currently updating the status value of the synchronization flag. If the state value of the synchronization mark updated by the current thread is a second preset value, determining that the current thread is the last thread for executing the task to be executed in the current task frame; if the state value of the synchronization mark updated by the current thread is not the second preset value, the current thread can be determined not to be the last thread for executing the task to be executed in the current task frame.
In different task frames, the thread of the last executed task to be executed in the task frame may not be the same. For example, in the current task frame, the thread 5 is the last thread that has executed the task to be executed in the plurality of threads, and then the thread 5 is the last thread of the current task frame; in the task frame last of the current task frame, the thread 3 is the last thread executing the task to be executed in the plurality of threads, and the thread 3 is the last thread of the task frame last of the current task frame.
In some alternative embodiments, the second preset value is 0 if the first preset value is the number of threads that wake up simultaneously. For example, the task schedule includes 5 time slot information, the number of threads for executing the task to be executed in the task schedule is 5, when the trigger time of the current task frame can be reached at present, the value of the synchronization identifier may be set to 5, and when one thread executes the task to be executed in the current task frame, the state value of the synchronization identifier may be updated to 0 (i.e., updated to a second preset value), the first thread executing the task to be executed in the current task frame executes the subtracting 1 operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 4, the second thread executing the task to be executed in the current task frame executes the subtracting 1 operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 3, and so on, when all threads execute the task to be executed in the current task frame, the state value of the synchronization identifier is updated to 0 (i.e., updated to the second preset value), which indicates that all threads execute the task to be executed in the current task frame.
In other alternative embodiments, if the first preset value is 0, the second preset value is the number of threads that wake up simultaneously. For example, the task schedule includes 5 time slot information, the number of threads for executing the task to be executed in the task schedule is 5, when the current time reaches the trigger time of the current task frame, the state value of the synchronization identifier may be set to 0, the first thread executing the task to be executed in the current task frame may perform the 1 increment operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 1, the second thread executing the task to be executed in the current task frame may perform the 1 increment operation on the state value of the synchronization identifier, the obtained state value of the synchronization identifier is 2, and so on, after all the 5 threads execute the task to be executed in the current task frame, the state value of the synchronization identifier is updated to 5 (i.e., updated to the second preset value), at this time, each thread may determine that all the threads have executed the task to be executed in the current task frame.
In this implementation manner, by determining whether the updated state value of the synchronization identifier is the second preset value, it can be intuitively determined whether the thread currently updated to the state value of the synchronization identifier is the last thread to execute the task to be executed in the current task frame in the multiple threads.
Optionally, in a further embodiment, in response to the current thread not being the last thread to complete the task to be performed in the current task frame, step S2306 may be performed; step S2307 may be performed in response to the current thread being the last thread to complete the task to be performed in the current task frame.
S2306, the current thread is scheduled to enter a sleep state.
In some of these embodiments, if the current thread is not the last thread, indicating that there are other threads that have not performed tasks to be performed in the current task frame, the current thread may be scheduled to enter a sleep state.
When the current thread is not the last thread which executes the task to be executed in the current task frame, the current thread is scheduled to actively enter the sleep state when the user task is not executed, so that CPU resources can be released, and resource waste is avoided.
S2307, it is determined whether the current time reaches the trigger time of the next task frame to the current task frame.
The next task frame to the current task frame is a task frame that is located after the current task frame in time sequence and is adjacent to the current task frame.
In some embodiments, if the current thread is the last thread to complete the task to be performed in the current task frame, it may be further determined whether the current time reaches the trigger time of the next task frame. For example, after the last thread executes each task to be executed in the current task frame, the moment of updating the state value of the synchronization mark is T2, the trigger moment of the next task frame of the current task frame is T3, and if the T3 moment is later than the T2 moment, the trigger moment of the next task frame is not reached at the current moment; and if the time T3 is not later than the time T2, indicating that the current time reaches the trigger time of the next task frame.
Optionally, in a further embodiment, step S2308 may be performed in response to the current time reaching the trigger time of the next task frame; step S2309 may be performed in response to the current time not reaching the trigger time of the next task frame.
S2308, waking up other threads in the plurality of threads through the last thread.
In some of these embodiments, if the current time reaches the trigger time of the next task frame, the last thread may wake up other threads of the plurality of threads through logic of the Start () function. Therefore, the thread which is executed with the task to be executed in each task frame in the current task frame can carry out dormancy and wake-up control on the threads at the trigger time of the next task frame, and therefore the cutting-in and cutting-out of other threads on the CPU caused by using other threads except the threads to carry out dormancy and wake-up control operation on the threads can be avoided, and the time delay from wake-up to actual operation of the threads can be reduced.
In some embodiments, the last thread that has executed the task to be executed in the current task frame may wake each thread of the plurality of threads based on the futex operating mechanism.
S2309, determining the third sleep time of the last thread according to the current time and the trigger time of the next task frame of the current task frame.
The third sleep duration refers to the time length that the last thread can sleep, and since the current time does not reach the trigger time of the next task frame of the current task frame, the last thread can sleep the third sleep duration.
In some alternative embodiments, the third sleep duration may be obtained by calculating a time difference between a trigger time of a next task frame to the current task frame and the current time. For example, when the current time is Tn and the trigger time of the next task frame of the current task frame is T3, the time difference between the trigger time of the next task frame of the current task frame and the current time is (T3-Tn), and the third sleep duration is (T3-Tn).
S2310, the last thread is scheduled to enter a sleep state.
After determining that the current thread is the last thread to execute the task to be executed in the current task frame, the method can further determine whether the current time reaches the trigger time of the next task frame, and schedule the last thread to enter the sleep state when the current time does not reach the trigger time of the next task frame, so that CPU resources can be released, and resource waste is avoided.
According to the embodiment of the disclosure, by adopting the synchronous identification variable, whether each thread is the last thread which performs the task to be performed in the current task frame in a plurality of threads or not can be intuitively determined, after the last thread is determined, the last thread performs the wake-up operation of the thread in the next task frame, the cut-in and cut-out on the CPU when the wake-up operation is performed by other threads can be avoided, a deterministic execution environment is created, the time delay from wake-up to actual operation of the threads is further reduced, and the execution period of each task to be performed is more stable.
Optionally, in some embodiments, after the last thread is scheduled to enter the sleep state, when the system indication time point reaches the trigger time of the next task frame, a plurality of threads corresponding to a plurality of time slot information in the task schedule may be synchronously awakened. In specific implementation, the last thread can be awakened after the duration of the sleep state of the last thread reaches the third sleep duration; after the last thread is awakened, other threads in the plurality of threads are awakened.
In a specific implementation, the sleep duration of the last thread may be counted by a timer after the last thread enters the sleep state, and the last thread is awakened after the sleep duration of the last thread reaches the third sleep duration.
Optionally, in some embodiments, when the duration of the sleep state of the last thread reaches the third sleep duration, and when the time point indicated by the system reaches the trigger time of the next task frame, the last thread may set the state value of the synchronization identifier to the first preset value through an atomic operation manner, and after setting the state value of the synchronization identifier, the state value of the synchronization identifier sync_count may be synchronously visible to other threads through a memory write barrier, and then wake up other threads in the multiple threads through a futex mechanism.
The memory write barrier is a synchronization barrier type instruction, which can indicate a synchronization point in the operation of random access to the memory, and in the embodiment of the present disclosure, the state value of the synchronization identifier can be ensured to be written into the memory before the synchronization point through the memory write barrier.
Fig. 6 is a flowchart illustrating a task scheduling method according to another exemplary embodiment of the present disclosure. As shown in fig. 6, in this embodiment, step S2032 may include:
s20321, determining whether the current time reaches the task start time of each task to be executed according to the task start time of each task to be executed.
In some embodiments, the time slot information includes execution time information of each task to be executed in each task frame, the execution time information of each task to be executed includes a task start time, and after each thread is awakened, whether the current time of the system reaches the task start time of each task to be executed can be compared. Step S20322 may be executed if the current time reaches the task start time of each task to be executed, and step S20323 may be executed if the current time does not reach the task start time of each task to be executed.
For example, assuming that the current time is denoted as Tn, in the current task frame, the tasks to be executed that are not executed by the current thread further have three task start times corresponding to R1, R2, R3, R1, R2, and R3, respectively, where T1 is earlier than T2, T2 is earlier than T3, and if Tn is earlier than T1, the current time has not yet reached the task start time of each task to be executed; if Tn is not earlier than T1, the current time reaches the task starting time of the task to be executed.
S20322, the next task to be executed is executed.
The next task to be executed is the task to be executed, which is not executed in at least one task to be executed and the starting time of the task reaches first.
For example, the current time is Tn, the tasks to be executed which are not executed by the thread 1 in the current task frame further include three tasks R1, R2, and R3, wherein the task starting times corresponding to R1, R2, and R3 are respectively T1, T2, and T3, and T1 is earlier than T2, and T2 is earlier than T3, and for the thread 1, the next task to be executed is R1.
After each thread completes one task to be executed in the current task frame, according to whether the system indication time point reaches the task starting time of the task to be executed, and when the task starting time of the task to be executed is reached, executing the task to be executed which is not executed in each task to be executed and is reached first at the task starting time, so that the orderly execution of each task to be executed can be realized.
S20323, determining a first sleep duration of the current thread according to the current time and the task starting time of the next task to be executed.
The first sleep duration refers to a time length that a current thread can sleep, and since the current time does not reach a task start time of a next task to be executed, the current thread can sleep first.
In some alternative embodiments, the first sleep duration may be obtained by calculating a time difference between a task start time and a current time of a next task to be performed. For example, when the current time is Tn and the task start time of the next task to be executed is T1, the time difference between the task start time of the next task to be executed and the current time is (T1-Tn), and the first sleep duration is (T1-Tn).
S20324, the current thread is scheduled to enter a sleep state, and is awakened after the duration of the sleep state reaches the first sleep duration, and the next task to be executed is executed after the current thread is awakened.
Optionally, in some embodiments, after the current thread is scheduled to enter the sleep state, the current thread may be awakened when the system indication time point reaches the task start time of the next task to be executed; after the current thread is awakened, the next task to be executed can be executed.
In a specific implementation, the current thread may be started to enter a sleep state, and the sleep time of the current thread is counted by a timer, and after the sleep time of the current thread reaches the first sleep time, the current thread is awakened.
Based on the embodiment of the disclosure, after each thread completes one task to be executed in the current task frame, if the system indicates that the time point does not reach the task starting time of the next task to be executed, the first sleep duration can be actively dormant first, the CPU resource is released, and the resource waste is avoided; when the system indication time point reaches the task starting time of the next task to be executed, the thread can be awakened and the next task to be executed, so that the next task to be executed is ensured to be executed at the expected time.
In some alternative embodiments, after the next task to be executed, it may be further determined whether the execution time of the next task to be executed exceeds the execution duration information of the next task to be executed, and if the execution time of the next task to be executed exceeds the execution duration information of the next task to be executed, a timeout report (TimeoutHook) message may be uploaded, thereby indicating that a timeout exists in the execution of the task to be executed to the user.
Fig. 7 is a flowchart illustrating a task scheduling method according to still another exemplary embodiment of the present disclosure. As shown in fig. 7, after step S20322 and step S20324, on the basis of the embodiment shown in fig. 6, it may further include:
S20325, determining whether the next task to be executed is the last task to be executed in the one task frame (i.e., the current task frame).
The last task to be executed is the last task of at least one task to be executed in the current task frame of the current thread.
In some embodiments, since at least one task to be executed is sequentially arranged in each time slot information in the task schedule, after the current thread completes executing the next task to be executed, it may be determined whether there are any non-executed tasks to be executed in the current task frame by reading the corresponding time slot information in the task schedule.
Optionally, in a further embodiment, if the next task to be executed by the current thread is the last task to be executed in the current task frame, step S20326 may be executed; if the next task to be executed that runs out is not the last task to be executed in the current task frame, step S20327 may be executed.
S20326, determining that at least one task to be executed in the time slot information corresponding to the current thread has been executed.
In some of these embodiments, if the next task to be executed by the current thread is the last task to be executed in the current task frame, it may be determined that the current thread has executed at least one task to be executed in the current task frame.
Further, in some embodiments, after the current thread performs at least one task to be performed in the current task frame, step S2033 in the embodiment shown in fig. 4 may be performed, where the status value of the synchronization identifier is updated through an atomic operation manner.
S20327, it is determined whether the execution completion time of the next task to be executed reaches the task start time of the next task to be executed.
The next task to be executed is a task to be executed which is located after the next task to be executed in time sequence in the current task frame and is adjacent to the next task to be executed.
In some embodiments, the time slot information includes execution time information of each task to be executed in each task frame, where the execution time information of each task to be executed includes a task start time, and after the next task to be executed is executed, the execution completion time of the next task to be executed may be compared with the task start time of the next task to be executed. If the execution completion time reaches the task start time of the next task to be executed, step S20328 may be executed; if the execution completion time does not reach the task start time of the next task to be executed next, step S20329 may be executed.
S20328, a next task to be executed is executed.
S20329, determining a second sleep time length of the current thread according to the execution completion time of the next task to be executed and the task start time of the next task to be executed, scheduling the current thread to enter a sleep state, and waking up the current thread after the time length of the sleep state reaches the second sleep time length.
The second sleep duration refers to the length of time that the current thread can sleep after the current thread completes the task to be executed next. The current thread may sleep for a second sleep duration because the execution completion time of the next task to be executed has not reached the task start time of the next task to be executed.
In some alternative embodiments, the second sleep duration may be obtained by calculating a time difference between a task start time of a next task to be executed and an execution completion time of the next task to be executed of the current task frame. For example, when the execution completion time of the next task to be executed is T1 and the task start time of the next task to be executed is T2, the second sleep time is (T2-T1).
In a specific implementation, the sleep duration of the current thread may be counted by a timer after the current thread enters the sleep state, and the current thread is awakened after the sleep duration of the current thread reaches the second sleep duration. After the current thread wakes up, the next task to be executed can be executed.
Based on the embodiment of the disclosure, after each thread completes execution of the next task, whether the executed next task is the last task to be executed in the current task frame or not can be determined, when the executed next task is not the last task to be executed, whether the execution completion time of the next task reaches the task starting time of the adjacent next task to be executed or not is further determined, when the execution completion time of the next task reaches the task starting time of the adjacent next task to be executed or not, the adjacent next task is directly executed without dormancy, when the execution completion time of the next task does not reach the task starting time of the adjacent next task to be executed, the sleep state is actively entered, CPU resources are yielded, resource waste is avoided, and when the system indicates that the time point reaches the task starting time of the adjacent next task to be executed, the current thread can be awakened, and the adjacent next task to be executed in expected time is ensured.
Exemplary apparatus
Fig. 8 is a schematic structural diagram of a task scheduling device according to an exemplary embodiment of the present disclosure. The apparatus of this embodiment may be used to implement a corresponding task scheduling method embodiment of the present disclosure, where the apparatus shown in fig. 8 includes: a task acquisition module 81, a thread wake module 82 and a task scheduling module 83.
The task obtaining module 81 is configured to read a task schedule, where the task schedule includes a plurality of time slot information, each time slot information includes information of at least one task frame, and each task frame includes trigger time of a task frame and execution time information of at least one task to be executed in the task frame, and frame periods of task frames corresponding to the plurality of time slot information are the same.
The thread wake-up module 82 is configured to wake up a plurality of threads corresponding to the plurality of time slot information synchronously in response to the current time reaching a trigger time of one task frame.
The task scheduling module 83 is configured to execute at least one task to be executed by each thread in the plurality of threads after waking up, based on execution time information of the at least one task to be executed in one task frame in the corresponding time slot information, respectively.
Fig. 9 is a schematic structural diagram of a task scheduling device according to another exemplary embodiment of the present disclosure. As shown in fig. 9, in some embodiments, the execution time information of each task to be executed may include: the task start time of the task to be executed.
Accordingly, in this embodiment, the task scheduling module 83 includes:
a first obtaining sub-module 831, configured to obtain, from the corresponding time slot information, a task start time of each task to be executed in the one task frame;
The first execution sub-module 832 is configured to execute each task to be executed according to a task start time of each task to be executed;
a state updating sub-module 833, configured to update, in response to completion of execution of at least one task to be executed in the one task frame, a state value of a synchronization identifier in an atomic operation manner, where the state value of the synchronization identifier is used to indicate a number of threads in the plurality of threads that do not complete the task to be executed in the one task frame;
a first synchronization sub-module 834 for synchronizing the updated state value of the synchronization identifier to a plurality of threads.
In some of these embodiments, the task scheduling device may further include:
the state initialization module 84 is configured to set a state value of the synchronization identifier to a first preset value in response to the current time reaching the trigger time of the one task frame.
In some embodiments, the first execution sub-module 832 is specifically configured to determine, according to task start times of each task to be executed, whether the current time reaches the task start time of each task to be executed; and executing the next task to be executed in response to the current moment reaching the task starting moment of the next task to be executed in the at least one task to be executed, wherein the next task to be executed is the task to be executed which is not executed in the at least one task to be executed and reaches the task starting moment first.
The first execution sub-module 832 is further configured to determine, according to the current time and the task start time of the next task to be executed, a first sleep duration of the current thread in response to the current time not reaching the task start time of each task to be executed; and scheduling the current thread to enter a sleep state, waking up the current thread after the duration of the sleep state reaches the first sleep duration, and executing the next task to be executed after the current thread is woken up.
In some of these embodiments, the task scheduling module 83 further includes:
a first determining sub-module 835 for determining whether the next task to be executed is the last task to be executed in the above task frame;
a second determining sub-module 836, configured to determine that at least one task to be executed is completed in response to the next task to be executed being the last task to be executed in the one task frame;
the first execution sub-module 832 is further configured to determine, in response to the next task not being the last task to be executed in the one task frame, whether an execution completion time of the next task to be executed reaches a task start time of an adjacent next task to be executed, where the adjacent next task to be executed is a task to be executed that is located after the next task to be executed in the one task frame in a time sequence and is adjacent to the next task to be executed.
The first execution sub-module 832 is further configured to execute the next task to be executed in response to the execution completion time of the next task to be executed reaching the task start time of the next task to be executed;
the first execution submodule 832 is further configured to determine a second sleep duration of the current thread according to the execution completion time of the next task to be executed and the task start time of the next task to be executed, schedule the current thread to enter a sleep state, and wake up the current thread after the duration of the sleep state reaches the second sleep duration, in response to the execution completion time of the next task to be executed not reaching the task start time of the next task to be executed.
In some of these embodiments, the execution time information of the task to be executed further includes: executing time length information of a task to be executed;
the task scheduling module 83 further includes:
the timeout report submodule 837 is configured to upload timeout report information in response to the execution time of the next task to be executed exceeding the execution time length information of the next task to be executed.
In some of these embodiments, the task scheduling device further includes:
the thread determining module 85 is configured to determine, based on whether the updated status value of the synchronization identifier is a second preset value, whether the current thread is a last thread, where the last thread is a thread that performs the task to be performed in the task frame last among the plurality of threads.
In some of these embodiments, the task scheduling device further includes:
the thread sleep module 86 is configured to schedule the current thread to enter a sleep state in response to the current thread not being the last thread.
In some of these embodiments, the task scheduling device further includes:
a first determining module 87, configured to determine, in response to the current thread being the last thread, whether the current time reaches a trigger time of a next task frame, where the next task frame is a task frame that is located after the one task frame in a time sequence and is adjacent to the one task frame;
a second determining module 88, configured to determine, according to the current time and the trigger time of the next task frame, a third sleep duration of the last thread in response to the current time not reaching the trigger time of the next task frame;
a thread sleep module 86 for scheduling the last thread to enter a sleep state;
a thread wake-up module 82, configured to wake up the last thread after the duration of the sleep state of the last thread reaches the third sleep duration; after the last thread is awakened, other threads in the plurality of threads are awakened.
The thread wake module 82 is configured to wake up other threads in the plurality of threads by the last thread in response to the current time reaching the trigger time of the next task frame.
The task scheduling device in the embodiment of the present disclosure corresponds to the embodiment of the task scheduling method in the present disclosure, and the related contents may be referred to each other, which is not described herein again. The corresponding beneficial technical effects of the task scheduling device in the embodiment of the present disclosure may refer to the corresponding beneficial technical effects of the above-mentioned exemplary task scheduling method section, and are not described herein again.
Exemplary electronic device
As shown in fig. 10, the electronic device includes one or more processors 11 and a memory 12. The processor 11 may be a Central Processing Unit (CPU) or other form of processing unit having data processing and/or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
Memory 12 may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. The volatile memory may include, for example, random Access Memory (RAM) and/or cache memory (cache), and the like. The non-volatile memory may include, for example, read Only Memory (ROM), hard disk, flash memory, and the like. One or more computer program instructions may be stored on the computer readable storage medium that can be executed by the processor 11 to implement the task scheduling methods and/or other desired functions of the various embodiments of the present disclosure described above. Various contents such as an input signal, a signal component, a noise component, and the like may also be stored in the computer-readable storage medium.
In one example, the electronic device may further include: an input device 13 and an output device 14, which are interconnected by a bus system and/or other forms of connection mechanisms (not shown). For example, the input device 1003 may be a microphone or microphone array for capturing input signals of a sound source, or a communication network connector for receiving collected input signals, and may include, for example, a keyboard, a mouse, and the like.
The output device 14 may output various information to the outside, including the determined distance information, direction information, and the like. The output device 14 may include, for example, a display, speakers, a printer, and a communication network and remote output devices connected thereto, etc.
Of course, only some of the components of the electronic device relevant to the present disclosure are shown in fig. 10 for simplicity, components such as buses, input/output interfaces, and the like being omitted. In addition, the electronic device may include any other suitable components depending on the particular application.
Exemplary computer program product and computer readable storage Medium
In addition to the methods and apparatus described above, embodiments of the present disclosure may also be a computer program product comprising computer program instructions which, when executed by a processor, cause the processor to perform steps in a task scheduling method according to various embodiments of the present disclosure described in the "exemplary methods" section of the present description.
The computer program product may write program code for performing the operations of embodiments of the present disclosure in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server.
Furthermore, embodiments of the present disclosure may also be a computer-readable storage medium, having stored thereon computer program instructions, which when executed by a processor, cause the processor to perform steps in a task scheduling method according to various embodiments of the present disclosure described in the above "exemplary method" section of the present disclosure.
The computer readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may include, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The basic principles of the present disclosure have been described above in connection with specific embodiments, however, it should be noted that the advantages, benefits, effects, etc. mentioned in the present disclosure are merely examples and not limiting, and these advantages, benefits, effects, etc. are not to be considered as necessarily possessed by the various embodiments of the present disclosure. Furthermore, the specific details disclosed herein are for purposes of illustration and understanding only, and are not intended to be limiting, since the disclosure is not necessarily limited to practice with the specific details described.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different manner from other embodiments, so that the same or similar parts between the embodiments are mutually referred to. For system embodiments, the description is relatively simple as it essentially corresponds to method embodiments, and reference should be made to the description of method embodiments for relevant points.
The block diagrams of the devices, apparatuses, devices, systems referred to in this disclosure are merely illustrative examples and are not intended to require or imply that the connections, arrangements, configurations must be made in the manner shown in the block diagrams. As will be appreciated by one of skill in the art, the devices, apparatuses, devices, systems may be connected, arranged, configured in any manner. Words such as "including," "comprising," "having," and the like are words of openness and mean "including but not limited to," and are used interchangeably therewith. The terms "or" and "as used herein refer to and are used interchangeably with the term" and/or "unless the context clearly indicates otherwise. The term "such as" as used herein refers to, and is used interchangeably with, the phrase "such as, but not limited to.
The methods and apparatus of the present disclosure may be implemented in a number of ways. For example, the methods and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, firmware. The above-described sequence of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the sequence specifically described above unless specifically stated otherwise. Furthermore, in some embodiments, the present disclosure may also be implemented as programs recorded in a recording medium, the programs including machine-readable instructions for implementing the methods according to the present disclosure. Thus, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
It is also noted that in the apparatus, devices and methods of the present disclosure, components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered equivalent to the present disclosure.
The previous description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects without departing from the scope of the disclosure. Thus, the present disclosure is not intended to be limited to the aspects shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing description has been presented for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of the disclosure to the form disclosed herein. Although a number of example aspects and embodiments have been discussed above, a person of ordinary skill in the art will recognize certain variations, modifications, alterations, additions, and subcombinations thereof.

Claims (14)

1. A task scheduling method, comprising:
reading a task schedule, wherein the task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, each task frame information comprises trigger time of the task frame and execution time information of at least one task to be executed in the task frame, and frame periods of the task frames corresponding to the plurality of time slot information are the same;
synchronously waking up a plurality of threads corresponding to the time slot information in response to the fact that the current time reaches the trigger time of one task frame;
each thread in the plurality of threads after awakening executes at least one task to be executed based on the execution time information of the task to be executed in the task frame in the corresponding time slot information.
2. The method of claim 1, wherein the execution time information of the task to be executed comprises: the task starting time of the task to be executed;
The executing the at least one task to be executed based on the execution time information of the at least one task to be executed in the corresponding time slot information, respectively, includes:
acquiring task starting time of each task to be executed in the task frame from the corresponding time slot information;
executing each task to be executed according to the task starting time of each task to be executed;
in response to completion of execution of at least one task to be executed in the task frame, updating a state value of a synchronization identifier in an atomic operation mode, wherein the state value of the synchronization identifier is used for indicating the number of threads which do not complete execution of the task to be executed in the task frame in the plurality of threads;
synchronizing the updated state value of the synchronization identifier to the plurality of threads.
3. The method according to any one of claims 1-2, further comprising, before the synchronously waking up the plurality of threads corresponding to the plurality of time slot information:
and setting the state value of the synchronous mark as a first preset value in response to the current moment reaching the triggering moment of one task frame.
4. A method according to any one of claims 2-3, wherein said executing each of said tasks to be executed according to a task start time of each of said tasks to be executed, respectively, comprises:
Determining whether the current time reaches the task starting time of each task to be executed according to the task starting time of each task to be executed;
and executing the next task to be executed in response to the current moment reaching the task starting moment of the next task to be executed in the at least one task to be executed, wherein the next task to be executed is the task to be executed which is not executed in the at least one task to be executed and reaches the task starting moment first.
5. The method of claim 4, wherein the executing each task to be executed according to a task start time of each task to be executed, respectively, further comprises:
determining a first sleep time of a current thread according to the current time and the task starting time of the next task to be executed in response to the current time not reaching the task starting time of each task to be executed;
and scheduling the current thread to enter a sleep state, waking up the current thread after the duration of the sleep state reaches the first sleep duration, and executing the next task to be executed after the current thread is woken up.
6. The method according to any one of claims 4-5, further comprising, after said executing said next task to be executed:
Determining whether the next task to be executed is the last task to be executed in the task frame;
determining that the at least one task to be executed is completed in response to the next task to be executed being the last task to be executed in the one task frame;
determining whether the execution completion time of the next task to be executed reaches the task start time of an adjacent next task to be executed in response to the next task to be executed not being the last task to be executed in the one task frame, wherein the adjacent next task to be executed is a task to be executed which is located behind the next task to be executed in time sequence in the one task frame and is adjacent to the next task to be executed;
executing the adjacent next task to be executed in response to the execution completion time of the next task to be executed reaching the task start time of the adjacent next task to be executed;
determining a second sleep duration of the current thread according to the execution completion time of the next task to be executed and the task start time of the next task to be executed in response to the execution completion time of the next task not reaching the task start time of the next task to be executed; and scheduling the current thread to enter a sleep state, and waking up the current thread after the duration of the sleep state reaches the second sleep duration.
7. The method according to any one of claims 4-6, wherein the execution time information of the task to be executed further includes: the execution duration information of the task to be executed;
after the next task to be executed is executed, the method further comprises the following steps:
and uploading timeout report information in response to the execution time of the next task to be executed exceeding the execution time length information of the next task to be executed.
8. The method according to any one of claims 2-7, further comprising, after updating the status value of the synchronization identifier by an atomic operation manner:
and determining whether the current thread is the last thread based on whether the updated state value of the synchronous identifier is a second preset value, wherein the last thread is the thread which is the last thread to finish executing the task to be executed in the task frame in the plurality of threads.
9. The method of claim 8, further comprising:
and in response to the current thread not being the last thread, scheduling the current thread to enter a sleep state.
10. The method of any of claims 8-9, further comprising:
determining whether the current time reaches the trigger time of a next task frame or not in response to the current thread being the last thread, wherein the next task frame is a task frame which is positioned behind the one task frame in time sequence and is adjacent to the one task frame;
Determining a third sleep time length of the last thread according to the current time and the trigger time of the next task frame in response to the current time not reaching the trigger time of the next task frame;
scheduling the last thread to enter a dormant state;
and the step of synchronously waking up a plurality of threads corresponding to the plurality of time slot information in response to the current time reaching the trigger time of one task frame comprises the following steps:
waking up the last thread after the duration of the sleep state of the last thread reaches the third sleep duration;
and after the last thread is awakened, awakening other threads in the plurality of threads.
11. The method of claim 10, wherein the synchronously waking up a plurality of threads corresponding to the plurality of time slot information in response to the current time reaching a trigger time of one task frame comprises:
and waking up other threads in the plurality of threads through the last thread in response to the current time reaching a trigger time of the next task frame.
12. A task scheduling device, comprising:
the task acquisition module is used for reading a task schedule, wherein the task schedule comprises a plurality of time slot information, each time slot information comprises information of at least one task frame, the information of each task frame comprises trigger time of the task frame and execution time information of at least one task to be executed in the task frame, and frame periods of the task frames corresponding to the plurality of time slot information are the same;
The thread awakening module is used for synchronously awakening a plurality of threads corresponding to the time slot information in response to the fact that the current moment reaches the trigger moment of one task frame;
and the task scheduling module is used for executing the at least one task to be executed based on the execution time information of the at least one task to be executed in the corresponding task frame in the time slot information through each thread in the plurality of threads after awakening.
13. A computer readable storage medium storing a computer program for executing the task scheduling method of any one of claims 1 to 11.
14. An electronic device, the electronic device comprising:
a processor;
a memory for storing the processor-executable instructions;
the processor is configured to read the executable instructions from the memory and execute the instructions to implement the task scheduling method of any one of claims 1-11.
CN202311257456.1A 2023-09-26 2023-09-26 Task scheduling method, device, electronic equipment and storage medium Pending CN117290068A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311257456.1A CN117290068A (en) 2023-09-26 2023-09-26 Task scheduling method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311257456.1A CN117290068A (en) 2023-09-26 2023-09-26 Task scheduling method, device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117290068A true CN117290068A (en) 2023-12-26

Family

ID=89251416

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311257456.1A Pending CN117290068A (en) 2023-09-26 2023-09-26 Task scheduling method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117290068A (en)

Similar Documents

Publication Publication Date Title
JP6125539B2 (en) Dynamic power management in real-time systems
US9823946B2 (en) Processor and program execution method capable of efficient program execution
CN107491346B (en) Application task processing method, device and system
CN108319495B (en) Task processing method and device
CN111813552B (en) Scheduling execution method, device and medium based on multi-thread task
US7043729B2 (en) Reducing interrupt latency while polling
US9785587B2 (en) Method for executing, within a multitasking onboard system, an application timed according to a plurality of different time domains including interruption management
CN105573825B (en) Method and device for inter-task synchronization of cross-operating system
US8132171B2 (en) Method of controlling thread access to a synchronization object
CN112199170A (en) Timing processing method, device and equipment of real-time operating system and storage medium
US20160302255A1 (en) Sensor data collecting device
JP2007164421A (en) Parallel processors, parallel processing method and parallel processing program
CN117290068A (en) Task scheduling method, device, electronic equipment and storage medium
Levis et al. Schedulers and tasks
CN116089049A (en) Asynchronous parallel I/O request-based process synchronous scheduling method, device and equipment
JP2000207174A (en) Electronic control unit
EP1088269A2 (en) Object-oriented system having anonymous scheduler design pattern
CN111611029B (en) IEC61499 function block modeling method for determining calculation time sequence
CN114416322A (en) Task scheduling method and device based on double linked lists, electronic equipment and storage medium
US9465655B2 (en) Method for managing threads using executing time scheduling technique and electronic device using the same method
CN112540886A (en) CPU load value detection method and device
KR20150130631A (en) Partition control apparatus and method of operating system
CN114185666A (en) Scheduling management method for periodic scheduling thread in time-sharing system
JP2010165209A (en) Multi-thread processor system
CN117270630A (en) System-on-chip and timestamp capturing method, device and storage medium thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination