Running cycle correction method and device of cycle task and computer equipment
By triggering the counter and recording time in the periodic task, correcting the operation cycle of the periodic task, the problem of the actual operation cycle inconsistent with the planned cycle is solved, and the accuracy of the data is improved.
Patent Information
- Application Number
- CN202411394430.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-02-14
AI Technical Summary
The actual operation cycle of the cycle task does not match the planned operation cycle, resulting in inaccurate data.
By triggering the counter to start counting and recording the first time, the counter value and the second time are obtained after the counter counts for a period of time, and the operation period of the period task is corrected based on these three values.
The actual operation cycle deviation of periodic tasks is avoided and the accuracy of data is improved.
Smart Images

Figure CN119440169A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of time correction, and in particular to a method, device and computer equipment for correcting the operation cycle of a periodic task. Background Art
[0002] A periodic task is a task that is executed repeatedly at fixed time intervals. Periodic tasks can be used to collect data at preset time intervals, update data at preset time intervals, or control equipment at preset time intervals. For example, when you need to update certain data regularly, you can set the task as a periodic task. After the periodic task is started, it will be executed repeatedly at fixed time intervals to achieve regular data updates.
[0003] In traditional technology, the operating cycle of a periodic task is determined based on the configuration parameters of the controller's crystal oscillator and the interrupt function. However, due to the processing error of the crystal oscillator and the inconsistency of the complexity of the built-in tasks in the interrupt function, the actual operating cycle of the periodic task will not match the planned operating cycle. The deviation of the actual operating cycle of the periodic task will lead to inaccurate data after the execution of the periodic task. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device and computer equipment for correcting the operating cycle of a periodic task in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for correcting the operating cycle of a periodic task, the method comprising: triggering a counter to start counting when the operating cycle task is running, and recording a first time, wherein the counter corresponds to the periodic task; obtaining a counter value, and recording a second time corresponding to when the counter value is obtained; and correcting the operating cycle of the periodic task according to the first time, the second time and the counter value.
[0006] In one embodiment, the correction of the operation cycle of the periodic task based on the first time, the second time and the counter value includes: determining the planned duration based on the counter value and the planned period of the periodic task; determining the actual duration based on the first time and the second time; and correcting the operation cycle of the periodic task based on the actual duration and the planned duration.
[0007] In one of the embodiments, determining the planned duration according to the counter value and the planned period of the periodic task includes: obtaining the planned parameters of the periodic task; wherein the planned parameters include the planned interruption period and the planned number of interruptions of the interruption function associated with the periodic task; determining the planned period of the periodic task according to the planned interruption period and the planned number of interruptions; determining the planned duration according to the counter value and the planned period of the periodic task.
[0008] In one of the embodiments, correcting the operating cycle of the periodic task based on the actual duration and the planned duration includes: determining a time deviation based on the actual duration and the planned duration; and adjusting the actual number of interruptions of the interrupt function associated with the periodic task based on a comparison result of the time deviation with a preset time threshold, so as to correct the operating cycle of the periodic task.
[0009] In one embodiment, adjusting the actual number of interruptions of the interruption function associated with the periodic task according to the comparison result of the time deviation and the preset time threshold includes: the preset time threshold includes a first time threshold and a second time threshold, the first time threshold is greater than zero, and the second time threshold is less than zero; if the time deviation is greater than the first time threshold, the actual number of interruptions of the interruption function is reduced by a first preset amount; if the time deviation is less than the second time threshold, the actual number of interruptions of the interruption function is increased by a second preset amount.
[0010] In one embodiment, obtaining the counter value and recording the second time corresponding to the time when the counter value is obtained includes: obtaining the real-time value of the counter; if the real-time value is equal to the preset value, obtaining the counter value and recording the second time corresponding to the time when the counter value is obtained.
[0011] In one of the embodiments, the method further includes: after obtaining the counter value, resetting the counter; after a preset time interval, triggering the counter to start counting, and correcting the operating cycle of the periodic task again.
[0012] In the second aspect, the present application also provides an operating cycle correction device for a periodic task, the device comprising: a trigger module, used to trigger a counter to start counting when the operating cycle task is running, and record a first time, wherein the counter corresponds to the periodic task; an acquisition module, used to obtain the counter value, and record the second time corresponding to when the counter value is obtained; a correction module, used to correct the operating cycle of the periodic task according to the first time, the second time and the counter value.
[0013] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method for correcting the operating cycle of any periodic task in the first aspect is implemented.
[0014] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for correcting the operating cycle of any periodic task in the first aspect is implemented.
[0015] The above-mentioned method, device and computer equipment for correcting the operation cycle of the periodic task trigger the counter corresponding to the periodic task to start counting when the periodic task is running, and record the first time when counting starts. After the counter counts for a period of time, the counter value is obtained and the corresponding second time is recorded. Finally, the operation cycle of the periodic task is corrected through the first time, the second time and the counter value. Deviations in the actual operation cycle of the periodic task are avoided, and the accuracy of the data obtained after the execution of the periodic task is further improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A schematic flow chart of a method for correcting an operation cycle of a periodic task in one embodiment;
[0017] Figure 2 It is a flowchart of a method for correcting an operation cycle of a periodic task in another embodiment;
[0018] Figure 3 It is a flowchart of a method for correcting the operating cycle of a periodic task in a specific embodiment;
[0019] Figure 4 It is a structural block diagram of an operation cycle calibration device of a periodic task in one embodiment;
[0020] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0022] When the software system is running, periodic tasks are generally used to implement tasks that need to be executed regularly. For example, when the mobile phone software is running, the positioning data will be updated. By setting the task of updating the positioning data as a periodic task, triggering the periodic task when the mobile phone software is running can achieve regular updates of the positioning data. When the vehicle software is running, it is necessary to record the vehicle's driving data, so it is necessary to obtain the vehicle's driving data regularly. By setting the task of obtaining the vehicle's driving data as a periodic task, triggering the periodic task when the vehicle is running can achieve real-time recording of the vehicle's driving data.
[0023] The operation cycle of the periodic task is related to the configuration parameters of the timer interrupt function. After the configuration parameters of the interrupt function are set in the register of the timer, the interrupt function is triggered periodically. After the configuration parameters of the interrupt function are determined, the interrupt cycle of the interrupt function will also be fixed. After the periodic task is set, the number of triggers of the interrupt function is detected. When the number of triggers reaches the preset number, the periodic task is triggered, thereby achieving the periodic operation of the periodic task. For example, after the configuration parameters of the interrupt function are set in the register of the timer, the interrupt cycle of the interrupt function is 1 microsecond. At this time, it is necessary to set a periodic task with a 10 microsecond operation cycle. Then, the interrupt function runs the periodic task once every 10 times it is triggered, thereby achieving the periodic operation of the periodic task. It can be understood that the operation cycle of the periodic task needs to be set according to actual needs. This embodiment does not make specific limitations. When the frequency of execution of the periodic task needs to be faster, the operation cycle can be set shorter. Usually, the operation cycle of the periodic function is generally divided into 1 second, 100 milliseconds, 50 milliseconds, 20 milliseconds, 10 milliseconds, 5 milliseconds, 1 millisecond, 100 microseconds, etc.
[0024] In one embodiment, Figure 1 As shown, a method for correcting the operating cycle of a periodic task is provided, comprising the following steps:
[0025] Step 101, running a periodic task triggers a counter to start counting and record a first time.
[0026] According to the actual scenario requirements, a periodic task is constructed in the software, and the periodic task can be any task that needs to be executed regularly. For example, the periodic task can be a task that periodically records vehicle driving data in the vehicle-mounted software; the periodic task can also be a task that periodically collects the operating status of the vehicle in the vehicle-mounted software and adjusts the duty cycle of the shift motor drive signal according to the operating status. The embodiment of the present application does not make specific restrictions. The periodic task corresponds to a counter, and the counter is used to record the number of times the periodic task is run. The running periodic task triggers the counter corresponding to the periodic task to start counting. It can be that the software corresponding to the periodic task is started, and when the periodic task starts running, the counter corresponding to the periodic task is triggered to start counting; it can also be that the software has been completed and the periodic task is in the running process. By obtaining the running cycle correction instruction input by the user, the counter corresponding to the periodic task is triggered to start counting. The embodiment of the present application does not specifically limit the time when the counter starts counting, but only needs to meet the requirement that the corresponding first time can be recorded when the counter starts counting. After the counter starts counting, the value of the counter is increased by 1 for each cycle of the periodic task. At this time, the value of the counter is the number of times the periodic task is run. When the counter starts counting, the first time corresponding to the time when the counter starts counting is recorded, wherein the first time may be the system time of the system corresponding to the running periodic task, or the time obtained by the system corresponding to the running periodic task through the network. For example, when the periodic task is running in the vehicle system, the first time may be the system time of the vehicle, or the time obtained by the vehicle through the vehicle network.
[0027] Step 102, obtaining a counter value, and recording a second time corresponding to when the counter value is obtained.
[0028] Since the running cycle time of a periodic task is relatively short, it is necessary to obtain the counter value, that is, the number of times the periodic task has been run, after the periodic task has been run for a period of time. Among them, obtaining the counter value can be to obtain the counter value when the counter value reaches a preset value; it can also be to obtain the running time of the periodic task, and obtain the counter value after the running time reaches the preset time; it can also be obtained through instructions input by the user, and this embodiment does not make specific limitations. The counter value is the current counting data of the counter, that is, the number of times the periodic task has been run. After obtaining the counter value, the second time corresponding to the time when the counter value is obtained is recorded. Among them, the second time can be the system time of the system corresponding to the running periodic task, or it can be the time obtained by the system corresponding to the running periodic task through the network. Taking the running of the periodic task in the vehicle system as an example, the second time can be the system time of the vehicle, or it can be the time obtained by the vehicle through the vehicle network.
[0029] Step 103, correcting the running period of the periodic task according to the first time, the second time and the counter value.
[0030] After obtaining the first time, the second time and the counter value, the counter value indicates the number of times the periodic function is run, and the planned running time of the periodic task can be determined by the counter value. The actual running time of the periodic task can be determined by the first time and the second time. Finally, the running period of the periodic task is adjusted by comparing the planned running time with the actual running time, so as to achieve the purpose of correcting the running period of the periodic task and make the running period of the periodic task more accurate.
[0031] The above-mentioned method for correcting the operation cycle of a periodic task triggers a counter corresponding to the periodic task to start counting when the periodic task is running, and records a first time when counting starts. After the counter counts for a period of time, the counter value is obtained, and the corresponding second time is recorded. Finally, the operation cycle of the periodic task is corrected through the first time, the second time and the counter value. This avoids deviations in the actual operation cycle of the periodic task and further improves the accuracy of the data obtained after the periodic task is executed.
[0032] In one embodiment, Figure 2 As shown, a method for correcting the operating cycle of a periodic task is provided, comprising the following steps:
[0033] Step 201, determining the planned duration according to the counter value and the planned period of the periodic task.
[0034] The counter value indicates the number of times the periodic task runs. The planned period is the ideal period set according to actual needs when the periodic task is constructed. When constructing a periodic task, the planned period corresponding to the periodic task is constructed according to the actual needs of the periodic task. For example, if the periodic task needs to record the vehicle's driving data every 10 milliseconds, the planned period corresponding to the constructed periodic task is 10 milliseconds; if the periodic task needs to collect the vehicle's operating status every 50 milliseconds and adjust the duty cycle of the shift motor drive signal according to the operating status, the planned period corresponding to the constructed periodic task is 50 milliseconds. After obtaining the counter value, the planned duration can be obtained by multiplying the counter value by the planned period of the periodic task. Among them, the planned duration is the length of time required for the ideal state when the periodic task runs the number of times corresponding to the counter value.
[0035] Step 202, determining the actual duration according to the first time and the second time.
[0036] After obtaining the first time and the second time, the first time indicates the time when the counter starts counting, and the second time indicates the time when the counter value is obtained. The actual duration can be determined by subtracting the first time from the second time. The actual duration is the actual length of time taken by the periodic task to run the number of times corresponding to the counter value. Since the first time and the second time are system time or the time obtained by the system through the network, the actual duration can accurately indicate the actual running time of the periodic task.
[0037] Step 203: Correct the running period of the periodic task according to the actual duration and the planned duration.
[0038] After calculating the actual duration and the planned duration, if the actual duration is greater than the planned duration, it means that the operating cycle of the periodic task has become longer relative to the planned cycle, and the operating cycle of the periodic task needs to be reduced; if the actual duration is less than the planned duration, it means that the operating cycle of the periodic task has become shorter relative to the planned cycle, and the operating cycle of the periodic task needs to be increased; if the actual duration is equal to the planned duration, there is no need to adjust the operating cycle of the periodic task. It is understandable that the operating cycle of the periodic task can also be corrected by setting a threshold range. First, the time deviation between the actual duration and the planned duration is determined. If the time deviation is greater than the maximum value of the threshold range, it means that the operating cycle of the periodic task has become longer relative to the planned cycle, and the operating cycle of the periodic task needs to be reduced; if the time deviation is less than the minimum value of the threshold range, it means that the operating cycle of the periodic task has become shorter relative to the planned cycle, and the operating cycle of the periodic task needs to be increased; if the time deviation is within the threshold range, there is no need to adjust the operating cycle of the periodic task.
[0039] This embodiment can accurately determine the planned duration of the periodic task through the counter value and the planned cycle, and can accurately determine the actual duration of the periodic task through the first time and the second time provided externally. The operating cycle of the periodic task can be corrected through the deviation between the actual duration and the planned duration, thereby improving the operating cycle accuracy of the periodic task and further improving the accuracy of the data obtained after the execution of the periodic task.
[0040] In one embodiment, before determining the planned duration, it is necessary to first obtain the planned period of the periodic task. Obtain the planned parameters of the periodic task; the planned parameters include the planned interruption period and the planned number of interruptions of the interrupt function associated with the periodic task; determine the planned period of the periodic task according to the planned interruption period and the planned number of interruptions; determine the planned duration according to the counter value and the planned period of the periodic task. When constructing the periodic task, it is necessary to construct the planned period corresponding to the periodic task according to actual needs. Constructing the periodic task according to actual needs can improve the adaptability of the periodic task. The planned period needs to be configured according to the interrupt function, that is, to configure the planned parameters of the periodic task. For example, the planned interruption period of the interrupt function is 1 millisecond. At this time, it is necessary to construct a periodic task with a period of 10 milliseconds. The planned parameters of the periodic task include the planned interruption period of the interrupt function of 1 millisecond and the planned number of interruptions of 10 times. The periodic task is run once every 10 times when the interrupt function is triggered, so that the planned period of the periodic task is set to 10 milliseconds. When obtaining the planned period of the periodic task, first obtain the planned parameters of the periodic task, that is, the planned interruption period and the planned number of interruptions of the interrupt function, multiply the planned interruption period by the planned number of interruptions, and obtain the planned period of the periodic task. Then, the planned duration is determined based on the counter value and the planned period. By obtaining the planned parameters of the periodic task configured when building the periodic task, the planned period of the periodic task can be accurately determined, thereby improving the operating period accuracy of the periodic task when correcting the operating period.
[0041] In one embodiment, the operation period of the periodic task is corrected according to the actual duration and the planned duration, specifically including:
[0042] Step 1: Determine the time deviation based on the actual duration and the planned duration.
[0043] After calculating the actual duration and the planned duration, the time deviation is obtained by subtracting the planned duration from the actual duration. The time deviation is the deviation between the actual time used and the ideal time required when the periodic task is running.
[0044] Step 2: According to the comparison result between the time deviation and the preset time threshold, the actual interruption times of the interruption function associated with the periodic task are adjusted to correct the operation cycle of the periodic task.
[0045] The preset time threshold is the time deviation allowed to occur according to actual needs. When the comparison result is that the time deviation meets the preset time threshold, there is no need to correct the running cycle of the periodic task. When the comparison result is that the time deviation does not meet the preset time threshold, it is necessary to correct the running cycle of the periodic task. When correcting the running cycle of the periodic task, since the running cycle is related to the interruption cycle and the number of interruptions of the interruption function, the interruption cycle is a fixed configuration of the interruption function and cannot be adjusted. Therefore, the purpose of correcting the running cycle of the periodic task can be achieved by adjusting the actual number of interruptions of the interruption function. Among them, the planned number of interruptions is the number of interruptions required for the ideal state configured by the periodic task according to actual needs. The actual number of interruptions is: when the periodic task is actually running, the interruption function runs the periodic task once every time the actual number of interruptions is triggered. For example, the planned interruption period of the interruption function is 1 millisecond. At this time, it is necessary to build a periodic task with a period of 10 milliseconds, and the planned number of interruptions is 10 times. When the periodic task first runs, the actual number of interrupts of its associated interrupt function is 10 times. However, during the running of the periodic task, the running cycle deviates. When the running cycle needs to be corrected, the actual number of interrupts is adjusted to 11 times. When subsequent periodic tasks run, the interrupt function needs to be triggered 11 times to run the periodic task once, thereby achieving the purpose of correcting the running cycle.
[0046] The preset time threshold includes: a first time threshold and a second time threshold. The first time threshold is greater than zero, and the second time threshold is less than zero. For example, the first time threshold may be 3 seconds, and the second time threshold may be -3 seconds; or the first time threshold may be 5 seconds, and the second time threshold may be -5 seconds. This embodiment does not specifically limit the setting value of the preset time threshold.
[0047] If the comparison result between the time deviation and the preset time threshold is: the time deviation is greater than the first time threshold, the actual number of interruptions of the interrupt function is reduced by the first preset number. When the time deviation is greater than the first time threshold, it means that the actual operation cycle of the periodic task is longer than the planned cycle, so the actual number of interruptions of the interrupt function is reduced. Specifically, the first preset number can be reduced, and the first preset number can be set according to actual needs, and this embodiment does not make specific limitations. Preferably, the first preset number can be 1, that is, the actual number of interruptions is reduced by 1 time. It can be understood that the first preset number can also be dynamically adjusted according to the difference between the time deviation and the first time threshold.
[0048] If the comparison result between the time deviation and the preset time threshold is: the time deviation is less than the second time threshold, then the actual number of interruptions of the interrupt function is increased by the second preset number. When the time deviation is less than the second time threshold, it means that the actual operation cycle of the periodic task is shorter than the planned cycle, then the actual number of interruptions of the interrupt function is increased. Specifically, the second preset number can be increased, and the second preset number can be set according to actual needs, and this embodiment does not make specific limitations. The first preset number and the second preset number can be the same or different. Preferably, the second preset number can be 1, that is, the actual number of interruptions is increased by 1 time. It can be understood that the second preset number can also be dynamically adjusted according to the difference between the time deviation and the second time threshold.
[0049] If the comparison result between the time deviation and the preset time threshold is: the time deviation is less than or equal to the first time threshold and greater than or equal to the second time threshold, it means that the actual operation period of the periodic task is within the allowable error range and the operation period is not corrected.
[0050] For example, the first time threshold is 3 seconds, and the second time threshold is -3 seconds. When the time deviation is greater than 3 seconds, the actual number of interruptions is reduced by 1. When the time deviation is less than -3 seconds, the actual number of interruptions is increased by 1.
[0051] By comparing the time deviation with the preset time threshold, when the time deviation is greater than the first time threshold, the actual number of interruptions is reduced, and when the time deviation is less than the second time threshold, the actual number of interruptions is increased, thereby achieving the purpose of correcting the operation cycle. By adjusting the actual number of interruptions, the actual operation cycle of the periodic task is adjusted. When performing the period correction of the periodic task, when the counter value remains unchanged, after reducing the actual number of interruptions, the time difference between the first time and the second time will become shorter, that is, the actual duration of the periodic task will become shorter; after increasing the actual number of interruptions, the time difference between the first time and the second time will become longer, that is, the actual duration of the periodic task will become longer.
[0052] In one embodiment, obtaining the counter value and recording the second time corresponding to the counter value obtaining specifically includes: obtaining the real-time value of the counter in real time after the counter starts counting, and when the real-time value is equal to the preset value, obtaining the counter value and recording the second time corresponding to the counter value obtaining. The preset value can be set according to actual needs and is not specifically limited in this embodiment.
[0053] By setting preset values, it is ensured that the operating cycle is corrected after the periodic task has run for a certain period of time, avoiding the situation where the time deviation cannot be reflected due to too few operating cycles, and further improving the correction accuracy of the operating cycle.
[0054] In one of the embodiments, after obtaining the counter value, the counter is reset; after a preset time interval, the counter is triggered to start counting, and the operation cycle of the periodic task is corrected again. After obtaining the counter value, the correction of the next operation cycle can be started. At this time, the counter needs to be reset first, and the counter is set to zero. After a preset time interval, the counter corresponding to the periodic task is triggered to start counting and record the third time; the counter value is obtained, and the fourth time corresponding to the counter value is obtained; according to the third time, the fourth time and the counter value, the operation cycle of the periodic task is corrected. Among them, the preset time interval can be zero, that is, the operation cycle correction of the periodic task can be carried out continuously without interruption, and can also be set to any time interval, that is, the operation cycle correction of the periodic task can be carried out intermittently at intervals of preset time, which is not specifically limited in the embodiments of the present application. Through multiple operation cycle corrections, the correction accuracy of the operation cycle can be improved, and the accuracy of the data obtained after the execution of the periodic task can be further improved.
[0055] Take the periodic task as an example of a task that periodically records vehicle driving data in the vehicle software. The periodic task needs to record the vehicle driving data every 10 milliseconds, so the planned period corresponding to the constructed periodic task is 10 milliseconds. The planned parameters of the periodic task include: the planned interruption period of the interrupt function is 1 millisecond and the planned number of interruptions is 10 times. Set the preset value to 180,000 times. Running the periodic task triggers the counter corresponding to the periodic task to start counting, and records the first time as 9:30:30. When the counter value reaches 180,000, obtain the counter value of 180,000, and record the second time as 10:00:35. Multiply the counter value by the planned period of the periodic task, that is, 180,000*10 milliseconds, and get the planned duration of 1800 seconds. Subtract the first time from the second time to get the actual duration, that is, 10:00:35 minus 9:30:30, and get the actual duration of 1805 seconds. Subtract the planned duration of 1800 seconds from the actual duration of 1805 seconds to get the time deviation of 5 seconds. At this time, if the first time threshold is 3 seconds and the second time threshold is -3 seconds, the time deviation of 5 seconds is greater than the first time threshold of 3 seconds, and the actual number of interruptions is reduced by 1. After obtaining the counter value, the counter is reset, and after a preset time interval, the counter is triggered to start counting, and the running cycle of the periodic task is corrected again.
[0056] Take the running of a periodic task on a vehicle network as an example. When the software's periodic function runs, that is, when the periodic task runs, a counter is triggered and the start time of a vehicle network is recorded. When the counter accumulates to a certain number of times, the end time of a vehicle network is recorded again. The value of the counter is multiplied by the planned operation cycle of the periodic function to obtain the planned time length. The end time of the vehicle network is subtracted from the start time of the vehicle network to obtain the actual time length. Among them, the planned operation cycle of the periodic function is the interruption function cycle multiplied by the number of interruptions. If the deviation after the actual time length is subtracted from the planned time length is greater than the first threshold value, the actual number of interruptions corresponding to the periodic function is subtracted by 1. If the deviation after the actual time length is subtracted from the planned time length is less than the second threshold value, the actual number of interruptions corresponding to the periodic function is increased by 1, and then the adjusted actual number of interruptions replaces the existing actual number of interruptions in the software. In this way, the cycle of the software periodic task is modified, so that the operation cycle of the software periodic task is more accurate.
[0057] like Figure 3 As shown, first, obtain the actual number of interruptions NrItrrpt of the interruption function associated with the periodic function. Trigger the counter to start counting within the periodic function, and record the start time T1 of an on-board network at the same time. Continue to run the counter. If the value of the counter is equal to the threshold value Nrlmt, record the end time T2 of an on-board network at the same time. Calculate the planned time length Ttar = threshold value Nrlmt * planned period of the periodic function; calculate the actual time length Tact = end time T2-start time T1. Calculate the time deviation Terr = actual time length Tact-planned time length Ttar. If the time deviation Terr>threshold Tlmt, then the actual number of interruptions NrItrrpt-1; if the time deviation Terr<-threshold Tlmt, then the actual number of interruptions NrItrrpt+1, and update the adjusted actual number of interruptions to the software. If -threshold Tlmt≤time deviation Terr≤threshold Tlmt, there is no need to adjust the actual number of interruptions.
[0058] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0059] Based on the same inventive concept, the embodiment of the present application also provides a periodic task operation cycle correction device for implementing the above-mentioned periodic task operation cycle correction method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in the embodiment of the operation cycle correction device for one or more periodic tasks provided below can refer to the limitations of the periodic task operation cycle correction method above, and will not be repeated here.
[0060] In one embodiment, Figure 4 As shown, a device for correcting the operation cycle of a periodic task is provided, comprising: a trigger module 401, an acquisition module 402 and a correction module 403, wherein:
[0061] The trigger module 401 is used to run a periodic task to trigger a counter to start counting and record a first time, wherein the counter corresponds to the periodic task.
[0062] The acquisition module 402 is used to acquire a counter value and record a second time corresponding to when the counter value is acquired.
[0063] The correction module 403 is used to correct the operation period of the periodic task according to the first time, the second time and the counter value.
[0064] The correction module 403 is also used to determine the planned duration based on the counter value and the planned period of the periodic task; determine the actual duration based on the first time and the second time; and correct the operating cycle of the periodic task based on the actual duration and the planned duration.
[0065] The correction module 403 is also used to obtain the planned parameters of the periodic task; wherein the planned parameters include the planned interruption period and the planned number of interruptions of the interruption function associated with the periodic task; the planned period of the periodic task is determined based on the planned interruption period and the planned number of interruptions; the planned duration is determined based on the counter value and the planned period of the periodic task.
[0066] The correction module 403 is also used to determine the time deviation based on the actual duration and the planned duration; based on the comparison result of the time deviation with the preset time threshold, adjust the actual number of interruptions of the interrupt function associated with the periodic task to correct the operation cycle of the periodic task.
[0067] The correction module 403 is also used to reduce the actual number of interruptions of the interruption function by a first preset number if the time deviation is greater than the first time threshold; if the time deviation is less than the second time threshold, increase the actual number of interruptions of the interruption function by a second preset number.
[0068] The acquisition module 402 is further used to acquire the real-time value of the counter; if the real-time value is equal to the preset value, the counter value is acquired, and the second time corresponding to the acquisition of the counter value is recorded.
[0069] The correction module 403 is further used to reset the counter after acquiring the counter value; after a preset time interval, trigger the counter to start counting, and correct the running cycle of the periodic task again.
[0070] Each module in the operation cycle correction device of the above-mentioned periodic task can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0071] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a method for correcting the operating cycle of a periodic task is implemented.
[0072] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0073] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the operation cycle correction method of any one of the periodic tasks in the above embodiments is implemented.
[0074] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method for correcting the operating cycle of any periodic task in the above embodiments is implemented.
[0075] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the method for correcting the operating cycle of a periodic task in any one of the above embodiments is implemented.
[0076] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0077] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0078] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for correcting the operating cycle of a periodic task, characterized in that: The method comprises: Running the periodic task triggers a counter to start counting and record a first time, wherein the counter corresponds to the periodic task; Obtaining a counter value, and recording a second time corresponding to when the counter value is obtained; The operation period of the periodic task is corrected according to the first time, the second time and the counter value.
2. The method according to claim 1, characterized in that: The step of correcting the operation period of the periodic task according to the first time, the second time and the counter value includes: Determine the planned duration according to the counter value and the planned period of the periodic task; Determine the actual duration according to the first time and the second time; The running period of the periodic task is corrected according to the actual duration and the planned duration.
3. The method according to claim 2, characterized in that Determining the planned duration according to the counter value and the planned period of the periodic task includes: Acquire the planned parameters of the periodic task; wherein the planned parameters include the planned interruption period and the planned interruption times of the interruption function associated with the periodic task; Determining the planned period of the periodic task according to the planned interruption period and the planned interruption times; The planned duration is determined according to the counter value and the planned period of the periodic task.
4. The method according to claim 2, characterized in that: Correcting the operation period of the periodic task according to the actual duration and the planned duration includes: Determine the time deviation according to the actual duration and the planned duration; According to the comparison result between the time deviation and the preset time threshold, the actual interruption times of the interruption function associated with the periodic task are adjusted to correct the operation cycle of the periodic task.
5. The method according to claim 4, characterized in that The adjusting the actual number of interruptions of the interruption function associated with the periodic task according to the comparison result of the time deviation and the preset time threshold comprises: the preset time threshold comprises a first time threshold and a second time threshold, the first time threshold is greater than zero, and the second time threshold is less than zero; If the time deviation is greater than the first time threshold, reducing the actual number of interruptions of the interruption function by a first preset amount; If the time deviation is less than the second time threshold, the actual interruption times of the interruption function are increased by a second preset amount.
6. The method according to claim 1, characterized in that The obtaining of the counter value and recording the second time corresponding to the obtaining of the counter value comprises: Get the real-time value of the counter; If the real-time value is equal to the preset value, the counter value is obtained, and the second time corresponding to the time when the counter value is obtained is recorded.
7. The method according to claim 1, characterized in that The method further comprises: After obtaining the counter value, resetting the counter; After a preset time interval, the counter is triggered to start counting, and the running cycle of the periodic task is corrected again.
8. A device for correcting the operation cycle of a periodic task, characterized in that: The device comprises: A trigger module, used for running a periodic task to trigger a counter to start counting and record a first time, wherein the counter corresponds to the periodic task; An acquisition module, used to acquire a counter value and record a second time corresponding to when the counter value is acquired; The correction module is used to correct the operation period of the periodic task according to the first time, the second time and the counter value.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.