Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm_arm: add pcpu list for core pinning #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/VM_Arm/configurations/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down
21 changes: 20 additions & 1 deletion components/VM_Arm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -1270,8 +1271,26 @@ static int main_continued(void)
}
}

axel-h marked this conversation as resolved.
Show resolved Hide resolved
int pcpu_assignments = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid assigning 0 and then overwriting this, it gives compiler warnings at the picky level.

    unsigned int pcpu_assignments = get_instance_size_pcpus_list();
    if (pcpu_assignments > NUM_VCPUS) {
        pcpu_assignments = NUM_VCPUS;
    }

Copy link
Member

@axel-h axel-h Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or well, we could even merge this nicely into the CPU node creation at line 1260:

    /* Create CPUs and DTB node */
    unsigned int pcpu_list_size = get_instance_size_pcpus_list();
    for (int i = 0; i < NUM_VCPUS; i++) {
        vm_vcpu_t *new_vcpu = create_vmm_plat_vcpu(&vm, VM_PRIO - 1);
        assert(new_vcpu);
        if (i < pcpu_list_size) {
            /* Assign VCPU to explicit physical CPU */
            new_vcpu->target_cpu = pcpus[i];
        }
    }

    // ... and now generate the device tree VCPU nodes

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;
}
Expand Down
16 changes: 16 additions & 0 deletions templates/seL4VMParameters.template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int get_instance_size_pcpus_list(void) {
unsigned int get_instance_size_pcpus_list(void) {

/*- if 'pcpus' in config.keys() -*/
return /*? len(config.get('pcpus')) ?*/;
/*- else -*/
return 0;
/*- endif -*/
}
2 changes: 2 additions & 0 deletions templates/seL4VMParameters.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ typedef struct {
} vm_config_t;

extern const vm_config_t vm_config;

int get_instance_size_pcpus_list(void);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int get_instance_size_pcpus_list(void);
unsigned int get_instance_size_pcpus_list(void);