[initcpiocfg] Refactor CPU-characteristics determination

The code is still over-wrought, but the API for cpuinfo
now exposes the interesting thing (is it Intel?) in
a useful -- more readable -- way.
This commit is contained in:
Adriaan de Groot 2021-09-21 12:42:58 +02:00
parent ee4da8fcc7
commit 45daebd989

View File

@ -28,7 +28,29 @@ def pretty_name():
return _("Configuring mkinitcpio.")
def cpuinfo():
class cpuinfo(object):
"""
Object describing the current CPU's characteristics. It may be
be considered a named tuple, there's no behavior here.
Fields in the object:
- is_intel (if it's definitely an Intel CPU)
- is_amd (if it's definitely an AMD CPU)
- number_of_cores
It is possible for both is_* fields to be False.
"""
def __init__(self):
self.is_intel = False
self.is_amd = False
self.number_of_cores = 0
cpu = self._cpuinfo()
self.is_intel = cpu['proc0']['vendor_id'].lower() == "genuineintel"
self.is_amd = cpu['proc0']['vendor_id'].lower() == "authenticamd"
self.number_of_cores = len(cpu)
@staticmethod
def _cpuinfo():
"""
Return the information in /proc/cpuinfo as a dictionary in the following
format:
@ -172,10 +194,9 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
else:
hooks.extend(["filesystems"])
if btrfs == "yes" and cpu['proc0']['vendor_id'].lower() != "genuineintel":
if btrfs == "yes" and not cpu.is_intel:
modules.append("crc32c")
elif (btrfs == "yes"
and cpu['proc0']['vendor_id'].lower() == "genuineintel"):
elif (btrfs == "yes" and cpu.is_intel):
modules.append("crc32c-intel")
else:
hooks.append("fsck")