From bc32dc8200e58f87951a43bf5ba56bf116f08e62 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Tue, 9 Nov 2021 09:45:43 +0100 Subject: [PATCH] move surf_presolve, surf_solve, and surf_get_clock to EngineImpl --- MANIFEST.in | 2 - doc/doxygen/module-surf.doc | 4 +- .../platform-failures/platform-failures.tesh | 2 +- src/include/surf/surf.hpp | 42 ----- src/kernel/EngineImpl.cpp | 138 +++++++++++++++- src/kernel/EngineImpl.hpp | 18 +++ src/kernel/resource/Action.cpp | 14 +- src/kernel/resource/VirtualMachineImpl.cpp | 2 +- src/s4u/s4u_Engine.cpp | 3 +- src/simdag/sd_global.cpp | 15 +- src/simdag/sd_task.cpp | 2 +- src/simdag/simdag_private.hpp | 1 - src/surf/LinkImpl.cpp | 7 +- src/surf/cpu_cas01.cpp | 3 +- src/surf/cpu_ti.cpp | 11 +- src/surf/host_clm03.cpp | 2 +- src/surf/network_cm02.cpp | 1 - src/surf/network_ns3.cpp | 13 +- src/surf/ptask_L07.hpp | 4 +- src/surf/sg_platf.cpp | 1 - src/surf/surf_c_bindings.cpp | 147 ------------------ src/surf/surf_interface.cpp | 8 - src/surf/xml/platf.hpp | 1 + src/surf/xml/surfxml_parseplatf.cpp | 1 - teshsuite/surf/surf_usage/surf_usage.cpp | 6 +- teshsuite/surf/surf_usage2/surf_usage2.cpp | 5 +- tools/cmake/DefinePackages.cmake | 2 - 27 files changed, 198 insertions(+), 257 deletions(-) delete mode 100644 src/include/surf/surf.hpp delete mode 100644 src/surf/surf_c_bindings.cpp diff --git a/MANIFEST.in b/MANIFEST.in index 0b79ccca77..20a36144d5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2193,7 +2193,6 @@ include src/include/catch.hpp include src/include/mc/datatypes.h include src/include/mc/mc.h include src/include/simgrid/sg_config.hpp -include src/include/surf/surf.hpp include src/include/xbt/coverage.h include src/include/xbt/mmalloc.h include src/include/xbt/parmap.hpp @@ -2665,7 +2664,6 @@ include src/surf/ns3/ns3_simulator.hpp include src/surf/ptask_L07.cpp include src/surf/ptask_L07.hpp include src/surf/sg_platf.cpp -include src/surf/surf_c_bindings.cpp include src/surf/surf_interface.cpp include src/surf/surf_interface.hpp include src/surf/surf_private.hpp diff --git a/doc/doxygen/module-surf.doc b/doc/doxygen/module-surf.doc index 5482451464..1d4aad03fb 100644 --- a/doc/doxygen/module-surf.doc +++ b/doc/doxygen/module-surf.doc @@ -66,11 +66,11 @@ a new action that represents the task you have just created. To execute the actions created with @a execute(), @a communicate() or @a execute_parallel_task(), call - surf_solve(). The function surf_solve() is where the simulation takes place. It returns the + EngineImpl::solve(). This function is where the simulation takes place. It returns the time elapsed to execute the actions. You can know what actions have changed their state thanks to the states sets. For example, if your want to know what actions are finished, extract them from @a surf_host_model->common_public->states.done_action_set. - Depending on these results, you can schedule other tasks and call surf_solve() again. + Depending on these results, you can schedule other tasks and call solve() again. Have a look at the implementation of @ref MSG_API "MSG" and @ref SD_API "Simdag" to see how these module interact with SURF. But if you want to create a new API on top of SURF, diff --git a/examples/c/platform-failures/platform-failures.tesh b/examples/c/platform-failures/platform-failures.tesh index 30cefae040..b8be3a441f 100644 --- a/examples/c/platform-failures/platform-failures.tesh +++ b/examples/c/platform-failures/platform-failures.tesh @@ -211,7 +211,7 @@ $ ${bindir:=.}/c-platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${p > [ 43.774742] (0:maestro@) Simulation time 43.7747 p NOT testing the mixture of failures and CpuTI: -p This test leads to a deadlock because of a bug somewhere in surf_solve. +p This test leads to a deadlock because of a bug somewhere in EngineImpl::solve. p We should debug this instead of ignoring the issue, but it's utterly p complex with such an integration test. One day, we will setup a set of p unit tests for the surf solver, and such issues will be addressable again. diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp deleted file mode 100644 index 802e69e716..0000000000 --- a/src/include/surf/surf.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef SURF_SURF_H -#define SURF_SURF_H - -#include "simgrid/forward.h" - -/*** SURF Globals **************************/ - -/** @ingroup SURF_simulation - * @brief Finish simulation initialization - * - * This function must be called before the first call to surf_solve() - */ -XBT_PUBLIC void surf_presolve(); - -/** @ingroup SURF_simulation - * @brief Performs a part of the simulation - * @param max_date Maximum date to update the simulation to, or -1 - * @return the elapsed time, or -1.0 if no event could be executed - * - * This function execute all possible events, update the action states and returns the time elapsed. - * When you call execute or communicate on a model, the corresponding actions are not executed immediately but only - * when you call surf_solve. - * Note that the returned elapsed time can be zero. - */ -XBT_PUBLIC double surf_solve(double max_date); - -/** @ingroup SURF_simulation - * @brief Return the current time - * - * Return the current time in millisecond. - */ -XBT_PUBLIC double surf_get_clock(); - -/* surf parse file related (public because called from a test suite) */ -XBT_PUBLIC void parse_platform_file(const std::string& file); - -#endif diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 0d0e039d01..b4492819ab 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -18,7 +18,6 @@ #include "src/smpi/include/smpi_actor.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf.hpp" -#include "surf/surf.hpp" //surf_presolve() and surf_solve() #include "xbt/xbt_modinter.h" /* whether initialization was already done */ #include @@ -30,7 +29,10 @@ #include "src/mc/remote/AppSide.hpp" #endif +double NOW = 0; + XBT_LOG_NEW_DEFAULT_CATEGORY(ker_engine, "Logging specific to Engine (kernel)"); + namespace simgrid { namespace kernel { EngineImpl* EngineImpl::instance_ = nullptr; /* That singleton is awful too. */ @@ -236,7 +238,7 @@ void EngineImpl::initialize(int* argc, char** argv) /* register a function to be called by SURF after the environment creation */ sg_platf_init(); - s4u::Engine::on_platform_created.connect(surf_presolve); + s4u::Engine::on_platform_created.connect([this]() { this->presolve(); }); if (config::get_value("debug/clean-atexit")) atexit(shutdown); @@ -547,6 +549,129 @@ void EngineImpl::display_all_actor_status() const } } +void EngineImpl::presolve() +{ + XBT_DEBUG("Consume all trace events occurring before the starting time."); + double next_event_date; + while ((next_event_date = profile::future_evt_set.next_date()) != -1.0) { + if (next_event_date > NOW) + break; + + double value = -1.0; + resource::Resource* resource = nullptr; + while (auto* event = profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) { + if (value >= 0) + resource->apply_event(event, value); + } + } + + XBT_DEBUG("Set every models in the right state by updating them to 0."); + for (auto const& model : models_) + model->update_actions_state(NOW, 0.0); +} + +double EngineImpl::solve(double max_date) +{ + double time_delta = -1.0; /* duration */ + double value = -1.0; + resource::Resource* resource = nullptr; + + if (max_date != -1.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; + } + + XBT_DEBUG("Looking for next event in all models"); + for (auto model : models_) { + if (not model->next_occurring_event_is_idempotent()) { + continue; + } + double next_event = model->next_occurring_event(NOW); + if ((time_delta < 0.0 || next_event < time_delta) && next_event >= 0.0) { + time_delta = next_event; + } + } + + XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta); + + XBT_DEBUG("Looking for next trace event"); + + while (true) { // Handle next occurring events until none remains + double next_event_date = profile::future_evt_set.next_date(); + XBT_DEBUG("Next TRACE event: %f", next_event_date); + + for (auto model : models_) { + /* Skip all idempotent models, they were already treated above + * NS3 is the one to handled here */ + if (model->next_occurring_event_is_idempotent()) + continue; + + if (next_event_date != -1.0) { + time_delta = std::min(next_event_date - NOW, time_delta); + } else { + time_delta = std::max(next_event_date - NOW, time_delta); // Get the positive component + } + + XBT_DEBUG("Run the NS3 network at most %fs", time_delta); + // run until min or next flow + double model_next_action_end = model->next_occurring_event(time_delta); + + XBT_DEBUG("Min for network : %f", model_next_action_end); + if (model_next_action_end >= 0.0) + time_delta = model_next_action_end; + } + + if (next_event_date < 0.0 || (next_event_date > NOW + time_delta)) { + // next event may have already occurred or will after the next resource change, then bail out + XBT_DEBUG("no next usable TRACE event. Stop searching for it"); + break; + } + + XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date); + + while (auto* event = profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) { + if (resource->is_used() || (watched_hosts().find(resource->get_cname()) != watched_hosts().end())) { + time_delta = next_event_date - NOW; + XBT_DEBUG("This event invalidates the next_occurring_event() computation of models. 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; + 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", resource->get_cname()); + resource->apply_event(event, value); + NOW = round_start; + } + } + + /* 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 (time_delta < 0) { + XBT_DEBUG("No next event at all. Bail out now."); + return -1.0; + } + + XBT_DEBUG("Duration set to %f", time_delta); + + // Bump the time: jump into the future + NOW = NOW + time_delta; + + // Inform the models of the date change + for (auto const& model : models_) + model->update_actions_state(NOW, time_delta); + + s4u::Engine::on_time_advance(time_delta); + + return time_delta; +} + void EngineImpl::run() { if (MC_record_replay_is_active()) { @@ -661,8 +786,8 @@ void EngineImpl::run() time = timer::Timer::next(); if (time > -1.0 || not actor_list_.empty()) { - XBT_DEBUG("Calling surf_solve"); - time = surf_solve(time); + XBT_DEBUG("Calling solve"); + time = solve(time); XBT_DEBUG("Moving time ahead : %g", time); } @@ -705,6 +830,11 @@ void EngineImpl::run() simgrid::s4u::Engine::on_simulation_end(); } + +double EngineImpl::get_clock() +{ + return NOW; +} } // namespace kernel } // namespace simgrid diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index f8f921cebc..451a8ec3df 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -187,8 +187,26 @@ public: void display_all_actor_status() const; void run_all_actors(); + /* @brief Finish simulation initialization + * This function must be called before the first call to solve() + */ + void presolve(); + /** @brief Performs a part of the simulation + * @param max_date Maximum date to update the simulation to, or -1 + * @return the elapsed time, or -1.0 if no event could be executed + * + * This function execute all possible events, update the action states and returns the time elapsed. + * When you call execute or communicate on a model, the corresponding actions are not executed immediately but only + * when you call solve(). + * Note that the returned elapsed time can be zero. + */ + double solve(double max_date); + /** @brief Run the main simulation loop. */ void run(); + + /** @brief Return the current time in milliseconds. */ + static double get_clock(); }; } // namespace kernel diff --git a/src/kernel/resource/Action.cpp b/src/kernel/resource/Action.cpp index 06ef1456f1..006295381e 100644 --- a/src/kernel/resource/Action.cpp +++ b/src/kernel/resource/Action.cpp @@ -5,9 +5,9 @@ #include "simgrid/kernel/resource/Action.hpp" #include "simgrid/kernel/resource/Model.hpp" +#include "src/kernel/EngineImpl.hpp" #include "src/kernel/lmm/maxmin.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" XBT_LOG_NEW_CATEGORY(kernel, "SimGrid internals"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_resource, kernel, "Resources, modeling the platform performance"); @@ -19,7 +19,7 @@ namespace resource { Action::Action(Model* model, double cost, bool failed) : Action(model, cost, failed, nullptr) {} Action::Action(Model* model, double cost, bool failed, lmm::Variable* var) - : remains_(cost), start_time_(surf_get_clock()), cost_(cost), model_(model), variable_(var) + : remains_(cost), start_time_(EngineImpl::get_clock()), cost_(cost), model_(model), variable_(var) { if (failed) state_set_ = model_->get_failed_action_set(); @@ -44,7 +44,7 @@ Action::~Action() void Action::finish(Action::State state) { - finish_time_ = surf_get_clock(); + finish_time_ = EngineImpl::get_clock(); set_remains(0); set_state(state); } @@ -107,7 +107,7 @@ void Action::set_bound(double bound) if (variable_) model_->get_maxmin_system()->update_variable_bound(variable_, bound); - if (model_->is_update_lazy() && get_last_update() != surf_get_clock()) + if (model_->is_update_lazy() && get_last_update() != EngineImpl::get_clock()) model_->get_action_heap().remove(this); XBT_OUT(); } @@ -163,7 +163,7 @@ void Action::suspend() model_->get_action_heap().remove(this); if (state_set_ == model_->get_started_action_set() && sharing_penalty_ > 0) { // If we have a lazy model, we need to update the remaining value accordingly - update_remains_lazy(surf_get_clock()); + update_remains_lazy(EngineImpl::get_clock()); } } suspended_ = SuspendStates::SUSPENDED; @@ -188,7 +188,7 @@ double Action::get_remains() XBT_IN("(%p)", this); /* update remains before returning it */ if (model_->is_update_lazy()) /* update remains before return it */ - update_remains_lazy(surf_get_clock()); + update_remains_lazy(EngineImpl::get_clock()); XBT_OUT(); return remains_; } @@ -206,7 +206,7 @@ void Action::update_remains(double delta) void Action::set_last_update() { - last_update_ = surf_get_clock(); + last_update_ = EngineImpl::get_clock(); } double ActionHeap::top_date() const diff --git a/src/kernel/resource/VirtualMachineImpl.cpp b/src/kernel/resource/VirtualMachineImpl.cpp index d0162ce547..054ac5cbf6 100644 --- a/src/kernel/resource/VirtualMachineImpl.cpp +++ b/src/kernel/resource/VirtualMachineImpl.cpp @@ -160,7 +160,7 @@ double VMModel::next_occurring_event(double now) lmm::System* vcpu_system = cpu->get_model()->get_maxmin_system(); vcpu_system->update_constraint_bound(cpu->get_constraint(), virt_overhead * solved_value); } - /* actual next occurring event is determined by VM CPU model at surf_solve */ + /* actual next occurring event is determined by VM CPU model at EngineImpl::solve */ return -1.0; } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index c4c3b0c8d6..f4531dfd91 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -13,7 +13,6 @@ #include "src/instr/instr_private.hpp" #include "src/kernel/EngineImpl.hpp" #include "src/mc/mc_replay.hpp" -#include "surf/surf.hpp" #include #include @@ -86,7 +85,7 @@ double Engine::get_clock() if (MC_is_active() || MC_record_replay_is_active()) { return MC_process_clock_get(kernel::actor::ActorImpl::self()); } else { - return surf_get_clock(); + return kernel::EngineImpl::get_clock(); } } diff --git a/src/simdag/sd_global.cpp b/src/simdag/sd_global.cpp index fa386cd504..8c7b9f7b73 100644 --- a/src/simdag/sd_global.cpp +++ b/src/simdag/sd_global.cpp @@ -24,7 +24,8 @@ namespace sd { std::set* simulate(double how_long) { XBT_VERB("Run simulation for %f seconds", how_long); - + auto engine = sd_global->engine_->get_impl(); + simgrid::kernel::EngineImpl::get_instance(); sd_global->watch_point_reached = false; sd_global->return_set.clear(); @@ -39,13 +40,13 @@ std::set* simulate(double how_long) not sd_global->watch_point_reached) { XBT_DEBUG("Total time: %f", total_time); - elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long - total_time : -1.0); - XBT_DEBUG("surf_solve() returns %f", elapsed_time); + elapsed_time = engine->solve(how_long > 0 ? simgrid_get_clock() + how_long - total_time : -1.0); + XBT_DEBUG("solve() returns %f", elapsed_time); if (elapsed_time > 0.0) total_time += elapsed_time; /* let's see which tasks are done */ - for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) { + for (auto const& model : engine->get_all_models()) { const simgrid::kernel::resource::Action* action = model->extract_done_action(); while (action != nullptr && action->get_data() != nullptr) { auto* task = static_cast(action->get_data()); @@ -114,7 +115,7 @@ std::set* simulate(double how_long) XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d", elapsed_time, total_time, sd_global->watch_point_reached); - XBT_DEBUG("current time = %f", surf_get_clock()); + XBT_DEBUG("current time = %f", simgrid_get_clock()); return &sd_global->return_set; } @@ -192,7 +193,7 @@ void SD_create_environment(const char* platform_file) jedule_sd_init(); #endif XBT_VERB("Starting simulation..."); - surf_presolve(); /* Takes traces into account */ + sd_global->engine_->get_impl()->presolve(); /* Takes traces into account */ } /** @@ -224,7 +225,7 @@ void SD_simulate_with_update(double how_long, xbt_dynar_t changed_tasks_dynar) /** @brief Returns the current clock, in seconds */ double SD_get_clock() { - return surf_get_clock(); + return simgrid_get_clock(); } /** diff --git a/src/simdag/sd_task.cpp b/src/simdag/sd_task.cpp index a00b21f9c1..4d88fa1f4b 100644 --- a/src/simdag/sd_task.cpp +++ b/src/simdag/sd_task.cpp @@ -296,7 +296,7 @@ void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state) jedule_log_sd_event(task); #endif } else - task->finish_time = surf_get_clock(); + task->finish_time = simgrid_get_clock(); task->surf_action->unref(); task->surf_action = nullptr; task->allocation->clear(); diff --git a/src/simdag/simdag_private.hpp b/src/simdag/simdag_private.hpp index bb06103925..8fcae4558e 100644 --- a/src/simdag/simdag_private.hpp +++ b/src/simdag/simdag_private.hpp @@ -5,7 +5,6 @@ #include "simgrid/s4u/Engine.hpp" #include "simgrid/simdag.h" -#include "surf/surf.hpp" #include #include #include diff --git a/src/surf/LinkImpl.cpp b/src/surf/LinkImpl.cpp index 77246502aa..a5a34ae20e 100644 --- a/src/surf/LinkImpl.cpp +++ b/src/surf/LinkImpl.cpp @@ -3,9 +3,10 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + +#include "src/kernel/EngineImpl.hpp" #include "src/surf/LinkImpl.hpp" -#include "simgrid/s4u/Engine.hpp" -#include "surf/surf.hpp" #include @@ -83,7 +84,7 @@ void LinkImpl::turn_off() s4u::Link::on_state_change(piface_); const kernel::lmm::Element* elem = nullptr; - double now = surf_get_clock(); + double now = EngineImpl::get_clock(); while (const auto* var = get_constraint()->get_variable(&elem)) { Action* action = var->get_id(); if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) { diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 62c30c4939..42fd5c1355 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -12,7 +12,6 @@ #include "src/surf/cpu_cas01.hpp" #include "src/surf/cpu_ti.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cpu_cas, res_cpu, "CPU resource, CAS01 model (used by default)"); @@ -115,7 +114,7 @@ void CpuCas01::apply_event(profile::Event* event, double value) } } else { const lmm::Element* elem = nullptr; - double date = surf_get_clock(); + double date = EngineImpl::get_clock(); get_iface()->turn_off(); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 53103d0c8c..e484442437 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -10,7 +10,6 @@ #include "src/kernel/resource/profile/Event.hpp" #include "src/kernel/resource/profile/Profile.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" #include #include @@ -307,7 +306,7 @@ void CpuTiModel::update_actions_state(double now, double /*delta*/) XBT_DEBUG("Action %p: finish", action); action->finish(Action::State::FINISHED); /* update remaining amount of all actions */ - action->cpu_->update_remaining_amount(surf_get_clock()); + action->cpu_->update_remaining_amount(EngineImpl::get_clock()); } } @@ -350,7 +349,7 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value) XBT_DEBUG("Speed changed in trace! New fixed value: %f", value); /* update remaining of actions and put in modified cpu list */ - update_remaining_amount(surf_get_clock()); + update_remaining_amount(EngineImpl::get_clock()); set_modified(true); @@ -368,7 +367,7 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value) } } else { get_iface()->turn_off(); - double date = surf_get_clock(); + double date = EngineImpl::get_clock(); /* put all action running on cpu to failed */ for (CpuTiAction& action : action_set_) { @@ -454,7 +453,7 @@ bool CpuTi::is_used() const double CpuTi::get_speed_ratio() { - speed_.scale = speed_integrated_trace_->get_power_scale(surf_get_clock()); + speed_.scale = speed_integrated_trace_->get_power_scale(EngineImpl::get_clock()); return CpuImpl::get_speed_ratio(); } @@ -603,7 +602,7 @@ void CpuTiAction::set_sharing_penalty(double sharing_penalty) double CpuTiAction::get_remains() { XBT_IN("(%p)", this); - cpu_->update_remaining_amount(surf_get_clock()); + cpu_->update_remaining_amount(EngineImpl::get_clock()); XBT_OUT(); return get_remains_no_update(); } diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 3a7b01299a..d11eeeab4b 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -39,7 +39,7 @@ namespace resource { double HostCLM03Model::next_occurring_event(double /*now*/) { /* nothing specific to be done here - * surf_solve already calls all the models next_occurring_event properly */ + * EngineImpl::solve already calls all the models next_occurring_event properly */ return -1.0; } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 144058eb23..3dc1bd7d3d 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -12,7 +12,6 @@ #include "src/kernel/resource/profile/Event.hpp" #include "src/surf/network_wifi.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" #include #include diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 4ff24bea16..04adf6d73b 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -37,7 +37,6 @@ #include "src/kernel/EngineImpl.hpp" #include "src/surf/surf_interface.hpp" #include "src/surf/xml/platf_private.hpp" // ClusterCreationArgs -#include "surf/surf.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns-3"); @@ -380,7 +379,7 @@ double NetworkNS3Model::next_occurring_event(double now) XBT_DEBUG("doing a ns3 simulation for a duration of %f", now); ns3_simulator(now); - time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - surf_get_clock(); + time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - EngineImpl::get_clock(); // NS-3 stops as soon as a flow ends, // but it does not process the other flows that may finish at the same (simulated) time. // If another flow ends at the same time, time_to_next_flow_completion = 0 @@ -389,7 +388,7 @@ double NetworkNS3Model::next_occurring_event(double now) XBT_DEBUG("min : %f", now); XBT_DEBUG("ns3 time : %f", ns3::Simulator::Now().GetSeconds()); - XBT_DEBUG("surf time : %f", surf_get_clock()); + XBT_DEBUG("surf time : %f", EngineImpl::get_clock()); XBT_DEBUG("Next completion %f :", time_to_next_flow_completion); return time_to_next_flow_completion; @@ -509,10 +508,10 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s // If there is no other started actions, we need to move NS-3 forward to be sync with SimGrid if (model->get_started_action_set()->size() == 1) { - while (double_positive(surf_get_clock() - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)) { + while (double_positive(EngineImpl::get_clock() - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)) { XBT_DEBUG("Synchronizing NS-3 (time %f) with SimGrid (time %f)", ns3::Simulator::Now().GetSeconds(), - surf_get_clock()); - ns3_simulator(surf_get_clock() - ns3::Simulator::Now().GetSeconds()); + EngineImpl::get_clock()); + ns3_simulator(EngineImpl::get_clock() - ns3::Simulator::Now().GetSeconds()); } } @@ -573,7 +572,7 @@ void ns3_simulator(double maxSeconds) if (maxSeconds > 0.0) // If there is a maximum amount of time to run id = ns3::Simulator::Schedule(ns3::Seconds(maxSeconds), &ns3::Simulator::Stop); - XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, surf_get_clock()); + XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, EngineImpl::get_clock()); ns3::Simulator::Run(); XBT_DEBUG("Simulator stopped at %fs", ns3::Simulator::Now().GetSeconds()); diff --git a/src/surf/ptask_L07.hpp b/src/surf/ptask_L07.hpp index 78dfe83776..7187117ce1 100644 --- a/src/surf/ptask_L07.hpp +++ b/src/surf/ptask_L07.hpp @@ -52,7 +52,7 @@ public: void update_actions_state(double /*now*/, double /*delta*/) override{ /* this action is done by HostL07Model which shares the LMM system with the CPU model * Overriding to an empty function here allows us to handle the Cpu07Model as a regular - * method in surf_presolve */ + * method in EngineImpl::presolve */ }; CpuImpl* create_cpu(s4u::Host* host, const std::vector& speed_per_pstate) override; @@ -72,7 +72,7 @@ public: void update_actions_state(double /*now*/, double /*delta*/) override{ /* this action is done by HostL07Model which shares the LMM system with the CPU model * Overriding to an empty function here allows us to handle the Cpu07Model as a regular - * method in surf_presolve */ + * method in EngineImpl::presolve */ }; HostL07Model* hostModel_; diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 2f89c3aef9..bf52327199 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -25,7 +25,6 @@ #include "src/surf/HostImpl.hpp" #include "src/surf/xml/platf.hpp" #include "src/surf/xml/platf_private.hpp" -#include "surf/surf.hpp" #include #include diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp deleted file mode 100644 index 59fd67e1af..0000000000 --- a/src/surf/surf_c_bindings.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include - -#include "src/instr/instr_private.hpp" -#include "src/kernel/EngineImpl.hpp" -#include "src/kernel/resource/DiskImpl.hpp" -#include "src/kernel/resource/VirtualMachineImpl.hpp" -#include "src/kernel/resource/profile/FutureEvtSet.hpp" -#include "surf/surf.hpp" - -#include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); - -/********* - * TOOLS * - *********/ - -extern double NOW; - -void surf_presolve() -{ - XBT_DEBUG("Consume all trace events occurring before the starting time."); - double next_event_date; - while ((next_event_date = simgrid::kernel::profile::future_evt_set.next_date()) != -1.0) { - if (next_event_date > NOW) - break; - - double value = -1.0; - simgrid::kernel::resource::Resource* resource = nullptr; - while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) { - if (value >= 0) - resource->apply_event(event, value); - } - } - - XBT_DEBUG("Set every models in the right state by updating them to 0."); - for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) - model->update_actions_state(NOW, 0.0); -} - -double surf_solve(double max_date) -{ - double time_delta = -1.0; /* duration */ - double value = -1.0; - simgrid::kernel::resource::Resource* resource = nullptr; - - if (max_date != -1.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; - } - - XBT_DEBUG("Looking for next event in all models"); - auto engine = simgrid::kernel::EngineImpl::get_instance(); - for (auto model : engine->get_all_models()) { - if (not model->next_occurring_event_is_idempotent()) { - continue; - } - double next_event = model->next_occurring_event(NOW); - if ((time_delta < 0.0 || next_event < time_delta) && next_event >= 0.0) { - time_delta = next_event; - } - } - - XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta); - - XBT_DEBUG("Looking for next trace event"); - - while (true) { // Handle next occurring events until none remains - double next_event_date = simgrid::kernel::profile::future_evt_set.next_date(); - XBT_DEBUG("Next TRACE event: %f", next_event_date); - - for (auto model : engine->get_all_models()) { - /* Skip all idempotent models, they were already treated above - * NS3 is the one to handled here */ - if (model->next_occurring_event_is_idempotent()) - continue; - - if (next_event_date != -1.0) { - time_delta = std::min(next_event_date - NOW, time_delta); - } else { - time_delta = std::max(next_event_date - NOW, time_delta); // Get the positive component - } - - XBT_DEBUG("Run the NS3 network at most %fs", time_delta); - // run until min or next flow - double model_next_action_end = model->next_occurring_event(time_delta); - - XBT_DEBUG("Min for network : %f", model_next_action_end); - if (model_next_action_end >= 0.0) - time_delta = model_next_action_end; - } - - if (next_event_date < 0.0 || (next_event_date > NOW + time_delta)) { - // next event may have already occurred or will after the next resource change, then bail out - XBT_DEBUG("no next usable TRACE event. Stop searching for it"); - break; - } - - XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", time_delta, NOW, next_event_date); - - while (auto* event = simgrid::kernel::profile::future_evt_set.pop_leq(next_event_date, &value, &resource)) { - if (resource->is_used() || (watched_hosts().find(resource->get_cname()) != watched_hosts().end())) { - time_delta = next_event_date - NOW; - XBT_DEBUG("This event invalidates the next_occurring_event() computation of models. 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; - 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", resource->get_cname()); - resource->apply_event(event, value); - NOW = round_start; - } - } - - /* 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 (time_delta < 0) { - XBT_DEBUG("No next event at all. Bail out now."); - return -1.0; - } - - XBT_DEBUG("Duration set to %f", time_delta); - - // Bump the time: jump into the future - NOW = NOW + time_delta; - - // Inform the models of the date change - for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) - model->update_actions_state(NOW, time_delta); - - simgrid::s4u::Engine::on_time_advance(time_delta); - - return time_delta; -} diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 06d25b6612..31af4cb116 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -12,7 +12,6 @@ #include "src/kernel/resource/profile/Profile.hpp" #include "src/surf/HostImpl.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" #include #include @@ -98,13 +97,6 @@ const std::vector surf_disk_model_description = { {"default", "Simplistic disk model.", &surf_disk_model_init_default}, }; -double NOW = 0; - -double surf_get_clock() -{ - return NOW; -} - /* returns whether #file_path is an absolute file path. Surprising, isn't it ? */ static bool is_absolute_file_path(const std::string& file_path) { diff --git a/src/surf/xml/platf.hpp b/src/surf/xml/platf.hpp index 262ffe381d..e313880add 100644 --- a/src/surf/xml/platf.hpp +++ b/src/surf/xml/platf.hpp @@ -25,5 +25,6 @@ XBT_PUBLIC double surf_parse_get_double(const std::string& s); XBT_PUBLIC int surf_parse_get_int(const std::string& s); XBT_PUBLIC void surf_parse(); /* Entry-point to the parser */ +XBT_PUBLIC void parse_platform_file(const std::string& file); #endif diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 0992af4de7..eb876f0a85 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -10,7 +10,6 @@ #include "src/surf/surf_interface.hpp" #include "src/surf/xml/platf.hpp" #include "src/surf/xml/platf_private.hpp" -#include "surf/surf.hpp" #include diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 9ec4cd6557..32f8006850 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -9,9 +9,9 @@ #include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object #include "simgrid/s4u/Engine.hpp" #include "simgrid/zone.h" +#include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/CpuImpl.hpp" #include "src/surf/network_interface.hpp" -#include "surf/surf.hpp" #include "xbt/config.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); @@ -69,7 +69,7 @@ int main(int argc, char** argv) /* Let's do something on it */ net_model->communicate(hostA, hostB, 150.0, -1.0); - surf_solve(-1.0); + e.get_impl()->solve(-1.0); do { XBT_INFO("Next Event : %g", simgrid::s4u::Engine::get_clock()); XBT_DEBUG("\t CPU actions"); @@ -106,7 +106,7 @@ int main(int argc, char** argv) action.unref(); } } while ((net_model->get_started_action_set()->size() || cpu_model_pm->get_started_action_set()->size()) && - surf_solve(-1.0) >= 0.0); + e.get_impl()->solve(-1.0) >= 0.0); XBT_DEBUG("Simulation Terminated"); diff --git a/teshsuite/surf/surf_usage2/surf_usage2.cpp b/teshsuite/surf/surf_usage2/surf_usage2.cpp index 9634f4f431..846a2d754d 100644 --- a/teshsuite/surf/surf_usage2/surf_usage2.cpp +++ b/teshsuite/surf/surf_usage2/surf_usage2.cpp @@ -13,7 +13,6 @@ #include "src/kernel/resource/CpuImpl.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" #include "xbt/config.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); @@ -43,7 +42,7 @@ int main(int argc, char** argv) auto net_model = as_zone->get_impl()->get_network_model(); net_model->communicate(hostA, hostB, 150.0, -1.0); - surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ + e.get_impl()->solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { simgrid::kernel::resource::Action* action = nullptr; running = 0; @@ -73,7 +72,7 @@ int main(int argc, char** argv) action = model->extract_done_action(); } } - } while (running && surf_solve(-1.0) >= 0.0); + } while (running && e.get_impl()->solve(-1.0) >= 0.0); XBT_INFO("Simulation Terminated"); return 0; diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 15a8cf1e19..9b8282bada 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -6,7 +6,6 @@ set(EXTRA_DIST src/include/mc/datatypes.h src/include/mc/mc.h src/include/simgrid/sg_config.hpp - src/include/surf/surf.hpp src/include/xbt/coverage.h src/include/xbt/parmap.hpp src/include/xbt/mmalloc.h @@ -359,7 +358,6 @@ set(SURF_SRC src/surf/SplitDuplexLinkImpl.cpp src/surf/network_wifi.cpp src/surf/sg_platf.cpp - src/surf/surf_c_bindings.cpp src/surf/surf_interface.cpp src/surf/xml/platf.hpp src/surf/xml/platf_private.hpp -- 2.20.1