Change in vdsm[master]: caps: Do not memoize CPU topology

vdelima at redhat.com vdelima at redhat.com
Mon Oct 27 12:35:07 UTC 2014


Vitor de Lima has uploaded a new change for review.

Change subject: caps: Do not memoize CPU topology
......................................................................

caps: Do not memoize CPU topology

This patch prevents the CPU topology from being memoized and implements
a fast way to retrieve this information without looking at the libvirt
capabilities XML.

This is needed in order to support host CPU hotplugging, to avoid using
disabled logical CPUs and to rescan for topology changes in ppc64.

Change-Id: Ia0e87b50d4fe882240c93a0a1600e3a0cb98d443
Signed-off-by: Vitor de Lima <vdelima at redhat.com>
---
M tests/capsTests.py
M vdsm/caps.py
2 files changed, 27 insertions(+), 57 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/34189/2

diff --git a/tests/capsTests.py b/tests/capsTests.py
index a309f2e..79f48db 100644
--- a/tests/capsTests.py
+++ b/tests/capsTests.py
@@ -75,46 +75,6 @@
         self.assertEqual(c.model(),
                          'Intel(R) Xeon(R) CPU           E5649  @ 2.53GHz')
 
-    @MonkeyPatch(platform, 'machine', lambda: caps.Architecture.PPC64)
-    def testCpuTopologyPPC64(self):
-        testPath = os.path.realpath(__file__)
-        dirName = os.path.split(testPath)[0]
-        # PPC64 1 socket, 4 cores, 4 threads per core
-        path = os.path.join(dirName, "caps_lscpu_ppc64_1_4_4.out")
-        t = caps.CpuTopology(open(path).read())
-        self.assertEqual(t.threads(), 16)
-        self.assertEqual(t.cores(), 4)
-        self.assertEqual(t.sockets(), 4)
-        # PPC64 2 sockets, 8 cores, 8 threads per core
-        path = os.path.join(dirName, "caps_lscpu_ppc64_2_4_8.out")
-        t = caps.CpuTopology(open(path).read())
-        self.assertEqual(t.threads(), 64)
-        self.assertEqual(t.cores(), 8)
-        self.assertEqual(t.sockets(), 2)
-
-    @MonkeyPatch(platform, 'machine', lambda: caps.Architecture.X86_64)
-    def testCpuTopologyX86_64(self):
-        testPath = os.path.realpath(__file__)
-        dirName = os.path.split(testPath)[0]
-        # 2 x Intel E5649 (with Hyperthreading)
-        path = os.path.join(dirName, "caps_libvirt_intel_E5649.out")
-        t = caps.CpuTopology(file(path).read())
-        self.assertEqual(t.threads(), 24)
-        self.assertEqual(t.cores(), 12)
-        self.assertEqual(t.sockets(), 2)
-        # 2 x AMD 6272 (with Modules)
-        path = os.path.join(dirName, "caps_libvirt_amd_6274.out")
-        t = caps.CpuTopology(file(path).read())
-        self.assertEqual(t.threads(), 32)
-        self.assertEqual(t.cores(), 16)
-        self.assertEqual(t.sockets(), 2)
-        # 1 x Intel E31220 (normal Multi-core)
-        path = os.path.join(dirName, "caps_libvirt_intel_E31220.out")
-        t = caps.CpuTopology(file(path).read())
-        self.assertEqual(t.threads(), 4)
-        self.assertEqual(t.cores(), 4)
-        self.assertEqual(t.sockets(), 1)
-
     def testEmulatedMachines(self):
         capsData = self._readCaps("caps_libvirt_amd_6274.out")
         machines = caps._getEmulatedMachines(caps.Architecture.X86_64,
diff --git a/vdsm/caps.py b/vdsm/caps.py
index 996dd76..320268c 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -196,7 +196,7 @@
                 getCpuTopology as getPPC64CpuTopology
             self._topology = getPPC64CpuTopology(capabilities)
         else:
-            self._topology = _getCpuTopology(capabilities)
+            self._topology = _getCpuTopology()
 
     def threads(self):
         return self._topology['threads']
@@ -222,24 +222,34 @@
     return libvirtconnection.get().getCapabilities()
 
 
- at utils.memoized
-def _getCpuTopology(capabilities):
-    if capabilities is None:
-        capabilities = _getCapsXMLStr()
-
-    caps = minidom.parseString(capabilities)
-    host = caps.getElementsByTagName('host')[0]
-    cells = host.getElementsByTagName('cells')[0]
-
-    sockets = set()
-    siblings = set()
+def _getOnlineCpus():
     onlineCpus = []
 
-    for cpu in cells.getElementsByTagName('cpu'):
-        if cpu.hasAttribute('socket_id') and cpu.hasAttribute('siblings'):
-            onlineCpus.append(cpu.getAttribute('id'))
-            sockets.add(cpu.getAttribute('socket_id'))
-            siblings.add(cpu.getAttribute('siblings'))
+    with open('/sys/devices/system/cpu/online', 'r') as fp:
+        for cpuRange in fp.read().rstrip('\n').split(','):
+            if '-' in cpuRange:
+                start, end = cpuRange.split('-')
+
+                onlineCpus += [str(n) for n in xrange(int(start), int(end)+1)]
+            else:
+                onlineCpus.append(cpuRange)
+
+    return onlineCpus
+
+
+def _getCpuTopology():
+    sockets = set()
+    siblings = set()
+    onlineCpus = _getOnlineCpus()
+
+    for cpu in onlineCpus:
+        cpuPath = '/sys/devices/system/cpu/cpu%s/' % cpu
+
+        with open(cpuPath + 'topology/physical_package_id', 'r') as fp:
+            sockets.add(fp.read().rstrip('\n'))
+
+        with open(cpuPath + 'topology/thread_siblings_list', 'r') as fp:
+            siblings.add(fp.read().rstrip('\n'))
 
     topology = {'sockets': len(sockets),
                 'cores': len(siblings),


-- 
To view, visit http://gerrit.ovirt.org/34189
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia0e87b50d4fe882240c93a0a1600e3a0cb98d443
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Vitor de Lima <vdelima at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Vitor de Lima <vdelima at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server


More information about the vdsm-patches mailing list