Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add vm tesh
authorPaul Bédaride <paul.bedaride@gmail.com>
Mon, 11 Aug 2014 13:18:50 +0000 (15:18 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Mon, 11 Aug 2014 13:25:14 +0000 (15:25 +0200)
include/xbt/dict.h
src/include/surf/surf.h
src/simix/smx_host.c
src/surf/surf_c_bindings.cpp
src/surf/vm_workstation_hl13.cpp
src/surf/workstation_interface.cpp
src/xbt/dict.c
teshsuite/java/sleep_host_off/CMakeLists.txt
teshsuite/msg/host_on_off_processes/host_on_off_processes.c
teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh

index 41a4aba..0c0ec92 100644 (file)
@@ -76,6 +76,7 @@ XBT_PUBLIC(void) xbt_dict_set(xbt_dict_t dict, const char *key, void *data,
 XBT_PUBLIC(void *) xbt_dict_get(xbt_dict_t dict, const char *key);
 XBT_PUBLIC(void *) xbt_dict_get_or_null(xbt_dict_t dict, const char *key);
 XBT_PUBLIC(char *) xbt_dict_get_key(xbt_dict_t dict, const void *data);
+XBT_PUBLIC(char *) xbt_dict_get_elm_key(xbt_dictelm_t elem);
 XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm(xbt_dict_t dict, const char *key);
 XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key);
 
index 4210fc9..1a9d56e 100644 (file)
@@ -192,6 +192,9 @@ static inline void *surf_cpu_resource_priv(const void *host) {
 static inline void *surf_workstation_resource_priv(const void *host){
   return (void*)xbt_lib_get_level((xbt_dictelm_t)host, SURF_WKS_LEVEL);
 }
+static inline void *surf_routing_resource_priv(const void *host){
+  return (void*)xbt_lib_get_level((xbt_dictelm_t)host, ROUTING_HOST_LEVEL);
+}
 static inline void *surf_storage_resource_priv(const void *storage){
   return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL);
 }
index 60ba70a..534e331 100644 (file)
@@ -120,6 +120,14 @@ void SIMIX_host_off(smx_host_t h, smx_process_t issuer)
       }
     }
   }
+  /*xbt_dynar_t vms = surf_workstation_get_vms(h);
+  unsigned int cpt;
+  smx_host_t vm;
+  xbt_dynar_foreach(vms, cpt, vm) {
+    SIMIX_vm_shutdown(vm, issuer);
+    SIMIX_vm_destroy(vm);
+  }
+  xbt_dynar_free(&vms);*/
 }
 
 /**
index d5a0cb0..70bd496 100644 (file)
@@ -26,6 +26,10 @@ static WorkstationPtr get_casted_workstation(surf_resource_t resource){
   return static_cast<WorkstationPtr>(surf_workstation_resource_priv(resource));
 }
 
+static RoutingEdgePtr get_casted_routing(surf_resource_t resource){
+  return static_cast<RoutingEdgePtr>(surf_routing_resource_priv(resource));
+}
+
 static WorkstationVMPtr get_casted_vm_workstation(surf_resource_t resource){
   return static_cast<WorkstationVMPtr>(surf_workstation_resource_priv(resource));
 }
@@ -402,7 +406,16 @@ int surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, cons
 }
 
 xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
-  return get_casted_workstation(resource)->getVms();
+  xbt_dynar_t vms = get_casted_workstation(resource)->getVms();
+  xbt_dynar_t vms_ = xbt_dynar_new(sizeof(smx_host_t), NULL);
+  unsigned int cpt;
+  WorkstationVMPtr vm;
+  xbt_dynar_foreach(vms, cpt, vm) {
+    smx_host_t vm_ = xbt_lib_get_elm_or_null(host_lib, vm->getName());
+    xbt_dynar_push(vms_, &vm_);
+  }
+  xbt_dynar_free(&vms);
+  return vms_;
 }
 
 void surf_workstation_get_params(surf_resource_t resource, ws_params_t params){
@@ -414,7 +427,30 @@ void surf_workstation_set_params(surf_resource_t resource, ws_params_t params){
 }
 
 void surf_vm_workstation_destroy(surf_resource_t resource){
-  delete get_casted_vm_workstation(resource);
+  /* ind_phys_workstation equals to smx_host_t */
+  //surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
+
+  /* Before clearing the entries in host_lib, we have to pick up resources. */
+  CpuPtr cpu = get_casted_cpu(resource);
+  WorkstationVMPtr vm = get_casted_vm_workstation(resource);
+  RoutingEdgePtr routing = get_casted_routing(resource);
+  char* name = xbt_dict_get_elm_key(resource);
+  /* We deregister objects from host_lib, without invoking the freeing callback
+   * of each level.
+   *
+   * Do not call xbt_lib_remove() here. It deletes all levels of the key,
+   * including MSG_HOST_LEVEL and others. We should unregister only what we know.
+   */
+  xbt_lib_unset(host_lib, name, SURF_CPU_LEVEL, 0);
+  xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0);
+  xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL, 0);
+
+  /* TODO: comment out when VM storage is implemented. */
+  // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
+
+  delete cpu;
+  delete vm;
+  delete routing;
 }
 
 void surf_vm_workstation_suspend(surf_resource_t resource){
index 73baddf..996f286 100644 (file)
@@ -233,7 +233,7 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na
    * from the VM name, we have to make sure that the system does not call the
    * free callback for the network resource object. The network resource object
    * is still used by the physical machine. */
-  p_netElm = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL));
+  p_netElm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL)));
   xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm);
 
   p_subWs = sub_ws;
