无法禁用硬件预取程序

时间:2012-04-13 17:56:12

标签: prefetch msr

我正在尝试禁用硬件预取程序在Intel核心i5 2500上运行一些内存基准测试。问题是我的BIOS中没有任何选项可以启用或禁用预取程序。所以我试图使用msr-tools来禁用预取器。但是msr-tool无法将一些特定值写入所需的寄存器(0x1a0h)。

$ rdmsr -p 0 0x1a0
850089

$ wrmsr -p 0 0x1a0 0x850289
wrmsr: CPU 0 cannot set MSR 0x000001a0 to 0x0000000000850289

所有cpus的情况都是一样的。但如果我尝试写入值0x850088(只是选择进行测试),它将成功写入该值。

任何人都可以指出问题出在哪里以及解决方案是什么?

我觉得奇怪的是我的BIOS中没有prefetcher禁用选项。这是某种版本的BIOS的情况吗?

感谢。

2 个答案:

答案 0 :(得分:0)

sudo modprobe msr
sudo rdmsr -p $i 0x1a0 -f 3:0

L2硬件预取器 - 位0

L2相​​邻高速缓存行预取器 - 位1

DCU预取器 - 第2位

DCU IP预取器 - 第3位

[1]

我得到9作为回应。如果设置该位,则预取器为OFF。 L2硬件预取器和DCU IP prefetecher对我来说是关闭的。 要打开它们:

$ sudo rdmsr -p 0 0x1a0
850089
# now we update bits 0 and 3
$ sudo wrmsr -p 0 0x850080 # 0b1001 = 0x9 wheras 0b0000 = 0x0
# check it took
$ sudo rdmsr -p 0 0x1a0
850080

所有预取者现在都在

要将它们关闭,它就是类似的     $ sudo wrmsr -p0 0x85008f     #this失败了,我可以设置位1,因此L2相邻的缓存行预取器保持打开状态     $ suod wrmsr -p0 0x85008d     #其他人可以关闭

[1] https://software.intel.com/en-us/articles/disclosure-of-hw-prefetcher-control-on-some-intel-processors

答案 1 :(得分:0)

如果您有 Nehalem、Westmere、Sandy Bridge、Ivy Bridge、Haswell 或 Broadwell Intel CPU,您可以使用 MSR 0x1a4 的 0:4 位启用/禁用各种预取器。请参阅:https://software.intel.com/content/www/us/en/develop/articles/disclosure-of-hw-prefetcher-control-on-some-intel-processors.html

# E.g. showing initially all enabled:
rdmsr -a -c 0x1a4
> 0xf
> <etc>

# Disable all 4 prefetchers, by setting all 4 bits:
wrmsr -a 0x1a4 $(( 2**0 | 2**1 | 2**2 | 2**3))
rdmsr -a -c 0x1a4
> 0xf
> <etc>

对于具有随机存取内存密集型工作负载的应用程序,这使我的性能提高了约 5%。

对于较旧的 Intel Core / NetBurst 架构,它似乎是不同的 MSR,0x1a0,能够通过位 9 和 19 启用/禁用 2 个不同的预取器。请参阅:

https://software.intel.com/content/www/us/en/develop/articles/optimizing-application-performance-on-intel-coret-microarchitecture-using-hardware-implemented-prefetchers.html

要禁用/启用它们,您可能会执行以下操作(未经测试,因为我没有核心 CPU - 所以如果我尝试设置这 2 位,则会出现错误):

MSRORIG=$(printf "0x%x\n" $(rdmsr -c 0x1a0)) 
# To set bits 9 and 19 and disable the prefetchers:
wrmsr -a 0x1a0 $((MSRORIG | 1<<19 | 1<<9))
# To unset and enable:
wrmsr -a 0x1a0 $((MSRORIG & ~(1<<19 | 1<<9)))
相关问题