Method and apparatus for synchronizing with a remote device
Patent Information
- Application Number
- CN202210102888.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-27
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2042-01-27
AI Technical Summary
一般来说,不同的时钟源之间存在误差,该误差来源于两个方面,一是不同设备的起始时间不同,如果一个设备本身没有实时时钟(RTC),则其在开机从零开始计时,与世界标准时(从1970年1月1日零时开始计时)就存在一个固定差距;二是时钟工作频率主要受晶振控制,而晶振的制造误差、温飘、时飘等都会导致时钟源与理想时钟之间存在误差
[0007]This invention provides a technical solution with a different technical concept, which can achieve time synchronization between devices by linear fitting based on two consecutively adjacent sampling points or two sampling points with a specific number of intervals, thereby solving the problem of clock inconsistency when devices cooperate.
Smart Images

Figure CN116560455B_ABST
Abstract
Description
Technical Field
[0001] This invention generally relates to the field of computers. More specifically, this invention relates to apparatus, methods, readable storage media, computer program products, and local devices for time synchronization with remote devices. Background Technology
[0002] Most computer devices are equipped with a clock source to provide a stable and level-matched square wave clock pulse signal. Generally, there are errors between different clock sources. These errors come from two aspects: First, different devices have different start times. If a device does not have a real-time clock (RTC), it starts counting from zero when it is powered on, which will have a fixed difference from Coordinated Universal Time (UTC) (which starts counting from 00:00 on January 1, 1970). Second, the clock operating frequency is mainly controlled by the crystal oscillator, and manufacturing errors, temperature drift, and time drift of the crystal oscillator can all cause errors between the clock source and the ideal clock.
[0003] Especially in distributed systems, for an event that needs to be tracked or measured, its start and end run on different devices or nodes, each using its own clock. If clock synchronization is not performed in advance, timing disorder may occur in their cooperation, making it impossible to integrate these devices or nodes. Summary of the Invention
[0004] In order to at least partially solve the technical problems mentioned in the background art, the present invention provides an apparatus, method, readable storage medium, computer program product, and local device for time synchronization with a remote device.
[0005] In one aspect, the present invention discloses a method for time synchronization with a remote device, comprising: obtaining a remote timestamp of a first sampling point; recording a local timestamp corresponding to the remote timestamp of the first sampling point; obtaining a remote timestamp of a second sampling point; recording a local timestamp corresponding to the remote timestamp of the second sampling point; and performing linear fitting based on the local timestamps and remote timestamps of the first and second sampling points to synchronize the time of the remote device.
[0006] In another aspect, the present invention discloses a computer-readable storage medium storing computer program code that is synchronized with a remote device, wherein the computer program code, when executed by a processing device, performs the methods described above. The present invention also discloses a computer program product comprising a computer program synchronized with a remote device, which, when executed by a processor, implements the steps of the aforementioned methods. The present invention further discloses a local device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the aforementioned methods.
[0007] This invention provides a technical solution with a different technical concept, which can achieve time synchronization between devices by linear fitting based on two consecutively adjacent sampling points or two sampling points with a specific number of intervals, thereby solving the problem of clock inconsistency when devices cooperate. Attached Figure Description
[0008] The above and other objects, features, and advantages of exemplary embodiments of the present invention will become readily apparent from the following detailed description taken in conjunction with the accompanying drawings. In the drawings, several embodiments of the invention are illustrated by way of example and not limitation, and like or corresponding reference numerals denote like or corresponding parts. Wherein:
[0009] Figure 1a This diagram illustrates the structure of a distributed system according to an embodiment of the present invention.
[0010] Figure 1b A schematic diagram of a heterogeneous computer system according to an embodiment of the present invention is shown;
[0011] Figure 2 This diagram illustrates an embodiment of the present invention where a local device connects to a remote device via an interface device.
[0012] Figure 3 This diagram illustrates a flowchart of time synchronization between an embodiment of the present invention and a remote device.
[0013] Figure 4 A schematic diagram illustrating the polling mechanism of an embodiment of the present invention is shown;
[0014] Figure 5 This diagram illustrates the calculation of the first average value according to an embodiment of the present invention;
[0015] Figure 6 This diagram illustrates a flowchart of time synchronization based on two sets of timestamps according to an embodiment of the present invention.
[0016] Figure 7 This diagram illustrates how an embodiment of the present invention calculates the slope based on two sets of timestamp pairs.
[0017] Figure 8 This is a schematic diagram illustrating linear fitting of two sampling points according to an embodiment of the present invention;
[0018] Figure 9 This illustrates a flowchart of another embodiment of the present invention and its time synchronization with a remote device;
[0019] Figure 10 This diagram illustrates the calculation of the average value according to another embodiment of the present invention;
[0020] Figure 11a This diagram illustrates the correction of the linear fitting result when the first sampling point and the second sampling point are adjacent sampling points.
[0021] Figure 11b This diagram illustrates the correction of the linear fitting result when the first sampling point is spaced one sampling point apart from the second sampling point. Detailed Implementation
[0022] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0023] It should be understood that the terms "first," "second," "third," and "fourth," etc., in the claims, specification, and drawings of this invention are used to distinguish different objects, rather than to describe a specific order. The terms "comprising" and "including" used in the specification and claims of this invention indicate the presence of the described features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or collections thereof.
[0024] It should also be understood that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this specification and claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations.
[0025] As used in this specification and claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection."
[0026] In the field of computer science, especially in distributed systems, clock synchronization is often required. For example, in heterogeneous computer systems, programmers program on their local devices and send computational tasks to remote devices via PCIe (Peripheral Component Interconnect Express) for execution. After the remote device completes the execution, it returns the results to the local device, where the programmer uses this data for adjustments. During the early development and optimization phases, programmers need to track the timestamps of the computational task at key points throughout its lifecycle. Some of these timestamps use the local device's time domain, while others use the remote device's time domain. Aligning these timestamps to the same timeline is essential. Furthermore, in distributed systems, devices can communicate with each other, and each device may have a different time domain (e.g., each device can act as a local device, using its own time domain, and other devices communicating with it can be considered remote devices). Therefore, to track the processing of the same task in a distributed system, it is necessary to synchronize the times of all devices to the same timeline.
[0027] Furthermore, since local and remote devices use different clock sources, and the actual operating frequency of a clock source in a real-world environment cannot be exactly the same as its nominal frequency, the accuracy of the clock source mainly depends on the accuracy of the crystal oscillator. PPM is commonly used to represent the deviation between its actual frequency and its nominal frequency. For example, if a crystal oscillator is nominally 1MHz and 10PPM, then the error per second of that crystal oscillator is: 10 / (10 6 )×(10 6 (Hz) = 10µs, meaning that the crystal oscillator will introduce a maximum error of 10 microseconds per second. Furthermore, the actual operating frequency of the crystal oscillator is not completely fixed and is affected by temperature, pressure, and time.
[0028] The actual test results showed that when taking the timestamps from both the local device and the remote device, the error value will continue to increase over time, but it is basically linear.
[0029] As can be seen from the above scenario, for an event that needs to be monitored, when the event is running on different devices and these devices have their own clocks, these clocks need to be synchronized in advance in order to observe the event correctly.
[0030] Therefore, one embodiment of the present invention provides a method for synchronizing the clocks of two devices, which can be applied to... Figure 1a The distributed system shown can also be applied to Figure 1b The heterogeneous computer system shown below illustrates specific embodiments of the invention in conjunction with the accompanying drawings.
[0031] Figure 1aThe diagram illustrates the structure of a distributed system according to an embodiment of the present invention. A distributed system may include multiple regions, each region having a local device 10 and multiple remote devices 11. The local device 10 manages the computer resources of the region globally, and the remote devices 11 act as edge nodes, providing complete computer resources to users.
[0032] Distributed systems are built on top of computer networks, so their physical structures are essentially the same. Local device 10 communicates with remote device 11 via the PCIe (Peripheral Component Interconnect Express) interface. When a user submits a request, local device 10 can select the most suitable remote device 11 from the system and submit the user's request to the processing program of that remote device 11. After the remote device 11 completes the task, it sends the result back to local device 10, which then sends the result back to the user. During this process, the user is unaware that multiple devices are collaborating. Of course, multiple remote devices 11 in a distributed system can also communicate and interconnect. One remote device 11 can communicate with other remote devices 11 for data or tasks to collaboratively complete task processing. Each remote device 11 can use... Figure 1b The chip 101 or board 12 shown. The clock synchronization method of this disclosure can be applied not only to... Figure 1a The time synchronization between the local device 10 and the remote device 11 can also be applied to Figure 1a Time synchronization between multiple remote devices 11.
[0033] Figure 1b This diagram illustrates a heterogeneous computer system according to this embodiment, which includes a board 12. As shown in Figure 1, the board 12 includes a chip 101, which is a system-on-a-chip (SoC) integrating one or more combined processing devices. These combined processing devices are artificial intelligence computing units used to support various deep learning and machine learning algorithms, meeting the intelligent processing needs of complex scenarios in fields such as computer vision, speech, natural language processing, and data mining. In particular, deep learning technology is widely used in cloud intelligence. A significant characteristic of cloud intelligence applications is the large volume of input data, placing high demands on the platform's storage and computing capabilities. The board 12 in this embodiment is suitable for cloud intelligence applications, possessing massive off-chip storage, on-chip storage, and powerful computing capabilities.
[0034] Chip 101 is connected to local device 10 via interface device 13. Data to be processed can be transmitted from local device 10 to chip 101 via interface device 13. The calculation results of chip 101 can be transmitted back to local device 10 via interface device 13. Depending on the application scenario, interface device 13 can have different interface forms, such as PCIe interface.
[0035] The board 12 also includes a storage device 104 for storing data, which includes one or more memory cells 105. The storage device 104 is connected to and transmits data with the controller 106 and the chip 101 via a bus. The controller 106 in the board 12 is configured to regulate the state of the chip 101. For this purpose, in one application scenario, the controller 106 may include a microcontroller (MCU).
[0036] Figure 2 This is a schematic diagram illustrating the connection between local device 10 and remote device 11 via interface device 13 in this embodiment. Figure 2 As shown, the chip 101 in the remote device 11 includes a computing unit 211, an interface device 13, a processing unit 212, and a remote memory 213.
[0037] The computing unit 211 is used to process input data such as computer vision, speech, natural language, and data mining, and is configured to execute user-specified operations. It is mainly implemented as a single-core intelligent processor or a multi-core intelligent processor to perform deep learning or machine learning calculations. It is a special artificial intelligence processor that can interact with the processing unit 212 to jointly complete the user-specified operations.
[0038] The processing unit 212, as a general-purpose processing device, performs basic controls including but not limited to data transfer, and starting and / or stopping the computing unit 211. Depending on the implementation, the processing unit 212 may be one or more types of processors, such as a central processing unit (CPU), a graphics processing unit (GPU), or other general-purpose and / or special-purpose processors. These processors include, but are not limited to, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs.
[0039] The remote memory 213 is used to store the data to be processed. It is DDR memory, typically 16G or larger, and is used to store the data of the computing unit 211 and / or the processing unit 212.
[0040] Interface device 13 is used to transmit data and control commands between chip 101 and local device 10. In this embodiment, interface device 13 is a PCIe interface, including multiple channels. Each channel is used for directional communication between devices. Two channels are exemplarily shown in the figure. The first channel includes a transmitting end 221 and a receiving end 222, responsible for data transmission from chip 101 to local device 10. The second channel includes a transmitting end 223 and a receiving end 224, responsible for data transmission from local device 10 to chip 101. In this embodiment, the interface device 13 is equipped with two symmetrical first and second channels, which can reduce data transmission errors and delays between local device 10 and remote device 12, thereby improving the time synchronization accuracy between the local device and the remote device.
[0041] Local device 10 is a general-purpose processing device that may include multiple processing units 231 and multiple local memories 232. The processing units 231 are used to perform the general tasks mentioned above, such as assigning a remote device to perform a specific task, and the local memories 232 are used to cache data.
[0042] Figure 3 This diagram illustrates a flowchart of time synchronization with remote devices in this embodiment. The method is executed by the local device, controlling time synchronization with all remote devices within the area to achieve clock synchronization. In this embodiment, the time synchronization task is primarily handled by the processing unit 231 of the local device 10, enabling the processing unit 212 in the remote device 11 to synchronize time based on information sent from the local device 10.
[0043] Since the time stamp error between the local device and the remote device is basically linear, this embodiment uses a linear function y = kx + b to linearly fit the relationship between the two. Time synchronization is performed every once in a while and the fitting result is updated to eliminate the temperature drift, time drift and error introduced by the crystal oscillator itself. Here, x is the time stamp of processing unit 212 (i.e., remote time stamp) and y is the time stamp of processing unit 231 (i.e., local time stamp).
[0044] Specifically, this embodiment uses a linear fit between two pairs of timestamps corresponding to two sampling points to obtain the temporal relationship between the local device and the remote device. Both the local device and the remote device periodically sample the time at each sampling point to generate a timestamp. Ideally, for each pair of timestamps at a sampling point (including the local timestamp and the remote timestamp), the time of both the local device and the remote device should be obtained simultaneously at the sampling point. However, in reality, due to the inevitable delay between the local device and the remote device, it is impossible to obtain the timestamps "simultaneously," and they can only be approximated as closely as possible.
[0045] In step 301, the remote device is initialized. First, the local device requests a block of memory from the remote device, namely remote memory 213, which is a shared storage space that both devices can access for communication. Next, the local device zeroes the value at a specific address in the remote memory and notifies the remote device via a remote procedure call (RPC) to create a polling thread for subsequent communication.
[0046] Polling is a mechanism by which a local device decides whether to provide services to a remote device. The local device periodically sends out queries to ask the remote device whether a specific service needs to be started. If so, the service is provided. After the service is completed, the query is sent out again, and the process is repeated until the polling function is turned off.
[0047] After the polling thread is created on the remote device, both the local and remote devices can access a specific address in the remote memory. They communicate by setting the value of that specific address to perform the task of recording timestamps. After polling starts, the remote device writes the first value to the specific address.
[0048] In step 302, when the local device polls the value at the specific address and finds that the value is the first value, it writes the second value to the specific address. In this embodiment, the first value is 1 and the second value is 2. That is, when the local device polls and finds that the value at the specific address is 1, it writes the value 2 to the specific address, changing its value from 1 to 2. When the value at the specific address in the remote memory changes from 1 to 2, this is the sampling point where the local device and the remote device sample their respective times. In this embodiment, the interval between each sampling point can be a fixed time. In other embodiments, the interval between each sampling point can also be non-fixed, such as random sampling at arbitrary intervals.
[0049] In step 303, while performing step 302, the local timestamp of the first sampling point is recorded. At the same time the local device writes the value 2 to the specific address, it also records the local timestamp of the local device and stores it in local memory 232 to confirm the local timestamp of the first sampling point.
[0050] In step 304, the remote timestamp of the first sampling point is obtained. When the remote device polls a specific address and finds that its value has changed to 2, it records the current time as the remote timestamp of the first sampling point and writes the remote timestamp to the remote memory. When the local device polls, it obtains the remote timestamp of the first sampling point from the remote memory and stores it in the local memory 232.
[0051] In step 305, the local timestamp corresponding to the remote timestamp of the first sampling point is recorded. Simultaneously, the local timestamp is recorded and stored in local memory 232 when the local device retrieves the remote timestamp of the first sampling point.
[0052] At this point, the local device obtains the local timestamp (first local timestamp) where the value 2 was written to a specific address in the first sampling point, the remote timestamp, and the local timestamp (second local timestamp) where the remote timestamp was retrieved.
[0053] Figure 4 The diagram illustrates the polling mechanism from another perspective. During remote device initialization, the local device clears the value at a specific address in the remote memory and notifies the remote device to create a polling thread for subsequent communication. The remote device then creates the polling thread and writes the value 1 to the specific address in the remote memory to notify the local device that the polling mechanism is in progress. When the local device polls and finds that the value at the specific address is 1, it writes the value 2 to the specific address and simultaneously records the first local timestamp of the first sampling point. Subsequently, the remote device polls the specific address and finds that its value has changed to 2, records the current time as the remote timestamp of the first sampling point, and writes this remote timestamp to the remote memory. When the local device polls the remote memory, it retrieves the remote timestamp of the first sampling point and records the current local timestamp. Through this polling mechanism, the local device obtains the first local timestamp, the remote timestamp, and the second local timestamp of the first sampling point.
[0054] In this embodiment, by creating real-time polling threads in both the local and remote devices, the overhead of acquiring sampling points (including local and remote timestamps) is reduced, thereby ensuring the accuracy of the acquired sampling points. This does not limit the invention to using other methods to acquire single sampling points; for example, the local device can directly notify the remote device to record the remote timestamp via an interrupt.
[0055] Back Figure 3Since linear fitting requires at least two sampling point timestamps, this embodiment repeats the aforementioned steps to obtain the local timestamp (first local timestamp) where the value 2 is written to a specific address, the remote timestamp, and the local timestamp (second local timestamp) where the remote timestamp is retrieved, for the second sampling point. Specifically, the local timestamp of the second sampling point is recorded in step 306, the remote timestamp of the second sampling point is obtained in step 307, and the local timestamp corresponding to the remote timestamp of the second sampling point is recorded in step 308. The operations of steps 306 to 308 are no different from those of steps 303 to 305, and therefore will not be described in detail.
[0056] As mentioned earlier, both the local and remote devices periodically sample time at sampling points, possibly every 1 second, 3 seconds, or 5 seconds, meaning each sampling point is spaced 1 second, 3 seconds, or 5 seconds apart. It is important to note that in this embodiment, the first and second sampling points can be adjacent sampling points or spaced a specific number of times apart.
[0057] The first and second sampling points can be any two of many sampling points, as long as the second sampling point occurs after the first sampling point. However, considering that it is more reasonable for the system to synchronize time based on the latest time error, the second sampling point is preferably the most recent sampling point. That is, in this embodiment, the most recent sampling point is first set as the second sampling point, and then the first sampling point is determined. If the first and second sampling points are adjacent sampling points, the first sampling point is set as the sampling point before the most recent sampling point; if the first and second sampling points are separated by a certain number of sampling points, the first sampling point is set as the sampling point that is separated from the most recent sampling point by a certain number of sampling points. The first local timestamp, second local timestamp, and remote timestamp of the first sampling point are extracted and linearly fitted with the first local timestamp, second local timestamp, and remote timestamp of the second sampling point. Regardless of whether the first and second sampling points are adjacent sampling points or separated by several sampling points, in this embodiment, the new sampling point generated in each period is set as the second sampling point, and then the first sampling point is determined by backtracking. The first and second sampling points are obtained for time synchronization in each sampling period.
[0058] After obtaining the first local timestamp, second local timestamp, and remote timestamp of the first sampling point and the first local timestamp, second local timestamp, and remote timestamp of the second sampling point, step 309 is executed to calculate the first average value of the local timestamp of the first sampling point and the local timestamp corresponding to the remote timestamp of the first sampling point. Figure 5 This diagram illustrates how the first average value is obtained in this embodiment.
[0059] As shown above, when the local device detects that the value at a specific address is 1, it writes the value 2 to the specific address and simultaneously records the first local timestamp 501 of the first sampling point. Subsequently, when the remote device polls the specific address and finds that its value has changed to 2, it records the current time as the remote timestamp 502 of the first sampling point. When the local device polls, it retrieves the remote timestamp 502 of the first sampling point and records the second local timestamp 503. In this embodiment, the time taken for the local device to transmit information to the remote device and the time taken for the remote device to transmit information to the local device are considered to be approximately the same, that is, the triangle 504 formed by the first local timestamp 501, the remote timestamp 502, and the second local timestamp 503 in the figure is an isosceles triangle. Accordingly, the time point when the remote timestamp 502 occurs should fall at the midpoint of the first local timestamp 501 and the second local timestamp 503 on the local end, which is the average value 505 of the first local timestamp 501 and the second local timestamp 503.
[0060] For the reasons mentioned above, in this step, the local device calculates a first average value for the local timestamp of the first sampling point and the local timestamp corresponding to the remote timestamp of the first sampling point. That is, it calculates the average value 505 of the first local timestamp 501 and the second local timestamp 503. The average value 505 reflects the local timestamp of the remote timestamp 502 corresponding to the time of the local device. The remote timestamp 502 and the first average value 505 are the timestamp pair of the first sampling point, both of which are stored in the local memory 232.
[0061] In step 310, a second average is calculated between the local timestamp of the second sampling point and the local timestamp corresponding to the remote timestamp of the second sampling point. The method by which the local device calculates the second average is also based on... Figure 5 As shown in the diagram, the second average value is the average of the first local timestamp and the second local timestamp of the second sampling point. The second average value represents the local timestamp corresponding to the remote timestamp of the second sampling point to the local device time. The remote timestamp and the second average value of the second sampling point are the timestamp pair of the second sampling point, and are also stored in local memory 232.
[0062] In step 311, the remote device is synchronized with the local and remote timestamps of the first and second sampling points. As mentioned earlier, at least two sets of sampling point data are required for linear fitting. The timestamp pair of the first sampling point obtained in step 309 is the first set, and the timestamp pair of the second sampling point obtained in step 310 is the second set. Figure 6 The flowchart shows the time synchronization process based on these two sets of timestamps.
[0063] In step 601, the slope is calculated based on the first and second average values, and the far-end timestamps of the first and second sampling points. The local device calculates the slope of the linear fit based on the above two sets of timestamp pairs. Figure 7 This diagram illustrates how this embodiment calculates the slope based on two sets of timestamp pairs, where the horizontal axis of the coordinate system represents the remote timestamp and the vertical axis represents the local timestamp. The coordinates of the timestamp pair of the first sampling point are (x1, y1), and the coordinates of the timestamp pair of the second sampling point are (x2, y2), as shown in the figure. Point A represents the timestamp pair of the first sampling point, and point B represents the timestamp pair of the second sampling point. As mentioned earlier, this embodiment uses y = kx + b for linear fitting. Given the coordinates of points A and B, the local device can calculate the values of k and b, i.e.:
[0064]
[0065]
[0066] Therefore, the expression for line segment AB is:
[0067]
[0068] Since k is the slope of line segment AB, the local device obtains the slope of this line segment. Therefore, this embodiment can perform time synchronization of the remote device based on the linear fitting expression determined by line segment AB. For example, according to the above expression for line segment AB and the local timestamp of the next moment, the corresponding remote timestamp of the next moment is calculated to achieve clock synchronization between the local device and the remote device.
[0069] Furthermore, to improve the accuracy and precision of time synchronization, the method in this embodiment may further include:
[0070] In step 602, the slope is reduced by 1 to generate an error value. Regardless of whether the first and second sampling points are adjacent or separated by only a few sampling points, the error between the local and remote devices at these two sampling points is extremely small. In other words, the slope k is a number very close to 1, for example, 1.000003231. Some devices have insufficient floating-point arithmetic precision, and aligning with such a small decimal place may lead to information loss. To solve this problem, the local device needs to shift the decimal places. In this step, the slope k is first reduced by 1 to generate an error value, that is, only the decimal places are left. In the example above, the error value is 0.000003231.
[0071] In step 603, the decimal part of the error value is shifted to an integer part to generate the amplified error value. The local device shifts the decimal part of the error value to an integer part, and the expression for the amplified error value is:
[0072]
[0073] Where N is a positive integer. If N is 9, the above error value, after being amplified, is 3231. After this conversion, it is equivalent to turning the decimal part of the slope k into an integer. By using integers for comparison, the risk of insufficient accuracy of some devices can be avoided.
[0074] In step 604, the amplified error value, the local timestamp of the second sampling point, and the remote timestamp are sent to the remote device. The local device sends the timestamp pair of the second sampling point and the amplified error value, etc., to the remote memory via a remote procedure call. With this information, the remote device can synchronize the remote clock with the local device's clock based on the characteristics of line segment AB to complete the time synchronization.
[0075] At this point, this embodiment has completed the time synchronization operation based on the first and second sampling points, and the system will execute it periodically. Figure 3 The process is designed to enable time synchronization at each sampling point.
[0076] Figure 8 This diagram illustrates the linear fitting of two sampling points in this embodiment. Starting from x0, the system performs time-synchronization sampling at fixed intervals. Taking sampling point x0 as an example, the timestamp pair obtained by the local device corresponds to point C. However, since each sampling has positive and negative errors, the actual timestamp pair will fall between C1 and C2, where C1 is the timestamp pair with the largest positive error and C2 is the timestamp pair with the largest negative error. At the next sampling point x1, the timestamp pair obtained by the local device is point D. Similarly, the actual timestamp pair will fall between D1 and D2. Since the error at each sampling point is approximately the same, the length of line segment C1C2 is approximately equal to the length of line segment D1D2.
[0077] When performing linear fitting using timestamp pairs of two adjacent sampling points (such as points C and D), it is necessary to calculate the expression for line segment CD, and then deduce that the local timestamp of the next sampling point x2 is the local timestamp corresponding to point E. However, when considering the errors of points C and D, it is found that the error range of estimating the local timestamp of the next sampling point based on two adjacent sampling points is the length of line segment E1E2. That is, the maximum error of the derived local timestamp occurs at point E1, which extends from line segment C2D1, and at point E2, which extends from line segment C1D2. If linear fitting is performed using timestamp pairs (points F and G) with an interval of one sampling point (sampling point x3 and sampling point x5), the local timestamp of the next sampling point x6 is calculated as the local timestamp corresponding to point H. Considering the errors, the error range of the local timestamp of sampling point x6 is the length of line segment H1H2, and the maximum error occurs at points H1 and H2.
[0078] from Figure 8It can be intuitively seen, or through mathematical derivation, that the length of line segment H1H2 is less than the length of line segment E1E2. This means that extending the sampling time helps reduce timing errors and improve timing accuracy. While maintaining a constant sampling point period, a design that samples at specific intervals has better technical performance. However, indefinitely increasing the number of intervals does not necessarily lead to better timing accuracy, because excessively long intervals between the first and second sampling points introduce other uncertainties, making the error more complex. For example, if the clock source frequency drift caused by changes in temperature and pressure cannot be accurately tracked, the timing error will increase. Preferably, the specific number of interval sampling points should be a range. Since each device is unique, the number of intervals between the first and second sampling points cannot be generalized; those skilled in the art should determine the most ideal number of intervals based on the actual situation. In this embodiment, an interval of 1 to 5 sampling points between the first and second sampling points is preferable, with 2 or 3 sampling points being more ideal.
[0079] As an optional implementation, the aforementioned range of sampling points and the time interval between sampling points can be determined based on the jump error of the sampling points. Specifically, this embodiment can determine the timestamp pair corresponding to the next sampling point based on the first and second sampling points of the interval; further, this embodiment can obtain the actual timestamp pair by sampling at the next sampling point, and then calculate the jump error based on the calculated timestamp pair and the actual sampled timestamp pair. When the jump error is within a preset range, the number of intervals between the first and second sampling points can be used as a specific number of intervals between the first and second sampling points. For example, this embodiment can calculate the first timestamp pair by fitting the first and second sampling points, where the interval between the first and second sampling points is n sampling points, where n is a positive integer. Then, the error between the first timestamp pair (based on the sampled timestamp pair) and the second timestamp pair (actually sampled timestamp pair) is calculated. When the first timestamp pair and the second timestamp pair are within a preset range, it can be determined that the interval between the first and second sampling points can be n sampling points. In other words, the local device determines whether the difference between the local timestamps of the first and second sampling points is greater than a threshold, which is set by those skilled in the art based on experience. If so, it indicates that the difference is too large and the jump is severe.
[0080] Furthermore, this embodiment can calculate multiple different first timestamp pairs based on sampling points with different intervals between the first and second sampling points, and calculate the transition error between each of these multiple different first timestamp pairs and the second timestamp pair, and determine a specific number of intervals between the first and second sampling points based on the multiple transition errors. For example, this embodiment can calculate the average or variance of the error based on the multiple transition errors. If the average or variance of the error is greater than a preset range, the number of intervals between the first and second sampling points is re-determined. If the average or variance of the error is within a preset range, the number of intervals corresponding to the set of sampling points with the smallest transition error can be used as the number of intervals between the first and second sampling points, or the number of intervals corresponding to the sampling points with transition errors close to the average or variance of the error can be used as the number of intervals between the first and second sampling points.
[0081] Similarly, the time interval between the above sampling points can also be determined using the above method.
[0082] Another embodiment of the present invention is a heterogeneous system for time synchronization between a local device and a remote device, used to synchronize the clocks of the two devices. The system is also... Figure 1a , Figure 1b and Figure 2 The structure shown. Figure 9 The flowchart illustrating time synchronization with a remote device in this embodiment is shown. This method is executed by the local device to achieve clock synchronization. Similarly, in this embodiment, the processing unit 231 of the local device 10 is responsible for the time synchronization task, and the processing unit 212 of the remote device 11 receives information from the local device 10 to adjust the clock of the remote device 11. The processing unit 231 communicates with the processing unit 212 through the interface device 13 and uses a linear function y = kx + b to linearly fit the relationship between the two, thereby eliminating the temperature drift, time drift, and errors introduced by the crystal oscillator and the time synchronization itself.
[0083] In step 901, the transmission efficiency between the local device and the interface is optimized. Here, the interface refers to interface device 13. The previous embodiment assumed that the time taken for the local device to transmit information to the remote device is approximately the same as the time taken for the remote device to transmit information to the local device. More specifically, it is assumed that the path length of the first channel of interface device 13 is approximately the same as the path length of the second channel.
[0084] In fact, due to the completely different affinity between the receiver 222 – local memory 232 – processing unit 231 and the receiver 224 – remote memory 213 – processing unit 212, the path length of the first channel often differs significantly from that of the second channel. This results in a significant discrepancy between the time taken for the local device to transmit information to the remote device and the time taken for the remote device to transmit information to the local device. Figure 5The ideal state is shown. Specifically, the difference in path length between the first and second channels depends on the path lengths of receiver 222 – local memory 232 – processing unit 231 and receiver 224 – remote memory 213 – processing unit 212. In this embodiment, the path length of receiver 222 – local memory 232 – processing unit 231 is greater than the path length of receiver 224 – remote memory 213 – processing unit 212, making the information transmission time between the local device and the remote device more similar. Figure 10 The situation shown. Clearly, Figure 10 The triangle 504 formed by the first local timestamp 501, the remote timestamp 502, and the second local timestamp 503 is not an isosceles triangle. Therefore, the time point of the remote timestamp 502 will not fall at the midpoint of the first local timestamp 501 and the second local timestamp 503 when mapped to the local device, resulting in errors in time synchronization calculations. This embodiment optimizes the transmission efficiency of the local device and interface, promoting... Figure 10 The relationship between the various timestamps is close to that of Figure 5 This approach optimizes the transmission path between the local and remote devices to improve the accuracy of a single time synchronization, thereby ensuring the time synchronization accuracy between the local and remote devices. This embodiment offers various methods for optimizing the transmission efficiency between the local device and the interface.
[0085] One optimization method is to designate the local memory 232 with the shortest transmission distance to the interface device 13 to store the remote timestamp. Since the local device has multiple local memory units 232, it can designate the local memory unit 232 closest to the receiver 222 as the local memory for storing relevant parameters, thereby shortening the path length from the receiver 222 to the local memory 232. After determining the local memory unit 232, the local device further designates the processing unit 231 with the shortest transmission distance to the local memory 232 to perform the time synchronization operation. The local device also has multiple processing units 231, and it can designate the processing unit 231 closest to the local memory 232 as the processing unit for performing the time synchronization operation, thereby shortening the path length from the local memory 232 to the processing unit 231. In this way, the path length from the receiver 222 to the local memory 232 to the processing unit 231 is as close as possible to the path length from the receiver 224 to the remote memory 213 to the processing unit 212.
[0086] Another optimization method is to increase the operating frequency of the local device's processing unit 231. The local device increases the operating frequency of the processing unit 231 so that the operating frequency of the processing unit 231 is higher than that of the processing unit 212. By speeding up the operation of the local device, the asymmetry problem caused by the excessively long path length of the receiver 222 - local memory 232 - processing unit 231 can be compensated.
[0087] Another optimization approach is to dedicate the resources of the local device's processing unit 231 to the time between obtaining the remote timestamp of the first sampling point and recording the local timestamp of the second sampling point. Because the processing unit 231's work is more complex than that of the processing unit 212, which focuses on performing deep learning or machine learning tasks, it is often interrupted by other tasks during time synchronization operations, causing time synchronization polling to be interrupted and exacerbating latency. The local device can force the processing unit 231's resources to be dedicated to time synchronization polling during the time synchronization period to mitigate the deterioration of latency.
[0088] The optimization methods for this step are not limited to those mentioned above. Those skilled in the art can optimize transmission efficiency according to actual conditions, and this step is not limited to using only one optimization method; for example, the above three methods can be used simultaneously. It should be clear that the above optimization methods can be executed individually to improve the accuracy of a single time synchronization. Of course, the above optimization methods can also be combined with the following steps, as described below.
[0089] In step 902, the remote device is initialized. The local device clears the value at a specific address in the remote memory and notifies the remote device via a remote procedure call to create a polling thread for subsequent communication. After polling begins, the remote device writes a first value to the specific address in the remote memory.
[0090] In step 903, when the local device polls the value of the specific address and finds that the value is the first value, it writes the second value to the specific address.
[0091] In step 904, while executing step 903, the local timestamp of the second sampling point is recorded. The second sampling point is the most recent sampling point. In step 905, the remote timestamp of the second sampling point is obtained. In step 906, the local timestamp corresponding to the remote timestamp of the second sampling point is recorded. The operations of steps 904 and 906 are the same as those of steps 303 and 305, respectively, and therefore will not be described in detail.
[0092] In step 907, it is determined whether a first sampling point that meets the conditions exists. If the first sampling point is set as an adjacent sampling point, except in the initial stage of the system where there is only one sampling point, it is certain that the previous sampling point of the second sampling point can be found. Step 908 is then executed, setting the adjacent sampling point as the first sampling point. If the first sampling point is set as a sampling point separated from the second sampling point by a specific number of sampling points, since the second sampling point is the closest sampling point, the local device checks backwards to see if there are any sampling points separated from the second sampling point by a specific number of sampling points. If so, step 908 is executed, setting the sampling point separated from the second sampling point by a specific number of sampling points as the first sampling point; if not, this generally occurs when the system has just started and there are not enough sampling points. In this case, step 909 is executed, setting the sampling point with the furthest interval as the first sampling point, which is usually the initial sampling point after the system starts. Figure 8 The sampling point x0 in the sample.
[0093] In step 910, the local timestamp of the first sampling point is retrieved from local memory. In step 911, the remote timestamp of the first sampling point is retrieved from local memory. These timestamps have already been obtained and stored in local memory through polling at the first sampling point. The polling mechanism is the same as in the previous embodiment and will not be described again.
[0094] In step 912, the local timestamp corresponding to the remote timestamp of the first sampling point is recorded.
[0095] In step 913, the average value of the local timestamp of the second sampling point and the local timestamp corresponding to the remote timestamp of the second sampling point is calculated, and the remote timestamp of the second sampling point and the average value are the timestamp pair of the second sampling point.
[0096] In step 914, the remote device is synchronized with the local timestamp and remote timestamp of the first and second sampling points. That is, a linear fit is performed based on the local timestamp and remote timestamp of the first and second sampling points to obtain a linear fit result, so as to realize the time synchronization between the devices based on the linear fit result.
[0097] Further optionally, in this embodiment, the above-described linear fitting time synchronization step can be performed once at any sampling point. Since the linear fitting steps at different sampling points use different sampling points, this will cause a jump in the timestamp of the same sampling point. Based on this, the method of this embodiment can also correct the current linear fitting result based on at least one historical linear fitting result, wherein the correction process for the linear fitting result is equivalent to correcting the linear fitting slope. In several embodiments, the above-described time synchronization step can be performed once at each sampling point; therefore, the correction step can be performed once at each sampling point. See the description below for details.
[0098] Figure 11aThis diagram illustrates the correction of the linear fitting result when the first and second sampling points are adjacent. In other words, given the previous sampling point x... i timestamp pairs and sampling point x i+1 After the timestamp pair, self-sampling point x i+1 Then all the way to sampling point x i+2 (i.e., sampling point x) i+1 sampling point x i+2 The clock of the remote device is obtained by using the previous sampling point x. i and sampling point x i+1 The timestamps are used for fitting.
[0099] After obtaining the timestamp pair (P point) for sampling point x0 and the timestamp pair (Q point) for sampling point x1, the y = k calculated using points P and Q is obtained. 01 x+b 01 As a fitting result, the local timestamp corresponding to the predicted far-end timestamp x2 should be the local timestamp corresponding to point R. Therefore, (sampling point x1, sampling point x2) is based on the fitting slope k. 01 The corresponding line segment QR is timed; while the clock of the remote device at sampling point x3 uses the timestamp pair of sampling point x1 (Q point) and the timestamp pair of sampling point x2 (S point) to calculate y = k. 12 x+b 12 As a fitting result, the local timestamp corresponding to the predicted remote timestamp x3 should be the local timestamp corresponding to point T.
[0100] As shown in the diagram, the local timestamp at sampling point x2 jumps because different timestamp pairs are used for calculations before and after x2. If the remote device obtains the corresponding local timestamps before and after sampling point x2 for time synchronization, a situation may occur where the earlier remote timestamp is later than the later remote timestamp, leading to timing disorder. This type of jump problem occurs at each sampling point.
[0101] To avoid the aforementioned jump, this embodiment does not use y = k between (sampling point x2, sampling point x3). 12 x+b 12 Instead of aligning time using (sampling point x2, sampling point x3), time alignment is performed using line segment RT. Therefore, the local timestamp corresponding to sampling point x2 is the local timestamp of point R, not the local timestamp of point S, to avoid errors caused by time jumps. That is, based on the historical fitting result y = k 01 x+b 01 and y=k 12 x+b 12Calculate the local timestamps corresponding to sampling points x2 and x3 respectively. Then, based on the timestamp pairs calculated by the linear fitting (i.e., the timestamp pairs corresponding to points R and T), calculate the linear fitting slope of (sampling point x2, sampling point x3). This linear fitting slope is not equal to the k mentioned above. 12 This involves the process of recalculating the slope and correcting the fitting results.
[0102] Similarly, the clock of the remote device at sampling point x4 is calculated using the timestamp pair (S point) of sampling point x2 and the timestamp pair (U point) of sampling point x3, yielding y = k. 23 x+b 23 As a fitting result, the local timestamp corresponding to the predicted remote timestamp x4 after time synchronization should be the local timestamp corresponding to point V, while (sampling point x3, sampling point x4) is time synchronized using line segment TV.
[0103] Depend on Figure 11a It can be seen that there are no breakpoints at sampling points x2 and x3, so there will be no time jump error. Other sampling points also update their local timestamps in the same way as described above, so that there are no breakpoints at any sampling point.
[0104] Figure 11b This diagram illustrates the correction of the linear fitting result when the first and second sampling points are spaced one sampling point apart. It is assumed that the clock of the remote device at sampling point x3 is calculated using the timestamp pair (point I) of sampling point x0 and the timestamp pair (point J) of sampling point x2, resulting in y = k. 01 x+b 01 As a fitting result, the local timestamp corresponding to the remote timestamp x3 should be the local timestamp corresponding to point K; while the clock of the remote device at sampling point x4 is calculated using the timestamp pair of sampling point x1 (point L) and the timestamp pair of sampling point x3 (point M), resulting in y = k. 12 x+b 12 As a fitting result, the local timestamp corresponding to the predicted remote timestamp x4 should be the local timestamp corresponding to point O.
[0105] As shown in the diagram, the local timestamp of sampling point x3 jumps due to the use of different timestamp pairs in the two calculations. If the remote device obtains the corresponding local timestamps before and after sampling point x3 for time synchronization, a situation may occur where the earlier remote timestamp is later than the later remote timestamp, leading to timing disorder. This type of jump problem occurs at each sampling point.
[0106] To avoid the aforementioned jump, this embodiment does not use y=k between (sampling point x3, sampling point x4). 12 x+b 12Instead of aligning the time using sampling point x3, sampling point x4, we now use line segment KO for time alignment. Therefore, the local timestamp corresponding to sampling point x3 is the local timestamp of point K, not the local timestamp of point M, to avoid errors caused by time jumps. That is, based on the historical fitting result y = k 01 x+b 01 and y=k 12 x+b 12 Calculate the local timestamps corresponding to sampling points x3 and x4 respectively. Then, based on the timestamp pairs calculated by the linear fitting (i.e., the timestamp pairs corresponding to points K and O), calculate the linear fitting slope of (sampling point x3, sampling point x4). This linear fitting slope is not equal to the aforementioned k. 12 This involves the process of recalculating the slope and correcting the fitting results.
[0107] Similarly, the clock of the remote device at sampling point x5 is calculated using the timestamp pair from sampling point x2 (point J) and the timestamp pair from sampling point x4 (point N), yielding y = k. 23 x+b 23 As a fitting result, the local timestamp corresponding to the predicted remote timestamp x5 after time synchronization should be the local timestamp corresponding to point W, while (sampling point x4, sampling point x5) is synchronized using line segment OW.
[0108] Depend on Figure 11b It can be seen that there are no breakpoints at sampling points x3 and x4, so there will be no time jump error. Other sampling points also update their local timestamps in the same way as described above, so that there are no breakpoints at any sampling point.
[0109] like Figure 11a As shown, when the local device performs pairing based on line segment RT and line segment TV (sampling point x2, sampling point x4), as follows: Figure 11b As shown, the local device synchronizes time based on the pair of line segments KO and OW (sampling point x3, sampling point x4). In this way, the timestamp pair at each sampling point is continuous, meaning one line segment follows the next, forming a connected polyline without any breaks, thus avoiding time errors caused by jumps in timestamp pairs. The time synchronization method in this embodiment is no different from the previous embodiment, so it will not be described in detail.
[0110] At this point, this embodiment has completed the time synchronization operation based on the first and second sampling points, and the system will execute it periodically. Figure 9 The process is designed to achieve time synchronization without jumps at each sampling point.
[0111] Another embodiment of the present invention is a computer-readable storage medium storing computer program code that is synchronized with a remote device. When the computer program code is run by a processing device, it performs actions such as... Figure 3, Figure 9 The method described herein. Another embodiment of the present invention is a computer program product, including a computer program for communicating with a remote device, characterized in that, when the computer program is executed by a processor, it implements as follows: Figure 3 , Figure 9 The steps of the method. Another embodiment of the invention is a local device, such as local device 10, including a memory (local memory 232), a processor (processing unit 231), and a computer program stored on the memory, characterized in that the processor executes the computer program to implement as... Figure 3 , Figure 9 The steps of the method are described.
[0112] In some implementation scenarios, the integrated unit described above can be implemented as a software program module. If implemented as a software program module and sold or used as an independent product, the integrated unit can be stored in a computer-readable storage device (CMSDD). Therefore, when the solution of this invention is embodied in a software product (e.g., a computer-readable storage medium, a computer program product, etc.), the software product can be stored in a memory, which may include several instructions to cause a computer device (e.g., a personal computer, a server, or a network device, etc.) to execute some or all of the steps of the method described in the embodiments of this invention. The aforementioned memory may include, but is not limited to, various media capable of storing program code, such as USB flash drives, flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0113] This invention provides a technical solution with a different technical concept, which can perform time synchronization based on two adjacent sampling points, or by using two sampling points spaced a specific number of times apart, and performing time synchronization based on the local timestamp and remote timestamp corresponding to these two sampling points respectively. At the same time, it eliminates the jump problem caused by breakpoints. This invention can improve the accuracy of time synchronization and has better technical effects compared with the prior art.
[0114] Depending on the application scenario, the electronic devices or apparatus of the present invention may include servers, cloud servers, server clusters, data processing devices, robots, computers, printers, scanners, tablet computers, smart terminals, PC devices, IoT terminals, mobile terminals, mobile phones, dashcams, navigators, sensors, cameras, video cameras, projectors, watches, headphones, mobile storage, wearable devices, visual terminals, autonomous driving terminals, vehicles, home appliances, and / or medical devices. The vehicles include airplanes, ships, and / or vehicles; the home appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, lights, gas stoves, and range hoods; the medical devices include MRI scanners, ultrasound machines, and / or electrocardiographs. The electronic devices or apparatus of the present invention can also be applied in fields such as the Internet, IoT, data centers, energy, transportation, public management, manufacturing, education, power grids, telecommunications, finance, retail, construction sites, and healthcare. Furthermore, the electronic devices or apparatus of the present invention can also be used in application scenarios related to artificial intelligence, big data, and / or cloud computing, such as cloud computing, edge computing, and terminal computing. In one or more embodiments, the high-computing-power electronic devices or apparatuses according to the present invention can be applied to cloud devices (e.g., cloud servers), while the low-power electronic devices or apparatuses can be applied to terminal devices and / or edge devices (e.g., smartphones or cameras). In one or more embodiments, the hardware information of the cloud devices and the hardware information of the terminal devices and / or edge devices are compatible with each other, so that suitable hardware resources can be matched from the hardware resources of the cloud devices to simulate the hardware resources of the terminal devices and / or edge devices based on the hardware information of the terminal devices and / or edge devices, so as to complete the unified management, scheduling and collaborative work of end-to-cloud or cloud-edge-end integration.
[0115] It should be noted that, for the sake of brevity, this invention describes some methods and their embodiments as a series of actions and combinations thereof. However, those skilled in the art will understand that the solution of this invention is not limited to the order of the described actions. Therefore, based on the disclosure or teachings of this invention, those skilled in the art will understand that some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art will understand that the embodiments described in this invention can be considered as optional embodiments, that is, the actions or modules involved are not necessarily essential for the implementation of one or more solutions of this invention. In addition, depending on the solution, the description of some embodiments of this invention also has different emphases. In view of this, those skilled in the art will understand that parts not described in detail in a certain embodiment of this invention can also refer to the relevant descriptions of other embodiments.
[0116] In terms of specific implementation, based on the disclosure and teachings of this invention, those skilled in the art will understand that the several embodiments disclosed herein can also be implemented in other ways not disclosed herein. For example, regarding the various units in the electronic device or device embodiments described above, this document has divided them based on logical functions, but in actual implementation, there may be other ways of division. As another example, multiple units or components can be combined or integrated into another system, or some features or functions in a unit or component can be selectively disabled. Regarding the connection relationship between different units or components, the connection discussed above in conjunction with the accompanying drawings can be a direct or indirect coupling between units or components. In some scenarios, the aforementioned direct or indirect coupling involves a communication connection utilizing an interface, wherein the communication interface can support electrical, optical, acoustic, magnetic, or other forms of signal transmission.
[0117] In this invention, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units. The aforementioned components or units may be located in the same position or distributed across multiple network units. Furthermore, depending on actual needs, some or all of the units can be selected to achieve the purpose of the solution described in the embodiments of this invention. Additionally, in some scenarios, multiple units in the embodiments of this invention may be integrated into one unit or each unit may exist physically independently.
[0118] In other implementation scenarios, the integrated units described above can also be implemented in hardware, i.e., as specific hardware circuits, which may include digital circuits and / or analog circuits. The physical implementation of the circuit's hardware structure may include, but is not limited to, physical devices, which may include, but are not limited to, transistors or memristors. Therefore, the various devices described herein (e.g., computing devices or other processing devices) can be implemented using appropriate hardware processors, such as central processing units, GPUs, FPGAs, DSPs, and ASICs. Furthermore, the aforementioned storage units or storage devices can be any suitable storage medium (including magnetic storage media or magneto-optical storage media), such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), ROM, and RAM.
[0119] The foregoing can be better understood in accordance with the following terms:
[0120] Clause A1. A method for time synchronization with a remote device, comprising: obtaining a remote timestamp of a first sampling point; recording a local timestamp corresponding to the remote timestamp of the first sampling point; obtaining a remote timestamp of a second sampling point; recording a local timestamp corresponding to the remote timestamp of the second sampling point; and performing linear fitting based on the local timestamp and remote timestamp of the first and second sampling points to synchronize the time of the remote device.
[0121] Clause A2. The method according to Clause A1 further includes: initializing the remote device before obtaining the remote timestamp of the first sampling point.
[0122] Clause A3. The method according to Clause A2, wherein the initialization step includes: zeroing the value at a specific address in the remote memory of the remote device; notifying the remote device to create a polling thread; and polling the value at the specific address.
[0123] Clause A4. The method according to Clause A3 further includes: when the value is a first value, writing a second value to the specific address; and recording a local timestamp of the first sampling point while performing the writing step.
[0124] Clause A5. The method according to Clause A3, wherein the remote timestamp is the time when the remote device polls the specific address and determines that the value is the second value.
[0125] Clause A6. The method according to Clause A1, wherein the remote device communicates with the local device via an interface, the method further comprising: optimizing the transmission efficiency between the local device and the interface.
[0126] Clause A7. The method according to Clause A6, wherein the optimization step includes: specifying a local memory with the shortest transmission distance to the interface to store the remote timestamp; and specifying a processing unit with the shortest transmission distance to the local memory to perform the time synchronization step.
[0127] Clause A8. The method according to Clause A6, wherein the optimization step includes: increasing the operating frequency of the processing unit of the local device.
[0128] Clause A9. The method according to Clause A6, wherein the optimization step includes: dedicating the resources of the processing unit of the local device between obtaining the remote timestamp of the first sampling point and recording the local timestamp of the second sampling point.
[0129] Clause A10. The method according to any one of Clauses A1-9 further includes: recording a local timestamp of the second sampling point; calculating a first average value of the local timestamp of the first sampling point and the local timestamp corresponding to the remote timestamp of the first sampling point; and calculating a second average value of the local timestamp of the second sampling point and the local timestamp corresponding to the remote timestamp of the second sampling point; wherein the time synchronization step performs linear fitting based on the first and second average values, the first sampling point and the remote timestamp of the second sampling point.
[0130] Clause A11. The method according to Clause A10, wherein the time synchronization step comprises: calculating a slope based on the first and second average values, the far-end timestamps of the first and second sampling points.
[0131] Clause A12. The method according to Clause A11, wherein the time synchronization step comprises: subtracting 1 from the slope to generate an error value; and shifting the decimal part of the error value to an integer part to generate an amplified error value.
[0132] Clause A13. The method according to Clause A12, wherein the time synchronization step includes: sending the amplified error value, the local timestamp of the second sampling point, and the remote timestamp to the remote device.
[0133] Clause A14. The method according to Clause A1, wherein the first and second sampling points are spaced apart by a specific number of sampling points.
[0134] Clause A15. The method according to Clause A14 further includes: determining whether there is a sampling point spaced apart from the second sampling point by the specified number of sampling points; and if not, setting the sampling point with the furthest interval as the first sampling point.
[0135] Clause A16. The method according to Clause A1, wherein the method includes: correcting the linear fit result based on at least one historical linear fit result.
[0136] Clause A17. A computer-readable storage medium having stored thereon computer program code that is synchronized with a remote device, and which, when run by a processing device, performs the method described in any one of Clauses A1 to A16.
[0137] Clause A18. A computer program product comprising a computer program that interacts with a remote device, characterized in that, when the computer program is executed by a processor, it implements the steps of the method described in any one of Clauses A1 to A16.
[0138] Clause A19. A local device comprising a memory, a processor, and a computer program stored on the memory, characterized in that the processor executes the computer program to implement the steps of the method described in any one of Clauses A1 to A16.
[0139] The embodiments of the present invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for time synchronization with a remote device, comprising: Record the local timestamp of the first sampling point; Obtain the remote timestamp of the first sampling point; Record the second local timestamp of the first sampling point, where the second local timestamp of the first sampling point is the time when the remote timestamp of the first sampling point is obtained; Record the local timestamp of the second sampling point; Obtain the remote timestamp of the second sampling point; Record the second local timestamp of the second sampling point, where the second local timestamp of the second sampling point is the time when the remote timestamp of the second sampling point was obtained; Calculate the first average value of the local timestamp of the first sampling point and the local timestamp corresponding to the remote timestamp of the first sampling point; Calculate the second average value of the local timestamp of the second sampling point and the local timestamp corresponding to the remote timestamp of the second sampling point; as well as The remote device is synchronized by performing linear fitting based on the first average value, the second average value, the remote timestamps of the first sampling point and the second sampling point.
2. The method according to claim 1, further comprising: Before obtaining the remote timestamp of the first sampling point, initialize the remote device.
3. The method according to claim 2, wherein initializing the remote device comprises: Clear the value at a specific address in the remote memory of the remote device; The remote device is notified to create a polling thread; as well as Poll the value at the specified address.
4. The method according to claim 3, further comprising: When the value is the first value, write the second value to the specific address; as well as Synchronize the writing of the second value to the specific address and record the local timestamp of the first sampling point.
5. The method according to claim 3, wherein the remote timestamp is the time when the remote device polls the specific address and determines that the value is the second value.
6. The method of claim 1, wherein the remote device communicates with the local device via an interface, the method further comprising: Optimize the transmission efficiency between the local device and the interface.
7. The method according to claim 6, wherein optimizing the transmission efficiency between the local device and the interface includes: The remote timestamp is stored in local memory with the shortest transmission distance to the interface. as well as The processing unit with the shortest transfer distance to the local memory is designated to perform the time synchronization with the remote device.
8. The method according to claim 6, wherein optimizing the transmission efficiency between the local device and the interface includes: Increase the operating frequency of the processing unit of the local device.
9. The method according to claim 6, wherein optimizing the transmission efficiency between the local device and the interface includes: The processing unit of the local device is dedicated to the time between obtaining the remote timestamp of the first sampling point and recording the local timestamp of the second sampling point.
10. The method of claim 1, wherein performing time synchronization with the remote device comprises: The slope is calculated based on the first average value and the second average value, and the remote timestamps of the first sampling point and the second sampling point.
11. The method of claim 10, wherein time synchronization with the remote device comprises: Subtract 1 from the slope to generate an error value; as well as The decimal part of the error value is shifted to an integer part to produce an amplified error value.
12. The method of claim 11, wherein time synchronization with the remote device comprises: The amplified error value, the local timestamp of the second sampling point, and the remote timestamp are sent to the remote device.
13. The method according to claim 1, wherein the first sampling point and the second sampling point are spaced apart by a specific number of sampling points.
14. The method of claim 13, further comprising: Determine whether there exists a sampling point at a specific interval from the second sampling point; as well as If not, then the sampling point with the furthest interval is set as the first sampling point.
15. The method according to claim 1, wherein, The method includes: The linear fitting result is corrected based on at least one historical linear fitting result.
16. A computer-readable storage medium having stored thereon computer program code that is synchronized with a remote device, wherein when the computer program code is run by a processing device, it performs the method of any one of claims 1 to 15.
17. A computer program product comprising a computer program for real-time communication with a remote device, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 15.
18. A local device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 15.
Citation Information
Patent Citations
Decentralized edge computing transactions with fine-grained time coordination
US20200127861A1
Method for the temporal calibration of a switched capacitor array
WO2015051824A1