Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the cpu model object in the workstation model object
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 15 Feb 2013 12:34:21 +0000 (13:34 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 15 Feb 2013 12:59:30 +0000 (13:59 +0100)
src/include/surf/surf.h
src/surf/vm_workstation.c
src/surf/workstation.c
src/surf/workstation_private.h

index 51435bd..a3d0324 100644 (file)
@@ -81,6 +81,13 @@ enum heap_action_type{
   NOTSET
 };
 
+
+typedef struct surf_resource {
+  surf_model_t model;
+  char *name;
+  xbt_dict_t properties;
+} s_surf_resource_t, *surf_resource_t;
+
 /** \ingroup SURF_actions
  *  \brief Action structure
  *
@@ -242,13 +249,14 @@ typedef struct surf_storage_model_extension_public {
   surf_action_t(*ls) (void *storage, const char *path);
 } s_surf_model_extension_storage_t;
 
-     /** \ingroup SURF_models
     *  \brief Workstation model extension public
     *
     *  Public functions specific to the workstation model.
     */
+/** \ingroup SURF_models
+ *  \brief Workstation model extension public
+ *
+ *  Public functions specific to the workstation model.
+ */
 typedef struct surf_workstation_model_extension_public {
-  surf_resource_t cpu;
+  /* This points to the surf cpu model object bound to the workstation model. */
+  surf_model_t cpu_model;
 
   surf_action_t(*execute) (void *workstation, double size);                                /**< Execute a computation amount on a workstation
                                       and create the corresponding action */
@@ -284,7 +292,15 @@ typedef struct surf_workstation_model_extension_public {
 } s_surf_model_extension_workstation_t;
 
 typedef struct surf_vm_workstation_model_extension_public {
+  /* The vm workstation model object has all members of the physical machine
+   * workstation model object. If these members are correctly initialized also
+   * in the vm workstation model object, we can access the vm workstation model
+   * object as if it is the pm workstatoin model object.
+   *
+   * But, it's not so clean. Think it again later.
+   * */
   s_surf_model_extension_workstation_t basic;
+
   void (*create) (const char *name, void *ind_phys_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 *ind_vm_workstation);
@@ -389,12 +405,6 @@ static inline void *surf_storage_resource_by_name(const char *name){
   return xbt_lib_get_elm_or_null(storage_lib, name);
 }
 
-typedef struct surf_resource {
-  surf_model_t model;
-  char *name;
-  xbt_dict_t properties;
-} s_surf_resource_t, *surf_resource_t;
-
 /**
  * Resource which have a metric handled by a maxmin system
  */
index 5ab5731..f4049bc 100644 (file)
@@ -7,14 +7,22 @@
 #include "xbt/ex.h"
 #include "xbt/dict.h"
 #include "portable.h"
+#include "surf_private.h"
 #include "surf/surf_resource.h"
 #include "simgrid/sg_config.h"
-
 #include "workstation_private.h"
 
+
+/* NOTE:
+ * The workstation_VM2013 struct includes the workstation_CLM03 struct in
+ * its first member. The workstation_VM2013_t struct inherites all
+ * characteristics of the workstation_CLM03 struct. So, we can treat a
+ * workstation_VM2013 object as a workstation_CLM03 if necessary.
+ **/
 typedef struct workstation_VM2013 {
   s_workstation_CLM03_t ws;    /* a VM is a ''v''host */
 
+  /* The workstation object of the lower layer */
   workstation_CLM03_t sub_ws;  // Pointer to the ''host'' OS
   e_msg_vm_state_t current_state;           // See include/msg/datatypes.h
 } s_workstation_VM2013_t, *workstation_VM2013_t;
@@ -32,9 +40,11 @@ static void vm_ws_create(const char *name, void *ind_phys_workstation)
   workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
 
   // //// WORKSTATION  RELATED STUFF ////
-  __init_ws(&(vm_ws->ws), name);
+  __init_workstation_CLM03(&vm_ws->ws, name, surf_vm_workstation_model);
+
   // Override the model with the current VM one.
-  vm_ws->ws.generic_resource.model = surf_vm_workstation_model;
+  // vm_ws->ws.generic_resource.model = surf_vm_workstation_model;
+
 
   // //// CPU  RELATED STUFF ////
   // This can be done directly during the creation of the surf_vm_worsktation model if
@@ -47,16 +57,20 @@ static void vm_ws_create(const char *name, void *ind_phys_workstation)
   // 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.
-  vm_ws->ws.net_elm=xbt_lib_get_or_null(host_lib,vm_ws->physical_ws->generic_resource.name,ROUTING_HOST_LEVEL);
+  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)
-  vm_ws->physical_ws = surf_workstation_resource_priv(ind_phys_workstation);
+  vm_ws->sub_ws = surf_workstation_resource_priv(ind_phys_workstation);
   vm_ws->current_state=msg_vm_state_created,
-  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
 
+
+  /* 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, cast ws to vm_ws. */
+  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, &vm_ws->ws);
 }
 
 /*
@@ -70,7 +84,7 @@ static void vm_ws_migrate(void *ind_vm_workstation, void *ind_dest_phys_workstat
 
    /* do something */
 
