Change in vdsm[master]: numa: move more stuff
mpolednik at redhat.com
mpolednik at redhat.com
Tue Feb 9 12:38:08 UTC 2016
Martin Polednik has uploaded a new change for review.
Change subject: numa: move more stuff
......................................................................
numa: move more stuff
wip
Change-Id: Ie786e8a3626dd257c2a244decfe3e6a127d04b28
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M lib/vdsm/numa.py
M tests/capsTests.py
M vdsm/caps.py
M vdsm/clientIF.py
4 files changed, 51 insertions(+), 69 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/53287/1
diff --git a/lib/vdsm/numa.py b/lib/vdsm/numa.py
index 90bc6e5..622d566 100644
--- a/lib/vdsm/numa.py
+++ b/lib/vdsm/numa.py
@@ -80,3 +80,30 @@
distances[cellIndex].append(sibling.get('value'))
return distances
+
+
+def cpu_topology(capabilities=None):
+ if capabilities is None:
+ capabilities = _get_libvirt_caps()
+
+ caps = ET.fromstring(capabilities)
+ host = caps.find('host')
+ cells = host.find('.//cells')
+
+ sockets = set()
+ siblings = set()
+ onlineCpus = []
+
+ for cpu in cells.iter(tag='cpu'):
+ if cpu.get('socket_id') is not None and \
+ cpu.get('siblings') is not None:
+ onlineCpus.append(cpu.get('id'))
+ sockets.add(cpu.get('socket_id'))
+ siblings.add(cpu.get('siblings'))
+
+ topology = {'sockets': len(sockets),
+ 'cores': len(siblings),
+ 'threads': len(onlineCpus),
+ 'onlineCpus': onlineCpus}
+
+ return topology
diff --git a/tests/capsTests.py b/tests/capsTests.py
index ce3cca5..5fb0478 100644
--- a/tests/capsTests.py
+++ b/tests/capsTests.py
@@ -68,10 +68,10 @@
dirName = os.path.split(testPath)[0]
# PPC64 4 sockets, 5 cores, 1 threads per core
path = os.path.join(dirName, "caps_libvirt_ibm_S822L.out")
- t = caps.CpuTopology(open(path).read())
- self.assertEqual(t.threads(), 20)
- self.assertEqual(t.cores(), 20)
- self.assertEqual(t.sockets(), 4)
+ t = numa.cpu_topology(open(path).read())
+ self.assertEqual(t['threads'], 20)
+ self.assertEqual(t['cores'], 20)
+ self.assertEqual(t['sockets'], 4)
@MonkeyPatch(platform, 'machine', lambda: cpuarch.X86_64)
def testCpuTopologyX86_64(self):
@@ -80,24 +80,24 @@
# 2 x Intel E5649 (with Hyperthreading)
path = os.path.join(dirName, "caps_libvirt_intel_E5649.out")
with open(path) as p:
- t = caps.CpuTopology(p.read())
- self.assertEqual(t.threads(), 24)
- self.assertEqual(t.cores(), 12)
- self.assertEqual(t.sockets(), 2)
+ t = numa.cpu_topology(p.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")
with open(path) as p:
- t = caps.CpuTopology(p.read())
- self.assertEqual(t.threads(), 32)
- self.assertEqual(t.cores(), 16)
- self.assertEqual(t.sockets(), 2)
+ t = numa.cpu_topology(p.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")
with open(path) as p:
- t = caps.CpuTopology(p.read())
- self.assertEqual(t.threads(), 4)
- self.assertEqual(t.cores(), 4)
- self.assertEqual(t.sockets(), 1)
+ t = numa.cpu_topology(p.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")
@@ -314,7 +314,7 @@
def test_getCpuTopology(self):
capsData = self._readCaps("caps_libvirt_intel_i73770_nosnap.out")
- result = caps._getCpuTopology(capsData)
+ result = numa.cpu_topology(capsData)
expected = {'cores': 4, 'threads': 8, 'sockets': 1,
'onlineCpus': ['0', '1', '2', '3', '4', '5', '6', '7']}
self.assertEqual(expected, result)
diff --git a/vdsm/caps.py b/vdsm/caps.py
index 73ddf8b..319a00d 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -90,23 +90,6 @@
'hwrng': '/dev/hwrng'}
-class CpuTopology(object):
- def __init__(self, capabilities=None):
- self._topology = _getCpuTopology(capabilities)
-
- def threads(self):
- return self._topology['threads']
-
- def cores(self):
- return self._topology['cores']
-
- def sockets(self):
- return self._topology['sockets']
-
- def onlineCpus(self):
- return self._topology['onlineCpus']
-
-
class KdumpStatus(object):
UNKNOWN = -1
DISABLED = 0
@@ -120,33 +103,6 @@
@utils.memoized
def _getCapsXMLStr():
return _getFreshCapsXMLStr()
-
-
-def _getCpuTopology(capabilities):
- if capabilities is None:
- capabilities = _getFreshCapsXMLStr()
-
- caps = ET.fromstring(capabilities)
- host = caps.find('host')
- cells = host.find('.//cells')
-
- sockets = set()
- siblings = set()
- onlineCpus = []
-
- for cpu in cells.iter(tag='cpu'):
- if cpu.get('socket_id') is not None and \
- cpu.get('siblings') is not None:
- onlineCpus.append(cpu.get('id'))
- sockets.add(cpu.get('socket_id'))
- siblings.add(cpu.get('siblings'))
-
- topology = {'sockets': len(sockets),
- 'cores': len(siblings),
- 'threads': len(onlineCpus),
- 'onlineCpus': onlineCpus}
-
- return topology
def _findLiveSnapshotSupport(guest):
@@ -465,15 +421,14 @@
caps['kvmEnabled'] = str(os.path.exists('/dev/kvm')).lower()
- cpuTopology = CpuTopology()
if config.getboolean('vars', 'report_host_threads_as_cores'):
- caps['cpuCores'] = str(cpuTopology.threads())
+ caps['cpuCores'] = str(numa.cpu_topology()['threads'])
else:
- caps['cpuCores'] = str(cpuTopology.cores())
+ caps['cpuCores'] = str(numa.cpu_topology()['cores'])
- caps['cpuThreads'] = str(cpuTopology.threads())
- caps['cpuSockets'] = str(cpuTopology.sockets())
- caps['onlineCpus'] = ','.join(cpuTopology.onlineCpus())
+ caps['cpuThreads'] = str(numa.cpu_topology()['threads'])
+ caps['cpuSockets'] = str(numa.cpu_topology()['sockets'])
+ caps['onlineCpus'] = ','.join(numa.cpu_topology()['onlineCpus'])
caps['cpuSpeed'] = cpuinfo.frequency()
caps['cpuModel'] = cpuinfo.model()
caps['cpuFlags'] = ','.join(cpuinfo.flags() + _getCompatibleCpuModels())
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 0d1e235..f01d8a3 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -40,9 +40,9 @@
import libvirt
from vdsm import libvirtconnection
from vdsm import concurrent
+from vdsm import numa
from vdsm import utils
from vdsm import supervdsm
-import caps
import blkid
from protocoldetector import MultiProtocolAcceptor
@@ -468,7 +468,7 @@
# we prefer running this code in external thread to avoid blocking
# API response.
mog = min(config.getint('vars', 'max_outgoing_migrations'),
- caps.CpuTopology().cores())
+ numa.cpu_topology()['cores'])
migration.SourceThread.setMaxOutgoingMigrations(mog)
recovery.all_vms(self)
--
To view, visit https://gerrit.ovirt.org/53287
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie786e8a3626dd257c2a244decfe3e6a127d04b28
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik at redhat.com>
More information about the vdsm-patches
mailing list