How to do a runtime check for power7 or greater on LinuxPPC?

左心房为你撑大大i 提交于 2019-12-11 07:54:50

问题


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

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