1 /* Copyright (c) 2007-2015. 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),
20 MSG_host_get_name(src_pm), MSG_host_get_name(dst_pm),
24 static int migration_worker_main(int argc, char *argv[])
26 xbt_assert(argc == 3);
27 char *vm_name = argv[1];
28 char *dst_pm_name = argv[2];
30 msg_vm_t vm = (msg_vm_t)MSG_host_by_name(vm_name);
31 msg_host_t dst_pm = MSG_host_by_name(dst_pm_name);
33 vm_migrate(vm, dst_pm);
38 static void vm_migrate_async(msg_vm_t vm, msg_host_t dst_pm)
40 const char *vm_name = MSG_vm_get_name(vm);
41 const char *dst_pm_name = MSG_host_get_name(dst_pm);
42 msg_host_t host = MSG_host_self();
44 const char *pr_name = "mig_wrk";
45 char **argv = xbt_new(char *, 4);
46 argv[0] = xbt_strdup(pr_name);
47 argv[1] = xbt_strdup(vm_name);
48 argv[2] = xbt_strdup(dst_pm_name);
51 MSG_process_create_with_arguments(pr_name, migration_worker_main, NULL, host, 3, argv);
54 static int master_main(int argc, char *argv[])
56 msg_host_t pm0 = MSG_host_by_name("Fafard");
57 msg_host_t pm1 = MSG_host_by_name("Tremblay");
58 msg_host_t pm2 = MSG_host_by_name("Bourassa");
60 msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
61 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
64 XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
69 vm0 = MSG_vm_create_core(pm0, "VM0");
70 MSG_vm_set_ramsize(vm0, 1e8); // 100Mbytes
73 XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000);
78 vm0 = MSG_vm_create_core(pm0, "VM0");
79 msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
81 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
82 MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
86 XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
87 vm_migrate_async(vm0, pm1);
88 vm_migrate_async(vm1, pm1);
89 MSG_process_sleep(10000);
94 vm0 = MSG_vm_create_core(pm0, "VM0");
95 vm1 = MSG_vm_create_core(pm0, "VM1");
97 MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes
98 MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes
102 XBT_INFO("Test: Migrate two VMs at once to different PMs");
103 vm_migrate_async(vm0, pm1);
104 vm_migrate_async(vm1, pm2);
105 MSG_process_sleep(10000);
113 static void launch_master(msg_host_t host)
115 const char *pr_name = "master_";
116 char **argv = xbt_new(char *, 2);
117 argv[0] = xbt_strdup(pr_name);
120 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
123 int main(int argc, char *argv[])
125 /* Get the arguments */
126 MSG_init(&argc, argv);
127 MSG_vm_live_migration_plugin_init();
129 /* load the platform file */
130 MSG_create_environment(argv[1]);
132 msg_host_t pm0 = MSG_host_by_name("Fafard");
135 int res = MSG_main();
136 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
138 return !(res == MSG_OK);