From 5a469c9dca9ce25cee1a52682d7eb7bbd736a49b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 17 May 2018 14:43:57 +0200 Subject: [PATCH] Reduce the foreign usages of s4u::Host::pimpl_cpu, which should be private --- include/simgrid/forward.h | 4 ++++ include/simgrid/s4u/Host.hpp | 6 ++++-- src/plugins/vm/VirtualMachineImpl.cpp | 1 - src/plugins/vm/s4u_VirtualMachine.cpp | 11 +++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 8f0fd64f36..4ce7e57926 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -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; diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index c0f9ffba83..4ce6a6aa8f 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -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 { + 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* 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; }; diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 6f9fe0b9a7..326fde567a 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -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 diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 8d83e9b75b..d6036369a5 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -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(pm->pimpl_cpu); + std::vector* speeds = new std::vector(); + 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(new simgrid::simix::Host()); -- 2.20.1