From: Paul Bédaride Date: Mon, 11 Aug 2014 13:18:50 +0000 (+0200) Subject: Add vm tesh X-Git-Tag: v3_12~850^2~16 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dd38b27f7d03f21920f17eda3083b16b19465824 Add vm tesh --- diff --git a/include/xbt/dict.h b/include/xbt/dict.h index 41a4aba22d..0c0ec92599 100644 --- a/include/xbt/dict.h +++ b/include/xbt/dict.h @@ -76,6 +76,7 @@ XBT_PUBLIC(void) xbt_dict_set(xbt_dict_t dict, const char *key, void *data, XBT_PUBLIC(void *) xbt_dict_get(xbt_dict_t dict, const char *key); XBT_PUBLIC(void *) xbt_dict_get_or_null(xbt_dict_t dict, const char *key); XBT_PUBLIC(char *) xbt_dict_get_key(xbt_dict_t dict, const void *data); +XBT_PUBLIC(char *) xbt_dict_get_elm_key(xbt_dictelm_t elem); XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm(xbt_dict_t dict, const char *key); XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 4210fc95b7..1a9d56edea 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -192,6 +192,9 @@ static inline void *surf_cpu_resource_priv(const void *host) { static inline void *surf_workstation_resource_priv(const void *host){ return (void*)xbt_lib_get_level((xbt_dictelm_t)host, SURF_WKS_LEVEL); } +static inline void *surf_routing_resource_priv(const void *host){ + return (void*)xbt_lib_get_level((xbt_dictelm_t)host, ROUTING_HOST_LEVEL); +} static inline void *surf_storage_resource_priv(const void *storage){ return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL); } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 60ba70a736..534e331e0f 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -120,6 +120,14 @@ void SIMIX_host_off(smx_host_t h, smx_process_t issuer) } } } + /*xbt_dynar_t vms = surf_workstation_get_vms(h); + unsigned int cpt; + smx_host_t vm; + xbt_dynar_foreach(vms, cpt, vm) { + SIMIX_vm_shutdown(vm, issuer); + SIMIX_vm_destroy(vm); + } + xbt_dynar_free(&vms);*/ } /** diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index d5a0cb088e..70bd4963b0 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -26,6 +26,10 @@ static WorkstationPtr get_casted_workstation(surf_resource_t resource){ return static_cast(surf_workstation_resource_priv(resource)); } +static RoutingEdgePtr get_casted_routing(surf_resource_t resource){ + return static_cast(surf_routing_resource_priv(resource)); +} + static WorkstationVMPtr get_casted_vm_workstation(surf_resource_t resource){ return static_cast(surf_workstation_resource_priv(resource)); } @@ -402,7 +406,16 @@ int surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, cons } xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){ - return get_casted_workstation(resource)->getVms(); + xbt_dynar_t vms = get_casted_workstation(resource)->getVms(); + xbt_dynar_t vms_ = xbt_dynar_new(sizeof(smx_host_t), NULL); + unsigned int cpt; + WorkstationVMPtr vm; + xbt_dynar_foreach(vms, cpt, vm) { + smx_host_t vm_ = xbt_lib_get_elm_or_null(host_lib, vm->getName()); + xbt_dynar_push(vms_, &vm_); + } + xbt_dynar_free(&vms); + return vms_; } void surf_workstation_get_params(surf_resource_t resource, ws_params_t params){ @@ -414,7 +427,30 @@ void surf_workstation_set_params(surf_resource_t resource, ws_params_t params){ } void surf_vm_workstation_destroy(surf_resource_t resource){ - delete get_casted_vm_workstation(resource); + /* ind_phys_workstation equals to smx_host_t */ + //surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName()); + + /* Before clearing the entries in host_lib, we have to pick up resources. */ + CpuPtr cpu = get_casted_cpu(resource); + WorkstationVMPtr vm = get_casted_vm_workstation(resource); + RoutingEdgePtr routing = get_casted_routing(resource); + char* name = xbt_dict_get_elm_key(resource); + /* We deregister objects from host_lib, without invoking the freeing callback + * of each level. + * + * Do not call xbt_lib_remove() here. It deletes all levels of the key, + * including MSG_HOST_LEVEL and others. We should unregister only what we know. + */ + xbt_lib_unset(host_lib, name, SURF_CPU_LEVEL, 0); + xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0); + xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL, 0); + + /* TODO: comment out when VM storage is implemented. */ + // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); + + delete cpu; + delete vm; + delete routing; } void surf_vm_workstation_suspend(surf_resource_t resource){ diff --git a/src/surf/vm_workstation_hl13.cpp b/src/surf/vm_workstation_hl13.cpp index 73baddfe4b..996f28698d 100644 --- a/src/surf/vm_workstation_hl13.cpp +++ b/src/surf/vm_workstation_hl13.cpp @@ -233,7 +233,7 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na * from the VM name, we have to make sure that the system does not call the * free callback for the network resource object. The network resource object * is still used by the physical machine. */ - p_netElm = static_cast(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL)); + p_netElm = new RoutingEdgeWrapper(static_cast(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL))); xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm); p_subWs = sub_ws; @@ -277,40 +277,9 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na */ WorkstationVMHL13::~WorkstationVMHL13() { - /* ind_phys_workstation equals to smx_host_t */ - surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName()); - - /* Before clearing the entries in host_lib, we have to pick up resources. */ - CpuCas01Ptr cpu = static_cast(surf_cpu_resource_priv(ind_vm_workstation)); - - /* We deregister objects from host_lib, without invoking the freeing callback - * of each level. - * - * Do not call xbt_lib_remove() here. It deletes all levels of the key, - * including MSG_HOST_LEVEL and others. We should unregister only what we know. - */ - xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0); - - /* TODO: comment out when VM storage is implemented. */ - // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); - - /* Free the cpu_action of the VM. */ int ret = p_action->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); - - /* Free the cpu resource of the VM. If using power_trace, we will have to */ - delete cpu; - - /* Free the network resource of the VM. */ - // Nothing has to be done, because net_elmts is just a pointer on the physical one - - /* Free the storage resource of the VM. */ - // Not relevant yet - - /* Free the workstation resource of the VM. */ } void WorkstationVMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) { @@ -379,7 +348,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm) /* update net_elm with that of the destination physical host */ RoutingEdgePtr old_net_elm = p_netElm; - RoutingEdgePtr new_net_elm = static_cast(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL)); + RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL))); xbt_assert(new_net_elm); /* Unregister the current net_elm from host_lib. Do not call the free callback. */ @@ -428,6 +397,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm) XBT_DEBUG("migrate VM(%s): change net_elm (%p to %p)", vm_name, old_net_elm, new_net_elm); XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); + delete old_net_elm; } void WorkstationVMHL13::setBound(double bound){ diff --git a/src/surf/workstation_interface.cpp b/src/surf/workstation_interface.cpp index a1d9d3a6ab..6b021c5b5f 100644 --- a/src/surf/workstation_interface.cpp +++ b/src/surf/workstation_interface.cpp @@ -376,7 +376,7 @@ int Workstation::fileMove(surf_file_t fd, const char* fullpath){ xbt_dynar_t Workstation::getVms() { - xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL); + xbt_dynar_t dyn = xbt_dynar_new(sizeof(WorkstationVMPtr), NULL); /* iterate for all virtual machines */ for (WorkstationVMModel::vm_list_t::iterator iter = @@ -384,8 +384,8 @@ xbt_dynar_t Workstation::getVms() iter != WorkstationVMModel::ws_vms.end(); ++iter) { WorkstationVMPtr ws_vm = &*iter; - if (this == ws_vm-> p_subWs) - xbt_dynar_push(dyn, &ws_vm->p_subWs); + if (this == ws_vm->p_subWs) + xbt_dynar_push(dyn, &ws_vm); } return dyn; diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 0d8985ff7d..f632631312 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -304,6 +304,15 @@ char *xbt_dict_get_key(xbt_dict_t dict, const void *data) return NULL; } +/** + * @brief retrieve the key associated to that xbt_dictelm_t. + * + */ +char *xbt_dict_get_elm_key(xbt_dictelm_t elm) +{ + return elm->key; +} + /** * \brief Retrieve data from the dict (null-terminated key) * @@ -346,7 +355,7 @@ XBT_INLINE xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key) XBT_INLINE void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key) { xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key); - + if (current == NULL) return NULL; diff --git a/teshsuite/java/sleep_host_off/CMakeLists.txt b/teshsuite/java/sleep_host_off/CMakeLists.txt index dceda482bd..df403b79d5 100644 --- a/teshsuite/java/sleep_host_off/CMakeLists.txt +++ b/teshsuite/java/sleep_host_off/CMakeLists.txt @@ -40,6 +40,5 @@ set(bin_files ) set(txt_files ${txt_files} - ${CMAKE_CURRENT_SOURCE_DIR}/README PARENT_SCOPE ) diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c index a9c9b78a7e..cb48a8a970 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c @@ -38,6 +38,7 @@ int test_launcher(int argc, char *argv[]) argvF = xbt_new(char*, 2); argvF[0] = xbt_strdup("process_daemon"); MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF); + MSG_process_sleep(3); XBT_INFO(" Turn off Jupiter"); MSG_host_off(jupiter); MSG_process_sleep(10); @@ -120,34 +121,37 @@ int test_launcher(int argc, char *argv[]) test =6; if (xbt_dynar_member(tests, &test)){ - /*XBT_INFO("Test 5: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node"); + XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node"); // Create VM0 int dpRate = 70; msg_vm_t vm0; -MSG_vm_create (msg_host_t ind_pm, const char *name, int ncpus, int ramsize, int net_cap, char *disk_path, int disksize, int mig_netspeed, int dp_intensity) - vm0 = MSG_vm_create_core(jupiter, "vm0"); - params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes - MSG_host_set_params(vm0, ¶ms); - MSG_vm_start(vm0); - XVM vm0 = null; - vm0 = new XVM( - host1, - "vm0", - 1, // Nb of vcpu - 2048, // Ramsize, - 125, // Net Bandwidth - null, //VM disk image - -1, //size of disk image, - 125, // Net bandwidth, - dpRate // Memory intensity - ); - vm0.start(); - vm0.setLoad(90); - - host1.off(); - Msg.info("Test 5 is also weird: when the node host1 is turned off once again, the VM and its daemon are not killed." + - " However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)\n");*/ + msg_process_t daemon; + + vm0 = MSG_vm_create (jupiter, "vm0", 1, 2048, 125, NULL, -1, 125, dpRate); + MSG_vm_start(vm0); + + argvF = xbt_new(char*, 2); + argvF[0] = xbt_strdup("process_daemon"); + daemon = MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, vm0, 1, argvF); + + argvF = xbt_new(char*, 2); + argvF[0] = xbt_strdup("process_daemonJUPI"); + MSG_process_create_with_arguments("process_daemonJUPI", process_daemon, NULL, jupiter, 1, argvF); + + MSG_process_suspend(daemon); + MSG_vm_set_bound(vm0, 90); + MSG_process_resume(daemon); + + MSG_process_sleep(10); + + XBT_INFO(" Turn Jupiter off"); + MSG_host_off(jupiter); + XBT_INFO(" Shutdown vm0"); + MSG_vm_shutdown(vm0); + XBT_INFO(" Destroy vm0"); + MSG_vm_destroy(vm0); + XBT_INFO("Test 6 is also weird: when the node Jupiter is turned off once again, the VM and its daemon are not killed. However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)"); } test = 7; @@ -172,12 +176,13 @@ MSG_vm_create (msg_host_t ind_pm, const char *name, int ncpus, int ramsize, int int process_daemon(int argc, char *argv[]) { msg_task_t task = NULL; + XBT_INFO(" Start daemon on %s (%f)", MSG_host_get_name(MSG_host_self()), MSG_get_host_speed(MSG_host_self())); for(;;){ - task = MSG_task_create("deamon", 100*MSG_get_host_speed(MSG_host_self()), 0, NULL); + task = MSG_task_create("deamon", MSG_get_host_speed(MSG_host_self()), 0, NULL); XBT_INFO(" Execute deamon"); + MSG_task_execute(task); MSG_task_destroy(task); } - MSG_task_execute(task); XBT_INFO(" Deamon done. See you!"); return 0; } diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh index 220808df57..eb10b87e9c 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh @@ -2,11 +2,14 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 1 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 1: > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Create a process on Jupiter +> [Jupiter:process_daemon:(2) 0.000000] [msg_test/INFO] Start daemon on Jupiter (76296000.000000) > [Jupiter:process_daemon:(2) 0.000000] [msg_test/INFO] Execute deamon -> [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Turn off Jupiter -> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test 1 seems ok, cool !(number of Process : 1, it should be 1 (i.e. the Test one)) -> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test done. See you! -> [10.000000] [msg_test/INFO] Simulation time 10 +> [Jupiter:process_daemon:(2) 1.000000] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemon:(2) 2.000000] [msg_test/INFO] Execute deamon +> [Tremblay:test_launcher:(1) 3.000000] [msg_test/INFO] Turn off Jupiter +> [Tremblay:test_launcher:(1) 13.000000] [msg_test/INFO] Test 1 seems ok, cool !(number of Process : 1, it should be 1 (i.e. the Test one)) +> [Tremblay:test_launcher:(1) 13.000000] [msg_test/INFO] Test done. See you! +> [13.000000] [msg_test/INFO] Simulation time 13 $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 2 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error > [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 2: @@ -61,3 +64,26 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platfor > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test done. See you! > [Tremblay:commTX:(3) 40.000000] [msg_test/INFO] TX done > [40.000000] [msg_test/INFO] Simulation time 40 + +$ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_processes_d.xml 6 --log=no_loc --log=msg.thresh:error --log=surf_maxmin.thresh:error +> [Tremblay:test_launcher:(1) 0.000000] [msg_test/INFO] Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node +> [0.000000] [surf_vm_workstation/INFO] Create VM(vm0)@PM(Jupiter) with 0 mounted disks +> [vm0:process_daemon:(2) 0.000000] [msg_test/INFO] Start daemon on vm0 (76296000.000000) +> [vm0:process_daemon:(2) 0.000000] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 0.000000] [msg_test/INFO] Start daemon on Jupiter (76296000.000000) +> [Jupiter:process_daemonJUPI:(3) 0.000000] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 1.000001] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 2.000002] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 3.000004] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 4.000005] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 5.000006] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 6.000007] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 7.000008] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 8.000009] [msg_test/INFO] Execute deamon +> [Jupiter:process_daemonJUPI:(3) 9.000011] [msg_test/INFO] Execute deamon +> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Turn Jupiter off +> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Shutdown vm0 +> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Destroy vm0 +> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test 6 is also weird: when the node Jupiter is turned off once again, the VM and its daemon are not killed. However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;) +> [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] Test done. See you! +> [10.000000] [msg_test/INFO] Simulation time 10