From ede7d4e0f2464d8646f1d1a3b09fa7f678660ade Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 8 Feb 2016 00:06:47 +0100 Subject: [PATCH] sanitize surf API: s/shareResources/next_occuring_event/ This means that we describe the external event (what it does for the caller) instead of the internal behavior (how it gets to that result) --- src/surf/cpu_cas01.cpp | 5 ++-- src/surf/cpu_cas01.hpp | 2 +- src/surf/cpu_interface.hpp | 2 +- src/surf/cpu_ti.cpp | 2 +- src/surf/cpu_ti.hpp | 2 +- src/surf/host_clm03.cpp | 8 ++--- src/surf/host_clm03.hpp | 2 +- src/surf/host_interface.hpp | 2 +- src/surf/host_ptask_L07.cpp | 2 +- src/surf/host_ptask_L07.hpp | 4 +-- src/surf/network_cm02.hpp | 2 +- src/surf/network_constant.cpp | 2 +- src/surf/network_constant.hpp | 13 ++++---- src/surf/network_interface.cpp | 2 +- src/surf/network_interface.hpp | 2 +- src/surf/network_ns3.cpp | 4 +-- src/surf/network_ns3.hpp | 11 ++++--- src/surf/storage_interface.hpp | 2 +- src/surf/storage_n11.cpp | 2 +- src/surf/storage_n11.hpp | 6 ++-- src/surf/surf_c_bindings.cpp | 54 ++++++++++++++++++---------------- src/surf/surf_interface.cpp | 10 +++---- src/surf/surf_interface.hpp | 11 ++++--- src/surf/vm_hl13.cpp | 6 ++-- src/surf/vm_hl13.hpp | 2 +- 25 files changed, 78 insertions(+), 82 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 7b28adefd2..a174238b21 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -100,10 +100,9 @@ Cpu *CpuCas01Model::createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, return cpu; } -double CpuCas01Model::shareResourcesFull(double /*now*/) +double CpuCas01Model::next_occuring_event_full(double /*now*/) { - return Model::shareResourcesMaxMin(getRunningActionSet(), - p_maxminSystem, lmm_solve); + return Model::shareResourcesMaxMin(getRunningActionSet(), p_maxminSystem, lmm_solve); } void CpuCas01Model::addTraces() diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index ff12def2a4..99cea9d15b 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -32,7 +32,7 @@ public: tmgr_trace_t speedTrace, int core, int initiallyOn, tmgr_trace_t state_trace) override; - double shareResourcesFull(double now) override; + double next_occuring_event_full(double now) override; void addTraces() override; ActionList *p_cpuRunningActionSetThatDoesNotNeedBeingChecked; }; diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 1684541bf5..baa184b27d 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -59,7 +59,7 @@ public: void updateActionsStateLazy(double now, double delta); void updateActionsStateFull(double now, double delta); - bool shareResourcesIsIdempotent() {return true;} + bool next_occuring_event_isIdempotent() {return true;} }; /************ diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 2f97c5ba1f..4a573ef1cc 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -444,7 +444,7 @@ Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, return cpu; } -double CpuTiModel::shareResources(double now) +double CpuTiModel::next_occuring_event(double now) { double min_action_duration = -1; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 9538984f2c..20d9cbc3fc 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -158,7 +158,7 @@ public: tmgr_trace_t speedTrace, int core, int initiallyOn, tmgr_trace_t state_trace) override; - double shareResources(double now) override; + double next_occuring_event(double now) override; void updateActionsState(double now, double delta) override; void addTraces() override; diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 0bfbc87276..c240e0ebfb 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -46,12 +46,12 @@ void surf_host_model_init_compound() namespace simgrid { namespace surf { -double HostCLM03Model::shareResources(double now){ +double HostCLM03Model::next_occuring_event(double now){ adjustWeightOfDummyCpuActions(); - double min_by_cpu = surf_cpu_model_pm->shareResources(now); - double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1; - double min_by_sto = surf_storage_model->shareResources(now); + double min_by_cpu = surf_cpu_model_pm->next_occuring_event(now); + double min_by_net = surf_network_model->next_occuring_event_isIdempotent() ? surf_network_model->next_occuring_event(now) : -1; + double min_by_sto = surf_storage_model->next_occuring_event(now); XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f", this, typeid(surf_cpu_model_pm).name(), min_by_cpu, diff --git a/src/surf/host_clm03.hpp b/src/surf/host_clm03.hpp index 74bff01ee6..4c66fc7da6 100644 --- a/src/surf/host_clm03.hpp +++ b/src/surf/host_clm03.hpp @@ -31,7 +31,7 @@ class HostCLM03Model : public HostModel { public: HostCLM03Model(): HostModel(){} ~HostCLM03Model() {} - double shareResources(double now) override; + double next_occuring_event(double now) override; void updateActionsState(double now, double delta) override; }; diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 9ab3f506f6..dfef15a477 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -62,7 +62,7 @@ public: double *bytes_amount, double rate); - bool shareResourcesIsIdempotent() override {return true;} + bool next_occuring_event_isIdempotent() override {return true;} }; /************ diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 54ad0844b4..a3224f7dc1 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -89,7 +89,7 @@ NetworkL07Model::~NetworkL07Model() } -double HostL07Model::shareResources(double /*now*/) +double HostL07Model::next_occuring_event(double /*now*/) { L07Action *action; diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index 1e1064da57..0b0349e4ff 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -43,7 +43,7 @@ public: HostL07Model(); ~HostL07Model(); - double shareResources(double now) override; + double next_occuring_event(double now) override; void updateActionsState(double now, double delta) override; Action *executeParallelTask(int host_nb, sg_host_t *host_list, double *flops_amount, double *bytes_amount, @@ -83,7 +83,7 @@ public: Action *communicate(NetCard *src, NetCard *dst, double size, double rate) override; void addTraces() override {DIE_IMPOSSIBLE;}; - bool shareResourcesIsIdempotent() override {return true;} + bool next_occuring_event_isIdempotent() override {return true;} HostL07Model *p_hostModel; }; diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index e4fa8f61e5..61e8b1ca1b 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -60,7 +60,7 @@ public: void updateActionsStateFull(double now, double delta) override; Action *communicate(NetCard *src, NetCard *dst, double size, double rate) override; - bool shareResourcesIsIdempotent() override {return true;} + bool next_occuring_event_isIdempotent() override {return true;} virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {}; protected: bool m_haveGap = false; diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 836a8c4707..df75a9d863 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -31,7 +31,7 @@ void surf_network_model_init_Constant() namespace simgrid { namespace surf { -double NetworkConstantModel::shareResources(double /*now*/) +double NetworkConstantModel::next_occuring_event(double /*now*/) { NetworkConstantAction *action = NULL; double min = -1.0; diff --git a/src/surf/network_constant.hpp b/src/surf/network_constant.hpp index 9ff6964354..0096b3d739 100644 --- a/src/surf/network_constant.hpp +++ b/src/surf/network_constant.hpp @@ -30,18 +30,15 @@ public: ~NetworkConstantModel() { } Action *communicate(NetCard *src, NetCard *dst, double size, double rate) override; - double shareResources(double now) override; + double next_occuring_event(double now) override; + bool next_occuring_event_isIdempotent() override {return true;} void updateActionsState(double now, double delta) override; - bool shareResourcesIsIdempotent() override {return true;} Link* createLink(const char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - int initiallyOn, - tmgr_trace_t state_trace, + double bw_initial, tmgr_trace_t bw_trace, + double lat_initial, tmgr_trace_t lat_trace, + int initiallyOn, tmgr_trace_t state_trace, e_surf_link_sharing_policy_t policy, xbt_dict_t properties) override { DIE_IMPOSSIBLE; } void addTraces() override { DIE_IMPOSSIBLE; } diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 45ca1efb3b..4489f8a3ec 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -158,7 +158,7 @@ double NetworkModel::bandwidthConstraint(double rate, double /*bound*/, double / return rate; } -double NetworkModel::shareResourcesFull(double now) +double NetworkModel::next_occuring_event_full(double now) { NetworkAction *action = NULL; ActionList *runningActions = surf_network_model->getRunningActionSet(); diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index cba38923fb..2b94aaf9ec 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -155,7 +155,7 @@ public: * @return The new bandwidth. */ virtual double bandwidthConstraint(double rate, double bound, double size); - double shareResourcesFull(double now); + double next_occuring_event_full(double now) override; }; /************ diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 2143f2c986..0ffb5dff2a 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -301,9 +301,9 @@ Action *NetworkNS3Model::communicate(NetCard *src, NetCard *dst, return (surf_action_t) action; } -double NetworkNS3Model::shareResources(double now) +double NetworkNS3Model::next_occuring_event(double now) { - XBT_DEBUG("ns3_share_resources"); + XBT_DEBUG("ns3_next_occuring_event"); //get the first relevant value from the running_actions list if (!getRunningActionSet()->size() || now == 0.0) diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index bbcbb1c294..0fbed87b02 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -53,12 +53,11 @@ public: e_surf_link_sharing_policy_t policy, xbt_dict_t properties); xbt_dynar_t getRoute(NetCard *src, NetCard *dst); - Action *communicate(NetCard *src, NetCard *dst, - double size, double rate); - double shareResources(double now); - void updateActionsState(double now, double delta); - void addTraces(){DIE_IMPOSSIBLE;} - bool shareResourcesIsIdempotent() {return false;} + Action *communicate(NetCard *src, NetCard *dst, double size, double rate); + double next_occuring_event(double now) override; + void updateActionsState(double now, double delta) override; + void addTraces() override {DIE_IMPOSSIBLE;} + bool next_occuring_event_isIdempotent() {return false;} }; /************ diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 60ec6c693d..a7438dae3e 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -83,7 +83,7 @@ public: xbt_dict_t properties, const char *attach) = 0; - bool shareResourcesIsIdempotent() {return true;} + bool next_occuring_event_isIdempotent() {return true;} xbt_dynar_t p_storageList; }; diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index c89ecfe88a..061023ed5c 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -114,7 +114,7 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id, return storage; } -double StorageN11Model::shareResources(double /*now*/) +double StorageN11Model::next_occuring_event(double /*now*/) { XBT_DEBUG("storage_share_resources"); unsigned int i, j; diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index ec2c3ae6ae..e27a296b58 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -32,9 +32,9 @@ public: ~StorageN11Model(); Storage *createStorage(const char* id, const char* type_id, const char* content_name, const char* content_type, xbt_dict_t properties, const char* attach); - void addTraces(){DIE_IMPOSSIBLE;} - double shareResources(double now); - void updateActionsState(double now, double delta); + void addTraces() override {DIE_IMPOSSIBLE;} + double next_occuring_event(double now) override; + void updateActionsState(double now, double delta) override; }; /************ diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index b6a24beaf8..08e1e516ff 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -56,7 +56,7 @@ void surf_presolve(void) double surf_solve(double max_date) { - double surf_min = -1.0; /* duration */ + double time_delta = -1.0; /* duration */ double next_event_date = -1.0; double model_next_action_end = -1.0; double value = -1.0; @@ -68,24 +68,26 @@ double surf_solve(double max_date) if(!host_that_restart) host_that_restart = xbt_dynar_new(sizeof(char*), NULL); - if (max_date > 0.0 && max_date != NOW) { - surf_min = max_date - NOW; + if (max_date > 0.0) { + xbt_assert(max_date > NOW,"You asked to simulate up to %f, but that's in the past already", max_date); + + time_delta = max_date - NOW; } /* Physical models MUST be resolved first */ XBT_DEBUG("Looking for next event in physical models"); - double next_event_phy = surf_host_model->shareResources(NOW); - if ((surf_min < 0.0 || next_event_phy < surf_min) && next_event_phy >= 0.0) { - surf_min = next_event_phy; + double next_event_phy = surf_host_model->next_occuring_event(NOW); + if ((time_delta < 0.0 || next_event_phy < time_delta) && next_event_phy >= 0.0) { + time_delta = next_event_phy; } if (surf_vm_model != NULL) { XBT_DEBUG("Looking for next event in virtual models"); - double next_event_virt = surf_vm_model->shareResources(NOW); - if ((surf_min < 0.0 || next_event_virt < surf_min) && next_event_virt >= 0.0) - surf_min = next_event_virt; + double next_event_virt = surf_vm_model->next_occuring_event(NOW); + if ((time_delta < 0.0 || next_event_virt < time_delta) && next_event_virt >= 0.0) + time_delta = next_event_virt; } - XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", surf_min); + XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta); XBT_DEBUG("Looking for next trace event"); @@ -93,20 +95,20 @@ double surf_solve(double max_date) next_event_date = future_evt_set->next_date(); XBT_DEBUG("Next TRACE event: %f", next_event_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); + if(! surf_network_model->next_occuring_event_isIdempotent()){ // NS3, I see you + if (next_event_date!=-1.0 && time_delta!=-1.0) { + time_delta = MIN(next_event_date - NOW, time_delta); } else { - surf_min = MAX(next_event_date - NOW, surf_min); // Get the positive component + time_delta = MAX(next_event_date - NOW, time_delta); // Get the positive component } - XBT_DEBUG("Run the NS3 network at most %fs", surf_min); + XBT_DEBUG("Run the NS3 network at most %fs", time_delta); // run until min or next flow - model_next_action_end = surf_network_model->shareResources(surf_min); + model_next_action_end = surf_network_model->next_occuring_event(time_delta); XBT_DEBUG("Min for network : %f", model_next_action_end); if(model_next_action_end>=0.0) - surf_min = model_next_action_end; + time_delta = model_next_action_end; } if (next_event_date < 0.0) { @@ -114,15 +116,15 @@ double surf_solve(double max_date) break; } - if ((surf_min == -1.0) || (next_event_date > NOW + surf_min)) + if ((time_delta == -1.0) || (next_event_date > NOW + time_delta)) break; // next event occurs after the next resource change, bail out - XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", surf_min, NOW, next_event_date); + XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date); while ((event = future_evt_set->pop_leq(next_event_date, &value, &resource))) { if (resource->isUsed() || xbt_dict_get_or_null(watched_hosts_lib, resource->getName())) { - surf_min = next_event_date - NOW; - XBT_DEBUG("This event will modify model state. Next event set to %f", surf_min); + time_delta = next_event_date - NOW; + XBT_DEBUG("This event will modify model state. Next event set to %f", time_delta); } // 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; @@ -138,24 +140,24 @@ double surf_solve(double max_date) /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0. * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0. * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */ - if (surf_min == -1.0) { + if (time_delta == -1.0) { XBT_DEBUG("No next event at all. Bail out now."); return -1.0; } - XBT_DEBUG("Duration set to %f", surf_min); + XBT_DEBUG("Duration set to %f", time_delta); // Bump the time: jump into the future - NOW = NOW + surf_min; + NOW = NOW + time_delta; // Inform the models of the date change xbt_dynar_foreach(all_existing_models, iter, model) { - model->updateActionsState(NOW, surf_min); + model->updateActionsState(NOW, time_delta); } TRACE_paje_dump_buffer (0); - return surf_min; + return time_delta; } /********* diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index ed6066350f..fabd2d8ce2 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -412,18 +412,18 @@ Model::~Model(){ delete p_doneActionSet; } -double Model::shareResources(double now) +double Model::next_occuring_event(double now) { //FIXME: set the good function once and for all if (p_updateMechanism == UM_LAZY) - return shareResourcesLazy(now); + return next_occuring_event_lazy(now); else if (p_updateMechanism == UM_FULL) - return shareResourcesFull(now); + return next_occuring_event_full(now); else xbt_die("Invalid cpu update mechanism!"); } -double Model::shareResourcesLazy(double now) +double Model::next_occuring_event_lazy(double now) { Action *action = NULL; double min = -1; @@ -500,7 +500,7 @@ double Model::shareResourcesLazy(double now) return min; } -double Model::shareResourcesFull(double /*now*/) { +double Model::next_occuring_event_full(double /*now*/) { THROW_UNIMPLEMENTED; } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index aff65e2da5..d660a8139e 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -312,12 +312,11 @@ public: * @param now The current time of the simulation * @return The delta of time till the next action will finish */ - virtual double shareResources(double now); - virtual double shareResourcesLazy(double now); - virtual double shareResourcesFull(double now); + virtual double next_occuring_event(double now); + virtual double next_occuring_event_lazy(double now); + virtual double next_occuring_event_full(double now); double shareResourcesMaxMin(ActionList* running_actions, - lmm_system_t sys, - void (*solve) (lmm_system_t)); + lmm_system_t sys, void (*solve) (lmm_system_t)); /** * @brief Update action to the current time @@ -334,7 +333,7 @@ public: * 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; + virtual bool next_occuring_event_isIdempotent()=0; protected: ActionLmmListPtr p_modifiedSet; diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 35b7b7bf4a..9edc53ab00 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -49,7 +49,7 @@ VirtualMachine *VMHL13Model::createVM(const char *name, sg_host_t host_PM) // const double virt_overhead = 0.95; const double virt_overhead = 1; -double VMHL13Model::shareResources(double now) +double VMHL13Model::next_occuring_event(double now) { /* TODO: update action's cost with the total cost of processes on the VM. */ @@ -101,8 +101,8 @@ double VMHL13Model::shareResources(double now) /* 2. Calculate resource share at the virtual machine layer. */ adjustWeightOfDummyCpuActions(); - double min_by_cpu = surf_cpu_model_vm->shareResources(now); - double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1; + double min_by_cpu = surf_cpu_model_vm->next_occuring_event(now); + double min_by_net = surf_network_model->next_occuring_event_isIdempotent() ? surf_network_model->next_occuring_event(now) : -1; // Fixme: take storage into account once it's implemented double min_by_sto = -1; diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index 6b0d8b2376..7b66c2a01a 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -34,7 +34,7 @@ public: ~VMHL13Model(){}; VirtualMachine *createVM(const char *name, sg_host_t host_PM) override; - double shareResources(double now) override; + double next_occuring_event(double now) override; void adjustWeightOfDummyCpuActions() override {}; void updateActionsState(double /*now*/, double /*delta*/) override; }; -- 2.20.1