Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
one step toward a live migration plugin
[simgrid.git] / teshsuite / msg / cloud-simple / cloud-simple.c
1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/msg.h"
7 #include "simgrid/plugins/live_migration.h"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int computation_fun(int argc, char* argv[])
12 {
13   const char* pr_name   = MSG_process_get_name(MSG_process_self());
14   const char* host_name = MSG_host_get_name(MSG_host_self());
15
16   msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
17
18   double clock_sta = MSG_get_clock();
19   MSG_task_execute(task);
20   double clock_end = MSG_get_clock();
21
22   XBT_INFO("%s:%s task executed %g", host_name, pr_name, clock_end - clock_sta);
23
24   MSG_task_destroy(task);
25
26   return 0;
27 }
28
29 static void launch_computation_worker(msg_host_t host)
30 {
31   const char* pr_name = "compute";
32   char** argv         = xbt_new(char*, 2);
33   argv[0]             = xbt_strdup(pr_name);
34   argv[1]             = NULL;
35
36   MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
37 }
38
39 struct task_priv {
40   msg_host_t tx_host;
41   msg_process_t tx_proc;
42   double clock_sta;
43 };
44
45 static int communication_tx_fun(int argc, char* argv[])
46 {
47   xbt_assert(argc == 2);
48   const char* mbox = argv[1];
49
50   msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
51
52   struct task_priv* priv = xbt_new(struct task_priv, 1);
53   priv->tx_proc          = MSG_process_self();
54   priv->tx_host          = MSG_host_self();
55   priv->clock_sta        = MSG_get_clock();
56
57   MSG_task_set_data(task, priv);
58
59   MSG_task_send(task, mbox);
60
61   return 0;
62 }
63
64 static int communication_rx_fun(int argc, char* argv[])
65 {
66   const char* pr_name   = MSG_process_get_name(MSG_process_self());
67   const char* host_name = MSG_host_get_name(MSG_host_self());
68   xbt_assert(argc == 2);
69   const char* mbox = argv[1];
70
71   msg_task_t task = NULL;
72   MSG_task_recv(&task, mbox);
73
74   struct task_priv* priv = MSG_task_get_data(task);
75   double clock_end       = MSG_get_clock();
76
77   XBT_INFO("%s:%s to %s:%s => %g sec", MSG_host_get_name(priv->tx_host), MSG_process_get_name(priv->tx_proc), host_name,
78            pr_name, clock_end - priv->clock_sta);
79
80   xbt_free(priv);
81   MSG_task_destroy(task);
82
83   return 0;
84 }
85
86 static void launch_communication_worker(msg_host_t tx_host, msg_host_t rx_host)
87 {
88   char* mbox             = bprintf("MBOX:%s-%s", MSG_host_get_name(tx_host), MSG_host_get_name(rx_host));
89   const char* pr_name_tx = "comm_tx";
90
91   char** argv = xbt_new(char*, 3);
92   argv[0]     = xbt_strdup(pr_name_tx);
93   argv[1]     = xbt_strdup(mbox);
94   argv[2]     = NULL;
95
96   MSG_process_create_with_arguments(pr_name_tx, communication_tx_fun, NULL, tx_host, 2, argv);
97
98   const char* pr_name_rx = "comm_rx";
99   argv                   = xbt_new(char*, 3);
100   argv[0]                = xbt_strdup(pr_name_rx);
101   argv[1]                = xbt_strdup(mbox);
102   argv[2]                = NULL;
103
104   MSG_process_create_with_arguments(pr_name_rx, communication_rx_fun, NULL, rx_host, 2, argv);
105
106   xbt_free(mbox);
107 }
108
109 static int master_main(int argc, char* argv[])
110 {
111   msg_host_t pm0 = MSG_host_by_name("Fafard");
112   msg_host_t pm1 = MSG_host_by_name("Tremblay");
113   msg_host_t pm2 = MSG_host_by_name("Bourassa");
114
115   XBT_INFO("## Test 1 (started): check computation on normal PMs");
116
117   XBT_INFO("### Put a task on a PM");
118   launch_computation_worker(pm0);
119   MSG_process_sleep(2);
120
121   XBT_INFO("### Put two tasks on a PM");
122   launch_computation_worker(pm0);
123   launch_computation_worker(pm0);
124   MSG_process_sleep(2);
125
126   XBT_INFO("### Put a task on each PM");
127   launch_computation_worker(pm0);
128   launch_computation_worker(pm1);
129   MSG_process_sleep(2);
130
131   XBT_INFO("## Test 1 (ended)");
132
133   XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
134
135   XBT_INFO("### Put a VM on a PM, and put a task to the VM");
136   msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
137   MSG_vm_start(vm0);
138   launch_computation_worker((msg_host_t)vm0);
139   MSG_process_sleep(2);
140   MSG_vm_destroy(vm0);
141
142   XBT_INFO("## Test 2 (ended)");
143
144   XBT_INFO(
145       "## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
146
147   XBT_INFO("### Put a VM on a PM, and put a task to the PM");
148   vm0 = MSG_vm_create_core(pm0, "VM0");
149   MSG_vm_start(vm0);
150   launch_computation_worker(pm0);
151   MSG_process_sleep(2);
152   MSG_vm_destroy(vm0);
153
154   XBT_INFO("## Test 3 (ended)");
155
156   XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
157            " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
158
159   XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
160   vm0          = MSG_vm_create_core(pm0, "VM0");
161   msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
162   MSG_vm_start(vm0);
163   MSG_vm_start(vm1);
164   launch_computation_worker((msg_host_t)vm0);
165   launch_computation_worker((msg_host_t)vm1);
166   MSG_process_sleep(2);
167   MSG_vm_destroy(vm0);
168   MSG_vm_destroy(vm1);
169
170   XBT_INFO("### Put a VM on each PM, and put a task to each VM");
171   vm0 = MSG_vm_create_core(pm0, "VM0");
172   vm1 = MSG_vm_create_core(pm1, "VM1");
173   MSG_vm_start(vm0);
174   MSG_vm_start(vm1);
175   launch_computation_worker((msg_host_t)vm0);
176   launch_computation_worker((msg_host_t)vm1);
177   MSG_process_sleep(2);
178   MSG_vm_destroy(vm0);
179   MSG_vm_destroy(vm1);
180   XBT_INFO("## Test 4 (ended)");
181
182   XBT_INFO("## Test 5  (started): Analyse network impact");
183   XBT_INFO("### Make a connection between PM0 and PM1");
184   launch_communication_worker(pm0, pm1);
185   MSG_process_sleep(5);
186
187   XBT_INFO("### Make two connection between PM0 and PM1");
188   launch_communication_worker(pm0, pm1);
189   launch_communication_worker(pm0, pm1);
190   MSG_process_sleep(5);
191
192   XBT_INFO("### Make a connection between PM0 and VM0@PM0");
193   vm0 = MSG_vm_create_core(pm0, "VM0");
194   MSG_vm_start(vm0);
195   launch_communication_worker(pm0, (msg_host_t)vm0);
196   MSG_process_sleep(5);
197   MSG_vm_destroy(vm0);
198
199   XBT_INFO("### Make a connection between PM0 and VM0@PM1");
200   vm0 = MSG_vm_create_core(pm1, "VM0");
201   MSG_vm_start(vm0);
202   launch_communication_worker(pm0, (msg_host_t)vm0);
203   MSG_process_sleep(5);
204   MSG_vm_destroy(vm0);
205
206   XBT_INFO("### Make two connections between PM0 and VM0@PM1");
207   vm0 = MSG_vm_create_core(pm1, "VM0");
208   MSG_vm_start(vm0);
209   launch_communication_worker(pm0, (msg_host_t)vm0);
210   launch_communication_worker(pm0, (msg_host_t)vm0);
211   MSG_process_sleep(5);
212   MSG_vm_destroy(vm0);
213
214   XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
215   vm0 = MSG_vm_create_core(pm1, "VM0");
216   MSG_vm_start(vm0);
217   launch_communication_worker(pm0, (msg_host_t)vm0);
218   launch_communication_worker(pm0, pm1);
219   MSG_process_sleep(5);
220   MSG_vm_destroy(vm0);
221
222   XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
223   vm0 = MSG_vm_create_core(pm0, "VM0");
224   vm1 = MSG_vm_create_core(pm1, "VM1");
225   MSG_vm_start(vm0);
226   MSG_vm_start(vm1);
227   launch_communication_worker((msg_host_t)vm0, (msg_host_t)vm1);
228   launch_communication_worker((msg_host_t)vm0, (msg_host_t)vm1);
229   MSG_process_sleep(5);
230   MSG_vm_destroy(vm0);
231   MSG_vm_destroy(vm1);
232
233   XBT_INFO("## Test 5 (ended)");
234
235   XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
236            " network one");
237   XBT_INFO("### Relocate VM0 between PM0 and PM1");
238   vm0 = MSG_vm_create_core(pm0, "VM0");
239   MSG_vm_set_ramsize(vm0, 1L * 1024 * 1024 * 1024); // 1GiB
240
241   MSG_vm_start(vm0);
242   launch_communication_worker((msg_host_t)vm0, pm2);
243   MSG_process_sleep(0.01);
244   MSG_vm_migrate(vm0, pm1);
245   MSG_process_sleep(0.01);
246   MSG_vm_migrate(vm0, pm0);
247   MSG_process_sleep(5);
248   MSG_vm_destroy(vm0);
249   XBT_INFO("## Test 6 (ended)");
250
251   return 0;
252 }
253
254 static void launch_master(msg_host_t host)
255 {
256   const char* pr_name = "master_";
257   char** argv         = xbt_new(char*, 2);
258   argv[0]             = xbt_strdup(pr_name);
259   argv[1]             = NULL;
260
261   MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
262 }
263
264 int main(int argc, char* argv[])
265 {
266   /* Get the arguments */
267   MSG_init(&argc, argv);
268   sg_vm_live_migration_plugin_init();
269
270   /* load the platform file */
271   const char* platform = "../../platforms/small_platform.xml";
272   if (argc == 2)
273     platform = argv[1];
274   MSG_create_environment(platform);
275
276   msg_host_t pm0 = MSG_host_by_name("Fafard");
277   launch_master(pm0);
278
279   int res = MSG_main();
280   XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
281
282   return !(res == MSG_OK);
283 }