CN114721797A - Timing method, device, equipment and medium based on unit timer - Google Patents

Timing method, device, equipment and medium based on unit timer Download PDF

Info

Publication number
CN114721797A
CN114721797A CN202210337976.2A CN202210337976A CN114721797A CN 114721797 A CN114721797 A CN 114721797A CN 202210337976 A CN202210337976 A CN 202210337976A CN 114721797 A CN114721797 A CN 114721797A
Authority
CN
China
Prior art keywords
timer
calibration
unit
timing
user
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
CN202210337976.2A
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.)
FAW Group Corp
Original Assignee
FAW Group Corp
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 FAW Group Corp filed Critical FAW Group Corp
Priority to CN202210337976.2A priority Critical patent/CN114721797A/en
Publication of CN114721797A publication Critical patent/CN114721797A/en
Pending legal-status Critical Current

Links

Images

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
    • G06F9/4887Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues involving deadlines, e.g. rate based, periodic
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0751Error or fault detection not based on redundancy
    • G06F11/0754Error or fault detection not based on redundancy by exceeding limits
    • G06F11/0757Error or fault detection not based on redundancy by exceeding limits by exceeding a time limit, i.e. time-out, e.g. watchdogs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0751Error or fault detection not based on redundancy
    • G06F11/0754Error or fault detection not based on redundancy by exceeding limits
    • G06F11/076Error or fault detection not based on redundancy by exceeding limits by exceeding a count or rate limit, e.g. word- or bit count limit
    • 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/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • 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
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Electric Clocks (AREA)

Abstract

The embodiment of the invention discloses a timing method, a timing device and a timing medium based on a unit timer. The method includes acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer, in the process that the user timer is timed by the unit timer, the calibration timer is triggered based on the calibration timing period of the calibration timer, if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period is equal to the preset trigger times, a restart of the unit timer is triggered so that the unit timer is triggered in advance, an error of the unit timer in a calibration timing period is reduced, an accuracy of the unit timer is improved, further, an accumulated error of the user timer is reduced, an accuracy of the user timer is improved, and, the method can improve the precision of the user timer only by calibrating the timer, and the occupied system resource is low.

Description

