Merge pull request #2952 from martin-frbg/issue2931

Try to read cpu ID from /sys/devices/.../cpu0 if HWCAP_CPUID fails
This commit is contained in:
Martin Kroeker 2020-10-28 09:37:32 +01:00 committed by GitHub
commit 2207a16235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 7 deletions

View File

@ -139,19 +139,30 @@ static gotoblas_t *force_coretype(char *coretype) {
static gotoblas_t *get_coretype(void) { static gotoblas_t *get_coretype(void) {
int implementer, variant, part, arch, revision, midr_el1; int implementer, variant, part, arch, revision, midr_el1;
char coremsg[128];
#if (!defined OS_LINUX && !defined OS_ANDROID)
return NULL;
#endif
#if (defined OS_LINUX || defined OS_ANDROID)
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) { if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
char coremsg[128]; #ifdef __linux
FILE *infile;
char buffer[512], *p, *cpu_part = NULL, *cpu_implementer = NULL;
p = (char *) NULL ;
infile = fopen("/sys/devices/system/cpu/cpu0/regs/identification/midr_el1","r");
if (!infile) return NULL;
fgets(buffer, sizeof(buffer), infile);
midr_el1=strtoul(buffer,NULL,16);
fclose(infile);
#else
snprintf(coremsg, 128, "Kernel lacks cpuid feature support. Auto detection of core type failed !!!\n"); snprintf(coremsg, 128, "Kernel lacks cpuid feature support. Auto detection of core type failed !!!\n");
openblas_warning(1, coremsg); openblas_warning(1, coremsg);
return NULL; return NULL;
}
#else
return NULL;
#endif #endif
} else {
get_cpu_ftr(MIDR_EL1, midr_el1); get_cpu_ftr(MIDR_EL1, midr_el1);
}
/* /*
* MIDR_EL1 * MIDR_EL1
* *
@ -219,6 +230,9 @@ static gotoblas_t *get_coretype(void) {
return &gotoblas_FALKOR; return &gotoblas_FALKOR;
} }
break; break;
default:
snprintf(coremsg, 128, "Unknown CPU model - implementer %x part %x\n",implementer,part);
openblas_warning(1, coremsg);
} }
return NULL; return NULL;
} }