Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ActivityImplPtr are not part of any C struct, only C++ classes
[simgrid.git] / src / msg / msg_vm.cpp
index 4ba7663..8d59a21 100644 (file)
@@ -58,7 +58,8 @@ void MSG_vm_get_params(msg_vm_t vm, vm_params_t params)
 /* **** Check state of a VM **** */
 static inline int __MSG_vm_is_state(msg_vm_t vm, e_surf_vm_state_t state)
 {
-  return static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getState() == state;
+  simgrid::s4u::VirtualMachine* castedVm = static_cast<simgrid::s4u::VirtualMachine*>(vm);
+  return castedVm->pimpl_vm_ != nullptr && castedVm->pimpl_vm_->getState() == state;
 }
 
 /** @brief Returns whether the given VM has just created, not running.
@@ -98,11 +99,12 @@ int MSG_vm_is_suspended(msg_vm_t vm)
  *  @ingroup msg_VMs*
  *  @param pm        Physical machine that will host the VM
  *  @param name      Must be unique
+ *  @param coreAmount Must be >= 1
  *  @param ramsize   [TODO]
  *  @param mig_netspeed Amount of Mbyte/s allocated to the migration (cannot be larger than net_cap). Use 0 if unsure.
  *  @param dp_intensity Dirty page percentage according to migNetSpeed, [0-100]. Use 0 if unsure.
  */
-msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int ramsize, int mig_netspeed, int dp_intensity)
+msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int coreAmount, int ramsize, int mig_netspeed, int dp_intensity)
 {
   simgrid::vm::VmHostExt::ensureVmExtInstalled();
 
@@ -110,7 +112,7 @@ msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int ramsize, int mig_net
   double host_speed = MSG_host_get_speed(pm);
   double update_speed = (static_cast<double>(dp_intensity)/100) * mig_netspeed;
 
-  msg_vm_t vm = MSG_vm_create_core(pm, name);
+  msg_vm_t vm = MSG_vm_create_multicore(pm, name, coreAmount);
   s_vm_params_t params;
   memset(&params, 0, sizeof(params));
   params.ramsize = static_cast<sg_size_t>(ramsize) * 1024 * 1024;
@@ -128,7 +130,7 @@ msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int ramsize, int mig_net
   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().
+/** @brief Create a new VM object with the default parameters
  *  @ingroup msg_VMs*
  *
  * A VM is treated as a host. The name of the VM must be unique among all hosts.
@@ -138,7 +140,19 @@ msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name)
   xbt_assert(sg_host_by_name(name) == nullptr,
              "Cannot create a VM named %s: this name is already used by an host or a VM", name);
 
-  return new simgrid::s4u::VirtualMachine(name, pm);
+  return new simgrid::s4u::VirtualMachine(name, pm, 1);
+}
+/** @brief Create a new VM object with the default parameters, but with a specified amount of cores
+ *  @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_multicore(msg_host_t pm, const char* name, int coreAmount)
+{
+  xbt_assert(sg_host_by_name(name) == nullptr,
+             "Cannot create a VM named %s: this name is already used by an host or a VM", name);
+
+  return new simgrid::s4u::VirtualMachine(name, pm, coreAmount);
 }
 
 /** @brief Destroy a VM. Destroy the VM object from the simulation.
@@ -153,9 +167,6 @@ void MSG_vm_destroy(msg_vm_t vm)
   if (MSG_vm_is_running(vm))
     MSG_vm_shutdown(vm);
 
-  xbt_assert(MSG_vm_is_created(vm) || __MSG_vm_is_state(vm, SURF_VM_STATE_DESTROYED),
-             "shutdown the given VM before destroying it");
-
   /* Then, destroy the VM object */
   simgrid::simix::kernelImmediate([vm]() {
     vm->destroy();
@@ -171,7 +182,7 @@ void MSG_vm_destroy(msg_vm_t vm)
 /** @brief Start a vm (i.e., boot the guest operating system)
  *  @ingroup msg_VMs
  *
- *  If the VM cannot be started (because of memory overprovisionning), an exception is generated.
+ *  If the VM cannot be started (because of memory over-provisioning), an exception is generated.
  */
 void MSG_vm_start(msg_vm_t vm)
 {