X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/10d24bfbe5d413bdb49bf12b9655fc73203cd4f0..87116782db3154fb79cd353db446bd226cf15976:/src/msg/msg_vm.c diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index a2786ac778..c4cb96d6ed 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -16,6 +16,7 @@ #include "xbt/sysdep.h" #include "xbt/log.h" #include "simgrid/platf.h" +#include "simgrid/host.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API"); @@ -75,7 +76,7 @@ void MSG_vm_set_property_value(msg_vm_t vm, const char *name, void *value, void_ msg_vm_t MSG_vm_get_by_name(const char *name) { - return MSG_get_host_by_name(name); + return MSG_host_by_name(name); } /** \ingroup m_vm_management @@ -118,7 +119,7 @@ int MSG_vm_is_running(msg_vm_t vm) */ int MSG_vm_is_migrating(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); return priv->is_migrating; } @@ -163,21 +164,26 @@ int MSG_vm_is_restoring(msg_vm_t vm) /** @brief Create a new VM with specified parameters. * @ingroup msg_VMs* - * All parameters are in MBytes + * @param pm Physical machine that will host the VM + * @param net_cap Maximal bandwidth that the VM can consume (in MByte/s) + * @param disk_path (unused) Path to the image that boots + * @param disksize (unused) will represent the size of the VM (will be used during migrations) + * @param mig_netspeed Amount of Mbyte/s allocated to the migration (cannot be larger than net_cap). Use 0 if unsure. + * @param dp_intensity Dirty page percentage according to migNetSpeed, [0-100]. Use 0 if unsure. * */ -msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char *name, +msg_vm_t MSG_vm_create(msg_host_t pm, const char *name, int ncpus, int ramsize, int net_cap, char *disk_path, int disksize, int mig_netspeed, int dp_intensity) { /* For the moment, intensity_rate is the percentage against the migration * bandwidth */ - double host_speed = MSG_get_host_speed(ind_pm); + double host_speed = MSG_get_host_speed(pm); double update_speed = ((double)dp_intensity/100) * mig_netspeed; - msg_vm_t vm = MSG_vm_create_core(ind_pm, name); - s_ws_params_t params; + msg_vm_t vm = MSG_vm_create_core(pm, name); + s_vm_params_t params; memset(¶ms, 0, sizeof(params)); params.ramsize = (sg_size_t)ramsize * 1024 * 1024; //params.overcommit = 0; @@ -205,7 +211,7 @@ msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name) /* make sure the VM of the same name does not exit */ { xbt_dictelm_t ind_host_tmp = xbt_lib_get_elm_or_null(host_lib, name); - if (ind_host_tmp && xbt_lib_get_level(ind_host_tmp, SIMIX_HOST_LEVEL) != NULL) { + if (ind_host_tmp && sg_host_simix(ind_host_tmp) != NULL) { XBT_ERROR("host %s already exits", name); return NULL; } @@ -353,7 +359,7 @@ static int migration_rx_fun(int argc, char *argv[]) // The structure has been created in the do_migration function and should only be freed in the same place ;) struct migration_session *ms = MSG_process_get_data(MSG_process_self()); - s_ws_params_t params; + s_vm_params_t params; simcall_host_get_params(ms->vm, ¶ms); int need_exit = 0; @@ -390,23 +396,25 @@ static int migration_rx_fun(int argc, char *argv[]) msg_vm_t vm = ms->vm; msg_host_t src_pm = ms->src_pm; msg_host_t dst_pm = ms-> dst_pm; - msg_host_priv_t priv = msg_host_resource_priv(vm); - -// TODO: we have an issue, if the DST node is turning off during the three next calls, then the VM is in an inconsistent state -// I should check with Takahiro in order to make this portion of code atomic - /* deinstall the current affinity setting for the CPU */ - simcall_vm_set_affinity(vm, src_pm, 0); - - /* Update the vm location */ - simcall_vm_migrate(vm, dst_pm); - - /* Resume the VM */ - simcall_vm_resume(vm); + msg_host_priv_t priv = sg_host_msg(vm); + +// // TODO: we have an issue, if the DST node is turning off during the three next calls, then the VM is in an inconsistent state +// // I should check with Takahiro in order to make this portion of code atomic +// /* deinstall the current affinity setting for the CPU */ +// simcall_vm_set_affinity(vm, src_pm, 0); +// +// /* Update the vm location */ +// simcall_vm_migrate(vm, dst_pm); +// +// /* Resume the VM */ +// simcall_vm_resume(vm); +// + simcall_vm_migratefrom_resumeto(vm, src_pm, dst_pm); /* install the affinity setting of the VM on the destination pm */ { - unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(priv->affinity_mask_db, (char *)dst_pm, sizeof(msg_host_t)); + unsigned long affinity_mask = (unsigned long)(uintptr_t) xbt_dict_get_or_null_ext(priv->affinity_mask_db, (char *)dst_pm, sizeof(msg_host_t)); simcall_vm_set_affinity(vm, dst_pm, affinity_mask); XBT_DEBUG("set affinity(0x%04lx@%s) for %s", affinity_mask, MSG_host_get_name(dst_pm), MSG_host_get_name(vm)); } @@ -414,7 +422,7 @@ static int migration_rx_fun(int argc, char *argv[]) { // Now the VM is running on the new host (the migration is completed) (even if the SRC crash) - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->is_migrating = 0; XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", ms->vm->key, ms->src_pm->key, ms->dst_pm->key); TRACE_msg_vm_change_host(ms->vm, ms->src_pm, ms->dst_pm); @@ -447,7 +455,7 @@ static int migration_rx_fun(int argc, char *argv[]) static void reset_dirty_pages(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); char *key = NULL; xbt_dict_cursor_t cursor = NULL; @@ -463,7 +471,7 @@ static void reset_dirty_pages(msg_vm_t vm) static void start_dirty_page_tracking(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->dp_enabled = 1; reset_dirty_pages(vm); @@ -471,7 +479,7 @@ static void start_dirty_page_tracking(msg_vm_t vm) static void stop_dirty_page_tracking(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->dp_enabled = 0; } @@ -507,7 +515,7 @@ static double get_computed(char *key, msg_vm_t vm, dirty_page_t dp, double remai static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug, int stage2_round_for_fancy_debug) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); double total = 0; char *key = NULL; @@ -544,7 +552,7 @@ static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug // msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host) void MSG_host_add_task(msg_host_t host, msg_task_t task) { - msg_host_priv_t priv = msg_host_resource_priv(host); + msg_host_priv_t priv = sg_host_msg(host); double remaining = MSG_task_get_flops_amount(task); char *key = bprintf("%s-%p", task->name, task); @@ -566,7 +574,7 @@ void MSG_host_add_task(msg_host_t host, msg_task_t task) void MSG_host_del_task(msg_host_t host, msg_task_t task) { - msg_host_priv_t priv = msg_host_resource_priv(host); + msg_host_priv_t priv = sg_host_msg(host); char *key = bprintf("%s-%p", task->name, task); @@ -601,7 +609,7 @@ static sg_size_t send_migration_data(msg_vm_t vm, msg_host_t src_pm, msg_host_t { sg_size_t sent = 0; char *task_name = get_mig_task_name(vm, src_pm, dst_pm, stage); - msg_task_t task = MSG_task_create(task_name, 0, size, NULL); + msg_task_t task = MSG_task_create(task_name, 0, (double)size, NULL); /* TODO: clean up */ @@ -618,7 +626,7 @@ static sg_size_t send_migration_data(msg_vm_t vm, msg_host_t src_pm, msg_host_t if (ret == MSG_OK) { sent = size; } else if (ret == MSG_TIMEOUT) { - sg_size_t remaining = MSG_task_get_remaining_communication(task); + sg_size_t remaining = (sg_size_t)MSG_task_get_remaining_communication(task); sent = size - remaining; XBT_INFO("timeout (%lf s) in sending_migration_data, remaining %llu bytes of %llu", timeout, remaining, size); @@ -696,7 +704,7 @@ static int migration_tx_fun(int argc, char *argv[]) // Note that the ms structure has been allocated in do_migration and hence should be freed in the same function ;) struct migration_session *ms = MSG_process_get_data(MSG_process_self()); - s_ws_params_t params; + s_vm_params_t params; simcall_host_get_params(ms->vm, ¶ms); const sg_size_t ramsize = params.ramsize; const sg_size_t devsize = params.devsize; @@ -711,7 +719,7 @@ static int migration_tx_fun(int argc, char *argv[]) #define MIGRATION_TIMEOUT_DO_NOT_HARDCODE_ME 10000000.0 double mig_timeout = MIGRATION_TIMEOUT_DO_NOT_HARDCODE_ME; - double remaining_size = ramsize + devsize; + double remaining_size = (double) (ramsize + devsize); double threshold = 0.0; /* check parameters */ @@ -803,7 +811,7 @@ static int migration_tx_fun(int argc, char *argv[]) sg_size_t sent = 0; double clock_prev_send = MSG_get_clock(); TRY { - XBT_INFO("Stage 2, gonna send %llu", updated_size); + 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_ANONYMOUS { //hostfailure (if you want to know whether this is the SRC or the DST please check directly in send_migration_data code) @@ -847,8 +855,8 @@ stage3: stop_dirty_page_tracking(ms->vm); TRY { - XBT_INFO("Stage 3: Gonna send %f", remaining_size); - send_migration_data(ms->vm, ms->src_pm, ms->dst_pm, remaining_size, ms->mbox, 3, 0, mig_speed, -1); + XBT_DEBUG("Stage 3: Gonna send %f", remaining_size); + send_migration_data(ms->vm, ms->src_pm, ms->dst_pm, (sg_size_t)remaining_size, ms->mbox, 3, 0, mig_speed, -1); } CATCH_ANONYMOUS { //hostfailure (if you want to know whether this is the SRC or the DST please check directly in send_migration_data code) // Stop the dirty page tracking an return (there is no memory space to release) @@ -857,7 +865,7 @@ stage3: } // At that point the Migration is considered valid for the SRC node but remind that the DST side should relocate effectively the VM on the DST node. - XBT_INFO("mig: tx_done"); + XBT_DEBUG("mig: tx_done"); return 0; } @@ -964,13 +972,19 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t new_pm) msg_host_t old_pm = simcall_vm_get_pm(vm); + if(MSG_host_is_off(old_pm)) + THROWF(vm_error, 0, "SRC host(%s) seems off, cannot start a migration", sg_host_name(old_pm)); + + if(MSG_host_is_off(new_pm)) + THROWF(vm_error, 0, "DST host(%s) seems off, cannot start a migration", sg_host_name(new_pm)); + if (!MSG_vm_is_running(vm)) THROWF(vm_error, 0, "VM(%s) is not running", sg_host_name(vm)); if (MSG_vm_is_migrating(vm)) THROWF(vm_error, 0, "VM(%s) is already migrating", sg_host_name(vm)); - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->is_migrating = 1; { @@ -1106,7 +1120,7 @@ msg_host_t MSG_vm_get_pm(msg_vm_t vm) */ void MSG_vm_set_bound(msg_vm_t vm, double bound) { - return simcall_vm_set_bound(vm, bound); + simcall_vm_set_bound(vm, bound); } @@ -1118,12 +1132,12 @@ void MSG_vm_set_bound(msg_vm_t vm, double bound) */ void MSG_vm_set_affinity(msg_vm_t vm, msg_host_t pm, unsigned long mask) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); if (mask == 0) xbt_dict_remove_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm)); else - xbt_dict_set_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm), (void *) mask, NULL); + xbt_dict_set_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm), (void *)(uintptr_t) mask, NULL); msg_host_t pm_now = MSG_vm_get_pm(vm); if (pm_now == pm) {