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/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");
12 static void computation_fun()
14 double clock_sta = simgrid::s4u::Engine::get_clock();
15 simgrid::s4u::this_actor::execute(1000000);
16 double clock_end = simgrid::s4u::Engine::get_clock();
18 XBT_INFO("%s:%s executed %g", simgrid::s4u::this_actor::get_host()->get_cname(),
19 simgrid::s4u::this_actor::get_cname(), clock_end - clock_sta);
22 static void launch_computation_worker(s4u_Host* host)
24 simgrid::s4u::Actor::create("compute", host, computation_fun);
29 const char* tx_actor_name;
33 static void communication_tx_fun(std::vector<std::string> args)
35 simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
36 auto* payload = new s_payload;
37 payload->tx_actor_name = simgrid::s4u::Actor::self()->get_cname();
38 payload->tx_host = simgrid::s4u::this_actor::get_host();
39 payload->clock_sta = simgrid::s4u::Engine::get_clock();
41 mbox->put(payload, 1000000);
44 static void communication_rx_fun(std::vector<std::string> args)
46 const char* actor_name = simgrid::s4u::Actor::self()->get_cname();
47 const char* host_name = simgrid::s4u::this_actor::get_host()->get_cname();
48 simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
50 const auto* payload = static_cast<struct s_payload*>(mbox->get());
51 double clock_end = simgrid::s4u::Engine::get_clock();
53 XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
54 clock_end - payload->clock_sta);
59 static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
61 std::string mbox_name = std::string("MBOX:") + tx_host->get_cname() + "-" + rx_host->get_cname();
62 std::vector<std::string> args;
63 args.push_back(mbox_name);
65 simgrid::s4u::Actor::create("comm_tx", tx_host, communication_tx_fun, args);
67 simgrid::s4u::Actor::create("comm_rx", rx_host, communication_rx_fun, args);
70 static void master_main()
72 s4u_Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
73 s4u_Host* pm1 = simgrid::s4u::Host::by_name("Tremblay");
74 s4u_Host* pm2 = simgrid::s4u::Host::by_name("Bourassa");
76 XBT_INFO("## Test 1 (started): check computation on normal PMs");
78 XBT_INFO("### Put an activity on a PM");
79 launch_computation_worker(pm0);
80 simgrid::s4u::this_actor::sleep_for(2);
82 XBT_INFO("### Put two activities on a PM");
83 launch_computation_worker(pm0);
84 launch_computation_worker(pm0);
85 simgrid::s4u::this_actor::sleep_for(2);
87 XBT_INFO("### Put an activity on each PM");
88 launch_computation_worker(pm0);
89 launch_computation_worker(pm1);
90 simgrid::s4u::this_actor::sleep_for(2);
92 XBT_INFO("## Test 1 (ended)");
95 "## Test 2 (started): check impact of running an activity inside a VM (there is no degradation for the moment)");
97 XBT_INFO("### Put a VM on a PM, and put an activity to the VM");
98 auto* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
100 launch_computation_worker(vm0);
101 simgrid::s4u::this_actor::sleep_for(2);
104 XBT_INFO("## Test 2 (ended)");
106 XBT_INFO("## Test 3 (started): check impact of running an activity collocated with a VM (there is no VM noise for "
109 XBT_INFO("### Put a VM on a PM, and put an activity to the PM");
110 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
112 launch_computation_worker(pm0);
113 simgrid::s4u::this_actor::sleep_for(2);
115 XBT_INFO("## Test 3 (ended)");
118 "## Test 4 (started): compare the cost of running two activities inside two different VMs collocated or not (for"
119 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
121 XBT_INFO("### Put two VMs on a PM, and put an activity to each VM");
122 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
124 auto* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1);
125 launch_computation_worker(vm0);
126 launch_computation_worker(vm1);
127 simgrid::s4u::this_actor::sleep_for(2);
131 XBT_INFO("### Put a VM on each PM, and put an activity to each VM");
132 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
133 vm1 = new simgrid::s4u::VirtualMachine("VM1", pm1, 1);
136 launch_computation_worker(vm0);
137 launch_computation_worker(vm1);
138 simgrid::s4u::this_actor::sleep_for(2);
141 XBT_INFO("## Test 4 (ended)");
143 XBT_INFO("## Test 5 (started): Analyse network impact");
144 XBT_INFO("### Make a connection between PM0 and PM1");
145 launch_communication_worker(pm0, pm1);
146 simgrid::s4u::this_actor::sleep_for(5);
148 XBT_INFO("### Make two connection between PM0 and PM1");
149 launch_communication_worker(pm0, pm1);
150 launch_communication_worker(pm0, pm1);
151 simgrid::s4u::this_actor::sleep_for(5);
153 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
154 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
156 launch_communication_worker(pm0, vm0);
157 simgrid::s4u::this_actor::sleep_for(5);
160 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
161 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
162 launch_communication_worker(pm0, vm0);
163 simgrid::s4u::this_actor::sleep_for(5);
166 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
167 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
169 launch_communication_worker(pm0, vm0);
170 launch_communication_worker(pm0, vm0);
171 simgrid::s4u::this_actor::sleep_for(5);
174 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
175 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
177 launch_communication_worker(pm0, vm0);
178 launch_communication_worker(pm0, pm1);
179 simgrid::s4u::this_actor::sleep_for(5);
182 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
183 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
184 vm1 = new simgrid::s4u::VirtualMachine("VM1", pm1, 1);
187 launch_communication_worker(vm0, vm1);
188 launch_communication_worker(vm0, vm1);
189 simgrid::s4u::this_actor::sleep_for(5);
193 XBT_INFO("## Test 5 (ended)");
194 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
196 XBT_INFO("### Relocate VM0 between PM0 and PM1");
197 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
198 vm0->set_ramsize(1L * 1024 * 1024 * 1024); // 1GiB
201 launch_communication_worker(vm0, pm2);
202 simgrid::s4u::this_actor::sleep_for(0.01);
203 sg_vm_migrate(vm0, pm1);
204 simgrid::s4u::this_actor::sleep_for(0.01);
205 sg_vm_migrate(vm0, pm0);
206 simgrid::s4u::this_actor::sleep_for(5);
208 XBT_INFO("## Test 6 (ended)");
211 int main(int argc, char* argv[])
213 simgrid::s4u::Engine e(&argc, argv);
214 sg_vm_live_migration_plugin_init();
215 e.load_platform(argv[1]); /* - Load the platform description */
217 simgrid::s4u::Actor::create("master_", simgrid::s4u::Host::by_name("Fafard"), master_main);
221 XBT_INFO("Simulation time %g", e.get_clock());