Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
code simplifications in VMs
[simgrid.git] / src / surf / virtual_machine.cpp
index 7582f29..794ec01 100644 (file)
@@ -50,7 +50,7 @@ s4u::Host *VMModel::createVM(const char *name, sg_host_t host_PM)
 // const double virt_overhead = 0.95;
 const double virt_overhead = 1;
 
-double VMModel::next_occuring_event(double now)
+double VMModel::nextOccuringEvent(double now)
 {
   /* TODO: update action's cost with the total cost of processes on the VM. */
 
@@ -95,7 +95,7 @@ double VMModel::next_occuring_event(double now)
   adjustWeightOfDummyCpuActions();
 
   /* 3. Ready. Get the next occuring event */
-  return surf_cpu_model_vm->next_occuring_event(now);
+  return surf_cpu_model_vm->nextOccuringEvent(now);
 }
 
 
@@ -103,35 +103,27 @@ double VMModel::next_occuring_event(double now)
  * Resource *
  ************/
 
-VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u::Host *host_PM)
-: HostImpl(model, name, nullptr, nullptr, nullptr)
-, hostPM_(host_PM)
+VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u::Host* host_PM)
+    : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/, nullptr /*cpu*/), hostPM_(host_PM)
 {
   /* Register this VM to the list of all VMs */
   allVms_.push_back(this);
-  piface_ = simgrid::s4u::Host::by_name_or_create(name);
+  piface_ = new simgrid::s4u::Host(name);
   piface_->extension_set<simgrid::surf::HostImpl>(this);
 
-  /* Currently, we assume a VM has no storage. */
-  storage_ = nullptr;
-
   /* Currently, a VM uses the network resource of its physical host. In
    * host_lib, this network resource object is referred 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. */
-  sg_host_t host_VM = simgrid::s4u::Host::by_name_or_create(name);
-  host_VM->pimpl_netcard = host_PM->pimpl_netcard;
-
-  vmState_ = SURF_VM_STATE_CREATED;
+  piface_->pimpl_netcard = host_PM->pimpl_netcard;
 
   // //// CPU  RELATED STUFF ////
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   CpuCas01 *sub_cpu = dynamic_cast<CpuCas01*>(host_PM->pimpl_cpu);
 
-  cpu_ = surf_cpu_model_vm->createCpu(host_VM, // the machine hosting the VM
-      sub_cpu->getSpeedPeakList(), 1 /*cores*/);
+  cpu_ = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
   if (sub_cpu->getPState() != 0)
     cpu_->setPState(sub_cpu->getPState());