test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH 1/2] Optimize virtual dut module for abstract cpu topo
@ 2015-09-21  7:34 Yong Liu
  2015-09-21  7:34 ` [dts] [PATCH 2/2] VT: Support cpu simulate topo in virtualization scenario module Yong Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Yong Liu @ 2015-09-21  7:34 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

In virtual machine, there's no concept of numa. When run performance case,
when request cores according to socket will be error.

Add new parameter "cpu_topo" in configuration file. With this parameter
enabled, will generate core mapping with socket and hyperthread awareness.

Add update virtual machine port infor function. When port is pass-through
from host, update numa id with host device numa.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/virt_dut.py b/framework/virt_dut.py
index 9404be6..529a2b1 100644
--- a/framework/virt_dut.py
+++ b/framework/virt_dut.py
@@ -54,9 +54,10 @@ class VirtDut(DPDKdut):
     or CRBBareMetal.
     """
 
-    def __init__(self, hyper, crb, serializer, virttype, vm_name, suite):
+    def __init__(self, hyper, crb, serializer, virttype, vm_name, suite, cpu_topo):
         self.vm_name = vm_name
         self.hyper = hyper
+        self.cpu_topo = cpu_topo
         super(Dut, self).__init__(crb, serializer)
         self.vm_ip = self.get_ip_address()
         self.NAME = 'virtdut' + LOG_NAME_SEP + '%s' % self.vm_ip
@@ -167,6 +168,10 @@ class VirtDut(DPDKdut):
 
         # scan ports before restore interface
         self.scan_ports()
+
+        # update with real numa id
+        self.update_ports()
+
         # restore dut ports to kernel
         if self.virttype != 'XEN':
             self.restore_interfaces()
@@ -202,6 +207,38 @@ class VirtDut(DPDKdut):
         cpuinfo = self.send_expect("grep --color=never \"processor\""
                                    " /proc/cpuinfo", "#", alt_session=False)
         cpuinfo = cpuinfo.split('\r\n')
+        if self.cpu_topo != '':
+            topo_reg = r"(\d)S/(\d)C/(\d)T"
+            m = re.match(topo_reg, self.cpu_topo)
+            if m:
+                socks = int(m.group(1))
+                cores = int(m.group(2))
+                threads = int(m.group(3))
+                total = socks * cores * threads
+                cores_persock = cores * threads
+                total_phycores = socks * cores
+                # cores should match cpu_topo
+                if total != len(cpuinfo):
+                    print dts.RED("Core number not matched!!!")
+                else:
+                    for core in range(total):
+                        thread = core / total_phycores
+                        phy_core = core % total_phycores
+                        # if this core is hyper core
+                        if thread:
+                            idx = core % total_phycores
+                            socket = idx / cores
+                        else:
+                            socket = core / cores
+
+                        # tricky here, socket must be string
+                        self.cores.append({'thread': core,
+                                           'socket': str(socket),
+                                           'core': phy_core})
+                    self.number_of_cores = len(self.cores)
+                    return
+
+        # default core map
         for line in cpuinfo:
             m = re.search("processor\t: (\d+)", line)
             if m:
@@ -268,6 +305,26 @@ class VirtDut(DPDKdut):
             self, 'scan_ports_uncached_%s' % self.get_os_type())
         return scan_ports_uncached()
 
+    def update_ports(self):
+        """
+        Update ports information, according to host pci
+        """
+        for port in self.ports_info:
+            vmpci = port['pci']
+            for pci_map in self.hyper.pci_maps:
+                # search pci mapping strucutre
+                if vmpci == pci_map['guestpci']:
+                    hostpci = pci_map['hostpci']
+                    # search host port info structure
+                    for hostport in self.host_dut.ports_info:
+                        # update port numa
+                        if hostpci == hostport['pci'] or \
+                           hostpci in hostport['sriov_vfs_pci']:
+                            port['numa'] = hostport['numa']
+                            port['port'].socket = hostport['numa']
+                            break
+                    break
+
     def map_available_ports(self):
         """
         Load or generate network connection mapping list.
-- 
1.9.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [dts] [PATCH 2/2] VT: Support cpu simulate topo in virtualization scenario module
  2015-09-21  7:34 [dts] [PATCH 1/2] Optimize virtual dut module for abstract cpu topo Yong Liu
@ 2015-09-21  7:34 ` Yong Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Yong Liu @ 2015-09-21  7:34 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Scene module add "cpu_topo" parameter which will be used as option of DUT instance.
"cpu_topo" should like "2S/5C/2T" mean that this virtual machine contain 20 lcores.
User can utilize "cpu_topo" and "cpu_pin" to make sure simulate topo same as real topo.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/virt_base.py b/framework/virt_base.py
index 16e6d24..4a445d1 100644
--- a/framework/virt_base.py
+++ b/framework/virt_base.py
@@ -224,7 +224,7 @@ class VirtBase(object):
         self.load_global_config()
         self.load_local_config(self.suite)
 
