如何在 C 中预取针对 AMD Opteron 6168 的指针?

发布于 2024-09-27 16:30:26 字数 367 浏览 1 评论 0原文

我正在用 C 语言编写一个多线程程序,其中一个核心定期从链接列表的头部抓取一个项目,而其他核心将项目附加到列表的后面(使用 CAS 魔法来保证线程安全,其他人为我提供了这一点) 。如果从列表头部取出一个项目的核心简单地启动下一个项目的预取(该项目肯定位于另一个核心的缓存中),那么我的程序似乎会运行得更快。

目前我的目标是 AMD Opteron 6168,在 Debian Linux 上使用 gcc 进行编译:我试图找到这方面的文档,但我处于不熟悉的领域。我能找到的只是使用 -O3 来启用编译器插入的预取(我认为是 for 循环),并且提到了一些 AMD 预取指令名称,例如 PREFETCHW。

我不知道如何找到我所追求的参考,或者如何将这样的语句插入到 C 中,也许作为汇编块?

I am writing a multi-threaded program in C where one core periodically grabs an item from the head of a linked list while other cores append items to the back of the list (using CAS magic for thread safety, someone else provided that for me). It appears that my program will run faster if the core taking an item from the head of the list simply initiates a prefetch for the next item, which is sure to be in another core's cache.

Currently I am targeting an AMD Opteron 6168, compiling with gcc on Debian Linux: I've tried to find documentation for this but I am in unfamiliar waters. All I can find is using -O3 to enable compiler-inserted prefetching (I think for loops) and some mentions of the AMD prefetch instruction names like PREFETCHW.

I do not know how to find the reference for what I'm after, or how to insert a statement like that into C, maybe as a block of assembly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄断弥空 2024-10-04 16:30:26

gcc 为此提供了一些内置函数。你可以做

__builtin_prefetch(&yourData);

gcc comes with some builtin functions for that. You can do

__builtin_prefetch(&yourData);
你的他你的她 2024-10-04 16:30:26

检查英特尔架构文档。

在 VC 中,你应该能够

asm
{
  prefetch POINTER_NAME
}

在 GCC 中做类似的事情 -

asm("prefetch %0", POINTER_NAME); //May have syntax slightly off

我之前已经看过这个。

Check the intel architecture docs.

In VC, you should be able to do something like this

asm
{
  prefetch POINTER_NAME
}

In GCC -

asm("prefetch %0", POINTER_NAME); //May have syntax slightly off

I've looked this over before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文