Merge pull request #2752 from kadler/cpuid_aix

Use systemcfg APIs for CPU detection on AIX
This commit is contained in:
Martin Kroeker 2020-07-31 12:52:24 +02:00 committed by GitHub
commit c88cbc5e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 28 deletions

View File

@ -38,6 +38,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#ifdef _AIX #ifdef _AIX
#include <sys/systemcfg.h>
#include <sys/vminfo.h> #include <sys/vminfo.h>
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
@ -137,35 +138,19 @@ int detect(void){
#endif #endif
#ifdef _AIX #ifdef _AIX
FILE *infile; // Cast from int to unsigned to ensure comparisons work for all bits in
char buffer[512], *p; // the bit mask, even the top bit
unsigned implementation = (unsigned) _system_configuration.implementation;
p = (char *)NULL; if (implementation >= 0x40000u) return CPUTYPE_POWER10;
infile = popen("prtconf|grep 'Processor Type'", "r"); else if (implementation & 0x20000) return CPUTYPE_POWER9;
while (fgets(buffer, sizeof(buffer), infile)){ else if (implementation & 0x10000) return CPUTYPE_POWER8;
if (!strncmp("Pro", buffer, 3)){ else if (implementation & 0x08000) return CPUTYPE_POWER7; // POWER 7
p = strchr(buffer, ':') + 2; else if (implementation & 0x04000) return CPUTYPE_POWER6;
#if 0 else if (implementation & 0x02000) return CPUTYPE_POWER5;
fprintf(stderr, "%s\n", p); else if (implementation & 0x01000) return CPUTYPE_POWER4; // MPC7450
#endif else if (implementation & 0x00800) return CPUTYPE_POWER4;
break; else return CPUTYPE_POWER3;
}
}
pclose(infile);
if (strstr(p, "POWER3")) return CPUTYPE_POWER3;
if (strstr(p, "POWER4")) return CPUTYPE_POWER4;
if (strstr(p, "PPC970")) return CPUTYPE_PPC970;
if (strstr(p, "POWER5")) return CPUTYPE_POWER5;
if (strstr(p, "POWER6")) return CPUTYPE_POWER6;
if (strstr(p, "POWER7")) return CPUTYPE_POWER6;
if (strstr(p, "POWER8")) return CPUTYPE_POWER8;
if (strstr(p, "POWER9")) return CPUTYPE_POWER9;
if (strstr(p, "POWER10")) return CPUTYPE_POWER10;
if (strstr(p, "Cell")) return CPUTYPE_CELL;
if (strstr(p, "7447")) return CPUTYPE_PPCG4;
return CPUTYPE_POWER5;
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__