mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 12:44:22 -07:00
Only add the overhead for each iteration of cpuinfo parsing if Xen is detected
This commit is contained in:
parent
3729259b68
commit
f274234824
1 changed files with 19 additions and 7 deletions
|
@ -609,7 +609,17 @@ class LinuxHardware(Hardware):
|
||||||
coreid = 0
|
coreid = 0
|
||||||
sockets = {}
|
sockets = {}
|
||||||
cores = {}
|
cores = {}
|
||||||
|
|
||||||
|
xen = False
|
||||||
xen_paravirt = False
|
xen_paravirt = False
|
||||||
|
if os.path.exists('/proc/xen'):
|
||||||
|
xen = True
|
||||||
|
try:
|
||||||
|
if 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'] = []
|
||||||
|
@ -617,6 +627,15 @@ class LinuxHardware(Hardware):
|
||||||
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':
|
||||||
|
@ -628,13 +647,6 @@ class LinuxHardware(Hardware):
|
||||||
if key == 'model name':
|
if key == 'model name':
|
||||||
model_name_occurrence += 1
|
model_name_occurrence += 1
|
||||||
i += 1
|
i += 1
|
||||||
elif 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
|
|
||||||
elif key == 'physical id':
|
elif key == 'physical id':
|
||||||
physid = data[1].strip()
|
physid = data[1].strip()
|
||||||
if physid not in sockets:
|
if physid not in sockets:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue