void vmm_scheduler_next(vmm_timer_event_t * ev, vmm_user_regs_t * regs) { int next, vcpu_count = vmm_manager_vcpu_count(); vmm_vcpu_t *cur_vcpu, *nxt_vcpu; /* Determine current vcpu */ cur_vcpu = sched.current_vcpu; /* Determine the next ready vcpu to schedule */ next = (cur_vcpu) ? cur_vcpu->id : -1; next = ((next + 1) < vcpu_count) ? (next + 1) : 0; nxt_vcpu = vmm_manager_vcpu(next); while (nxt_vcpu->state != VMM_VCPU_STATE_READY) { next = ((next + 1) < vcpu_count) ? (next + 1) : 0; nxt_vcpu = vmm_manager_vcpu(next); } /* Do context switch between current and next vcpus */ if (!cur_vcpu || (cur_vcpu->id != nxt_vcpu->id)) { if (cur_vcpu && (cur_vcpu->state & VMM_VCPU_STATE_SAVEABLE)) { if (cur_vcpu->state == VMM_VCPU_STATE_RUNNING) { cur_vcpu->state = VMM_VCPU_STATE_READY; } vmm_vcpu_regs_switch(cur_vcpu, nxt_vcpu, regs); } else { vmm_vcpu_regs_switch(NULL, nxt_vcpu, regs); } } if (nxt_vcpu) { nxt_vcpu->state = VMM_VCPU_STATE_RUNNING; sched.current_vcpu = nxt_vcpu; vmm_timer_event_start(ev, nxt_vcpu->time_slice); } }
static int cmd_vcpu_list(struct vmm_chardev *cdev, int dummy) { int id, count; char state[10]; char path[256]; struct vmm_vcpu *vcpu; vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); vmm_cprintf(cdev, "| %-5s| %-6s| %-9s| %-16s| %-33s|\n", "ID ", "Prio", "State", "Name", "Device Path"); vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); count = vmm_manager_vcpu_count(); for (id = 0; id < count; id++) { vcpu = vmm_manager_vcpu(id); switch (vcpu->state) { case VMM_VCPU_STATE_UNKNOWN: vmm_strcpy(state, "Unknown"); break; case VMM_VCPU_STATE_RESET: vmm_strcpy(state, "Reset"); break; case VMM_VCPU_STATE_READY: vmm_strcpy(state, "Ready"); break; case VMM_VCPU_STATE_RUNNING: vmm_strcpy(state, "Running"); break; case VMM_VCPU_STATE_PAUSED: vmm_strcpy(state, "Paused"); break; case VMM_VCPU_STATE_HALTED: vmm_strcpy(state, "Halted"); break; default: vmm_strcpy(state, "Invalid"); break; } if (vcpu->node) { vmm_devtree_getpath(path, vcpu->node); vmm_cprintf(cdev, "| %-5d| %-6d| %-9s| %-16s| %-33s|\n", id, vcpu->priority, state, vcpu->name, path); } else { vmm_cprintf(cdev, "| %-5d| %-6d| %-9s| %-16s| %-33s|\n", id, vcpu->priority, state, vcpu->name, "(NA)"); } } vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); return VMM_OK; }