1 /* Copyright (c) 2007-2020. 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. */
6 #include "simgrid/actor.h"
7 #include "simgrid/engine.h"
8 #include "simgrid/host.h"
9 #include "simgrid/mailbox.h"
10 #include "simgrid/plugins/live_migration.h"
11 #include "simgrid/vm.h"
14 #include "xbt/sysdep.h"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(cloud_simple, "Messages specific for this example");
18 static void computation_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
20 const char* pr_name = sg_actor_get_name(sg_actor_self());
21 const char* host_name = sg_host_get_name(sg_host_self());
23 double clock_sta = simgrid_get_clock();
24 sg_actor_execute(1000000);
25 double clock_end = simgrid_get_clock();
27 XBT_INFO("%s:%s task executed %g", host_name, pr_name, clock_end - clock_sta);
30 static void launch_computation_worker(sg_host_t host)
32 sg_actor_create("compute", host, computation_fun, 0, NULL);
41 static void communication_tx_fun(int argc, char* argv[])
43 xbt_assert(argc == 2);
44 sg_mailbox_t mbox = sg_mailbox_by_name(argv[1]);
46 struct task_priv* priv = xbt_new(struct task_priv, 1);
47 priv->tx_proc = sg_actor_self();
48 priv->tx_host = sg_host_self();
49 priv->clock_sta = simgrid_get_clock();
51 sg_mailbox_put(mbox, priv, 1000000);
54 static void communication_rx_fun(int argc, char* argv[])
56 const char* pr_name = sg_actor_get_name(sg_actor_self());
57 const char* host_name = sg_host_get_name(sg_host_self());
58 xbt_assert(argc == 2);
59 sg_mailbox_t mbox = sg_mailbox_by_name(argv[1]);
61 struct task_priv* priv = (struct task_priv*)sg_mailbox_get(mbox);
62 double clock_end = simgrid_get_clock();
64 XBT_INFO("%s:%s to %s:%s => %g sec", sg_host_get_name(priv->tx_host), sg_actor_get_name(priv->tx_proc), host_name,
65 pr_name, clock_end - priv->clock_sta);
70 static void launch_communication_worker(sg_host_t tx_host, sg_host_t rx_host)
72 char* mbox = bprintf("MBOX:%s-%s", sg_host_get_name(tx_host), sg_host_get_name(rx_host));
74 const char* tx_argv[] = {"comm_tx", mbox, NULL};
75 sg_actor_create("comm_tx", tx_host, communication_tx_fun, 2, tx_argv);
77 const char* rx_argv[] = {"comm_rx", mbox, NULL};
78 sg_actor_create("comm_rx", rx_host, communication_rx_fun, 2, rx_argv);
83 static void master_main(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
85 sg_host_t pm0 = sg_host_by_name("Fafard");
86 sg_host_t pm1 = sg_host_by_name("Tremblay");
87 sg_host_t pm2 = sg_host_by_name("Bourassa");
89 XBT_INFO("## Test 1 (started): check computation on normal PMs");
91 XBT_INFO("### Put a task on a PM");
92 launch_computation_worker(pm0);
93 sg_actor_sleep_for(2);
95 XBT_INFO("### Put two tasks on a PM");
96 launch_computation_worker(pm0);
97 launch_computation_worker(pm0);
98 sg_actor_sleep_for(2);
100 XBT_INFO("### Put a task on each PM");
101 launch_computation_worker(pm0);
102 launch_computation_worker(pm1);
103 sg_actor_sleep_for(2);
105 XBT_INFO("## Test 1 (ended)");
107 XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
109 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
110 sg_vm_t vm0 = sg_vm_create_core(pm0, "VM0");
112 launch_computation_worker((sg_host_t)vm0);
113 sg_actor_sleep_for(2);
116 XBT_INFO("## Test 2 (ended)");
119 "## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
121 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
122 vm0 = sg_vm_create_core(pm0, "VM0");
124 launch_computation_worker(pm0);
125 sg_actor_sleep_for(2);
128 XBT_INFO("## Test 3 (ended)");
130 XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
131 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
133 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
134 vm0 = sg_vm_create_core(pm0, "VM0");
135 sg_vm_t vm1 = sg_vm_create_core(pm0, "VM1");
138 launch_computation_worker((sg_host_t)vm0);
139 launch_computation_worker((sg_host_t)vm1);
140 sg_actor_sleep_for(2);
144 XBT_INFO("### Put a VM on each PM, and put a task to each VM");
145 vm0 = sg_vm_create_core(pm0, "VM0");
146 vm1 = sg_vm_create_core(pm1, "VM1");
149 launch_computation_worker((sg_host_t)vm0);
150 launch_computation_worker((sg_host_t)vm1);
151 sg_actor_sleep_for(2);
154 XBT_INFO("## Test 4 (ended)");
156 XBT_INFO("## Test 5 (started): Analyse network impact");
157 XBT_INFO("### Make a connection between PM0 and PM1");
158 launch_communication_worker(pm0, pm1);
159 sg_actor_sleep_for(5);
161 XBT_INFO("### Make two connection between PM0 and PM1");
162 launch_communication_worker(pm0, pm1);
163 launch_communication_worker(pm0, pm1);
164 sg_actor_sleep_for(5);
166 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
167 vm0 = sg_vm_create_core(pm0, "VM0");
169 launch_communication_worker(pm0, (sg_host_t)vm0);
170 sg_actor_sleep_for(5);
173 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
174 vm0 = sg_vm_create_core(pm1, "VM0");
176 launch_communication_worker(pm0, (sg_host_t)vm0);
177 sg_actor_sleep_for(5);
180 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
181 vm0 = sg_vm_create_core(pm1, "VM0");
183 launch_communication_worker(pm0, (sg_host_t)vm0);
184 launch_communication_worker(pm0, (sg_host_t)vm0);
185 sg_actor_sleep_for(5);
188 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
189 vm0 = sg_vm_create_core(pm1, "VM0");
191 launch_communication_worker(pm0, (sg_host_t)vm0);
192 launch_communication_worker(pm0, pm1);
193 sg_actor_sleep_for(5);
196 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
197 vm0 = sg_vm_create_core(pm0, "VM0");
198 vm1 = sg_vm_create_core(pm1, "VM1");
201 launch_communication_worker((sg_host_t)vm0, (sg_host_t)vm1);
202 launch_communication_worker((sg_host_t)vm0, (sg_host_t)vm1);
203 sg_actor_sleep_for(5);
207 XBT_INFO("## Test 5 (ended)");
209 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
211 XBT_INFO("### Relocate VM0 between PM0 and PM1");
212 vm0 = sg_vm_create_core(pm0, "VM0");
213 sg_vm_set_ramsize(vm0, 1L * 1024 * 1024 * 1024); // 1GiB
216 launch_communication_worker((sg_host_t)vm0, pm2);
217 sg_actor_sleep_for(0.01);
218 sg_vm_migrate(vm0, pm1);
219 sg_actor_sleep_for(0.01);
220 sg_vm_migrate(vm0, pm0);
221 sg_actor_sleep_for(5);
223 XBT_INFO("## Test 6 (ended)");
226 int main(int argc, char* argv[])
228 /* Get the arguments */
229 simgrid_init(&argc, argv);
230 sg_vm_live_migration_plugin_init();
232 /* load the platform file */
233 simgrid_load_platform(argv[1]);
235 sg_actor_create("master_", sg_host_by_name("Fafard"), master_main, 0, NULL);
238 XBT_INFO("Simulation time %g", simgrid_get_clock());