Skip to content

Commit

Permalink
libsel4vm: set affinity in vm_assign_vcpu_target
Browse files Browse the repository at this point in the history
Calling seL4_TCB_SetAffinity in the vm_assign_vcpu_target function
allows the vcpu to correctly run on the cpu it is assigned to.
Previously the vcpu was getting assigned to the same core as it's ID.

Signed-off-by: Alex Pavey <[email protected]>
  • Loading branch information
Alex Pavey authored and Alex Pavey committed Nov 17, 2022
1 parent 9a64b59 commit 20bbba0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 0 additions & 6 deletions libsel4vm/src/arch/arm/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ int vm_create_vcpu_arch(vm_t *vm, vm_vcpu_t *vcpu)
vcpu->vcpu_arch.unhandled_vcpu_callback = NULL;
vcpu->vcpu_arch.unhandled_vcpu_callback_cookie = NULL;

#if CONFIG_MAX_NUM_NODES > 1
if (seL4_TCB_SetAffinity(vcpu->tcb.tcb.cptr, vcpu->vcpu_id)) {
err = -1;
}
#endif /* CONFIG_MAX_NUM_NODES > 1 */

#ifdef CONFIG_DEBUG_BUILD
char vcpu_name[32];
snprintf(vcpu_name, sizeof(vcpu_name), "%s:%d", vm->vm_name, vcpu->vcpu_id);
Expand Down
9 changes: 9 additions & 0 deletions libsel4vm/src/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ int vm_assign_vcpu_target(vm_vcpu_t *vcpu, int target_cpu)
ZF_LOGE("Failed to assign target cpu - A VCPU is already assigned to core %d", target_cpu);
return -1;
}

#if CONFIG_MAX_NUM_NODES > 1
int err = seL4_TCB_SetAffinity(vcpu->tcb.tcb.cptr, target_cpu);
if (err) {
ZF_LOGE("[vCPU %u] Failed to set vCPU affinity to %d", vcpu->vcpu_id, target_cpu);
return -1;
}
#endif /* CONFIG_MAX_NUM_NODES > 1 */

vcpu->target_cpu = target_cpu;
return 0;
}

0 comments on commit 20bbba0

Please sign in to comment.