diff options
author | Jack Lloyd <[email protected]> | 2017-01-04 15:24:57 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-01-04 15:24:57 -0500 |
commit | a0330350f7f43bddb4a41e2db87ed0b8e2c955b3 (patch) | |
tree | 11fe8af9cf207cf1898f89e86ae722411582dd47 | |
parent | 51b83c2f3807cfd36744b94dfe337a6d31f00847 (diff) |
Improve CPU detection logic. Read /proc/cpuinfo when available.
Sometimes platform module is very useless and returns empty strings
or bogus data. /proc/cpuinfo at least provides another data point.
Refactor how processor guessing is done, now input values are collected,
from platform module and /proc/cpuinfo, then each considered as if it
had been passed to --cpu option.
All this could be simplified further since we no longer rely on the submodel
settings much anymore. If someone wanted to compile specially for their CPU
they could specify that with --cc-abi-flags (or --cxxflags when that's added).
Not making that change here.
-rwxr-xr-x | configure.py | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/configure.py b/configure.py index 979493b4f..f33356d6e 100755 --- a/configure.py +++ b/configure.py @@ -1147,32 +1147,43 @@ def canon_processor(archinfo, proc): proc, match, submodel)) return (ainfo.basename, submodel) - logging.debug('Known CPU names: ' + ' '.join( - sorted(flatten([[ainfo.basename] + \ - ainfo.aliases + \ - [x for (x,_) in ainfo.all_submodels()] - for ainfo in archinfo.values()])))) +def system_cpu_info(): - raise Exception('Unknown or unidentifiable processor "%s"' % (proc)) + cpu_info = [] -def guess_processor(archinfo): - base_proc = platform.machine() + with open('/proc/cpuinfo') as f: + for line in f.readlines(): + if line.find(':') != -1: + (key,val) = [s.strip() for s in line.split(':')] - if base_proc == '': - raise Exception('Could not determine target CPU; set with --cpu') + # Different Linux arch use different names for this field in cpuinfo + if key in ["model name", "cpu model", "Processor"]: + cpu_info.append(val) + break - full_proc = fixup_proc_name(platform.processor()) or base_proc + if platform.processor() != '': + cpu_info.append(platform.processor()) - for ainfo in archinfo.values(): - if ainfo.basename == base_proc or base_proc in ainfo.aliases: - for (match,submodel) in ainfo.all_submodels(): - if re.search(match, full_proc) != None: - return (ainfo.basename, submodel) + if platform.machine() != '': + cpu_info.append(platform.machine()) + + return cpu_info - return canon_processor(archinfo, ainfo.basename) +def guess_processor(archinfo): + cpu_info = system_cpu_info() - # No matches, so just use the base proc type - return canon_processor(archinfo, base_proc) + for input in cpu_info: + + if input != '': + try: + match = canon_processor(archinfo, input) + if match != None: + logging.debug("Matched '%s' to processor '%s'" % (input, match)) + return match + except Exception as e: + logging.debug("Failed to deduce CPU from '%s'" % (input)) + + raise Exception('Could not determine target CPU; set with --cpu') """ Read a whole file into memory as a string @@ -2108,6 +2119,12 @@ def main(argv = None): for policy in module_policies.values(): policy.cross_check(modules) + logging.debug('Known CPU names: ' + ' '.join( + sorted(flatten([[ainfo.basename] + \ + ainfo.aliases + \ + [x for (x,_) in ainfo.all_submodels()] + for ainfo in info_arch.values()])))) + if options.list_modules: for k in sorted(modules.keys()): print(k) @@ -2180,9 +2197,15 @@ def main(argv = None): options.arch, options.cpu)) else: cpu_from_user = options.cpu - (options.arch, options.cpu) = canon_processor(info_arch, options.cpu) - logging.info('Canonicalizized CPU target %s to %s/%s' % ( - cpu_from_user, options.arch, options.cpu)) + + results = canon_processor(info_arch, options.cpu) + + if results != None: + (options.arch, options.cpu) = results + logging.info('Canonicalizized CPU target %s to %s/%s' % ( + cpu_from_user, options.arch, options.cpu)) + else: + logging.error('Unknown or unidentifiable processor "%s"' % (options.cpu)) logging.info('Target is %s-%s-%s-%s' % ( options.compiler, options.os, options.arch, options.cpu)) |