@@ -277,40 +277,9 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na
  */
 WorkstationVMHL13::~WorkstationVMHL13()
 {
-  /* ind_phys_workstation equals to smx_host_t */
-  surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
-
-  /* Before clearing the entries in host_lib, we have to pick up resources. */
-  CpuCas01Ptr cpu = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(ind_vm_workstation));
-
-  /* We deregister objects from host_lib, without invoking the freeing callback
-   * of each level.
-   *
-   * Do not call xbt_lib_remove() here. It deletes all levels of the key,
-   * including MSG_HOST_LEVEL and others. We should unregister only what we know.
-   */
-  xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0);
-  xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0);
-  xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0);
-
-  /* TODO: comment out when VM storage is implemented. */
-  // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
-
-
   /* Free the cpu_action of the VM. */
   int ret = p_action->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
-
-  /* Free the cpu resource of the VM. If using power_trace, we will have to */
-  delete cpu;
-
-  /* Free the network resource of the VM. */
-  // Nothing has to be done, because net_elmts is just a pointer on the physical one
-
-  /* Free the storage resource of the VM. */
-  // Not relevant yet
-
-  /* Free the workstation resource of the VM. */
 }
 
 void WorkstationVMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) {
@@ -379,7 +348,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm)
 
    /* update net_elm with that of the destination physical host */
    RoutingEdgePtr old_net_elm = p_netElm;
-   RoutingEdgePtr new_net_elm = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL));
+   RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL)));
    xbt_assert(new_net_elm);
 
    /* Unregister the current net_elm from host_lib. Do not call the free callback. */
@@ -428,6 +397,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm)
 
    XBT_DEBUG("migrate VM(%s): change net_elm (%p to %p)", vm_name, old_net_elm, new_net_elm);
    XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst);
