mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make the CPU facts Hyperthreading aware
This commit is contained in:
parent
f8396622fa
commit
efc4bc10d4
1 changed files with 14 additions and 6 deletions
|
@ -518,7 +518,9 @@ class LinuxHardware(Hardware):
|
||||||
def get_cpu_facts(self):
|
def get_cpu_facts(self):
|
||||||
i = 0
|
i = 0
|
||||||
physid = 0
|
physid = 0
|
||||||
|
coreid = 0
|
||||||
sockets = {}
|
sockets = {}
|
||||||
|
cores = {}
|
||||||
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'] = []
|
||||||
|
@ -536,14 +538,20 @@ class LinuxHardware(Hardware):
|
||||||
physid = data[1].strip()
|
physid = data[1].strip()
|
||||||
if physid not in sockets:
|
if physid not in sockets:
|
||||||
sockets[physid] = 1
|
sockets[physid] = 1
|
||||||
|
elif key == 'core id':
|
||||||
|
coreid = data[1].strip()
|
||||||
|
if coreid not in sockets:
|
||||||
|
cores[coreid] = 1
|
||||||
elif key == 'cpu cores':
|
elif key == 'cpu cores':
|
||||||
sockets[physid] = int(data[1].strip())
|
sockets[physid] = int(data[1].strip())
|
||||||
if len(sockets) > 0:
|
elif key == 'siblings':
|
||||||
self.facts['processor_count'] = len(sockets)
|
cores[coreid] = int(data[1].strip())
|
||||||
self.facts['processor_cores'] = reduce(lambda x, y: x + y, sockets.values())
|
self.facts['processor_count'] = sockets and len(sockets) or i
|
||||||
else:
|
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'] = 'NA'
|
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…
Reference in a new issue