1 /* Copyright (c) 2007-2012. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/sysdep.h" /* calloc, printf */
10 /* Create a log channel to have nice outputs. */
12 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
17 void vm_migrate(msg_vm_t vm, msg_host_t dst_pm)
19 msg_host_t src_pm = MSG_vm_get_pm(vm);
20 double mig_sta = MSG_get_clock();
21 MSG_vm_migrate(vm, dst_pm);
22 double mig_end = MSG_get_clock();
24 XBT_INFO("%s migrated: %s->%s in %g s", MSG_vm_get_name(vm),
25 MSG_host_get_name(src_pm), MSG_host_get_name(dst_pm),
29 int migration_worker_main(int argc, char *argv[])
31 xbt_assert(argc == 3);
32 char *vm_name = argv[1];
33 char *dst_pm_name = argv[2];
35 msg_vm_t vm = MSG_get_host_by_name(vm_name);
36 msg_host_t dst_pm = MSG_get_host_by_name(dst_pm_name);
38 vm_migrate(vm, dst_pm);
43 void vm_migrate_async(msg_vm_t vm, msg_host_t dst_pm)
45 const char *vm_name = MSG_vm_get_name(vm);
46 const char *dst_pm_name = MSG_host_get_name(dst_pm);
47 msg_host_t host = MSG_host_self();
49 const char *pr_name = "mig_wrk";
50 char **argv = xbt_new(char *, 4);
51 argv[0] = xbt_strdup(pr_name);
52 argv[1] = xbt_strdup(vm_name);
53 argv[2] = xbt_strdup(dst_pm_name);
56 MSG_process_create_with_arguments(pr_name, migration_worker_main, NULL, host, 3, argv);
59 int master_main(int argc, char *argv[])
61 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
62 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
63 msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
64 msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
67 memset(¶ms, 0, sizeof(params));
71 vm0 = MSG_vm_create_core(pm0, "VM0");
72 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
73 MSG_host_set_params(vm0, ¶ms);
76 XBT_INFO("Test: Migrate a VM with %ld Mbytes RAM", params.ramsize / 1000 / 1000);
83 vm0 = MSG_vm_create_core(pm0, "VM0");
84 params.ramsize = 1L * 1000 * 1000 * 100; // 100Mbytes
85 MSG_host_set_params(vm0, ¶ms);
88 XBT_INFO("Test: Migrate a VM with %ld Mbytes RAM", params.ramsize / 1000 / 1000);
95 vm0 = MSG_vm_create_core(pm0, "VM0");
96 vm1 = MSG_vm_create_core(pm0, "VM1");
98 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
99 MSG_host_set_params(vm0, ¶ms);
100 MSG_host_set_params(vm1, ¶ms);
104 XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
105 vm_migrate_async(vm0, pm1);
106 vm_migrate_async(vm1, pm1);
107 MSG_process_sleep(10000);
114 vm0 = MSG_vm_create_core(pm0, "VM0");
115 vm1 = MSG_vm_create_core(pm0, "VM1");
117 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
118 MSG_host_set_params(vm0, ¶ms);
119 MSG_host_set_params(vm1, ¶ms);
123 XBT_INFO("Test: Migrate two VMs at once to different PMs");
124 vm_migrate_async(vm0, pm1);
125 vm_migrate_async(vm1, pm2);
126 MSG_process_sleep(10000);
135 void launch_master(msg_host_t host)
137 const char *pr_name = "master_";
138 char **argv = xbt_new(char *, 2);
139 argv[0] = xbt_strdup(pr_name);
142 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
146 int main(int argc, char *argv[])
148 /* Get the arguments */
149 MSG_init(&argc, argv);
151 /* load the platform file */
152 MSG_create_environment(argv[1]);
154 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
155 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
158 int res = MSG_main();
159 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
162 return !(res == MSG_OK);