From d4be32492fcb56ad33f704c7e602b5efa48ed9d0 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 14 Aug 2019 00:49:31 +0200 Subject: [PATCH 1/1] small simplifications around simcalls - Use ActivityImpl::register_simcall() where possible - Uniformity in ActivityImpl::post() methods - Rename processes into actors --- src/kernel/activity/CommImpl.cpp | 8 +++--- src/kernel/activity/ConditionVariableImpl.cpp | 5 ++-- src/kernel/activity/ExecImpl.cpp | 5 ++-- src/kernel/activity/IoImpl.cpp | 1 + src/kernel/activity/SemaphoreImpl.cpp | 9 +++---- src/kernel/activity/SleepImpl.cpp | 1 + src/s4u/s4u_Actor.cpp | 7 ++--- src/simix/smx_global.cpp | 26 +++++++++---------- 8 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index b7351de1d8..03c3cbfb25 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -238,7 +238,7 @@ void simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kernel::activity: } simcall_comm_test__set__result(simcall, res); - if (simcall_comm_test__get__result(simcall)) { + if (res) { comm->simcalls_.push_back(simcall); comm->finish(); } else { @@ -564,10 +564,8 @@ void CommImpl::post() /* destroy the surf actions associated with the Simix communication */ cleanupSurf(); - /* if there are simcalls associated with the synchro, then answer them */ - if (not simcalls_.empty()) { - finish(); - } + /* Answer all simcalls associated with the synchro */ + finish(); } void CommImpl::finish() diff --git a/src/kernel/activity/ConditionVariableImpl.cpp b/src/kernel/activity/ConditionVariableImpl.cpp index fd84ce5853..ccaeac9a87 100644 --- a/src/kernel/activity/ConditionVariableImpl.cpp +++ b/src/kernel/activity/ConditionVariableImpl.cpp @@ -99,9 +99,8 @@ void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::Actor } RawImplPtr synchro(new RawImpl()); - (*synchro).set_host(issuer->get_host()).set_timeout(timeout).start(); - synchro->simcalls_.push_front(simcall); - issuer->waiting_synchro = std::move(synchro); + synchro->set_host(issuer->get_host()).set_timeout(timeout).start(); + synchro->register_simcall(simcall); sleeping_.push_back(*simcall->issuer_); } diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index ea1159d295..016f1e7609 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -204,9 +204,8 @@ void ExecImpl::post() timeout_detector_ = nullptr; } - /* If there are simcalls associated with the synchro, then answer them */ - if (not simcalls_.empty()) - finish(); + /* Answer all simcalls associated with the synchro */ + finish(); } void ExecImpl::finish() diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index ba69f5f326..6022c2d9bb 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -75,6 +75,7 @@ void IoImpl::post() } on_completion(*this); + /* Answer all simcalls associated with the synchro */ finish(); } diff --git a/src/kernel/activity/SemaphoreImpl.cpp b/src/kernel/activity/SemaphoreImpl.cpp index 4848f27bf7..2daeba6def 100644 --- a/src/kernel/activity/SemaphoreImpl.cpp +++ b/src/kernel/activity/SemaphoreImpl.cpp @@ -14,14 +14,11 @@ namespace activity { void SemaphoreImpl::acquire(actor::ActorImpl* issuer, double timeout) { - RawImplPtr synchro = nullptr; - XBT_DEBUG("Wait semaphore %p (timeout:%f)", this, timeout); if (value_ <= 0) { - synchro = RawImplPtr(new RawImpl()); - (*synchro).set_host(issuer->get_host()).set_timeout(timeout).start(); - synchro->simcalls_.push_front(&issuer->simcall); - issuer->waiting_synchro = synchro; + RawImplPtr synchro = RawImplPtr(new RawImpl()); + synchro->set_host(issuer->get_host()).set_timeout(timeout).start(); + synchro->register_simcall(&issuer->simcall); sleeping_.push_back(*issuer); } else { value_--; diff --git a/src/kernel/activity/SleepImpl.cpp b/src/kernel/activity/SleepImpl.cpp index 09f5e1408c..e20cdf7d66 100644 --- a/src/kernel/activity/SleepImpl.cpp +++ b/src/kernel/activity/SleepImpl.cpp @@ -48,6 +48,7 @@ void SleepImpl::post() } else if (surf_action_->get_state() == resource::Action::State::FINISHED) { state_ = SIMIX_DONE; } + /* Answer all simcalls associated with the synchro */ finish(); } diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 4239ef2e40..1840dfe657 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -103,8 +103,7 @@ void Actor::join(double timeout) issuer->simcall_answer(); } else { smx_activity_t sync = issuer->join(target, timeout); - sync->simcalls_.push_back(&issuer->simcall); - issuer->waiting_synchro = sync; + sync->register_simcall(&issuer->simcall); } }); } @@ -315,9 +314,7 @@ void sleep_for(double duration) return; } smx_activity_t sync = issuer->sleep(duration); - sync->simcalls_.push_back(&issuer->simcall); - issuer->waiting_synchro = sync; - + sync->register_simcall(&issuer->simcall); }); Actor::on_wake_up(*issuer->ciface()); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 25ce05455f..30f3d47102 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -355,7 +355,7 @@ static void SIMIX_wake_processes() } } -/** Handle any pending timer */ +/** Handle any pending timer. Returns if something was actually run. */ static bool SIMIX_execute_timers() { bool result = false; @@ -561,38 +561,38 @@ void SIMIX_display_process_status() /* List the process and their state */ XBT_INFO("Legend of the following listing: \"Process (@): \""); for (auto const& kv : simix_global->process_list) { - smx_actor_t process = kv.second; + smx_actor_t actor = kv.second; - if (process->waiting_synchro) { + if (actor->waiting_synchro) { const char* synchro_description = "unknown"; // we don't care about the Activity type to get its name, use RawImpl const char* name = boost::static_pointer_cast>( - process->waiting_synchro) + actor->waiting_synchro) ->get_cname(); - if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(actor->waiting_synchro) != nullptr) synchro_description = "execution"; - if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(actor->waiting_synchro) != nullptr) synchro_description = "communication"; - if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(actor->waiting_synchro) != nullptr) synchro_description = "sleeping"; - if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(actor->waiting_synchro) != nullptr) synchro_description = "synchronization"; - if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(actor->waiting_synchro) != nullptr) synchro_description = "I/O"; - XBT_INFO("Process %ld (%s@%s): waiting for %s synchro %p (%s) in state %d to finish", process->get_pid(), - process->get_cname(), process->get_host()->get_cname(), synchro_description, - process->waiting_synchro.get(), name, (int)process->waiting_synchro->state_); + XBT_INFO("Actor %ld (%s@%s): waiting for %s activity %p (%s) in state %d to finish", actor->get_pid(), + actor->get_cname(), actor->get_host()->get_cname(), synchro_description, actor->waiting_synchro.get(), + name, (int)actor->waiting_synchro->state_); } else { - XBT_INFO("Process %ld (%s@%s)", process->get_pid(), process->get_cname(), process->get_host()->get_cname()); + XBT_INFO("Actor %ld (%s@%s)", actor->get_pid(), actor->get_cname(), actor->get_host()->get_cname()); } } } -- 2.20.1