Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert this example too
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 5 Dec 2017 08:31:47 +0000 (09:31 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 5 Dec 2017 08:32:09 +0000 (09:32 +0100)
.gitignore
examples/s4u/CMakeLists.txt
examples/s4u/energy-vm/s4u-energy-vm.cpp [new file with mode: 0644]
examples/s4u/energy-vm/s4u-energy-vm.tesh [new file with mode: 0644]

index c76894c..d985817 100644 (file)
@@ -205,6 +205,7 @@ examples/s4u/dht-chord/s4u-dht-chord
 examples/s4u/energy-link/s4u-energy-link
 examples/s4u/energy-ptask/s4u-energy-ptask
 examples/s4u/energy-pstate/s4u-energy-pstate
+examples/s4u/energy-vm/s4u-energy-vm
 examples/s4u/io/s4u-io
 examples/s4u/io-file-remote/s4u-io-file-remote
 examples/s4u/io-storage-raw/s4u-io-storage-raw
index 7a1b5f5..d20f005 100644 (file)
@@ -2,7 +2,7 @@ foreach (example actions-comm actions-storage
                  actor-create actor-daemon actor-execute actor-join actor-kill actor-lifetime actor-migration actor-suspend actor-yield
                  app-masterworker app-pingpong app-token-ring
                  async-wait async-waitany async-waitall
-                 energy-link energy-pstate energy-ptask
+                 energy-link energy-pstate energy-ptask energy-vm
                  io io-file-remote io-storage-raw
                  platform-properties plugin-hostload mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
@@ -68,7 +68,7 @@ foreach(example actions-comm actions-storage
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
                 async-wait async-waitall async-waitany
                 dht-chord 
-                energy-link energy-pstate energy-ptask
+                energy-link energy-pstate energy-ptask energy-vm
                 platform-properties plugin-hostload mutex
                 io io-file-remote io-storage-raw)
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" 
diff --git a/examples/s4u/energy-vm/s4u-energy-vm.cpp b/examples/s4u/energy-vm/s4u-energy-vm.cpp
new file mode 100644 (file)
index 0000000..8855473
--- /dev/null
@@ -0,0 +1,72 @@
+/* Copyright (c) 2007-2010, 2013-2015, 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. */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/plugins/energy.h"
+#include "simgrid/s4u/VirtualMachine.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(energy_vm, "Messages of this example");
+
+static void executor()
+{
+  simgrid::s4u::this_actor::execute(300E6);
+  XBT_INFO("This worker is done.");
+}
+
+static void dvfs()
+{
+  simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
+  simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
+  simgrid::s4u::Host* host3 = simgrid::s4u::Host::by_name("MyHost3");
+
+  /* Host 1 */
+  XBT_INFO("Creating and starting two VMs");
+  simgrid::s4u::VirtualMachine* vm_host1 = new simgrid::s4u::VirtualMachine("vm_host1", host1, 1);
+  vm_host1->start();
+  simgrid::s4u::VirtualMachine* vm_host2 = new simgrid::s4u::VirtualMachine("vm_host2", host2, 1);
+  vm_host2->start();
+
+  XBT_INFO("Create two tasks on Host1: both inside a VM");
+  simgrid::s4u::Actor::createActor("p11", vm_host1, executor);
+  simgrid::s4u::Actor::createActor("p12", vm_host1, executor);
+
+  XBT_INFO("Create two tasks on Host2: one inside a VM, the other directly on the host");
+  simgrid::s4u::Actor::createActor("p21", vm_host2, executor);
+  simgrid::s4u::Actor::createActor("p22", host2, executor);
+
+  XBT_INFO("Create two tasks on Host3: both directly on the host");
+  simgrid::s4u::Actor::createActor("p31", host3, executor);
+  simgrid::s4u::Actor::createActor("p32", host3, executor);
+
+  XBT_INFO("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, "
+           "so they run for 6 seconds)");
+  simgrid::s4u::this_actor::sleep_for(5);
+  XBT_INFO("Wait another 5 seconds. The tasks stop at some point in between");
+  simgrid::s4u::this_actor::sleep_for(5);
+
+  vm_host1->destroy();
+  vm_host2->destroy();
+}
+
+int main(int argc, char* argv[])
+{
+  sg_host_energy_plugin_init();
+  simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+
+  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+
+  e->loadPlatform(argv[1]);
+
+  simgrid::s4u::Actor::createActor("dvfs", simgrid::s4u::Host::by_name("MyHost1"), dvfs);
+
+  e->run();
+
+  XBT_INFO("Total simulation time: %.2f; Host2 and Host3 must have the exact same energy consumption; Host1 is "
+           "multi-core and will differ.",
+           simgrid::s4u::Engine::getClock());
+
+  return 0;
+}
diff --git a/examples/s4u/energy-vm/s4u-energy-vm.tesh b/examples/s4u/energy-vm/s4u-energy-vm.tesh
new file mode 100644 (file)
index 0000000..08f8f4f
--- /dev/null
@@ -0,0 +1,22 @@
+#! ./tesh
+
+p Testing the mechanism for computing host energy consumption in case of VMs
+
+$ ${bindir:=.}/s4u-energy-vm$EXEEXT ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:dvfs@MyHost1) Creating and starting two VMs
+> [  0.000000] (1:dvfs@MyHost1) Create two tasks on Host1: both inside a VM
+> [  0.000000] (1:dvfs@MyHost1) Create two tasks on Host2: one inside a VM, the other directly on the host
+> [  0.000000] (1:dvfs@MyHost1) Create two tasks on Host3: both directly on the host
+> [  0.000000] (1:dvfs@MyHost1) Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, so they run for 6 seconds)
+> [  5.000000] (1:dvfs@MyHost1) Wait another 5 seconds. The tasks stop at some point in between
+> [  6.000000] (5:p22@MyHost2) This worker is done.
+> [  6.000000] (7:p32@MyHost3) This worker is done.
+> [  6.000000] (6:p31@MyHost3) This worker is done.
+> [  6.000000] (3:p12@vm_host1) This worker is done.
+> [  6.000000] (2:p11@vm_host1) This worker is done.
+> [  6.000000] (4:p21@vm_host2) This worker is done.
+> [ 10.000000] (0:maestro@) Total energy consumption: 4320.000000 Joules (used hosts: 4320.000000 Joules; unused/idle hosts: 0.000000)
+> [ 10.000000] (0:maestro@) Total simulation time: 10.00; Host2 and Host3 must have the exact same energy consumption; Host1 is multi-core and will differ.
+> [ 10.000000] (0:maestro@) Energy consumption of host MyHost1: 1120.000000 Joules
+> [ 10.000000] (0:maestro@) Energy consumption of host MyHost2: 1600.000000 Joules
+> [ 10.000000] (0:maestro@) Energy consumption of host MyHost3: 1600.000000 Joules