From 1300b88c419e071782315f75655a580b545c9dd3 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 10 Feb 2014 14:51:25 +0100 Subject: [PATCH] Make a list of WorkstationVM, instead of iterating over all hosts to list them. With this change, execution time is reduced by 50% on a chord example with 10000 hosts. --- src/surf/vm_workstation_hl13.cpp | 41 ++++++++----------------- src/surf/vm_workstation_interface.cpp | 5 +++ src/surf/vm_workstation_interface.hpp | 8 ++++- src/surf/workstation_interface.cpp | 44 ++++++++------------------- 4 files changed, 38 insertions(+), 60 deletions(-) diff --git a/src/surf/vm_workstation_hl13.cpp b/src/surf/vm_workstation_hl13.cpp index d9299c09ed..b5fe764dfa 100644 --- a/src/surf/vm_workstation_hl13.cpp +++ b/src/surf/vm_workstation_hl13.cpp @@ -110,27 +110,18 @@ 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.begin(); ++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 = static_cast(ws_vm->p_cpu); + xbt_assert(cpu, "cpu-less workstation"); double solved_value = get_solved_value(static_cast(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; @@ -164,20 +155,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.begin(); ++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, diff --git a/src/surf/vm_workstation_interface.cpp b/src/surf/vm_workstation_interface.cpp index 46299a4c70..688ad12418 100644 --- a/src/surf/vm_workstation_interface.cpp +++ b/src/surf/vm_workstation_interface.cpp @@ -28,6 +28,8 @@ WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation p_cpuModel = surf_cpu_model_vm; } +WorkstationVMModel::vm_list_t WorkstationVMModel::ws_vms; + /************ * Resource * ************/ @@ -36,6 +38,7 @@ WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu) : Workstation(model, name, props, NULL, netElm, cpu) { + WorkstationVMModel::ws_vms.push_back(*this); surf_callback_emit(workstationVMCreatedCallbacks, this); } @@ -46,6 +49,8 @@ WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props, WorkstationVM::~WorkstationVM() { surf_callback_emit(workstationVMDestructedCallbacks, this); + WorkstationVMModel::ws_vms.erase(WorkstationVMModel:: + vm_list_t::s_iterator_to(*this)); } void WorkstationVM::setState(e_surf_resource_state_t state){ diff --git a/src/surf/vm_workstation_interface.hpp b/src/surf/vm_workstation_interface.hpp index 262b288f7a..66a3e9da10 100644 --- a/src/surf/vm_workstation_interface.hpp +++ b/src/surf/vm_workstation_interface.hpp @@ -78,6 +78,11 @@ public: virtual void createResource(const char *name, void *ind_phys_workstation)=0; void adjustWeightOfDummyCpuActions() {}; + + typedef boost::intrusive::list > + vm_list_t; + static vm_list_t ws_vms; }; /************ @@ -88,7 +93,8 @@ public: * @brief SURF workstation VM interface class * @details A workstation VM represent an virtual machine */ -class WorkstationVM : public Workstation { +class WorkstationVM : public Workstation, + public boost::intrusive::list_base_hook<> { public: /** * @brief WorkstationVM consrtructor diff --git a/src/surf/workstation_interface.cpp b/src/surf/workstation_interface.cpp index 5f8d501cc2..cd222049a1 100644 --- a/src/surf/workstation_interface.cpp +++ b/src/surf/workstation_interface.cpp @@ -46,24 +46,14 @@ WorkstationModel::~WorkstationModel() { * not get any CPU share in the PM layer. */ void WorkstationModel::adjustWeightOfDummyCpuActions() { - /* 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]); - CpuCas01Ptr cpu_cas01 = 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_cas01, "cpu-less workstation"); + /* iterate for all virtual machines */ + for (WorkstationVMModel::vm_list_t::iterator iter = + WorkstationVMModel::ws_vms.begin(); + iter != WorkstationVMModel::ws_vms.begin(); ++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; + CpuCas01Ptr cpu_cas01 = static_cast(ws_vm->p_cpu); + xbt_assert(cpu_cas01, "cpu-less workstation"); int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->getConstraint()); // int is_active_old = constraint_is_active(cpu_cas01); @@ -309,20 +299,12 @@ xbt_dynar_t Workstation::getVms() { xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL); - /* 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]); - if (!ws) - continue; - /* skip if it is not a virtual machine */ - if (ws->getModel() != static_cast(surf_vm_workstation_model)) - continue; - - /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ - WorkstationVMPtr ws_vm = static_cast(ws); + /* iterate for all virtual machines */ + for (WorkstationVMModel::vm_list_t::iterator iter = + WorkstationVMModel::ws_vms.begin(); + iter != WorkstationVMModel::ws_vms.begin(); ++iter) { + + WorkstationVMPtr ws_vm = &*iter; if (this == ws_vm-> p_subWs) xbt_dynar_push(dyn, &ws_vm->p_subWs); } -- 2.20.1