Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
small simplifications around simcalls
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 13 Aug 2019 22:49:31 +0000 (00:49 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 15 Aug 2019 13:37:41 +0000 (15:37 +0200)
- Use ActivityImpl::register_simcall() where possible
- Uniformity in ActivityImpl::post() methods
- Rename processes into actors

src/kernel/activity/CommImpl.cpp
src/kernel/activity/ConditionVariableImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/IoImpl.cpp
src/kernel/activity/SemaphoreImpl.cpp
src/kernel/activity/SleepImpl.cpp
src/s4u/s4u_Actor.cpp
src/simix/smx_global.cpp

index b7351de..03c3cbf 100644 (file)
@@ -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()
index fd84ce5..ccaeac9 100644 (file)
@@ -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_);
 }
 
index ea1159d..016f1e7 100644 (file)
@@ -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()
index ba69f5f..6022c2d 100644 (file)
@@ -75,6 +75,7 @@ void IoImpl::post()
   }
   on_completion(*this);
 
+  /* Answer all simcalls associated with the synchro */
   finish();
 }
 
index 4848f27..2daeba6 100644 (file)
@@ -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_--;
index 09f5e14..e20cdf7 100644 (file)
@@ -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();
 }
 
index 4239ef2..1840dfe 100644 (file)
@@ -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());
index 25ce054..30f3d47 100644 (file)
@@ -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 <pid> (<name>@<host>): <status>\"");
   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<simgrid::kernel::activity::ActivityImpl_T<simgrid::kernel::activity::RawImpl>>(
-              process->waiting_synchro)
+              actor->waiting_synchro)
               ->get_cname();
 
-      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(process->waiting_synchro) != nullptr)
+      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(actor->waiting_synchro) != nullptr)
         synchro_description = "execution";
 
-      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(process->waiting_synchro) != nullptr)
+      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(actor->waiting_synchro) != nullptr)
         synchro_description = "communication";
 
-      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(process->waiting_synchro) != nullptr)
+      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro) != nullptr)
         synchro_description = "sleeping";
 
-      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(process->waiting_synchro) != nullptr)
+      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(actor->waiting_synchro) != nullptr)
         synchro_description = "synchronization";
 
-      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro) != nullptr)
+      if (boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(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());
     }
   }
 }