-    def start(self, load_config=True, set_target=True, auto_portmap=True, bind_dev=True):
+    def start(self, load_config=True, set_target=True, cpu_topo='', auto_portmap=True, bind_dev=True):
         """
         Start VM and instantiate the VM with VirtDut.
         """
@@ -238,7 +238,7 @@ class VirtBase(object):
             self._start_vm()
 
             # connect vm dut and init running environment
-            vm_dut = self.instantiate_vm_dut(set_target, auto_portmap)
+            vm_dut = self.instantiate_vm_dut(set_target, cpu_topo, auto_portmap)
         except Exception as vm_except:
             if self.handle_exception(vm_except):
                 print dts.RED("Handled expection " + str(type(vm_except)))
@@ -293,7 +293,7 @@ class VirtBase(object):
         """
         NotImplemented
 
-    def instantiate_vm_dut(self, set_target=True, auto_portmap=True, bind_dev=True):
+    def instantiate_vm_dut(self, set_target=True, cpu_topo='', auto_portmap=True, bind_dev=True):
         """
         Instantiate the Dut class for VM.
         """
@@ -317,7 +317,8 @@ class VirtBase(object):
                 serializer,
                 self.virt_type,
                 self.vm_name,
-                self.suite)
+                self.suite,
+                cpu_topo)
         except:
             raise exception.VirtDutConnectException
             return None
diff --git a/framework/virt_scene.py b/framework/virt_scene.py
index 7eb475d..896d86b 100644
--- a/framework/virt_scene.py
+++ b/framework/virt_scene.py
@@ -193,8 +193,19 @@ class VirtScene(object):
         else:
             model = 'host'
 
-        cores = self.host_dut.virt_pool.alloc_cpu(vm=vm_name, number=num,
-                                                  socket=numa)
+        cpu_topo = ''
+        if 'cpu_topo' in cpu_conf.keys():
+            cpu_topo = cpu_conf['cpu_topo']
+
+        pin_cores = []
+        if 'cpu_pin' in cpu_conf.keys():
+            pin_cores = cpu_conf['cpu_pin'].split()
+
+        if len(pin_cores):
+            cores = self.host_dut.virt_pool.alloc_cpu(vm=vm_name, corelist=pin_cores)
+        else:
+            cores = self.host_dut.virt_pool.alloc_cpu(vm=vm_name, number=num,
+                                                      socket=numa)
         core_cfg = ''
         for core in cores:
             core_cfg += '%s ' % core
@@ -203,6 +214,7 @@ class VirtScene(object):
         cpu_param['number'] = num
         cpu_param['model'] = model
         cpu_param['cpupin'] = core_cfg
+        cpu_param['cputopo'] = cpu_topo
 
         # replace with allocated cpus
         params['cpu'] = [cpu_param]
@@ -419,6 +431,12 @@ class VirtScene(object):
         # update vm name
         vm.params[index]['name'][0]['name'] = vm.vm_name
 
+    def get_cputopo(self, params):
+        for param in params:
+            if 'cpu' in param.keys():
+                cpu_topo = param['cpu'][0]['cputopo']
+                return cpu_topo
+
     def start_vms(self):
         self.vms = []
         if self.vm_type == 'kvm':
@@ -434,9 +452,12 @@ class VirtScene(object):
                 scene_params = self.vm_confs[vm_name]
                 # reload merged configurations
                 self.merge_params(vm, scene_params)
+                # get cpu topo
+                topo = self.get_cputopo(scene_params)
                 try:
                     vm_dut = vm.start(load_config=False, set_target=False,
-                                      auto_portmap=self.auto_portmap)
+                                      auto_portmap=self.auto_portmap,
+                                      cpu_topo=topo)
                     if vm_dut is None:
                         raise Exception("Set up VM ENV failed!")
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-21  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-21  7:34 [dts] [PATCH 1/2] Optimize virtual dut module for abstract cpu topo Yong Liu
2015-09-21  7:34 ` [dts] [PATCH 2/2] VT: Support cpu simulate topo in virtualization scenario module Yong Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).