X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5b3677b425b9cc6949c1573d59ac772540cbf4b2..3dbeba193df2e406bd9eff5be73c8bce0db0185e:/src/surf/vm_workstation_hl13.cpp diff --git a/src/surf/vm_workstation_hl13.cpp b/src/surf/vm_workstation_hl13.cpp index 1be5053ade..725b313a38 100644 --- a/src/surf/vm_workstation_hl13.cpp +++ b/src/surf/vm_workstation_hl13.cpp @@ -9,10 +9,10 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_vm_workstation); -void surf_vm_workstation_model_init_current_default(void){ +void surf_vm_workstation_model_init_HL13(void){ if (surf_cpu_model_vm) { surf_vm_workstation_model = new WorkstationVMHL13Model(); - ModelPtr model = static_cast(surf_vm_workstation_model); + ModelPtr model = surf_vm_workstation_model; xbt_dynar_push(model_list, &model); xbt_dynar_push(model_list_invoke, &model); @@ -31,11 +31,6 @@ void WorkstationVMHL13Model::updateActionsState(double /*now*/, double /*delta*/ return; } -xbt_dynar_t WorkstationVMHL13Model::getRoute(WorkstationPtr src, WorkstationPtr dst){ - XBT_DEBUG("ws_get_route"); - return surf_network_model->getRoute(src->p_netElm, dst->p_netElm); -} - ActionPtr WorkstationVMHL13Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate){ return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate); } @@ -43,15 +38,16 @@ ActionPtr WorkstationVMHL13Model::communicate(WorkstationPtr src, WorkstationPtr /* ind means ''indirect'' that this is a reference on the whole dict_elm * structure (i.e not on the surf_resource_private infos) */ -void WorkstationVMHL13Model::createResource(const char *name, void *ind_phys_workstation) +WorkstationVMPtr WorkstationVMHL13Model::createWorkstationVM(const char *name, surf_resource_t ind_phys_workstation) { - WorkstationVMHL13Ptr ws = new WorkstationVMHL13(this, name, NULL, static_cast(ind_phys_workstation)); + WorkstationVMHL13Ptr ws = new WorkstationVMHL13(this, name, NULL, ind_phys_workstation); - xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast(ws)); + xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws); /* TODO: * - check how network requests are scheduled between distinct processes competing for the same card. */ + return ws; } static inline double get_solved_value(CpuActionPtr cpu_action) @@ -74,10 +70,10 @@ double WorkstationVMHL13Model::shareResources(double now) /* 0. Make sure that we already calculated the resource share at the physical * machine layer. */ { - ModelPtr ws_model = static_cast(surf_workstation_model); - ModelPtr vm_ws_model = static_cast(surf_vm_workstation_model); - unsigned int index_of_pm_ws_model = xbt_dynar_search(model_list_invoke, &ws_model); - unsigned int index_of_vm_ws_model = xbt_dynar_search(model_list_invoke, &vm_ws_model); + _XBT_GNUC_UNUSED ModelPtr ws_model = surf_workstation_model; + _XBT_GNUC_UNUSED ModelPtr vm_ws_model = surf_vm_workstation_model; + _XBT_GNUC_UNUSED unsigned int index_of_pm_ws_model = xbt_dynar_search(model_list_invoke, &ws_model); + _XBT_GNUC_UNUSED unsigned int index_of_vm_ws_model = xbt_dynar_search(model_list_invoke, &vm_ws_model); xbt_assert((index_of_pm_ws_model < index_of_vm_ws_model), "Cannot assume surf_workstation_model comes before"); /* Another option is that we call sub_ws->share_resource() here. The @@ -110,31 +106,22 @@ double WorkstationVMHL13Model::shareResources(double now) * **/ - /* iterate for all hosts including virtual machines */ - xbt_lib_cursor_t cursor; - char *key; - void **ind_host; - xbt_lib_foreach(host_lib, cursor, key, ind_host) { - WorkstationPtr ws = static_cast(ind_host[SURF_WKS_LEVEL]); - CpuPtr cpu = static_cast(ind_host[SURF_CPU_LEVEL]); - - if (!ws) - continue; - /* skip if it is not a virtual machine */ - if (ws->getModel() != static_cast(surf_vm_workstation_model)) - continue; - xbt_assert(cpu, "cpu-less workstation"); + /* iterate for all virtual machines */ + for (WorkstationVMModel::vm_list_t::iterator iter = + WorkstationVMModel::ws_vms.begin(); + iter != WorkstationVMModel::ws_vms.end(); ++iter) { - /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ - WorkstationVMPtr ws_vm = static_cast(ws); + WorkstationVMPtr ws_vm = &*iter; + CpuPtr cpu = ws_vm->p_cpu; + xbt_assert(cpu, "cpu-less workstation"); - double solved_value = get_solved_value(static_cast(ws_vm->p_action)); + double solved_value = get_solved_value(ws_vm->p_action); XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, - ws->getName(), ws_vm->p_subWs->getName()); + ws_vm->getName(), ws_vm->p_subWs->getName()); // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution. // cpu_cas01->constraint->bound = solved_value; - xbt_assert(cpu->getModel() == static_cast(surf_cpu_model_vm)); + xbt_assert(cpu->getModel() == surf_cpu_model_vm); lmm_system_t vcpu_system = cpu->getModel()->getMaxminSystem(); lmm_update_constraint_bound(vcpu_system, cpu->getConstraint(), virt_overhead * solved_value); } @@ -144,7 +131,7 @@ double WorkstationVMHL13Model::shareResources(double now) adjustWeightOfDummyCpuActions(); double min_by_cpu = p_cpuModel->shareResources(now); - double min_by_net = surf_network_model->shareResources(now); + double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1; double min_by_sto = -1; if (p_cpuModel == surf_cpu_model_pm) min_by_sto = surf_storage_model->shareResources(now); @@ -164,20 +151,14 @@ double WorkstationVMHL13Model::shareResources(double now) /* FIXME: 3. do we have to re-initialize our cpu_action object? */ #if 0 - /* iterate for all hosts including virtual machines */ - xbt_lib_foreach(host_lib, cursor, key, ind_host) { - WorkstationCLM03Ptr ws_clm03 = ind_host[SURF_WKS_LEVEL]; - - /* skip if it is not a virtual machine */ - if (!ws_clm03) - continue; - if (ws_clm03->getModel() != surf_vm_workstation_model) - continue; + /* iterate for all virtual machines */ + for (WorkstationVMModel::vm_list_t::iterator iter = + WorkstationVMModel::ws_vms.begin(); + iter != WorkstationVMModel::ws_vms.end(); ++iter) { - /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ { #if 0 - WorkstationVM2013Ptr ws_vm2013 = (workstation_VM2013_t) ws_clm03; + WorkstationVM2013Ptr ws_vm2013 = static_cast(&*iter); XBT_INFO("cost %f remains %f start %f finish %f", ws_vm2013->cpu_action->cost, ws_vm2013->cpu_action->remains, ws_vm2013->cpu_action->start, @@ -202,26 +183,26 @@ double WorkstationVMHL13Model::shareResources(double now) ActionPtr WorkstationVMHL13Model::executeParallelTask(int workstation_nb, void **workstation_list, - double *computation_amount, - double *communication_amount, + double *flops_amount, + double *bytes_amount, double rate){ #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) if ((workstation_nb == 1) - && (cost_or_zero(communication_amount, 0) == 0.0)) - return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]); + && (cost_or_zero(bytes_amount, 0) == 0.0)) + return ((WorkstationCLM03Ptr)workstation_list[0])->execute(flops_amount[0]); else if ((workstation_nb == 1) - && (cost_or_zero(computation_amount, 0) == 0.0)) - return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate); + && (cost_or_zero(flops_amount, 0) == 0.0)) + return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],bytes_amount[0], rate); else if ((workstation_nb == 2) - && (cost_or_zero(computation_amount, 0) == 0.0) - && (cost_or_zero(computation_amount, 1) == 0.0)) { + && (cost_or_zero(flops_amount, 0) == 0.0) + && (cost_or_zero(flops_amount, 1) == 0.0)) { int i,nb = 0; double value = 0.0; for (i = 0; i < workstation_nb * workstation_nb; i++) { - if (cost_or_zero(communication_amount, i) > 0.0) { + if (cost_or_zero(bytes_amount, i) > 0.0) { nb++; - value = cost_or_zero(communication_amount, i); + value = cost_or_zero(bytes_amount, i); } } if (nb == 1) @@ -247,7 +228,7 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na p_storage = NULL; /* Currently, a VM uses the network resource of its physical host. In - * host_lib, this network resource object is refered from two different keys. + * 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 @@ -265,9 +246,9 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na /* 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 = static_cast(surf_cpu_model_vm)->createResource(name, // name - sub_cpu->p_powerPeakList, // host->power_peak, - sub_cpu->m_pstate, + 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, @@ -278,7 +259,7 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to peridocally input GUESTOS_NOISE to the system? how ? */ // vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_phys_workstation, GUESTOS_NOISE); - p_action = static_cast(sub_cpu->execute(0)); + p_action = sub_cpu->execute(0); /* The SURF_WKS_LEVEL at host_lib saves workstation_CLM03 objects. Please * note workstation_VM2013 objects, inheriting the workstation_CLM03 @@ -291,45 +272,14 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na } /* - * A physical host does not disapper in the current SimGrid code, but a VM may - * disapper during a simulation. + * A physical host does not disappear in the current SimGrid code, but a VM may + * disappear during a simulation. */ WorkstationVMHL13::~WorkstationVMHL13() { - /* ind_phys_workstation equals to smx_host_t */ - // surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName()); - - /* Before clearing the entries in host_lib, we have to pick up resources. */ - // CpuCas01Ptr cpu = static_cast(surf_cpu_resource_priv(ind_vm_workstation)); - - /* We deregister objects from host_lib, without invoking the freeing callback - * of each level. - * - * Do not call xbt_lib_remove() here. It deletes all levels of the key, - * including MSG_HOST_LEVEL and others. We should unregister only what we know. - */ - xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0); - - /* TODO: comment out when VM stroage is implemented. */ - // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); - - /* Free the cpu_action of the VM. */ - int ret = p_action->unref(); + _XBT_GNUC_UNUSED int ret = p_action->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); - - /* Free the cpu resource of the VM. If using power_trace, we will have to */ - //delete cpu; - - /* Free the network resource of the VM. */ - // Nothing has to be done, because net_elmts is just a pointer on the physical one - - /* Free the storage resource of the VM. */ - // Not relevant yet - - /* Free the workstation resource of the VM. */ } void WorkstationVMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) { @@ -398,7 +348,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm) /* update net_elm with that of the destination physical host */ RoutingEdgePtr old_net_elm = p_netElm; - RoutingEdgePtr new_net_elm = static_cast(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL)); + RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast(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. */ @@ -432,21 +382,22 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm) if (p_action->getRemainsNoUpdate() > 0) XBT_CRITICAL("FIXME: need copy the state(?), %f", p_action->getRemainsNoUpdate()); - int ret = p_action->unref(); - xbt_assert(ret == 1, "Bug: some resource still remains"); - /* keep the bound value of the cpu action of the VM. */ double old_bound = p_action->getBound(); if (old_bound != 0) { - XBT_INFO("migrate VM(%s): set bound (%lf) at %s", vm_name, old_bound, pm_name_dst); + 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; } void WorkstationVMHL13::setBound(double bound){ @@ -458,7 +409,7 @@ void WorkstationVMHL13::setAffinity(CpuPtr cpu, unsigned long mask){ } /* - * A surf level object will be useless in the upper layer. Returing the + * A surf level object will be useless in the upper layer. Returning the * dict_elm of the host. **/ surf_resource_t WorkstationVMHL13::getPm()