Stopwatch.GetTimeStamp on multiprocessors

☆樱花仙子☆ 提交于 2019-12-13 07:25:49

问题


Stopwatch.GetTimeStamp() may return different timing results on different processors because of bugs in the BIOS or the Hardware Abstraction Layer.

Does anyone know what these bugs hold in store in concrete terms?

  1. Could timestamps on different processors potentially be totally unrelated - or would they be only off by some small amount (sub-milliseconds?) at most?
  2. Could numbers on different processors drift apart over time - which then would in effect lead to the aforementioned "timestamps totally unrelated"? (I would think different frequencies on different processors might do this)

回答1:


that is because it is written in the doc:

The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Win32 APIs QueryPerformanceFrequency and QueryPerformanceCounter.

And therefore comes the alea of using the performance counter.

Windows implementation has at least 2 possible sources for performance counter, the HPET, the RDTC, and this is determined by ACPI. However, ACPI is mostly the problem, most manufacturers are implementing it badly therefore sometimes the decision to ignore completely the ACPI advice and do something else instead.

When using RDTC, thread migration over another CPU will result in slightly negative results if luck is not with you and that you measure a super small time anyway. But it can happen.



来源:https://stackoverflow.com/questions/24051968/stopwatch-gettimestamp-on-multiprocessors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!