用户空间记忆障碍?(Linux x86 - 64)

时间:2023-01-30 15:12:29

It is easy to set memory barriers on the kernel side: the macros mb, wmb, rmb, etc. are always in place thanks to the Linux kernel headers.

在内核端设置内存屏障很容易:由于Linux内核头,宏mb、wmb、rmb等总是存在。

How to accomplish this on the user side?

如何在用户方面实现它?

8 个解决方案

#1


7  

Posix defines a number of functions as acting as memory barriers. Memory locations must not be concurrently accessed; to prevent this, use synchronization - and that synchronization will also work as a barrier.

Posix定义了许多函数作为内存屏障。不能同时访问内存位置;要防止这种情况发生,请使用同步—同步也将成为障碍。

#2


5  

You are looking for the full memory barrier atomic builtins of gcc.

您正在寻找gcc的完整的内存屏障原子构建。

Please note the detail on the reference i gave here says,

请注意我在这里给出的参考资料,

The [following] builtins are intended to be compatible with those described in the Intel Itanium Processor-specific Application Binary Interface, section 7.4. As such, they depart from the normal GCC practice of using the “__builtin_” prefix, and further that they are overloaded such that they work on multiple types.

[以下]内置程序旨在与Intel Itanium处理器专用的应用程序二进制接口7.4中描述的内容兼容。因此,它们与使用“__builtin_”前缀的常规GCC实践不同,而且它们是重载的,因此可以处理多个类型。

#3


4  

Use libatomic_ops. http://www.hpl.hp.com/research/linux/atomic_ops/

使用libatomic_ops。http://www.hpl.hp.com/research/linux/atomic_ops/

It's not compiler-specific, and less buggy than the GCC stuff. It's not a giganto-library that provides tons of functionality you don't care about. It just provides atomic operations. Also, it's portable to different CPU architectures.

它不是特定于编译器的,而且比GCC的东西更不容易出错。它并不是一个提供大量你不关心的功能的巨型库。它只提供原子操作。而且,它可以移植到不同的CPU架构。

#4


2  

Linux x64 means you can use the Intel memory barrier instructions. You might wrap them in macros similar to those in the Linux headers, if those macros aren't appropriate or accessible to your code

Linux x64意味着您可以使用英特尔内存障碍指令。如果这些宏不适合您的代码,您可以用类似于Linux header中的宏来封装它们。

#5


2  

__sync_synchronize() in GCC 4.4+

__sync_synchronize在GCC 4.4 +()

The Intel Memory Ordering White Paper, a section from Volume 3A of Intel 64 and IA-32 manual http://developer.intel.com/Assets/PDF/manual/253668.pdf

英特尔内存订购白皮书,来自英特尔64卷3A版和IA-32手册http://developer.intel.com/Assets/PDF/manual/253668.pdf

#6


2  

The Qprof profiling library (nothing to do with Qt) also includes in its source code a library of atomic operations, including memory barriers. They work on many compilers and architectures. I'm using it on a project of mine.

Qprof概要库(与Qt无关)在源代码中还包括一个原子操作库,包括内存障碍。它们处理许多编译器和体系结构。我正在我的一个项目中使用它。

http://www.hpl.hp.com/research/linux/qprof/download.php4

http://www.hpl.hp.com/research/linux/qprof/download.php4

#7


1  

Simply borrowing barriers defined for Linux kernel, just add those macros to your header file: http://lxr.linux.no/#linux+v3.6.5/arch/x86/include/asm/barrier.h#L21 . And of course, give Linux developers credit in your source code.

简单地借用为Linux内核定义的屏障,只需将这些宏添加到头文件:http://lxr.linux.nox.linux /# Linux +v3.6.5/arch/x86/include/asm/barrier。h # L21。当然,在你的源代码中给Linux开发人员一定的信任。

#8


0  

The include/arch/qatomic_*.h headers of a recent Qt distribution include (LGPL) code for a lot of architectures and all kinds of memory barriers (acquire, release, both).

