Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed conflicts - Adrien
authoralebre <adrien.lebre@inria.fr>
Thu, 31 Jan 2013 16:13:06 +0000 (17:13 +0100)
committeralebre <adrien.lebre@inria.fr>
Thu, 31 Jan 2013 16:13:06 +0000 (17:13 +0100)
src/include/surf/surf.h
src/msg/msg_vm.c
src/simix/smx_vm.c
src/surf/vm_workstation.c

index 8ddd7fb..a7b45bf 100644 (file)
@@ -280,9 +280,9 @@ typedef struct surf_vm_workstation_model_extension_public {
   s_surf_model_extension_workstation_t basic;
   void* (*create) (const char *name, void *workstation); // First operation of the VM model
   // start does not appear here as it corresponds to turn the state from created to running (see smx_vm.c)
-   int (*get_state) (void *workstation);
+  int (*get_state) (void *workstation);
   void (*set_state) (void *workstation, int state);
-   void  (*destroy) (const char *name); // destory the vm-specific data
+  void  (*destroy) (const char *name); // destory the vm-specific data
 } s_surf_model_extension_vm_workstation_t;
 
 /** \ingroup SURF_models
index 9d0941f..568fc00 100644 (file)
@@ -227,6 +227,7 @@ void MSG_vm_suspend(msg_vm_t vm) {
   #endif
 }
 
+
 /** @brief Immediately resumes the execution of all processes within the given VM.
  *  @ingroup msg_VMs
  *
@@ -247,26 +248,37 @@ void MSG_vm_resume(msg_vm_t vm) {
   #endif
 }
 
-/** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
- *  @ingroup msg_VMs
- *
- * No extra delay occurs. If you want to simulate this too, you want to
- * use a #MSG_process_sleep() or something. I'm not quite sure.
- */
+
 void MSG_vm_shutdown(msg_vm_t vm)
 {
-  msg_process_t process;
-  XBT_DEBUG("%lu processes in the VM", xbt_dynar_length(vm->processes));
-  while (xbt_dynar_length(vm->processes) > 0) {
-    process = xbt_dynar_get_as(vm->processes,0,msg_process_t);
-    MSG_process_kill(process);
+  /* msg_vm_t equals to msg_host_t */
+  char *name = simcall_host_get_name(vm);
+  smx_host_t smx_host = xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL);
+  smx_process_t smx_process, smx_process_next;
+
+  XBT_DEBUG("%lu processes in the VM", xbt_swag_size(SIMIX_host_priv(smx_host)->process_list));
+
+  xbt_swag_foreach_safe(smx_process, SIMIX_host_priv(smx_host)->process_list) {
+         XBT_DEBUG("kill %s", SIMIX_host_get_name(smx_host));
+         simcall_process_kill(smx_process);
   }
 
+  /* taka: not yet confirmed */
   #ifdef HAVE_TRACING
   TRACE_msg_vm_kill(vm);
   #endif
 
+
+  /* TODO: update the state of vm */
+
+#if 0
+  while (xbt_dynar_length(vm->processes) > 0) {
+    process = xbt_dynar_get_as(vm->processes,0,msg_process_t);
+  }
+#endif
 }
+
+
 /**
  * \ingroup msg_VMs
  * \brief Reboot the VM, restarting all the processes in it.
@@ -290,6 +302,7 @@ void MSG_vm_reboot(msg_vm_t vm)
 
   xbt_dynar_free(&new_processes);
 }
+
 /** @brief Destroy a msg_vm_t.
  *  @ingroup msg_VMs
  */
index 9ab0802..1041a7b 100644 (file)
@@ -84,10 +84,16 @@ int SIMIX_pre_vm_state(smx_host_t vm){
  *
  * \param h the host to destroy (a smx_host_t)
  */
-void SIMIX_host_destroy(void *h)
+void SIMIX_vm_host_destroy(void *h)
 {
   smx_host_priv_t host = (smx_host_priv_t) h;
 
+  smx_host_t
+  xbt_lib_(host_lib,name,SIMIX_HOST_LEVEL,smx_host);
+
+  /* jump to vm_ws_destroy() */
+  surf_vm_workstation_model->extension.vm_workstation.destroy(name);
+
   xbt_assert((host != NULL), "Invalid parameters");
 
   /* Clean Simulator data */
index 90242e9..1db863c 100644 (file)
@@ -25,13 +25,30 @@ surf_model_t surf_vm_workstation_model = NULL;
 static void vm_ws_create (const char *name, void *phys_workstation)
 {
   workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
-// TODO Implement the surf vm workstation model
+// TODO Complete the surf vm workstation model
   vm_ws->generic_resource.model = surf_vm_workstation_model;
   vm_ws->generic_resource.name = xbt_strdup(name);
   vm_ws->physical_workstation = phys_workstation;
   vm_ws->current_state=msg_vm_state_created,
   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
 }
+/*
+ * A physical host does not disapper in the current SimGrid code, but a VM may
+ * disapper during a simulation.
+ */
+static void vm_ws_destroy(const char *name)
+{
+       workstation_VM2013_t workstation = xbt_lib_get_or_null(host_lib, name, SURF_WKS_LEVEL);
+       xbt_assert(workstation);
+       xbt_assert(workstation->generic_resource.model == surf_vm_workstation_model);
+
+       xbt_free(workstation->generic_resource.name);
+
+       /* not defined yet, but we should have  */
+       // xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
+
+       xbt_free(workstation);
+}
 
 static int vm_ws_get_state(void *vm_ws){
        return ((workstation_VM2013_t)vm_ws)->current_state;
@@ -49,6 +66,7 @@ static void surf_vm_workstation_model_init_internal(void)
   surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create;
   surf_vm_workstation_model->extension.vm_workstation.set_state = vm_ws_set_state;
   surf_vm_workstation_model->extension.vm_workstation.get_state = vm_ws_get_state;
+  surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
 
 }