+ XBT_DEBUG("mig-stage2.%d: remaining_size %f (%s threshold %f)", stage2_round, remaining_size,
+ (remaining_size < threshold) ? "<" : ">", threshold);
+ if (remaining_size < threshold)
+ break;
+
+ sg_size_t sent = 0;
+ double clock_prev_send = MSG_get_clock();
+ try {
+ XBT_DEBUG("Stage 2, gonna send %llu", updated_size);
+ sent = send_migration_data(ms->vm, ms->src_pm, ms->dst_pm, updated_size, ms->mbox, 2, stage2_round, mig_speed,
+ mig_timeout);
+ } catch (xbt_ex& e) {
+ // hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data
+ // code)
+ // Stop the dirty page tracking an return (there is no memory space to release)
+ stop_dirty_page_tracking(ms->vm);
+ return 0;
+ }
+ double clock_post_send = MSG_get_clock();
+
+ if (sent == updated_size) {
+ /* timeout did not happen */
+ double bandwidth = updated_size / (clock_post_send - clock_prev_send);
+ threshold = get_threshold_value(bandwidth, max_downtime);
+ XBT_DEBUG("actual bandwidth %f, threshold %f", bandwidth / 1024 / 1024, threshold);
+ remaining_size -= sent;
+ stage2_round += 1;
+ mig_timeout -= (clock_post_send - clock_prev_send);
+ xbt_assert(mig_timeout > 0);
+
+ } else if (sent < updated_size) {
+ /* When timeout happens, we move to stage 3. The size of memory pages
+ * updated before timeout must be added to the remaining size. */
+ XBT_VERB("mig-stage2.%d: timeout, force moving to stage 3. sent %llu / %llu, eta %lf", stage2_round, sent,
+ updated_size, (clock_post_send - clock_prev_send));
+ remaining_size -= sent;
+
+ double computed = lookup_computed_flop_counts(ms->vm, 2, stage2_round);
+ updated_size = get_updated_size(computed, dp_rate, dp_cap);
+ remaining_size += updated_size;
+ break;
+ } else
+ XBT_CRITICAL("bug");
+ }