1

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).

Peeter Joot
  • 7,848
  • 7
  • 48
  • 82
  • Related to your use of `__power_set`, see OpenSSL's usage and comments at [`ppccap.c`](https://github.com/openssl/openssl/blob/master/crypto/ppccap.c). OpenSSL uses a trick for *"POWER7 and above"*. Regarding your Linux question, also see [Detect Power8 in-core crypto through getauxval?](https://stackoverflow.com/q/46144668/608639) – jww Mar 17 '18 at 14:43

2 Answers2

2

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

chmeee
  • 3,608
  • 1
  • 21
  • 28
  • I see hints that this is either not allowed in userspace code: http://cr.yp.to/hardware/ppc.html or may be emulated: http://lkml.indiana.edu/hypermail/linux/kernel/0503.1/1147.html but will try it. – Peeter Joot Jul 21 '12 at 15:19
  • I get an illegal instruction on AIX (using: __asm__ ( "mfpvr %0\n\t" : "=r"(v) )), and on LinuxPPC (on a POWER5 machine according to /proc/cpuinfo) I get: 0x3A0203. Any idea how to decode the mfpvr return? – Peeter Joot Jul 21 '12 at 15:51
  • You're right, the PVR is supervisor-only, my mistake. I don't know offhand if 64-bit is different, but the ppc32 PEM states bits 0-15 identify a particular processor version, while bits 16-31 identify various releases (engineering fixes) within that version. From what I can find online, the processor version (bits 0-15) is assigned by Power.org, while the revision number is implementation-specific. – chmeee Jul 21 '12 at 23:09
-1

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?

Community
  • 1
  • 1
Peeter Joot
  • 7,848
  • 7
  • 48
  • 82