找出CPU时钟频率(每个内核,每个处理器) [英] Finding out the CPU clock frequency (per core, per processor)

查看:329
本文介绍了找出CPU时钟频率(每个内核,每个处理器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CPUz等程序非常善于提供关于系统(总线速度,内存时序等)的深入信息。



但是,有一种编程方式计算每个核心(以及每个处理器,在每个CPU多个核心的多处理器系统中)频率,而不必处理CPU的具体信息。



我试图开发防欺诈工具(用于时钟有限基准竞争),这将能够记录系统中所有活动核心(跨所有处理器)的基准运行期间的CPU时钟。

解决方案

我会在这里展开我的评论。



你想要做的是非常困难的 - 对于不切实际的以下原因:




  • 没有可移植的方式来获取处理器频率。 rdtsc 总是给出正确的频率,因为SpeedStep和Turbo Boost等效果。 b $ b
  • 所有已知的测量频率的方法都需要精确的时间测量。但是,确定的骗子可以篡改系统中的所有时钟和计时器。






没有可移植的方式获取处理器频率



获取CPU频率的简单方法是调用 rdtsc 两次,两者之间有固定的时间间隔。



问题是 rdtsc 没有给出真正的频率的处理器。因为诸如游戏的实时应用程序依赖于它,所以 rdtsc 需要通过CPU节流和Turbo Boost保持一致。因此,一旦你的系统启动, rdtsc 将总是以相同的速率运行(除非你开始使用 SetFSB 或其他)。



例如,在我的Core i7 2600K, rdtsc 将始终显示 3.4 GHz 的频率。但实际上,它在 1.6 GHz 空闲,并通过超频Turbo Boost乘法器在负载下时钟高达 4.6 GHz 46x



现在假设你找到一种方法来测量真实的频率, rdtsc )。要获取每个套接字上每个核心的频率,请使用线程亲缘性



我不知道CPUz如何测量正确的频率。但我认为它实际上一路进入BIOS,它是自己的总线速度x乘法器算术。这需要具有所有处理器系统的数据库。 (这解释了为什么CPUz需要不断地更新新的处理器)



所有已知的测量频率的方法需要准确的时间测量: / p>

这可能是更大的问题。您需要一个计时器来测量频率。一个有能力的黑客将能够篡改所有的时钟,你可以在C / C ++中使用。
这包括所有以下内容:




  • clock()

  • gettimeofday()

  • QueryPerformanceCounter $ c>

  • 等...



换句话说,你不能相信任何计时器,因为有能力的黑客将能够欺骗所有的计时器。例如 clock() gettimeofday()可以通过直接在操作系统中更改系统时钟来欺骗。愚弄 QueryPerformanceCounter()更难。根据 XtremeSystems论坛管理员的请求,我不会透露如何执行此操作。他们教我一些最强大的超频秘籍,以便我可以开发和实施对策到我的 y-cruncher多线程Pi基准。但在大多数情况下,我并不能完全成功地实施这些对策...






在评论中,是的我已经实施了一个体面的反作弊系统,以防止计时器黑客。虽然我不尝试获得准确的频率测量,定时器保护足以使基准相当难以欺骗。



我显然不能进入细节,但它的一部分涉及在基准测试期间使用多个时钟并重新同步它们多次。如果他们中的任何一个达到非同步,然后提高欺骗标志。



总的来说,我有的不是完美的。我可以在大约5分钟自己攻击它。 (好吧,我知道它是如何工作的)。此外,它偶尔会给出假阳性...这也是坏的。


Programs like CPUz are very good at giving in depth information about the system (bus speed, memory timings, etc.)

However, is there a programmatic way of calculating the per core (and per processor, in multi processor systems with multiple cores per CPU) frequency without having to deal with CPU specific info.

I am trying to develop a anti cheating tool (for use with clock limited benchmark competitions) which will be able to record the CPU clock during the benchmark run for all the active cores in the system (across all processors.)

解决方案

I'll expand on my comments here. This is too big and in-depth for me to fit in the comments.

What you're trying to do is very difficult - to the point of being impractical for the following reasons:

  • There's no portable way to get the processor frequency. rdtsc does NOT always give the correct frequency due to effects such as SpeedStep and Turbo Boost.
  • All known methods to measure frequency require an accurate measurement of time. However, a determined cheater can tamper with all the clocks and timers in the system.

There's no portable way to get the processor frequency:

The "easy" way to get the CPU frequency is to call rdtsc twice with a fixed time-duration in between. Then dividing out the difference will give you the frequency.

The problem is that rdtsc does not give the true frequency of the processor. Because real-time applications such as games rely on it, rdtsc needs to be consistent through CPU throttling and Turbo Boost. So once your system boots, rdtsc will always run at the same rate (unless you start messing with the bus speeds with SetFSB or something).

For example, on my Core i7 2600K, rdtsc will always show the frequency at 3.4 GHz. But in reality, it idles at 1.6 GHz and clocks up to 4.6 GHz under load via the overclocked Turbo Boost multiplier at 46x.

Now suppose you find a way to measure the true frequency, (or you're happy enough with rdtsc). To get the frequencies of each core on each socket, you do that by playing with thread-affinities.

I'm not sure exactly how CPUz measures the correct frequency. But I think it actually goes all the way into BIOS and does it's own bus-speed x multiplier arithmetic. This requires having a database of all the processor systems. (which explains why CPUz needs to be constantly updated with new processors)

All known methods to measure frequency require an accurate measurement of time:

This is perhaps the bigger problem. You need a timer to be able to measure the frequency. A capable hacker will be able to tamper with all the clocks that you can use in C/C++. This includes all of the following:

  • clock()
  • gettimeofday()
  • QueryPerformanceCounter()
  • etc...

The list goes on and on. In other words, you cannot trust any of the timers as a capable hacker will be able to spoof all of them. For example clock() and gettimeofday() can be fooled by changing the system clock directly within the OS. Fooling QueryPerformanceCounter() is harder. At the request of the XtremeSystems Forums admins, I will not reveal how to do this. They have taught me some of the most powerful overclocking cheats just so that I could develop and implement countermeasures into my y-cruncher Multi-threaded Pi Benchmark. But for the most part, I'm not entirely successful in implementing these countermeasures...


So to answer your question in the comments, yes I have implemented a decent anti-cheating system to prevent timer hacks. Although I don't try to get an accurate frequency measurement, the timer-protection is enough to make the benchmarks reasonably hard to cheat.

I obviously can't go into details, but part of it involves using multiple clocks and re-syncing them multiple times during a benchmark. If any of them get to far out-of-sync, then raise the cheat flag.

Overall, what I have is not perfect. I can hack it myself in about 5 min. (well, I know how it works). Furthermore, it occasionally gives false-positives... which is also bad.

这篇关于找出CPU时钟频率(每个内核,每个处理器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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