Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dict to map in vms
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 12 Jul 2017 08:05:14 +0000 (10:05 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 12 Jul 2017 08:05:14 +0000 (10:05 +0200)
src/msg/msg_vm.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp

index 79ebf4e..2eb403d 100644 (file)
@@ -365,18 +365,15 @@ static int migration_rx_fun(int argc, char *argv[])
 static void start_dirty_page_tracking(msg_vm_t vm)
 {
   vm->pimpl_vm_->dp_enabled = 1;
-  if (not vm->pimpl_vm_->dp_objs)
+  if (vm->pimpl_vm_->dp_objs.empty())
     return;
 
-  char *key = nullptr;
-  xbt_dict_cursor_t cursor = nullptr;
-  dirty_page_t dp = nullptr;
-  xbt_dict_foreach (vm->pimpl_vm_->dp_objs, cursor, key, dp) {
+  for (auto elm : vm->pimpl_vm_->dp_objs) {
+    dirty_page_t dp    = elm.second;
     double remaining = MSG_task_get_flops_amount(dp->task);
     dp->prev_clock = MSG_get_clock();
     dp->prev_remaining = remaining;
-
-    // XBT_INFO("%s@%s remaining %f", key, sg_host_name(vm), remaining);
+    XBT_DEBUG("%s@%s remaining %f", elm.first.c_str(), vm->getCname(), remaining);
   }
 }
 
@@ -385,7 +382,7 @@ static void stop_dirty_page_tracking(msg_vm_t vm)
   vm->pimpl_vm_->dp_enabled = 0;
 }
 
-static double get_computed(char *key, msg_vm_t vm, dirty_page_t dp, double remaining, double clock)
+static double get_computed(const char* key, msg_vm_t vm, dirty_page_t dp, double remaining, double clock)
 {
   double computed = dp->prev_remaining - remaining;
   double duration = clock - dp->prev_clock;
@@ -400,10 +397,9 @@ static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug
 {
   double total = 0;
 
-  char *key = nullptr;
-  xbt_dict_cursor_t cursor = nullptr;
-  dirty_page_t dp = nullptr;
-  xbt_dict_foreach (vm->pimpl_vm_->dp_objs, cursor, key, dp) {
+  for (auto elm : vm->pimpl_vm_->dp_objs) {
+    const char* key  = elm.first.c_str();
+    dirty_page_t dp  = elm.second;
     double remaining = MSG_task_get_flops_amount(dp->task);
 
     double clock = MSG_get_clock();
@@ -443,10 +439,7 @@ void MSG_host_add_task(msg_host_t host, msg_task_t task)
     dp->prev_clock = MSG_get_clock();
     dp->prev_remaining = remaining;
   }
-  if (not vm->pimpl_vm_->dp_objs)
-    vm->pimpl_vm_->dp_objs = xbt_dict_new_homogeneous(nullptr);
-  xbt_assert(xbt_dict_get_or_null(vm->pimpl_vm_->dp_objs, key) == nullptr);
-  xbt_dict_set(vm->pimpl_vm_->dp_objs, key, dp, nullptr);
+  vm->pimpl_vm_->dp_objs.insert({key, dp});
   XBT_DEBUG("add %s on %s (remaining %f, dp_enabled %d)", key, host->getCname(), remaining, vm->pimpl_vm_->dp_enabled);
 
   xbt_free(key);
@@ -459,8 +452,10 @@ void MSG_host_del_task(msg_host_t host, msg_task_t task)
     return;
 
   char *key = bprintf("%s-%p", task->name, task);
-  dirty_page_t dp = (dirty_page_t)(vm->pimpl_vm_->dp_objs ? xbt_dict_get_or_null(vm->pimpl_vm_->dp_objs, key) : NULL);
-  xbt_assert(dp->task == task);
+  dirty_page_t dp = nullptr;
+  if (vm->pimpl_vm_->dp_objs.find(key) != vm->pimpl_vm_->dp_objs.end())
+    dp = vm->pimpl_vm_->dp_objs.at(key);
+  xbt_assert(dp && dp->task == task);
 
   /* If we are in the middle of dirty page tracking, we record how much computation has been done until now, and keep
    * the information for the lookup_() function that will called soon. */
@@ -472,8 +467,8 @@ void MSG_host_del_task(msg_host_t host, msg_task_t task)
 
     vm->pimpl_vm_->dp_updated_by_deleted_tasks += updated;
   }
-  if (vm->pimpl_vm_->dp_objs)
-    xbt_dict_remove(vm->pimpl_vm_->dp_objs, key);
+
+  vm->pimpl_vm_->dp_objs.erase(key);
   xbt_free(dp);
 
   XBT_DEBUG("del %s on %s", key, host->getCname());
index 019fd79..a3b4a0a 100644 (file)
@@ -126,21 +126,18 @@ VirtualMachineImpl::~VirtualMachineImpl()
     allVms_.erase(iter);
 
   /* dirty page tracking */
-  unsigned int size          = xbt_dict_size(dp_objs);
+  unsigned int size          = dp_objs.size();
   static bool already_warned = false;
   if (size > 0 && not already_warned) {
-    xbt_dict_cursor_t cursor = nullptr;
-    xbt_dict_cursor_first(dp_objs, &cursor);
+    auto front = dp_objs.begin();
     XBT_WARN("Dirty page tracking: %u pending task(s) on a destroyed VM (first one is %s).\n"
              "If you don't understand why your task was not properly removed, please report that bug.\n"
              "This is a known bug if you turned the host off during the VM execution.\n"
              "Please remind us of that problem at some point: our code base is not ready to fix this harmless issue in "
              "2016, sorry.",
-             size, (xbt_log_no_loc ? "(name hidden)" : xbt_dict_cursor_get_key(cursor)));
-    xbt_dict_cursor_free(&cursor);
+             size, (xbt_log_no_loc ? "(name hidden)" : front->first.c_str()));
     already_warned = true;
   }
-  xbt_dict_free(&dp_objs);
 
   /* Free the cpu_action of the VM. */
   XBT_ATTRIB_UNUSED int ret = action_->unref();
index 797bfb0..1063bf1 100644 (file)
@@ -8,6 +8,7 @@
 #include "src/surf/HostImpl.hpp"
 #include <algorithm>
 #include <deque>
+#include <unordered_map>
 
 #ifndef VM_INTERFACE_HPP_
 #define VM_INTERFACE_HPP_
@@ -15,6 +16,8 @@
 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
                           // It corresponds to the cost of a VM running no tasks.
 
+typedef struct dirty_page* dirty_page_t;
+
 namespace simgrid {
 namespace vm {
 
@@ -86,8 +89,8 @@ public:
   surf::Action* action_ = nullptr;
 
   /* Dirty pages stuff */
+  std::unordered_map<std::string, dirty_page_t> dp_objs;
   int dp_enabled                     = 0;
-  xbt_dict_t dp_objs                 = nullptr;
   double dp_updated_by_deleted_tasks = 0;
 
 protected: