-static void start_dirty_page_tracking(msg_vm_t vm)
-{
- vm->pimpl_vm_->dp_enabled = true;
- if (vm->pimpl_vm_->dp_objs.empty())
- return;
-
- for (auto const& 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_DEBUG("%s@%s remaining %f", elm.first.c_str(), vm->getCname(), remaining);
- }
-}
-
-static void stop_dirty_page_tracking(msg_vm_t vm)
-{
- vm->pimpl_vm_->dp_enabled = false;
-}
-
-static double get_computed(const std::string& 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;
-
- XBT_DEBUG("%s@%s: computed %f ops (remaining %f -> %f) in %f secs (%f -> %f)", key.c_str(), vm->getCname(), computed,
- dp->prev_remaining, remaining, duration, dp->prev_clock, clock);
-
- return computed;
-}
-
-static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug, int stage2_round_for_fancy_debug)
-{
- double total = 0;
-
- for (auto const& elm : vm->pimpl_vm_->dp_objs) {
- const std::string& key = elm.first;
- dirty_page_t dp = elm.second;
- double remaining = MSG_task_get_flops_amount(dp->task);
-
- double clock = MSG_get_clock();
-
- total += get_computed(key, vm, dp, remaining, clock);
-
- dp->prev_remaining = remaining;
- dp->prev_clock = clock;
- }
-
- total += vm->pimpl_vm_->dp_updated_by_deleted_tasks;
-
- XBT_DEBUG("mig-stage%d.%d: computed %f flop_counts (including %f by deleted tasks)", stage_for_fancy_debug,
- stage2_round_for_fancy_debug, total, vm->pimpl_vm_->dp_updated_by_deleted_tasks);
-
- vm->pimpl_vm_->dp_updated_by_deleted_tasks = 0;
-
- return total;
-}
-
-// TODO Is this code redundant with the information provided by
-// msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host)
-/** @brief take care of the dirty page tracking, in case we're adding a task to a migrating VM */
-void MSG_host_add_task(msg_host_t host, msg_task_t task)
-{
- simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
- if (vm == nullptr)
- return;
-
- double remaining = MSG_task_get_flops_amount(task);
- std::string key = simgrid::xbt::string_printf("%s-%p", task->name, task);
-
- dirty_page_t dp = new s_dirty_page;
- dp->task = task;
- if (vm->pimpl_vm_->dp_enabled) {
- dp->prev_clock = MSG_get_clock();
- dp->prev_remaining = remaining;
- }
- vm->pimpl_vm_->dp_objs.insert({key, dp});
- XBT_DEBUG("add %s on %s (remaining %f, dp_enabled %d)", key.c_str(), host->getCname(), remaining,
- vm->pimpl_vm_->dp_enabled);
-}
-
-void MSG_host_del_task(msg_host_t host, msg_task_t task)
-{
- simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
- if (vm == nullptr)
- return;
-
- std::string key = simgrid::xbt::string_printf("%s-%p", task->name, task);
- dirty_page_t dp = nullptr;
- auto dp_obj = vm->pimpl_vm_->dp_objs.find(key);
- if (dp_obj != vm->pimpl_vm_->dp_objs.end())
- dp = dp_obj->second;
- 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. */
- if (vm->pimpl_vm_->dp_enabled) {
- double remaining = MSG_task_get_flops_amount(task);
- double clock = MSG_get_clock();
- double updated = get_computed(key, vm, dp, remaining, clock); // was host instead of vm
-
- vm->pimpl_vm_->dp_updated_by_deleted_tasks += updated;
- }
-
- vm->pimpl_vm_->dp_objs.erase(key);
- delete dp;
-
- XBT_DEBUG("del %s on %s", key.c_str(), host->getCname());
-}
-