Improved ARM platform/CPU detection#1953
Conversation
for x86_64, POWER, AArch32, and AArch64
| POWER = 'POWER' | ||
| X86_64 = 'x86_64' | ||
|
|
||
| AMD = 'AMD' |
There was a problem hiding this comment.
make it clear that these are vendors, while the above are architectures (with a comment)
| 'ARM': ARM, | ||
| CPU_ARCHITECTURES = [AARCH32, AARCH64, POWER, X86_64] | ||
| CPU_FAMILIES = [AMD, ARM, INTEL, POWER] | ||
| CPU_VENDORS = [AMD, APM, ARM, BROADCOM, CAVIUM, DEC, IBM, INTEL, MARVELL, MOTOROLA, NVIDIA, QUALCOMM, MARVELL] |
There was a problem hiding this comment.
@geimer MARVELL is listed twice, your sorting algorithm is broken ;)
There was a problem hiding this comment.
Hmm... seems like it's using [begin,end] rather than [begin,end(
Have to check... ;)
| CPU_ARCHITECTURES = [AARCH32, AARCH64, POWER, X86_64] | ||
| CPU_FAMILIES = [AMD, ARM, INTEL, POWER] | ||
| CPU_VENDORS = [AMD, APM, ARM, BROADCOM, CAVIUM, DEC, IBM, INTEL, MARVELL, MOTOROLA, NVIDIA, QUALCOMM, MARVELL] | ||
| VENDOR_IDS = { |
| 'GenuineIntel': INTEL, | ||
| 'IBM': IBM, | ||
| } | ||
| ARM_CORTEX_IDS = { |
| arch = AARCH64 | ||
| elif power_regex.match(machine): | ||
| arch = POWER | ||
| elif machine == 'x86_64': |
There was a problem hiding this comment.
rather than sorting alphabetically, I would try and rank these by how common they are, to short-circuit early in the most common case (i.e. x86_64)?
There was a problem hiding this comment.
also, compare with X86_64 constant here?
| elif arch == POWER: | ||
| vendor_regex = re.compile(r"model\s+:\s*(\w+)") | ||
| elif arch == X86_64: | ||
| vendor_regex = re.compile(r"vendor_id\s+:\s*(\S+)") |
|
|
||
| else: | ||
| arch = get_cpu_architecture() | ||
| if arch in [AARCH32, AARCH64]: |
There was a problem hiding this comment.
if get_cpu_architecture() in [AARCH32, AARCH64]:since arch is only used in one place?
There was a problem hiding this comment.
I personally find the function call within the if statement less readable. But this is a matter of taste, of course.
There was a problem hiding this comment.
well, consider this a suggestion, ok to leave it as is if you like this better
| # we need 'model name' on Linux/x86, but 'model' is there first with different info | ||
| # 'model name' is not there for Linux/POWER, but 'model' has the right info | ||
| model_regex = re.compile(r"^model(?:\s+name)?\s+:\s*(?P<model>.*[A-Za-z].+)\s*$", re.M) | ||
| txt = read_file(PROC_CPUINFO_FP) |
There was a problem hiding this comment.
move this down too, to where it's actually used (i.e. in the else), and maybe rename txt to proc_cpuinfo?
There was a problem hiding this comment.
The txt variable is actually used in both branches of the if statement...
But I'm fine with renaming. Makes sense.
There was a problem hiding this comment.
ah, ok, my bad...
if you rename txt, do it consistently throughout this module where we read PROC_CPUINFO_FP please :)
| if res: | ||
| model_ids = list(set(res)) | ||
| id_list = [] | ||
| for model_id in model_ids: |
There was a problem hiding this comment.
model_ids = model_regex.findall(txt)
if model_ids:
id_list = []
for model_id in set(model_ids):There was a problem hiding this comment.
Will the iteration order be the same for every run? OK, I may have missed a sort() call in my first attempt, but that's a different story...
There was a problem hiding this comment.
No, there's no order in a set, and creating a list from it isn't going to change that (the order you get in the list may in theory be different every time).
If you want to guarantee order over unique elements, use sorted(set(model_ids))
| if model_id in ARM_CORTEX_IDS: | ||
| id_list.append(ARM_CORTEX_IDS[model_id]) | ||
| else: | ||
| id_list.append(UNKNOWN) |
There was a problem hiding this comment.
collapse to:
id_list.append(ARM_CORTEX_IDS.get(model_id, UNKNOWN))|
@geimer: thanks for the bump, I lost track of this, sorry Looks perfect now, so going in, thanks again for all your effort on this one! |
This PR revises several functions in
framework.tools.systemtools, especially to improve the platform/CPU detection for ARM-based systems.