1 /* Copyright (c) 2007-2018. 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 /* This is an example of how the bootup and shutdown periods can be modeled
7 * with SimGrid, taking both the time and overall consumption into account.
9 * The main idea is to augment the platform description to declare fake
10 * pstate that represent these states. The CPU speed of these state is zero
11 * (the CPU delivers 0 flop per second when booting) while the energy
12 * consumption is the one measured on average on the modeled machine.
14 * When you want to bootup the machine, you set it into the pstate encoding
15 * the boot (3 in this example), and leave it so for the right time using a
16 * sleep_for(). During that time no other execution can progress since the
17 * resource speed is set at 0 flop/s in this fake pstate. Once this is over,
18 * the boot is done and we switch back to the regular pstate. Conversely,
19 * the fake pstate 4 is used to encode the shutdown delay.
21 * Some people don't like the idea to add fake pstates for the boot time, and
22 * would like SimGrid to provide a "cleaner" model for that. But the "right"
23 * model depends on the study you want to conduct. If you want to study the
24 * instantaneous consumption of a rebooting data center, the model used here
25 * is not enough since it considers only the average consumption over the boot,
26 * while the instantaneous consumption changes dramatically. Conversely, a
27 * model taking the instantaneous changes into account will be very difficult
28 * to instantiate correctly (which values will you use?), so it's not adapted
29 * to most studies. At least, fake pstates allow you to do exactly what you
30 * need for your very study.
33 #include "simgrid/s4u.hpp"
34 #include "simgrid/plugins/energy.h"
36 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this example");
38 static void simulate_bootup(simgrid::s4u::Host* host)
40 int previous_pstate = host->getPstate();
42 XBT_INFO("Switch to virtual pstate 3, that encodes the 'booting up' state in that platform");
45 XBT_INFO("Actually start the host");
48 XBT_INFO("Wait 150s to simulate the boot time.");
49 simgrid::s4u::this_actor::sleep_for(150);
51 XBT_INFO("The host is now up and running. Switch back to previous pstate %d", previous_pstate);
52 host->setPstate(previous_pstate);
55 static void simulate_shutdown(simgrid::s4u::Host* host)
57 int previous_pstate = host->getPstate();
59 XBT_INFO("Switch to virtual pstate 4, that encodes the 'shutting down' state in that platform");
62 XBT_INFO("Wait 7 seconds to simulate the shutdown time.");
63 simgrid::s4u::this_actor::sleep_for(7);
65 XBT_INFO("Switch back to previous pstate %d, that will be used on reboot.", previous_pstate);
66 host->setPstate(previous_pstate);
68 XBT_INFO("Actually shutdown the host");
74 simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
76 XBT_INFO("Initial pstate: %d; Energy dissipated so far:%.0E J", host1->getPstate(),
77 sg_host_get_consumed_energy(host1));
79 XBT_INFO("Sleep for 10 seconds");
80 simgrid::s4u::this_actor::sleep_for(10);
81 XBT_INFO("Done sleeping. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
82 sg_host_get_consumed_energy(host1));
84 simulate_shutdown(host1);
85 XBT_INFO("Host1 is now OFF. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
86 sg_host_get_consumed_energy(host1));
88 XBT_INFO("Sleep for 10 seconds");
89 simgrid::s4u::this_actor::sleep_for(10);
90 XBT_INFO("Done sleeping. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
91 sg_host_get_consumed_energy(host1));
93 simulate_bootup(host1);
94 XBT_INFO("Host1 is now ON again. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
95 sg_host_get_consumed_energy(host1));
100 int main(int argc, char* argv[])
102 sg_host_energy_plugin_init();
103 simgrid::s4u::Engine e(&argc, argv);
105 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
107 e.load_platform(argv[1]);
108 simgrid::s4u::Actor::create("Boot Monitor", simgrid::s4u::Host::by_name("MyHost2"), monitor);
112 XBT_INFO("End of simulation.");