1 /* Copyright (c) 2007-2018. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/msg.h"
8 #include "simgrid/plugins/live_migration.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
12 static void vm_migrate(msg_vm_t vm, msg_host_t dst_pm)
14 msg_host_t src_pm = MSG_vm_get_pm(vm);
15 double mig_sta = MSG_get_clock();
16 MSG_vm_migrate(vm, dst_pm);
17 double mig_end = MSG_get_clock();
19 XBT_INFO("%s migrated: %s->%s in %g s", MSG_vm_get_name(vm), MSG_host_get_name(src_pm), MSG_host_get_name(dst_pm),
23 static int migration_worker_main(int argc, char* argv[])
25 xbt_assert(argc == 3);
26 char* vm_name = argv[1];
27 char* dst_pm_name = argv[2];
29 msg_vm_t vm = (msg_vm_t)MSG_host_by_name(vm_name);
30 msg_host_t dst_pm = MSG_host_by_name(dst_pm_name);
32 vm_migrate(vm, dst_pm);
37 static void vm_migrate_async(msg_vm_t vm, msg_host_t dst_pm)
39 const char* vm_name = MSG_vm_get_name(vm);
40 const char* dst_pm_name = MSG_host_get_name(dst_pm);
41 msg_host_t host = MSG_host_self();
43 const char* pr_name = "mig_wrk";
44 char** argv = xbt_new(char*, 4);
45 argv[0] = xbt_strdup(pr_name);
46 argv[1] = xbt_strdup(vm_name);
47 argv[2] = xbt_strdup(dst_pm_name);
50 MSG_process_create_with_arguments(pr_name, migration_worker_main, NULL, host, 3, argv);
53 static int master_main(int argc, char* argv[])
55 msg_host_t pm0 = MSG_host_by_name("Fafard");
56 msg_host_t pm1 = MSG_host_by_name("Tremblay");
57 msg_host_t pm2 = MSG_host_by_name("Bourassa");
59 msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
60 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
63 XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
68 vm0 = MSG_vm_create_core(pm0, "VM0");
69 MSG_vm_set_ramsize(vm0, 1e8); // 100Mbytes
72 XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
77 vm0 = MSG_vm_create_core(pm0, "VM0");
78 msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
80 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
81 MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
85 XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
86 vm_migrate_async(vm0, pm1);
87 vm_migrate_async(vm1, pm1);
88 MSG_process_sleep(10000);
93 vm0 = MSG_vm_create_core(pm0, "VM0");
94 vm1 = MSG_vm_create_core(pm0, "VM1");
96 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
97 MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
101 XBT_INFO("Test: Migrate two VMs at once to different PMs");
102 vm_migrate_async(vm0, pm1);
103 vm_migrate_async(vm1, pm2);
104 MSG_process_sleep(10000);
112 static void launch_master(msg_host_t host)
114 const char* pr_name = "master_";
115 char** argv = xbt_new(char*, 2);
116 argv[0] = xbt_strdup(pr_name);
119 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
122 int main(int argc, char* argv[])
124 /* Get the arguments */
125 MSG_init(&argc, argv);
126 MSG_vm_live_migration_plugin_init();
128 /* load the platform file */
129 MSG_create_environment(argv[1]);
131 msg_host_t pm0 = MSG_host_by_name("Fafard");
134 int res = MSG_main();
135 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
137 return !(res == MSG_OK);