Change in vdsm[master]: numa: refactor to single pass caps parse
mpolednik at redhat.com
mpolednik at redhat.com
Tue Feb 9 12:38:09 UTC 2016
Martin Polednik has uploaded a new change for review.
Change subject: numa: refactor to single pass caps parse
......................................................................
numa: refactor to single pass caps parse
wip
Change-Id: Ie81b5b76523070ec9fd7a6ffe902ffa25da9e3a6
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M lib/vdsm/numa.py
1 file changed, 43 insertions(+), 53 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/88/53288/1
diff --git a/lib/vdsm/numa.py b/lib/vdsm/numa.py
index 622d566..51517eb 100644
--- a/lib/vdsm/numa.py
+++ b/lib/vdsm/numa.py
@@ -20,10 +20,14 @@
from __future__ import absolute_import
+from collections import defaultdict, namedtuple
import xml.etree.ElementTree as ET
from . import utils
from . import libvirtconnection
+
+
+NumaTopology = namedtuple('NumaTopology', 'topology, distances, cpu_topology')
def _get_libvirt_caps():
@@ -31,25 +35,42 @@
@utils.memoized
-def topology(capabilities=None):
+def _numa(capabilities=None):
if capabilities is None:
capabilities = _get_libvirt_caps()
+
+ topology = defaultdict(dict)
+ distances = {}
+ sockets = set()
+ siblings = set()
+ online_cpus = []
+
caps = ET.fromstring(capabilities)
- host = caps.find('host')
- cells = host.find('.//cells')
- cellsInfo = {}
- cellSets = cells.findall('cell')
- for cell in cellSets:
- cellInfo = {}
- cpus = []
- for cpu in cell.iter(tag='cpu'):
- cpus.append(int(cpu.get('id')))
- cellInfo['cpus'] = cpus
- cellIndex = cell.get('id')
- memInfo = memory_by_cell(int(cellIndex))
- cellInfo['totalMemory'] = memInfo['total']
- cellsInfo[cellIndex] = cellInfo
- return cellsInfo
+ cells = caps.find('host').find('.//cells').findall('cell')
+
+ for cell in cells:
+ cell_id = cell.get('id')
+ meminfo = memory_by_cell(int(cell_id))
+ topology[cell_id]['totalMemory'] = meminfo['total']
+ topology[cell_id]['cpus'] = []
+ distances[cell_id] = []
+
+ for cpu in cell.find('cpus').findall('cpu'):
+ topology[cell_id]['cpus'].append(int(cpu.get('id')))
+ if cpu.get('siblings') and cpu.get('socket_id'):
+ online_cpus.append(cpu.get('id'))
+ sockets.add(cpu.get('socket_id'))
+ siblings.add(cpu.get('siblings'))
+
+ for sibling in cell.find('distances').findall('sibling'):
+ distances[cell_id].append(int(sibling.get('value')))
+
+ cpu_topology = {'sockets': len(sockets),
+ 'cores': len(siblings),
+ 'threads': len(online_cpus),
+ 'onlineCpus': online_cpus}
+
+ return NumaTopology(topology, distances, cpu_topology)
def memory_by_cell(index):
@@ -66,44 +87,13 @@
return cellMemInfo
- at utils.memoized
-def distances(capabilities=None):
- if capabilities is None:
- capabilities = _get_libvirt_caps()
- caps = ET.fromstring(capabilities)
- cells = caps.find('host').find('.//cells').findall('cell')
- distances = {}
- for cell in cells:
- cellIndex = cell.get('id')
- distances[cellIndex] = []
- for sibling in cell.find('distances').findall('sibling'):
- distances[cellIndex].append(sibling.get('value'))
-
- return distances
+def topology():
+ return _numa().topology
-def cpu_topology(capabilities=None):
- if capabilities is None:
- capabilities = _get_libvirt_caps()
+def distances():
+ return _numa().distances
- 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 cpu_topology():
+ return _numa().cpu_topology
--
To view, visit https://gerrit.ovirt.org/53288
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie81b5b76523070ec9fd7a6ffe902ffa25da9e3a6
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