xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); host->setPowerEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host)); }
VMHL13::VMHL13(VMModelPtr model, const char* name, xbt_dict_t props, surf_resource_t host_PM) : VM(model, name, props, NULL, NULL) { HostPtr sub_ws = static_cast<HostPtr>(surf_host_resource_priv(host_PM)); /* Currently, we assume a VM has no storage. */ p_storage = NULL; /* Currently, a VM uses the network resource of its physical host. In * host_lib, this network resource object is referred from two different keys. * When deregistering the reference that points the network resource object * from the VM name, we have to make sure that the system does not call the * free callback for the network resource object. The network resource object * is still used by the physical machine. */ p_netElm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL))); xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm); p_subWs = sub_ws; p_currentState = SURF_VM_STATE_CREATED; // //// CPU RELATED STUFF //// // Roughly, create a vcpu resource by using the values of the sub_cpu one. CpuCas01Ptr sub_cpu = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(host_PM)); /* We can assume one core and cas01 cpu for the first step. * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */ p_cpu = surf_cpu_model_vm->createCpu(name, // name sub_cpu->getPowerPeakList(), // host->power_peak, sub_cpu->getPState(), 1, // host->power_scale, NULL, // host->power_trace, 1, // host->core_amount, SURF_RESOURCE_ON, // host->initial_state, NULL, // host->state_trace, NULL); // host->properties, /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ // vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(host_PM, GUESTOS_NOISE); p_action = sub_cpu->execute(0); XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws->getName(), xbt_dynar_length(p_storage)); }
void CpuCas01Model::addTraces() { xbt_dict_cursor_t cursor = NULL; char *trace_name, *elm; static int called = 0; if (called) return; called = 1; /* connect all traces relative to hosts */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); host->setStateEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host)); }
CpuPtr CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak, int pstate, double power_scale, tmgr_trace_t power_trace, int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace, xbt_dict_t cpu_properties) { CpuPtr cpu = NULL; xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), "Host '%s' declared several times in the platform file", name); xbt_assert(xbt_dynar_getfirst_as(power_peak, double) > 0.0, "Power has to be >0.0. Did you forget to specify the mandatory power attribute?"); xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core); cpu = new CpuCas01(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties); xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); return cpu; }
void test(char *platform) { void *cpuA = NULL; void *cpuB = NULL; void *cardA = NULL; void *cardB = NULL; surf_action_t actionA = NULL; surf_action_t actionB = NULL; surf_action_t actionC = NULL; e_surf_action_state_t stateActionA; e_surf_action_state_t stateActionB; e_surf_action_state_t stateActionC; double now = -1.0; xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01"); xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02"); parse_platform_file(platform); /*********************** CPU ***********************************/ XBT_DEBUG("%p", surf_cpu_model_pm); cpuA = surf_cpu_resource_by_name("Cpu A"); cpuB = surf_cpu_resource_by_name("Cpu B"); /* Let's check that those two processors exist */ XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuA)), cpuA); XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuB)), cpuB); /* Let's do something on it */ actionA = surf_cpu_execute(cpuA, 1000.0); actionB = surf_cpu_execute(cpuB, 1000.0); actionC = surf_cpu_sleep(cpuB, 7.32); /* Use whatever calling style you want... */ stateActionA = surf_action_get_state(actionA); /* When you know actionA model type */ stateActionB = surf_action_get_state(actionB); /* If you're unsure about it's model type */ stateActionC = surf_action_get_state(actionC); /* When you know actionA model type */ /* And just look at the state of these tasks */ XBT_DEBUG("actionA : %p (%s)", actionA, string_action(stateActionA)); XBT_DEBUG("actionB : %p (%s)", actionB, string_action(stateActionB)); XBT_DEBUG("actionC : %p (%s)", actionB, string_action(stateActionC)); /*********************** Network *******************************/ XBT_DEBUG("%p", surf_network_model); cardA = sg_routing_edge_by_name_or_null("Cpu A"); cardB = sg_routing_edge_by_name_or_null("Cpu B"); /* Let's check that those two processors exist */ XBT_DEBUG("%s : %p", surf_routing_edge_name(cardA), cardA); XBT_DEBUG("%s : %p", surf_routing_edge_name(cardB), cardB); /* Let's do something on it */ surf_network_model_communicate(surf_network_model, cardA, cardB, 150.0, -1.0); surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { surf_action_t action = NULL; now = surf_get_clock(); XBT_DEBUG("Next Event : %g", now); XBT_DEBUG("\t CPU actions"); while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_cpu_model_pm))) { XBT_DEBUG("\t * Failed : %p", action); surf_action_unref(action); } while ((action = surf_model_extract_done_action_set((surf_model_t)surf_cpu_model_pm))) { XBT_DEBUG("\t * Done : %p", action); surf_action_unref(action); } XBT_DEBUG("\t Network actions"); while ((action = surf_model_extract_failed_action_set((surf_model_t)surf_network_model))) { XBT_DEBUG("\t * Failed : %p", action); surf_action_unref(action); } while ((action = surf_model_extract_done_action_set((surf_model_t)surf_network_model))) { XBT_DEBUG("\t * Done : %p", action); surf_action_unref(action); } } while ((surf_model_running_action_set_size((surf_model_t)surf_network_model) || surf_model_running_action_set_size((surf_model_t)surf_cpu_model_pm)) && surf_solve(-1.0) >= 0.0); XBT_DEBUG("Simulation Terminated"); }
/* * Update the physical host of the given VM */ void VMHL13::migrate(surf_resource_t ind_dst_pm) { /* ind_dst_pm equals to smx_host_t */ HostPtr ws_dst = static_cast<HostPtr>(surf_host_resource_priv(ind_dst_pm)); const char *vm_name = getName(); const char *pm_name_src = p_subWs->getName(); const char *pm_name_dst = ws_dst->getName(); xbt_assert(ws_dst); /* do something */ /* update net_elm with that of the destination physical host */ RoutingEdgePtr old_net_elm = p_netElm; RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL))); xbt_assert(new_net_elm); /* Unregister the current net_elm from host_lib. Do not call the free callback. */ xbt_lib_unset(host_lib, vm_name, ROUTING_HOST_LEVEL, 0); /* Then, resister the new one. */ p_netElm = new_net_elm; xbt_lib_set(host_lib, vm_name, ROUTING_HOST_LEVEL, p_netElm); p_subWs = ws_dst; /* Update vcpu's action for the new pm */ { #if 0 XBT_INFO("cpu_action->remains %g", p_action->remains); XBT_INFO("cost %f remains %f start %f finish %f", p_action->cost, p_action->remains, p_action->start, p_action->finish ); XBT_INFO("cpu_action state %d", surf_action_get_state(p_action)); #endif /* create a cpu action bound to the pm model at the destination. */ CpuActionPtr new_cpu_action = static_cast<CpuActionPtr>( static_cast<CpuPtr>(surf_cpu_resource_priv(ind_dst_pm))->execute(0)); e_surf_action_state_t state = p_action->getState(); if (state != SURF_ACTION_DONE) XBT_CRITICAL("FIXME: may need a proper handling, %d", state); if (p_action->getRemainsNoUpdate() > 0) XBT_CRITICAL("FIXME: need copy the state(?), %f", p_action->getRemainsNoUpdate()); /* keep the bound value of the cpu action of the VM. */ double old_bound = p_action->getBound(); if (old_bound != 0) { XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name, old_bound, pm_name_dst); new_cpu_action->setBound(old_bound); } _XBT_GNUC_UNUSED int ret = p_action->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); p_action = new_cpu_action; } XBT_DEBUG("migrate VM(%s): change net_elm (%p to %p)", vm_name, old_net_elm, new_net_elm); XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); delete old_net_elm; }
static CpuPtr get_casted_cpu(surf_resource_t resource){ return static_cast<CpuPtr>(surf_cpu_resource_priv(resource)); }