Skip to content

Commit

Permalink
fix(core/vm): remove unnecessary cpu_idle and vcpu_arch_run calls
Browse files Browse the repository at this point in the history
This commit is structured into two parts:
- Removed unnecessary cpu_idle call from vcpu_run to prevent
redundant invocations. This change eliminates continuous calls to cpu_idle in
scenarios where the profile implementation does not jump to a predefined
wake-up point but instead returns directly.
In such cases, the stack was manually rewound, and control was transferred
to the cpu_idle_wakeup function, which then re-entered vcpu_run, leading to
repeated invocations of cpu_idle.
- Removed the vcpu_arch_run call to avoid repeating the same logic for ARM and
RISCV architectures. Instead now we call directly the vcpu_arch_entry if the
core is ready to run.

Signed-off-by: João Peixoto <[email protected]>
  • Loading branch information
joaopeixoto13 committed Oct 22, 2024
1 parent c764a53 commit a62f42c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
11 changes: 1 addition & 10 deletions src/arch/armv8/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ void vcpu_arch_reset(struct vcpu* vcpu, vaddr_t entry)
*/
}

static inline bool vcpu_psci_state_on(struct vcpu* vcpu)
bool vcpu_arch_is_on(struct vcpu* vcpu)
{
return vcpu->arch.psci_ctx.state == ON;
}

void vcpu_arch_run(struct vcpu* vcpu)
{
if (vcpu_psci_state_on(vcpu)) {
vcpu_arch_entry();
} else {
cpu_idle();
}
}
8 changes: 2 additions & 6 deletions src/arch/riscv/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ void vcpu_writepc(struct vcpu* vcpu, unsigned long pc)
vcpu->regs.sepc = pc;
}

void vcpu_arch_run(struct vcpu* vcpu)
bool vcpu_arch_is_on(struct vcpu* vcpu)
{
if (vcpu->arch.sbi_ctx.state == STARTED) {
vcpu_arch_entry();
} else {
cpu_idle();
}
return vcpu->arch.sbi_ctx.state == STARTED;
}
2 changes: 1 addition & 1 deletion src/core/inc/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ unsigned long vcpu_readreg(struct vcpu* vcpu, unsigned long reg);
void vcpu_writereg(struct vcpu* vcpu, unsigned long reg, unsigned long val);
unsigned long vcpu_readpc(struct vcpu* vcpu);
void vcpu_writepc(struct vcpu* vcpu, unsigned long pc);
void vcpu_arch_run(struct vcpu* vcpu);
void vcpu_arch_reset(struct vcpu* vcpu, vaddr_t entry);
bool vcpu_arch_is_on(struct vcpu* vcpu);

#endif /* __VM_H__ */
6 changes: 2 additions & 4 deletions src/core/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ __attribute__((weak)) cpumap_t vm_translate_to_vcpu_mask(struct vm* vm, cpumap_t

void vcpu_run(struct vcpu* vcpu)
{
if (vcpu->active == false) {
cpu_idle();
} else {
vcpu_arch_run(vcpu);
if (vcpu_arch_is_on(vcpu) && vcpu->active == true) {
vcpu_arch_entry();
}
}

0 comments on commit a62f42c

Please sign in to comment.