如何声明内存范围内使用不可缓存的x86平台的gcc? [英] How do declare a memory range as uncacheable using gcc on x86 platform?

查看:189
本文介绍了如何声明内存范围内使用不可缓存的x86平台的gcc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我看了一下这方面的说明movntdqa但想出了一个干净的方式前preSS内存范围不可缓存或读取数据,从而不污染缓存。
我想从GCC做到这一点。我的主要目标是交换到随机位置在大阵。希望通过避免缓存因为很少有数据resue加速这一操作。

Although I have read about movntdqa instructions regarding this but have figured out a clean way to express a memory range uncacheable or read data so as to not pollute the cache. I want to do this from gcc. My main goal is to swap to random locations in an large array. Hoping to accelerate this operation by avoiding caching since there is very little data resue.

推荐答案

我想你所描述的是内存类型范围寄存器。你可以控制这些在Linux下(如果有,你是用户0),使用的/ proc / MTTR / 的ioctl(2)请参见这里的一个例子。由于它的工作原理上的物理的地址范围我想你会以合理的方式使用它有一个困难时期。

I think what you're describing is Memory Type Range Registers. You can control these under Linux (if available and you're user 0) using /proc/mttr / ioctl(2) see here for an example. As it works on a physical address range I think you're going to have a hard time using it in a reasonable way.

有一个更好的办法是看编译器GCC内部函数提供并找到一个或多个,即前presses你的意图。看看乌尔里希Drepper关于每个程序员应该知道内存是什么系列,尤其是部分5 它与绕过交易缓存。它看起来像 _mm_ prefetch(PTR,_MM_HINT_NTA)可能适合您的需求。

A better way is to look at the compiler intrinsics GCC provides and find one or more, that expresses your intent. Have a look at Ulrich Drepper's series on "What every programmer should know about memory", in particular part 5 which deals with bypassing the cache. It looks like _mm_prefetch(ptr, _MM_HINT_NTA) might be appropriate for your needs.

一如往常,当涉及到性能 - 测量,测量,测量。 Drepper的系列具有优良的部分详细介绍了如何可以做到这一点(部分7 )以及code的例子和其他战略,来尝试加快你的code的内存性能的时候。

As always when it comes to performance - measure, measure, measure. Drepper's series has excellent parts detailing how this can be done (part 7) as well as code examples and other strategies to try when speeding up the memory performance of your code.

这篇关于如何声明内存范围内使用不可缓存的x86平台的gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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