我想通过编程禁用硬件预取.

Optimizing Application Performance on Intel® Core™ Microarchitecture Using Hardware-Implemented Prefetchers

以下是一个相关片段:

"DPL预取和L2流预取设置也可以通过编程方式更改

下表显示了为了控制DPL和L2流预取而必须更改的IA32_MISC_ENABLE MSR中的位:

Prefetcher Type MSR (0x1A0) Bit Value 
DPL (Hardware Prefetch) Bit 9 0 = Enable 1 = Disable 
L2 Streamer (Adjacent Cache Line Prefetch) Bit 19 0 = Enable 1 = Disable"

我试着用http://etallen.com/msr.html,但没用.

顺便说一句,我使用的是内核2.6.18-92.el5,内核中有MSR个链接:

$ grep -i msr /boot/config-$(uname -r)
CONFIG_X86_MSR=y
...

推荐答案

From the Intel reference:
This instruction must be executed at privilege level 0 or in real-address mode; otherwise, a general protection exception #GP(0) will be generated. Specifying a reserved or unimplemented MSR address in ECX will also cause a general protection exception.

...
The CPUID instruction should be used to determine whether MSRs are supported (EDX[5]=1) before using this instruction.

So, your fault might be related to a cpu that doesn't support MSRs or using the wrong MSR address.

There are lots of examples of using the MSRs in the kernel source:

In the kernel source, for a single cpu, it demonstrates disabling prefetch for the Xeon in arch/i386/kernel/cpu/intel.c, in the function:

static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)

The rdmsr function arguments are the msr number, a pointer to the low 32 bit word, and a pointer to the high 32 bit word.
The wrmsr function arguments are the msr number, the low 32 bit word value, and the high 32 bit word value.

multi-core or smp systems have to pass the cpu struct in as the first argument:
void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);

Linux相关问答推荐

将UTC字符串日期时间转换为毫秒UTC时间戳

eBPF:仅使用系统调用加载 eBPF 程序并将其附加到 sys_enter_execve

JSON 转义 CURL/JQ 输出

为什么库中不调用全局变量的构造函数?

如何验证所有 csv 文件是否具有相同的第一行?

为什么 perf stat 不计算 cycles:u 在 BIOS 中禁用超线程的 Broadwell CPU 上?

如何拆分多个分隔符但将它们保留在方括号之间?

如何在 Linux 上使用 -grep 构建过滤间隔的命令

如何在 AWS Linux 服务器上实现虚拟主机?

判断指定名称的画面是否存在

具体来说,fork() 如何处理 Linux 中 malloc() 动态分配的内存?

RealUID,保存的 UID,有效的 UID.这是怎么回事?

加密/解密在两个不同的 openssl 版本之间不能很好地工作

从Linux中的行尾删除空格

使用 ssh 判断远程主机上是否存在文件

Pthread mutex互斥断言错误

何时使用管道与何时使用共享内存

在 PHP / Apache / Linux 环境中,为什么 chmod 777 是危险的?

CentOS:在 PHP 安装中启用 GD 支持

如何在 Linux 中将 .so 文件添加到 java.library.path