Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the foreign usages of s4u::Host::pimpl_cpu, which should be private
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 17 May 2018 12:43:57 +0000 (14:43 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 17 May 2018 13:07:02 +0000 (15:07 +0200)
include/simgrid/forward.h
include/simgrid/s4u/Host.hpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/s4u_VirtualMachine.cpp

index 8f0fd64..4ce7e57 100644 (file)
@@ -121,6 +121,10 @@ namespace trace_mgr {
   class trace;
   class future_evt_set;
 }
+namespace vm {
+class VMModel;
+class VirtualMachineImpl;
+} // namespace vm
 } // namespace simgrid
 
 typedef simgrid::s4u::Actor s4u_Actor;
index c0f9ffb..4ce6a6a 100644 (file)
@@ -35,6 +35,8 @@ namespace s4u {
  * and actors can retrieve the host on which they run using simgrid::s4u::Host::current().
  */
 class XBT_PUBLIC Host : public simgrid::xbt::Extendable<Host> {
+  friend simgrid::vm::VMModel;            // Use the pimpl_cpu to compute the VM sharing
+  friend simgrid::vm::VirtualMachineImpl; // creates the the pimpl_cpu
 
 public:
   explicit Host(const char* name);
@@ -146,10 +148,10 @@ private:
   std::unordered_map<std::string, Storage*>* mounts_ = nullptr; // caching
 
 public:
-  // TODO, this could be a unique_ptr
-  surf::HostImpl* pimpl_ = nullptr;
   /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
   surf::Cpu* pimpl_cpu = nullptr;
+  // TODO, this could be a unique_ptr
+  surf::HostImpl* pimpl_ = nullptr;
   /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
   kernel::routing::NetPoint* pimpl_netpoint = nullptr;
 };
index 6f9fe0b..326fde5 100644 (file)
@@ -90,7 +90,6 @@ double VMModel::next_occuring_event(double now)
   /* iterate for all virtual machines */
   for (s4u::VirtualMachine* const& ws_vm : VirtualMachineImpl::allVms_) {
     surf::Cpu* cpu = ws_vm->pimpl_cpu;
-    xbt_assert(cpu, "cpu-less host");
 
     double solved_value =
         ws_vm->getImpl()->action_->get_variable()->get_value(); // this is X1 in comment above, what
index 8d83e9b..d603636 100644 (file)
@@ -33,12 +33,15 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount,
 
   /* Currently, a VM uses the network resource of its physical host */
   pimpl_netpoint = pm->pimpl_netpoint;
+
   // Create a VCPU for this VM
-  surf::CpuCas01* sub_cpu = dynamic_cast<surf::CpuCas01*>(pm->pimpl_cpu);
+  std::vector<double>* speeds = new std::vector<double>();
+  for (int i = 0; i < pm->getPstatesCount(); i++)
+    speeds->push_back(pm->getPstateSpeed(i));
 
-  pimpl_cpu = surf_cpu_model_vm->createCpu(this, sub_cpu->getSpeedPeakList(), coreAmount);
-  if (sub_cpu->getPState() != 0)
-    pimpl_cpu->setPState(sub_cpu->getPState());
+  surf_cpu_model_vm->createCpu(this, speeds, pm->getCoreCount());
+  if (pm->getPstate() != 0)
+    setPstate(pm->getPstate());
 
   /* Make a process container */
   extension_set<simgrid::simix::Host>(new simgrid::simix::Host());