Timing method, device, equipment and medium based on unit timer
Technical Field
The embodiment of the invention relates to the technical field of timers, in particular to a timing method, a timing device and a timing medium based on a unit timer.
Background
Timers are a common technique in computer software. The timer may be used to repeatedly process tasks that require cycling or that require a set amount of time to execute. However, the conventional timer has the technical problems of inaccurate timing, complex design, occupation of system resources and the like.
Disclosure of Invention
The embodiment of the invention provides a timing method, a timing device and a timing medium based on a unit timer, and aims to solve the technical problems of inaccurate timing and over-high system resource occupation in the prior art.
In a first aspect, an embodiment of the present invention provides a timing method based on a unit timer, where the method includes:
acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
in the process that the user timer is timed by the unit timer, the calibration timer is triggered based on a calibration timing period of the calibration timer;
and if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the unit timer to restart so as to enable the unit timer to be triggered in advance.
Optionally, the method further includes:
if the calibration timer detects that the actual total trigger times of the unit timer in the calibration timing period are not equal to the preset trigger times, the unit timing period and/or the calibration timing period of the unit timer are/is adjusted based on the actual total trigger times and the preset trigger times.
Optionally, the method further includes:
determining the average error time length generated by the unit timer running once;
acquiring a preset maximum accumulated error generated by the unit timer during one-time running of the calibration timer;
determining a unit timing period of the unit timer and a calibration timing period of the calibration timer based on the average error duration and the maximum accumulated error.
Optionally, the method further includes:
determining a proportional relationship between a unit timing period of the unit timer and the calibration timing period;
and determining the preset triggering times of the unit timer in the calibration timing period based on the proportional relation.
Optionally, the method further includes:
in the process that the user timer adopts the unit timer to perform timing, determining the accumulated timing length corresponding to the unit timer based on the user timer;
and if the accumulated timing length reaches the reference timing length corresponding to the user timer, triggering a processing function corresponding to the user timer.
Optionally, the method further includes:
acquiring a timer linked list of the user timer, wherein the timer linked list comprises at least one timing length to be executed;
and determining the reference timing length corresponding to the user timer based on the timer linked list.
Optionally, the method further includes:
displaying a unit timing period, the calibration timing period, the actual total trigger times and the preset trigger times of the unit timer on a display interface;
and acquiring the adjustment operation information of a user on the display interface, and updating the unit timing cycle and/or the calibration timing cycle based on the adjustment operation information.
In a second aspect, an embodiment of the present invention further provides a timing apparatus based on a unit timer, where the apparatus includes:
an acquisition module for acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
a timing module, configured to trigger the calibration timer based on a calibration timing cycle of the calibration timer in a process that the user timer performs timing by using the unit timer;
and the calibration module is used for triggering the restart of the unit timer if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, so that the unit timer is triggered in advance.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a unit timer based timing method as provided by any embodiment of the invention.
In a fourth aspect, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the unit timer based timing method provided in any embodiment of the present invention.
The embodiment of the invention has the following advantages or beneficial effects:
by acquiring a user timer, a unit timer for calculating unit time length for the user timer and a calibration timer for calculating calibration time length for the unit timer, in the process that the user timer is timed by the unit timer, the calibration timer is triggered based on a calibration timing period of the calibration timer, if the calibration timer detects that the current trigger time number of the unit timer in the calibration timing period is equal to a preset trigger time number, the restart of the unit timer is triggered, so that the unit timer is triggered in advance, the accumulated error of the unit timer in the calibration timing period is reduced, the precision of the unit timer is improved, further, the accumulated error of the user timer is reduced, the precision of the user timer is improved, the technical problem of inaccurate timing of the traditional timer is solved, and the precision of the user timer can be improved only by calibrating the timer, the occupied system resources are low.
Drawings
In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, a brief description is given below of the drawings used in describing the embodiments. It should be clear that the described figures are only views of some of the embodiments of the invention to be described, not all, and that for a person skilled in the art, other figures can be derived from these figures without inventive effort.
Fig. 1A is a schematic flowchart of a timing method based on a unit timer according to an embodiment of the present invention;
fig. 1B is a schematic timing cycle diagram of various timers according to an embodiment of the present invention;
fig. 1C is a timing process of a user timer according to an embodiment of the present invention;
fig. 2A is a schematic flowchart illustrating a timing method based on a unit timer according to a second embodiment of the present invention;
fig. 2B is a schematic diagram of a period adjustment process according to a second embodiment of the present invention;
fig. 3A is a schematic flowchart of a timing method based on a unit timer according to a third embodiment of the present invention;
fig. 3B is a schematic diagram illustrating an initialization process of a unit timer and a calibration timer according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a timing device based on a unit timer according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some structures related to the present invention are shown in the drawings, not all of them.
Example one
Fig. 1A is a schematic flowchart of a timing method based on a unit timer according to an embodiment of the present invention, where this embodiment is applicable to a case where a user timer is clocked by the unit timer, and the method may be executed by a timing apparatus based on the unit timer, where the apparatus may be implemented by hardware and/or software, and the method specifically includes the following steps:
s110, acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer.
Wherein the user timer may be used to time the task to be processed in the program. Specifically, the computer program may set a corresponding user timer for each task to be processed according to an actual task requirement, or set a corresponding user timer for a task that needs to be executed cyclically for a set time duration.
The unit timer may be a timer that performs cycle timing in units of a minimum timing time. In this embodiment, the unit timer can be used as a timing unit of the user timer, and the unit duration in the user timer is a duration calculated by running the unit timer once, that is, a unit timing period of the unit timer. Illustratively, the unit timing period of the unit timer may be 1 ms.
The calibration timer may be a timer for calibrating the unit timer, and in particular, the calibration timer may be used to restart the unit timer. In the present embodiment, the calibration timing period of the calibration timer may be set to a value much larger than the unit timing period of the unit timer, and the calibration timing period of the calibration timer may be equal to an integer multiple of the unit timing period. Illustratively, the calibration timing period of the calibration timer may be 10 ms.
As shown in fig. 1B, a timing cycle diagram of each timer is shown, where a calibration timing cycle of the calibration timer is m milliseconds, a unit timing cycle of the unit timer is n milliseconds, and a user timing cycle of the user timer is X × n milliseconds.
And S120, in the process that the user timer adopts the unit timer for timing, the calibration timer is triggered based on the calibration timing cycle of the calibration timer.
Specifically, in the process that the user timer adopts the unit timer to time, the unit timer is triggered, and the user timer accumulates all unit durations timed by the unit timer. For example, if the unit timing period of the unit timer is 1ms, and the unit timer is triggered once, 1ms is added to the duration calculated by the user timer. In this embodiment, the time length that needs to be calculated by the user timer may be much longer than the unit timing period of the unit timer, for example, the time length that needs to be calculated by the user timer is 80 ms.
In the embodiment, during the process that the user timer is timed by using the unit timer, the unit timer is triggered circularly to increase the accumulated timing of the user timer by repeatedly calculating the unit duration in the user timer. At the same time, the calibration timer may run cyclically according to its calibration timing period. Following the above example, the calibration timer may be run every 10ms, i.e. the time duration calculated for each run is 10 ms.
And S130, if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the unit timer to restart so as to enable the unit timer to be triggered in advance.
Specifically, after the calibration timer is triggered, the triggering times of the unit timer in the current calibration timing period may be monitored, and if the current triggering times of the unit timer in the current calibration timing period is equal to the preset triggering times, the calibration timer may immediately trigger the restart of the unit timer, so that the unit timer is triggered in advance, that is, the unit timer is triggered again after the unit timer has not passed through the unit timing period.
In other words, after the unit timer is triggered, the unit timer calculates the duration of one unit timing period, and triggers again after the duration calculation is completed. The calibration timer can restart the unit timer immediately without waiting for the unit timer to calculate the duration of one unit timing period when the current trigger time of the unit timer is the preset trigger time, so that the unit timer is triggered again. Since the user timer calculates the accumulated time length of the user timer according to the triggering times of the unit timer, when the calibration timer restarts the unit timer, the user timer immediately adds the accumulated time length to one unit timing period.
Illustratively, the calibration timing period is 10ms, the unit timing period of the unit timer is 1ms, after the calibration timer is triggered, when the calibration timer detects that the unit timer is triggered 9 times, that is, when the user timer determines that the cumulative calculation time of the unit timer during the running period of the calibration timer is 9ms, the calibration timer immediately restarts the unit timer so that the number of times of triggering the unit timer reaches 10 times, at this time, the cumulative time calculated by the user timer is 10 ms.
It should be noted that, in the present embodiment, the purpose of triggering the restart of the unit timer by using the calibration timer is to: since the time consumed by the unit timer to process the function may cause an error in the time length calculated by the unit timer running once, for example, the actual time length required by the unit timer running once is 1.2ms, and the calculated time length is 1ms, that is, the error in the running once is 0.2ms, if the unit timer is not calibrated, the accumulated error of the user timer may be large. Therefore, in this embodiment, the calibration timer may be set, and the restart of the unit timer is triggered in one calibration timing period, so that the unit timer is restarted immediately after being triggered for a certain time, and the unit timer is triggered again after being triggered for a certain time, and it is not necessary to calculate one unit timing period, thereby reducing the accumulated error of the unit timer in one calibration timing period, and further improving the accuracy of the unit timer.
In this embodiment, the preset number of triggers may be a preset number of times for triggering the restart of the unit timer; the preset trigger time may be any value, and of course, the preset trigger time cannot exceed the ratio between the calibration timing period and the unit timing period. For example, the preset number of triggers may be obtained by: determining a proportional relationship between a unit timing period of the unit timer and the calibration timing period; and determining the preset triggering times of the unit timer in the calibration timing period based on the proportional relation.
The proportional relationship may be a ratio of the calibration timing period to the unit timing period, i.e., a multiple relationship between the standard timing period and the unit timing period. For example, the standard trigger times may be set according to the proportional relationship, for example, the value of the preset trigger times may be equal to the value of the proportional relationship minus 1. For example, if the calibration timing period is m milliseconds and the unit timing period is n milliseconds, the preset number of triggers may be m milliseconds
Figure BDA0003575092340000081
Wherein m is an integer multiple of n. That is, the preset number of triggers may be the second last trigger that the unit timer should trigger within one calibration timing period, regardless of the running error of the unit timer.
Of course, the preset number of times of triggering may also be any one time triggered by the unit timer within one calibration timing period, and the calibration timer may trigger a restart of the unit timer within one calibration timing period.
Specifically, during the process of timing by the user timer, the calibration timer may be triggered cyclically, and in each calibration timing period, the unit timer is restarted by triggering once, so as to reduce the accumulated error in each calibration timing period, and further reduce the accumulated error during the timing period of the user timer.
In this embodiment, the method may further include: in the process that the user timer adopts the unit timer to perform timing, determining the accumulated timing length corresponding to the unit timer based on the user timer; and if the accumulated timing length reaches the reference timing length corresponding to the user timer, triggering a processing function corresponding to the user timer.
The user timer can determine the accumulated timing length corresponding to the unit timer according to the triggering times of the unit timer. Specifically, each time the unit timer is triggered, the user timer can increase the unit timing period of the unit timer on the basis of the existing timing length; the user timer can judge the accumulated timing length once every time the user timer accumulates the unit timing period, namely, whether the accumulated timing length reaches the reference timing length is judged, wherein the reference timing length can be the preset length which needs timing of the user timer, and if the accumulated timing length reaches the reference timing length, a processing function corresponding to the user timer is triggered. The processing function includes, but is not limited to, a data processing task and a control task for an application, such as refreshing a usage state of an application, restarting an application, and the like.
It should be noted that the reference timing length may be obtained from a preset user timer linked list. That is, optionally, the method further comprises: acquiring a timer linked list of the user timer, wherein the timer linked list comprises at least one timing length to be executed; and determining the reference timing length corresponding to the user timer based on the timer linked list.
The timer linked list can be a linked list used for storing each timing length to be executed; the timing lengths to be executed can be stored in the timer linked list according to the sequence of the execution time. Specifically, the timing length with the closest execution time may be read from the timer linked list as the reference time length corresponding to the user timer.
Illustratively, as shown in fig. 1C, a timing procedure of a user timer is illustrated. Specifically, after a timer linked list of the user timer is initialized, the unit timer can be triggered to perform timing, the user timer accumulates the timing length of the unit timer, further, whether the accumulated timing length exceeds a reference timing length is judged, and if yes, a user timer processing function is triggered.
In the technical scheme of the embodiment, by acquiring a user timer, a unit timer for calculating unit time length for the user timer, and a calibration timer for calculating calibration time length for the unit timer, in the process that the user timer adopts the unit timer for timing, the calibration timer is triggered based on a calibration timing cycle of the calibration timer, if the calibration timer detects that the current trigger time number of the unit timer in the calibration timing cycle is equal to a preset trigger time number, the calibration timer is triggered to restart the unit timer, so that the unit timer is triggered in advance, the accumulated error of the unit timer in the calibration timing cycle is reduced, the precision of the unit timer is improved, further, the accumulated error of the user timer is reduced, the precision of the user timer is improved, and the technical problem that the traditional timer cannot accurately count time is solved, in addition, the method can improve the precision of the user timer only by calibrating the timer, and the occupied system resource is low.
Example two
Fig. 2A is a schematic flowchart of a timing method based on a unit timer according to a second embodiment of the present invention, and in this embodiment, based on the above embodiments, the unit timer period and/or the calibration timer period may be adjusted based on the actual total number of times that the unit timer triggers in the calibration timer period. Wherein explanations of the same or corresponding terms as those of the above embodiments are omitted. Referring to fig. 2A, the timing method based on a unit timer provided in this embodiment includes the following steps:
s210, acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer.
S220, in the process that the user timer adopts the unit timer for timing, the calibration timer is triggered based on the calibration timing cycle of the calibration timer.
And S230, if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the unit timer to restart so that the unit timer is triggered in advance.
S240, if the calibration timer detects that the actual total trigger count of the unit timer in the calibration timing period is not equal to the preset trigger count, adjusting the unit timing period of the unit timer and/or the calibration timing period based on the actual total trigger count and the preset trigger count.
In this embodiment, the preset number of triggers is equal to the ratio between the calibration timing period and the unit timing period minus 1. Specifically, if the actual total trigger time is not equal to the preset trigger time, it indicates that the accumulated error of the unit timer in one calibration timing period is large, and the unit timer cannot complete the triggering of the preset trigger time in one calibration timing period. Therefore, the number of times that the unit timer should run in one calibration timing period can be reduced by adjusting the unit timing period and/or the calibration timing period, and further, the accumulated error of the unit timer in one calibration timing period is reduced, so that the total number of times that the unit timer is triggered in one calibration timing period can reach the preset triggering number.
Specifically, if the unit timing period is increased, the ratio of the calibration timing period to the unit timing period is decreased, and the number of times that the unit timer should be operated within one calibration timing period is decreased; if the calibration timing period is reduced, the ratio of the calibration timing period to the unit timing period is reduced, and the number of times the unit timer should be operated in one calibration timing period is reduced.
In this embodiment, the unit timing period and/or the calibration timing period may be adjusted according to a difference between the actual total trigger times and the preset trigger times. Or feeding back prompt information needing to be adjusted to the display interface, and updating the unit timing period and/or the calibration timing period according to the operation adjusted by the user.
As, optionally, the method further comprises: displaying a unit timing period, the calibration timing period, the actual total trigger times and the preset trigger times of the unit timer on a display interface; and acquiring the adjustment operation information of a user on the display interface, and updating the unit timing cycle and/or the calibration timing cycle based on the adjustment operation information.
Specifically, when it is determined that the actual trigger time is not equal to the preset trigger time, the current timing of the user timer is suspended or terminated, and the prompt information is fed back on the display interface to obtain the adjustment operation information of the user on the display interface, and further, after the unit timing period and/or the calibration timing period are updated according to the operation adjustment information, the timing of the user timer may be re-executed according to the updated unit timing period and the calibration timing period.
Of course, the embodiment may also adjust the unit timing period and/or the calibration timing period after the timing of the user timer is completed once, or before the timing of the user timer is started, so that the error accuracy of the user timer can be controlled within the allowable range when the user timer is timed based on the unit timer next time.
Illustratively, as shown in fig. 2B, a schematic diagram of a cycle adjustment process is shown. After the calibration timer is triggered, the unit timer can be restarted, a processing function of the unit timer is triggered, after the calibration timer finishes one-time timing, the actual triggering times of the unit timer in the period are obtained, whether the actual triggering times of the unit timer are equal to the standard triggering times or not is judged, if not, the unit timing period and the calibration timing period are adjusted, and if yes, the timing is successfully corrected. Of course, during the process that the user timer is timed by the unit timer, the calibration timer may be continuously triggered to continuously calibrate the unit timer.
According to the technical scheme of the embodiment, whether the actual total trigger times of the unit timer in the calibration timing period are equal to the preset trigger times or not is judged, if not, the unit timing period and/or the calibration timing period are/is adjusted according to the actual total trigger times and the preset trigger times, so that the accumulated error of the unit timer in the calibration timing period is reduced, the actual total trigger times of the unit timer in the calibration timing period can reach the preset trigger times, and the technical problem that the traditional timer is inaccurate in timing is solved.
EXAMPLE III
Fig. 3A is a schematic flowchart of a timing method based on a unit timer according to a third embodiment of the present invention, and this embodiment exemplarily illustrates a determination process of a unit timing period and a calibration timing period based on the foregoing embodiments. Wherein explanations of the same or corresponding terms as those of the above embodiments are omitted. Referring to fig. 3A, the timing method based on a unit timer provided in this embodiment includes the following steps:
s310, acquiring a user timer, a unit timer used for calculating unit time length for the user timer, and a calibration timer used for calculating calibration time length aiming at the unit timer.
S320, determining the average error time length generated by the unit timer running once, and acquiring the preset maximum accumulated error generated by the unit timer during the calibration timer running once.
Specifically, the average error duration may be a delay duration caused by time consumption of a processing function of the unit timer, and theoretically, the unit timer should run once for a unit timing period, however, due to the existence of the average error duration, the required duration for the unit timer to run once may be equal to the sum of the unit timing period and the average error duration. If the unit timing period is 1ms and the average error duration is 0.1ms, the duration required for the unit timer to run once is 1.1 ms. For example, the actual time length of the unit timer running for multiple times may be obtained, and then the average error time length may be calculated according to each actual time length and the unit timing period.
In this embodiment, the maximum accumulated error of the preset unit timer generated during one time of the operation of the calibration timer may be the maximum error of the unit timer generated in one calibration timing period.
S330, determining a unit timing period of the unit timer and a calibration timing period of the calibration timer based on the average error duration and the maximum accumulated error.
Specifically, according to the unit timing period, the calibration timing period, and the average error duration of the unit timer, the analog accumulated error of the unit timer in the calibration timing period may be calculated, and the unit timing period and the calibration timing period may be set on the condition that the analog accumulated error cannot exceed the maximum accumulated error.
For example, the unit timing period of the unit timer and the calibration timing period of the calibration timer may be determined by the following formulas:
Figure BDA0003575092340000141
wherein the content of the first and second substances,
Figure BDA0003575092340000142
representing the analog accumulated error, at represents the average error duration, m is the calibration timing period, n is the unit timing period,
Figure BDA0003575092340000143
representing the number of times the unit timer is expected to run during the calibration timing period, and y is a preset maximum accumulated error. Through the above formula, the unit timing period and the calibration timing period are set so that the unit timing period and the calibration timing period satisfy the above manner.
Illustratively, as shown in fig. 3B, a schematic diagram of the initialization flow of the unit timer and the calibration timer is shown. Specifically, the unit timer and the calibration timer may be initialized, the unit timing period and the calibration timing period may be set through the above steps, the processing function of the calibration timer may be further configured, and the unit timer and the calibration timer may be started.
S340, in the process that the user timer adopts the unit timer for timing, the calibration timer is triggered based on the calibration timing cycle of the calibration timer.
And S350, if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the restart of the unit timer so as to trigger the unit timer in advance.
According to the technical scheme of the embodiment, the unit timing cycle and the calibration timing cycle are set by determining the average error duration of the unit timer and the preset maximum accumulated error of the unit timer in one calibration timing cycle, so that the error of the unit timing cycle in one calibration timing cycle is controlled within an allowable range, and the positioning accuracy of the user timer is further improved.
Example four
Fig. 4 is a schematic structural diagram of a timing device based on a unit timer according to a fourth embodiment of the present invention, where the present embodiment is applicable to a case where a user timer is clocked by the unit timer, and the device specifically includes: an acquisition module 410, a timing module 420, and a calibration module 430.
An obtaining module 410, configured to obtain a user timer, a unit timer used for calculating a unit time length for the user timer, and a calibration timer used for calculating a calibration time length for the unit timer;
a timing module 420, configured to trigger the calibration timer based on a calibration timing period of the calibration timer in a process that the user timer is timed by using the unit timer;
the calibration module 430 is configured to trigger a restart of the unit timer if the calibration timer detects that the current trigger time of the unit timer in the calibration timing period is equal to a preset trigger time, so that the unit timer is triggered in advance.
Optionally, the apparatus further includes an adjusting module, where the adjusting module is configured to adjust the unit timing cycle of the unit timer and/or the calibration timing cycle based on the actual total trigger count and the preset trigger count if the calibration timer detects that the actual total trigger count of the unit timer in the calibration timing cycle is not equal to the preset trigger count.
Optionally, the apparatus further includes a period setting module, where the period setting module is configured to determine an average error duration generated when the unit timer runs once; acquiring a preset maximum accumulated error generated by the unit timer during one-time running of the calibration timer; determining a unit timing period of the unit timer and a calibration timing period of the calibration timer based on the average error duration and the maximum accumulated error.
Optionally, the calibration module 430 is further configured to determine a proportional relationship between a unit timing period of the unit timer and the calibration timing period; and determining the preset triggering times of the unit timer in the calibration timing period based on the proportional relation.
Optionally, the timing module 420 is further configured to determine, based on the user timer, an accumulated timing length corresponding to the unit timer in a process that the user timer performs timing by using the unit timer; and if the accumulated timing length reaches the reference timing length corresponding to the user timer, triggering a processing function corresponding to the user timer.
Optionally, the timing module 420 is further configured to obtain a timer linked list of the user timer, where the timer linked list includes at least one timing length to be executed; and determining the reference timing length corresponding to the user timer based on the timer linked list.
Optionally, the adjusting module is further configured to display a unit timing cycle, the calibration timing cycle, the actual total trigger times, and the preset trigger times of the unit timer on a display interface; and acquiring adjustment operation information of a user on the display interface, and updating the unit timing cycle and/or the calibration timing cycle based on the adjustment operation information.
In the embodiment, by acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer, in a process that the user timer is timed by using the unit timer, the calibration timer is triggered based on a calibration timing cycle of the calibration timer, and if the calibration timer detects that a current trigger time of the unit timer in the calibration timing cycle is equal to a preset trigger time, the calibration timer triggers restarting of the unit timer, so that the unit timer is triggered in advance, an accumulated error of the unit timer in the calibration timing cycle is reduced, and thus the accuracy of the unit timer is improved, further, the accumulated error of the user timer is reduced, the accuracy of the user timer is improved, and the technical problem of inaccurate timing of a traditional timer is solved, in addition, the method can improve the precision of the user timer only by calibrating the timer, and the occupied system resource is low.
The timing device based on the unit timer provided by the embodiment of the invention can execute the timing method based on the unit timer provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
It should be noted that, the units and modules included in the system are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the embodiment of the invention.
EXAMPLE five
Fig. 5 is a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention. FIG. 5 illustrates a block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention. The electronic device 12 shown in fig. 5 is only an example and should not bring any limitation to the function and the scope of use of the embodiment of the present invention. The device 12 is typically an electronic device that assumes a timing function based on a unit timer.
As shown in FIG. 5, electronic device 12 is embodied in the form of a general purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a memory 28, and a bus 18 that couples the various components (including the memory 28 and the processing unit 16).
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, an enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
Electronic device 12 typically includes a variety of computer-readable media. Such media may be any available media that is accessible by electronic device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
Memory 28 may include computer device readable media in the form of volatile Memory, such as Random Access Memory (RAM) 30 and/or cache Memory 32. The electronic device 12 may further include other removable/non-removable, volatile/nonvolatile computer storage media. By way of example only, the storage device 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 5, commonly referred to as a "hard drive"). Although not shown in FIG. 5, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a Compact disk-Read Only Memory (CD-ROM), a Digital Video disk (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product 40, with program product 40 having a set of program modules 42 configured to carry out the functions of embodiments of the invention. Program product 40 may be stored, for example, in memory 28, and such program modules 42 include, but are not limited to, one or more application programs, other program modules, and program data, each of which examples or some combination may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
Electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, mouse, camera, etc., and display), one or more devices that enable a user to interact with electronic device 12, and/or any devices (e.g., network card, modem, etc.) that enable electronic device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the electronic device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), Wide Area Network (WAN), and/or a public Network such as the internet) via the Network adapter 20. As shown, the network adapter 20 communicates with other modules of the electronic device 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, Redundant processing units, external disk drive Arrays, disk array (RAID) devices, tape drives, and data backup storage devices, to name a few.
The processor 16 executes various functional applications and data processing by running the program stored in the memory 28, for example, implementing the unit timer-based timing method provided by the above-described embodiment of the present invention, including:
acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
in the process that the user timer adopts the unit timer for timing, the calibration timer is triggered based on a calibration timing period of the calibration timer;
and if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the unit timer to restart so as to enable the unit timer to be triggered in advance.
Of course, those skilled in the art will understand that the processor may also implement the technical solution of the unit timer based timing method provided in any embodiment of the present invention.
EXAMPLE six
An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the unit timer-based timing method steps provided in any embodiment of the present invention, and the method includes:
acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
in the process that the user timer is timed by the unit timer, the calibration timer is triggered based on a calibration timing period of the calibration timer;
and if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the unit timer to restart so as to enable the unit timer to be triggered in advance.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for embodiments of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, 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 computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A method for timing based on a unit timer, the method comprising:
acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
in the process that the user timer is timed by the unit timer, the calibration timer is triggered based on a calibration timing period of the calibration timer;
and if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, triggering the restart of the unit timer so as to trigger the unit timer in advance.
2. The method of claim 1, further comprising:
if the calibration timer detects that the actual total trigger times of the unit timer in the calibration timing period are not equal to the preset trigger times, the unit timing period and/or the calibration timing period of the unit timer are/is adjusted based on the actual total trigger times and the preset trigger times.
3. The method of claim 1, further comprising:
determining the average error time length generated by the unit timer running once;
acquiring a preset maximum accumulated error generated by the unit timer during one-time running of the calibration timer;
determining a unit timing period of the unit timer and a calibration timing period of the calibration timer based on the average error duration and the maximum accumulated error.
4. The method of claim 1, further comprising:
determining a proportional relationship between a unit timing period of the unit timer and the calibration timing period;
and determining the preset triggering times of the unit timer in the calibration timing period based on the proportional relation.
5. The method of claim 1, further comprising:
in the process that the user timer adopts the unit timer for timing, determining the accumulated timing length corresponding to the unit timer based on the user timer;
and if the accumulated timing length reaches the reference timing length corresponding to the user timer, triggering a processing function corresponding to the user timer.
6. The method of claim 5, further comprising:
acquiring a timer linked list of the user timer, wherein the timer linked list comprises at least one timing length to be executed;
and determining the reference timing length corresponding to the user timer based on the timer linked list.
7. The method of claim 2, further comprising:
displaying a unit timing period, the calibration timing period, the actual total trigger times and the preset trigger times of the unit timer on a display interface;
and acquiring the adjustment operation information of a user on the display interface, and updating the unit timing cycle and/or the calibration timing cycle based on the adjustment operation information.
8. A timing apparatus based on a unit timer, the apparatus comprising:
an acquisition module for acquiring a user timer, a unit timer for calculating a unit time length for the user timer, and a calibration timer for calculating a calibration time length for the unit timer;
a timing module, configured to trigger the calibration timer based on a calibration timing cycle of the calibration timer when the user timer is timed by using the unit timer;
and the calibration module is used for triggering the restart of the unit timer if the calibration timer detects that the current trigger times of the unit timer in the calibration timing period are equal to the preset trigger times, so that the unit timer is triggered in advance.
9. An electronic device, characterized in that the electronic device comprises:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the unit timer based timing method of any one of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the unit timer-based timing method according to any one of claims 1 to 7.
CN202210337976.2A 2022-03-31 2022-03-31 Timing method, device, equipment and medium based on unit timer Pending CN114721797A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210337976.2A CN114721797A (en) 2022-03-31 2022-03-31 Timing method, device, equipment and medium based on unit timer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210337976.2A CN114721797A (en) 2022-03-31 2022-03-31 Timing method, device, equipment and medium based on unit timer

