On 6/2/2022 4:08 PM, Junjie Mao wrote: Chenli Wei <chenli.wei@...> writes:
From: Chenli Wei <chenli.wei@...>
The current code assume that there must be an HV_RAM_START element in the scenario and we will generate it if user have not set, the default value of HV_RAM_START is 0x00400000 which cause an overlap issue.
This patch remove the requires of HV_RAM_START element, calculate HV_RAM_SIZE and find a region of e820 to run the ACRN which start address will be HV_RAM_START.
It is still valid if the user set HV_RAM_START by XMLs.
Signed-off-by: Chenli Wei <chenli.wei@...> --- .../config_tools/hv_config/board_defconfig.py | 50 +------------------ misc/config_tools/library/common.py | 2 +- misc/config_tools/schema/config.xsd | 2 +- misc/config_tools/static_allocators/hv_ram.py | 49 ++++++++++++++++++ misc/config_tools/xforms/config_common.xsl | 5 ++ 5 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 misc/config_tools/static_allocators/hv_ram.py
diff --git a/misc/config_tools/hv_config/board_defconfig.py b/misc/config_tools/hv_config/board_defconfig.py index 5d47533af..65a198486 100644 --- a/misc/config_tools/hv_config/board_defconfig.py +++ b/misc/config_tools/hv_config/board_defconfig.py @@ -13,8 +13,6 @@ import common DESC = """# Board defconfig generated by acrn-config tool """ -HV_RAM_SIZE_MAX = 0x40000000 - MEM_ALIGN = 2 * common.SIZE_M @@ -54,60 +52,14 @@ def get_serial_type(): def get_memory(hv_info, config): - # this dictonary mapped with 'address start':'mem range' - ram_range = {} - - post_launched_vm_num = 0 - for id in common.VM_TYPES: - if common.VM_TYPES[id] in scenario_cfg_lib.VM_DB and \ - scenario_cfg_lib.VM_DB[common.VM_TYPES[id]]["load_type"] == "POST_LAUNCHED_VM": - post_launched_vm_num += 1 - hv_ram_size = common.HV_BASE_RAM_SIZE + common.POST_LAUNCHED_VM_RAM_SIZE * post_launched_vm_num - - ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_ENABLED") - total_shm_size = 0 - if ivshmem_enabled == 'y': - raw_shmem_regions = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_REGION") - for raw_shm in raw_shmem_regions: - if raw_shm is None or raw_shm.strip() == '': - continue - raw_shm_splited = raw_shm.split(',') - if len(raw_shm_splited) == 3 and raw_shm_splited[0].strip() != '' \ - and raw_shm_splited[1].strip() != '' and len(raw_shm_splited[2].strip().split(':')) >= 1: - try: - size = raw_shm_splited[1].strip() - int_size = int(size) * 0x100000 - total_shm_size += int_size - except Exception as e: - print(e) - - hv_ram_size += 2 * max(total_shm_size, 0x200000) - if hv_ram_size > HV_RAM_SIZE_MAX: - common.print_red("requested RAM size should be smaller then {}".format(HV_RAM_SIZE_MAX), err=True) - err_dic["board config: total vm number error"] = \ - "requested RAM size should be smaller then {}".format(HV_RAM_SIZE_MAX) - return err_dic - - # reseve 16M memory for hv sbuf, ramoops, etc. - reserved_ram = 0x1000000 # We recommend to put hv ram start address high than 0x10000000 to # reduce memory conflict with GRUB/Service VM Kernel. hv_start_offset = 0x10000000 - total_size = reserved_ram + hv_ram_size for start_addr in list(board_cfg_lib.USED_RAM_RANGE): if hv_start_offset <= start_addr < 0x80000000: del board_cfg_lib.USED_RAM_RANGE[start_addr] - ram_range = board_cfg_lib.get_ram_range() - avl_start_addr = board_cfg_lib.find_avl_memory(ram_range, str(total_size), hv_start_offset) - hv_start_addr = int(avl_start_addr, 16) + int(hex(reserved_ram), 16) - hv_start_addr = common.round_up(hv_start_addr, MEM_ALIGN) - board_cfg_lib.USED_RAM_RANGE[hv_start_addr] = total_size - - if not hv_info.mem.hv_ram_start: - print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) - else: - print("CONFIG_HV_RAM_START={}".format(hv_info.mem.hv_ram_start), file=config) + print("CONFIG_HV_RAM_START={}".format(hv_info.mem.hv_ram_start), file=config) print("CONFIG_STACK_SIZE={}".format(hv_info.mem.stack_size), file=config) print("CONFIG_IVSHMEM_ENABLED={}".format(hv_info.mem.ivshmem_enable), file=config) diff --git a/misc/config_tools/library/common.py b/misc/config_tools/library/common.py index 7ea12fa9d..24ece4bf3 100644 --- a/misc/config_tools/library/common.py +++ b/misc/config_tools/library/common.py @@ -45,7 +45,7 @@ MAX_VM_NUM = 16 MAX_VUART_NUM = 8 HV_BASE_RAM_SIZE = 0x1400000 -POST_LAUNCHED_VM_RAM_SIZE = 0x1000000 +VM_RAM_SIZE = 0x2800000 class MultiItem(): diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd index 07777522e..24a15877f 100644 --- a/misc/config_tools/schema/config.xsd +++ b/misc/config_tools/schema/config.xsd @@ -129,7 +129,7 @@ <xs:documentation>Specify the size of the memory stack in bytes for each physical CPU. For example, if you specify 8 kilobytes, each CPU will get its own 8-kilobyte stack.</xs:documentation> </xs:annotation> </xs:element> - <xs:element name="HV_RAM_START" type="HexFormat" default="0x00400000"> + <xs:element name="HV_RAM_START" type="HexFormat" default="0x00400000" minOccurs="0"> The default value seems to be useless here as you have logic in the static allocator to determine one if it is not given. Yes, we could remove the default="0x00400000" and we need the minOccurs="0". There was a schema error if we remove both the "default" and "minOccurs" parameters.
|