问题
I can check for power7+ on AIX with something like:
inline bool ossPower7orLater( )
{
#if defined _AIX
if ( !__power_set( POWER_6 | POWER_5 | POWER_4 ) )
{
return true ;
}
else
#endif
return false ;
}
using macros from systemcfg.h. Here the __power_set()
macro is used instead of __power_7()
to avoid coding a check for power7 that will break when power8 comes out.
How would this be extended to include support for LinuxPPC too? I could imagine there's probably some instruction that could be used, so pointing me at that if there's nothing better would be acceptable (ie: I could code up an asm block if I knew what to use).
回答1:
The mfpvr
asm instruction can be used to get the processor version. Of course, this will likely break on later processors unless IBM follows a set pattern for its processor versioning, but it's a simple solution.
Note: mfpvr is supervisor-only, but LinuxPPC emulates it.
Another solution is to check /proc/cpuinfo
(very tedious, though). This will give you a string-representation of the CPU, as well as the PVR.
An example I found online:
processor : 0
cpu : POWER7 (architected), altivec supported
clock : 3550.000000MHz
revision : 2.0 (pvr 003f 0200)
I hope this helps
回答2:
Was able to do this by checking the ELF AUX header as discussed here:
programatic way to find ELF aux header (or envp) in shared library code?
来源:https://stackoverflow.com/questions/11250464/how-to-do-a-runtime-check-for-power7-or-greater-on-linuxppc