int ProbePointerBits(int *sure) { int i; char *uname; char *cmnd, *res; *sure = 0; /* * This probe should be running on backend; if its ptr length is 8, we've * definitely got a 64 bit machine * NOTE: getting 4 could be a result of compiler flags on a 64-bit arch, * so reverse is not dispositive */ if (sizeof(void*) == 8) { *sure = 1; return(64); } res = atlsys_1L(NULL, "/usr/sbin/prtconf | fgrep 'Kernel Type'", 0, 0); if (res) { if (GetLastInt(res) == 64) { *sure = 1; free(res); return(64); } free(res); } /* * Note this is a weak probe, archinfo_x86 much better . . . */ uname = FindUname(NULL); i = strlen(uname) + 4; cmnd = malloc(sizeof(char)*i); assert(cmnd); sprintf(cmnd, "%s -a", uname); res = atlsys_1L(NULL, cmnd, 0, 0); free(cmnd); if (res) { /* * If uname is a known 64-bit platform, we're sure we've got OS support * for 64bits (may not have compiler support, but that's not our fault) */ if (strstr(res, "x86_64") || strstr(res, "ppc64") || strstr(res, "ia64")) { *sure = 1; free(res); return(64); } free(res); } return(32); }
int ProbeMhz() { int mhz=0; char res[1024]; if (!CmndOneLine(NULL, "fgrep 'cpu MHz' /proc/cpuinfo", res)) mhz = GetFirstInt(res); if (!mhz && !CmndOneLine(NULL, "cat /proc/cpuinfo | fgrep clock | fgrep MHz", res)) mhz = GetLastInt(res); return(mhz); }
int ConfirmPtrbits(enum OSTYPE OS0, enum ASMDIA asmd0, char *targ0, char *flag, char *find, int *sure) /* * Retries pointer width probe using -m64; OK to fail: use prior val in that * case */ { char osname[128]; char *cmnd, *res, *targ; char *frm="make IRunArchInfo_%s MYFLAGS=\"-m64 -DATL_OS_%s -DATL_%s\" args=\"%s\" %s | fgrep '%s'"; enum OSTYPE OS; enum ASMDIA asmd; int i, iret=0; *sure = 0; asmd = (asmd0 > ASM_None && asmd0 < NASMD) ? asmd0 : gas_x86_32; OS = (OS0 > OSOther && OS0 < NOS) ? OS0 : OSLinux; i = (OS == OSOSX) ? OSFreeBSD : OS; assert(strlen(osnam[i]) < 128); strlowcpy(osname, osnam[i]); if (targ0) { i = strlen(targ0) + 24; targ = malloc(sizeof(char)*i); assert(targ); sprintf(targ, "atlrun=atlas_runX targ=%s", targ0); } else { targ = malloc(sizeof(char)); assert(targ); targ[0] = '\0'; } /* * Try OS-specific probe, compiling with -m64 (assumes gcc workalike) */ i = 1 + strlen(frm) + strlen(osnam) + strlen(osnam[OS]) + strlen(ASMNAM[asmd]) + strlen(flag) + strlen(targ) + strlen(find); cmnd = malloc(i*sizeof(char)); assert(cmnd); sprintf(cmnd, frm, osname, osnam[OS], ASMNAM[asmd], flag, targ, find); free(targ); res = atlsys_1L(NULL, cmnd, 0, 0); free(cmnd); if (res) { iret = GetFirstInt(res); *sure = GetLastInt(res); free(res); } return(iret); }
int ProbeMhz() { int mhz=0; char *res; res = atlsys_1L(NULL, "/usr/sbin/prtconf | fgrep 'Processor Clock Speed'", 0, 0); if (res) { mhz = GetLastInt(res); /* assumes clock speed always given in MHz */ free(res); } return(mhz); }
int ProbeNCPU() { int ncpu = 0; char *res; res = atlsys_1L(NULL, "/usr/sbin/prtconf | fgrep 'Number Of Processors'", 0, 0); if (res) { ncpu = GetLastInt(res); free(res); } return(ncpu); }
int ProbeNCPU() { int ncpu = 0; char *reslns, res[1024]; #if 0 if (mach == Dec21264 || mach == Dec21164 || mach == Dec21064) { if ( !CmndOneLine(NULL, "fgrep 'cpus detected' /proc/cpuinfo", res) ) ncpu = GetLastInt(res); } #endif if (!ncpu) { reslns = CmndResults(NULL, "grep '^processor' /proc/cpuinfo"); if (reslns) ncpu = fNumLines(reslns); } return(ncpu); }
int ProbeOneInt(enum OSTYPE OS0, enum ASMDIA asmd0, char *targ0, char *flag, char *find, int *sure) /* * Handles calls to all available backend probes that return one int, * keeps trying them until out of probes or one returns good (non-zero) value */ { char osname[128]; char *cmnd, *res, *frm, *targ; enum OSTYPE OS; enum ASMDIA asmd; int i, iret=0; *sure = 0; asmd = (asmd0 > ASM_None && asmd0 < NASMD) ? asmd0 : gas_x86_32; OS = (OS0 > OSOther && OS0 < NOS) ? OS0 : OSLinux; if (OS == OSOSX) strlowcpy(osname, osnam[OSFreeBSD]); else if (OSIsWin(OS)) strcpy(osname, "win"); else strlowcpy(osname, osnam[OS]); if (targ0) { i = strlen(targ0) + 24; targ = malloc(sizeof(char)*i); assert(targ); sprintf(targ, "atlrun=atlas_runX targ=%s", targ0); } else { targ = malloc(sizeof(char)); assert(targ); targ[0] = '\0'; } /* * If Assembler right or unspecified, try x86 probe */ if (asmd == gas_x86_32 || asmd == gas_x86_64) { frm = "make IRunArchInfo_x86 MYFLAGS=\"-DATL_OS_%s -DATL_%s\" args=\"%s\" %s | fgrep '%s'"; i = strlen(frm) + strlen(osnam[OS]) + strlen(ASMNAM[asmd]) + strlen(flag) + strlen(targ) + strlen(find) + 1; cmnd = malloc(sizeof(char)*i); assert(cmnd); sprintf(cmnd, frm, osnam[OS], ASMNAM[asmd], flag, targ, find); res = atlsys_1L(NULL, cmnd, 0, 0); if (res) { iret = GetFirstInt(res); *sure = GetLastInt(res); free(res); } free(cmnd); } /* * If that didn't work, try OS-specific probe */ if (!iret) { frm = "make IRunArchInfo_%s MYFLAGS=\"-DATL_OS_%s -DATL_%s\" args=\"%s\" %s | fgrep '%s'"; i = 1 + strlen(frm) + strlen(osname) + 3+strlen(osnam[OS]) + strlen(ASMNAM[asmd]) + strlen(flag) + strlen(targ) + strlen(find); cmnd = malloc(sizeof(char)*i); assert(cmnd); sprintf(cmnd, frm, osname, osnam[OS], ASMNAM[asmd], flag, targ, find); res = atlsys_1L(NULL, cmnd, 0, 0); if (res) { iret = GetFirstInt(res); *sure = GetLastInt(res); free(res); } free(cmnd); } return(iret); }
enum MACHTYPE ProbeArch() { enum ARCHFAM fam; enum MACHTYPE mach=MACHOther; int ierr, i; char res[1024]; fam = ProbeArchFam(NULL); switch(fam) { case AFPPC: if ( !CmndOneLine(NULL, "cat /proc/cpuinfo | fgrep cpu", res) ) { #if 0 if (strstr(res, "604e")) mach = PPC604e; else if (strstr(res, "604")) mach = PPC604; else #endif if (strstr(res, "G4")) mach = PPCG4; else if (strstr(res, "7400")) mach = PPCG4; else if (strstr(res, "7410")) mach = PPCG4; else if (strstr(res, "7447")) mach = PPCG4; else if (strstr(res, "7455")) mach = PPCG4; else if (strstr(res, "PPC970FX")) mach = PPCG5; else if (strstr(res, "PPC970MP")) mach = PPCG5; else if (strstr(res, "POWER7")) mach = IbmPwr7; else if (strstr(res, "POWER6")) mach = IbmPwr6; else if (strstr(res, "POWER5")) mach = IbmPwr5; else if (strstr(res, "POWER4")) mach = IbmPwr4; } break; case AFMIPS: res[0] = '\0'; ierr = CmndOneLine(NULL, "fgrep 'cpu model' /proc/cpuinfo", res); if (!ierr && res[0] != '\0') { if (strstr(res, "ICE9")) mach = MIPSICE9; /* * I have no access to what cpuinfo on Linux does for this procs, so this * is a WAG as to what it would say */ else if (strstr(res, "R10000") || strstr(res, "R12000") || strstr(res, "R12000") || strstr(res, "R14000")) mach = MIPSR1xK; } break; case AFIA64: res[0] = '\0'; ierr = CmndOneLine(NULL, "fgrep 'IA-64' /proc/cpuinfo", res); if (ierr || res[0] == '\0') ierr = CmndOneLine(NULL, "fgrep \"model name\" /proc/cpuinfo", res); if (!ierr && res[0] != '\0') { if (strstr(res, "IA-64") || strstr(res, "McKinley")) mach = IA64Itan2; else if (strstr(res, "Itanium")) mach = IA64Itan; } break; case AFX86: res[0] = '\0'; ierr = CmndOneLine(NULL, "fgrep 'model name' /proc/cpuinfo", res); if (ierr || res[0] == '\0') ierr = CmndOneLine(NULL, "fgrep model /proc/cpuinfo", res); if (!ierr && res[0] != '\0') { if (strstr(res, "Pentium")) { /* Pentium of some flavor */ if (strstr(res, " III ")) mach = IntPIII; else if (strstr(res, " II ")) mach = IntPII; else if (strstr(res, "Pro")) mach = IntPPRO; else if (strstr(res, "MMX")) mach = IntP5MMX; else if (strstr(res, " 4 ")) { ierr = CmndOneLine(NULL, "fgrep 'model' /proc/cpuinfo | fgrep -v 'name'", res); if (!ierr) { i = GetLastInt(res); if (i < 3) mach = IntP4; else if (i == 3) mach = IntP4E; } } } else if (strstr(res, "Core")) { if (strstr(res, "i7")) { if (strstr(res, "2600")) mach = IntCorei2; else mach = IntCorei1; } if (strstr(res, "i5")) { if (strstr(res, "i5-2500") || strstr(res, "i5-2400") || strstr(res, "i5-2390") || strstr(res, "i5-2300")) mach = IntCorei2; else mach = IntCorei1; } } else if (strstr(res, "Xeon")) /* dreaded Xeon-is-anything */ { if (strstr(res, "E5420")) mach = IntCore2; } else if (strstr(res, "Efficeon")) mach = TMEff; else if (strstr(res, "Athlon HX")) mach = AmdHammer; else if (strstr(res, "Opteron") || strstr(res, "Hammer") || strstr(res, "Athlon(tm) 64")) mach = AmdHammer; else if (strstr(res, "Athlon")) mach = AmdAthlon; else if (strstr(res, "AMD-K7")) mach = AmdAthlon; } break; /* * Add these back if we get machine access and can test */ case AFSPARC: /* don't know here anymore */ #if 0 if ( !CmndOneLine(NULL, "fgrep cpu /proc/cpuinfo", res) ) { if (strstr(res, "UltraSparc II")) mach = SunUS2; else if (strstr(res, "UltraSparc I")) mach = SunUS1; else if (strstr(res, "UltraSparc")) mach = SunUSX; } #endif break; case AFALPHA: #if 0 res[0] = '\0'; ierr = CmndOneLine(NULL, "fgrep 'model name' /proc/cpuinfo", res); if (ierr || res[0] == '\0') ierr = CmndOneLine(NULL, "fgrep model /proc/cpuinfo", res); if (!ierr && res[0] != '\0') { if (strstr(res, "EV5")) mach = Dec21164; else if (strstr(res, "EV4")) mach = Dec21064; else if (strstr(res, "EV6")) mach = Dec21264; } #endif break; default: #if 0 if (!CmndOneLine(NULL, "fgrep 'cpu family' /proc/cpuinfo", res)) if (strstr(res, "PA-RISC 2.0")) mach = HPPA20; #else ; #endif } return(mach); }