我该怎么办的的x86 Windows中的CPU缓存刷新? [英] How can I do a CPU cache flush in x86 Windows?

查看:357
本文介绍了我该怎么办的的x86 Windows中的CPU缓存刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是在Windows迫使CPU缓存刷新(为基准的原因,我想模仿开始,在CPU缓存中没有数据),preferably一个基本的C实现或Win32调用。

I am interested in forcing a CPU cache flush in Windows (for benchmarking reasons, I want to emulate starting with no data in CPU cache), preferably a basic C implementation or Win32 call.

有没有一种已知的方式与系统调用,甚至一些刁钻的说做一个大的的memcpy

Is there a known way to do this with a system call or even something as sneaky as doing say a large memcpy?

英特尔的i686平台(P4和最多是好的为好)。

Intel i686 platform (P4 and up is okay as well).

推荐答案

幸运的是,明确地刷新缓存的方法不止一种。

Fortunately, there is more than one way to explicitly flush the caches.

指令WBINVD写回修改的缓存内容,标志着缓存空。它执行总线周期,使外部缓存刷新自己的数据。不幸的是,它是一个特权指令。但是,如果有可能根据类似DOS下运行测试程序,这是要走的路。这具有保持OS的超高速缓存足迹的优点非常小。

The instruction "wbinvd" writes back modified cache content and marks the caches empty. It executes a bus cycle to make external caches flush their data. Unfortunately, it is a privileged instruction. But if it is possible to run the test program under something like DOS, this is the way to go. This has the advantage of keeping the cache footprint of the "OS" very small.

此外,有INVD指令,该指令高速缓存无效的没有刷新他们回到主内存。这违反主内存和缓存的一致性,所以你必须自己照顾的。并不推荐使用。

Additionally, there is the "invd" instruction, which invalidates caches without flushing them back to main memory. This violates the coherency of main memory and cache, so you have to take care of that by yourself. Not really recommended.

有关基准目的,最简单的解决方案可能是复制大量的内存块标有厕所的区域(写入合并),而不是WB。显卡的内存映射区域是一个不错的人选,或者你可以自己通过MTRR寄存器标记区域WC。

For benchmarking purposes, the simplest solution is probably copying a large memory block to a region marked with WC (write combining) instead of WB. The memory mapped region of the graphics card is a good candidate, or you can mark a region as WC by yourself via the MTRR registers.

您可以找到一些资源约在基准测试程序短例程用于测量时钟周期和性能监控。

You can find some resources about benchmarking short routines at Test programs for measuring clock cycles and performance monitoring.

这篇关于我该怎么办的的x86 Windows中的CPU缓存刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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