Publications (1)

Publication Number Publication Date
CN114721797A true CN114721797A (en) 2022-07-08

Family

ID=82242674

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210337976.2A Pending CN114721797A (en) 2022-03-31 2022-03-31 Timing method, device, equipment and medium based on unit timer

Country Status (1)

Country Link
CN (1) CN114721797A (en)

Similar Documents

Publication Publication Date Title
US20040025172A1 (en) Counter functions in an application program interface for network devices
CN110110306B (en) Data display method and device, terminal and computer readable storage medium
CN111078422A (en) Message processing method, message processing device, readable storage medium and electronic equipment
CN112149863A (en) Method, apparatus, and computer storage medium for determining resource consumption
CN114721797A (en) Timing method, device, equipment and medium based on unit timer
US10955872B2 (en) System and method to retain baseboard management controller real-time clock time during BMC reboot
CN110912949B (en) Method and device for submitting sites
CN107168776B (en) Event statistical method, device, equipment and storage medium
US20180373512A1 (en) Method and device for simulating synchronous blocking in asynchronous environment, storage medium, server and terminal
CN113407102A (en) Virtual key display method, device, system and storage medium
CN114509791A (en) Satellite positioning error analysis method and device capable of reducing storage
CN112883041A (en) Data updating method and device, electronic equipment and storage medium
CN113760417A (en) Page countdown display method and device
CN112328299A (en) Server firmware information viewing method, device, equipment and storage medium
CN111562974A (en) Method, device and equipment for acquiring offline data and storage medium
US10049060B2 (en) Semiconductor device and control method of the same
CN112235006B (en) Week counting method and receiving device for overcoming zero return of GPS/Beidou week number
CN115563015B (en) Code heat statistics method, device, equipment and storage medium
US20240004582A1 (en) Monitoring and exporting command execution times in a semiconductor device
CN116527185A (en) Sensor timestamp calibration method and device, intelligent terminal and storage medium
US20230102907A1 (en) Device with time stamp synchronizing and related method
US9280354B1 (en) Interval timer
CN111277353B (en) System time deviation correction processing method and device, computer equipment and medium
CN117706901A (en) Alarm clock time calibration method, device, equipment and storage medium
CN116414766A (en) Heterogeneous system inter-core time synchronization method, heterogeneous system and mobile terminal

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