From: Frederic Suter Date: Sat, 16 Feb 2019 20:49:06 +0000 (+0100) Subject: Methods and renaming in simix::Global X-Git-Tag: v3_22~319 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/002c591623abdaa8c94a3b434a2f179c35d29cb9 Methods and renaming in simix::Global + s/process/actors/ + empty_trash and process_runall should be here --- diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index 2682e62941..364b82226e 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -176,13 +176,13 @@ void SwappedContextFactory::run_all() SwappedContext* context = static_cast(process->context_); context->resume(); }, - simix_global->process_to_run); + simix_global->actors_to_run); } else { // sequential execution - if (simix_global->process_to_run.empty()) + if (simix_global->actors_to_run.empty()) return; /* maestro is already saved in the first slot of workers_context_ */ - smx_actor_t first_actor = simix_global->process_to_run.front(); + smx_actor_t first_actor = simix_global->actors_to_run.front(); process_index_ = 1; /* execute the first actor; it will chain to the others when using suspend() */ static_cast(first_actor->context_)->resume(); @@ -251,10 +251,10 @@ void SwappedContext::suspend() unsigned long int i = factory_->process_index_; factory_->process_index_++; - if (i < simix_global->process_to_run.size()) { + if (i < simix_global->actors_to_run.size()) { /* Actually swap into the next actor directly without transiting to maestro */ XBT_DEBUG("Run next actor"); - next_context = static_cast(simix_global->process_to_run[i]->context_); + next_context = static_cast(simix_global->actors_to_run[i]->context_); } else { /* all processes were run, actually return to maestro */ XBT_DEBUG("No more actors to run"); diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 171e32e62e..cb9cab4e81 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -182,7 +182,7 @@ void ThreadContext::attach_stop() void SerialThreadContext::run_all() { - for (smx_actor_t const& actor : simix_global->process_to_run) { + for (smx_actor_t const& actor : simix_global->actors_to_run) { XBT_DEBUG("Handling %p", actor); ThreadContext* context = static_cast(actor->context_); context->release(); @@ -207,9 +207,9 @@ void ParallelThreadContext::finalize() void ParallelThreadContext::run_all() { - for (smx_actor_t const& actor : simix_global->process_to_run) + for (smx_actor_t const& actor : simix_global->actors_to_run) static_cast(actor->context_)->release(); - for (smx_actor_t const& actor : simix_global->process_to_run) + for (smx_actor_t const& actor : simix_global->actors_to_run) static_cast(actor->context_)->wait(); } diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index bbc1d548ca..162fd84426 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -39,9 +39,9 @@ void wait_for_requests() #if SIMGRID_HAVE_MC xbt_assert(mc_model_checker == nullptr, "This must be called from the client"); #endif - while (not simix_global->process_to_run.empty()) { - SIMIX_process_runall(); - for (smx_actor_t const& process : simix_global->process_that_ran) { + while (not simix_global->actors_to_run.empty()) { + simix_global->run_all_actors(); + for (smx_actor_t const& process : simix_global->actors_that_ran) { smx_simcall_t req = &process->simcall; if (req->call != SIMCALL_NONE && not simgrid::mc::request_is_visible(req)) SIMIX_simcall_handle(req, 0); diff --git a/src/mc/mc_smx.hpp b/src/mc/mc_smx.hpp index 8e2bb3675b..3c7165d6d4 100644 --- a/src/mc/mc_smx.hpp +++ b/src/mc/mc_smx.hpp @@ -18,7 +18,7 @@ * (copy of `simix_global->process_list`); * * - `model_checker->process.smx_old_process_infos` - * (copy of `simix_global->process_to_destroy`); + * (copy of `simix_global->actors_to_destroy`); * * - `model_checker->hostnames`. * diff --git a/src/mc/remote/RemoteClient.hpp b/src/mc/remote/RemoteClient.hpp index ca36ebd958..d2c84c41b8 100644 --- a/src/mc/remote/RemoteClient.hpp +++ b/src/mc/remote/RemoteClient.hpp @@ -223,7 +223,7 @@ public: */ std::vector smx_actors_infos; - /** Copy of `simix_global->process_to_destroy` + /** Copy of `simix_global->actors_to_destroy` * * See mc_smx.c. */ diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 4fc435d496..2fb512e81a 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -67,31 +67,13 @@ void SIMIX_process_cleanup(smx_actor_t process) #if SIMGRID_HAVE_MC xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, process); #endif - simix_global->process_to_destroy.push_back(*process); + simix_global->actors_to_destroy.push_back(*process); } process->context_->iwannadie = false; simix_global->mutex.unlock(); } -/** - * Garbage collection - * - * Should be called some time to time to free the memory allocated for processes that have finished (or killed). - */ -void SIMIX_process_empty_trash() -{ - while (not simix_global->process_to_destroy.empty()) { - smx_actor_t process = &simix_global->process_to_destroy.front(); - simix_global->process_to_destroy.pop_front(); - XBT_DEBUG("Getting rid of %p",process); - intrusive_ptr_release(process); - } -#if SIMGRID_HAVE_MC - xbt_dynar_reset(simix_global->dead_actors_vector); -#endif -} - namespace simgrid { namespace kernel { namespace actor { @@ -169,11 +151,11 @@ void ActorImpl::kill(smx_actor_t actor) actor->exit(); - if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), actor) == - end(simix_global->process_to_run) && + if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) == + end(simix_global->actors_to_run) && actor != this) { XBT_DEBUG("Inserting %s in the to_run list", actor->get_cname()); - simix_global->process_to_run.push_back(actor); + simix_global->actors_to_run.push_back(actor); } } @@ -327,11 +309,11 @@ void ActorImpl::throw_exception(std::exception_ptr e) boost::dynamic_pointer_cast(waiting_synchro); if (sleep != nullptr) { SIMIX_process_sleep_destroy(waiting_synchro); - if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), this) == - end(simix_global->process_to_run) && + if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) == + end(simix_global->actors_to_run) && this != SIMIX_process_self()) { XBT_DEBUG("Inserting [%p] %s in the to_run list", this, get_cname()); - simix_global->process_to_run.push_back(this); + simix_global->actors_to_run.push_back(this); } } @@ -394,7 +376,7 @@ ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, /* Now insert it in the global process list and in the process to run list */ simix_global->process_list[actor->pid_] = actor; XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname()); - simix_global->process_to_run.push_back(actor); + simix_global->actors_to_run.push_back(actor); intrusive_ptr_add_ref(actor); /* The on_creation() signal must be delayed until there, where the pid and everything is set */ @@ -459,7 +441,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn /* Now insert it in the global process list and in the process to run list */ simix_global->process_list[actor->pid_] = actor; XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname()); - simix_global->process_to_run.push_back(actor); + simix_global->actors_to_run.push_back(actor); intrusive_ptr_add_ref(actor); auto* context = dynamic_cast(actor->context_); @@ -483,22 +465,6 @@ void SIMIX_process_detach() context->attach_stop(); } -/** - * @brief Executes the processes from simix_global->process_to_run. - * - * The processes of simix_global->process_to_run are run (in parallel if - * possible). On exit, simix_global->process_to_run is empty, and - * simix_global->process_that_ran contains the list of processes that just ran. - * The two lists are swapped so, be careful when using them before and after a - * call to this function. - */ -void SIMIX_process_runall() -{ - SIMIX_context_runall(); - - simix_global->process_to_run.swap(simix_global->process_that_ran); - simix_global->process_to_run.clear(); -} /** @deprecated When this function gets removed, also remove the xbt_ex class, that is only there to help users to * transition */ @@ -528,11 +494,11 @@ void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const c boost::dynamic_pointer_cast(actor->waiting_synchro); if (sleep != nullptr) { SIMIX_process_sleep_destroy(actor->waiting_synchro); - if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), actor) == - end(simix_global->process_to_run) && + if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) == + end(simix_global->actors_to_run) && actor != SIMIX_process_self()) { XBT_DEBUG("Inserting [%p] %s in the to_run list", actor, actor->get_cname()); - simix_global->process_to_run.push_back(actor); + simix_global->actors_to_run.push_back(actor); } } @@ -688,7 +654,7 @@ void SIMIX_process_yield(smx_actor_t self) */ const std::vector& simgrid::simix::process_get_runnable() { - return simix_global->process_to_run; + return simix_global->actors_to_run; } /** @brief Returns the process from PID. */ diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 684b322919..011afe7de2 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -31,7 +31,7 @@ public: void set_auto_restart(bool autorestart) { auto_restart_ = autorestart; } void set_kill_time(double kill_time); boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */ - boost::intrusive::list_member_hook<> smx_destroy_list_hook; /* simix_global->process_to_destroy */ + boost::intrusive::list_member_hook<> smx_destroy_list_hook; /* simix_global->actors_to_destroy */ boost::intrusive::list_member_hook<> smx_synchro_hook; /* {mutex,cond,sem}->sleeping */ aid_t pid_ = 0; @@ -162,9 +162,7 @@ XBT_PUBLIC void create_maestro(std::function code); typedef simgrid::kernel::actor::ActorImpl* smx_actor_t; -XBT_PRIVATE void SIMIX_process_runall(); XBT_PRIVATE void SIMIX_process_cleanup(smx_actor_t arg); -XBT_PRIVATE void SIMIX_process_empty_trash(); XBT_PRIVATE void SIMIX_process_yield(smx_actor_t self); extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor); diff --git a/src/simix/popping.cpp b/src/simix/popping.cpp index e353c11375..70d34c7f44 100644 --- a/src/simix/popping.cpp +++ b/src/simix/popping.cpp @@ -16,11 +16,11 @@ void SIMIX_simcall_answer(smx_simcall_t simcall) simcall->issuer->simcall.call = SIMCALL_NONE; #if 0 /* This check should be useless and slows everyone. Reactivate if you see something weird in process scheduling. */ - if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), simcall->issuer) != - end(simix_global->process_to_run)) + if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), simcall->issuer) != + end(simix_global->actors_to_run)) DIE_IMPOSSIBLE; #endif - simix_global->process_to_run.push_back(simcall->issuer); + simix_global->actors_to_run.push_back(simcall->issuer); } } diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index cb24df2b63..ff85b0e7c1 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -147,6 +147,33 @@ double SIMIX_timer_next() namespace simgrid { namespace simix { +void Global::empty_trash() +{ + while (not actors_to_destroy.empty()) { + smx_actor_t actor = &actors_to_destroy.front(); + actors_to_destroy.pop_front(); + XBT_DEBUG("Getting rid of %p", actor); + intrusive_ptr_release(actor); + } +#if SIMGRID_HAVE_MC + xbt_dynar_reset(simix_global->dead_actors_vector); +#endif +} +/** + * @brief Executes the actors in simix_global->actors_to_run. + * + * The actors in simix_global->actors_to_run are run (in parallel if possible). On exit, simix_global->actors_to_run + * is empty, and simix_global->actors_that_ran contains the list of actors that just ran. + * The two lists are swapped so, be careful when using them before and after a call to this function. + */ +void Global::run_all_actors() +{ + SIMIX_context_runall(); + + simix_global->actors_to_run.swap(simix_global->actors_that_ran); + simix_global->actors_to_run.clear(); +} + simgrid::config::Flag breakpoint{"simix/breakpoint", "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0}; } @@ -221,7 +248,7 @@ void SIMIX_clean() smx_cleaned = 1; XBT_DEBUG("SIMIX_clean called. Simulation's over."); - if (not simix_global->process_to_run.empty() && SIMIX_get_clock() <= 0.0) { + if (not simix_global->actors_to_run.empty() && SIMIX_get_clock() <= 0.0) { XBT_CRITICAL(" "); XBT_CRITICAL("The time is still 0, and you still have processes ready to run."); XBT_CRITICAL("It seems that you forgot to run the simulation that you setup."); @@ -242,7 +269,7 @@ void SIMIX_clean() /* Kill all processes (but maestro) */ simix_global->maestro_process->kill_all(); SIMIX_context_runall(); - SIMIX_process_empty_trash(); + simix_global->empty_trash(); /* Exit the SIMIX network module */ SIMIX_mailbox_exit(); @@ -252,9 +279,9 @@ void SIMIX_clean() simix_timers.pop(); } /* Free the remaining data structures */ - simix_global->process_to_run.clear(); - simix_global->process_that_ran.clear(); - simix_global->process_to_destroy.clear(); + simix_global->actors_to_run.clear(); + simix_global->actors_that_ran.clear(); + simix_global->actors_to_destroy.clear(); simix_global->process_list.clear(); #if SIMGRID_HAVE_MC @@ -319,8 +346,7 @@ static bool SIMIX_execute_timers() bool result = false; while (not simix_timers.empty() && SIMIX_get_clock() >= simix_timers.top().first) { result = true; - // FIXME: make the timers being real callbacks - // (i.e. provide dispatchers that read and expand the args) + // FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args) smx_timer_t timer = simix_timers.top().second; simix_timers.pop(); try { @@ -373,7 +399,7 @@ void SIMIX_run() double time = 0; do { - XBT_DEBUG("New Schedule Round; size(queue)=%zu", simix_global->process_to_run.size()); + XBT_DEBUG("New Schedule Round; size(queue)=%zu", simix_global->actors_to_run.size()); if (simgrid::simix::breakpoint >= 0.0 && surf_get_clock() >= simgrid::simix::breakpoint) { XBT_DEBUG("Breakpoint reached (%g)", simgrid::simix::breakpoint.get()); @@ -387,11 +413,11 @@ void SIMIX_run() SIMIX_execute_tasks(); - while (not simix_global->process_to_run.empty()) { - XBT_DEBUG("New Sub-Schedule Round; size(queue)=%zu", simix_global->process_to_run.size()); + while (not simix_global->actors_to_run.empty()) { + XBT_DEBUG("New Sub-Schedule Round; size(queue)=%zu", simix_global->actors_to_run.size()); /* Run all processes that are ready to run, possibly in parallel */ - SIMIX_process_runall(); + simix_global->run_all_actors(); /* answer sequentially and in a fixed arbitrary order all the simcalls that were issued during that sub-round */ @@ -399,21 +425,21 @@ void SIMIX_run() /* Here, the order is ok because: * - * Short proof: only maestro adds stuff to the process_to_run array, so the execution order of user contexts do + * Short proof: only maestro adds stuff to the actors_to_run array, so the execution order of user contexts do * not impact its order. * * Long proof: processes remain sorted through an arbitrary (implicit, complex but fixed) order in all cases. * * - if there is no kill during the simulation, processes remain sorted according by their PID. * Rationale: This can be proved inductively. - * Assume that process_to_run is sorted at a beginning of one round (it is at round 0: the deployment file + * Assume that actors_to_run is sorted at a beginning of one round (it is at round 0: the deployment file * is parsed linearly). * Let's show that it is still so at the end of this round. * - if a process is added when being created, that's from maestro. It can be either at startup * time (and then in PID order), or in response to a process_create simcall. Since simcalls are handled * in arbitrary order (inductive hypothesis), we are fine. * - If a process is added because it's getting killed, its subsequent actions shouldn't matter - * - If a process gets added to process_to_run because one of their blocking action constituting the meat + * - If a process gets added to actors_to_run because one of their blocking action constituting the meat * of a simcall terminates, we're still good. Proof: * - You are added from SIMIX_simcall_answer() only. When this function is called depends on the resource * kind (network, cpu, disk, whatever), but the same arguments hold. Let's take communications as an @@ -439,7 +465,7 @@ void SIMIX_run() * and the argument is very similar to the previous one. * So, in any case, the orders of calls to SIMIX_comm_finish() do not depend on the order in which user * processes are executed. - * So, in any cases, the orders of processes within process_to_run do not depend on the order in which + * So, in any cases, the orders of processes within actors_to_run do not depend on the order in which * user processes were executed previously. * So, if there is no killing in the simulation, the simulation reproducibility is not jeopardized. * - If there is some process killings, the order is changed by this decision that comes from user-land @@ -449,13 +475,13 @@ void SIMIX_run() * * So science works, bitches [http://xkcd.com/54/]. * - * We could sort the process_that_ran array completely so that we can describe the order in which simcalls are + * We could sort the actors_that_ran array completely so that we can describe the order in which simcalls are * handled (like "according to the PID of issuer"), but it's not mandatory (order is fixed already even if * unfriendly). * That would thus be a pure waste of time. */ - for (smx_actor_t const& process : simix_global->process_that_ran) { + for (smx_actor_t const& process : simix_global->actors_that_ran) { if (process->simcall.call != SIMCALL_NONE) { SIMIX_simcall_handle(&process->simcall, 0); } @@ -494,13 +520,13 @@ void SIMIX_run() SIMIX_wake_processes(); } while (again); - /* Clean processes to destroy */ - SIMIX_process_empty_trash(); + /* Clean actors to destroy */ + simix_global->empty_trash(); XBT_DEBUG("### time %f, #processes %zu, #to_run %zu", time, simix_global->process_list.size(), - simix_global->process_to_run.size()); + simix_global->actors_to_run.size()); - } while (time > -1.0 || not simix_global->process_to_run.empty()); + } while (time > -1.0 || not simix_global->actors_to_run.empty()); if (not simix_global->process_list.empty()) { diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp index f22840caaf..9bc917e7ee 100644 --- a/src/simix/smx_private.hpp +++ b/src/simix/smx_private.hpp @@ -24,16 +24,24 @@ class Global { friend XBT_PUBLIC bool simgrid::s4u::this_actor::is_maestro(); public: + /** + * Garbage collection + * + * Should be called some time to time to free the memory allocated for actors that have finished (or killed). + */ + void empty_trash(); + void run_all_actors(); + smx_context_factory_t context_factory = nullptr; - std::vector process_to_run; - std::vector process_that_ran; + std::vector actors_to_run; + std::vector actors_that_ran; std::map process_list; boost::intrusive::list, &kernel::actor::ActorImpl::smx_destroy_list_hook>> - process_to_destroy; + actors_to_destroy; #if SIMGRID_HAVE_MC - /* MCer cannot read members process_list and process_to_destroy above in the remote process, so we copy the info it + /* MCer cannot read members process_list and actors_to_destroy above in the remote process, so we copy the info it * needs in a dynar. * FIXME: This is supposed to be a temporary hack. * A better solution would be to change the split between MCer and MCed, where the responsibility