Skip to content

Commit

Permalink
rvvm: Implement RVVM_OPT_MAX_CPU_CENT
Browse files Browse the repository at this point in the history
- Very minimal but functional implementation
- Further enhancement would imply balancing the preemption across machines, accounting for sleep imprecision
  • Loading branch information
LekKit authored Apr 21, 2023
1 parent 6da35f0 commit 6e84d08
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rvvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ static void* rvvm_eventloop(void* arg)
if ((vm->csr.ie & INTERRUPT_MTIMER) && rvtimer_pending(&vm->timer)) {
riscv_hart_check_timer(vector_at(machine->harts, i));
}
if (rvvm_get_opt(machine, RVVM_OPT_MAX_CPU_CENT) < 100) {
uint32_t preempt = 10 - ((10 * rvvm_get_opt(machine, RVVM_OPT_MAX_CPU_CENT) + 9) / 100);
riscv_hart_preempt(vm, preempt);
}
}

vector_foreach(machine->mmio, i) {
Expand Down

0 comments on commit 6e84d08

Please sign in to comment.