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"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static void vm_migrate(msg_vm_t vm, msg_host_t dst_pm)
13 msg_host_t src_pm = MSG_vm_get_pm(vm);
14 double mig_sta = MSG_get_clock();
15 MSG_vm_migrate(vm, dst_pm);
16 double mig_end = MSG_get_clock();
18 XBT_INFO("%s migrated: %s->%s in %g s", MSG_vm_get_name(vm),
19 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_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 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
56 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
57 msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
58 msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
59 xbt_dynar_free(&hosts_dynar);
62 memset(¶ms, 0, sizeof(params));
64 vm0 = MSG_vm_create_core(pm0, "VM0");
65 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
66 MSG_host_set_params(vm0, ¶ms);
69 XBT_INFO("Test: Migrate a VM with %llu Mbytes RAM", params.ramsize / 1000 / 1000);
74 vm0 = MSG_vm_create_core(pm0, "VM0");
75 params.ramsize = 1L * 1000 * 1000 * 100; // 100Mbytes
76 MSG_host_set_params(vm0, ¶ms);
79 XBT_INFO("Test: Migrate a VM with %llu Mbytes RAM", params.ramsize / 1000 / 1000);
84 vm0 = MSG_vm_create_core(pm0, "VM0");
85 vm1 = MSG_vm_create_core(pm0, "VM1");
87 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
88 MSG_host_set_params(vm0, ¶ms);
89 MSG_host_set_params(vm1, ¶ms);
93 XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
94 vm_migrate_async(vm0, pm1);
95 vm_migrate_async(vm1, pm1);
96 MSG_process_sleep(10000);
101 vm0 = MSG_vm_create_core(pm0, "VM0");
102 vm1 = MSG_vm_create_core(pm0, "VM1");
104 params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
105 MSG_host_set_params(vm0, ¶ms);
106 MSG_host_set_params(vm1, ¶ms);
110 XBT_INFO("Test: Migrate two VMs at once to different PMs");
111 vm_migrate_async(vm0, pm1);
112 vm_migrate_async(vm1, pm2);
113 MSG_process_sleep(10000);
121 static void launch_master(msg_host_t host)
123 const char *pr_name = "master_";
124 char **argv = xbt_new(char *, 2);
125 argv[0] = xbt_strdup(pr_name);
128 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
131 int main(int argc, char *argv[])
133 /* Get the arguments */
134 MSG_init(&argc, argv);
136 /* load the platform file */
137 MSG_create_environment(argv[1]);
139 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
140 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
141 xbt_dynar_free(&hosts_dynar);
144 int res = MSG_main();
145 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
147 return !(res == MSG_OK);