Skip to content

Commit

Permalink
Only add the overhead for each iteration of cpuinfo parsing if Xen is…
Browse files Browse the repository at this point in the history
… detected
  • Loading branch information
maxamillion committed Jan 7, 2015
1 parent 3729259 commit f274234
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/ansible/module_utils/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,33 @@ def get_cpu_facts(self):
coreid = 0
sockets = {}
cores = {}

xen = 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):
return
self.facts['processor'] = []
for line in open("/proc/cpuinfo").readlines():
data = line.split(":", 1)
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)
# works for some ARM devices, like the Sheevaplug.
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
Expand All @@ -628,13 +647,6 @@ def get_cpu_facts(self):
if key == 'model name':
model_name_occurrence += 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':
physid = data[1].strip()
if physid not in sockets:
Expand Down

0 comments on commit f274234

Please sign in to comment.