Is there any reliable (preferably, free of both false negatives and false positives) way to detect availability of the LDREX
/STREX
atomic operations at runtime on Linux/ARM? I've looked for something in the AT_HWCAP
field of the aux vector and found a few things which might indirectly imply availability (e.g. HWCAP_LPAE
supposedly does) but they would likely have false negatives.
在Linux / ARM上运行时检测LDREX / STREX原子操作的可用性是否有任何可靠的(最好是没有误报和误报)?我在aux矢量的AT_HWCAP字段中寻找了一些东西,发现了一些可能间接暗示可用性的东西(例如HWCAP_LPAE据说可能),但它们可能会有误报。
2 个解决方案
#1
4
LDREX
/STREX
were introduced in the ARMv6 architecture, so you just need to check the architecture version - if it's v6 or later, you have them. If not, you don't. From privileged code you could read the MIDR directly, otherwise some userspace interface like /proc/cpuinfo
.
LDREX / STREX是在ARMv6架构中引入的,因此您只需要检查架构版本 - 如果它是v6或更高版本,您就拥有它们。如果没有,你就不这样做。从特权代码中你可以直接读取MIDR,否则一些用户空间接口就像/ proc / cpuinfo。
If you really need to implement atomics that work across all architecture versions, you may be better off relying on the cmpxchg
provided by the Kernel User helpers than trying to roll your own.
如果你真的需要实现适用于所有架构版本的原子,那么你可能最好依靠内核用户助手提供的cmpxchg,而不是试图自己推出。
#2
0
Mpcore, the TRM doesnt say if you can or cant access this in a non-priveledged mode.
Mpcore,TRM没有说你是否可以在非priveledged模式下访问它。
MRC p15,0,<Rd>,c0,c0,0; reads Main ID register
The cpu id register a few after that does explicitly say: accessible in privileged modes only So I would hope/assume the arm docs would have said the same thing about the main id register. of course how many main id register answers do you have to wade through to verify what core this is or not?
cpu id注册了一些之后明确说明:只能在特权模式下访问所以我希望/假设arm文档会对主id寄存器说同样的事情。当然有多少主要的id寄存器答案,你必须通过验证核实这是什么核心?
Ahh, MIDR = Main ID Register, Notlikethat mentioned MIDR, I guess it is an easy test to see if you can access the MIDR in user mode...
啊,MIDR =主ID寄存器,Notlikethat提到MIDR,我想这是一个简单的测试,看看你是否可以在用户模式下访问MIDR ...
EDIT:
编辑:
The 1176 does clearly state about the MIDR.
1176确实明确说明了MIDR。
accessible in privileged modes only.
仅在特权模式下可访问。
I wonder if that restriction went away.
我想知道这种限制是否消失了。
EDIT2:
EDIT2:
Verified on an mpcore, that you cannot access the MIDR in user mode.
在mpcore上验证,您无法在用户模式下访问MIDR。
EDIT3:
EDIT3:
I think you have to rely on the kernel to help out userspace. And/or if you only support ARMv6 or newer then ldrex/strex will be there and you dont have to check, assuming this is not running on a cortex-m, but an arm11 or cortex-a/r.
我认为你必须依靠内核来帮助用户空间。和/或如果你只支持ARMv6或更新,那么ldrex / strex将在那里,你不必检查,假设这不是在cortex-m上运行,而是arm11或cortex-a / r。
#1
4
LDREX
/STREX
were introduced in the ARMv6 architecture, so you just need to check the architecture version - if it's v6 or later, you have them. If not, you don't. From privileged code you could read the MIDR directly, otherwise some userspace interface like /proc/cpuinfo
.
LDREX / STREX是在ARMv6架构中引入的,因此您只需要检查架构版本 - 如果它是v6或更高版本,您就拥有它们。如果没有,你就不这样做。从特权代码中你可以直接读取MIDR,否则一些用户空间接口就像/ proc / cpuinfo。
If you really need to implement atomics that work across all architecture versions, you may be better off relying on the cmpxchg
provided by the Kernel User helpers than trying to roll your own.
如果你真的需要实现适用于所有架构版本的原子,那么你可能最好依靠内核用户助手提供的cmpxchg,而不是试图自己推出。
#2
0
Mpcore, the TRM doesnt say if you can or cant access this in a non-priveledged mode.
Mpcore,TRM没有说你是否可以在非priveledged模式下访问它。
MRC p15,0,<Rd>,c0,c0,0; reads Main ID register
The cpu id register a few after that does explicitly say: accessible in privileged modes only So I would hope/assume the arm docs would have said the same thing about the main id register. of course how many main id register answers do you have to wade through to verify what core this is or not?
cpu id注册了一些之后明确说明:只能在特权模式下访问所以我希望/假设arm文档会对主id寄存器说同样的事情。当然有多少主要的id寄存器答案,你必须通过验证核实这是什么核心?
Ahh, MIDR = Main ID Register, Notlikethat mentioned MIDR, I guess it is an easy test to see if you can access the MIDR in user mode...
啊,MIDR =主ID寄存器,Notlikethat提到MIDR,我想这是一个简单的测试,看看你是否可以在用户模式下访问MIDR ...
EDIT:
编辑:
The 1176 does clearly state about the MIDR.
1176确实明确说明了MIDR。
accessible in privileged modes only.
仅在特权模式下可访问。
I wonder if that restriction went away.
我想知道这种限制是否消失了。
EDIT2:
EDIT2:
Verified on an mpcore, that you cannot access the MIDR in user mode.
在mpcore上验证,您无法在用户模式下访问MIDR。
EDIT3:
EDIT3:
I think you have to rely on the kernel to help out userspace. And/or if you only support ARMv6 or newer then ldrex/strex will be there and you dont have to check, assuming this is not running on a cortex-m, but an arm11 or cortex-a/r.
我认为你必须依靠内核来帮助用户空间。和/或如果你只支持ARMv6或更新,那么ldrex / strex将在那里,你不必检查,假设这不是在cortex-m上运行,而是arm11或cortex-a / r。