mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
Merge pull request #9947 from maxamillion/issue-9759-fix-processor-facts
don't double the count of i for LinuxHardware cpuinfo keys on 'vendor_id' and 'model name' keys
This commit is contained in:
commit
bd62530700
1 changed files with 44 additions and 7 deletions
|
@ -630,22 +630,49 @@ class LinuxHardware(Hardware):
|
||||||
|
|
||||||
def get_cpu_facts(self):
|
def get_cpu_facts(self):
|
||||||
i = 0
|
i = 0
|
||||||
|
vendor_id_occurrence = 0
|
||||||
|
model_name_occurrence = 0
|
||||||
physid = 0
|
physid = 0
|
||||||
coreid = 0
|
coreid = 0
|
||||||
sockets = {}
|
sockets = {}
|
||||||
cores = {}
|
cores = {}
|
||||||
|
|
||||||
|
xen = False
|
||||||
|
xen_paravirt = False
|
||||||
|
try:
|
||||||
|
if os.path.exists('/proc/xen'):
|
||||||
|
xen = True
|
||||||
|
elif open('/sys/hypervisor/type').readline().strip() == 'xen':
|
||||||
|
xen = True
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
if not os.access("/proc/cpuinfo", os.R_OK):
|
if not os.access("/proc/cpuinfo", os.R_OK):
|
||||||
return
|
return
|
||||||
self.facts['processor'] = []
|
self.facts['processor'] = []
|
||||||
for line in open("/proc/cpuinfo").readlines():
|
for line in open("/proc/cpuinfo").readlines():
|
||||||
data = line.split(":", 1)
|
data = line.split(":", 1)
|
||||||
key = data[0].strip()
|
key = data[0].strip()
|
||||||
|
|
||||||
|
if xen:
|
||||||
|
if key == 'flags':
|
||||||
|
# Check for vme cpu flag, Xen paravirt does not expose this.
|
||||||
|
# Need to detect Xen paravirt because it exposes cpuinfo
|
||||||
|
# differently than Xen HVM or KVM and causes reporting of
|
||||||
|
# only a single cpu core.
|
||||||
|
if 'vme' not in data:
|
||||||
|
xen_paravirt = True
|
||||||
|
|
||||||
# model name is for Intel arch, Processor (mind the uppercase P)
|
# model name is for Intel arch, Processor (mind the uppercase P)
|
||||||
# works for some ARM devices, like the Sheevaplug.
|
# works for some ARM devices, like the Sheevaplug.
|
||||||
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
|
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
|
||||||
if 'processor' not in self.facts:
|
if 'processor' not in self.facts:
|
||||||
self.facts['processor'] = []
|
self.facts['processor'] = []
|
||||||
self.facts['processor'].append(data[1].strip())
|
self.facts['processor'].append(data[1].strip())
|
||||||
|
if key == 'vendor_id':
|
||||||
|
vendor_id_occurrence += 1
|
||||||
|
if key == 'model name':
|
||||||
|
model_name_occurrence += 1
|
||||||
i += 1
|
i += 1
|
||||||
elif key == 'physical id':
|
elif key == 'physical id':
|
||||||
physid = data[1].strip()
|
physid = data[1].strip()
|
||||||
|
@ -661,13 +688,23 @@ class LinuxHardware(Hardware):
|
||||||
cores[coreid] = int(data[1].strip())
|
cores[coreid] = int(data[1].strip())
|
||||||
elif key == '# processors':
|
elif key == '# processors':
|
||||||
self.facts['processor_cores'] = int(data[1].strip())
|
self.facts['processor_cores'] = int(data[1].strip())
|
||||||
|
|
||||||
|
if vendor_id_occurrence == model_name_occurrence:
|
||||||
|
i = vendor_id_occurrence
|
||||||
|
|
||||||
if self.facts['architecture'] != 's390x':
|
if self.facts['architecture'] != 's390x':
|
||||||
self.facts['processor_count'] = sockets and len(sockets) or i
|
if xen_paravirt:
|
||||||
self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1
|
self.facts['processor_count'] = i
|
||||||
self.facts['processor_threads_per_core'] = ((cores.values() and
|
self.facts['processor_cores'] = i
|
||||||
cores.values()[0] or 1) / self.facts['processor_cores'])
|
self.facts['processor_threads_per_core'] = 1
|
||||||
self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] *
|
self.facts['processor_vcpus'] = i
|
||||||
self.facts['processor_count'] * self.facts['processor_cores'])
|
else:
|
||||||
|
self.facts['processor_count'] = sockets and len(sockets) or i
|
||||||
|
self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1
|
||||||
|
self.facts['processor_threads_per_core'] = ((cores.values() and
|
||||||
|
cores.values()[0] or 1) / self.facts['processor_cores'])
|
||||||
|
self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] *
|
||||||
|
self.facts['processor_count'] * self.facts['processor_cores'])
|
||||||
|
|
||||||
def get_dmi_facts(self):
|
def get_dmi_facts(self):
|
||||||
''' learn dmi facts from system
|
''' learn dmi facts from system
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue