Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the segfault upon exit
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 22 Feb 2013 15:06:21 +0000 (16:06 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 22 Feb 2013 15:06:21 +0000 (16:06 +0100)
include/xbt/lib.h
src/simix/smx_vm.c
src/surf/vm_workstation.c
src/surf/workstation.c
src/surf/workstation_private.h
src/xbt/lib.c

index 3b0ef3c..36232d9 100644 (file)
@@ -26,7 +26,7 @@ XBT_PUBLIC(void) xbt_lib_free(xbt_lib_t * lib);
 XBT_PUBLIC(int) xbt_lib_add_level(xbt_lib_t lib, void_f_pvoid_t free_f);
 XBT_PUBLIC(void) xbt_lib_set(xbt_lib_t lib, const char *name, int level,
                              void *obj);
-XBT_PUBLIC(void) xbt_lib_unset(xbt_lib_t lib, const char *key, int level);
+XBT_PUBLIC(void) xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback);
 XBT_PUBLIC(void *) xbt_lib_get_or_null(xbt_lib_t lib, const char *name,
                                        int level);
 XBT_PUBLIC(xbt_dictelm_t) xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key);
index d4eeea8..59156f1 100644 (file)
@@ -313,7 +313,7 @@ void SIMIX_vm_destroy(smx_host_t ind_vm)
   smx_host_priv_t host_priv = SIMIX_host_priv(ind_vm);
 
   /* this will call the registered callback function, i.e., SIMIX_host_destroy().  */
-  xbt_lib_unset(host_lib, hostname, SIMIX_HOST_LEVEL);
+  xbt_lib_unset(host_lib, hostname, SIMIX_HOST_LEVEL, 1);
 
   /* jump to vm_ws_destroy(). The surf level resource will be freed. */
   surf_vm_workstation_model->extension.vm_workstation.destroy(ind_vm);
index d8f2d75..82b329f 100644 (file)
@@ -20,34 +20,56 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
 
 surf_model_t surf_vm_workstation_model = NULL;
 
+/* ind means ''indirect'' that this is a reference on the whole dict_elm
+ * structure (i.e not on the surf_resource_private infos) */
+
 static void vm_ws_create(const char *name, void *ind_phys_workstation)
 {
-  workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
-
-  vm_ws->sub_ws = surf_workstation_resource_priv(ind_phys_workstation);
-  vm_ws->current_state = SURF_VM_STATE_CREATED;
-
+  workstation_CLM03_t sub_ws = surf_workstation_resource_priv(ind_phys_workstation);
+  const char *sub_ws_name = sub_ws->generic_resource.name;
+
+  /* The workstation_VM2013 struct inherits the workstation_CLM03 struct. We
+   * create a physical workstation resource, but specifying the size of
+   * s_workstation_VM2013_t and the vm workstation model object. */
+  workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_VM2013_t),
+      surf_vm_workstation_model, name, NULL);
+
+  /* Currently, we assume a VM has no storage. */
+  ws->storage = NULL;
+
+  /* Currently, a VM uses the network resource of its physical host. In
+   * host_lib, this network resource object is refered from two different keys.
+   * When deregistering the reference that points the network resource object
+   * 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. */
+  ws->net_elm = xbt_lib_get_or_null(host_lib, sub_ws_name, ROUTING_HOST_LEVEL);
+  xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, ws->net_elm);
+
+  /* The SURF_WKS_LEVEL at host_lib saves workstation_CLM03 objects. Please
+   * note workstation_VM2013 objects, inheriting the workstation_CLM03
+   * structure, are also saved there. 
+   *
+   * If you want to get a workstation_VM2013 object from host_lib, see
+   * ws->generic_resouce.model->type first. If it is
+   * SURF_MODEL_TYPE_VM_WORKSTATION, you can cast ws to vm_ws. */
+  XBT_INFO("Create VM(%s) @ PM(%s) with %ld mounted disks", name, sub_ws_name, xbt_dynar_length(ws->storage));
+  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
 
-  // //// WORKSTATION  RELATED STUFF ////
-  /* Create a workstation_CLM03 resource and register it to the system
-     Please note that the new ws is added into the host_lib. Then,
-     if you want to get a workstation_VM2013 object from host_lib, see
-     ws->generic_resouce.model->type first. If it is  SURF_MODEL_TYPE_VM_WORKSTATION,
-     you can cast ws to vm_ws. */
 
