在英特尔 64 位机器上启用/禁用缓存:CD 位始终设置? [英] enable/disable cache on intel 64bit machine: CD bit always set?

查看:16
本文介绍了在英特尔 64 位机器上启用/禁用缓存:CD 位始终设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Xen 中为我的机器 Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz 禁用所有级别的缓存.我编写了一个工具来调用以下汇编代码来禁用/启用缓存并显示 CR0 寄存器的值.

I'm trying to disable all level of cache for my machine Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz in Xen. I wrote a tool to call the following assemble code to disable/enable the cache and show the CR0 register's value.

case XENMEM_disable_cache:
    __asm__ __volatile__(
        "pushq %%rax
	"
        "movq %%cr0,%%rax
	"
        "orq $0x40000000,%%rax
	"
        "movq %%rax,%%cr0
	"
        "movq %%cr0, %0
	"
        "wbinvd
	"
        "popq  %%rax"
        : "=r"(cr0)
        :
        :);
    // gdprintk(XENLOG_WARNING, "gdprintk:XENMEM_disable_cache disable cache!
    // TODO IMPLEMENT
");
    printk("<1>printk: disable cache! cr0=%#018lx
", cr0);
    rc = 0;
    break;

case XENMEM_enable_cache:
    __asm__ __volatile__(
        "pushq %%rax
	"
        "movq %%cr0,%%rax
	"
        "andq $0xffffffffbfffffff,%%rax
	" /*~0x4000000*/
        "movq %%rax,%%cr0
	"
        "movq %%cr0, %0
	"
        "popq  %%rax"
        : "=r"(cr0)
        :
        :);
    printk("<1>printk: enable cache; cr0=%#018lx
", cr0);
    rc = 0;
    break;

case XENMEM_show_cache:
    __asm__ __volatile__(
        "pushq %%rax
	"
        "movq %%cr0, %%rax
	"
        "movq %%rax, %0
	"
        "popq %%rax"
        : "=r"(cr0)
        :
        :);
    // gdprintk(XENLOG_WARNING, "gdprintk:XENMEM_show_cache_status! CR0 value is
    // %#018lx
", cr0);
    printk("<1>printk: XENMEM_show_cache_status! CR0 value is %#018lx
", cr0);
    return (long)cr0;

代码可以编译运行.运行禁用缓存代码后,系统变得非常慢,这确认缓存已禁用.另外,CR0 的值表明我在运行禁用缓存代码时设置了 CD 位.

The code can compile and run. After I run the disable cache code, the system becomes extremely slow, which confirms the cache is disabled. In addition, the value of CR0 shows the CD bit is set when I run the disable cache code.

但是,当我运行 show cache 代码时,无论我禁用/启用缓存,输出都显示 CR0 的 CD 位为 0.

However, when I run the show cache code, the output shows the CD bit of CR0 is 0, no matter I disable/enable cache.

我的问题是:

禁用缓存时,CR0 寄存器的 CD 位(30 位)是否始终设置为 1?

Is the CD bit(30bit) of CR0 register always set 1 when cache is disabled?

如果没有,我的代码肯定有问题,请您帮我指出我犯的错误吗?

If not, there must be something wrong with my code, could you please help me point out the error I made?

答案:

以上代码只设置了运行代码的内核上CR0寄存器的CD位.我们需要使用 smp_call_function() 来调用所有内核上的代码!

The above code only set the CD bit of the CR0 register on the core where the code is running. We need to use the smp_call_function() to call the code on all cores!

我的新问题是:

如果我禁用缓存,然后使用上述代码启用缓存,则 CR0 的 CD 位被清除.但是,系统的性能仍然非常非常慢,就像我禁用缓存时一样.所以在我看来启用缓存代码不起作用?但是,由于 CD 位已被清除,因此启用缓存代码应该有效!所以问题是:启用缓存后我应该等待多长时间才能拥有与禁用缓存之前相同的性能?

If I disable cache and then enable cache using the above code, the CD bit of CR0 is cleared. However, the system's performance is still very very slow, just like when I disable the cache. So it seems to me that enabling the cache code does NOT work? However, since CD bit has been cleared, the enabling cache code should have worked! So the question is: How long should I wait after I enable cache so that I can have the same performance just like the performance before I disable cache?

顺便说一句,当我运行启用缓存代码时,printk 输出显示 CR0 的 CD 位为 0.

BTW, when I run the enble cache code, the printk output shows that the CR0's CD bit is 0.

推荐答案

如果您使用的是 SMP 系统,您应该使用 smp_call_function() 为每个内核调用禁用缓存代码,因为从理论上讲,您的显示缓存代码可能在不同的处理器上运行.要使用该函数,#include .

If you're on an SMP system, you should invoke the disable-cache code for every core with smp_call_function(), since it is theoretically possible that your show-cache code is running on a different processor. To use that function, #include <include/linux/smp.h>.

smp_call_function() 调用仅在其他内核上给出的函数指针,而不是在当前内核上.通过在调用 smp_call_function() 的内核上自己调用函数,确保在所有内核上运行该函数.

smp_call_function() invokes the function pointer it is given only on other cores, not on the current one. Make sure to run the function on all cores by invoking the function yourself on the core that invokes smp_call_function().

这篇关于在英特尔 64 位机器上启用/禁用缓存:CD 位始终设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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