多处理器上的Stopwatch.GetTimeStamp [英] Stopwatch.GetTimeStamp on multiprocessors

查看:305
本文介绍了多处理器上的Stopwatch.GetTimeStamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stopwatch.GetTimeStamp()可能返回由于BIOS或硬件抽象层中的错误,不同处理器上的计时结果不同

有人知道这些错误在存储什么吗?具体来说?

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


  1. 不同处理器上的时间戳是否可能完全不相关-或仅相差很小(亚毫秒)最多)?

  2. 不同处理器上的数字是否会随时间推移而漂移-那么实际上会导致上述完全不相关的时间戳吗? (我认为不同处理器上的不同频率可能会这样做)


推荐答案



that is because it is written in the doc:


Stopwatch类有助于在托管代码中操纵与计时相关的
性能计数器。具体来说,可以使用Frequency
字段和GetTimestamp方法代替非托管的
Win32 API QueryPerformanceFrequency和QueryPerformanceCounter。

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实施至少有两个可能的性能计数器来源:HPET,RDTC,这是由ACPI确定。但是,ACPI主要是问题所在,大多数制造商都实施得很糟糕,因此有时决定完全忽略ACPI建议,而做其他事情。

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.

使用RDTC时,线程如果运气不佳,并且您测量的时间过短,则在另一个CPU上进行迁移将导致稍微负面的结果。但这有可能发生。

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.

这篇关于多处理器上的Stopwatch.GetTimeStamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