-  __init_workstation_CLM03(&vm_ws->ws, name);
+  /* We initialize the VM-specific members. */
+  workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
+  vm_ws->sub_ws = sub_ws;
+  vm_ws->current_state = SURF_VM_STATE_CREATED;
 
-  // Override the model with the current VM one.
-  vm_ws->ws.generic_resource.model = surf_vm_workstation_model;
 
 
   // //// CPU  RELATED STUFF ////
-  // Roughly, create a vcpu resource by using the values of  the sub_cpu one.
+  // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   cpu_Cas01_t sub_cpu = surf_cpu_resource_priv(ind_phys_workstation);
 
   /* We can assume one core and cas01 cpu for the first step.
-   * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource.
-   * */
+   * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
   cpu_cas01_create_resource(name, // name
       sub_cpu->power_peak,        // host->power_peak,
       1,                          // host->power_scale,
@@ -58,22 +80,16 @@ static void vm_ws_create(const char *name, void *ind_phys_workstation)
       NULL,                       // host->properties,
       surf_cpu_model_vm);
 
-  vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_phys_workstation, GUESTOS_NOISE);
 
-  //// NET RELATED STUFF ////
-  // Bind virtual net_elm to the host
-  // TODO rebind each time you migrate a VM
-  // TODO check how network requests are scheduled between distinct processes competing for the same card.
-  // Please note that the __init_workstation_CLM03 invocation assigned NULL to ws.net_elm since no network elements
-  // were previously created for this hostname. Indeed all network elements are created during the SimGrid initialization phase by considering
-  // the platform file.
-  vm_ws->ws.net_elm = xbt_lib_get_or_null(host_lib, vm_ws->sub_ws->generic_resource.name, ROUTING_HOST_LEVEL);
-  xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, vm_ws->ws.net_elm);
 
-  // //// STORAGE RELATED STUFF ////
- // ind means ''indirect'' that this is a reference on the whole dict_elm structure (i.e not on the surf_resource_private infos)
+  /* We create cpu_action corresponding to a VM process on the host operating system. */
+  vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_phys_workstation, GUESTOS_NOISE);
 
 
+  /* TODO:
+   * - rebind each time you migrate a VM
+   * - check how network requests are scheduled between distinct processes competing for the same card.
+   */
 }
 
 /*
@@ -97,39 +113,50 @@ static void vm_ws_migrate(void *ind_vm_workstation, void *ind_dest_phys_workstat
 static void vm_ws_destroy(void *ind_vm_workstation)
 { 
        /* ind_phys_workstation equals to smx_host_t */
+
+  /* Before clearing the entries in host_lib, we have to pick up resources. */
        workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_workstation);
-       cpu_Cas01_t sub_cpu = surf_cpu_resource_priv(ind_vm_workstation);
+  cpu_Cas01_t cpu = surf_cpu_resource_priv(ind_vm_workstation);
+       const char *name = vm_ws->ws.generic_resource.name;
+  XBT_INFO("%s", name);
 
        xbt_assert(vm_ws);
        xbt_assert(vm_ws->ws.generic_resource.model == surf_vm_workstation_model);
 
-  {
-    int ret = surf_cpu_model_pm->action_unref(vm_ws->cpu_action);
-    xbt_assert(ret == 1, "Bug: some resource still remains");
-  }
-
-       const char *name = vm_ws->ws.generic_resource.name;
 
+  /* xbt_lib_remove() deletes all entries associated to the VM from host_lib.
+   * This function does not invoke the registered freeing callback of each
+   * level.
+   *
+   * FIXME: But, this function deletes all levels of the key. We must
+   * be sure that there is no entry at any level. */
+       // xbt_lib_remove(host_lib, name);
        // Remove all others in the lib associated to the VM