包括/ arch / qatomic_ *。最近Qt分布的h标头包括许多架构的(LGPL)代码和各种内存障碍(获取、发布、两者)。

#1


7  

Posix defines a number of functions as acting as memory barriers. Memory locations must not be concurrently accessed; to prevent this, use synchronization - and that synchronization will also work as a barrier.

Posix定义了许多函数作为内存屏障。不能同时访问内存位置;要防止这种情况发生,请使用同步—同步也将成为障碍。

#2


5  

You are looking for the full memory barrier atomic builtins of gcc.

您正在寻找gcc的完整的内存屏障原子构建。

Please note the detail on the reference i gave here says,

请注意我在这里给出的参考资料,

The [following] builtins are intended to be compatible with those described in the Intel Itanium Processor-specific Application Binary Interface, section 7.4. As such, they depart from the normal GCC practice of using the “__builtin_” prefix, and further that they are overloaded such that they work on multiple types.

[以下]内置程序旨在与Intel Itanium处理器专用的应用程序二进制接口7.4中描述的内容兼容。因此,它们与使用“__builtin_”前缀的常规GCC实践不同,而且它们是重载的,因此可以处理多个类型。

#3


4  

Use libatomic_ops. http://www.hpl.hp.com/research/linux/atomic_ops/

使用libatomic_ops。http://www.hpl.hp.com/research/linux/atomic_ops/

It's not compiler-specific, and less buggy than the GCC stuff. It's not a giganto-library that provides tons of functionality you don't care about. It just provides atomic operations. Also, it's portable to different CPU architectures.

它不是特定于编译器的,而且比GCC的东西更不容易出错。它并不是一个提供大量你不关心的功能的巨型库。它只提供原子操作。而且,它可以移植到不同的CPU架构。

#4


2  

Linux x64 means you can use the Intel memory barrier instructions. You might wrap them in macros similar to those in the Linux headers, if those macros aren't appropriate or accessible to your code

Linux x64意味着您可以使用英特尔内存障碍指令。如果这些宏不适合您的代码,您可以用类似于Linux header中的宏来封装它们。

#5


2  

__sync_synchronize() in GCC 4.4+

__sync_synchronize在GCC 4.4 +()

The Intel Memory Ordering White Paper, a section from Volume 3A of Intel 64 and IA-32 manual http://developer.intel.com/Assets/PDF/manual/253668.pdf

英特尔内存订购白皮书,来自英特尔64卷3A版和IA-32手册http://developer.intel.com/Assets/PDF/manual/253668.pdf

#6


2  

The Qprof profiling library (nothing to do with Qt) also includes in its source code a library of atomic operations, including memory barriers. They work on many compilers and architectures. I'm using it on a project of mine.

Qprof概要库(与Qt无关)在源代码中还包括一个原子操作库,包括内存障碍。它们处理许多编译器和体系结构。我正在我的一个项目中使用它。

http://www.hpl.hp.com/research/linux/qprof/download.php4

http://www.hpl.hp.com/research/linux/qprof/download.php4

#7


1  

Simply borrowing barriers defined for Linux kernel, just add those macros to your header file: http://lxr.linux.no/#linux+v3.6.5/arch/x86/include/asm/barrier.h#L21 . And of course, give Linux developers credit in your source code.

简单地借用为Linux内核定义的屏障,只需将这些宏添加到头文件:http://lxr.linux.nox.linux /# Linux +v3.6.5/arch/x86/include/asm/barrier。h # L21。当然,在你的源代码中给Linux开发人员一定的信任。

#8


0  

The include/arch/qatomic_*.h headers of a recent Qt distribution include (LGPL) code for a lot of architectures and all kinds of memory barriers (acquire, release, both).

包括/ arch / qatomic_ *。最近Qt分布的h标头包括许多架构的(LGPL)代码和各种内存障碍(获取、发布、两者)。