1 /* Copyright (c) 2007-2023. 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/s4u.hpp"
7 #include "simgrid/plugins/live_migration.h"
8 #include "simgrid/s4u/VirtualMachine.hpp"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11 namespace sg4 = simgrid::s4u;
13 static void computation_fun()
15 double clock_sta = sg4::Engine::get_clock();
16 sg4::this_actor::execute(1000000);
17 double clock_end = sg4::Engine::get_clock();
19 XBT_INFO("%s:%s executed %g", sg4::this_actor::get_host()->get_cname(), sg4::this_actor::get_cname(),
20 clock_end - clock_sta);
23 static void launch_computation_worker(s4u_Host* host)
25 sg4::Actor::create("compute", host, computation_fun);
30 const char* tx_actor_name;
34 static void communication_tx_fun(std::vector<std::string> args)
36 sg4::Mailbox* mbox = sg4::Mailbox::by_name(args.at(0));
37 auto* payload = new s_payload;
38 payload->tx_actor_name = sg4::Actor::self()->get_cname();
39 payload->tx_host = sg4::this_actor::get_host();
40 payload->clock_sta = sg4::Engine::get_clock();
42 mbox->put(payload, 1000000);
45 static void communication_rx_fun(std::vector<std::string> args)
47 const char* actor_name = sg4::Actor::self()->get_cname();
48 const char* host_name = sg4::this_actor::get_host()->get_cname();
49 sg4::Mailbox* mbox = sg4::Mailbox::by_name(args.at(0));
51 auto payload = mbox->get_unique<struct s_payload>();
52 double clock_end = sg4::Engine::get_clock();
54 XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
55 clock_end - payload->clock_sta);
58 static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
60 std::string mbox_name = "MBOX:" + tx_host->get_name() + "-" + rx_host->get_name();
61 std::vector<std::string> args;
62 args.push_back(mbox_name);
64 sg4::Actor::create("comm_tx", tx_host, communication_tx_fun, args);
66 sg4::Actor::create("comm_rx", rx_host, communication_rx_fun, args);
69 static void master_main()
71 s4u_Host* pm0 = sg4::Host::by_name("Fafard");
72 s4u_Host* pm1 = sg4::Host::by_name("Tremblay");
73 s4u_Host* pm2 = sg4::Host::by_name("Bourassa");
75 XBT_INFO("## Test 1 (started): check computation on normal PMs");
77 XBT_INFO("### Put an activity on a PM");
78 launch_computation_worker(pm0);
79 sg4::this_actor::sleep_for(2);
81 XBT_INFO("### Put two activities on a PM");
82 launch_computation_worker(pm0);
83 launch_computation_worker(pm0);
84 sg4::this_actor::sleep_for(2);
86 XBT_INFO("### Put an activity on each PM");
87 launch_computation_worker(pm0);
88 launch_computation_worker(pm1);
89 sg4::this_actor::sleep_for(2);
91 XBT_INFO("## Test 1 (ended)");
94 "## Test 2 (started): check impact of running an activity inside a VM (there is no degradation for the moment)");
96 XBT_INFO("### Put a VM on a PM, and put an activity to the VM");
97 auto* vm0 = pm0->create_vm("VM0", 1);
99 launch_computation_worker(vm0);
100 sg4::this_actor::sleep_for(2);
103 XBT_INFO("## Test 2 (ended)");
105 XBT_INFO("## Test 3 (started): check impact of running an activity collocated with a VM (there is no VM noise for "
108 XBT_INFO("### Put a VM on a PM, and put an activity to the PM");
109 vm0 = pm0->create_vm("VM0", 1);
111 launch_computation_worker(pm0);
112 sg4::this_actor::sleep_for(2);
114 XBT_INFO("## Test 3 (ended)");
117 "## Test 4 (started): compare the cost of running two activities inside two different VMs collocated or not (for"
118 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
120 XBT_INFO("### Put two VMs on a PM, and put an activity to each VM");
121 vm0 = pm0->create_vm("VM0", 1);
123 auto* vm1 = pm0->create_vm("VM1", 1);
124 launch_computation_worker(vm0);
125 launch_computation_worker(vm1);
126 sg4::this_actor::sleep_for(2);
130 XBT_INFO("### Put a VM on each PM, and put an activity to each VM");
131 vm0 = pm0->create_vm("VM0", 1);
132 vm1 = pm1->create_vm("VM1", 1);
135 launch_computation_worker(vm0);
136 launch_computation_worker(vm1);
137 sg4::this_actor::sleep_for(2);
140 XBT_INFO("## Test 4 (ended)");
142 XBT_INFO("## Test 5 (started): Analyse network impact");
143 XBT_INFO("### Make a connection between PM0 and PM1");
144 launch_communication_worker(pm0, pm1);
145 sg4::this_actor::sleep_for(5);
147 XBT_INFO("### Make two connection between PM0 and PM1");
148 launch_communication_worker(pm0, pm1);
149 launch_communication_worker(pm0, pm1);
150 sg4::this_actor::sleep_for(5);
152 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
153 vm0 = pm0->create_vm("VM0", 1);
155 launch_communication_worker(pm0, vm0);
156 sg4::this_actor::sleep_for(5);
159 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
160 vm0 = pm1->create_vm("VM0", 1);
161 launch_communication_worker(pm0, vm0);
162 sg4::this_actor::sleep_for(5);
165 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
166 vm0 = pm1->create_vm("VM0", 1);
168 launch_communication_worker(pm0, vm0);
169 launch_communication_worker(pm0, vm0);
170 sg4::this_actor::sleep_for(5);
173 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
174 vm0 = pm1->create_vm("VM0", 1);
176 launch_communication_worker(pm0, vm0);
177 launch_communication_worker(pm0, pm1);
178 sg4::this_actor::sleep_for(5);
181 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
182 vm0 = pm0->create_vm("VM0", 1);
183 vm1 = pm1->create_vm("VM1", 1);
186 launch_communication_worker(vm0, vm1);
187 launch_communication_worker(vm0, vm1);
188 sg4::this_actor::sleep_for(5);
192 XBT_INFO("## Test 5 (ended)");
193 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
195 XBT_INFO("### Relocate VM0 between PM0 and PM1");
196 vm0 = pm0->create_vm("VM0", 1);
197 vm0->set_ramsize(1L * 1024 * 1024 * 1024); // 1GiB
200 launch_communication_worker(vm0, pm2);
201 sg4::this_actor::sleep_for(0.01);
202 sg_vm_migrate(vm0, pm1);
203 sg4::this_actor::sleep_for(0.01);
204 sg_vm_migrate(vm0, pm0);
205 sg4::this_actor::sleep_for(5);
207 XBT_INFO("## Test 6 (ended)");
210 int main(int argc, char* argv[])
212 sg4::Engine e(&argc, argv);
213 sg_vm_live_migration_plugin_init();
214 e.load_platform(argv[1]); /* - Load the platform description */
216 sg4::Actor::create("master_", e.host_by_name("Fafard"), master_main);
220 XBT_INFO("Simulation time %g", sg4::Engine::get_clock());