本文介绍了如何获得准确的多核/线程感知时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,秒表/ QueryPerformanceCounter滴答声可能会在将在所有内核上运行的多线程异步应用程序中出现问题.

As we all know the stopwatch/QueryPerformanceCounter ticks might have issues in a multi-threaded async application that will be running on all cores.

我是否有任何办法获得一些可靠的滴答/时间戳,例如具有高分辨率/准确性的值,并且在所有CPU内核之间也是一致的?

Are there any way for me to get some reliable tick/timestamp like values that has high resolution/accuracy as well is consistent across cpu cores?

如果不可能的话,下一个最佳方法是什么,以便在各个内核之间获得良好的时间戳记? DateTime.UtcNow.Ticks 还是 Environment.TickCount ?还有其他柜台吗?

If not possible, what is the next best way to get a good timestamp across cores?DateTime.UtcNow.Ticks or Environment.TickCount? Any other counters?

我确实需要比DateTime.UtcNow.Ticks可以提供的分辨率更好的分辨率. (10-15ms),因为我正在.NET中处理仪器应用程序.

I do need better resolution than what DateTime.UtcNow.Ticks can provide. (10-15ms) as i am working on a instrumentation application in .NET.

推荐答案

在多处理器计算机上,线程在哪个处理器上运行无关紧要.但是,由于BIOS或硬件抽象层(HAL)中的错误,您可以在不同的处理器上获得不同的计时结果.指定处理器关联 对于线程,请使用ProcessThread.ProcessorAffinity方法.

On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread.ProcessorAffinity method.


我有什么办法获得一些可靠的滴答/时间戳,例如具有高分辨率/精度的值,并且在cpu内核之间也是一致的?


Are there any way for me to get some reliable tick/timestamp like values that has high resolution/accuracy as well is consistent across cpu cores?

如果无法使秒表(QueryPerformanceCounter)多核安全,那么在各个核之间获得良好时间戳的下一个最佳方法是什么? ** DateTime.UtcNow.Ticks **或** Environment.TickCount **?还有其他柜台吗?

If not possible to make the stopwatch(QueryPerformanceCounter) multi-core safe, what is the next best way to get a good timestamp across cores? **DateTime.UtcNow.Ticks** or **Environment.TickCount**? Any other counters?

我确实需要比DateTime.UtcNow.Ticks可以提供的分辨率更好的分辨率. (10-15ms)

I do need better resolution than what DateTime.UtcNow.Ticks can provide. (10-15ms)


这篇关于如何获得准确的多核/线程感知时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 22:20