From: Martin Quinson Date: Sun, 7 Feb 2016 22:27:36 +0000 (+0100) Subject: sanitize the surf API X-Git-Tag: v3_13~935 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d2782917c11aa6d946e6f21189d6e653114b9295 sanitize the surf API updateState() and friends don't need to have the current date passed as an parameter: they can use surf_get_time() on the rare cases where they need it. This makes the surf_solve loop rather ugly as the code is not ready to jump to the right time to handle events yet. Will soon be fixed. --- diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 08a68e8b92..7b28adefd2 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -183,7 +183,7 @@ void CpuCas01::onSpeedChange() { Cpu::onSpeedChange(); } -void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value, double date) +void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value) { lmm_variable_t var = NULL; lmm_element_t elem = NULL; @@ -206,6 +206,7 @@ void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value, doubl turnOn(); } else { lmm_constraint_t cnst = getConstraint(); + double date = surf_get_clock(); turnOff(); diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index 59d99308ae..ff12def2a4 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -47,7 +47,7 @@ public: int pstate, double speedScale, tmgr_trace_t speedTrace, int core, int initiallyOn, tmgr_trace_t stateTrace) ; ~CpuCas01(); - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; CpuAction *execution_start(double size) override; CpuAction *sleep(double duration) override; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 01beca94e6..2f97c5ba1f 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -561,8 +561,7 @@ void CpuTi::set_speed_trace(tmgr_trace_t trace) } } -void CpuTi::updateState(tmgr_trace_iterator_t event_type, - double value, double date) +void CpuTi::updateState(tmgr_trace_iterator_t event_type, double value) { CpuTiAction *action; @@ -571,10 +570,9 @@ void CpuTi::updateState(tmgr_trace_iterator_t event_type, CpuTiTgmr *trace; s_tmgr_event_t val; - XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(), - value, date); + XBT_DEBUG("Finish trace date: value %f", value); /* update remaining of actions and put in modified cpu swag */ - updateRemainingAmount(date); + updateRemainingAmount(surf_get_clock()); modified(true); @@ -599,6 +597,7 @@ void CpuTi::updateState(tmgr_trace_iterator_t event_type, turnOn(); } else { turnOff(); + double date = surf_get_clock(); /* put all action running on cpu to failed */ for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end()) diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index d4d305a6b5..9538984f2c 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -120,8 +120,10 @@ public: void set_speed_trace(tmgr_trace_t trace); - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; void updateActionsFinishTime(double now); + void updateRemainingAmount(double now); + bool isUsed() override; CpuAction *execution_start(double size) override; CpuAction *sleep(double duration) override; @@ -136,7 +138,6 @@ public: double current_frequency; - void updateRemainingAmount(double now); public: boost::intrusive::list_member_hook<> cpu_ti_hook; }; diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index a6f84f232e..9ab3f506f6 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -229,7 +229,7 @@ public: virtual int fileMove(surf_file_t fd, const char* fullpath); bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override + void updateState(tmgr_trace_iterator_t event_type, double value) override {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource public: diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index d77a0f7157..54ad0844b4 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -480,7 +480,7 @@ bool LinkL07::isUsed(){ return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint()); } -void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value, double /*date*/){ +void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value){ XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value); if (triggered == p_speedEvent) { m_speedScale = value; @@ -497,13 +497,13 @@ void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value, double / } } -void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value, double date) { - XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date); +void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value) { + XBT_DEBUG("Updating link %s (%p) with value=%f", getName(), this, value); if (triggered == m_bandwidth.event) { - updateBandwidth(value, date); + updateBandwidth(value); tmgr_trace_event_unref(&m_bandwidth.event); } else if (triggered == m_latency.event) { - updateLatency(value, date); + updateLatency(value); tmgr_trace_event_unref(&m_latency.event); } else if (triggered == m_stateEvent) { if (value > 0) @@ -516,13 +516,13 @@ void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value, double } } -void LinkL07::updateBandwidth(double value, double date) +void LinkL07::updateBandwidth(double value) { m_bandwidth.peak = value; lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(), m_bandwidth.peak * m_bandwidth.scale); } -void LinkL07::updateLatency(double value, double date) +void LinkL07::updateLatency(double value) { lmm_variable_t var = NULL; L07Action *action; diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index 18a3d3f486..1e1064da57 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -99,7 +99,7 @@ public: int core, int initiallyOn, tmgr_trace_t state_trace); ~CpuL07(); bool isUsed() override; - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; Action *execution_start(double size) override; Action *sleep(double duration) override; protected: @@ -118,9 +118,9 @@ public: e_surf_link_sharing_policy_t policy); ~LinkL07(){ }; bool isUsed() override; - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; - void updateBandwidth(double value, double date=surf_get_clock()) override; - void updateLatency(double value, double date=surf_get_clock()) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; + void updateBandwidth(double value) override; + void updateLatency(double value) override; }; /********** diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 7adf7b1054..c3be602d82 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -170,10 +170,7 @@ NetworkCm02Model::NetworkCm02Model() } else if (!strcmp(optim, "Lazy")) { p_updateMechanism = UM_LAZY; m_selectiveUpdate = 1; - xbt_assert((select == 1) - || - (xbt_cfg_is_default_value - (_sg_cfg_set, "network/maxmin_selective_update")), + xbt_assert((select == 1) || (xbt_cfg_is_default_value(_sg_cfg_set, "network/maxmin_selective_update")), "Disabling selective update while using the lazy update mechanism is dumb!"); } else { xbt_die("Unsupported optimization (%s) for this model", optim); @@ -545,16 +542,15 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_ -void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, - double value, double date) +void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, double value) { /* Find out which of my iterators was triggered, and react accordingly */ if (triggered == m_bandwidth.event) { - updateBandwidth(value, date); + updateBandwidth(value); tmgr_trace_event_unref(&m_bandwidth.event); } else if (triggered == m_latency.event) { - updateLatency(value, date); + updateLatency(value); tmgr_trace_event_unref(&m_latency.event); } else if (triggered == m_stateEvent) { if (value > 0) @@ -562,6 +558,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, else { lmm_variable_t var = NULL; lmm_element_t elem = NULL; + double now = surf_get_clock(); turnOff(); while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) { @@ -569,7 +566,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, if (action->getState() == SURF_ACTION_RUNNING || action->getState() == SURF_ACTION_READY) { - action->setFinishTime(date); + action->setFinishTime(now); action->setState(SURF_ACTION_FAILED); } } @@ -584,7 +581,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, getConstraint()); } -void NetworkCm02Link::updateBandwidth(double value, double date){ +void NetworkCm02Link::updateBandwidth(double value) { double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (m_bandwidth.peak * m_bandwidth.scale); lmm_variable_t var = NULL; @@ -599,7 +596,7 @@ void NetworkCm02Link::updateBandwidth(double value, double date){ getConstraint(), sg_bandwidth_factor * (m_bandwidth.peak * m_bandwidth.scale)); - TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale); + TRACE_surf_link_set_bandwidth(surf_get_clock(), getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale); if (sg_weight_S_parameter > 0) { while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) { action = (NetworkCm02Action*) lmm_variable_id(var); @@ -610,7 +607,7 @@ void NetworkCm02Link::updateBandwidth(double value, double date){ } } -void NetworkCm02Link::updateLatency(double value, double date){ +void NetworkCm02Link::updateLatency(double value){ double delta = value - m_latency.peak; lmm_variable_t var = NULL; lmm_element_t elem = NULL; diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index a5c4284a7f..e4fa8f61e5 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -82,9 +82,9 @@ public: double lat_initial, tmgr_trace_t lat_trace, e_surf_link_sharing_policy_t policy); - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; - void updateBandwidth(double value, double date=surf_get_clock()) override; - void updateLatency(double value, double date=surf_get_clock()) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; + void updateBandwidth(double value) override; + void updateLatency(double value) override; virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {}; diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index e199d1d68d..cba38923fb 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -218,13 +218,13 @@ public: virtual double getBandwidth(); /** @brief Update the bandwidth in bytes per second of current Link */ - virtual void updateBandwidth(double value, double date=surf_get_clock())=0; + virtual void updateBandwidth(double value)=0; /** @brief Get the latency in seconds of current Link */ virtual double getLatency(); /** @brief Update the latency in seconds of current Link */ - virtual void updateLatency(double value, double date=surf_get_clock())=0; + virtual void updateLatency(double value)=0; /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */ virtual int sharingPolicy(); diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 00069455cd..2143f2c986 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -401,9 +401,9 @@ NetworkNS3Link::~NetworkNS3Link() { } -void NetworkNS3Link::updateState(tmgr_trace_iterator_t event_type, double value, double date) +void NetworkNS3Link::updateState(tmgr_trace_iterator_t event_type, double value) { - + THROW_UNIMPLEMENTED; } /********** diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index 57c31ab7d5..bbcbb1c294 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -70,9 +70,9 @@ public: double bw_initial, double lat_initial); ~NetworkNS3Link(); - void updateState(tmgr_trace_iterator_t event_type, double value, double date); - void updateBandwidth(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;} - void updateLatency(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;} + void updateState(tmgr_trace_iterator_t event_type, double value) override; + void updateBandwidth(double value) override {THROW_UNIMPLEMENTED;} + void updateLatency(double value) override {THROW_UNIMPLEMENTED;} //private: int m_created; diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 7cc21ff054..866fd71046 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -140,7 +140,7 @@ bool Storage::isUsed() return false; } -void Storage::updateState(tmgr_trace_iterator_t /*event_type*/, double /*value*/, double /*date*/) +void Storage::updateState(tmgr_trace_iterator_t /*event_type*/, double /*value*/) { THROW_UNIMPLEMENTED; } diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 2bcd3b6e7e..60ec6c693d 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -147,7 +147,7 @@ public: * @param value [description] * @param date [description] */ - void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value) override; void turnOn() override; void turnOff() override; diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 16ead873b4..b6a24beaf8 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -44,7 +44,7 @@ void surf_presolve(void) while ((event = future_evt_set->pop_leq(next_event_date, &value, &resource))) { if (value >= 0){ - resource->updateState(event, value, NOW); + resource->updateState(event, value); } } } @@ -68,7 +68,7 @@ double surf_solve(double max_date) if(!host_that_restart) host_that_restart = xbt_dynar_new(sizeof(char*), NULL); - if (max_date != -1.0 && max_date != NOW) { + if (max_date > 0.0 && max_date != NOW) { surf_min = max_date - NOW; } @@ -96,8 +96,8 @@ double surf_solve(double max_date) 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{ - surf_min = MAX(next_event_date - NOW, surf_min); + } else { + surf_min = MAX(next_event_date - NOW, surf_min); // Get the positive component } XBT_DEBUG("Run the NS3 network at most %fs", surf_min); @@ -124,10 +124,14 @@ double surf_solve(double max_date) surf_min = next_event_date - NOW; XBT_DEBUG("This event will modify model state. Next event set to %f", surf_min); } + // FIXME: I'm too lame to update NOW live, so I change it and restore it so that the real update with surf_min will work + double round_start = NOW; + NOW = next_event_date; /* update state of the corresponding resource to the new value. Does not touch lmm. It will be modified if needed when updating actions */ - XBT_DEBUG("Calling update_resource_state for resource %s with min %f", resource->getName(), surf_min); - resource->updateState(event, value, next_event_date); + XBT_DEBUG("Calling update_resource_state for resource %s", resource->getName()); + resource->updateState(event, value); + NOW = round_start; } } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index d0739e75e7..aff65e2da5 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -417,9 +417,8 @@ public: * * @param event_type [TODO] * @param value [TODO] - * @param date [TODO] */ - virtual void updateState(tmgr_trace_iterator_t event_type, double value, double date)=0; + virtual void updateState(tmgr_trace_iterator_t event_type, double value)=0; /** @brief Check if the current Resource is used (if it currently serves an action) */ virtual bool isUsed()=0; diff --git a/teshsuite/surf/trace_usage/trace_usage.cpp b/teshsuite/surf/trace_usage/trace_usage.cpp index c9fb7e4c5f..d7e3efe7aa 100644 --- a/teshsuite/surf/trace_usage/trace_usage.cpp +++ b/teshsuite/surf/trace_usage/trace_usage.cpp @@ -24,7 +24,7 @@ class DummyTestResource public: DummyTestResource(const char *name) : Resource(nullptr,name) {} bool isUsed() override {return false;} - void updateState(tmgr_trace_iterator_t it, double date, double value) override {} + void updateState(tmgr_trace_iterator_t it, double value) override {} }; static void test(void)