Windows 7 Timing Functions: Understanding GetSystemTimeAdjustment
As you observed, the results from using the GetSystemTimeAdjustment function on Windows 7 can be puzzling. To gain a better understanding, let's address your questions:
Question 1: Correctness of Assumption
Your assumption is generally correct. If the system time is periodically synchronized, you would expect either no change or changes in multiples of the increment obtained from GetSystemTimeAdjustment.
Question 2: Reason for Discrepancy
The discrepancy you encountered is due to the fact that the granularity of the system time provided by GetSystemTimeAsFileTime may not always align with the actual update interval reported by GetSystemTimeAdjustment.
Explanation:
GetSystemTimeAsFileTime provides access to the system's wall clock in 100ns units. However, the actual update rate of the system time can vary depending on hardware factors and the settings of the multimedia timer interface.
In your case, NtQueryTimerResolution is reporting an update period of ~25µs, while GetSystemTimeAdjustment indicates an adjustment of 15.6ms. This suggests that the system time is being updated more frequently than it is actually synchronized.
Implications:
This means that the changes observed in your timestamp loop are not solely due to the time adjustment being applied. Rather, they reflect the underlying updates to the system time, which occur at a higher frequency.
Recommended Approach:
Instead of relying on GetSystemTimeAdjustment for precise timing, consider using NtQueryTimerResolution to determine the actual update interval of the system time. This will provide a more accurate representation of the system's timing behavior.
The above is the detailed content of ## Why Does GetSystemTimeAdjustment Not Always Reflect the True Time Adjustment on Windows 7?. For more information, please follow other related articles on the PHP Chinese website!