Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid into hypervisor
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Thu, 14 Feb 2013 12:53:35 +0000 (13:53 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Thu, 14 Feb 2013 12:53:35 +0000 (13:53 +0100)
The missing header file was added.

src/msg/msg_vm.c
src/simix/smx_user.c
src/simix/smx_vm.c
src/surf/workstation.c

index 6891726..a6b5b99 100644 (file)
@@ -161,44 +161,67 @@ int MSG_vm_is_restoring(msg_vm_t vm)
 
 /* **** ******** MSG vm actions ********* **** */
 
-/** @brief Create a new VM (the VM is just attached to the location but it is not started yet).
+/** @brief Create a new VM with specified parameters.
  *  @ingroup msg_VMs*
  *
- * Please note that a VM is a specific host. Hence, you should give a different name
- * for each VM/PM.
  */
-msg_vm_t MSG_vm_create(msg_host_t ind_host, const char *name,
-                                            int core_nb, int mem_cap, int net_cap){
+msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char *name,
+                                            int core_nb, int mem_cap, int net_cap, char *disk_path, int disk_size)
+{
+  msg_vm_t vm = MSG_vm_create_core(ind_pm, name);
+
+  MSG_vm_set_property_value(vm, "CORE_NB", bprintf("%d", core_nb), free);
+  MSG_vm_set_property_value(vm, "MEM_CAP", bprintf("%d", mem_cap), free);
+  MSG_vm_set_property_value(vm, "NET_CAP", bprintf("%d", net_cap), free);
+
+  /* TODO: We will revisit the disk support later. */
 
-  // Note new and vm_workstation refer to the same area (due to the lib/dict appraoch)
-  msg_vm_t new = NULL;
+  return vm;
+}
+
+
+/** @brief Create a new VM object. The VM is not yet started. The resource of the VM is allocated upon MSG_vm_start().
+ *  @ingroup msg_VMs*
+ *
+ * A VM is treated as a host. The name of the VM must be unique among all hosts.
+ */
+msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name)
+{
+  /* make sure the VM of the same name does not exit */
+  {
+    void *ind_host_tmp = xbt_lib_get_elm_or_null(host_lib, name);
+    if (ind_host_tmp) {
+      XBT_ERROR("host %s already exits", name);
+      return NULL;
+    }
+  }
+
+  /* Note: ind_vm and vm_workstation point to the same elm object. */
+  msg_vm_t ind_vm = NULL;
   void *ind_vm_workstation =  NULL;
-  // Ask simix to create the surf vm resource
-  ind_vm_workstation = simcall_vm_create(name,ind_host);
-  new = (msg_vm_t) __MSG_host_create(ind_vm_workstation);
 
-  MSG_vm_set_property_value(new, "CORE_NB", bprintf("%d", core_nb), free);
-  MSG_vm_set_property_value(new, "MEM_CAP", bprintf("%d", mem_cap), free);
-  MSG_vm_set_property_value(new, "NET_CAP", bprintf("%d", net_cap), free);
+  // Ask simix to create the surf vm resource
+  ind_vm_workstation = simcall_vm_create(name, ind_pm);
+  ind_vm = (msg_vm_t) __MSG_host_create(ind_vm_workstation);
 
-  XBT_DEBUG("A new VM has been created");
-  // TODO check whether the vm (i.e the virtual host) has been correctly added into the list of all hosts.
+  XBT_DEBUG("A new VM (%s) has been created", name);
 
   #ifdef HAVE_TRACING
-  TRACE_msg_vm_create(name, ind_host);
+  TRACE_msg_vm_create(name, ind_pm);
   #endif
 
-  return new;
+  return ind_vm;
 }
 
+
 /** @brief Start a vm (ie. boot)
  *  @ingroup msg_VMs
  *
  *  If the VM cannot be started, an exception is generated.
  *
  */