-    // Please note that you only remove the entries (and not free them)
-       xbt_lib_remove(host_lib, name);
-
-       //Free the CPU
+  // Please note that you only remove the entries (and not free them)
+  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_STORAGE_LEVEL, 0);
+  xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL, 0);
 
 
-       // Free the net_elmts
-       // Nothing has to be done, because net_elmts is just a pointer on the physical one
+  /* Free the cpu_action of the VM. */
+  int ret = surf_cpu_model_pm->action_unref(vm_ws->cpu_action);
+  xbt_assert(ret == 1, "Bug: some resource still remains");
 
-       // Free the storage
-    // Not relevant yet
+  /* Free the cpu resource of the VM. If using power_trace, we will have to
+   * free other objects than lmm_constraint. */
+  surf_model_t cpu_model = cpu->generic_resource.model;
+  lmm_constraint_free(cpu_model->model_private->maxmin_system, cpu->constraint);
+  surf_resource_free(cpu);
 
-       //Free the WS
-       free(vm_ws);
+  /* 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
 
-       // Not yet implemented
-  /* NOTE: surf_resource_free() frees vm_ws->ws.generic_resource.name and
-   * vm_ws->ws. Do not free them here. */
+       /* Free the workstation resource of the VM. */
+  surf_resource_free(vm_ws);
 }
 
 static int vm_ws_get_state(void *ind_vm_ws){
@@ -167,6 +194,10 @@ static double get_solved_value(surf_action_t cpu_action)
 
 static double vm_ws_share_resources(surf_model_t workstation_model, double now)
 {
+  /* TODO: udpate action's cost with the total cost of processes on the VM. */
+
+
+
   /* 0. Make sure that we already calculated the resource share at the physical
    * machine layer. */
   {
index 0c8db05..327c1a8 100644 (file)
@@ -19,22 +19,19 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
 surf_model_t surf_workstation_model = NULL;
 
 
-void __init_workstation_CLM03(workstation_CLM03_t ws, const char *id)
+static void workstation_new(sg_platf_host_cbarg_t host)
 {
-  ws->generic_resource.model = surf_workstation_model;
-  ws->generic_resource.name = xbt_strdup(id);
-  ws->storage = xbt_lib_get_or_null(storage_lib, id, ROUTING_STORAGE_HOST_LEVEL);
-  ws->net_elm = xbt_lib_get_or_null(host_lib, id, ROUTING_HOST_LEVEL);
+  const char *name = host->id;
 
-  XBT_DEBUG("Create ws %s with %ld mounted disks", id, xbt_dynar_length(ws->storage));
-  xbt_lib_set(host_lib, id, SURF_WKS_LEVEL, ws);
-}
+  /* NOTE: The properties object is NULL, because the current code uses that of
+   * that of a cpu resource. */
+  workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_CLM03_t), surf_workstation_model, name, NULL);
 
-static void workstation_new(sg_platf_host_cbarg_t host)
-{
-  workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
+  ws->storage = xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL);
+  ws->net_elm = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
 
-  __init_workstation_CLM03(workstation, host->id);
+  XBT_DEBUG("Create ws %s with %ld mounted disks", name, xbt_dynar_length(ws->storage));
+  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
 }
 
 
index ca5e707..017f847 100644 (file)
@@ -12,7 +12,6 @@ typedef struct workstation_CLM03 {
   xbt_dynar_t storage;
 } s_workstation_CLM03_t, *workstation_CLM03_t;
 
-void __init_workstation_CLM03(workstation_CLM03_t ws, const char *id);
 
 int ws_resource_used(void *resource_id);
 double ws_share_resources(surf_model_t workstation_model, double now);
index a76ca15..3dfdca5 100644 (file)
@@ -71,7 +71,7 @@ void xbt_lib_set(xbt_lib_t lib, const char *key, int level, void *obj)
 }
 
 /* for vm */
-void xbt_lib_unset(xbt_lib_t lib, const char *key, int level)
+void xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback)
 {
   void **elts = xbt_dict_get_or_null(lib->dict, key);
   if (!elts) {
@@ -86,7 +86,8 @@ void xbt_lib_unset(xbt_lib_t lib, const char *key, int level)
      return;
   } else {
      XBT_DEBUG("Remove %p of key %s at level %d", obj, key, level);
-     lib->free_f[level](obj);
+     if (invoke_callback)
+       lib->free_f[level](obj);
      elts[level] = NULL;
   }