Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert another example to S4U (and document it)
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 17 Dec 2017 14:46:22 +0000 (15:46 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 19 Dec 2017 08:25:50 +0000 (09:25 +0100)
examples/msg/CMakeLists.txt
examples/msg/energy-onoff/energy-onoff.c [deleted file]
examples/msg/energy-onoff/energy-onoff.tesh [deleted file]
examples/msg/energy-onoff/platform_onoff.xml [deleted file]
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/energy-boot/platform_boot.xml [new file with mode: 0644]
examples/s4u/energy-boot/s4u-energy-boot.cpp [new file with mode: 0644]
examples/s4u/energy-boot/s4u-energy-boot.tesh [new file with mode: 0644]

index a53a953..da49ac2 100644 (file)
@@ -1,7 +1,7 @@
 # C examples
 foreach(x app-masterworker 
           cloud-capping cloud-masterworker cloud-migration
-          dht-pastry energy-onoff energy-vm platform-failures 
+          dht-pastry energy-vm platform-failures 
           process-create 
           synchro-semaphore trace-categories 
           trace-route-user-variables trace-link-user-variables trace-masterworker
@@ -50,7 +50,6 @@ set(tesh_files   ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-k
                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/network-ns3.tesh                 PARENT_SCOPE)
 set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-multicore_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-vivaldi_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/energy-onoff/platform_onoff.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3hosts_2links_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links-timer_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links_d.xml
@@ -63,7 +62,7 @@ set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/a
 foreach(x app-masterworker 
           cloud-capping cloud-masterworker cloud-migration
           dht-pastry dht-kademlia platform-failures
-          energy-onoff energy-vm
+          energy-vm
           process-create 
           synchro-semaphore)
   ADD_TESH_FACTORIES(msg-${x} "thread;ucontext;raw;boost" 
diff --git a/examples/msg/energy-onoff/energy-onoff.c b/examples/msg/energy-onoff/energy-onoff.c
deleted file mode 100644 (file)
index cd82406..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "simgrid/msg.h"
-#include "simgrid/plugins/energy.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-static void simulate_bootup(msg_host_t host) {
-  int previous_pstate = MSG_host_get_pstate(host);
-
-  XBT_INFO("Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example");
-  MSG_host_set_pstate(host,3);
-
-  msg_host_t host_list[1] = {host};
-  double flops_amount[1] = {1};
-  double bytes_amount[1] = {0};
-
-  XBT_INFO("Actually start the host");
-  MSG_host_on(host);
-
-  XBT_INFO("Simulate the boot up by executing one flop on that host");
-  // We use a parallel task to run some task on a remote host.
-  msg_task_t bootup = MSG_parallel_task_create("boot up", 1, host_list, flops_amount, bytes_amount, NULL);
-  MSG_task_execute(bootup);
-  MSG_task_destroy(bootup);
-
-  XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
-  MSG_host_set_pstate(host, previous_pstate);
-}
-
-static void simulate_shutdown(msg_host_t host) {
-  int previous_pstate = MSG_host_get_pstate(host);
-
-  XBT_INFO("Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example");
-  MSG_host_set_pstate(host,4);
-
-  msg_host_t host_list[1] = {host};
-  double flops_amount[1] = {1};
-  double bytes_amount[1] = {0};
-
-  XBT_INFO("Simulate the shutdown by executing one flop on that remote host (using a parallel task)");
-  msg_task_t shutdown = MSG_parallel_task_create("shutdown", 1, host_list, flops_amount, bytes_amount, NULL);
-  MSG_task_execute(shutdown);
-  MSG_task_destroy(shutdown);
-
-  XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
-  MSG_host_set_pstate(host, previous_pstate);
-
-  XBT_INFO("Actually shutdown the host");
-  MSG_host_off(host);
-}
-
-static int onoff(int argc, char *argv[]) {
-  msg_host_t host1 = MSG_host_by_name("MyHost1");
-
-  XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host1,"watt_per_state"));
-  XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_speed(host1),
-           sg_host_get_consumed_energy(host1));
-
-  XBT_INFO("Sleep for 10 seconds");
-  MSG_process_sleep(10);
-  XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J", MSG_host_get_speed(host1),
-           sg_host_get_consumed_energy(host1));
-
-  simulate_shutdown(host1);
-  XBT_INFO("Host1 is now OFF. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", MSG_host_get_speed(host1),
-           sg_host_get_consumed_energy(host1));
-
-  XBT_INFO("Sleep for 10 seconds");
-  MSG_process_sleep(10);
-  XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J", MSG_host_get_speed(host1),
-           sg_host_get_consumed_energy(host1));
-
-  simulate_bootup(host1);
-  XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", MSG_host_get_speed(host1),
-           sg_host_get_consumed_energy(host1));
-
-  return 0;
-}
-
-int main(int argc, char *argv[])
-{
-  sg_host_energy_plugin_init();
-  MSG_init(&argc, argv);
-
-  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
-
-  MSG_create_environment(argv[1]);
-
-  MSG_process_create("onoff_test", onoff, NULL, MSG_get_host_by_name("MyHost2"));
-
-  msg_error_t res = MSG_main();
-
-  XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
-
-  return res != MSG_OK;
-}
diff --git a/examples/msg/energy-onoff/energy-onoff.tesh b/examples/msg/energy-onoff/energy-onoff.tesh
deleted file mode 100644 (file)
index 94f529a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#! ./tesh
-
-p Testing the mechanism for computing host energy consumption
-
-! output sort 19
-$ ${bindir:=.}/energy-onoff$EXEEXT ${srcdir:=.}/platform_onoff.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:onoff_test@MyHost2) Energetic profile: 95.0:200.0,93.0:170.0,90.0:150.0, 120:120,110:110
-> [  0.000000] (1:onoff_test@MyHost2) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J
-> [  0.000000] (1:onoff_test@MyHost2) Sleep for 10 seconds
-> [ 10.000000] (1:onoff_test@MyHost2) Done sleeping. Current peak speed=1E+08; Energy dissipated=950.00 J
-> [ 10.000000] (1:onoff_test@MyHost2) Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example
-> [ 10.000000] (1:onoff_test@MyHost2) Simulate the shutdown by executing one flop on that remote host (using a parallel task)
-> [ 16.997901] (1:onoff_test@MyHost2) Switch back to previously selected pstate 0
-> [ 16.997901] (1:onoff_test@MyHost2) Actually shutdown the host
-> [ 16.997901] (1:onoff_test@MyHost2) Host1 is now OFF. Current peak speed=1E+08 flop/s; Energy dissipated=1720 J
-> [ 16.997901] (1:onoff_test@MyHost2) Sleep for 10 seconds
-> [ 26.997901] (1:onoff_test@MyHost2) Done sleeping. Current peak speed=1E+08; Energy dissipated=1819.77 J
-> [ 26.997901] (1:onoff_test@MyHost2) Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example
-> [ 26.997901] (1:onoff_test@MyHost2) Actually start the host
-> [ 26.997901] (1:onoff_test@MyHost2) Simulate the boot up by executing one flop on that host
-> [176.997893] (0:maestro@) Total energy consumption: 37519.557482 Joules (used hosts: 37519.557482 Joules; unused/idle hosts: 0.000000)
-> [176.997893] (0:maestro@) Total simulation time: 177.00
-> [176.997893] (0:maestro@) Energy consumption of host MyHost1: 19819.768169 Joules
-> [176.997893] (0:maestro@) Energy consumption of host MyHost2: 17699.789313 Joules
-> [176.997893] (1:onoff_test@MyHost2) Switch back to previously selected pstate 0
-> [176.997893] (1:onoff_test@MyHost2) Host1 is now ON again. Current peak speed=1E+08 flop/s; Energy dissipated=19820 J
-
-! output sort 19
-$ ${bindir:=.}/energy-onoff$EXEEXT ${srcdir:=.}/platform_onoff.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=host/model:ptask_L07
-> [  0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07'
-> [  0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks.
-> [  0.000000] (1:onoff_test@MyHost2) Energetic profile: 95.0:200.0,93.0:170.0,90.0:150.0, 120:120,110:110
-> [  0.000000] (1:onoff_test@MyHost2) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J
-> [  0.000000] (1:onoff_test@MyHost2) Sleep for 10 seconds
-> [ 10.000000] (1:onoff_test@MyHost2) Done sleeping. Current peak speed=1E+08; Energy dissipated=950.00 J
-> [ 10.000000] (1:onoff_test@MyHost2) Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example
-> [ 10.000000] (1:onoff_test@MyHost2) Simulate the shutdown by executing one flop on that remote host (using a parallel task)
-> [ 16.997901] (1:onoff_test@MyHost2) Switch back to previously selected pstate 0
-> [ 16.997901] (1:onoff_test@MyHost2) Actually shutdown the host
-> [ 16.997901] (1:onoff_test@MyHost2) Host1 is now OFF. Current peak speed=1E+08 flop/s; Energy dissipated=1720 J
-> [ 16.997901] (1:onoff_test@MyHost2) Sleep for 10 seconds
-> [ 26.997901] (1:onoff_test@MyHost2) Done sleeping. Current peak speed=1E+08; Energy dissipated=1819.77 J
-> [ 26.997901] (1:onoff_test@MyHost2) Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example
-> [ 26.997901] (1:onoff_test@MyHost2) Actually start the host
-> [ 26.997901] (1:onoff_test@MyHost2) Simulate the boot up by executing one flop on that host
-> [176.997893] (0:maestro@) Total energy consumption: 37519.557482 Joules (used hosts: 37519.557482 Joules; unused/idle hosts: 0.000000)
-> [176.997893] (0:maestro@) Total simulation time: 177.00
-> [176.997893] (0:maestro@) Energy consumption of host MyHost1: 19819.768169 Joules
-> [176.997893] (0:maestro@) Energy consumption of host MyHost2: 17699.789313 Joules
-> [176.997893] (1:onoff_test@MyHost2) Switch back to previously selected pstate 0
-> [176.997893] (1:onoff_test@MyHost2) Host1 is now ON again. Current peak speed=1E+08 flop/s; Energy dissipated=19820 J
-
diff --git a/examples/msg/energy-onoff/platform_onoff.xml b/examples/msg/energy-onoff/platform_onoff.xml
deleted file mode 100644 (file)
index 5010de2..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
-<platform version="4.1">
-  <zone  id="AS0"  routing="Full">
-
-    <!-- Use the pstate mechanism to encode the boot/shutdown time and energy -->
-
-    <!-- That may be seen as a misuse of the pstate mechanism and crude hack, but this is efficient: we can do what 
-         we want without too much burden, and since the whole intelligence is at user level, we do control the model. 
-
-         The same could be done to encode the time and energy to switch between pstates. These times seem negligible 
-         in our experiments, but if they are important to you, now you know how to do that. -->
-
-    <!-- pstate values:
-      * 0-2: real pstates
-         0: p1 100 MFlops/s, [idle: 95W -> full burning: 200W]
-         1: p2  50 MFlops/s, [idle: 93W -> full burning: 170W]
-         2: p3  20 MFlops/s, [idel: 90W -> full burning: 150W] 
-      * 3: booting up was measured to take 150s and 18000J.
-           So we create a pstate with 1 flop/150 s so that the application burns 1 flop in that virtual pstate to
-           simulate a boot.
-           Multiply everything by 1000 or whatever if this trick is too painful to you, that's the same by the end.
-           The energy consumption is 18000/150=120W
-      * 4: shutting down was measured to take 7 s and 770 J
-
-      Please note that we tried to put sensible values in this file but you should still take them with a grain of salt.
-      If you want a realistic simulation, you have to actually benchmark your platform and application, and use the 
-      values that are right for you. -->
-
-    <host id="MyHost1" speed="100.0Mf,50.0Mf,20.0Mf,                               0.006666667f,0.1429f" pstate="0" >
-      <prop id="watt_per_state" value="95.0:200.0,93.0:170.0,90.0:150.0, 120:120,110:110" />
-      <prop id="watt_off"       value="10" />
-    </host>
-    <host id="MyHost2" speed="100.0Mf" >
-      <prop id="watt_per_state" value="100.0:200.0" />
-      <prop id="watt_off"       value="10" />
-    </host>
-
-    <link id="link1" bandwidth="100kBps" latency="0"/>
-    <route src="MyHost1" dst="MyHost2">
-      <link_ctn id="link1"/>
-    </route>
-  </zone>
-</platform>
index 010edb3..2af1506 100644 (file)
@@ -2,7 +2,7 @@ foreach (example actor-create actor-daemon actor-join actor-kill actor-lifetime
                  app-chainsend app-masterworker app-pingpong app-token-ring
                  async-wait async-waitany async-waitall
                  cloud-simple
-                 energy-exec energy-link energy-vm
+                 energy-exec energy-boot energy-link energy-vm
                  exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote
                  io-file-system io-file-remote io-storage-raw
                  mutex
@@ -55,6 +55,7 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/energy-boot/platform_boot.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/io-file-remote/s4u-io-file-remote_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/platform-properties/s4u-platform-properties_d.xml
                                  ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split_d.xml
@@ -72,7 +73,7 @@ foreach(example actor-create actor-daemon actor-join actor-kill actor-lifetime a
                 async-wait async-waitall async-waitany
                 cloud-simple
                 dht-chord 
-                energy-exec energy-link energy-vm
+                energy-exec energy-boot energy-link energy-vm
                 exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote
                 platform-properties plugin-hostload mutex
                 io-file-system io-file-remote io-storage-raw
index 7c8a609..cafaae8 100644 (file)
@@ -244,6 +244,12 @@ result in short reads and short write, as in reality.
     This example shows how to retrieve and display the energy consumed
     by the network during communications.
 
+  - <b>Modeling the shutdown and boot of hosts</b>
+    @ref examples/s4u/energy-boot/platform_boot.xml
+    @ref examples/s4u/energy-boot/s4u-energy-boot.cpp\n
+    Simple example of model of model for the energy consumption during
+    the host boot and shutdown periods.
+
 @section s4u_ex_tracing Tracing and visualization features
 
 Tracing can be activated by various configuration options which
@@ -310,20 +316,22 @@ than the previous examples.
 @example examples/s4u/async-wait/s4u-async-wait.cpp
 @example examples/s4u/async-waitall/s4u-async-waitall.cpp
 @example examples/s4u/async-waitany/s4u-async-waitany.cpp
-@example examples/s4u/dht-chord/s4u-dht-chord.cpp
-@example examples/s4u/exec-basic/s4u-exec-basic.cpp
-@example examples/s4u/exec-async/s4u-exec-async.cpp
-@example examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
-@example examples/s4u/exec-monitor/s4u-exec-monitor.cpp
-@example examples/s4u/exec-ptask/s4u-exec-ptask.cpp
-@example examples/s4u/exec-remote/s4u-exec-remote.cpp 
 @example examples/s4u/app-bittorrent/s4u-bittorrent.cpp
 @example examples/s4u/app-chainsend/s4u-app-chainsend.cpp
 @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp
 @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp
 @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp
+@example examples/s4u/dht-chord/s4u-dht-chord.cpp
+@example examples/s4u/energy-boot/platform_boot.xml
+@example examples/s4u/energy-boot/s4u-energy-boot.cpp
 @example examples/s4u/energy-exec/s4u-energy-exec.cpp
 @example examples/s4u/energy-link/s4u-energy-link.cpp
+@example examples/s4u/exec-basic/s4u-exec-basic.cpp
+@example examples/s4u/exec-async/s4u-exec-async.cpp
+@example examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
+@example examples/s4u/exec-monitor/s4u-exec-monitor.cpp
+@example examples/s4u/exec-ptask/s4u-exec-ptask.cpp
+@example examples/s4u/exec-remote/s4u-exec-remote.cpp 
 @example examples/s4u/io-file-system/s4u-io-file-system.cpp
 @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp
 @example examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp
diff --git a/examples/s4u/energy-boot/platform_boot.xml b/examples/s4u/energy-boot/platform_boot.xml
new file mode 100644 (file)
index 0000000..f137829
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4.1">
+  <zone  id="AS0"  routing="Full">
+
+    <!-- Use the pstate mechanism to encode the boot/shutdown time and energy.
+      --
+      -- See the C++ file in the same directory for more information.
+      -->
+
+    <!-- pstate values:
+      * 0-2: real pstates
+         0: p1 100 MFlops/s, [idle: 95W -> full burning: 200W]
+         1: p2  50 MFlops/s, [idle: 93W -> full burning: 170W]
+         2: p3  20 MFlops/s, [idel: 90W -> full burning: 150W] 
+      * 3: booting up was measured to take 150s and 18000J.
+           So we create a pstate 3 consuming 18000J/150s=120W, and a boot remains at this pstate for 150s.
+           Speed is set at 0 flop/s so that nothing progresses during the boot.
+      * 4: shutting down was measured to take 7 s and 770 J
+           So we create a pstate 4 consuming 770J/7s=110W, and a boot remains at this pstate for 7s.
+
+      Please note that even if these values are educated guesses, you should still challenge them.
+      If you want a realistic simulation, you have to use values coming from a real benchmark of your platform. 
+      -->
+
+    <host id="MyHost1"          speed="100.0Mf,50.0Mf,20.0Mf,                    0f,0f" pstate="0" >
+      <prop id="watt_per_state" value="95.0:200.0,93.0:170.0,90.0:150.0,         120:120,110:110" />
+      <prop id="watt_off"       value="10" />
+    </host>
+    <host id="MyHost2" speed="100.0Mf" >
+      <prop id="watt_per_state" value="100.0:200.0" />
+      <prop id="watt_off"       value="10" />
+    </host>
+
+    <link id="link1" bandwidth="100kBps" latency="0"/>
+    <route src="MyHost1" dst="MyHost2">
+      <link_ctn id="link1"/>
+    </route>
+  </zone>
+</platform>
diff --git a/examples/s4u/energy-boot/s4u-energy-boot.cpp b/examples/s4u/energy-boot/s4u-energy-boot.cpp
new file mode 100644 (file)
index 0000000..4be7995
--- /dev/null
@@ -0,0 +1,115 @@
+/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* This is an example of how the bootup and shutdown periods can be modeled
+ * with SimGrid, takes both the time and overall consumption into account.
+ *
+ * The main idea is to augment the platform description to declare fake
+ * pstate that represent these states. The CPU speed of these state is zero
+ * (the CPU delivers 0 flop per second when booting) while the energy
+ * consumption is the one measured on average on the modeled machine.
+ *
+ * When you want to bootup the machine, you set it into the pstate encoding
+ * the boot (3 in this example), and leave it so for the right time using a
+ * sleep_for(). During that time no other execution can progress since the
+ * resource speed is set at 0 flop/s in this fake pstate. Once this is over,
+ * the boot is done and we switch back to the regular pstate. Conversely,
+ * the fake pstate 4 is used to encode the shutdown delay.
+ *
+ * Some people don't like the idea to add fake pstates for the boot time, and
+ * would like SimGrid to provide a "cleaner" model for that. But the "right"
+ * model depends on the study you want to conduct. If you want to study the
+ * instantaneous consumption of a rebooting data center, the model used here
+ * is not enough since it considers only the average consumption over the boot,
+ * while the instantaneous consumption changes dramatically. Conversely, a
+ * model taking the instantaneous changes into account will be very difficult
+ * to instantiate correctly (which values will you use?), so it's not adapted
+ * to most studies. At least, fake pstates allow you to do exactly what you
+ * need for your very study.
+ */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/plugins/energy.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this example");
+
+static void simulate_bootup(simgrid::s4u::Host* host)
+{
+  int previous_pstate = host->getPstate();
+
+  XBT_INFO("Switch to virtual pstate 3, that encodes the 'booting up' state in that platform");
+  host->setPstate(3);
+
+  XBT_INFO("Actually start the host");
+  host->turnOn();
+
+  XBT_INFO("Wait 150s to simulate the boot time.");
+  simgrid::s4u::this_actor::sleep_for(150);
+
+  XBT_INFO("The host is now up and running. Switch back to previous pstate %d", previous_pstate);
+  host->setPstate(previous_pstate);
+}
+
+static void simulate_shutdown(simgrid::s4u::Host* host)
+{
+  int previous_pstate = host->getPstate();
+
+  XBT_INFO("Switch to virtual pstate 4, that encodes the 'shutting down' state in that platform");
+  host->setPstate(4);
+
+  XBT_INFO("Wait 7 seconds to simulate the shutdown time.");
+  simgrid::s4u::this_actor::sleep_for(7);
+
+  XBT_INFO("Switch back to previous pstate %d, that will be used on reboot.", previous_pstate);
+  host->setPstate(previous_pstate);
+
+  XBT_INFO("Actually shutdown the host");
+  host->turnOff();
+}
+
+static int monitor()
+{
+  simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
+
+  XBT_INFO("Initial pstate: %d; Energy dissipated so far:%.0E J", host1->getPstate(),
+           sg_host_get_consumed_energy(host1));
+
+  XBT_INFO("Sleep for 10 seconds");
+  simgrid::s4u::this_actor::sleep_for(10);
+  XBT_INFO("Done sleeping. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
+           sg_host_get_consumed_energy(host1));
+
+  simulate_shutdown(host1);
+  XBT_INFO("Host1 is now OFF. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
+           sg_host_get_consumed_energy(host1));
+
+  XBT_INFO("Sleep for 10 seconds");
+  simgrid::s4u::this_actor::sleep_for(10);
+  XBT_INFO("Done sleeping. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
+           sg_host_get_consumed_energy(host1));
+
+  simulate_bootup(host1);
+  XBT_INFO("Host1 is now ON again. Current pstate: %d; Energy dissipated so far: %.2f J", host1->getPstate(),
+           sg_host_get_consumed_energy(host1));
+
+  return 0;
+}
+
+int main(int argc, char* argv[])
+{
+  sg_host_energy_plugin_init();
+  simgrid::s4u::Engine e(&argc, argv);
+
+  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
+
+  e.loadPlatform(argv[1]);
+  simgrid::s4u::Actor::createActor("Boot Monitor", simgrid::s4u::Host::by_name("MyHost2"), monitor);
+
+  e.run();
+
+  XBT_INFO("End of simulation.");
+
+  return 0;
+}
diff --git a/examples/s4u/energy-boot/s4u-energy-boot.tesh b/examples/s4u/energy-boot/s4u-energy-boot.tesh
new file mode 100644 (file)
index 0000000..6f9f4c9
--- /dev/null
@@ -0,0 +1,47 @@
+#! ./tesh
+
+p Modeling the host energy consumption during boot and shutdown
+
+$ ${bindir:=.}/s4u-energy-boot$EXEEXT ${srcdir:=.}/platform_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:Boot Monitor@MyHost2) Initial pstate: 0; Energy dissipated so far:0E+00 J
+> [  0.000000] (1:Boot Monitor@MyHost2) Sleep for 10 seconds
+> [ 10.000000] (1:Boot Monitor@MyHost2) Done sleeping. Current pstate: 0; Energy dissipated so far: 950.00 J
+> [ 10.000000] (1:Boot Monitor@MyHost2) Switch to virtual pstate 4, that encodes the 'shutting down' state in that platform
+> [ 10.000000] (1:Boot Monitor@MyHost2) Wait 7 seconds to simulate the shutdown time.
+> [ 17.000000] (1:Boot Monitor@MyHost2) Switch back to previous pstate 0, that will be used on reboot.
+> [ 17.000000] (1:Boot Monitor@MyHost2) Actually shutdown the host
+> [ 17.000000] (1:Boot Monitor@MyHost2) Host1 is now OFF. Current pstate: 0; Energy dissipated so far: 1720.00 J
+> [ 17.000000] (1:Boot Monitor@MyHost2) Sleep for 10 seconds
+> [ 27.000000] (1:Boot Monitor@MyHost2) Done sleeping. Current pstate: 0; Energy dissipated so far: 1820.00 J
+> [ 27.000000] (1:Boot Monitor@MyHost2) Switch to virtual pstate 3, that encodes the 'booting up' state in that platform
+> [ 27.000000] (1:Boot Monitor@MyHost2) Actually start the host
+> [ 27.000000] (1:Boot Monitor@MyHost2) Wait 150s to simulate the boot time.
+> [177.000000] (1:Boot Monitor@MyHost2) The host is now up and running. Switch back to previous pstate 0
+> [177.000000] (1:Boot Monitor@MyHost2) Host1 is now ON again. Current pstate: 0; Energy dissipated so far: 19820.00 J
+> [177.000000] (0:maestro@) Total energy consumption: 37520.000000 Joules (used hosts: 37520.000000 Joules; unused/idle hosts: 0.000000)
+> [177.000000] (0:maestro@) End of simulation.
+> [177.000000] (0:maestro@) Energy consumption of host MyHost1: 19820.000000 Joules
+> [177.000000] (0:maestro@) Energy consumption of host MyHost2: 17700.000000 Joules
+
+$ ${bindir:=.}/s4u-energy-boot$EXEEXT ${srcdir:=.}/platform_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=host/model:ptask_L07
+> [  0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07'
+> [  0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks.
+> [  0.000000] (1:Boot Monitor@MyHost2) Initial pstate: 0; Energy dissipated so far:0E+00 J
+> [  0.000000] (1:Boot Monitor@MyHost2) Sleep for 10 seconds
+> [ 10.000000] (1:Boot Monitor@MyHost2) Done sleeping. Current pstate: 0; Energy dissipated so far: 950.00 J
+> [ 10.000000] (1:Boot Monitor@MyHost2) Switch to virtual pstate 4, that encodes the 'shutting down' state in that platform
+> [ 10.000000] (1:Boot Monitor@MyHost2) Wait 7 seconds to simulate the shutdown time.
+> [ 17.000000] (1:Boot Monitor@MyHost2) Switch back to previous pstate 0, that will be used on reboot.
+> [ 17.000000] (1:Boot Monitor@MyHost2) Actually shutdown the host
+> [ 17.000000] (1:Boot Monitor@MyHost2) Host1 is now OFF. Current pstate: 0; Energy dissipated so far: 1720.00 J
+> [ 17.000000] (1:Boot Monitor@MyHost2) Sleep for 10 seconds
+> [ 27.000000] (1:Boot Monitor@MyHost2) Done sleeping. Current pstate: 0; Energy dissipated so far: 1820.00 J
+> [ 27.000000] (1:Boot Monitor@MyHost2) Switch to virtual pstate 3, that encodes the 'booting up' state in that platform
+> [ 27.000000] (1:Boot Monitor@MyHost2) Actually start the host
+> [ 27.000000] (1:Boot Monitor@MyHost2) Wait 150s to simulate the boot time.
+> [177.000000] (1:Boot Monitor@MyHost2) The host is now up and running. Switch back to previous pstate 0
+> [177.000000] (1:Boot Monitor@MyHost2) Host1 is now ON again. Current pstate: 0; Energy dissipated so far: 19820.00 J
+> [177.000000] (0:maestro@) Total energy consumption: 37520.000000 Joules (used hosts: 37520.000000 Joules; unused/idle hosts: 0.000000)
+> [177.000000] (0:maestro@) End of simulation.
+> [177.000000] (0:maestro@) Energy consumption of host MyHost1: 19820.000000 Joules
+> [177.000000] (0:maestro@) Energy consumption of host MyHost2: 17700.000000 Joules