From: Martin Quinson Date: Mon, 20 Jul 2015 16:14:21 +0000 (+0200) Subject: Kill models getName() call sites. X-Git-Tag: v3_12~459 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3715b2a421abd8357f41fb2be3c25a351f1af8cb?hp=12ab87e38dd389503c6b2738b8d3d085558354eb Kill models getName() call sites. - Debug messages now depend on typeid(...).name(). Beware, the output may be compiler dependent. - It was mainly used to have a specific handling of NS3, which method shareRessources() is not idempotent (ie, it actually moves the model in the future with no possibility of rolling it back afterward). So NS3->shareRessource() needs to be run after all other shareRessources, and before the updateState()s. Add a shareResourcesIsIdempotent() method to all models to detect whether we need to activate that strange behavior without having to rely on the model name. - Removing models namesmakes Model pure virtual, possibly allowing diamon-shaped inheritance in L07, where we need only one model for CpuModel and NetworkModel. --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 1dee6917be..15b1b8e1e5 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -198,11 +198,9 @@ XBT_PUBLIC(void) surf_as_cluster_set_backbone(AS_t as, void* backbone); /** @{ @ingroup SURF_c_bindings */ -/** - * @brief Get the name of a surf model +/** @brief Get the name of a surf model (dont rely on exact value) * - * @param model A model - * @return The name of the model + * This is implemented using typeid(), so it may change with the compiler */ XBT_PUBLIC(const char *) surf_model_name(surf_model_t model); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 6375ce014c..ecbf8b09a6 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -90,6 +90,7 @@ public: void updateActionsStateLazy(double now, double delta); void updateActionsStateFull(double now, double delta); + bool shareResourcesIsIdempotent() {return true;} }; /************ diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index bfe88b0fca..2932677a85 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -69,13 +69,13 @@ double HostCLM03Model::shareResources(double now){ adjustWeightOfDummyCpuActions(); double min_by_cpu = surf_cpu_model_pm->shareResources(now); - double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1; + double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1; double min_by_sto = surf_storage_model->shareResources(now); XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f", - this, surf_cpu_model_pm->getName(), min_by_cpu, - surf_network_model->getName(), min_by_net, - surf_storage_model->getName(), min_by_sto); + this, typeid(surf_cpu_model_pm).name(), min_by_cpu, + typeid(surf_network_model).name(), min_by_net, + typeid(surf_storage_model).name(), min_by_sto); double res = max(max(min_by_cpu, min_by_net), min_by_sto); if (min_by_cpu >= 0.0 && min_by_cpu < res) diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 48fa525ad2..78e7f5ac05 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -80,6 +80,8 @@ public: double rate)=0; virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0; + + bool shareResourcesIsIdempotent() {return true;} }; /************ diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index 66c5b03711..33a957dfa8 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -81,6 +81,8 @@ public: Action *communicate(RoutingEdge */*src*/, RoutingEdge */*dst*/, double /*size*/, double /*rate*/) {DIE_IMPOSSIBLE;}; void addTraces() {DIE_IMPOSSIBLE;}; + bool shareResourcesIsIdempotent() {return true;} + HostL07Model *p_hostModel; }; diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index 3dd58ea178..300783755b 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -56,6 +56,7 @@ public: void updateActionsStateFull(double now, double delta); Action *communicate(RoutingEdge *src, RoutingEdge *dst, double size, double rate); + bool shareResourcesIsIdempotent() {return true;} }; /************ diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index b296eb2347..82bcc7e84b 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -46,6 +46,7 @@ public: double shareResources(double now); void updateActionsState(double now, double delta); void addTraces(){DIE_IMPOSSIBLE;} + bool shareResourcesIsIdempotent() {return false;} }; /************ diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 241cb67152..9e0e4420ed 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -84,6 +84,8 @@ public: xbt_dict_t properties, const char *attach) = 0; + bool shareResourcesIsIdempotent() {return true;} + xbt_dynar_t p_storageList; }; diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 6ea7968267..c3464409b2 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -76,11 +76,11 @@ double surf_solve(double max_date) XBT_DEBUG("Looking for next action end for all models except NS3"); xbt_dynar_foreach(model_list_invoke, iter, model) { double next_action_end = -1.0; - if (strcmp(model->getName(), "network NS3")) { - XBT_DEBUG("Running for Resource [%s]", model->getName()); + if (model->shareResourcesIsIdempotent()) { + XBT_DEBUG("Running for Resource [%s]", typeid(model).name()); next_action_end = model->shareResources(NOW); XBT_DEBUG("Resource [%s] : next action end = %f", - model->getName(), next_action_end); + typeid(model).name(), next_action_end); } if ((surf_min < 0.0 || next_action_end < surf_min) && next_action_end >= 0.0) { @@ -97,7 +97,7 @@ double surf_solve(double max_date) next_event_date = tmgr_history_next_date(history); - if(!strcmp(surf_network_model->getName(), "network NS3")){ + if(! surf_network_model->shareResourcesIsIdempotent()){ // NS3, I see you if(next_event_date!=-1.0 && surf_min!=-1.0) { surf_min = MIN(next_event_date - NOW, surf_min); } else{ @@ -186,7 +186,7 @@ void surf_as_cluster_set_backbone(AS_t as, void* backbone){ } const char *surf_model_name(surf_model_t model){ - return model->getName(); + return typeid(model).name(); } surf_action_t surf_model_extract_done_action_set(surf_model_t model){ diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 2197bb078d..f9ca6dbcf5 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -211,6 +211,13 @@ public: virtual void updateActionsStateLazy(double now, double delta); virtual void updateActionsStateFull(double now, double delta); + /** @brief Returns whether this model have an idempotent shareResource() + * + * The only model that is not is NS3: computing the next timestamp moves the model up to that point, + * so we need to call it only when the next timestamp of other sources is computed. + */ + virtual bool shareResourcesIsIdempotent()=0; + protected: ActionLmmListPtr p_modifiedSet; lmm_system_t p_maxminSystem; diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 4afa59eccb..68cfc56309 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -127,7 +127,7 @@ double VMHL13Model::shareResources(double now) adjustWeightOfDummyCpuActions(); double min_by_cpu = surf_cpu_model_vm->shareResources(now); - double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1; + double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1; // Fixme: take storage into account once it's implemented double min_by_sto = -1;