CN117112160A - Timing task scheduling method, device, equipment and medium - Google Patents
Timing task scheduling method, device, equipment and medium Download PDFInfo
- Publication number
- CN117112160A CN117112160A CN202310952920.2A CN202310952920A CN117112160A CN 117112160 A CN117112160 A CN 117112160A CN 202310952920 A CN202310952920 A CN 202310952920A CN 117112160 A CN117112160 A CN 117112160A
- Authority
- CN
- China
- Prior art keywords
- current
- time
- timing task
- ready queue
- local time
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 46
- 238000004590 computer program Methods 0.000 claims description 23
- 238000003780 insertion Methods 0.000 claims description 19
- 230000037431 insertion Effects 0.000 claims description 19
- 230000001121 heart beat frequency Effects 0.000 claims description 12
- 230000006870 function Effects 0.000 claims description 8
- 238000001514 detection method Methods 0.000 description 17
- 238000010586 diagram Methods 0.000 description 12
- 238000004891 communication Methods 0.000 description 5
- 230000009286 beneficial effect Effects 0.000 description 3
- 230000002159 abnormal effect Effects 0.000 description 2
- 238000013473 artificial intelligence Methods 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 2
- 230000009191 jumping Effects 0.000 description 2
- 235000008694 Humulus lupulus Nutrition 0.000 description 1
- 238000009825 accumulation Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000003247 decreasing effect Effects 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000009877 rendering Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
- G06F9/4887—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues involving deadlines, e.g. rate based, periodic
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The application discloses a timing task scheduling method, a device, equipment and a medium, belonging to the technical field of multitasking, which are applied to a current-level working thread and comprise the following steps: acquiring the current global time and the current local time of the next-stage working thread, and determining the current time interval of the current global time and the current local time; if the current time interval is not greater than the preset threshold value, judging whether the current global time and the current local time are equal; if the current global time is equal to the current local time after the current next-level working thread is updated, the current global time after the current update and the current local time after the current next-level working thread are acquired, and the step of re-jumping to the current time interval for determining the current global time and the current local time is carried out; if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal. The reliability of the scheduled timing tasks is improved.
Description
Technical Field
The present application relates to the field of multitasking, and in particular, to a method, apparatus, device, and medium for scheduling timed tasks.
Background
Scheduled execution of timed tasks is an important ring in a storage system. By timing tasks, special tasks can be conveniently completed. The scheduling of the timing tasks comprises modules of timing task storage, task triggering, task processing, time setting and the like. Based on the precision and stability requirements of the storage system, the safety of tasks and the timeliness of task processing are required to be ensured, so that the detection of a working thread for executing a timing task is required to be carried out, and abnormal conditions are required to be processed in time so as to ensure the timing task scheduling.
In summary, how to improve the reliability of the scheduled timing tasks is a problem to be solved in the art.
Disclosure of Invention
In view of the above, the present application aims to provide a method, an apparatus, a device and a medium for scheduling timed tasks, which improve the reliability of the scheduled timed tasks. The specific scheme is as follows:
in a first aspect, the present application discloses a method for scheduling a timing task, which is applied to a current level working thread, and includes:
acquiring current global time and current local time of a next-level working thread, and determining current time intervals of the current global time and the current local time;
If the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal;
if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time;
if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
Optionally, after the determining the current time interval of the current global time and the current local time, the method further includes:
and if the current time interval is greater than a preset threshold, sending an alarm instruction to a preset display platform so that a user can stop executing all the working threads based on the alarm instruction displayed by the preset display platform.
Optionally, the updating the current local time includes:
And increasing the current local time by a preset unit time step length to update the current local time.
Optionally, the next-level working thread performs a corresponding timing task based on the current local time, including:
the next-stage working thread judges whether a local current first ready queue is empty, if not, the current heartbeat times of the timing tasks in the current first ready queue are updated based on the current local time so as to obtain the current updated heartbeat times of the timing tasks;
if the timing task with the current updated heartbeat times of zero exists in the current first ready queue, executing the timing task; and if the current updated heartbeat times of the timing task do not exist, updating again.
Optionally, if the timing task with the current updated heartbeat frequency being zero exists in the current first ready queue, executing the timing task; if not, updating the current updated heartbeat times of the timing task again, wherein the updating comprises the following steps:
when the data structure of the current first ready queue is a linked list structure, judging whether the current heartbeat times of the first timing task in the current first ready queue are zero or not;
If not, updating the current updated heartbeat times of all the timing tasks in the current first ready queue again;
if yes, executing the first timing task in the current first ready queue, updating the current first ready queue to obtain a next first ready queue, taking the next first ready queue as the current first ready queue, and then re-jumping to the step of judging whether the current updated heartbeat frequency of the first timing task in the current first ready queue is zero.
Optionally, the executing the first timing task in the current first ready queue includes:
determining the first timing task in the current first ready queue as a target timing task, and taking down the target timing task from the current first ready queue;
and executing the callback function of the target timing task.
Optionally, the timing task scheduling method further includes:
and if the timing task to be inserted currently exists, inserting the timing task to be inserted into a current second ready queue of the current-level working thread to obtain a next ready queue.
Optionally, the inserting the timing task to be inserted into the current second ready queue of the current level work thread includes:
adding a write lock for a current second ready queue of the current level working thread, obtaining unit heartbeat time corresponding to the frequency of a central processing unit, and determining a multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time so as to determine the initial heartbeat times of the timing task to be inserted based on the multiple relation;
determining a data structure of the current second ready queue;
if the data structure of the current second ready queue is an array or a queue, inserting the timing task to be inserted into the tail part of the current second ready queue;
if the data structure of the current second ready queue is a linked list, determining the insertion position of the timing task to be inserted and the updated heartbeat time based on the initial heartbeat time and the heartbeat time of the timing task stored in the current second ready queue so as to insert the timing task to be inserted into the current second ready queue;
and adjusting the task state of the timing task to be inserted into the state to be executed, and releasing the write lock of the current second ready queue.
In a second aspect, the present application discloses a timed task scheduling device, applied to a current level working thread, comprising:
the interval determining module is used for acquiring the current global time and the current local time of the next-level working thread and determining the current time interval of the current global time and the current local time;
the time judging module is used for judging whether the current global time and the current local time are equal or not if the current time interval is not larger than a preset threshold value;
the first jump module is used for acquiring the current global time after the current update and the current local time after the current work thread of the next stage update if the current global time and the current local time are equal, and re-jumping to the step of determining the current global time and the current time interval of the current local time;
and the second jump module is used for updating the current local time if the current local time is not equal, so that the next-stage working thread executes a corresponding timing task based on the current local time and jumps again to the step of judging whether the current global time and the current local time are equal.
In a third aspect, the present application discloses an electronic device, comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the steps of the previously disclosed timed task scheduling method.
In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein the computer program when executed by a processor implements the steps of the previously disclosed timed task scheduling method.
The application has the beneficial effects that: the method is applied to the current level working thread, acquires the current global time and the current local time of the next level working thread, and determines the current global time and the current time interval of the current local time; if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal; if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time; if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal. Therefore, the application is a mutual detection mechanism for detecting the next-level working thread by the current-level working thread, not a self-detection mechanism, and can avoid the fact that the detection cannot be carried out due to overtime, namely the overtime detection can be reliably carried out; if the current global time is consistent with the current local time of the next-level working thread, the next-level working thread is indicated to work normally, adjustment of the next-level working thread is not needed, and if the current global time is inconsistent with the current local time of the next-level working thread, the current local time of the next-level working thread is updated, so that the next-level working thread can execute a corresponding timing task based on the current local time, and the timing task is guaranteed to be scheduled in time.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present application, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for scheduling timing tasks disclosed by the application;
FIG. 2 is a schematic diagram of a particular worker thread of the present disclosure;
FIG. 3 is a schematic diagram of a specific timed task structure according to the present disclosure;
FIG. 4 is a schematic illustration of a specific timed task insertion according to the present disclosure;
FIG. 5 is a schematic illustration of task insertion based on the number of heartbeats in accordance with the disclosure of the present application;
FIG. 6 is a schematic illustration of one embodiment of the insertion position determination of the present disclosure;
FIG. 7 is a flowchart of a specific method for scheduling timed tasks according to the present disclosure;
FIG. 8 is a flowchart of another specific method for scheduling timed tasks according to the present disclosure;
FIG. 9 is a schematic diagram of a timing task scheduler according to the present disclosure;
Fig. 10 is a block diagram of an electronic device according to the present disclosure.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Scheduled execution of timed tasks is an important ring in a storage system. By timing tasks, special tasks can be conveniently completed. The scheduling of the timing tasks comprises modules of timing task storage, task triggering, task processing, time setting and the like. Based on the precision and stability requirements of the storage system, the safety of tasks and the timeliness of task processing are required to be ensured, so that the detection of a working thread for executing a timing task is required to be carried out, and abnormal conditions are required to be processed in time so as to ensure the timing task scheduling.
Therefore, the application correspondingly provides a timing task scheduling scheme, and the scheduled reliability of the timing task is improved.
Referring to fig. 1, the embodiment of the application discloses a timing task scheduling method, which is applied to a current level working thread and comprises the following steps:
step S11: and acquiring the current global time and the current local time of the next-stage working thread, and determining the current global time and the current time interval of the current local time.
It should be noted that in this embodiment, whether the current level working thread detects the next level working thread overtime is detected instead of detecting the thread itself, because if the next level working thread overtime, self-checking cannot be performed, and in this embodiment, through the working thread mutual checking mechanism, even if the next level working thread overtime, the current level working thread can detect the next level working thread, so as to ensure that the detection work can be performed normally. The current level and the next level are opposite, for example, 3 working threads, namely working thread 0, working thread 1 and working thread 2, exist in a preset scheduling system, when the current level of working thread is the working thread 0, the working thread 1 is the next level of working thread, when the current level of working thread is the working thread 1, the working thread 2 is the next level of working thread, and when the current level of working thread is the working thread 2, the working thread 0 is the next level of working thread, namely, a closed loop detection level is formed, so that each working thread only needs to detect another working thread, and not only can each working thread be detected by another working thread, but also the burden of the working thread cannot be excessively increased.
For example, in a specific working thread schematic diagram shown in fig. 2, a system includes N central processing units (Central Processing Unit, i.e., CPU) cores, where N working threads should exist, a global time may be understood as a real-time for updating by the system, that is, an implementation time for maintaining all working threads, and a global time for a working thread is a real-time for updating by the working thread itself, where local times of all working threads should be substantially consistent with the global time, that is, a current time interval between a local time and a global time needs to be acquired, that is, whether a timeout needs to be determined according to a size relationship between the current time interval and a preset threshold, and if the current time interval is greater than the preset threshold, a next level of working thread timeout needs to be reported, and all working threads need to be suspended.
Step S12: and if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal.
It will be appreciated that if the current time interval is not greater than the preset threshold, it is indicated that the current local time of the next level worker thread is substantially consistent with the current global time, but it is necessary to determine whether the current local time of the next level worker thread is completely consistent with the current global time or has a certain deviation.
Step S13: and if so, acquiring the current global time updated currently and the current local time updated currently by the next-stage working thread, and re-jumping to the step of determining the current global time and the current time interval of the current local time.
In this embodiment, when the current global time and the current local time are equal, it is indicated that the next-level working thread does not have a local time update problem at present, so that the timing task of the next-level working thread will be executed in time, and only the current global time after the current update and the current local time after the current next-level working thread update need to be re-acquired, that is, if the current global time and the current local time are equal, the updated global time and local time need to be re-acquired, and whether the next-level working thread has a local update problem is continuously detected.
Step S14: if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
It can be understood that if the current time interval between the current global time and the current local time is smaller than the preset threshold and the current global time and the current local time are not equal, a certain deviation exists between the current local time of the next-level working thread and the current global time, but the deviation is not large, so that the next-level working thread can execute a corresponding timing task based on the current local time by actively updating the current local time of the next-level working thread. When the current local time of the next-level working thread is updated each time, only the time step with the minimum granularity is added, so that the working thread can execute the timing task with high precision, and therefore whether the updated current local time is consistent with the current global time cannot be determined, whether the updated current local time is consistent with the current global time or not needs to be judged again, that is, if so, the next-level working thread can normally complete the timing task without adjusting, and if not, the current local time of the next-level working thread needs to be updated until the updated local time is consistent with the current global time.
In this embodiment, if there is a timing task to be inserted currently, the timing task to be inserted is inserted into a current second ready queue of the current level working thread to obtain a next ready queue. The creating task module in the scheduling system creates the timing task to be inserted according to specific conditions so that the subsequent timing task to be inserted is inserted into the corresponding working thread. The structure of the timing task to be inserted comprises a task state, a callback function, a timing duration, whether the task is circularly scheduled and a task position identifier, wherein the task state can be used for indicating whether the corresponding ready queue is inserted currently, the callback function is used for executing the timing task, the timing duration is used for indicating the executed time of the timing task, the unit of the timing duration is milliseconds, if the task is expected to run after P milliseconds, the timing duration is set to be P (P is a positive integer), whether the task is circularly scheduled or not is whether the timing task needs to be executed at intervals, the task position identifier is used for indicating the position in the current ready queue, and all the tasks in the ready queue can be connected in series according to the task identifier, so that the execution sequence of the task can be determined.
Taking the data structure of the ready queue as a linked list structure, as shown in fig. 3, a specific timing task structure schematic diagram is shown, if the task is circularly scheduled is a boolean variable, if the timing task is hoped to be circularly scheduled, the task is set to be true, otherwise, the task is set to be false, if the timing task is set to be circularly timed, the timing task is executed once every fixed time, and a linked list pointer (i.e. a task position identifier) is used for completing the mounting in the ready queue.
It will be appreciated that all the working threads have the same task insertion mode, and in order to maximize performance, the number of working threads needs to be determined by the number of cores, that is, if there are n central processing units cores, n working threads need to be created, and a ready queue exists in each working thread for storing timing tasks, unlike the prior art that only one working thread can store one timing task, in this embodiment, a plurality of timing tasks can be stored in one ready queue, so that the number of working threads can be reduced, and more resources can be available for processing other tasks.
In this embodiment, the inserting the timing task to be inserted into the current second ready queue of the current level work thread includes: adding a write lock for a current second ready queue of the current level working thread, obtaining unit heartbeat time corresponding to the frequency of a central processing unit, and determining a multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time so as to determine the initial heartbeat times of the timing task to be inserted based on the multiple relation; determining a data structure of the current second ready queue; if the data structure of the current second ready queue is an array or a queue, inserting the timing task to be inserted into the tail part of the current second ready queue; if the data structure of the current second ready queue is a linked list, determining the insertion position of the timing task to be inserted and the updated heartbeat time based on the initial heartbeat time and the heartbeat time of the timing task stored in the current second ready queue so as to insert the timing task to be inserted into the current second ready queue; and adjusting the task state of the timing task to be inserted into the state to be executed, and releasing the write lock of the current second ready queue. A specific timing task insertion diagram, for example, shown in fig. 4, is that the specific process of inserting a timing task to be inserted into the current second ready queue of the current level worker thread is as follows:
1) And adding a write lock to the current second ready queue of the current-level working thread, so that the current second ready queue can only execute the insertion of the timing task to be inserted, and a plurality of timing tasks to be inserted are prevented from being inserted into the current second ready queue at the same time.
2) Converting the timing time length of the timing task from unit millisecond to the heartbeat frequency of the central processing unit, namely obtaining the unit heartbeat time corresponding to the frequency of the central processing unit, and determining the multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time so as to determine the initial heartbeat frequency of the timing task to be inserted based on the multiple relation; for example, the frequency of the central processing unit is 2GHZ, so that the time of one heartbeat is 10 milliseconds, that is, the unit heartbeat time is 10 milliseconds, the multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time is obtained, and it should be noted that the multiple relation of an integer needs to be obtained, that is, if the timing time length of the timing task to be inserted is 70 milliseconds, the multiple relation is 7, and if the timing time length of the timing task to be inserted is 73 milliseconds, the multiple relation is 7, and then the initial heartbeat frequency of the timing task to be inserted is determined to be 7; wherein a timing duration of 70 milliseconds indicates that the timing task should be performed after 70 milliseconds when the task is inserted, and an initial heartbeat number of 7 indicates that the timing task should be performed after 7 heartbeats of the local time when the task is inserted.
3) Determining a data structure of the current second ready queue; it will be appreciated that if the data structures of the ready queues are different, their corresponding timing task insertion patterns are also different.
4.1 If the data structure of the current second ready queue is an array or a queue, inserting the timing task to be inserted into the tail of the current second ready queue; if the data structure of the current second ready queue is an array or a queue, the timing task to be inserted is not required to be inserted according to the sequence of the task scheduling time;
4.2 If the data structure of the current second ready queue is a linked list, determining the insertion position of the timing task to be inserted and the updated heartbeat number based on the initial heartbeat number and the heartbeat number of the timing task stored in the current second ready queue so as to insert the timing task to be inserted into the current second ready queue; for example, a specific heartbeat-based task insertion schematic diagram shown in fig. 5, for example, a current local time is 2, the heartbeat number of a timing task a is 1, which represents that the timing task a needs to be executed when the local time is 3, the heartbeat number of the timing task B is 3, which represents that the timing task B needs to be executed when the local time is 6, and the heartbeat number of the timing task C is 1, which represents that the timing task a needs to be executed when the local time is 7, that is, the executed time of the timing task at the current position is the accumulation of the heartbeat number of the timing task itself and the heartbeat number of all the preceding timing tasks, when the timing task to be inserted needs to be inserted into the current second ready queue, the insertion position of the timing task to be inserted and the updated heartbeat number of the timing task to be updated are determined according to the heartbeat number of the stored heartbeat number of the timing task to be 3, for example, the initial heartbeat number of the timing task to be inserted needs to be executed when the local time is 4, which represents that the timing task to be inserted needs to be executed when the local time is 4, and the timing task to be inserted is the timing task to be inserted, and the timing task to be inserted is the timing task D, and the timing task to be inserted is the timing task to be updated, and the timing task to be inserted is the timing task D, and the timing task to be inserted is the timing task to be inserted. For example, the insertion position determining process will be described with reference to a specific insertion position determining schematic diagram shown in fig. 6:
B101: determining a current timing task according to the sequence of the timing tasks stored in the current second ready queue;
and B102: reading the heartbeat times Yn of the current timing task, and comparing the heartbeat times Yn of the current timing task with the initial heartbeat times X of the timing task to be inserted;
b103: if Yn is equal to X, determining the insertion position of the timing task to be inserted as the back of the current timing task, and jumping to B108, wherein the number of heartbeat times after updating the timing task to be inserted is 0;
b104: if Yn is greater than X, proving that the executed time of the current timing task is later than the executed time of the timing task to be inserted, and the executed time of the last timing task is earlier than the executed time of the timing task to be inserted, so that the insertion position of the timing task to be inserted can be determined as between the last timing task and the current timing task, and the process jumps to B108;
b105: if Yn is smaller than X, indicating that the executed time of the current timing task is earlier than the executed time of the timing task to be inserted, calculating a difference value R between Yn and X, namely r=x-Yn, and determining R as a new heartbeat number; it can be understood that the calculation mode is accumulated when determining the executed time of each timing task, so that the calculation mode is gradually decreased when updating the number of heartbeats of the timing task to be inserted;
And B106: if there is a timing task after the current timing task, determining the next timing task according to the sequence of the timing tasks already stored in the current second ready queue, taking the next timing task as a new current timing task, and then jumping to B102.
B107: if the timing task does not exist behind the current timing task, the current timing task in the current second ready queue is the timing task which is executed at the latest, and the executed time of the current timing task is earlier than the executed time of the timing task to be inserted, so that the behind of the current timing task can be determined as the inserting position of the timing task to be inserted, and the process jumps to B108;
and B108: and ending the insertion position determining process of the timing task to be inserted.
5) And adjusting the task state of the timing task to be inserted into a state to be executed (queue state), and releasing the write lock of the current second ready queue.
The application has the beneficial effects that: the method is applied to the current level working thread, acquires the current global time and the current local time of the next level working thread, and determines the current global time and the current time interval of the current local time; if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal; if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time; if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal. Therefore, the application is a mutual detection mechanism for detecting the next-level working thread by the current-level working thread, not a self-detection mechanism, and can avoid the fact that the detection cannot be carried out due to overtime, namely the overtime detection can be reliably carried out; if the current global time is consistent with the current local time of the next-level working thread, the next-level working thread is indicated to work normally, adjustment of the next-level working thread is not needed, and if the current global time is inconsistent with the current local time of the next-level working thread, the current local time of the next-level working thread is updated, so that the next-level working thread can execute a corresponding timing task based on the current local time, and the timing task is guaranteed to be scheduled in time.
Referring to fig. 7, the embodiment of the application discloses a specific timing task scheduling method, which is applied to a current level working thread and comprises the following steps:
step S21: and acquiring the current global time and the current local time of the next-stage working thread, and determining the current global time and the current time interval of the current local time.
Step S22: and if the current time interval is greater than a preset threshold, sending an alarm instruction to a preset display platform so that a user can stop executing all the working threads based on the alarm instruction displayed by the preset display platform.
It will be appreciated that if the current time interval is greater than the preset threshold, it indicates that the next-level working thread is overtime, for example, the preset threshold is 80 hops, that is, 800 ms, and if the current time interval is greater than the preset threshold, it may be determined that the next-level working thread is stuck, and the user needs to perform a corresponding operation, so that an alarm instruction (panic) is sent to the preset display platform, that is, the user is enabled to stop executing all the working threads based on the alarm instruction displayed by the preset display platform.
Step S23: and if the current time interval is not greater than the preset threshold value, judging whether the current global time and the current local time are equal.
Step S24: and if so, acquiring the current global time updated currently and the current local time updated currently by the next-stage working thread, and re-jumping to the step of determining the current global time and the current time interval of the current local time.
Step S25: if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
In this embodiment, the executing, by the next-level worker thread, a corresponding timing task based on the current local time includes: the next-stage working thread judges whether a local current first ready queue is empty, if not, the current heartbeat times of the timing tasks in the current first ready queue are updated based on the current local time so as to obtain the current updated heartbeat times of the timing tasks; if the timing task with the current updated heartbeat times of zero exists in the current first ready queue, executing the timing task; and if the current updated heartbeat times of the timing task do not exist, updating again. Firstly, judging whether a timing task exists in a current first ready queue, if not, indicating that the timing task which is not waiting to be executed exists in the current first ready queue, if so, indicating that the timing task which is waiting to be executed exists in the current first ready queue, then updating the current heartbeat frequency of the timing task in the current first ready queue based on the current local time, namely judging whether the timing task which is needed to be executed now exists in the current first ready queue according to the updated heartbeat frequency and the current local time, namely, judging whether the timing task which is zero in the current heartbeat frequency after updating exists or not, and if so, executing the timing task.
In this embodiment, if the timing task with the current updated heartbeat frequency being zero exists in the current first ready queue, the timing task is executed; if not, updating the current updated heartbeat times of the timing task again, wherein the updating comprises the following steps: when the data structure of the current first ready queue is a linked list structure, judging whether the current heartbeat times of the first timing task in the current first ready queue are zero or not; if not, updating the current updated heartbeat times of all the timing tasks in the current first ready queue again; if yes, executing the first timing task in the current first ready queue, updating the current first ready queue to obtain a next first ready queue, taking the next first ready queue as the current first ready queue, and then re-jumping to the step of judging whether the current updated heartbeat frequency of the first timing task in the current first ready queue is zero. It can be understood that, because the timing tasks are inserted according to the order of the executed time, it is determined whether the current heartbeat number after the update of the first timing task in the current first ready queue is zero, and it can be determined whether there is a timing task that needs to be executed now in the current first ready queue, that is, if the current heartbeat number after the update of the first timing task is zero, the current first timing task needs to be executed, after the current first timing task is executed, the current first ready queue is updated to obtain the next first ready queue, and the next first ready queue is used as the current first ready queue, and then the step of determining whether the current heartbeat number after the current update of the first timing task in the current first ready queue is zero is skipped again, that is, until all the timing tasks that need to be executed now are executed.
In this embodiment, the executing the first timing task in the current first ready queue includes: determining the first timing task in the current first ready queue as a target timing task, and taking down the target timing task from the current first ready queue; and executing the callback function of the target timing task. When executing the target timing task A, the target timing task A needs to be removed from the current first ready queue, namely the next first ready queue does not store the target timing task A, because the callback function of the timing task is included when the timing task is created, and therefore the execution of the callback function completes the scheduling of the target timing task.
Therefore, the application obtains the current time interval of the current global time and the current local time, determines how to finish the detection of the working thread and the scheduling of the timing task according to the current time interval, and ensures the stability of the scheduling system.
Referring to fig. 8, an embodiment of the present application discloses another specific method for scheduling a timed task, which is applied to a current level working thread, and includes:
step S31: and acquiring the current global time and the current local time of the next-stage working thread, and determining the current global time and the current time interval of the current local time.
Step S32: and if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal.
Step S33: and if so, acquiring the current global time updated currently and the current local time updated currently by the next-stage working thread, and re-jumping to the step of determining the current global time and the current time interval of the current local time.
Step S34: if not, increasing the current local time by a preset unit time step length to update the current local time, so that the next-level working thread executes a corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
In this embodiment, in order to achieve high-precision completion of the timing task, if the current global time and the current local time are not equal on the basis that the current time interval is not greater than the preset threshold, only the preset unit time step may be updated each time when the current local time is updated, where the preset unit time step may be 1 heartbeat number, for example, the current local time is 4, the current global time is 7, and the current local time is updated, that is, the new current local time is 5, if there is a timing task that needs to be performed when the local time is 5 in the ready queue of the next working thread, after the current local time is updated, the timing task that needs to be performed when the local time is 5 may not be performed according to the preset unit time step, for example, the new current local time is 6, and then the timing task that needs to be performed when the local time is 5 may not be performed, that is, high-precision completion of the timing task scheduling may not be achieved.
Therefore, when the current local time is updated each time, the preset unit time step is increased, namely the update is performed with the minimum update granularity, so that each timing task in the next-stage working thread can be executed, the timing task which is ignored to be executed does not exist, and the task precision requirement of the storage millisecond level is met in precision.
Referring to fig. 9, an embodiment of the present application discloses a timing task scheduling device, which is applied to a current level working thread, including:
the interval determining module 11 is configured to obtain a current global time and a current local time of a next-level working thread, and determine a current time interval between the current global time and the current local time;
a time judging module 12, configured to judge whether the current global time and the current local time are equal if the current time interval is not greater than a preset threshold;
a first skip module 13, configured to obtain the current global time after current update and the current local time after current update of the next-level working thread if the current global time and the current local time are equal, and skip to the step of determining the current global time and the current time interval of the current local time;
And a second skip module 14, configured to update the current local time if the current local time is not equal, so that the next-stage working thread executes a corresponding timing task based on the current local time, and skip to the step of determining whether the current global time and the current local time are equal.
The application has the beneficial effects that: the method is applied to the current level working thread, acquires the current global time and the current local time of the next level working thread, and determines the current global time and the current time interval of the current local time; if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal; if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time; if not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal. Therefore, the application is a mutual detection mechanism for detecting the next-level working thread by the current-level working thread, not a self-detection mechanism, and can avoid the fact that the detection cannot be carried out due to overtime, namely the overtime detection can be reliably carried out; if the current global time is consistent with the current local time of the next-level working thread, the next-level working thread is indicated to work normally, adjustment of the next-level working thread is not needed, and if the current global time is inconsistent with the current local time of the next-level working thread, the current local time of the next-level working thread is updated, so that the next-level working thread can execute a corresponding timing task based on the current local time, and the timing task is guaranteed to be scheduled in time.
Further, the embodiment of the application also provides electronic equipment. Fig. 10 is a block diagram of an electronic device 20, according to an exemplary embodiment, and the contents of the diagram should not be construed as limiting the scope of use of the present application in any way.
Fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application. Specifically, the method comprises the following steps: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input output interface 25, and a communication bus 26. Wherein the memory 22 is used for storing a computer program, which is loaded and executed by the processor 21 for realizing the following steps:
acquiring current global time and current local time of a next-level working thread, and determining current time intervals of the current global time and the current local time;
if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal;
if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time;
If not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
and if the current time interval is greater than a preset threshold, sending an alarm instruction to a preset display platform so that a user can stop executing all the working threads based on the alarm instruction displayed by the preset display platform.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
and increasing the current local time by a preset unit time step length to update the current local time.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
the next-stage working thread judges whether a local current first ready queue is empty, if not, the current heartbeat times of the timing tasks in the current first ready queue are updated based on the current local time so as to obtain the current updated heartbeat times of the timing tasks;
If the timing task with the current updated heartbeat times of zero exists in the current first ready queue, executing the timing task; and if the current updated heartbeat times of the timing task do not exist, updating again.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
when the data structure of the current first ready queue is a linked list structure, judging whether the current heartbeat times of the first timing task in the current first ready queue are zero or not;
if not, updating the current updated heartbeat times of all the timing tasks in the current first ready queue again;
if yes, executing the first timing task in the current first ready queue, updating the current first ready queue to obtain a next first ready queue, taking the next first ready queue as the current first ready queue, and then re-jumping to the step of judging whether the current updated heartbeat frequency of the first timing task in the current first ready queue is zero.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
determining the first timing task in the current first ready queue as a target timing task, and taking down the target timing task from the current first ready queue;
and executing the callback function of the target timing task.
In some embodiments, the processor may specifically implement the following steps by executing the computer program stored in the memory:
and if the timing task to be inserted currently exists, inserting the timing task to be inserted into a current second ready queue of the current-level working thread to obtain a next ready queue.
In some embodiments, the processor may further include the following steps by executing the computer program stored in the memory:
adding a write lock for a current second ready queue of the current level working thread, obtaining unit heartbeat time corresponding to the frequency of a central processing unit, and determining a multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time so as to determine the initial heartbeat times of the timing task to be inserted based on the multiple relation;
Determining a data structure of the current second ready queue;
if the data structure of the current second ready queue is an array or a queue, inserting the timing task to be inserted into the tail part of the current second ready queue;
if the data structure of the current second ready queue is a linked list, determining the insertion position of the timing task to be inserted and the updated heartbeat time based on the initial heartbeat time and the heartbeat time of the timing task stored in the current second ready queue so as to insert the timing task to be inserted into the current second ready queue;
and adjusting the task state of the timing task to be inserted into the state to be executed, and releasing the write lock of the current second ready queue.
In this embodiment, the power supply 23 is configured to provide an operating voltage for each hardware device on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and the external device, and the communication protocol to be followed is any communication protocol applicable to the technical solution of the present application, which is not limited herein in detail; the input/output interface 25 is used for acquiring external input data or outputting external output data, and the specific interface type thereof may be selected according to the specific application requirement, which is not limited herein.
Processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of DSP (Digital Signal Processing ), FPGA (Field-Programmable Gate Array, field programmable gate array), PLA (Programmable Logic Array ). The processor 21 may also comprise a main processor, which is a processor for processing data in an awake state, also called CPU (Central Processing Unit ); a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit, image processor) for rendering and drawing of content required to be displayed by the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence ) processor for processing computing operations related to machine learning.
The memory 22 may be a carrier for storing resources, such as a read-only memory, a random access memory, a magnetic disk, or an optical disk, and the resources stored thereon include an operating system 221, a computer program 222, and data 223, and the storage may be temporary storage or permanent storage.
The operating system 221 is used for managing and controlling various hardware devices on the electronic device and the computer program 222, so as to implement the operation and processing of the processor 21 on the mass data 223 in the memory 22, which may be Windows, unix, linux. The computer program 222 may further include a computer program that can be used to perform other specific tasks in addition to the computer program that can be used to perform the timed task scheduling method performed by the electronic device disclosed in any of the previous embodiments. The data 223 may include, in addition to data received by the electronic device and transmitted by the external device, data collected by the input/output interface 25 itself, and so on.
Further, the embodiment of the application also discloses a computer readable storage medium, wherein the storage medium stores a computer program, and when the computer program is loaded and executed by a processor, the method steps executed in the timing task scheduling process disclosed in any embodiment are realized.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above detailed description of a method, device, apparatus and medium for scheduling timing tasks, provided by the present invention, applies specific examples herein to illustrate the principles and embodiments of the present invention, and the above description of the examples is only for helping to understand the method and core ideas of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.
Claims (11)
1. A method for scheduling a timed task, applied to a current level worker thread, comprising:
acquiring current global time and current local time of a next-level working thread, and determining current time intervals of the current global time and the current local time;
if the current time interval is not greater than a preset threshold value, judging whether the current global time and the current local time are equal;
if the current global time is equal to the current local time after the current working thread of the next stage is updated, acquiring the current global time after the current updating and the current local time after the current working thread of the next stage are updated, and re-jumping to the step of determining the current time interval between the current global time and the current local time;
If not, updating the current local time so that the next-level working thread executes the corresponding timing task based on the current local time, and re-jumping to the step of judging whether the current global time and the current local time are equal.
2. The timed task scheduling method according to claim 1, characterized in that after said determining the current time interval of the current global time and the current local time, further comprising:
and if the current time interval is greater than a preset threshold, sending an alarm instruction to a preset display platform so that a user can stop executing all the working threads based on the alarm instruction displayed by the preset display platform.
3. The timed task scheduling method according to claim 1, characterized in that said updating the current local time comprises:
and increasing the current local time by a preset unit time step length to update the current local time.
4. The timed task scheduling method according to claim 1, characterized in that the next-level worker thread performs a corresponding timed task based on the current local time, comprising:
The next-stage working thread judges whether a local current first ready queue is empty, if not, the current heartbeat times of the timing tasks in the current first ready queue are updated based on the current local time so as to obtain the current updated heartbeat times of the timing tasks;
if the timing task with the current updated heartbeat times of zero exists in the current first ready queue, executing the timing task; and if the current updated heartbeat times of the timing task do not exist, updating again.
5. The method according to claim 4, wherein the timing task is executed if the timing task with the current updated heartbeat number of zero exists in the current first ready queue; if not, updating the current updated heartbeat times of the timing task again, wherein the updating comprises the following steps:
when the data structure of the current first ready queue is a linked list structure, judging whether the current heartbeat times of the first timing task in the current first ready queue are zero or not;
if not, updating the current updated heartbeat times of all the timing tasks in the current first ready queue again;
If yes, executing the first timing task in the current first ready queue, updating the current first ready queue to obtain a next first ready queue, taking the next first ready queue as the current first ready queue, and then re-jumping to the step of judging whether the current updated heartbeat frequency of the first timing task in the current first ready queue is zero.
6. The method of claim 5, wherein said executing a first of said timed tasks in said current first ready queue comprises:
determining the first timing task in the current first ready queue as a target timing task, and taking down the target timing task from the current first ready queue;
and executing the callback function of the target timing task.
7. A timed task scheduling method according to any one of claims 1 to 6, characterised in that it further comprises:
and if the timing task to be inserted currently exists, inserting the timing task to be inserted into a current second ready queue of the current-level working thread to obtain a next ready queue.
8. The timed task scheduling method according to claim 7, wherein the inserting the timed task to be inserted into the current second ready queue of the current level worker thread comprises:
adding a write lock for a current second ready queue of the current level working thread, obtaining unit heartbeat time corresponding to the frequency of a central processing unit, and determining a multiple relation between the timing time length of the timing task to be inserted and the unit heartbeat time so as to determine the initial heartbeat times of the timing task to be inserted based on the multiple relation;
determining a data structure of the current second ready queue;
if the data structure of the current second ready queue is an array or a queue, inserting the timing task to be inserted into the tail part of the current second ready queue;
if the data structure of the current second ready queue is a linked list, determining the insertion position of the timing task to be inserted and the updated heartbeat time based on the initial heartbeat time and the heartbeat time of the timing task stored in the current second ready queue so as to insert the timing task to be inserted into the current second ready queue;
And adjusting the task state of the timing task to be inserted into the state to be executed, and releasing the write lock of the current second ready queue.
9. A timed task scheduler for use with a current level worker thread, comprising:
the interval determining module is used for acquiring the current global time and the current local time of the next-level working thread and determining the current time interval of the current global time and the current local time;
the time judging module is used for judging whether the current global time and the current local time are equal or not if the current time interval is not larger than a preset threshold value;
the first jump module is used for acquiring the current global time after the current update and the current local time after the current work thread of the next stage update if the current global time and the current local time are equal, and re-jumping to the step of determining the current global time and the current time interval of the current local time;
and the second jump module is used for updating the current local time if the current local time is not equal, so that the next-stage working thread executes a corresponding timing task based on the current local time and jumps again to the step of judging whether the current global time and the current local time are equal.
10. An electronic device, comprising:
a memory for storing a computer program;
processor for executing the computer program to implement the steps of the timed task scheduling method according to any one of claims 1 to 8.
11. A computer-readable storage medium storing a computer program; wherein the computer program when executed by a processor implements the steps of the timed task scheduling method of any one of claims 1 to 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310952920.2A CN117112160A (en) | 2023-07-31 | 2023-07-31 | Timing task scheduling method, device, equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310952920.2A CN117112160A (en) | 2023-07-31 | 2023-07-31 | Timing task scheduling method, device, equipment and medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117112160A true CN117112160A (en) | 2023-11-24 |
Family
ID=88810152
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310952920.2A Pending CN117112160A (en) | 2023-07-31 | 2023-07-31 | Timing task scheduling method, device, equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117112160A (en) |
-
2023
- 2023-07-31 CN CN202310952920.2A patent/CN117112160A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111813552B (en) | Scheduling execution method, device and medium based on multi-thread task | |
US9990229B2 (en) | Scheduling method and apparatus for applying laxity correction based on task completion proportion and preset time | |
CN107491346B (en) | Application task processing method, device and system | |
CN112199170B (en) | Timing processing method, device, equipment and storage medium of real-time operating system | |
CN111143045B (en) | Task scheduling method and device of intelligent home operating system and storage medium | |
US11853792B2 (en) | Baseline monitoring method and apparatus, readable medium, and electronic device | |
US9785587B2 (en) | Method for executing, within a multitasking onboard system, an application timed according to a plurality of different time domains including interruption management | |
US8132171B2 (en) | Method of controlling thread access to a synchronization object | |
EP3244314A1 (en) | Temporal relationship extension of state machine observer | |
CN113190427A (en) | Caton monitoring method and device, electronic equipment and storage medium | |
US11853153B2 (en) | Multi-thread exit method and mobile terminal | |
CN117112160A (en) | Timing task scheduling method, device, equipment and medium | |
US20080072106A1 (en) | Method and system of specifying semantics of a late trigger | |
CN112882857B (en) | Performance problem positioning method, device, electronic equipment and storage medium | |
CN115617475A (en) | Method and device for setting circulating alarm clock, electronic equipment and storage medium | |
CN110968405A (en) | Method and device for detecting planned tasks | |
WO2000063776A2 (en) | Object-oriented system having anonymous scheduler design pattern | |
CN114003498A (en) | Software anomaly detection method and device and electronic equipment | |
KR101989337B1 (en) | Method and Apparatus for Displaying Real Time Wake Information in Radar System | |
CN113032110A (en) | High-availability task scheduling method based on distributed peer-to-peer architecture design | |
CN114528793B (en) | Method for performing behavior simulation on Verilog HDL | |
CN108920298B (en) | Monitoring semaphore processing method and device based on Shenwei architecture | |
CN118093146B (en) | Multitasking method, device, equipment and storage medium | |
CN114153571A (en) | Task scheduling method, system, equipment and storage medium based on fixed time slice | |
CN114253714B (en) | Method, system and equipment for processing multithreaded data based on blocking queue |
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 |