Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
shutdown all hosted VMs when an host is turned off
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 30 Sep 2017 21:22:08 +0000 (23:22 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 30 Sep 2017 21:22:08 +0000 (23:22 +0200)
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp
src/simix/smx_host.cpp
teshsuite/msg/host_on_off_processes/host_on_off_processes.c
teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh

index ea9a040..b60dfc3 100644 (file)
@@ -44,6 +44,23 @@ std::deque<s4u::VirtualMachine*> VirtualMachineImpl::allVms_;
 // const double virt_overhead = 0.95;
 const double virt_overhead = 1;
 
+static void hostStateChange(s4u::Host& host)
+{
+  if (host.isOff()) { // just turned off.
+    std::vector<s4u::VirtualMachine*> trash;
+    /* Find all VMs living on that host */
+    for (s4u::VirtualMachine* const& vm : VirtualMachineImpl::allVms_)
+      if (vm->getPm() == &host)
+        trash.push_back(vm);
+    for (s4u::VirtualMachine* vm : trash)
+      vm->pimpl_vm_->shutdown(SIMIX_process_self());
+  }
+}
+VMModel::VMModel()
+{
+  s4u::Host::onStateChange.connect(hostStateChange);
+}
+
 double VMModel::nextOccuringEvent(double now)
 {
   /* TODO: update action's cost with the total cost of processes on the VM. */
@@ -224,7 +241,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer)
         THROW_IMPOSSIBLE;
         break;
     }
-    XBT_VERB("Shuting down the VM %s even if it's not running but %s", piface_->getCname(), stateName);
+    XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName);
   }
 
   xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
@@ -233,7 +250,8 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer)
   smx_actor_t smx_process;
   smx_actor_t smx_process_safe;
   xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("kill %s", smx_process->cname());
+    XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process->cname(), smx_process->host->getCname(),
+              issuer->cname());
     SIMIX_process_kill(smx_process, issuer);
   }
 
index 1063bf1..79c3aff 100644 (file)
@@ -121,6 +121,7 @@ protected:
  */
 class VMModel : public surf::HostModel {
 public:
+  VMModel();
   void ignoreEmptyVmInPmLMM() override{};
 
   double nextOccuringEvent(double now) override;
index 017c339..8698541 100644 (file)
@@ -28,7 +28,7 @@ namespace simgrid {
 
     Host::~Host()
     {
-      /* Clean Simulator data */
+      /* All processes should be gone when the host is turned off (by the end of the simulation). */
       if (xbt_swag_size(process_list) != 0) {
         std::string msg     = std::string("Shutting down host, but it's not empty:");
         smx_actor_t process = nullptr;
@@ -81,7 +81,8 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer)
       smx_actor_t process = nullptr;
       xbt_swag_foreach(process, host->process_list) {
         SIMIX_process_kill(process, issuer);
-        XBT_DEBUG("Killing %s@%s on behalf of %s", process->cname(), process->host->getCname(), issuer->cname());
+        XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process->cname(),
+                  process->host->getCname(), issuer->cname());
       }
     }
   } else {
index 12d7f31..680b014 100644 (file)
@@ -12,7 +12,8 @@ int tasks_done = 0;
 
 static void task_cleanup_handler(void *task)
 {
-  MSG_task_destroy(task);
+  if (task)
+    MSG_task_destroy(task);
 }
 
 static int process_daemon(int argc, char *argv[])
@@ -171,7 +172,7 @@ static int test_launcher(int argc, char *argv[])
     MSG_process_sleep(10);
     XBT_INFO("  Turn Jupiter off");
     MSG_host_off(jupiter);
-    XBT_INFO("Test 5 seems ok, cool !(number of Process : %d, it should be 2", MSG_process_get_number());
+    XBT_INFO("Test 5 seems ok (number of Process: %d, it should be 2)", MSG_process_get_number());
   }
 
   test =6;
index 13b028d..5d5d220 100644 (file)
@@ -61,7 +61,7 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platfor
 > [Tremblay:commTX:(3) 10.000000] [msg_test/INFO]   Start TX
 > [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   number of processes: 3
 > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO]   Turn Jupiter off
-> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok, cool !(number of Process : 2, it should be 2
+> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok (number of Process: 2, it should be 2)
 > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO]   Test done. See you!
 > [Tremblay:commTX:(3) 40.000000] [msg_test/INFO]   TX done
 > [40.000000] [msg_test/INFO] Simulation time 40