Skip to content

Improved ARM platform/CPU detection#1953

Merged
boegel merged 8 commits intoeasybuilders:developfrom
geimer:cpu_detection
Oct 27, 2016
Merged

Improved ARM platform/CPU detection#1953
boegel merged 8 commits intoeasybuilders:developfrom
geimer:cpu_detection

Conversation

@geimer
Copy link
Copy Markdown
Contributor

@geimer geimer commented Oct 9, 2016

This PR revises several functions in framework.tools.systemtools, especially to improve the platform/CPU detection for ARM-based systems.

@geimer geimer mentioned this pull request Oct 9, 2016
4 tasks
@boegel boegel added this to the v3.0 milestone Oct 10, 2016
POWER = 'POWER'
X86_64 = 'x86_64'

AMD = 'AMD'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it clear that these are vendors, while the above are architectures (with a comment)

Comment thread easybuild/tools/systemtools.py Outdated
'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]
Copy link
Copy Markdown
Member

@boegel boegel Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geimer MARVELL is listed twice, your sorting algorithm is broken ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reference for this list?

'GenuineIntel': INTEL,
'IBM': IBM,
}
ARM_CORTEX_IDS = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref?

Comment thread easybuild/tools/systemtools.py Outdated
arch = AARCH64
elif power_regex.match(machine):
arch = POWER
elif machine == 'x86_64':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, compare with X86_64 constant here?

Comment thread easybuild/tools/systemtools.py Outdated
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+)")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, sort by most common?


else:
arch = get_cpu_architecture()
if arch in [AARCH32, AARCH64]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if get_cpu_architecture() in [AARCH32, AARCH64]:

since arch is only used in one place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally find the function call within the if statement less readable. But this is a matter of taste, of course.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, consider this a suggestion, ok to leave it as is if you like this better

Comment thread easybuild/tools/systemtools.py Outdated
# 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this down too, to where it's actually used (i.e. in the else), and maybe rename txt to proc_cpuinfo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The txt variable is actually used in both branches of the if statement...
But I'm fine with renaming. Makes sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, my bad...

if you rename txt, do it consistently throughout this module where we read PROC_CPUINFO_FP please :)

Comment thread easybuild/tools/systemtools.py Outdated
if res:
model_ids = list(set(res))
id_list = []
for model_id in model_ids:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_ids = model_regex.findall(txt)
if model_ids:
    id_list = []
    for model_id in set(model_ids):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Comment thread easybuild/tools/systemtools.py Outdated
if model_id in ARM_CORTEX_IDS:
id_list.append(ARM_CORTEX_IDS[model_id])
else:
id_list.append(UNKNOWN)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collapse to:

id_list.append(ARM_CORTEX_IDS.get(model_id, UNKNOWN))

@geimer
Copy link
Copy Markdown
Contributor Author

geimer commented Oct 27, 2016

@boegel Would you please take another look at this? I almost believe that this PR is a prerequisite for further work on #1952. Thanks!

@boegel
Copy link
Copy Markdown
Member

boegel commented Oct 27, 2016

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants