Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top