From f274234824c8556362b9dea8516d4a5d6e44f392 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Wed, 7 Jan 2015 08:45:14 -0600 Subject: [PATCH] Only add the overhead for each iteration of cpuinfo parsing if Xen is detected --- lib/ansible/module_utils/facts.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index a3442d20bb..d9929c8338 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -609,7 +609,17 @@ class LinuxHardware(Hardware): 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'] = [] @@ -617,6 +627,15 @@ class LinuxHardware(Hardware): 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': @@ -628,13 +647,6 @@ class LinuxHardware(Hardware): 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: