--- upstream/dynamips-0.2.5/hv_vm.c 2007/10/06 16:01:44 1 +++ upstream/dynamips-0.2.6-RC5/hv_vm.c 2007/10/06 16:09:07 6 @@ -43,6 +43,23 @@ #include "registry.h" #include "hypervisor.h" +/* Find the specified CPU */ +static cpu_mips_t *find_cpu(hypervisor_conn_t *conn,vm_instance_t *vm, + u_int cpu_id) +{ + cpu_mips_t *cpu; + + cpu = cpu_group_find_id(vm->cpu_group,cpu_id); + + if (!cpu) { + vm_release(vm); + hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU specified"); + return NULL; + } + + return cpu; +} + /* Set debugging level */ static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[]) { @@ -178,6 +195,139 @@ return(0); } +/* Set the idle PC value when the CPU is online */ +static int cmd_set_idle_pc_online(hypervisor_conn_t *conn, + int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + cpu->idle_pc = strtoull(argv[2],NULL,0); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Get the idle PC proposals */ +static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + int i; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + mips64_get_idling_pc(cpu); + + for(i=0;iidle_pc_prop_count;i++) { + hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", + cpu->idle_pc_prop[i].pc, + cpu->idle_pc_prop[i].count); + } + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Dump the idle PC proposals */ +static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + int i; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + for(i=0;iidle_pc_prop_count;i++) { + hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", + cpu->idle_pc_prop[i].pc, + cpu->idle_pc_prop[i].count); + } + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Set CPU idle max value */ +static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + cpu->idle_max = atoi(argv[2]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Set CPU idle sleep time value */ +static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn, + int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + cpu->idle_sleep_time = atoi(argv[2]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Show info about potential timer drift */ +static int cmd_show_timer_drift(hypervisor_conn_t *conn, + int argc,char *argv[]) +{ + vm_instance_t *vm; + cpu_mips_t *cpu; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) + return(-1); + + hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", + cpu->timer_drift); + + hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u", + cpu->timer_irq_pending); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + /* Set the exec area size */ static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[]) { @@ -193,6 +343,37 @@ return(0); } +/* Set ghost RAM file */ +static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + vm->ghost_ram_filename = strdup(argv[1]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Set ghost RAM status */ +static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + vm->ghost_status = atoi(argv[1]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + + /* Set PCMCIA ATA disk0 size */ static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[]) { @@ -405,6 +586,36 @@ return(0); } +/* Send a message on the console */ +static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + vtty_store_str(vm->vtty_con,argv[1]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + +/* Send a message on the AUX port */ +static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + vm_instance_t *vm; + + if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) + return(-1); + + vtty_store_str(vm->vtty_aux,argv[1]); + + vm_release(vm); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + /* Show info about VM object */ static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err) { @@ -424,6 +635,27 @@ return(0); } +/* Show console TCP port info about VM object */ +static void cmd_show_vm_list_con_ports(registry_entry_t *entry,void *opt, + int *err) +{ + hypervisor_conn_t *conn = opt; + vm_instance_t *vm = entry->data; + + if (vm->vtty_con_type == VTTY_TYPE_TCP) + hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%d)", + vm->name,vm->vtty_con_tcp_port); +} + +/* VM console TCP port list */ +static int cmd_vm_list_con_ports(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + int err = 0; + registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list_con_ports,conn,&err); + hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); + return(0); +} + /* VM commands */ static hypervisor_cmd_t vm_cmd_array[] = { { "set_debug_level", 2, 2, cmd_set_debug_level, NULL }, @@ -438,6 +670,14 @@ { "set_disk1", 2, 2, cmd_set_disk1, NULL }, { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL }, { "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL }, + { "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL }, + { "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL }, + { "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL }, + { "set_idle_max", 3, 3, cmd_set_idle_max, NULL }, + { "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL }, + { "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL }, + { "set_ghost_file", 2, 2, cmd_set_ghost_file, NULL }, + { "set_ghost_status", 2, 2, cmd_set_ghost_status, NULL }, { "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL }, { "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL }, { "extract_config", 1, 1, cmd_extract_config, NULL }, @@ -445,7 +685,10 @@ { "cpu_info", 2, 2, cmd_show_cpu_info, NULL }, { "suspend", 1, 1, cmd_suspend, NULL }, { "resume", 1, 1, cmd_resume, NULL }, + { "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, + { "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL }, { "list", 0, 0, cmd_vm_list, NULL }, + { "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL }, { NULL, -1, -1, NULL, NULL }, };