From 34a2576110368644e1a8b8ca7d608e28400cddd1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 9 Jun 2015 17:06:55 +0200 Subject: [PATCH] New example for MSG host ON/OFF switching --- .gitignore | 1 + ChangeLog | 4 +- buildtools/Cmake/AddTests.cmake | 1 + buildtools/Cmake/MakeExe.cmake | 1 + examples/msg/energy/onoff/CMakeLists.txt | 31 +++++ .../msg/energy/onoff/deployment_onoff.xml | 7 + examples/msg/energy/onoff/onoff.c | 128 ++++++++++++++++++ examples/msg/energy/onoff/onoff.tesh | 25 ++++ examples/msg/energy/onoff/platform_onoff.xml | 51 +++++++ 9 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 examples/msg/energy/onoff/CMakeLists.txt create mode 100644 examples/msg/energy/onoff/deployment_onoff.xml create mode 100644 examples/msg/energy/onoff/onoff.c create mode 100644 examples/msg/energy/onoff/onoff.tesh create mode 100644 examples/msg/energy/onoff/platform_onoff.xml diff --git a/.gitignore b/.gitignore index a3bc4683c6..f39dd86a97 100644 --- a/.gitignore +++ b/.gitignore @@ -139,6 +139,7 @@ examples/msg/cloud/scale examples/msg/cloud/simple_vm examples/msg/cloud/two_tasks_vm examples/msg/energy/pstate/pstate +examples/msg/energy/onoff/onoff examples/msg/energy/e2/e2 examples/msg/energy/e3/e3 examples/msg/pastry/pastry diff --git a/ChangeLog b/ChangeLog index ceb1e4d462..565fe293c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,7 +11,9 @@ SimGrid (3.12) NOT RELEASED; urgency=low get_data_size(t) -> get_bytes_amount(t) - Massive cleanups in the functions related to the energy - MSG_host_get_pstate_number() -> MSG_host_get_nb_pstates() - - New: MSG_host_get_pstate() + - New: MSG_host_get_pstate() + * New example: + - msg/energy/onoff: switching hosts on and off jMSG: * Interface improvement: - Rename Host.isAvail() to Host.isOn() diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 4c0e4460a6..86d24c60aa 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -234,6 +234,7 @@ IF(NOT enable_memcheck) ADD_TESH_FACTORIES(msg-cloud-simple-vm "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/cloud/ --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg/cloud/ --cd ${CMAKE_BINARY_DIR}/examples/msg/cloud/ ${CMAKE_HOME_DIRECTORY}/examples/msg/cloud/simple_vm.tesh) ADD_TESH_FACTORIES(msg-energy-pstates "thread;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy/pstate/pstate.tesh) ADD_TESH_FACTORIES(msg-energy-consumption "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e2/energy_consumption.tesh) + ADD_TESH_FACTORIES(msg-energy-onoff "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy/onoff/onoff.tesh) ADD_TESH_FACTORIES(msg-energy-concurrent-tasks "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e3/concurrent_tasks.tesh) ADD_TESH_FACTORIES(msg-token-ring "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY} --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/token_ring.tesh) ADD_TESH_FACTORIES(msg-migration "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/migration/migration.tesh) diff --git a/buildtools/Cmake/MakeExe.cmake b/buildtools/Cmake/MakeExe.cmake index 926e241a73..4848c99b16 100644 --- a/buildtools/Cmake/MakeExe.cmake +++ b/buildtools/Cmake/MakeExe.cmake @@ -36,6 +36,7 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/cloud) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/pstate) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e2) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e3) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/onoff) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/exception) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/gpu) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/gtnets) diff --git a/examples/msg/energy/onoff/CMakeLists.txt b/examples/msg/energy/onoff/CMakeLists.txt new file mode 100644 index 0000000000..06ca5a6091 --- /dev/null +++ b/examples/msg/energy/onoff/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 2.6) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(onoff onoff.c) + +### Add definitions for compile +target_link_libraries(onoff simgrid ) + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/energy_consumption.tesh + PARENT_SCOPE + ) + +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/deployment_onoff.xml + PARENT_SCOPE + ) + +set(examples_src + ${examples_src} + ${CMAKE_CURRENT_SOURCE_DIR}/onoff.c + PARENT_SCOPE + ) + +set(bin_files + ${bin_files} + PARENT_SCOPE + ) diff --git a/examples/msg/energy/onoff/deployment_onoff.xml b/examples/msg/energy/onoff/deployment_onoff.xml new file mode 100644 index 0000000000..b3e8d26e72 --- /dev/null +++ b/examples/msg/energy/onoff/deployment_onoff.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/msg/energy/onoff/onoff.c b/examples/msg/energy/onoff/onoff.c new file mode 100644 index 0000000000..2a033783c2 --- /dev/null +++ b/examples/msg/energy/onoff/onoff.c @@ -0,0 +1,128 @@ +/* Copyright (c) 2007-2010, 2013-2014. 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 + +#include "simgrid/msg.h" +#include "xbt/sysdep.h" /* calloc */ +#include "simgrid/plugins.h" + +/* Create a log channel to have nice outputs. */ +#include "xbt/log.h" +#include "xbt/asserts.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_get_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_current_power_peak(host1), MSG_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_current_power_peak(host1), MSG_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_current_power_peak(host1), MSG_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_current_power_peak(host1), MSG_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_current_power_peak(host1), MSG_host_get_consumed_energy(host1)); + + + return 0; +} + +int main(int argc, char *argv[]) +{ + msg_error_t res = MSG_OK; + sg_energy_plugin_init(); + MSG_init(&argc, argv); + + if (argc != 3) { + XBT_CRITICAL("Usage: %s platform_file deployment_file\n", + argv[0]); + XBT_CRITICAL + ("example: %s msg_platform.xml msg_deployment.xml\n", + argv[0]); + exit(1); + } + + MSG_create_environment(argv[1]); + + /* Application deployment */ + MSG_function_register("onoff_test", onoff); + + MSG_launch_application(argv[2]); + + res = MSG_main(); + + XBT_INFO("Total simulation time: %.2f", MSG_get_clock()); + + if (res == MSG_OK) + return 0; + else + return 1; +} + diff --git a/examples/msg/energy/onoff/onoff.tesh b/examples/msg/energy/onoff/onoff.tesh new file mode 100644 index 0000000000..ed6091cda5 --- /dev/null +++ b/examples/msg/energy/onoff/onoff.tesh @@ -0,0 +1,25 @@ +#! ./tesh + +p Testing the mechanism for computing host energy consumption + +! output sort +$ $SG_TEST_EXENV energy/onoff/onoff$EXEEXT ${srcdir:=.}/energy/onoff/platform_onoff.xml ${srcdir:=.}/energy/onoff/deployment_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:@) Total simulation time: 177.00 +> [176.997893] (0:@) Total energy of host MyHost1: 19819.768169 Joules +> [176.997893] (0:@) Total energy 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 new file mode 100644 index 0000000000..64a58a5e96 --- /dev/null +++ b/examples/msg/energy/onoff/platform_onoff.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.20.1