Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/arch/armv8m/inc/arch/vtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ struct vtimer {
};

struct vtimer;
struct vcpu;

void vtimer_init(struct vtimer* vtimer);
void vtimer_reset(struct vtimer* vtimer);
void vtimer_save_state(struct vtimer* vtimer);
void vtimer_restore_state(struct vtimer* vtimer);
void vtimer_restore_state(struct vcpu* vcpu, struct vtimer* vtimer);

#endif /* VTIMER_H */
2 changes: 2 additions & 0 deletions src/arch/armv8m/sau.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ static void sau_entry_set(struct sau_vm* sau_vm, mpid_t mpid, struct mp_region*
unsigned long rbar = (mpr->base & SAU_RBAR_BADDR_MSK);
unsigned long rlar = (lim & SAU_RLAR_LADDR_MSK) | mpr->mem_flags.rlar;

sau_arch_disable();
sau->rnr = mpid;
ISB();
sau->rbar = rbar;
sau_vm->entry[mpid].rbar = rbar;
sau->rlar = rlar;
sau_vm->entry[mpid].rlar = rlar;
sau_arch_enable();
}

static mpid_t sau_entry_allocate(void)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/armv8m/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void vcpu_restore_state(struct vcpu* vcpu)

vmpu_restore_state(&vcpu->arch.vmpu);
// vfp_restore_state(&vcpu->regs.vfp_regs);
vtimer_restore_state(&vcpu->arch.vtimer);
vtimer_restore_state(vcpu, &vcpu->arch.vtimer);
sau_restore(&vcpu->arch.sau_vm);
}

Expand Down
20 changes: 16 additions & 4 deletions src/arch/armv8m/vtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vm.h>
#include <arch/sysregs.h>
#include <arch/systick.h>
#include <sched.h>

void vtimer_init(struct vtimer* vtimer)
{
Expand All @@ -21,7 +22,7 @@ void vtimer_save_state(struct vtimer* vtimer)
vtimer->cvr = systick_get_cvr(systick_ns);
}

void vtimer_restore_state(struct vtimer* vtimer)
void vtimer_restore_state(struct vcpu* vcpu, struct vtimer* vtimer)
{
/* Note: Restoring the CVR implies that we simulate a new count routine, i.e., we need to
disable the timer, reload the previous CVR value to RVR, start the count and immediately stop
Expand All @@ -32,9 +33,20 @@ void vtimer_restore_state(struct vtimer* vtimer)
// Clear CVR
systick_set_cvr(systick_ns, 0);
// Set RVR with the cvr value to be restored
systick_set_rvr(systick_ns, vtimer->cvr);
// Enable the systick timer to force the reload of the cvr
systick_set_csr(systick_ns, systick_get_csr(systick_ns) | SYSTICK_CSR_ENABLE);

if (vcpu->first_run != 0) {
uint32_t vcpu_num = list_size(&cpu()->vcpu_lst);
uint32_t elapsed_time = (uint32_t)time_slice * (vcpu_num - 1);
if (vtimer->cvr < elapsed_time) {
systick_set_rvr(systick_ns, 1);
} else {
systick_set_rvr(systick_ns, vtimer->cvr - elapsed_time);
}

// Enable the systick timer to force the reload of the cvr
systick_set_csr(systick_ns,
systick_get_csr(systick_ns) | SYSTICK_CSR_ENABLE | SYSTICK_CSR_CLKSOURCE);
}

// Restore the CSR and RVR
systick_set_csr(systick_ns, vtimer->csr);
Expand Down
2 changes: 2 additions & 0 deletions src/core/inc/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <crossconhyp.h>

extern const unsigned long long time_slice;

void sched_start(void);
void sched_yield(void);
void sched_init(void);
Expand Down
4 changes: 3 additions & 1 deletion src/core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include <vm.h>
#include <cpu.h>

const unsigned long long time_slice = TIME_MS(10);

void sched_init() { }

static inline timer_value_t sched_next_event_time(void)
{
// hardcoded 10 ms time slice
return (timer_value_t)(timer_arch_get_count() + TIME_MS(10));
return (timer_value_t)(timer_arch_get_count() + time_slice);
}

static void sched_timer_event_handler(struct timer_event* timer_event);
Expand Down
2 changes: 1 addition & 1 deletion src/core/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config)
for (size_t i = 0; i < vm_config->platform.dev_num; i++) {
struct vm_dev_region* dev = &vm_config->platform.devs[i];
INFO("VM %d adding MMIO region, VA: 0x%lx size: 0x%lx mapped at 0x%lx\n", vm->id, dev->va,
dev->va, dev->pa);
dev->size, dev->pa);

size_t n = ALIGN(dev->size, PAGE_SIZE) / PAGE_SIZE;

Expand Down
Loading