-   vm_ws->physical_workstation = surf_workstation_resource_priv(ind_dest_phys_workstation);
+   vm_ws->sub_ws = surf_workstation_resource_priv(ind_dest_phys_workstation);
 }
 
 /*
@@ -82,13 +96,13 @@ static void vm_ws_destroy(void *ind_vm_workstation)
        /* ind_phys_workstation equals to smx_host_t */
        workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_workstation);
        xbt_assert(vm_ws);
-       xbt_assert(vm_ws->generic_resource.model == surf_vm_workstation_model);
+       xbt_assert(vm_ws->ws.generic_resource.model == surf_vm_workstation_model);
 
-       const char *name = vm_ws->generic_resource.name;
+       const char *name = vm_ws->ws.generic_resource.name;
        /* this will call surf_resource_free() */
        xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
 
-       xbt_free(vm_ws->generic_resource.name);
+       xbt_free(vm_ws->ws.generic_resource.name);
        xbt_free(vm_ws);
 }
 
@@ -127,7 +141,7 @@ static double vm_ws_share_resources(surf_model_t workstation_model, double now)
 static const char *vm_ws_get_phys_host(void *ind_vm_ws)
 {
        workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
-       return vm_ws->physical_workstation->name;
+       return vm_ws->sub_ws->generic_resource.name;
 }
 
 static void surf_vm_workstation_model_init_internal(void)
@@ -137,6 +151,8 @@ static void surf_vm_workstation_model_init_internal(void)
   surf_vm_workstation_model->name = "Virtual Workstation";
   surf_vm_workstation_model->type = SURF_MODEL_TYPE_VM_WORKSTATION;
 
+  surf_vm_workstation_model->extension.vm_workstation.basic.cpu_model = surf_cpu_model_vm;
+
   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;
@@ -144,7 +160,7 @@ static void surf_vm_workstation_model_init_internal(void)
   surf_vm_workstation_model->extension.vm_workstation.get_phys_host = vm_ws_get_phys_host;
   surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
 
-  surf_vm_workstation_model->model_private->share_resources = ws_share_resources;
+  surf_vm_workstation_model->model_private->share_resources = vm_ws_share_resources;
 }
 
 void surf_vm_workstation_model_init()
index f627c89..33a2438 100644 (file)
@@ -7,6 +7,7 @@
 #include "xbt/ex.h"
 #include "xbt/dict.h"
 #include "portable.h"
+#include "surf_private.h"
 #include "storage_private.h"
 #include "surf/surf_resource.h"
 #include "simgrid/sg_config.h"
@@ -18,19 +19,22 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
 surf_model_t surf_workstation_model = NULL;
 
 
-void __init_ws(workstation_CLM03_t ws,  const char *id){
-  ws->generic_resource.model = surf_workstation_model;
+void __init_workstation_CLM03(workstation_CLM03_t ws, const char *id, surf_model_t workstation_model)
+{
+  ws->generic_resource.model = 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);
+
   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);
-  ws->generic_resource.model.extension.cpu=cpu_model_cas01(0);
 }
+
 static void workstation_new(sg_platf_host_cbarg_t host)
 {
   workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
-  __init_ws(workstation, host->id, level);
+
+  __init_workstation_CLM03(workstation, host->id, surf_workstation_model);
 }
 
 static int ws_resource_used(void *resource_id)
@@ -387,7 +391,6 @@ static void surf_workstation_model_init_internal(void)
 {
   surf_workstation_model = surf_model_init();
 
-  // TODO  surf_workstation_model->extension.cpu=cpu_model_cas01(0);
   surf_workstation_model->name = "Workstation";
   surf_workstation_model->type = SURF_MODEL_TYPE_WORKSTATION;
   surf_workstation_model->action_unref = ws_action_unref;
@@ -416,6 +419,11 @@ static void surf_workstation_model_init_internal(void)
   surf_workstation_model->get_latency_limited = ws_get_latency_limited;
 #endif
 
+  /* For VM support, we have a surf cpu model object for each workstation model
+   * object. The physical workstation model object has the cpu model object of
+   * the physical machine layer. */
+  surf_workstation_model->extension.workstation.cpu_model = surf_cpu_model_pm;
+
   surf_workstation_model->extension.workstation.execute = ws_execute;
   surf_workstation_model->extension.workstation.sleep = ws_action_sleep;
   surf_workstation_model->extension.workstation.get_state = ws_get_state;
index 75043ca..d8a706e 100644 (file)
@@ -6,7 +6,6 @@
 
 #ifndef WS_PRIVATE_H_
 #define WS_PRIVATE_H_
-#include "surf_private.h"
 typedef struct workstation_CLM03 {
   s_surf_resource_t generic_resource;   /* Must remain first to add this to a trace */
   void *net_elm;