From e68e5225037280edd88a7a57558760ad9d008184 Mon Sep 17 00:00:00 2001 From: Alex Pavey Date: Mon, 11 Jan 2021 11:24:31 -0500 Subject: [PATCH 1/2] vm_arm: add pcpu list for core pinning Adds a pcpu list to the VM_Arm component to allow pinning of vcpus to specific physical cpus within a CAmkES configuration. Signed-off-by: Alex Pavey --- components/VM_Arm/configurations/vm.h | 1 + components/VM_Arm/src/main.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/VM_Arm/configurations/vm.h b/components/VM_Arm/configurations/vm.h index 8e15dec2..f5916fa7 100644 --- a/components/VM_Arm/configurations/vm.h +++ b/components/VM_Arm/configurations/vm.h @@ -65,6 +65,7 @@ provides VMDTBPassthrough dtb; \ attribute int base_prio; \ attribute int num_vcpus = 1; \ + attribute int pcpus[] = []; \ attribute int num_extra_frame_caps; \ attribute int extra_frame_map_address; \ attribute { \ diff --git a/components/VM_Arm/src/main.c b/components/VM_Arm/src/main.c index cf591e4d..b527d07b 100644 --- a/components/VM_Arm/src/main.c +++ b/components/VM_Arm/src/main.c @@ -1262,6 +1262,7 @@ static int main_continued(void) vm_vcpu_t *new_vcpu = create_vmm_plat_vcpu(&vm, VM_PRIO - 1); assert(new_vcpu); } + if (vm_config.generate_dtb) { err = fdt_generate_plat_vcpu_node(&vm, gen_dtb_buf); if (err) { @@ -1270,8 +1271,26 @@ static int main_continued(void) } } + int pcpu_assignments = 0; + if (get_instance_size_pcpus_list() < NUM_VCPUS) { + pcpu_assignments = get_instance_size_pcpus_list(); + } else { + pcpu_assignments = NUM_VCPUS; + } + /* Assign vcpus to explicit pcpus */ + for (int j = 0; j < pcpu_assignments; j++) { + vm.vcpus[j]->target_cpu = pcpus[j]; + } + vm_vcpu_t *vm_vcpu = vm.vcpus[BOOT_VCPU]; - err = vm_assign_vcpu_target(vm_vcpu, 0); + + /* Use affinity as boot core if pcpus are not specified */ + if (0 == pcpu_assignments) { + err = vm_assign_vcpu_target(vm_vcpu, get_instance_affinity()); + } else { + err = vm_assign_vcpu_target(vm_vcpu, vm_vcpu->target_cpu); + } + if (err) { return -1; } From f060b5c0788ec7abf85fcb872abc433385542713 Mon Sep 17 00:00:00 2001 From: Alex Pavey Date: Fri, 9 Dec 2022 15:03:14 -0800 Subject: [PATCH 2/2] vm_arm: add method to get size of VM's pcpu list Signed-off-by: Alex Pavey --- templates/seL4VMParameters.template.c | 16 ++++++++++++++++ templates/seL4VMParameters.template.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/templates/seL4VMParameters.template.c b/templates/seL4VMParameters.template.c index 7b7ce070..158df21c 100644 --- a/templates/seL4VMParameters.template.c +++ b/templates/seL4VMParameters.template.c @@ -124,3 +124,19 @@ const vm_config_t vm_config = { /*- endif -*/ }; + +/*- if 'pcpus' in config.keys() -*/ + /*- for c in config.get('pcpus') -*/ +#if (/*? c ?*/ >= CONFIG_MAX_NUM_NODES) +#error "Invalid CPU number /*? c ?*/ in PCPU list of /*? me.name ?*/" +#endif + /*- endfor -*/ +/*- endif -*/ + +int get_instance_size_pcpus_list(void) { +/*- if 'pcpus' in config.keys() -*/ + return /*? len(config.get('pcpus')) ?*/; +/*- else -*/ + return 0; +/*- endif -*/ +} diff --git a/templates/seL4VMParameters.template.h b/templates/seL4VMParameters.template.h index ab30b5e6..b7d52501 100644 --- a/templates/seL4VMParameters.template.h +++ b/templates/seL4VMParameters.template.h @@ -42,3 +42,5 @@ typedef struct { } vm_config_t; extern const vm_config_t vm_config; + +int get_instance_size_pcpus_list(void);