-void MSG_vm_start(msg_vm_t vm) {
-
+void MSG_vm_start(msg_vm_t vm)
+{
   //Please note that vm start can raise an exception if the VM cannot be started.
   simcall_vm_start(vm);
 
@@ -276,9 +299,7 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t destination)
  * This function stops the exection of the VM. All the processes on this VM
  * will pause. The state of the VM is perserved. We can later resume it again.
  *
- * FIXME: No suspension cost occurs. If you want to simulate this too, you want to
- * use a \ref MSG_file_write() before or after, depending on the exact semantic
- * of VM suspend to you.
+ * No suspension cost occurs.
  */
 void MSG_vm_suspend(msg_vm_t vm)
 {
@@ -293,9 +314,7 @@ void MSG_vm_suspend(msg_vm_t vm)
 /** @brief Resume the execution of the VM. All processes on the VM run again.
  *  @ingroup msg_VMs
  *
- * FIXME: No resume cost occurs. If you want to simulate this too, you want to
- * use a \ref MSG_file_read() before or after, depending on the exact semantic
- * of VM resume to you.
+ * No resume cost occurs.
  */
 void MSG_vm_resume(msg_vm_t vm)
 {
index b3bcde9..d51ccfa 100644 (file)
@@ -295,9 +295,10 @@ void* simcall_vm_create(const char *name, smx_host_t phys_host){
  *
  * \param vm VM
  */
-void simcall_vm_start(smx_host_t vm) {
-  /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
-  simcall_BODY_vm_set_state(vm, msg_vm_state_running);
+void simcall_vm_start(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_start(vm);
 }
 
 /**
index a954b4a..ccd4a25 100644 (file)
@@ -45,41 +45,70 @@ smx_host_t SIMIX_vm_create(const char *name, smx_host_t ind_phys_host)
 
 
 smx_host_t SIMIX_pre_vm_create(smx_simcall_t simcall, const char *name, smx_host_t ind_phys_host){
-   return SIMIX_vm_create(name, ind_phys_host);
+  return SIMIX_vm_create(name, ind_phys_host);
 }
 
 
+static int get_host_property_as_integer(smx_host_t host, const char *name)
+{
+  xbt_dict_t dict = simix_host_get_properties(host);
+
+  char *value = xbt_dict_get_or_null(dict, name);
+  return atoi(value);
+}
+
+
+
 /* **** start a VM **** */
-static int __can_be_started(smx_host_t vm){
+static int __can_be_started(smx_host_t vm)
+{
        // TODO add checking code related to overcommitment or not.
+
+  int overcommit = get_host_property_as_integer("OverCommit");
+  int core_nb = get_host_property_as_integer("CORE_NB");
+  int mem_cap = get_host_property_as_integer("MEM_CAP");
+  int net_cap = get_host_property_as_integer("NET_CAP");
+
+  /* we need to get other VM objects on this physical host. */
+
+
+
        return 1;
 }
-void SIMIX_vm_start(smx_host_t ind_vm){
 
+void SIMIX_vm_start(smx_host_t ind_vm)
+{
   //TODO only start the VM if you can
   if (__can_be_started(ind_vm))
-         SIMIX_vm_set_state(ind_vm, msg_vm_state_running);
+    SIMIX_vm_set_state(ind_vm, msg_vm_state_running);
   else
-         THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(ind_vm));
+    THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(ind_vm));
 }
 
-void SIMIX_pre_vm_start(smx_simcall_t simcall, smx_host_t ind_vm){
-   SIMIX_vm_start(ind_vm);
+void SIMIX_pre_vm_start(smx_simcall_t simcall, smx_host_t ind_vm)
+{
+  SIMIX_vm_start(ind_vm);
 }
 
 /* ***** set/get state of a VM ***** */
-void SIMIX_vm_set_state(smx_host_t ind_vm, int state){
-       surf_vm_workstation_model->extension.vm_workstation.set_state(ind_vm, state);
+void SIMIX_vm_set_state(smx_host_t ind_vm, int state)
+{
+  surf_vm_workstation_model->extension.vm_workstation.set_state(ind_vm, state);
 }
-void SIMIX_pre_vm_set_state(smx_host_t ind_vm, int state){
-       SIMIX_vm_set_state(ind_vm, state);
+
+void SIMIX_pre_vm_set_state(smx_host_t ind_vm, int state)
+{
+  SIMIX_vm_set_state(ind_vm, state);
 }
 
-int SIMIX_vm_get_state(smx_host_t ind_vm){
- return surf_vm_workstation_model->extension.vm_workstation.get_state(ind_vm);
+int SIMIX_vm_get_state(smx_host_t ind_vm)
+{
+  return surf_vm_workstation_model->extension.vm_workstation.get_state(ind_vm);
 }
-int SIMIX_pre_vm_get_state(smx_host_t ind_vm){
-       return SIMIX_vm_get_state(ind_vm);
+
+int SIMIX_pre_vm_get_state(smx_host_t ind_vm)
+{
+  return SIMIX_vm_get_state(ind_vm);
 }
 
 
@@ -206,7 +235,7 @@ void SIMIX_vm_save(smx_host_t ind_vm)
 }
 
 void SIMIX_pre_vm_save(smx_simcall_t simcall, smx_host_t ind_vm){
-   SIMIX_vm_save(ind_vm);
+  SIMIX_vm_save(ind_vm);
 }
 
 
@@ -236,7 +265,7 @@ void SIMIX_vm_restore(smx_host_t ind_vm)
 }
 
 void SIMIX_pre_vm_restore(smx_simcall_t simcall, smx_host_t ind_vm){
-   SIMIX_vm_restore(ind_vm);
+  SIMIX_vm_restore(ind_vm);
 }
 
 
index 74bae72..5e3a613 100644 (file)
@@ -70,7 +70,7 @@ static void ws_action_cancel(surf_action_t action)
   if (action->model_type == surf_network_model)
     surf_network_model->action_cancel(action);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->action_cancel(action);
+    action->model_type->action_cancel(action);
   else if (action->model_type == surf_workstation_model)
     ws_parallel_action_cancel(action);
   else
@@ -84,7 +84,7 @@ static void ws_action_state_set(surf_action_t action,
   if (action->model_type == surf_network_model)
     surf_network_model->action_state_set(action, state);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->action_state_set(action, state);
+    action->model_type->action_state_set(action, state);
   else if (action->model_type == surf_workstation_model)
     surf_action_state_set(action, state);
   else
@@ -127,7 +127,7 @@ static void ws_action_suspend(surf_action_t action)
   if (action->model_type == surf_network_model)
     surf_network_model->suspend(action);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->suspend(action);
+    action->model_type->suspend(action);
   else
     DIE_IMPOSSIBLE;
 }
@@ -137,7 +137,7 @@ static void ws_action_resume(surf_action_t action)
   if (action->model_type == surf_network_model)
     surf_network_model->resume(action);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->resume(action);
+    action->model_type->resume(action);
   else
     DIE_IMPOSSIBLE;
 }
@@ -147,7 +147,7 @@ static int ws_action_is_suspended(surf_action_t action)
   if (action->model_type == surf_network_model)
     return surf_network_model->is_suspended(action);
   if (action->model_type == surf_cpu_model)
-    return surf_cpu_model->is_suspended(action);
+    return action->model_type->is_suspended(action);
   DIE_IMPOSSIBLE;
   return -1;
 }
@@ -158,7 +158,7 @@ static void ws_action_set_max_duration(surf_action_t action,
   if (action->model_type == surf_network_model)
     surf_network_model->set_max_duration(action, duration);
   else if (action->model_type == surf_cpu_model)
-         surf_cpu_model->set_max_duration(action, duration);
+    action->model_type->set_max_duration(action, duration);
   else
     DIE_IMPOSSIBLE;
 }
@@ -168,7 +168,7 @@ static void ws_action_set_priority(surf_action_t action, double priority)
   if (action->model_type == surf_network_model)
     surf_network_model->set_priority(action, priority);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->set_priority(action, priority);
+    action->model_type->set_priority(action, priority);
   else
     DIE_IMPOSSIBLE;
 }
@@ -179,7 +179,7 @@ static void ws_action_set_category(surf_action_t action, const char *category)
   if (action->model_type == surf_network_model)
     surf_network_model->set_category(action, category);
   else if (action->model_type == surf_cpu_model)
-    surf_cpu_model->set_category(action, category);
+    action->model_type->set_category(action, category);
   else
     DIE_IMPOSSIBLE;
 }
@@ -200,7 +200,7 @@ static double ws_action_get_remains(surf_action_t action)
   if (action->model_type == surf_network_model)
     return surf_network_model->get_remains(action);
   if (action->model_type == surf_cpu_model)
-    return surf_cpu_model->get_remains(action);
+    return action->model_type->get_remains(action);
   DIE_IMPOSSIBLE;
   return -1.0;
 }
@@ -218,20 +218,20 @@ static surf_action_t ws_communicate(void *workstation_src,
 
 static e_surf_resource_state_t ws_get_state(void *workstation)
 {
-  return surf_cpu_model->extension.cpu.
-      get_state(workstation);
+  surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
+  return cpu->model->extension.cpu.get_state(workstation);
 }
 
 static double ws_get_speed(void *workstation, double load)
 {
-  return surf_cpu_model->extension.cpu.
-      get_speed(workstation, load);
+  surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
+  return cpu->model->extension.cpu.get_speed(workstation, load);
 }
 
 static double ws_get_available_speed(void *workstation)
 {
-  return surf_cpu_model->extension.cpu.
-      get_available_speed(workstation);
+  surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
+  return cpu->model->extension.cpu.get_available_speed(workstation);
 }
 
 static surf_action_t ws_execute_parallel_task(int workstation_nb,