Is there something like x86 cpuid() available for PowerPC?

被刻印的时光 ゝ 提交于 2019-12-13 18:30:55

问题


I'd like to write some C code be able to query processor attributes on PowerPC, much like one can do with cpuid on x86. I'm after things like brand, model, stepping, SIMD width, available operations, so that there can be run-time confirmation that the code is being used on a compatible platform before something blows up.

Is there a general mechanism for doing this on PowerPC? If so, where can one read about it?


回答1:


Note that PowerPC has not dozens of extensions / features like x86. It is required to read specific privileged registers that may depend on cores.

I checked on Linux and you can access PVR, there is a trap in the kernel to manage that.

Reading /proc/cpuinfo can return if Altivec is supported, the memory and L2 cache size ... but that is not really convenient.

A better solution is described here: http://www.freehackers.org/thomas/2011/05/13/how-to-detect-altivec-availability-on-linuxppc-at-runtime/

That uses the content of /proc/self/auxv that provides "the ELF interpreter information passed to the process at exec time".

The example is about Altivec but you can get other features (listed in include "asm/cputable.h"): 32 or 64 bit cpu, Altivec, SPE, FPU, MMU, 4xx MAC, ...

Last, you will find information on caches (size, line size, associativity, ...), look at files in: /sys/devices/system/cpu/cpu0/cache




回答2:


PowerPC doesn't have an analogue to the CPUID instruction. The closest you can get is to read the PVR (processor version register). This is a supervisor-privileged SPR, though. However, some operating systems, FreeBSD for example, will trap and execute that for user space processes.

The PVR is read-only, and should be unique for any given processor model and revision. Given this, you can ascertain what features are provided by a given CPU.



来源:https://stackoverflow.com/questions/17948969/is-there-something-like-x86-cpuid-available-for-powerpc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!