From 9670caabf0a7017d43994c9d16a91d4712a4abfe Mon Sep 17 00:00:00 2001 From: Yuanyuan Zhao Date: Mon, 14 Feb 2022 06:33:21 +0000 Subject: [PATCH] config tool: ivshmem: new design for ivshmem According to the new design of DX, implement ivshmem configuration and generate hv related files. Tracked-On: #6690 Signed-off-by: Yuanyuan Zhao Reviewed-by: Junjie Mao --- misc/config_tools/schema/types.xsd | 98 ++++++++++++++----- misc/config_tools/static_allocators/bdf.py | 8 +- misc/config_tools/static_allocators/gpa.py | 2 +- .../config_tools/static_allocators/lib/lib.py | 30 +++--- misc/config_tools/xforms/config_common.xsl | 2 +- misc/config_tools/xforms/ivshmem_cfg.h.xsl | 20 ++-- misc/config_tools/xforms/lib.xsl | 24 ++--- misc/config_tools/xforms/pci_dev.c.xsl | 43 ++++---- 8 files changed, 138 insertions(+), 89 deletions(-) mode change 100644 => 100755 misc/config_tools/xforms/ivshmem_cfg.h.xsl diff --git a/misc/config_tools/schema/types.xsd b/misc/config_tools/schema/types.xsd index d1617b025..7d611eeef 100644 --- a/misc/config_tools/schema/types.xsd +++ b/misc/config_tools/schema/types.xsd @@ -139,39 +139,83 @@ Read more about the available scheduling options in :ref:`cpu_sharing`. - - - Either empty or a string naming the shared region, -its size, and the VM IDs that can access it, such as ``hv:/shm_region_0, 2, 0:2``. -See :ref:`ivshmem-hv` for more information. - + - + + + + + + + + + + + + Name of the VM which use this IVSHMEM. + + + + + Bus, Device and function of the virtual +device in VM . Set in hex. + + + + + + + + + + Set each VM which use this IVSHMEM. + + + + + + + + + + + + + + + + + + + + + + + + Memory size of inter-VM shared memory (IVSHMEM) +in megabytes. The value should be a power of 2 +and no more than 512. + + + + + Set all VMs which use this IVSHMEM. + + + + + + - - - Enable inter-VM shared memory (IVSHMEM) -feature. - - - - - A comma-separated list with the inter-VM shared memory region name, -size, and VM IDs that may communicate using this shared region: - -* Prefix the region ``name`` with ``hv:/`` (for an hv-land solution). - (See :ref:`ivshmem-hld` for details.) -* Specify the region ``size`` in MB. Must be a power of 2, e.g., 2, 4, - 8, 16, up to 512. -* Specify all VM IDs that may use this shared memory area, - separated by a ``:``. For example, use ``0:2`` to share this area between - VMs 0 and 2, or ``0:1:2`` (to let VMs 0, 1, and 2 share this area). - - + + + Set a inter-VM shared memory. + + diff --git a/misc/config_tools/static_allocators/bdf.py b/misc/config_tools/static_allocators/bdf.py index 6d76da09f..56d423af5 100644 --- a/misc/config_tools/static_allocators/bdf.py +++ b/misc/config_tools/static_allocators/bdf.py @@ -38,14 +38,14 @@ def insert_vuart_to_dev_dict(scenario_etree, devdict, used): used.append(free_bdf) def insert_ivsheme_to_dev_dict(scenario_etree, devdict, vm_id, used): - shmem_regions = lib.lib.get_shmem_regions(scenario_etree) + shmem_regions = lib.lib.get_ivshmem_regions_by_tree(scenario_etree) if vm_id not in shmem_regions: return shmems = shmem_regions.get(vm_id) for shm in shmems.values(): - free_bdf = find_unused_bdf(used) - devdict[f"{IVSHMEM}_{shm.get('id')}"] = free_bdf - used.append(free_bdf) + bdf = lib.lib.BusDevFunc.from_str(shm.get('vbdf')) + devdict[f"{IVSHMEM}_{shm.get('id')}"] = bdf + used.append(bdf) def insert_pt_devs_to_dev_dict(vm_node_etree, devdict, used): """ diff --git a/misc/config_tools/static_allocators/gpa.py b/misc/config_tools/static_allocators/gpa.py index 72b347e86..dbcb71f25 100644 --- a/misc/config_tools/static_allocators/gpa.py +++ b/misc/config_tools/static_allocators/gpa.py @@ -126,7 +126,7 @@ def insert_legacy_vuart_to_dev_dict(vm_node, devdict_io_port): devdict_io_port[(f"{LEGACY_VUART}_{vuart_id}", "base")] = LEGACY_VUART_IO_PORT_SIZE def insert_ivsheme_to_dev_dict(scenario_etree, devdict_32bits, devdict_64bits, vm_id): - shmem_regions = lib.lib.get_shmem_regions(scenario_etree) + shmem_regions = lib.lib.get_ivshmem_regions_by_tree(scenario_etree) if vm_id not in shmem_regions: return shmems = shmem_regions.get(vm_id) diff --git a/misc/config_tools/static_allocators/lib/lib.py b/misc/config_tools/static_allocators/lib/lib.py index 0e08c9447..60c956767 100644 --- a/misc/config_tools/static_allocators/lib/lib.py +++ b/misc/config_tools/static_allocators/lib/lib.py @@ -89,29 +89,35 @@ def get_native_ttys(): native_ttys[tty] = tmp_dic return native_ttys -def get_shmem_regions(etree): - ivshmem_enabled = common.get_node("//IVSHMEM_ENABLED/text()", etree) +def get_ivshmem_regions_by_tree(etree): + ivshmem_enabled = get_ivshmem_enabled_by_tree(etree) if ivshmem_enabled == 'n': return {} - # format is shm_name, shm_size, VM IDs - # example: hv:/shm_region_0, 2, 0:2 ivshmem_regions = etree.xpath("//IVSHMEM_REGION") shmem_regions = {} for idx in range(len(ivshmem_regions)): - shm_string = ivshmem_regions[idx].text - if shm_string is None: + shm_name = ivshmem_regions[idx].get('name') + if shm_name is None: continue - shm_string_list = shm_string.split(',') - shm_name = shm_string_list[0].strip() - shm_size = shm_string_list[1].strip() - vmid_list = [vm_id.strip() for vm_id in shm_string_list[2].split(':')] - for vm_id in vmid_list: + shm_size = common.get_node("./IVSHMEM_SIZE/text()", ivshmem_regions[idx]) + shm_vm_list = ivshmem_regions[idx].xpath(".//IVSHMEM_VM") + for shm_vm in shm_vm_list: + vm_name = common.get_node("./VM_NAME/text()", shm_vm) + vm_id = common.get_node(f"//vm[name = '{vm_name}']/@id", etree) + vbdf = common.get_node("./VBDF/text()", shm_vm) if vm_id not in shmem_regions: shmem_regions[vm_id] = {} - shmem_regions[vm_id][shm_name] = {'id' : str(idx), 'size' : shm_size} + shmem_regions[vm_id][shm_name] = {'id' : str(idx), 'size' : shm_size, 'vbdf' : vbdf} return shmem_regions +def get_ivshmem_enabled_by_tree(etree): + ivshmem_vms = etree.xpath("//IVSHMEM_VM") + shmem_enabled = 'n' + if len(ivshmem_vms) != 0: + shmem_enabled = 'y' + return shmem_enabled + def is_pre_launched_vm(vm_type): if vm_type in PRE_LAUNCHED_VMS_TYPE: return True diff --git a/misc/config_tools/xforms/config_common.xsl b/misc/config_tools/xforms/config_common.xsl index 7be0d9ad1..34966ea09 100644 --- a/misc/config_tools/xforms/config_common.xsl +++ b/misc/config_tools/xforms/config_common.xsl @@ -141,7 +141,7 @@ - + diff --git a/misc/config_tools/xforms/ivshmem_cfg.h.xsl b/misc/config_tools/xforms/ivshmem_cfg.h.xsl old mode 100644 new mode 100755 index 037e47a0a..439c9ff59 --- a/misc/config_tools/xforms/ivshmem_cfg.h.xsl +++ b/misc/config_tools/xforms/ivshmem_cfg.h.xsl @@ -26,23 +26,22 @@ - + - + - - - - + + + @@ -50,21 +49,22 @@ - + - + + - + - + { \ diff --git a/misc/config_tools/xforms/lib.xsl b/misc/config_tools/xforms/lib.xsl index 510793020..aa399da4b 100644 --- a/misc/config_tools/xforms/lib.xsl +++ b/misc/config_tools/xforms/lib.xsl @@ -304,17 +304,16 @@ - - + - - - - - - - - + + + + + + + + @@ -323,8 +322,9 @@ - - + + + diff --git a/misc/config_tools/xforms/pci_dev.c.xsl b/misc/config_tools/xforms/pci_dev.c.xsl index d5c34aee8..8397962b5 100644 --- a/misc/config_tools/xforms/pci_dev.c.xsl +++ b/misc/config_tools/xforms/pci_dev.c.xsl @@ -141,29 +141,28 @@ + - - - - { - - - - - - - - - - - - - - - - }, - - + + { + + + + + + + + + + + + + + + + + }, +