Time calibration method and device, electronic equipment and storage medium
By calculating the number of CPU cycles and ticks from the system startup to the target time, determining whether the target time needs to be calibrated, solving the problem of inaccurate time caused by system clock time drift, and improving the accuracy of time acquisition.
Patent Information
- Application Number
- CN202510179811.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-06-27
AI Technical Summary
In the prior art, the time drift of the system clock causes inaccurate recording times, which reduces the accuracy of time acquisition.
After the system starts, the number of CPU cycles corresponding to the first time period from the system startup time to the target time is obtained, and the number of CPU cycles per unit time is calculated to determine whether the target time needs to be calibrated.
Regardless of whether the system clock is time drifting, the number of ticks from the initial time to the target time will not change, thereby improving the accuracy of time acquisition through a calibration method based on the number of ticks.
Smart Images

Figure CN120215630A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and particularly to a time calibration method, device, electronic device, and storage medium. Background Art
[0002] In modern information systems, timestamps play a crucial role. Timestamps not only provide a time dimension for data but also ensure the accuracy and traceability of system operation. Especially when dealing with complex business logics and data flows across multiple links, recording the time at a specific moment is particularly important, which can provide valuable clues for subsequent business operations, data analysis, and problem troubleshooting.
[0003] In the related art, during the execution of a business, if it is necessary to record a certain moment, the current system time is directly obtained and used as the moment to be recorded.
[0004] However, after recording a certain moment, if the system clock drifts, the previously recorded moment will be inaccurate when used later. For example, after a security policy takes effect, it is first hit at 00:00:00, and the time at this moment is recorded. Then, during the operation of the system, time drift occurs, resulting in the current moment being 10:00:00, while the system time is 11:00:00. At this time, using the previously recorded time of the first hit of the security policy, 00:00:00, is inaccurate, and the corresponding time should be 01:00:00, thus reducing the accuracy of moment acquisition. Summary of the Invention
[0005] The present invention provides a time calibration method, device, electronic device, and storage medium to solve the defect of reducing the accuracy of moment acquisition in the prior art.
[0006] The present invention provides a time calibration method, including: After the system starts, obtain the number of CPU cycles corresponding to a first time period, where the first time period is the time period from the system start moment to the target moment, and the target moment is the moment that needs to be recorded when executing the target business; Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to an initial time period from the system start moment to an initial moment, and the number of CPU cycles corresponding to a unit time, determine the first tick count from the initial moment to the target moment; the initial moment is the moment before the start of the business process during the system startup; Based on the first tick count, determine whether to calibrate the target moment.
[0007] A time calibration method provided by the present invention, determining the first tick count from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup time to the initial time, and the number of CPU cycles corresponding to the unit time, includes: Subtract the number of CPU cycles corresponding to the initial time period from the number of CPU cycles corresponding to the first time period to obtain a first difference in the number of CPU cycles; Determine the ratio of the first difference and the number of CPU cycles corresponding to the unit time as the first tick count.
[0008] A time calibration method provided by the present invention, determining whether to calibrate the target time based on the first tick count, includes: Determine the target initial time; Determine the sum value of the target initial time and the first tick count; In the case where the sum value is different from the target time, calibrate the target time based on the sum value; In the case where the sum value is the same as the target time, do not calibrate the target time.
[0009] A time calibration method provided by the present invention, determining the target initial time, includes: Obtain the number of CPU cycles corresponding to the second time period and the system time when the preset cycle arrives; the second time period is the time period from the system startup time to when the preset cycle arrives; Based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time, determine the second tick count from the initial time to when the preset cycle arrives; Determine the difference between the system time when the preset cycle arrives and the second tick count as the predicted time; In the case where the predicted time is different from the initial time, determine the predicted time as the target initial time; In the case where the predicted time is the same as the initial time, determine the initial time as the target initial time.
[0010] A time calibration method provided by the present invention, based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time, determining the second tick count from the initial time to when the preset cycle arrives, includes: Subtract the number of CPU cycles corresponding to the second time period from the number of CPU cycles corresponding to the initial time period to obtain a second difference in the number of CPU cycles; Determine the ratio of the second difference to the number of CPU cycles corresponding to the unit time as the second tick count.
[0011] According to a time calibration method provided by the present invention, the target service is a service for monitoring whether network data hits a preset security policy; The target time is the time when it is monitored that the network data hits the preset security policy.
[0012] The present invention also provides a time calibration device, including: An acquisition unit, configured to, after the system is started, acquire the number of CPU cycles corresponding to a first time period, where the first time period is a time period from the system start time to the target time, and the target time is the time that needs to be recorded when executing the target service; A first determination unit, configured to determine a first tick count from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to an initial time period from the system start time to the initial time, and the number of CPU cycles corresponding to the unit time; the initial time is the time before the service process is started during the system startup process; A second determination unit, configured to determine whether to calibrate the target time based on the first tick count.
[0013] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where when the processor executes the program, the time calibration method described in any one of the above is implemented.
[0014] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the time calibration method described in any one of the above is implemented.
[0015] The present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the time calibration method described in any one of the above is implemented.
[0016] The time calibration method, device, electronic device, and storage medium provided by the present invention, after the system is started, obtain the number of CPU cycles corresponding to the first time period. The first time period is the time period from the system start time to the target time that needs to be recorded when executing the target service. Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system start time to the initial time, and the number of CPU cycles corresponding to the unit time, determine the first tick count from the initial time to the target time, and determine whether to calibrate the target time based on the first tick count. Since regardless of whether the system clock drifts in time, the tick count from the initial time to the target time will not change, calibrating the target time based on the tick count from the initial time to the target time can improve the accuracy of time acquisition. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0018] Figure 1 is one of the flow diagrams of the time calibration method provided by the embodiments of the present invention.
[0019] Figure 2 is another flow diagram of the time calibration method provided by the embodiments of the present invention.
[0020] Figure 3 is yet another flow diagram of the time calibration method provided by the embodiments of the present invention.
[0021] Figure 4 is the overall flow diagram of the time calibration method provided by the embodiments of the present invention.
[0022] Figure 5 is the structural diagram of the time calibration device provided by the embodiments of the present invention.
[0023] Figure 6 is the physical structure diagram of the electronic device provided by the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] To make the objectives, technical solutions, and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention with reference to the drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.
[0025] The following combines with Figures 1-4 to describe the time calibration method of the present invention. The execution subject of this time calibration method can be an electronic device such as a computer, a server, a terminal, etc., or a time calibration device set in the electronic device, and this time calibration device can be implemented by software, hardware or a combination of both.
[0026] Figure 1 is one of the schematic flowcharts of the time calibration method provided by the embodiments of the present invention. As Figure 1 shown, this time calibration method includes the following steps: Step 101: After the system starts, obtain the number of CPU (Central Processing Unit) cycles corresponding to the first time period. The first time period is the time period from the system start time to the target time, and the target time is the time that needs to be recorded when executing the target service.
[0027] Among them, the CPU cycle is also called the machine cycle, which is the time unit required to complete a basic operation. In a computer, for the convenience of management, the execution process of an instruction is usually divided into several stages, such as instruction fetching, decoding, execution, etc. Each stage completes a basic operation, and the time required to complete a basic operation is the CPU cycle. The clock cycle is the smallest time unit for the processor to execute an action. The higher the main frequency of the processor, the shorter the clock cycle. A CPU cycle usually consists of several clock cycles. At a specific moment, the CPU is executing a certain stage of a certain instruction or waiting for the arrival of the next clock cycle. Therefore, the number of CPU cycles corresponding to a moment is not a fixed value, but is related to the currently executed instruction and the working state of the CPU.
[0028] Exemplarily, after the system starts, if it is necessary to record the time when executing the target service, obtain the number of CPU cycles cycle corresponding to the first time period from the system start time to the target time to be recorded; specifically, the time stamp counter (Time Stamp Counter, TSC) can be read through rdtsc, and rdtsc is an x86 CPU instruction. This time stamp counter records the number of clock cycles elapsed since the CPU started (powered on), so the number of CPU cycles cycle corresponding to the first time period can be obtained by reading the TSC.
[0029] Step 102: Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system start time to the initial time, and the number of CPU cycles corresponding to the unit time, determine the first tick count from the initial time to the target time; the initial time is the time before the business process starts during the system startup process.
[0030] Exemplarily, when the system starts, since the system startup takes a certain amount of time, a certain moment before the business process starts during the system startup process can be selected as the initial moment start_time, and the number of CPU cycles start_cycle corresponding to the initial time period from the system startup moment to the initial moment start_time is obtained, and the initial moment start_time and the number of CPU cycles start_cycle corresponding to the initial time period are saved. It should be noted here that the initial moment start_time and the number of CPU cycles start_cycle corresponding to the initial time period are obtained before the business process of the system runs. In this way, when the target business needs to record the moment during operation, the initial moment start_time and the number of CPU cycles start_cycle corresponding to the initial time period can be used as a basis. During the system operation, sampling is performed at two time points t0 and t1 respectively, the number of CPU cycles cycle0 corresponding to the time period from the system startup moment to the t0 moment and the number of CPU cycles cycle1 corresponding to the time period from the system startup moment to the t1 moment are obtained, and the number of CPU cycles cycle_per_sec corresponding to the unit time can be calculated using the calculation formula (1).
[0031] cycle_per_sec=(cycle1 - cycle0) / (t1 - t0) (1) It should be noted that the units of the t0 moment and the t1 moment can be seconds, milliseconds, microseconds, etc., and can be specifically selected based on actual needs. Taking the units of the t0 moment and the t1 moment as seconds as an example, the number of CPU cycles corresponding to the unit time is the number of CPU cycles per second.
[0032] When the number of CPU cycles cycle corresponding to the first time period, the number of CPU cycles start_cycle corresponding to the initial time period, and the number of CPU cycles cycle_per_sec corresponding to the unit time are obtained, the first tick count from the initial moment to the target moment can be determined based on the number of CPU cycles cycle corresponding to the first time period, the number of CPU cycles start_cycle corresponding to the initial time period, and the number of CPU cycles cycle_per_sec corresponding to the unit time.
[0033] Optionally, determining the first tick count from the initial moment to the target moment based on the number of CPU cycles cycle corresponding to the first time period, the number of CPU cycles start_cycle corresponding to the initial time period, and the number of CPU cycles cycle_per_sec corresponding to the unit time can be achieved through the following method: Subtract the number of CPU cycles corresponding to the first time period from the number of CPU cycles corresponding to the initial time period to obtain a first difference in the number of CPU cycles; determine the ratio of the first difference to the number of CPU cycles corresponding to the unit time as the first tick count.
[0034] Exemplarily, the first tick count T0 is determined using the following formula (2): T0 =(cycle - start_cycle) / cycle_per_sec (2) Step 103: Based on the first tick count, determine whether to calibrate the target time.
[0035] Exemplarily, after the system clock drifts in time, the initial time start_time will change with the time drift, but the number of CPU cycles start_cycle corresponding to the initial time period is a fixed value and will not change. Therefore, the first tick count T0 determined based on the number of CPU cycles will not change with the time drift. However, in practical applications, users do not perceive the tick count. What users need is the specific time. For example, users need the time represented in the form of year, month, day, hour, minute, and second. Therefore, it is necessary to convert the determined first tick count T0 into a specific time, and compare the obtained time after conversion with the target time. If the obtained time after conversion is different from the target time, it means that the system clock has drifted in time, and then the target time needs to be calibrated to the obtained time after conversion; if the obtained time after conversion is the same as the target time, it means that the system clock has not drifted in time, and then there is no need to calibrate the target time.
[0036] It should be noted that there are mainly the following situations for the system clock to drift in time: the system time is modified, the time zone is changed, or there is a time deviation in the system time due to problems such as the system clock hardware.
[0037] The time calibration method provided by the present invention, after the system is started, obtains the number of CPU cycles corresponding to the first time period. The first time period is the time period from the system start time to the target time that needs to be recorded when executing the target service. Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system start time to the initial time, and the number of CPU cycles corresponding to the unit time, determine the first tick count from the initial time to the target time, and determine whether to calibrate the target time based on the first tick count. Since the tick count from the initial time to the target time does not change regardless of whether the system clock drifts in time, calibrating the target time based on the tick count from the initial time to the target time can improve the accuracy of time acquisition.
[0038] In one embodiment, Figure 2 is the second flowchart of the time calibration method provided by the embodiment of the present invention, asFigure 2 As shown, step 103 determines whether to calibrate the target time based on the first tick count, and can be specifically implemented through the following steps: Step 1031: Determine the target initial time.
[0039] Exemplarily, when the initial time is obtained, in order to prevent the initial time from being inaccurate after the system clock drifts in time, it is necessary to calibrate the initial time, and determine the calibrated initial time as the target initial time start_time1. If the system clock does not drift in time after the initial time is recorded, it means that the initial time has not changed and is accurate, then the initial time is not calibrated, that is, the initial time is the target initial time start_time1.
[0040] Step 1032: Determine the sum of the target initial time and the first tick count.
[0041] Exemplarily, add the target initial time start_time1 and the first tick count T0 to obtain the sum value time in the current clock environment, that is, time = start_time1 + T0.
[0042] Step 1033: When the sum value is different from the target time, calibrate the target time based on the sum value.
[0043] Exemplarily, when the sum value time is obtained, compare the sum value time with the target time. When it is determined that the sum value time is different from the target time, it means that the system clock has drifted in time at least once, and it is necessary to update the target time to the sum value time, that is, the calibration of the target time is realized, so that the calibrated target time matches the current clock environment and improves the accuracy of the target time.
[0044] Step 1034: When the sum value is the same as the target time, do not calibrate the target time.
[0045] Exemplarily, when it is determined that the sum value time is the same as the target time, it means that the system clock has not drifted in time and the target time has not changed, then there is no need to calibrate the target time.
[0046] In this embodiment, the sum of the target initial time and the first tick count is determined. When the sum value is different from the target time, the target time is calibrated based on the sum value; when the sum value is the same as the target time, the target time is not calibrated, which improves the accuracy of the obtained target time.
[0047] In one embodiment, Figure 3 is the third flowchart of the time calibration method provided by the embodiment of the present invention. As Figure 3As shown in the figure, the above step 1031 determines the target initial moment, which can be specifically achieved through the following steps: Step 301: Obtain the number of CPU cycles corresponding to the second time period and the system moment corresponding to the arrival of the preset cycle; the second time period is the time period from the system startup moment to the arrival of the preset cycle.
[0048] Among them, the granularity of the preset cycle can be set based on actual requirements. For example, the preset cycle is 10 milliseconds. There are multiple second time periods, which can be the time period from the system startup moment to the arrival of the first 10 milliseconds, the time period from the system startup moment to the arrival of the second 10 milliseconds, the time period from the system startup moment to the arrival of the third 10 milliseconds, etc.
[0049] Exemplarily, the timer obtains the number of CPU cycles based on the preset cycle. When the preset cycle arrives, it obtains the number of CPU cycles cycle1 corresponding to the second time period from the system startup moment to the arrival of the preset cycle and the system moment now corresponding to the arrival of the preset cycle.
[0050] Step 302: Determine the second tick count from the initial moment to the arrival of the preset cycle based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time.
[0051] Optionally, subtract the number of CPU cycles corresponding to the initial time period from the number of CPU cycles corresponding to the second time period to obtain the second difference of the number of CPU cycles; determine the ratio of the second difference to the number of CPU cycles corresponding to the unit time as the second tick count.
[0052] Exemplarily, use the following formula (3) to determine the second tick count T1: T1=(cycle1 - start_cycle) / cycle_per_sec (3) Step 303: Determine the predicted moment as the difference between the system moment corresponding to the arrival of the preset cycle and the second tick count.
[0053] Exemplarily, when determining the second tick count T1, the initial moment is deduced based on the second tick count T1 and the system moment now corresponding to the arrival of the preset cycle, that is, the initial moment is predicted to obtain the predicted moment. Specifically, determine the difference between the system moment now corresponding to the arrival of the preset cycle and the second tick count T1, and determine this difference as the predicted moment start_time0 in the current clock environment, that is, start_time0 = now - T1 = now - (cycle1 - start_cycle) / cycle_per_sec.
[0054] Step 304: When the prediction moment is different from the initial moment, determine the prediction moment as the target initial moment.
[0055] Exemplarily, when the prediction moment start_time0 is obtained, compare the prediction moment start_time0 with the initial moment start_time. When it is determined that the prediction moment start_time0 is different from the initial moment start_time, it indicates that the system clock has experienced time drift. It is necessary to update the initial moment start_time to the prediction moment start_time0 to obtain the target initial moment start_time1. At this time, start_time1 = start_time0, achieving the calibration of the initial moment start_time.
[0056] Step 305: When the prediction moment is the same as the initial moment, determine the initial moment as the target initial moment.
[0057] Exemplarily, when it is determined that the prediction moment start_time0 is the same as the initial moment start_time, it indicates that the system clock has not experienced time drift and the initial moment start_time has not changed. Then there is no need to calibrate the initial moment start_time, and the initial moment start_time is determined as the target initial moment start_time1. At this time, start_time1 = start_time, keeping the value recorded by the initial moment start_time unchanged.
[0058] In this embodiment, obtain the number of CPU cycles corresponding to the second time period from the system startup moment to the arrival of the preset period. Based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time, determine the second tick count from the initial moment to the arrival of the preset period. Determine whether to calibrate the initial moment based on the second tick count. Since regardless of whether the system clock has experienced time drift, the tick count from the initial moment to the arrival of the preset period will not change, calibrating the initial moment based on the tick count from the initial moment to the arrival of the preset period can improve the accuracy of the recorded initial moment.
[0059] In one embodiment, the target service is a service for monitoring whether network data hits a preset security policy; the target moment is the moment when it is monitored that the network data hits the preset security policy.
[0060] Exemplarily, to improve the security of network data, multiple preset security policies can be set in advance. After the system starts, it can execute to monitor whether the network data hits the target service of the preset security policy. When the network data first hits the preset security policy, the first hit time needs to be recorded, and this first hit time is the target time. If the subsequent service needs to use this target time, for example, the system wants to display the first hit times of all preset security policies to the user, and count the number of times the preset security policy is hit within a preset duration based on these first hit times, etc. Therefore, it is necessary to ensure the accuracy of the target time. By adopting the above steps 101 to 103, the calibration of the target time can be achieved, and the accuracy of the target time can be improved.
[0061] It should be noted that the target service can also be a virus detection service, a vulnerability scanning service, an operation log generation service, etc. When the target service is a virus detection service, the target time is the time when the virus is detected; when the target service is a vulnerability scanning service, the target time is the time when the vulnerability is detected; when the target service is an operation log generation service, the target time is the time when the operation log is generated. The present invention does not make any limitations in this regard.
[0062] Figure 4 is the overall flowchart of the time calibration method provided by the embodiment of the present invention. As Figure 4 shown, when the system starts, the startup information (the initial time start_time and the number of CPU cycles start_cycle corresponding to the initial time period) is recorded, the number of CPU cycles cycle_per_sec corresponding to the unit time is calculated, and the timer timer monitors and calibrates the initial time start_time. start_time0 = now - T1 = now - (cycle1 - start_cycle) / cycle_per_sec, and the target initial time start_time1 is obtained. After the system starts, the target service runs. If the system clock drifts in time, the target service is still running, and when it is necessary to record the target time, instead of directly determining the system time as the target time, the first tick count T0 = (cycle - start_cycle) / cycle_per_sec is recorded. When the target time is used subsequently, if the system clock drifts in time after the target time is recorded, the target time is updated to T0 + start_time1.
[0063] The time calibration method provided by the embodiment of the present invention can ensure that any time record is based on the current clock environment and is consistent with the drift of the current time regardless of whether the system clock drifts in time and how many times it drifts in time. It realizes fault tolerance after the time drift occurs, and ensures the accuracy, reliability, and availability of service data.
[0064] The time calibration device provided by the present invention will be described below. The time calibration device described below can be correspondingly referred to the time calibration method described above.
[0065] Figure 5 is a schematic structural diagram of the time calibration device provided by an embodiment of the present invention. As Figure 5 shown, the time calibration device 500 includes an acquisition unit 501, a first determination unit 502, and a second determination unit 503; wherein: The acquisition unit 501 is configured to, after the system is started, acquire the number of CPU cycles corresponding to a first time period, where the first time period is a time period from the system start time to a target time, and the target time is the time that needs to be recorded when executing a target service; The first determination unit 502 is configured to determine a first tick count from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to an initial time period from the system start time to an initial time, and the number of CPU cycles corresponding to a unit time; the initial time is the time before the service process is started during the system startup process; The second determination unit 503 is configured to determine whether to calibrate the target time based on the first tick count.
[0066] For the time calibration device provided by the present invention, after the system is started, the number of CPU cycles corresponding to a first time period is acquired. The first time period is a time period from the system start time to the target time that needs to be recorded when executing a target service. Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to an initial time period from the system start time to an initial time, and the number of CPU cycles corresponding to a unit time, the first tick count from the initial time to the target time is determined. Whether to calibrate the target time is determined based on the first tick count. Since the tick count from the initial time to the target time does not change regardless of whether the system clock drifts in time, calibrating the target time based on the tick count from the initial time to the target time can improve the accuracy of time acquisition.
[0067] Based on any of the above embodiments, the first determination unit 502 is specifically configured to: Subtract the number of CPU cycles corresponding to the initial time period from the number of CPU cycles corresponding to the first time period to obtain a first difference of the number of CPU cycles; Determine the ratio of the first difference to the number of CPU cycles corresponding to a unit time as the first tick count.
[0068] Based on any of the above embodiments, the second determination unit 503 is specifically configured to: Determine a target initial time; Determine the sum value of the target initial time and the first tick count; In the case where the sum value is different from the target time, calibrate the target time based on the sum value; In the case where the sum value is the same as the target time, do not calibrate the target time.
[0069] Based on any of the above embodiments, the second determination unit 503 is further specifically configured to: Obtain the number of CPU cycles corresponding to the second time period and the system time corresponding to the arrival of the preset cycle; the second time period is the time period from the system startup time to the arrival of the preset cycle; Based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time, determine the second tick count from the initial time to the arrival of the preset cycle; Determine the difference between the system time corresponding to the arrival of the preset cycle and the second tick count as the predicted time; In the case where the predicted time is different from the initial time, determine the predicted time as the target initial time; In the case where the predicted time is the same as the initial time, determine the initial time as the target initial time.
[0070] Based on any of the above embodiments, the second determination unit 503 is further specifically configured to: Subtract the number of CPU cycles corresponding to the initial time period from the number of CPU cycles corresponding to the second time period to obtain a second difference in the number of CPU cycles; Determine the ratio of the second difference to the number of CPU cycles corresponding to the unit time as the second tick count.
[0071] Based on any of the above embodiments, the target service is a service for monitoring whether network data hits a preset security policy; The target time is the time when it is monitored that the network data hits the preset security policy.
[0072] Figure 6 It is a schematic diagram of the physical structure of the electronic device provided by the embodiments of the present invention, as Figure 6As shown in the figure, the electronic device may include: a processor 610, a communications interface 620, a memory 630, and a communication bus 640. Among them, the processor 610, the communications interface 620, and the memory 630 complete communication with each other through the communication bus 640. The processor 610 may call the logical instructions in the memory 630 to execute the time calibration method, which includes: after the system starts up, obtaining the number of CPU cycles corresponding to a first time period, where the first time period is the time period from the system startup time to the target time, and the target time is the time that needs to be recorded when executing the target service; Based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to an initial time period from the system startup time to an initial time, and the number of CPU cycles corresponding to a unit time, determining the first tick count from the initial time to the target time; the initial time is the time before the service process starts during the system startup process; Based on the first tick count, determining whether to calibrate the target time.
[0073] In addition, when the logical instructions in the above-mentioned memory 630 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0074] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the time calibration method provided by the above-mentioned various methods. The method includes: after the system starts up, obtaining the number of CPU cycles corresponding to a first time period, where the first time period is the time period from the system startup time to the target time, and the target time is the time that needs to be recorded when executing the target service; Determine the first tick count from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup time to the initial time, and the number of CPU cycles corresponding to the unit time; the initial time is the time before the business process starts during the system startup process; Based on the first tick count, determine whether to calibrate the target time.
[0075] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is used to implement the time calibration method provided by the above-mentioned various methods. The method includes: after the system starts up, obtain the number of CPU cycles corresponding to the first time period, where the first time period is the time period from the system startup time to the target time, and the target time is the time that needs to be recorded when executing the target service; Determine the first tick count from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup time to the initial time, and the number of CPU cycles corresponding to the unit time; the initial time is the time before the business process starts during the system startup process; Based on the first tick count, determine whether to calibrate the target time.
[0076] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.
[0077] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solutions, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0078] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or perform equivalent replacements for some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A time calibration method, characterized in that: include: After the system is started, the number of CPU cycles corresponding to the first time period is obtained, where the first time period is the time period from the system startup time to the target time, and the target time is the time that needs to be recorded when executing the target business; Determine a first tick number from the initial time to the target time based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup time to the initial time, and the number of CPU cycles corresponding to the unit time; the initial time is the time before the business process is started during the system startup process; Based on the first tick number, it is determined whether to calibrate the target time.
2. The time calibration method according to claim 1, characterized in that: The determining a first tick number from the initial moment to the target moment based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup moment to the initial moment, and the number of CPU cycles corresponding to the unit time comprises: Subtract the number of CPU cycles corresponding to the first time period from the number of CPU cycles corresponding to the initial time period to obtain a first difference in the number of CPU cycles; The ratio of the first difference and the number of CPU cycles corresponding to the unit time is determined as the first tick number.
3. The time calibration method according to claim 1, characterized in that: The determining whether to calibrate the target time based on the first tick number includes: Determine the target initial time; determining a sum of the target initial time and the first tick number; In a case where the sum value is different from the target time, calibrating the target time based on the sum value; When the sum value is the same as the target time, the target time is not calibrated.
4. The time calibration method according to claim 3, characterized in that: The determining of the target initial time comprises: Obtain the number of CPU cycles corresponding to the second time period and the system time corresponding to the arrival of the preset cycle; the second time period is the time period from the system startup time to the arrival of the preset cycle; Determine a second tick number from the initial moment to the arrival of the preset period based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time; Determine the difference between the system time corresponding to when the preset period arrives and the second tick number as the predicted time; In the case where the predicted time is different from the initial time, determining the predicted time as the target initial time; When the predicted time is the same as the initial time, the initial time is determined as the target initial time.
5. The time calibration method according to claim 4, characterized in that: The determining, based on the number of CPU cycles corresponding to the second time period, the number of CPU cycles corresponding to the initial time period, and the number of CPU cycles corresponding to the unit time, a second number of ticks from the initial moment to the arrival of the preset period includes: Subtract the number of CPU cycles corresponding to the initial time period from the number of CPU cycles corresponding to the second time period to obtain a second difference in the number of CPU cycles; The ratio of the second difference and the number of CPU cycles corresponding to the unit time is determined as the second tick number.
6. The time calibration method according to any one of claims 1 to 5, characterized in that: The target business is a business that monitors whether network data hits a preset security policy; The target time is the time when the network data is monitored to hit the preset security policy.
7. A time calibration device, characterized in that: include: an acquisition unit, configured to acquire the number of CPU cycles corresponding to a first time period after the system is started, wherein the first time period is a time period from the system startup time to a target time, and the target time is a time that needs to be recorded when executing a target service; a first determining unit, configured to determine a first tick number from the initial moment to the target moment based on the number of CPU cycles corresponding to the first time period, the number of CPU cycles corresponding to the initial time period from the system startup moment to the initial moment, and the number of CPU cycles corresponding to the unit time; the initial moment is a moment before the service process is started during the system startup process; The second determining unit is configured to determine whether to calibrate the target time based on the first tick number.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the time calibration method as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the time calibration method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the time calibration method according to any one of claims 1 to 6 is implemented.