Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a deque instead of an intrusive hook for all VMs
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Aug 2016 20:32:12 +0000 (22:32 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Aug 2016 20:39:11 +0000 (22:39 +0200)
- This is much simpler this way.
- Also, put it in the VirtualMachine class, not the Model one.

src/surf/HostImpl.cpp
src/surf/virtual_machine.cpp
src/surf/virtual_machine.hpp
src/surf/vm_hl13.cpp

index 010d319..d4ae879 100644 (file)
@@ -44,11 +44,8 @@ HostImpl *HostModel::createHost(const char *name, kernel::routing::NetCard *netE
 void HostModel::adjustWeightOfDummyCpuActions()
 {
   /* iterate for all virtual machines */
 void HostModel::adjustWeightOfDummyCpuActions()
 {
   /* iterate for all virtual machines */
-  for (VMModel::vm_list_t::iterator iter =
-         VMModel::ws_vms.begin();
-       iter !=  VMModel::ws_vms.end(); ++iter) {
+  for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
 
 
-    VirtualMachine *ws_vm = &*iter;
     Cpu *cpu = ws_vm->p_cpu;
 
     int is_active = lmm_constraint_used(cpu->getModel()->getMaxminSystem(), cpu->getConstraint());
     Cpu *cpu = ws_vm->p_cpu;
 
     int is_active = lmm_constraint_used(cpu->getModel()->getMaxminSystem(), cpu->getConstraint());
@@ -379,13 +376,8 @@ xbt_dynar_t HostImpl::getVms()
 {
   xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachine*), nullptr);
 
 {
   xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachine*), nullptr);
 
-  /* iterate for all virtual machines */
-  for (simgrid::surf::VMModel::vm_list_t::iterator iter =
-         simgrid::surf::VMModel::ws_vms.begin();
-       iter !=  simgrid::surf::VMModel::ws_vms.end(); ++iter) {
-
-    simgrid::surf::VirtualMachine *ws_vm = &*iter;
-    if (this == ws_vm->getPm()->extension(simgrid::surf::HostImpl::EXTENSION_ID))
+  for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
+    if (this == ws_vm->getPm()->extension<simgrid::surf::HostImpl>())
       xbt_dynar_push(dyn, &ws_vm);
   }
 
       xbt_dynar_push(dyn, &ws_vm);
   }
 
index 5e333c0..1666df5 100644 (file)
@@ -28,7 +28,7 @@ simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmStateChange;
  * Model *
  *********/
 
  * Model *
  *********/
 
-VMModel::vm_list_t VMModel::ws_vms;
+std::deque<VirtualMachine*> VirtualMachine::allVms_;
 
 /************
  * Resource *
 
 /************
  * Resource *
@@ -38,7 +38,7 @@ VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u:
 : HostImpl(model, name, nullptr, nullptr, nullptr)
 , hostPM_(hostPM)
 {
 : HostImpl(model, name, nullptr, nullptr, nullptr)
 , hostPM_(hostPM)
 {
-  VMModel::ws_vms.push_back(*this);
+  allVms_.push_back(this);
   piface = simgrid::s4u::Host::by_name_or_create(name);
   piface->extension_set<simgrid::surf::HostImpl>(this);
 }
   piface = simgrid::s4u::Host::by_name_or_create(name);
   piface->extension_set<simgrid::surf::HostImpl>(this);
 }
@@ -49,7 +49,8 @@ VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u:
 VirtualMachine::~VirtualMachine()
 {
   onVmDestruction(this);
 VirtualMachine::~VirtualMachine()
 {
   onVmDestruction(this);
-  VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this));
+  allVms_.erase( find(allVms_.begin(), allVms_.end(), this) );
+
   /* Free the cpu_action of the VM. */
   XBT_ATTRIB_UNUSED int ret = action_->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
   /* Free the cpu_action of the VM. */
   XBT_ATTRIB_UNUSED int ret = action_->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
index d5cc175..d75e480 100644 (file)
@@ -4,6 +4,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include <deque>
 #include <boost/intrusive/list.hpp>
 
 #include <xbt/base.h>
 #include <boost/intrusive/list.hpp>
 
 #include <xbt/base.h>
@@ -89,11 +90,10 @@ public:
 
   e_surf_vm_state_t getState();
   void setState(e_surf_vm_state_t state);
 
   e_surf_vm_state_t getState();
   void setState(e_surf_vm_state_t state);
+  static std::deque<VirtualMachine*> allVms_;
+
 protected:
   e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
 protected:
   e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
-
-public:
-  boost::intrusive::list_member_hook<> vm_hook;
 };
 
 /*********
 };
 
 /*********
@@ -116,11 +116,6 @@ public:
    */
   virtual s4u::Host *createVM(const char *name, sg_host_t host_PM)=0;
   void adjustWeightOfDummyCpuActions() {};
    */
   virtual s4u::Host *createVM(const char *name, sg_host_t host_PM)=0;
   void adjustWeightOfDummyCpuActions() {};
-
-  typedef boost::intrusive::member_hook<
-    VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
-  typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
-  static vm_list_t ws_vms;
 };
 
 }
 };
 
 }
index 5328921..9dd72aa 100644 (file)
@@ -67,8 +67,7 @@ double VMHL13Model::next_occuring_event(double now)
    **/
 
   /* iterate for all virtual machines */
    **/
 
   /* iterate for all virtual machines */
-  for (VMModel::vm_list_t::iterator iter = VMModel::ws_vms.begin(); iter !=  VMModel::ws_vms.end(); ++iter) {
-    VirtualMachine *ws_vm = &*iter;
+  for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
     Cpu *cpu = ws_vm->p_cpu;
     xbt_assert(cpu, "cpu-less host");
 
     Cpu *cpu = ws_vm->p_cpu;
     xbt_assert(cpu, "cpu-less host");