+   delete old_net_elm;
 }
 
 void WorkstationVMHL13::setBound(double bound){
index a1d9d3a..6b021c5 100644 (file)
@@ -376,7 +376,7 @@ int Workstation::fileMove(surf_file_t fd, const char* fullpath){
 
 xbt_dynar_t Workstation::getVms()
 {
-  xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
+  xbt_dynar_t dyn = xbt_dynar_new(sizeof(WorkstationVMPtr), NULL);
 
   /* iterate for all virtual machines */
   for (WorkstationVMModel::vm_list_t::iterator iter =
@@ -384,8 +384,8 @@ xbt_dynar_t Workstation::getVms()
        iter !=  WorkstationVMModel::ws_vms.end(); ++iter) {
 
     WorkstationVMPtr ws_vm = &*iter;
-    if (this == ws_vm-> p_subWs)
-      xbt_dynar_push(dyn, &ws_vm->p_subWs);
+    if (this == ws_vm->p_subWs)
+      xbt_dynar_push(dyn, &ws_vm);
   }
 
   return dyn;
index 0d8985f..f632631 100644 (file)
@@ -304,6 +304,15 @@ char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
   return NULL;
 }
 
+/**
+ * @brief retrieve the key associated to that xbt_dictelm_t.
+ *
+ */
+char *xbt_dict_get_elm_key(xbt_dictelm_t elm)
+{
+  return elm->key;
+}
+
 /**
  * \brief Retrieve data from the dict (null-terminated key)
  *
@@ -346,7 +355,7 @@ XBT_INLINE xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
 XBT_INLINE void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
 {
   xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
-  
+
   if (current == NULL)
     return NULL;
 
index dceda48..df403b7 100644 (file)
@@ -40,6 +40,5 @@ set(bin_files
   )
 set(txt_files
   ${txt_files}
-  ${CMAKE_CURRENT_SOURCE_DIR}/README
   PARENT_SCOPE
   )
index a9c9b78..cb48a8a 100644 (file)
@@ -38,6 +38,7 @@ int test_launcher(int argc, char *argv[])
     argvF = xbt_new(char*, 2);
     argvF[0] = xbt_strdup("process_daemon");
     MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF);
+    MSG_process_sleep(3);
     XBT_INFO("  Turn off Jupiter");
     MSG_host_off(jupiter);
     MSG_process_sleep(10);
@@ -120,34 +121,37 @@ int test_launcher(int argc, char *argv[])
 
   test =6;
   if (xbt_dynar_member(tests, &test)){
-    /*XBT_INFO("Test 5: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node");
+    XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node");
 
     // Create VM0
     int dpRate = 70;
     msg_vm_t vm0;
-MSG_vm_create (msg_host_t ind_pm, const char *name, int ncpus, int ramsize, int net_cap, char *disk_path, int disksize, int mig_netspeed, int dp_intensity)
-  vm0 = MSG_vm_create_core(jupiter, "vm0");
-  params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
-  MSG_host_set_params(vm0, &params);
-  MSG_vm_start(vm0);
-    XVM vm0 = null;
-        vm0 = new XVM(
-                host1,
-                "vm0",
-                1, // Nb of vcpu
-                2048, // Ramsize,
-                125, // Net Bandwidth
-                null, //VM disk image
-                -1,   //size of disk image,
-                125, // Net bandwidth,
-                dpRate // Memory intensity
-        );
-        vm0.start();
-        vm0.setLoad(90);
-
-        host1.off();
-        Msg.info("Test 5 is also weird: when the node host1 is turned off once again, the VM and its daemon are not killed." +
-                " However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)\n");*/
+    msg_process_t daemon;
+
+    vm0 = MSG_vm_create (jupiter, "vm0", 1, 2048, 125, NULL, -1, 125, dpRate);
+    MSG_vm_start(vm0);
+
+    argvF = xbt_new(char*, 2);
+    argvF[0] = xbt_strdup("process_daemon");
+    daemon = MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, vm0, 1, argvF);
+
+    argvF = xbt_new(char*, 2);
+    argvF[0] = xbt_strdup("process_daemonJUPI");
+    MSG_process_create_with_arguments("process_daemonJUPI", process_daemon, NULL, jupiter, 1, argvF);
+
+    MSG_process_suspend(daemon);
+    MSG_vm_set_bound(vm0, 90);
+    MSG_process_resume(daemon);
+
+    MSG_process_sleep(10);
+
+    XBT_INFO("  Turn Jupiter off");
+    MSG_host_off(jupiter);
+    XBT_INFO("  Shutdown vm0");
+    MSG_vm_shutdown(vm0);
+    XBT_INFO("  Destroy vm0");
+    MSG_vm_destroy(vm0);
+    XBT_INFO("Test 6 is also weird: when the node Jupiter is turned off once again, the VM and its daemon are not killed. However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)");
   }
 
   test = 7;
