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 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10 static int computation_fun(int argc, char *argv[])
12 const char *pr_name = MSG_process_get_name(MSG_process_self());
13 const char *host_name = MSG_host_get_name(MSG_host_self());
15 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
17 double clock_sta = MSG_get_clock();
18 MSG_task_execute(task);
19 double clock_end = MSG_get_clock();
21 XBT_INFO("%s:%s task executed %g", host_name, pr_name, clock_end - clock_sta);
23 MSG_task_destroy(task);
28 static void launch_computation_worker(msg_host_t host)
30 const char *pr_name = "compute";
31 char **argv = xbt_new(char *, 2);
32 argv[0] = xbt_strdup(pr_name);
35 MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
40 msg_process_t tx_proc;
44 static int communication_tx_fun(int argc, char *argv[])
46 xbt_assert(argc == 2);
47 const char *mbox = argv[1];
49 msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);
51 struct task_priv *priv = xbt_new(struct task_priv, 1);
52 priv->tx_proc = MSG_process_self();
53 priv->tx_host = MSG_host_self();
54 priv->clock_sta = MSG_get_clock();
56 MSG_task_set_data(task, priv);
58 MSG_task_send(task, mbox);
63 static int communication_rx_fun(int argc, char *argv[])
65 const char *pr_name = MSG_process_get_name(MSG_process_self());
66 const char *host_name = MSG_host_get_name(MSG_host_self());
67 xbt_assert(argc == 2);
68 const char *mbox = argv[1];
70 msg_task_t task = NULL;
71 MSG_task_recv(&task, mbox);
73 struct task_priv *priv = MSG_task_get_data(task);
74 double clock_end = MSG_get_clock();
76 XBT_INFO("%s:%s to %s:%s => %g sec", MSG_host_get_name(priv->tx_host), MSG_process_get_name(priv->tx_proc),
77 host_name, pr_name, clock_end - priv->clock_sta);
80 MSG_task_destroy(task);
85 static void launch_communication_worker(msg_host_t tx_host, msg_host_t rx_host)
87 char *mbox = bprintf("MBOX:%s-%s", MSG_host_get_name(tx_host), MSG_host_get_name(rx_host));
90 const char *pr_name_tx = "comm_tx";
91 argv = xbt_new(char *, 3);
92 argv[0] = xbt_strdup(pr_name_tx);
93 argv[1] = xbt_strdup(mbox);
96 MSG_process_create_with_arguments(pr_name_tx, communication_tx_fun, NULL, tx_host, 2, argv);
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);
104 MSG_process_create_with_arguments(pr_name_rx, communication_rx_fun, NULL, rx_host, 2, argv);
110 static int master_main(int argc, char *argv[])
112 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
113 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
114 msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
115 msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
119 XBT_INFO("## Test 1 (started): check computation on normal PMs");
121 XBT_INFO("### Put a task on a PM");
122 launch_computation_worker(pm0);
123 MSG_process_sleep(2);
125 XBT_INFO("### Put two tasks on a PM");
126 launch_computation_worker(pm0);
127 launch_computation_worker(pm0);
128 MSG_process_sleep(2);
130 XBT_INFO("### Put a task on each PM");
131 launch_computation_worker(pm0);
132 launch_computation_worker(pm1);
133 MSG_process_sleep(2);
135 XBT_INFO("## Test 1 (ended)");
137 XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
139 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
140 vm0 = MSG_vm_create_core(pm0, "VM0");
142 launch_computation_worker(vm0);
143 MSG_process_sleep(2);
146 XBT_INFO("## Test 2 (ended)");
148 XBT_INFO("## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
150 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
151 vm0 = MSG_vm_create_core(pm0, "VM0");
153 launch_computation_worker(pm0);
154 MSG_process_sleep(2);
157 XBT_INFO("## Test 3 (ended)");
159 XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
160 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
162 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
163 vm0 = MSG_vm_create_core(pm0, "VM0");
164 vm1 = MSG_vm_create_core(pm0, "VM1");
167 launch_computation_worker(vm0);
168 launch_computation_worker(vm1);
169 MSG_process_sleep(2);
173 XBT_INFO("### Put a VM on each PM, and put a task to each VM");
174 vm0 = MSG_vm_create_core(pm0, "VM0");
175 vm1 = MSG_vm_create_core(pm1, "VM1");
178 launch_computation_worker(vm0);
179 launch_computation_worker(vm1);
180 MSG_process_sleep(2);
183 XBT_INFO("## Test 4 (ended)");
185 XBT_INFO("## Test 5 (started): Analyse network impact");
186 XBT_INFO("### Make a connection between PM0 and PM1");
187 launch_communication_worker(pm0, pm1);
188 MSG_process_sleep(5);
190 XBT_INFO("### Make two connection between PM0 and PM1");
191 launch_communication_worker(pm0, pm1);
192 launch_communication_worker(pm0, pm1);
193 MSG_process_sleep(5);
195 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
196 vm0 = MSG_vm_create_core(pm0, "VM0");
198 launch_communication_worker(pm0, vm0);
199 MSG_process_sleep(5);
202 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
203 vm0 = MSG_vm_create_core(pm1, "VM0");
205 launch_communication_worker(pm0, vm0);
206 MSG_process_sleep(5);
209 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
210 vm0 = MSG_vm_create_core(pm1, "VM0");
212 launch_communication_worker(pm0, vm0);
213 launch_communication_worker(pm0, vm0);
214 MSG_process_sleep(5);
217 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
218 vm0 = MSG_vm_create_core(pm1, "VM0");
220 launch_communication_worker(pm0, vm0);
221 launch_communication_worker(pm0, pm1);
222 MSG_process_sleep(5);
225 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
226 vm0 = MSG_vm_create_core(pm0, "VM0");
227 vm1 = MSG_vm_create_core(pm1, "VM1");
230 launch_communication_worker(vm0, vm1);
231 launch_communication_worker(vm0, vm1);
232 MSG_process_sleep(5);
236 XBT_INFO("## Test 5 (ended)");
238 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
240 XBT_INFO("### Relocate VM0 between PM0 and PM1");
241 vm0 = MSG_vm_create_core(pm0, "VM0");
243 s_vm_params_t params;
244 memset(¶ms, 0, sizeof(params));
245 params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes
246 MSG_host_set_params(vm0, ¶ms);
249 launch_communication_worker(vm0, pm2);
250 MSG_process_sleep(0.01);
251 MSG_vm_migrate(vm0, pm1);
252 MSG_process_sleep(0.01);
253 MSG_vm_migrate(vm0, pm0);
254 MSG_process_sleep(5);
256 XBT_INFO("## Test 6 (ended)");
258 xbt_dynar_free(&hosts_dynar);
262 static void launch_master(msg_host_t host)
264 const char *pr_name = "master_";
265 char **argv = xbt_new(char *, 2);
266 argv[0] = xbt_strdup(pr_name);
269 MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
272 int main(int argc, char *argv[])
274 /* Get the arguments */
275 MSG_init(&argc, argv);
277 /* load the platform file */
278 xbt_assert(argc == 2);
279 MSG_create_environment(argv[1]);
281 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
282 msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
285 int res = MSG_main();
286 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
287 xbt_dynar_free(&hosts_dynar);
289 return !(res == MSG_OK);