问题
I would like to know if everyone knows how precise PTP synchronization can be guaranteed on Windows Server 2008.
I know about this thread: What is the minimum guaranteed time for a process in windows? which discusses windows' native time and yes, this does not give any guarantees at all.
But what when it comes to hardware solutions (PTP)? Are there any limitations preventing a guarantee of < 1ms? I know the processes depending on the time will be competing for CPU time but if the process DOES have CPU time when needed, are there anything else the might come in the way?
EDIT 1: I added "(compared to Linux)" to the title, as this was originally one of my concerns.
回答1:
A few things can be arranged to obtain reliable process times on Windows Server 2008. Some of them are:
Avoiding heavy load on the CPU.
Arrange for small memory footprint of the code.
Set the process priority class and the thread priority high. Possibly even as high as
REALTIME_PRIORITY_CLASS
andTHREAD_PRIORITY_TIME_CRITICAL
respectively.Set the thread affinity mask to avoid that the time critical part runs on
Core 0
. Core 0 is dedicated to some of the system services. Using a different code avoids dependencies.Use of
Sleep(0)
when appropriate. Sleep(0) is an asynchronous service and forces the scheduler to react. This way you can trigger the scheduler which will choose your process/thread to get CPU immedeately since it has utmost priority.Ensure that the code does give time to other services too. Utmost priority will cause all other threads to basically stop. (no mouse events or whatsoever will be processed)
Possibly increase the systems interrupt frequency by means of the mutimedia timer API. Use the timeGetDevCaps function to query the maximum allowed interrupt frequency of your system and use timeBeginPeriod with
wPeriodMin
returned bytimeBeginPeriod
in theTIMECAPS
structure. This will force your system to run at its maximum interrupt frequency. Don't forget to release the multimedia timer resource by a call to timeEndPeriod when you are done.
When these rules are carfully followed, accurate timing into the 10 microsecond regime is obtainable with ver high reliability. However the sum of all the above results in some complexity. Therefore a guarantee can never be given. But even on RTOS systems there is no such guarantee. When coding is not done properly things don't work the way they are supposed to do, no matter what/how the OS is called. Some more notes and links to the equivalent .Net services can be found here.
Taking all this enables the implementation of time synchronization (Precision Time Protocol) down to a few 10 microseconds.
Precision Time Protocol developers faq can be found here.
Edit after Linux was askted for too: There are some packages available, for example this one. Typical accuracies reported here are in the 10 to 100 microsecond range too.
Not surprisingly the results are very similar for Windows and Linux when running on comparable standard hardware. Non of the two can do anything magic.
来源:https://stackoverflow.com/questions/13136320/ptp-sync-on-windows-server-compared-to-i-e-linux-what-precision-can-be-guar