1 /* Copyright (c) 2007-2022. 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 auto payload = mbox->get_unique<struct s_payload>();
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);
57 static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
59 std::string mbox_name = std::string("MBOX:") + tx_host->get_cname() + "-" + rx_host->get_cname();
60 std::vector<std::string> args;
61 args.push_back(mbox_name);
63 simgrid::s4u::Actor::create("comm_tx", tx_host, communication_tx_fun, args);
65 simgrid::s4u::Actor::create("comm_rx", rx_host, communication_rx_fun, args);
68 static void master_main()
70 s4u_Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
71 s4u_Host* pm1 = simgrid::s4u::Host::by_name("Tremblay");
72 s4u_Host* pm2 = simgrid::s4u::Host::by_name("Bourassa");
74 XBT_INFO("## Test 1 (started): check computation on normal PMs");
76 XBT_INFO("### Put an activity on a PM");
77 launch_computation_worker(pm0);
78 simgrid::s4u::this_actor::sleep_for(2);
80 XBT_INFO("### Put two activities on a PM");
81 launch_computation_worker(pm0);
82 launch_computation_worker(pm0);
83 simgrid::s4u::this_actor::sleep_for(2);
85 XBT_INFO("### Put an activity on each PM");
86 launch_computation_worker(pm0);
87 launch_computation_worker(pm1);
88 simgrid::s4u::this_actor::sleep_for(2);
90 XBT_INFO("## Test 1 (ended)");
93 "## Test 2 (started): check impact of running an activity inside a VM (there is no degradation for the moment)");
95 XBT_INFO("### Put a VM on a PM, and put an activity to the VM");
96 auto* vm0 = pm0->create_vm("VM0", 1);
98 launch_computation_worker(vm0);
99 simgrid::s4u::this_actor::sleep_for(2);
102 XBT_INFO("## Test 2 (ended)");
104 XBT_INFO("## Test 3 (started): check impact of running an activity collocated with a VM (there is no VM noise for "
107 XBT_INFO("### Put a VM on a PM, and put an activity to the PM");
108 vm0 = pm0->create_vm("VM0", 1);
110 launch_computation_worker(pm0);
111 simgrid::s4u::this_actor::sleep_for(2);
113 XBT_INFO("## Test 3 (ended)");
116 "## Test 4 (started): compare the cost of running two activities inside two different VMs collocated or not (for"
117 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
119 XBT_INFO("### Put two VMs on a PM, and put an activity to each VM");
120 vm0 = pm0->create_vm("VM0", 1);
122 auto* vm1 = pm0->create_vm("VM1", 1);
123 launch_computation_worker(vm0);
124 launch_computation_worker(vm1);
125 simgrid::s4u::this_actor::sleep_for(2);
129 XBT_INFO("### Put a VM on each PM, and put an activity to each VM");
130 vm0 = pm0->create_vm("VM0", 1);
131 vm1 = pm1->create_vm("VM1", 1);
134 launch_computation_worker(vm0);
135 launch_computation_worker(vm1);
136 simgrid::s4u::this_actor::sleep_for(2);
139 XBT_INFO("## Test 4 (ended)");
141 XBT_INFO("## Test 5 (started): Analyse network impact");
142 XBT_INFO("### Make a connection between PM0 and PM1");
143 launch_communication_worker(pm0, pm1);
144 simgrid::s4u::this_actor::sleep_for(5);
146 XBT_INFO("### Make two connection between PM0 and PM1");
147 launch_communication_worker(pm0, pm1);
148 launch_communication_worker(pm0, pm1);
149 simgrid::s4u::this_actor::sleep_for(5);
151 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
152 vm0 = pm0->create_vm("VM0", 1);
154 launch_communication_worker(pm0, vm0);
155 simgrid::s4u::this_actor::sleep_for(5);
158 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
159 vm0 = pm1->create_vm("VM0", 1);
160 launch_communication_worker(pm0, vm0);
161 simgrid::s4u::this_actor::sleep_for(5);
164 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
165 vm0 = pm1->create_vm("VM0", 1);
167 launch_communication_worker(pm0, vm0);
168 launch_communication_worker(pm0, vm0);
169 simgrid::s4u::this_actor::sleep_for(5);
172 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
173 vm0 = pm1->create_vm("VM0", 1);
175 launch_communication_worker(pm0, vm0);
176 launch_communication_worker(pm0, pm1);
177 simgrid::s4u::this_actor::sleep_for(5);
180 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
181 vm0 = pm0->create_vm("VM0", 1);
182 vm1 = pm1->create_vm("VM1", 1);
185 launch_communication_worker(vm0, vm1);
186 launch_communication_worker(vm0, vm1);
187 simgrid::s4u::this_actor::sleep_for(5);
191 XBT_INFO("## Test 5 (ended)");
192 XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
194 XBT_INFO("### Relocate VM0 between PM0 and PM1");
195 vm0 = pm0->create_vm("VM0", 1);
196 vm0->set_ramsize(1L * 1024 * 1024 * 1024); // 1GiB
199 launch_communication_worker(vm0, pm2);
200 simgrid::s4u::this_actor::sleep_for(0.01);
201 sg_vm_migrate(vm0, pm1);
202 simgrid::s4u::this_actor::sleep_for(0.01);
203 sg_vm_migrate(vm0, pm0);
204 simgrid::s4u::this_actor::sleep_for(5);
206 XBT_INFO("## Test 6 (ended)");
209 int main(int argc, char* argv[])
211 simgrid::s4u::Engine e(&argc, argv);
212 sg_vm_live_migration_plugin_init();
213 e.load_platform(argv[1]); /* - Load the platform description */
215 simgrid::s4u::Actor::create("master_", e.host_by_name("Fafard"), master_main);
219 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());