Change in vdsm[master]: virt: numa: move activation check in the caller

fromani at redhat.com fromani at redhat.com
Fri Mar 27 08:08:19 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: virt: numa: move activation check in the caller
......................................................................

virt: numa: move activation check in the caller

The existing NUMA position reporting code is activated
only if a VM is configured with 'virtual NUMA', referred
in the code as 'guest Numa Node'.
If this configuration is absent, the NUMA sampling just
does nothing.

Besides naming, this makes the code a bit harder to read
and to reason about, since often readers assume NUMA positioning
reporting always executed.

To make this easier to read, and to make room for future patches
which want to move NUMA sampling in periodic operations,
we move this check into the calling site(s), with no other intended
changes in the flow of code.

Change-Id: Ib1b94c2b45b0cbd4455d4fff719b932173536af3
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/numaUtilsTests.py
M vdsm/numaUtils.py
M vdsm/virt/vm.py
3 files changed, 22 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/39261/1

diff --git a/tests/numaUtilsTests.py b/tests/numaUtilsTests.py
index f872f3d..5a5a8ff 100644
--- a/tests/numaUtilsTests.py
+++ b/tests/numaUtilsTests.py
@@ -72,5 +72,6 @@
         with fake.VM(VM_PARAMS) as testvm:
             testvm._vmStats = fake.VmStatsThread(testvm)
             expectedResult = {'0': [0, 1], '1': [0, 1]}
+            self.assertTrue(testvm.hasGuestNumaNode)
             vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(testvm)
             self.assertEqual(expectedResult, vmNumaNodeRuntimeMap)
diff --git a/vdsm/numaUtils.py b/vdsm/numaUtils.py
index 01a4270..761a083 100644
--- a/vdsm/numaUtils.py
+++ b/vdsm/numaUtils.py
@@ -67,24 +67,23 @@
 
     vmNumaNodeRuntimeMap = {}
 
-    if 'guestNumaNodes' in vm.conf:
-        vcpu_to_pcpu = _get_mapping_vcpu_to_pcpu(vm)
-        if vcpu_to_pcpu:
-            vm_numa_placement = defaultdict(set)
+    vcpu_to_pcpu = _get_mapping_vcpu_to_pcpu(vm)
+    if vcpu_to_pcpu:
+        vm_numa_placement = defaultdict(set)
 
-            vcpu_to_pnode = supervdsm.getProxy().getVcpuNumaMemoryMapping(
-                vm.conf['vmName'].encode('utf-8'))
-            pcpu_to_pnode = _get_mapping_pcpu_to_pnode()
-            vcpu_to_vnode = _get_mapping_vcpu_to_vnode(vm)
+        vcpu_to_pnode = supervdsm.getProxy().getVcpuNumaMemoryMapping(
+            vm.conf['vmName'].encode('utf-8'))
+        pcpu_to_pnode = _get_mapping_pcpu_to_pnode()
+        vcpu_to_vnode = _get_mapping_vcpu_to_vnode(vm)
 
-            for vcpu_id, pcpu_id in vcpu_to_pcpu.iteritems():
-                vnode_index = str(vcpu_to_vnode[vcpu_id])
-                vm_numa_placement[vnode_index].add(pcpu_to_pnode[pcpu_id])
-                vm_numa_placement[vnode_index].update(
-                    vcpu_to_pnode.get(vcpu_id, ()))
+        for vcpu_id, pcpu_id in vcpu_to_pcpu.iteritems():
+            vnode_index = str(vcpu_to_vnode[vcpu_id])
+            vm_numa_placement[vnode_index].add(pcpu_to_pnode[pcpu_id])
+            vm_numa_placement[vnode_index].update(
+                vcpu_to_pnode.get(vcpu_id, ()))
 
-            vmNumaNodeRuntimeMap = dict((k, list(v)) for k, v in
-                                        vm_numa_placement.iteritems())
+        vmNumaNodeRuntimeMap = dict((k, list(v)) for k, v in
+                                    vm_numa_placement.iteritems())
 
     return vmNumaNodeRuntimeMap
 
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index dc226fb..af624cc 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -258,7 +258,9 @@
         """
         Numa CPU assignments.
         """
-        vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(self._vm)
+        vmNumaNodeRuntimeMap = {}
+        if self._vm.hasGuestNumaNode:
+            numaUtils.getVmNumaNodeRuntimeInfo(self._vm)
         return vmNumaNodeRuntimeMap
 
     def _sampleDisk(self):
@@ -5024,6 +5026,10 @@
                              statsAge)
             stats['monitorResponse'] = '-1'
 
+    @property
+    def hasGuestNumaNode(self):
+        return 'guestNumaNodes' in self.conf
+
 
 class LiveMergeCleanupThread(threading.Thread):
     def __init__(self, vm, jobId, drive, doPivot):


-- 
To view, visit https://gerrit.ovirt.org/39261
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1b94c2b45b0cbd4455d4fff719b932173536af3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list