@@ -172,12 +176,13 @@ MSG_vm_create (msg_host_t ind_pm, const char *name, int ncpus, int ramsize, int
 int process_daemon(int argc, char *argv[])
 {
   msg_task_t task = NULL;
+  XBT_INFO("  Start daemon on %s (%f)",  MSG_host_get_name(MSG_host_self()), MSG_get_host_speed(MSG_host_self()));
   for(;;){
-    task = MSG_task_create("deamon", 100*MSG_get_host_speed(MSG_host_self()), 0, NULL);
+    task = MSG_task_create("deamon", MSG_get_host_speed(MSG_host_self()), 0, NULL);
     XBT_INFO("  Execute deamon");
+    MSG_task_execute(task);
     MSG_task_destroy(task);
   }
-  MSG_task_execute(task);
   XBT_INFO("  Deamon done. See you!");
   return 0;
 }
index 220808d..eb10b87 100644 (file)
@@ -2,11 +2,14 @@
 $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 1 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error
 > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 1:
 > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO]   Create a process on Jupiter
+> [Jupiter:process_daemon:(2) 0.000000] [msg_test/INFO]   Start daemon on Jupiter (76296000.000000)
 > [Jupiter:process_daemon:(2) 0.000000] [msg_test/INFO]   Execute deamon
-> [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO]   Turn off Jupiter
-> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test 1 seems ok, cool !(number of Process : 1, it should be 1 (i.e. the Test one))
-> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   Test done. See you!
-> [10.000000] [msg_test/INFO] Simulation time 10
+> [Jupiter:process_daemon:(2) 1.000000] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemon:(2) 2.000000] [msg_test/INFO]   Execute deamon
+> [Tremblay:test_launcher:(1) 3.000000] [msg_test/INFO]   Turn off Jupiter
+> [Tremblay:test_launcher:(1) 13.000000] [msg_test/INFO] Test 1 seems ok, cool !(number of Process : 1, it should be 1 (i.e. the Test one))
+> [Tremblay:test_launcher:(1) 13.000000] [msg_test/INFO]   Test done. See you!
+> [13.000000] [msg_test/INFO] Simulation time 13
 
 $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 2 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error
 > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 2:
@@ -61,3 +64,26 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platfor
 > [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
+
+$ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 6 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error
+> [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node
+> [0.000000] [surf_vm_workstation/INFO] Create VM(vm0)@PM(Jupiter) with 0 mounted disks
+> [vm0:process_daemon:(2) 0.000000] [msg_test/INFO]   Start daemon on vm0 (76296000.000000)
+> [vm0:process_daemon:(2) 0.000000] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 0.000000] [msg_test/INFO]   Start daemon on Jupiter (76296000.000000)
+> [Jupiter:process_daemonJUPI:(3) 0.000000] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 1.000001] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 2.000002] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 3.000004] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 4.000005] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 5.000006] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 6.000007] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 7.000008] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 8.000009] [msg_test/INFO]   Execute deamon
+> [Jupiter:process_daemonJUPI:(3) 9.000011] [msg_test/INFO]   Execute deamon
+> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   Turn Jupiter off
+> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   Shutdown vm0
+> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   Destroy vm0
+> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test 6 is also weird: when the node Jupiter is turned off once again, the VM and its daemon are not killed. However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)
+> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO]   Test done. See you!
+> [10.000000] [msg_test/INFO] Simulation time 10