Time Synchronization Method, Device, Computer Equipment and Storage Medium
Through the processor internal communication mechanism decoding and passing timestamp information, efficient time synchronization of industrial servers is achieved, solving the problems of high hardware complexity and delay in traditional methods, and improving the accuracy of time synchronization.
Patent Information
- Application Number
- CN202210600234.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-30
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-05-30
AI Technical Summary
In traditional methods, the time synchronization hardware link of industrial servers is complex, with high cost and high delay, making it difficult to meet the requirements in specific scenarios.
The serial encoded signal provided by the timer device is obtained through the first operating system running on the processor, the timestamp information is decoded, and the time synchronization command is transmitted to the second operating system using the communication mechanism inside the processor to realize system time synchronization.
Reduces hardware complexity and processing delays, improves the accuracy of time synchronization, and reduces the complexity of hardware and software.
Smart Images

Figure CN115102653B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic information technology, and particularly to a time synchronization method, device, computer device, and storage medium. Background Art
[0002] With the development of electronic information technology, a server cluster composed of multiple servers often needs to adopt a unified time reference. For example, when a server cluster fails, the cause and process of the accident can be accurately analyzed according to the time of the failure; or the logs of different servers can be combined and analyzed according to the time recorded in the server logs, etc. The working environment of industrial products is extremely harsh, and the requirements for servers are also very strict. The clock of the server drifts greatly during operation, and cross-regional time asynchronization easily leads to untimely instruction responses and difficult fault location. Therefore, accurate and unified time is the most basic requirement for a server cluster.
[0003] In traditional methods, servers in the industrial field can include an external FPGA, an X86 processor, and a large number of communication and control peripherals connected to a time service device. The hardware link for realizing time synchronization is quite long, not only the hardware design cost is high, but also the product cost is high. At the same time, the delay on the hardware link is also high, which cannot meet the requirements in specific scenarios. Summary of the Invention
[0004] Based on this, it is necessary to provide a time synchronization method, device, computer device, storage medium, and computer program product that can reduce hardware complexity for the above technical problems.
[0005] In a first aspect, the present application provides a time synchronization method. The method includes:
[0006] The first operating system running on the processor obtains the serial coding signal provided by the time service device; decodes the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal; and according to the communication mechanism inside the processor, transmits the timestamp information to the second operating system running on the processor, and transmits the time synchronization command triggered when the unit time coding frame is decoded to the second operating system.
[0007] When receiving the time synchronization command, the second operating system synchronizes the system time of the second operating system according to the timestamp information.
[0008] In one embodiment, the unit time coding frame includes a first preset number of code elements, and the timestamp information is encoded into the first second preset number of code elements in the unit time coding frame, and the second preset number is less than the first preset number;
[0009] Transmitting the timestamp information to a second operating system running on the processor according to the communication mechanism inside the processor; transmitting a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system, including:
[0010] When decoding the first second preset number of symbols in the unit-time encoded frame, obtaining the timestamp information and transmitting the timestamp information to a second operating system running on the processor according to the communication mechanism inside the processor;
[0011] When decoding the first preset number of symbols in the unit-time encoded frame, transmitting a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system according to the communication mechanism inside the processor.
[0012] In one embodiment, verification data is encoded in the first second preset number of symbols in the unit-time encoded frame, and the method further includes:
[0013] When the first operating system decodes the first second preset number of symbols in the unit-time encoded frame, obtaining the verification data and transmitting the verification data to the second operating system;
[0014] After receiving the verification data, the second operating system uses the verification data to verify the received timestamp information;
[0015] When the second operating system receives the time synchronization command, synchronizing the system time of the second operating system according to the timestamp information, including:
[0016] In response to the time synchronization command, the second operating system synchronizes the system time of the second operating system using the timestamp information after verification passes.
[0017] In one embodiment, the method further includes:
[0018] The second operating system synchronizes the real-time clock of the processor every preset period;
[0019] Whenever the second operating system detects a shutdown or restart event, it immediately synchronizes the real-time clock of the processor.
[0020] In one embodiment, the first operating system is an operating system of the processor with a trusted execution environment; the second operating system is an operating system of the processor with a rich execution environment; and transmitting a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system according to the communication mechanism inside the processor includes:
[0021] Transmit a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system through an interrupt communication method that complies with security standards between the trusted execution environment and the rich execution environment.
[0022] In one embodiment, the transmitting the timestamp information to the second operating system running on the processor according to the communication mechanism inside the processor includes:
[0023] When obtaining the timestamp information, transmit the timestamp information to the second operating system of the processor immediately through an interrupt communication method between the first operating system and the second operating system; or, when obtaining the timestamp information, write the timestamp information to the shared memory between the first operating system and the second operating system of the processor immediately, so that the second operating system reads the timestamp information from the shared memory;
[0024] The transmitting the time synchronization command triggered when decoding the unit-time encoded frame to the second operating system includes:
[0025] Transmit a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system of the processor through an interrupt communication method between the first operating system and the second operating system.
[0026] In one embodiment, the method further includes:
[0027] When a control interface provided by the second operating system for the user layer is called, the second operating system transmits call parameters to the first operating system to trigger the first operating system to control the decoding of the serial encoded signal according to the call parameters.
[0028] In a second aspect, the present application further provides a time synchronization device. The device includes:
[0029] A first module, configured to instruct a first operating system running on a processor to obtain a serial encoded signal provided by a timing device; decode the serial encoded signal to obtain timestamp information of a unit-time encoded frame in the serial encoded signal; transmit the timestamp information to a second operating system running on the processor; transmit a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system;
[0030] A second module, configured to instruct the second operating system to synchronize the system time of the second operating system according to the timestamp information when receiving the time synchronization command.
[0031] In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor. The memory stores a computer program, and the processor executes the steps of the above time synchronization method.
[0032] In a fourth aspect, the present application also provides a computer-readable storage medium. On the computer-readable storage medium, there is stored a computer program, and the computer program is executed by a processor to perform the steps of the above time synchronization method.
[0033] In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program, and the computer program is executed by a processor to perform the steps of the above time synchronization method.
[0034] For the above time synchronization method, device, computer device, storage medium, and computer program product, a serial coding signal provided by a timing device is obtained through a first operating system running on a processor. The serial coding signal is decoded to obtain the timestamp information of the unit time coding frame in the serial coding signal. According to the communication mechanism inside the processor, the timestamp information is transmitted to a second operating system running on the processor; a time synchronization command triggered when the unit time coding frame is decoded is transmitted to the second operating system. When receiving the time synchronization command, the second operating system synchronizes the system time of the second operating system according to the timestamp information. In this way, in the case of decoding a unit time coding frame, the second operating system can be instructed to perform time synchronization through the time synchronization command. In this way, time synchronization can be achieved without adding other hardware devices. Compared with the method of adding dedicated devices to achieve time synchronization in the traditional technology, the hardware complexity is reduced. Moreover, compared with the traditional technology of using a network for communication to synchronize clocks, communication is performed through the communication mechanism inside the processor, greatly reducing the processing delay, reducing the software complexity, and improving the accuracy of time synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is an application environment diagram of the time synchronization method in an embodiment;
[0036] Figure 2 It is a schematic flowchart of the time synchronization method in an embodiment;
[0037] Figure 3 It is a schematic diagram of the principle of the time synchronization method in an embodiment;
[0038] Figure 4 It is a schematic flowchart of the time synchronization method in an embodiment;
[0039] Figure 5 It is a structural block diagram of the time synchronization device in an embodiment;
[0040] Figure 6 It is the internal structure diagram of a computer device in an embodiment. Specific implementation manners
[0041] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be 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.
[0042] The time synchronization method provided by the embodiments of the present application can be applied to, for example Figure 1 the application environment shown in the figure. Among them, the time synchronization device 110 communicates with the server 120 through a serial port. Among them, the time synchronization device 110 is used to provide a serial coding signal. The processor of the server 120 runs a first operating system and a second operating system.
[0043] The time synchronization device 110 sends serial coding information to the first operating system running on the processor of the server 120. The first operating system obtains the serial coding signal provided by the time synchronization device 110. The first operating system decodes the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal. The first operating system transfers the timestamp information to the second operating system running on the processor. The first operating system transfers the time synchronization command triggered when the unit time coding frame is decoded to the second operating system. When receiving the time synchronization command, the second operating system synchronizes the system time of the second operating system according to the timestamp information.
[0044] In one embodiment, the server 120 can also be replaced by a terminal, and there is no limitation thereto. Among them, the terminal can be but is not limited to various personal computers, laptop computers, smart phones, tablet computers and portable wearable devices.
[0045] In one embodiment, the server 120 is a power industry server. In the power system, since it is necessary to analyze the cause and process of an accident accurately according to the data at the time of a fault, the sequence and accurate time of the actions of each switch and breaker. The working environment of industrial products is very harsh, and the requirements for the server are also very demanding. The clock of the server drifts greatly during operation, and cross-regional time asynchronization easily leads to untimely instruction response and difficult fault location. Therefore, it is necessary to synchronize the system time of the power industry server.
[0046] In one embodiment, as Figure 2 shown in the figure, a time synchronization method is provided. In this embodiment, an example is given where the method is applied to a server. It can be understood that the method can also be applied to a terminal.
[0047] In this embodiment, the method includes the following steps:
[0048] S202, the first operating system running on the processor acquires the serial coding signal provided by the timing device; decodes the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal.
[0049] Among them, the timing device is a device that provides a standard and reliable time signal for the applicator to perform time synchronization. The unit time coding frame is a frame obtained by encoding time every unit time. The timestamp refers to the total number of seconds from 00:00:00 on January 1, 1970, Greenwich Mean Time (08:00:00 on January 1, 1970, Beijing Time) to the present. The timestamp information is used to describe the timestamp. For example, the timestamp information may include seconds, minutes, hours, days, and years, and is used to describe the corresponding timestamp.
[0050] Specifically, a physical connection (such as a serial port) is maintained between the timing device and the first operating system running on the processor. The first operating system acquires the serial coding signal provided by the timing device through the physical connection. The first operating system decodes the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal.
[0051] In one embodiment, the serial coding signal is the serial coding signal corresponding to IRIG-B (B format under the IRIG time code standard). IRIG-B has one frame per second. One time frame period includes 100 code elements, and the total width of each code element is 10 ms.
[0052] In one embodiment, the processor is a processor based on the ARMv9 architecture.
[0053] S204, according to the communication mechanism inside the processor, transmit the timestamp information to the second operating system running on the processor; transmit the time synchronization command triggered when the unit time coding frame is decoded to the second operating system.
[0054] Among them, the time synchronization command is a command used to indicate synchronizing the system time.
[0055] Specifically, according to the communication mechanism inside the processor, the first operating system transmits the timestamp information to the second operating system running on the processor. The first operating system transmits the time synchronization command triggered when the unit time coding frame is decoded to the second operating system. It can be understood that the timestamp information and the time synchronization command can be sent simultaneously or in two separate times. There is no limitation on this.
[0056] In one embodiment, the number of symbols in the coded frame per unit time is a first preset number. The timestamp information is encoded into the first second preset number of symbols in the coded frame per unit time. The first operating system can compare the number of decoded symbols with the second preset number and the first preset number respectively to trigger the transmission of the timestamp information and the time synchronization instruction correspondingly.
[0057] In one embodiment, the first operating system is a secure operating system with a trusted execution environment; the second operating system is an operating system with a rich execution environment. The first operating system can transmit the timestamp information and the time synchronization instruction based on the secure communication mechanism between the trusted execution environment and the rich execution environment.
[0058] In one embodiment, the first operating system can transmit the timestamp information and the time synchronization command to the second operating system through the interrupt communication method between the first operating system and the second operating system; the first operating system can also write the timestamp information into the shared memory between the first operating system and the second operating system of the processor to transmit the timestamp information.
[0059] In one embodiment, the communication mechanism inside the processor can be at least one of shared memory, interrupt, etc.
[0060] S206. When the second operating system receives the time synchronization command, it synchronizes the system time of the second operating system according to the timestamp information.
[0061] Specifically, after receiving the time synchronization command transmitted by the first operating system, the second operating system synchronizes the system time of the second operating system according to the timestamp information.
[0062] In one embodiment, after receiving the timestamp information transmitted by the first operating system, the second operating system verifies the timestamp information. After receiving the time synchronization command transmitted by the first operating system, the second operating system synchronizes the system time of the second operating system using the verified timestamp information. It can be understood that the second operating system can synchronize the system time only when it judges that the system time needs to be synchronized.
[0063] In one embodiment, after synchronizing the system time, the second operating system can also synchronize the real-time clock of the processor according to the preset clock synchronization rule.
[0064] The above time synchronization method, device, computer device, storage medium, and computer program product obtain a serial coding signal provided by a timing device through a first operating system running on a processor. Decode the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal. According to the communication mechanism inside the processor, transmit the timestamp information to a second operating system running on the processor, and transmit a time synchronization command triggered when the unit time coding frame is decoded to the second operating system. When the second operating system receives the time synchronization command, synchronize the system time of the second operating system according to the timestamp information. In this way, when a unit time coding frame is decoded, the second operating system can be instructed to perform time synchronization through the time synchronization command. In this way, time synchronization can be achieved without adding other hardware devices. Compared with the method of adding special devices to achieve time synchronization in the traditional technology, the hardware complexity is reduced. Moreover, compared with the traditional technology of using a network for communication to synchronize clocks, communication is carried out through the communication mechanism inside the processor, which greatly reduces the processing delay, reduces the software complexity, and improves the accuracy of time synchronization.
[0065] In one embodiment, the unit time coding frame includes a first preset number of code elements, and the timestamp information is encoded into the first second preset number of code elements in the unit time coding frame, and the second preset number is less than the first preset number; according to the communication mechanism inside the processor, transmit the timestamp information to a second operating system running on the processor; transmitting a time synchronization command triggered when the unit time coding frame is decoded to the second operating system includes: when the first second preset number of code elements in the unit time coding frame are decoded, obtaining the timestamp information, and according to the communication mechanism inside the processor, transmitting the timestamp information to a second operating system running on the processor; when the first preset number of code elements of the unit time coding frame are decoded, according to the communication mechanism inside the processor, transmit the time synchronization command triggered when the unit time coding frame is decoded to the second operating system.
[0066] Specifically, the unit time coding frame includes a first preset number of code elements. The first second preset number of code elements in the unit time coding frame have encoded data of timestamp information, and the second preset number is less than the first preset number. When the first operating system receives the first code element of the unit time coding frame, it starts counting the number of code elements, and updates the count value for each processed code element. Determine that the first second preset number of code elements in the unit time coding frame are decoded through the count value, immediately determine the timestamp information, and transmit the timestamp information to a second operating system running on the processor according to the communication mechanism inside the processor. Determine that the first preset number of code elements of the unit time coding frame are decoded through the count value, and immediately transmit the time synchronization command triggered when the unit time coding frame is decoded to the second operating system according to the communication mechanism inside the processor.
[0067] In this embodiment, by comparing the number of decoded code elements with a second preset number and a first preset number respectively, the transmission of timestamp information and the transmission of time synchronization instructions are triggered correspondingly. In this way, there is no need to add a judgment logic for time points, but different processes are triggered by the number of code elements, so as to conveniently and timely send timestamp information and time synchronization instructions.
[0068] In one embodiment, verification data is encoded in the first second preset number of code elements in a unit-time coding frame. The method further includes: when the first operating system decodes the first second preset number of code elements in the unit-time coding frame, obtaining the verification data and transmitting the verification data to the second operating system; after receiving the verification data, the second operating system uses the verification data to verify the received timestamp information; when the second operating system receives a time synchronization command, synchronizing the system time of the second operating system according to the timestamp information, including: in response to the time synchronization command, the second operating system uses the timestamp information after passing the verification to synchronize the system time of the second operating system.
[0069] Specifically, verification data and timestamp information are encoded in the first second preset number of code elements in a unit-time coding frame. When the first operating system decodes the first second preset number of code elements in the unit-time coding frame, it obtains the verification data and the timestamp information, and transmits the verification data and the timestamp information to the second operating system. After receiving the verification data and the timestamp information, the second operating system uses the verification data to verify the received timestamp information. In the case of passing the verification, in response to the time synchronization command, the second operating system uses the timestamp information after passing the verification to synchronize the system time of the second operating system. It can be understood that the transmission of the verification data and the timestamp information can be completed in one transmission or divided into two transmissions.
[0070] In one implementation, the second operating system responds to the time synchronization command in an interrupt program. It can be understood that this speeds up the timeliness of processing the time synchronization command, thereby improving the accuracy of system time synchronization. After testing, the system time synchronization accuracy of this case can reach the nanosecond level.
[0071] In this embodiment, after obtaining the verification data, the timestamp information is verified in advance using the verification data. In this way, when responding to the time synchronization command, the system time of the second operating system can be directly synchronized using the timestamp information after passing the verification, avoiding an overly long response time for the time synchronization command, thereby reducing unnecessary delays and improving the accuracy of time synchronization.
[0072] In one embodiment, the method further includes: the second operating system synchronizes the real-time clock of the processor every preset period; whenever the second operating system detects a shutdown or restart event, it immediately synchronizes the real-time clock of the processor.
[0073] Among them, the real-time clock is also called RTC (Real_Time Clock). The RTC can be implemented through an integrated circuit.
[0074] Specifically, after the second operating system synchronizes the system time, it can also synchronize the real-time clock of the processor every preset period. For example, it synchronizes the real-time clock of the processor every 5 minutes. Whenever the second operating system detects a shutdown or restart event, it immediately synchronizes the real-time clock of the processor.
[0075] In one implementation, the RTC of the server uses an active crystal oscillator to improve the stability of the real-time clock.
[0076] In this embodiment, the clock is synchronized through a preset period instead of real-time synchronization, thereby reducing hardware loss. And when the second operating system performs shutdown or restart, the real-time clock is immediately synchronized, further improving the accuracy of the real-time clock.
[0077] In one embodiment, the first operating system is an operating system for the processor with a trusted execution environment; the second operating system is an operating system for the processor with a rich execution environment; according to the communication mechanism inside the processor, transmitting the time synchronization command triggered when decoding the unit time coding frame to the second operating system includes: transmitting the time synchronization command triggered when decoding the unit time coding frame to the second operating system through an interrupt communication method that complies with security standards between the trusted execution environment and the rich execution environment.
[0078] Among them, the trusted execution environment (Trusted Execution Environment) can ensure computing that is not interfered by the conventional operating system, so it is called "trusted". Usually, the trusted execution environment is used for digital rights management (DRM: Digital Rights Management), mobile payment, etc. The rich execution environment (Rich Execution Environment) is a general environment for the device, running a general OS (Operating System), such as Android, IOS, linux system, etc.
[0079] Specifically, the first operating system is an operating system with a trusted execution environment for the processor; the second operating system is an operating system with a rich execution environment for the processor. The first operating system can transmit a time synchronization command triggered when decoding a unit-time encoded frame to the second operating system through an interrupt communication method that complies with security standards between the trusted execution environment and the rich execution environment.
[0080] In one embodiment, the operating system with a trusted execution environment can be an OPTEE operating system (Open-source Portable Trusted Execution Environment OS, open-source portable trusted execution environment operating system). The operating system with a rich execution environment can be a Linux operating system. The secure OPTEE system and the Linux system are isolated from each other, and data sharing can be completed by sharing memory between the two systems.
[0081] In one embodiment, the interrupt communication method that complies with security standards between the OPTEE operating system and the Linux operating system can be implemented through the SMC instruction in the ATF. Among them, ATF
[0082] (Arm Trusted Firmware) is the trusted system firmware of the arm processor, providing a reference implementation software for the secure world. The SMC instruction is a synchronous exception instruction of the arm processor, and the processing related to SMC is a part of the ATF. The operating system with a trusted execution environment can trigger the CPU to enter the interrupt program with a rich execution environment by calling the SMC instruction. After the interrupt program is executed, it returns to the operating system with a trusted execution environment again.
[0083] In this embodiment, by using the operating system with a trusted execution environment to perform decoding, the security of the generated timestamp information is improved; by using a communication method that complies with security standards for communication, the security of transmitting the timestamp information is improved, thereby avoiding system anomalies caused by time tampering.
[0084] In one embodiment, transmitting the timestamp information to the second operating system running on the processor according to the communication mechanism inside the processor includes: when obtaining the timestamp information, immediately transmitting the timestamp information to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system; or, when obtaining the timestamp information, immediately writing the timestamp information into the shared memory between the first operating system and the second operating system of the processor, so that the second operating system reads the timestamp information from the shared memory; transmitting the time synchronization command triggered when decoding the unit time coded frame to the second operating system includes: transmitting the time synchronization command triggered when decoding the unit time coded frame to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system.
[0085] Specifically, there are two ways to transmit the timestamp information. When obtaining the timestamp information, the timestamp information can be immediately transmitted to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system; that is, the transmission of the timestamp information can also be implemented by using the SMC instruction in the ATF. Or, when obtaining the timestamp information, the timestamp information is immediately written into the shared memory between the first operating system and the second operating system of the processor, so that the second operating system reads the timestamp information from the shared memory. The first operating system also needs to transmit the time synchronization command triggered when decoding the unit time coded frame to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system.
[0086] In one embodiment, after the first operating system writes the timestamp information into the shared memory, the interrupt communication method can be used, that is, the SMC instruction in the ATF can also be used to notify the second operating system to process the shared memory. It can be understood that the second operating system can also trigger the processing of the data in the shared memory by identifying whether the data in the shared memory is updated.
[0087] In one embodiment, registers can be used to read and write the timestamp information. Specifically, when not using the shared memory but using the interrupt communication method, the first operating system (such as the optee operating system) can write the timestamp information into the relevant registers when calling the SMC instruction, and the interrupt program (also known as the SMC handler) of the second operating system (such as the linux operating system) can obtain the timestamp information by reading the values of the relevant registers. For example, the values of the X1 to X4 registers can be read to obtain the timestamp information. It can be understood that the transmission efficiency of the timestamp information is improved by writing and reading the register values.
[0088] In one embodiment, the definition of the shared memory fields between the first and second operating systems is as follows:
[0089]
[0090] Among them, the header and tail are defined as "0x55" and "0xff" respectively, which can be used to ensure that the data is not overwritten by other irrelevant data. The data array stores timestamp-related information: seconds, minutes, hours, days, and years. After the first operating system decodes the code elements, it converts the relevant data into decimal character representations, mainly including: important time information such as seconds, minutes, hours, days, and years, leap second-related fields, time quality, check bits, and timestamp-related data are stored in the data array. info stores one byte, represented by a binary number. The leap second bit occupies the 7th and 8th bits, the time quality occupies a total of 4 bits from the 3rd to the 6th, the check bit is the lowest bit, which is the first check value of the parity check carried by the unit time coding frame, and the 2nd bit is reserved. pc is the parity check, which is the second check value obtained after the first operating system performs a parity check on the unit time coding frame. For the IRIG-B code, the first 76 frames of data already include timestamp information, check bits, leap seconds, and time quality, etc. The first operating system can write the timestamp information and check information and other data into the shared memory in the format of this structure after decoding 76 code elements. When the second operating system obtains the corresponding data of this structure from the shared memory, it parses out data such as check bits and time quality and performs verification processing. Specifically, when the time quality indicates that the time accuracy of the timestamp information is within the preset range and the timestamp information is determined to be accurate based on the check bit, the verification passes; when the time quality data indicates that the time accuracy of the timestamp information exceeds the preset range, or the timestamp information is determined to be incorrect based on the check bit, the verification fails.
[0091] In one embodiment, the process of the second operating system using the verification data to verify the received timestamp information includes: the second operating system can compare the first check value and the second check value. If the two values are the same, it can be determined that the timestamp information obtained by the first operating system is accurate; if the two values are different, it can be determined that the timestamp information obtained by the first operating system is inaccurate.
[0092] In this embodiment, the timestamp information is transmitted through the shared memory method, reducing the data transmission delay. The timestamp information and time synchronization commands are transmitted through the interrupt communication method, improving the real-time performance of the processing, thereby improving the accuracy of time synchronization.
[0093] In one embodiment, the method further includes: when the control interface provided by the second operating system for the user layer is called, the second operating system transmits call parameters to the first operating system to trigger the first operating system to control the decoding of the serial coding signal according to the call parameters.
[0094] Specifically, a control interface for the user layer provided by the second operating system. When this control interface is called, the second operating system passes call parameters to the first operating system to trigger the first operating system to control the decoding of the serial encoded signal according to the call parameters. For example, it can control the enabling, disabling, and enabling of decoding-related processes. It can be understood that the second operating system passing call parameters to the first operating system can be achieved through interrupt communication.
[0095] In one embodiment, when the clock control interface for the user layer provided by the second operating system is called, the second operating system can control whether to automatically synchronize the clock according to the call parameters.
[0096] In this embodiment, by providing a control interface for the user layer to control the decoding of the serial encoded signal and the synchronization of the real-time clock, the flexibility of the operation is improved.
[0097] In one embodiment, as Figure 3 shown, a schematic diagram of the principle of the time synchronization method is presented. Specifically, the first operating system and the second operating system are running on the processor. The time-giving device sends a serial encoded signal to the serial port, and the first operating system can obtain the serial encoded signal provided by the time-giving device from the serial port.
[0098] The first operating system decodes the serial encoded signal to obtain the timestamp information of the unit time coding frame in the serial encoded signal, and writes this timestamp information into the shared memory of the first operating system and the second operating system. The first operating system passes a time synchronization command triggered when the unit time coding frame is decoded to the second operating system. When the second operating system receives the time synchronization command, it synchronizes the system time of the second operating system according to the timestamp information in the shared memory.
[0099] In one embodiment, as Figure 4As shown, a flowchart of a time synchronization method is presented. The first operating system can be an operating system with a trusted execution environment for the processor; the second operating system can be an operating system with a rich execution environment for the processor. The interrupt communication method between the two operating systems can be an interrupt communication method that complies with security standards between the trusted execution environment and the rich execution environment. Specifically, when the first operating system parses the first symbol, it starts counting, and for each received symbol decoded, it updates the count value. Since the unit-time coding frame includes a first preset number of symbols, the timestamp information is encoded in the first second preset number of symbols before the unit-time coding frame. When the first second preset number of symbols in the unit-time coding frame are decoded, the timestamp information is obtained and written to the shared memory to transfer the timestamp information to the second operating system. When the first second preset number of symbols in the unit-time coding frame are decoded, the first operating system can also obtain verification data and transfer the verification data to the second operating system. When the first preset number of symbols in the unit-time coding frame are decoded, a time synchronization command triggered when the unit-time coding frame is decoded is transferred to the second operating system, the count value is cleared to 0, and it returns to receive the first symbol of a new unit-time coding frame again. The second operating system starts a kernel real-time thread and reads the new timestamp information and verification data from the shared memory through this thread, and uses the verification data to verify the received timestamp information. The second operating system responds to the time synchronization command in the interrupt program, and in the case where the verification passes and the system time needs to be synchronized, it synchronizes the system time of the second operating system with the timestamp information after verification. The second operating system can also synchronize the real-time clock of the processor every preset period, and whenever a shutdown or restart event is detected, it immediately synchronizes the real-time clock of the processor. The second operating system can also provide a control interface for the user layer to control the decoding of the serial coding signal and control whether to automatically synchronize the clock.
[0100] It should be understood that although the steps in the flowcharts in some embodiments of the present application are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowchart can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same moment, but can be executed at different moments, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0101] Based on the same inventive concept, an embodiment of this application further provides a time synchronization device for implementing the above-mentioned time synchronization method. The solution provided by this device for solving problems is similar to the solution described in the above method. Therefore, the specific limitations in one or more embodiments of the time synchronization device provided below can refer to the limitations on the time synchronization method in the foregoing, and will not be repeated here.
[0102] In one embodiment, as Figure 5 shown, a time synchronization device 500 is provided, including: a first module 502 and a second module 504, where:
[0103] The first module 502 is used to instruct the first operating system running on the processor to obtain the serial coding signal provided by the timing device; decode the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal; transmit the timestamp information to the second operating system running on the processor; and transmit the time synchronization command triggered when decoding the unit time coding frame to the second operating system.
[0104] The second module 504 is used to instruct the second operating system to synchronize the system time of the second operating system according to the timestamp information when receiving the time synchronization command.
[0105] In one embodiment, the unit time coding frame includes a first preset number of code elements, and the timestamp information is encoded into the first second preset number of code elements in the unit time coding frame, and the second preset number is less than the first preset number; the first module 502 is further used to obtain the timestamp information when decoding the first second preset number of code elements in the unit time coding frame, and transmit the timestamp information to the second operating system running on the processor; when decoding the first preset number of code elements of the unit time coding frame, transmit the time synchronization command triggered when decoding the unit time coding frame to the second operating system.
[0106] In one embodiment, verification data is encoded in the first second preset number of code elements in the unit time coding frame, and the first module 502 is further used to instruct the first operating system to obtain the verification data when decoding the first second preset number of code elements in the unit time coding frame, and transmit the verification data to the second operating system; after receiving the verification data, the second operating system uses the verification data to verify the received timestamp information. The second module 504 is further used to synchronize the system time of the second operating system with the timestamp information after verification through the second operating system in response to the time synchronization command.
[0107] In one embodiment, the second module 504 is further used to instruct the second operating system to synchronize the real-time clock of the processor every preset period; instruct the second operating system to synchronize the real-time clock of the processor immediately whenever a shutdown or restart event is detected.
[0108] In one embodiment, the first operating system is an operating system in which the processor has a trusted execution environment; the second operating system is an operating system in which the processor has a rich execution environment; the first module 502 is further configured to transmit, through an interrupt communication method that complies with security standards between the trusted execution environment and the rich execution environment, a time synchronization command triggered when decoding a unit-time encoded frame to the second operating system.
[0109] In one embodiment, the first module 502 is further configured to, when obtaining timestamp information, immediately transmit the timestamp information to the second operating system of the processor through an interrupt communication method between the first operating system and the second operating system; or, when obtaining timestamp information, immediately write the timestamp information into a shared memory between the first operating system and the second operating system of the processor, so that the second operating system reads the timestamp information from the shared memory. The first module 502 is further configured to transmit, through an interrupt communication method between the first operating system and the second operating system, a time synchronization command triggered when decoding a unit-time encoded frame to the second operating system of the processor.
[0110] In one embodiment, the second module 504 is further configured to, when a control interface provided by the second operating system for the user layer is called, the second operating system transmits call parameters to the first operating system to trigger the first operating system to control the decoding of the serial encoded signal according to the call parameters.
[0111] The above time synchronization device obtains a serial encoded signal provided by a timing device through a first operating system running on a processor. Decode the serial encoded signal to obtain timestamp information of a unit-time encoded frame in the serial encoded signal. Communicate through the communication mechanism inside the processor to transmit the timestamp information to a second operating system running on the processor; transmit a time synchronization command triggered when decoding a unit-time encoded frame to the second operating system. When receiving the time synchronization command, the second operating system synchronizes the system time of the second operating system according to the timestamp information. In this way, in the case of decoding a unit-time encoded frame, the second operating system can be instructed to perform time synchronization through the time synchronization command. In this way, time synchronization can be achieved without adding other hardware devices. Compared with the method of adding dedicated devices to achieve time synchronization in the traditional technology, the hardware complexity is reduced. And, compared with using a network for communication to synchronize clocks in the traditional technology, communicating through the communication mechanism inside the processor greatly reduces the processing delay, reduces the software complexity, and improves the accuracy of time synchronization.
[0112] For the specific limitations of the above time synchronization device, reference may be made to the limitations of the above time synchronization method in the foregoing text, which will not be elaborated herein. Each module in the above time synchronization device can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in the processor of the computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so as to facilitate the processor to call and execute the operations corresponding to each of the above modules.
[0113] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structural diagram can be as Figure 6 shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. 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, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. When the computer program is executed by the processor, it implements a time synchronization method.
[0114] Those skilled in the art can understand that Figure 6 the structure shown in
[0115] is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0116] 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, it implements the steps in the above method embodiments.
[0117] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, it implements the steps in the above method embodiments.
[0118] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. 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 methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0119] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, 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, it should be considered to be within the scope described in this specification.
[0120] The above embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. A time synchronization method, characterized in that, The method includes: The first operating system running on the processor obtains the serial coding signal provided by the timing device; decodes the serial coding signal to obtain the timestamp information of the unit time coding frame in the serial coding signal; when obtaining the timestamp information, immediately transmits the timestamp information to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system; or, when obtaining the timestamp information, immediately writes the timestamp information to the shared memory between the first operating system and the second operating system of the processor, so that the second operating system reads the timestamp information from the shared memory, and transmits the time synchronization command triggered when decoding the unit time coding frame to the second operating system of the processor through the interrupt communication method between the first operating system and the second operating system; the processor is a processor based on the ARMv9 architecture; the first operating system is an operating system with a trusted execution environment for the processor; the second operating system is an operating system with a rich execution environment for the processor; the interrupt communication method is implemented through the SMC instruction in the ATF, and the ATF is the trusted system firmware of the arm processor; When the second operating system receives the time synchronization command, it synchronizes the system time of the second operating system according to the timestamp information.
2. The method according to claim 1, characterized in that, The unit time coding frame includes a first preset number of code elements, and the timestamp information is encoded into the first second preset number of code elements in the unit time coding frame, and the second preset number is less than the first preset number; Transmit the timestamp information to the second operating system running on the processor according to the internal communication mechanism of the processor; Transmitting the time synchronization command triggered when decoding the unit time coding frame to the second operating system includes: When decoding the first second preset number of code elements in the unit time coding frame, obtain the timestamp information, and transmit the timestamp information to the second operating system running on the processor according to the internal communication mechanism of the processor; When decoding the first preset number of code elements of the unit time coding frame, transmit the time synchronization command triggered when decoding the unit time coding frame to the second operating system according to the internal communication mechanism of the processor.
3. The method according to claim 2, wherein Verification data is encoded in the first second preset number of code elements in the unit time coding frame, and the method further includes: When the first operating system decodes the first second preset number of code elements in the unit time coding frame, obtain the verification data, and transmit the verification data to the second operating system; After receiving the verification data, the second operating system uses the verification data to verify the received timestamp information; When the second operating system receives the time synchronization command, synchronizing the system time of the second operating system according to the timestamp information includes: In response to the time synchronization command, the second operating system synchronizes the system time of the second operating system using the timestamp information after verification.
4. The method according to claim 1, wherein The method further includes: The second operating system synchronizes the real-time clock of the processor at preset intervals; Whenever the second operating system detects a shutdown or restart event, it immediately synchronizes the real-time clock of the processor.
5. The method according to claim 2, characterized in that, The first operating system is an operating system with a trusted execution environment for the processor; the second operating system is an operating system with a rich execution environment for the processor; The step of transmitting a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system according to the internal communication mechanism of the processor includes: Transmitting a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system through an interrupt communication method that meets security standards between the trusted execution environment and the rich execution environment.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: When the control interface provided by the second operating system for the user layer is called, the second operating system transmits call parameters to the first operating system to trigger the first operating system to control the decoding of the serial encoded signal according to the call parameters.
7. A time synchronization device, characterized in that, The device includes: A first module, configured to instruct the first operating system running on the processor to obtain a serial encoded signal provided by a timing device; decode the serial encoded signal to obtain timestamp information of a unit-time encoded frame in the serial encoded signal; when obtaining the timestamp information, immediately transmit the timestamp information to the second operating system of the processor through an interrupt communication method between the first operating system and the second operating system; or, when obtaining the timestamp information, immediately write the timestamp information into a shared memory between the first operating system and the second operating system of the processor, so that the second operating system reads the timestamp information from the shared memory and transmits a time synchronization command triggered when decoding the unit-time encoded frame to the second operating system of the processor through an interrupt communication method between the first operating system and the second operating system; the processor is a processor based on the ARMv9 architecture; the first operating system is an operating system with a trusted execution environment for the processor; the second operating system is an operating system with a rich execution environment for the processor; the interrupt communication method is implemented through the SMC instruction in the ATF, and the ATF is the trusted system firmware of the arm processor; A second module, configured to instruct the second operating system to synchronize the system time of the second operating system according to the timestamp information when receiving the time synchronization command.
8. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Control method of high-quality satellite platform time synchronization errors
CN107065688A
Time synchronization method and device, computer equipment and storage medium
CN113672031A