From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH v2 11/16] framework/virt_resource: support multiple VMs module
Date: Tue, 9 Jan 2018 19:11:09 -0500 [thread overview]
Message-ID: <1515543074-81373-12-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1515543074-81373-1-git-send-email-yong.liu@intel.com>
1. Add serial/migrate/display port allocation support.
2. Add parallel lock for virtualzation resource allocation functions.
3. Quick scan free port in port allocation function.
Signed-off-by: Marvin Liu <yong.liu@intel.com>
diff --git a/framework/virt_resource.py b/framework/virt_resource.py
index b830f4e..1b37d4c 100644
--- a/framework/virt_resource.py
+++ b/framework/virt_resource.py
@@ -31,10 +31,14 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from random import randint
-from utils import get_obj_funcs
+from utils import get_obj_funcs, parallel_lock, RED
-INIT_FREE_PORT = 6060
+INIT_FREE_PORT = 6000
+INIT_SERIAL_PORT = 7000
+INIT_MIGRATE_PORT = 8000
+INIT_DISPLAY_PORT = 0
+QuickScan = True
class VirtResource(object):
@@ -149,6 +153,7 @@ class VirtResource(object):
for cpu in cpus:
self.__core_used(cpu)
+ @parallel_lock()
def alloc_cpu(self, vm='', number=-1, socket=-1, corelist=None):
"""
There're two options for request cpu resouce for vm.
@@ -207,12 +212,14 @@ class VirtResource(object):
return False
return True
+ @parallel_lock()
def free_cpu(self, vm):
if self.__vm_has_resource(vm, 'cores'):
for core in self.allocated_info[vm]['cores']:
self.__core_unused(core)
self.allocated_info[vm].pop('cores')
+ @parallel_lock()
def alloc_pf(self, vm='', number=-1, socket=-1, pflist=[]):
"""
There're two options for request pf devices for vm.
@@ -246,12 +253,14 @@ class VirtResource(object):
self.allocated_info[vm]['ports'] = ports
return ports
+ @parallel_lock()
def free_pf(self, vm):
if self.__vm_has_resource(vm, 'ports'):
for pci in self.allocated_info[vm]['ports']:
self.__port_unused(pci)
self.allocated_info[vm].pop('ports')
+ @parallel_lock()
def alloc_vf_from_pf(self, vm='', pf_pci='', number=-1, vflist=[]):
"""
There're two options for request vf devices of pf device.
@@ -286,12 +295,14 @@ class VirtResource(object):
self.allocated_info[vm]['vfs'] = vfs
return vfs
+ @parallel_lock()
def free_vf(self, vm):
if self.__vm_has_resource(vm, 'vfs'):
for pci in self.allocated_info[vm]['vfs']:
self.__vf_unused(pci)
self.allocated_info[vm].pop('vfs')
+ @parallel_lock()
def add_vf_on_pf(self, pf_pci='', vflist=[]):
"""
Add vf devices generated by specified pf devices.
@@ -307,6 +318,7 @@ class VirtResource(object):
self.used_vfs += used_vfs
self.vfs += vfs
+ @parallel_lock()
def del_vf_on_pf(self, pf_pci='', vflist=[]):
"""
Remove vf devices generated by specified pf devices.
@@ -327,66 +339,95 @@ class VirtResource(object):
del self.used_vfs[index]
del self.vfs[index]
- def alloc_port(self, vm=''):
+ @parallel_lock()
+ def _check_port_allocated(self, port):
+ """
+ Check whether port has been pre-allocated
+ """
+ for vm_info in self.allocated_info.values():
+ if vm_info.has_key('hostport') and port == vm_info['hostport']:
+ return True
+ if vm_info.has_key('serialport') and port == vm_info['serialport']:
+ return True
+ if vm_info.has_key('migrateport') and port == vm_info['migrateport']:
+ return True
+ if vm_info.has_key('displayport') and port == (vm_info['displayport'] + 5900):
+ return True
+ return False
+
+ @parallel_lock()
+ def alloc_port(self, vm='', port_type='connect'):
"""
Allocate unused host port for vm
"""
+ global INIT_FREE_PORT
+ global INIT_SERIAL_PORT
+ global INIT_MIGRATE_PORT
+ global INIT_DISPLAY_PORT
+
if vm == '':
print "Alloc host port request vitual machine name!!!"
return None
- port_start = INIT_FREE_PORT + randint(1, 100)
- port_step = randint(1, 10)
- port = None
- count = 20
+ if port_type == 'connect':
+ port = INIT_FREE_PORT
+ elif port_type == 'serial':
+ port = INIT_SERIAL_PORT
+ elif port_type == 'migrate':
+ port = INIT_MIGRATE_PORT
+ elif port_type == 'display':
+ port = INIT_DISPLAY_PORT + 5900
+
while True:
- if self.dut.check_port_occupied(port_start) is False:
- port = port_start
+ if self.dut.check_port_occupied(port) is False and self._check_port_allocated(port) is False:
break
- count -= 1
- if count < 0:
- print 'No available port on the host!!!'
- break
- port_start += port_step
+ else:
+ port += 1
+ continue
if vm not in self.allocated_info:
self.allocated_info[vm] = {}
- self.allocated_info[vm]['hostport'] = port
+ if port_type == 'connect':
+ self.allocated_info[vm]['hostport'] = port
+ elif port_type == 'serial':
+ self.allocated_info[vm]['serialport'] = port
+ elif port_type == 'migrate':
+ self.allocated_info[vm]['migrateport'] = port
+ elif port_type == 'display':
+ port -= 5900
+ self.allocated_info[vm]['displayport'] = port
+
+ # do not scan port from the begining
+ if QuickScan:
+ if port_type == 'connect':
+ INIT_FREE_PORT = port
+ elif port_type == 'serial':
+ INIT_SERIAL_PORT = port
+ elif port_type == 'migrate':
+ INIT_MIGRATE_PORT = port
+ elif port_type == 'display':
+ INIT_DISPLAY_PORT = port
+
return port
+ @parallel_lock()
def free_port(self, vm):
if self.__vm_has_resource(vm, 'hostport'):
self.allocated_info[vm].pop('hostport')
-
- def alloc_vnc_num(self, vm=''):
- """
- Allocate unused host VNC display number for VM.
- """
- if vm == '':
- print "Alloc vnc display number request vitual machine name!!!"
- return None
-
- max_vnc_display_num = self.dut.get_maximal_vnc_num()
- free_vnc_display_num = max_vnc_display_num + 1
-
- if vm not in self.allocated_info:
- self.allocated_info[vm] = {}
-
- self.allocated_info[vm]['vnc_display_num'] = free_vnc_display_num
-
- return free_vnc_display_num
-
- def free_vnc_num(self, vm):
- if self.__vm_has_resource(vm, 'vnc_display_num'):
- self.allocated_info[vm].pop('vnc_display_num')
-
+ if self.__vm_has_resource(vm, 'serialport'):
+ self.allocated_info[vm].pop('serialport')
+ if self.__vm_has_resource(vm, 'migrateport'):
+ self.allocated_info[vm].pop('migrateport')
+ if self.__vm_has_resource(vm, 'displayport'):
+ self.allocated_info[vm].pop('displayport')
+
+ @parallel_lock()
def free_all_resource(self, vm):
"""
Free all resource VM has been allocated.
"""
self.free_port(vm)
- self.free_vnc_num(vm)
self.free_vf(vm)
self.free_pf(vm)
self.free_cpu(vm)
--
1.9.3
next prev parent reply other threads:[~2018-01-10 7:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 2:49 [dts] [PATCH v1 00/16] Support parallel multiple virtual machine management Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 01/16] framework: add external thread pool library Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 02/16] framework/multiple_vm: add multiple VM management module Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 03/16] framework/utils: support locks function in parallel model Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 04/16] framework: add DUT index support Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 05/16] framework/logger: optimize output format for child threads Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 06/16] framework/dts: support multiple VMs module Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 07/16] framework/debugger: " Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 08/16] framework/ssh_pexpect: " Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 09/16] framework/ssh_connection: support DUT index argument Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 10/16] framework/settings: add parallel related settings Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 11/16] framework/virt_resource: support multiple VMs module Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 12/16] framework/virt_base: add attach/quick start/quit function for VM management Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 13/16] framework/virt_dut: support multiple VMs module Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 14/16] framework/qemu_kvm: " Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 15/16] conf/virt_global: add vm management related configuration Marvin Liu
2018-01-08 2:49 ` [dts] [PATCH v1 16/16] doc: add descriptions for multiple virtual machine module Marvin Liu
2018-01-10 0:10 ` [dts] [PATCH v2 00/16] Support parallel multiple virtual machines management Marvin Liu
2018-01-10 0:10 ` [dts] [PATCH v2 01/16] framework: add external thread pool library Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 02/16] framework/multiple_vm: add multiple VM management module Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 03/16] framework/utils: support locks for parallel model Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 04/16] framework: add DUT index support Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 05/16] framework/logger: optimize output format for threads Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 06/16] framework/dts: support multiple VMs module Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 07/16] framework/debugger: " Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH 08/16] framework/ssh_pexpect: " Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 09/16] framework/ssh_connection: " Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 10/16] framework/settings: add parallel related settings Marvin Liu
2018-01-10 0:11 ` Marvin Liu [this message]
2018-01-10 0:11 ` [dts] [PATCH v2 12/16] framework/virt_base: add attach/quick start/quit function for VM management Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 13/16] framework/virt_dut: support multiple VMs module Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 14/16] framework/qemu_kvm: " Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 15/16] conf/virt_global: add vm management related configuration Marvin Liu
2018-01-10 0:11 ` [dts] [PATCH v2 16/16] doc: add descriptions for multiple virtual machines module Marvin Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1515543074-81373-12-git-send-email-yong.liu@intel.com \
--to=yong.liu@intel.com \
--cc=dts@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).