From 9ba4cc81c2019fce2a4647f8724435eaa9af960c Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 13 Feb 2020 00:32:53 +0100 Subject: [PATCH] convert msg/energy-consumption to c/energy-exec --- .gitignore | 1 - MANIFEST.in | 4 +- examples/c/CMakeLists.txt | 6 +- examples/c/energy-exec/energy-exec.c | 85 +++++++++++++++++++ .../c/energy-exec/energy-exec.tesh | 8 +- teshsuite/msg/CMakeLists.txt | 4 +- .../energy-consumption/energy-consumption.c | 84 ------------------ 7 files changed, 97 insertions(+), 95 deletions(-) create mode 100644 examples/c/energy-exec/energy-exec.c rename teshsuite/msg/energy-consumption/energy-consumption.tesh => examples/c/energy-exec/energy-exec.tesh (91%) delete mode 100644 teshsuite/msg/energy-consumption/energy-consumption.c diff --git a/.gitignore b/.gitignore index 938024f499..0513a60904 100644 --- a/.gitignore +++ b/.gitignore @@ -247,7 +247,6 @@ teshsuite/msg/cloud-capping/cloud-capping teshsuite/msg/cloud-migration/cloud-migration teshsuite/msg/cloud-simple/cloud-simple teshsuite/msg/cloud-two-tasks/cloud-two-tasks -teshsuite/msg/energy-consumption/energy-consumption teshsuite/msg/energy-pstate/energy-pstate teshsuite/msg/energy-ptask/energy-ptask teshsuite/msg/get_sender/get_sender diff --git a/MANIFEST.in b/MANIFEST.in index ebe4a9e962..7db7a4ae31 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -45,6 +45,8 @@ include examples/c/async-waitall/async-waitall_d.xml include examples/c/async-waitany/async-waitany.c include examples/c/async-waitany/async-waitany.tesh include examples/c/async-waitany/async-waitany_d.xml +include examples/c/energy-exec/energy-exec.c +include examples/c/energy-exec/energy-exec.tesh include examples/c/io-disk-raw/io-disk-raw.c include examples/c/io-disk-raw/io-disk-raw.tesh include examples/deprecated/java/app/bittorrent/Common.java @@ -647,8 +649,6 @@ include teshsuite/msg/cloud-simple/cloud-simple.c include teshsuite/msg/cloud-simple/cloud-simple.tesh include teshsuite/msg/cloud-two-tasks/cloud-two-tasks.c include teshsuite/msg/cloud-two-tasks/cloud-two-tasks.tesh -include teshsuite/msg/energy-consumption/energy-consumption.c -include teshsuite/msg/energy-consumption/energy-consumption.tesh include teshsuite/msg/energy-pstate/energy-pstate.c include teshsuite/msg/energy-pstate/energy-pstate.tesh include teshsuite/msg/energy-ptask/energy-ptask.c diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 871a0bfaa7..23e2e054bc 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -2,6 +2,7 @@ foreach(x actor-create actor-daemon actor-exiting actor-join actor-kill actor-migrate actor-suspend actor-yield app-pingpong app-token-ring async-waitall async-waitany + energy-exec io-disk-raw) add_executable (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c) target_link_libraries(${x}-c simgrid) @@ -24,8 +25,9 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/actor-cr foreach(x actor-create actor-daemon actor-exiting actor-join actor-kill actor-migrate actor-suspend actor-yield - app-pingpong app-token-ring - async-waitall async-waitany + app-pingpong app-token-ring + async-waitall async-waitany + energy-exec io-disk-raw) ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x} diff --git a/examples/c/energy-exec/energy-exec.c b/examples/c/energy-exec/energy-exec.c new file mode 100644 index 0000000000..bddb036fdf --- /dev/null +++ b/examples/c/energy-exec/energy-exec.c @@ -0,0 +1,85 @@ +/* Copyright (c) 2007-2020. 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/actor.h" +#include "simgrid/engine.h" +#include "simgrid/host.h" +#include "simgrid/plugins/energy.h" +#include "xbt/asserts.h" +#include "xbt/config.h" +#include "xbt/log.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(energy_exec, "Messages specific for this example"); + +static void dvfs(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +{ + sg_host_t host = sg_host_by_name("MyHost1"); + + XBT_INFO("Energetic profile: %s", sg_host_get_property_value(host, "wattage_per_state")); + XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", sg_host_speed(host), + sg_host_get_consumed_energy(host)); + + double start = simgrid_get_clock(); + XBT_INFO("Sleep for 10 seconds"); + sg_actor_sleep_for(10); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", + simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_consumed_energy(host)); + + // Run a task + start = simgrid_get_clock(); + XBT_INFO("Run a task of %.0E flops", 100E6); + sg_actor_self_execute(100E6); + XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW" + " depending on load; Energy dissipated=%.0f J", + simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_wattmin_at(host, sg_host_get_pstate(host)), + sg_host_get_wattmax_at(host, sg_host_get_pstate(host)), sg_host_get_consumed_energy(host)); + + // ========= Change power peak ========= + int pstate = 2; + sg_host_set_pstate(host, pstate); + XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, + sg_host_get_pstate_speed(host, pstate), sg_host_speed(host)); + + // Run a second task + start = simgrid_get_clock(); + XBT_INFO("Run a task of %.0E flops", 100E6); + sg_actor_self_execute(100E6); + XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_consumed_energy(host)); + + start = simgrid_get_clock(); + XBT_INFO("Sleep for 4 seconds"); + sg_actor_sleep_for(4); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_consumed_energy(host)); + + // =========== Turn the other host off ========== + XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.", + sg_host_get_consumed_energy(sg_host_by_name("MyHost2"))); + sg_host_turn_off(sg_host_by_name("MyHost2")); + start = simgrid_get_clock(); + sg_actor_sleep_for(10); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid_get_clock() - start, sg_host_speed(host), sg_host_get_consumed_energy(host)); +} + +int main(int argc, char* argv[]) +{ + simgrid_init(&argc, argv); + sg_cfg_set_string("plugin", "host_energy"); + + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); + + simgrid_load_platform(argv[1]); + sg_actor_t actor = sg_actor_init("dvfs_test", sg_host_by_name("MyHost1")); + sg_actor_start(actor, dvfs, 0, NULL); + + simgrid_run(); + + XBT_INFO("End of simulation"); + + return 0; +} diff --git a/teshsuite/msg/energy-consumption/energy-consumption.tesh b/examples/c/energy-exec/energy-exec.tesh similarity index 91% rename from teshsuite/msg/energy-consumption/energy-consumption.tesh rename to examples/c/energy-exec/energy-exec.tesh index b7752c9b69..f38dd07afc 100644 --- a/teshsuite/msg/energy-consumption/energy-consumption.tesh +++ b/examples/c/energy-exec/energy-exec.tesh @@ -2,7 +2,7 @@ p Testing the mechanism for computing host energy consumption -$ ${bindir:=.}/energy-consumption ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ ${bindir:=.}/energy-exec-c ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (1:dvfs_test@MyHost1) Energetic profile: 100.0:93.33333333333333:200.0, 93.0:90.0:170.0, 90.0:90.0:150.0 > [ 0.000000] (1:dvfs_test@MyHost1) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J > [ 0.000000] (1:dvfs_test@MyHost1) Sleep for 10 seconds @@ -17,12 +17,12 @@ $ ${bindir:=.}/energy-consumption ${platfdir}/energy_platform.xml "--log=root.fm > [ 20.000000] (1:dvfs_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated 2000 J so far. > [ 30.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2905 J > [ 30.000000] (0:maestro@) Total energy consumption: 8005.000000 Joules (used hosts: 2905.000000 Joules; unused/idle hosts: 5100.000000) -> [ 30.000000] (0:maestro@) Total simulation time: 30.00 +> [ 30.000000] (0:maestro@) End of simulation > [ 30.000000] (0:maestro@) Energy consumption of host MyHost1: 2905.000000 Joules > [ 30.000000] (0:maestro@) Energy consumption of host MyHost2: 2100.000000 Joules > [ 30.000000] (0:maestro@) Energy consumption of host MyHost3: 3000.000000 Joules -$ ${bindir:=.}/energy-consumption ${platfdir}/energy_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=host/model:ptask_L07 +$ ${bindir:=.}/energy-exec-c ${platfdir}/energy_cluster.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:dvfs_test@MyHost1) Energetic profile: 100.0:93.33333333333333:200.0, 93.0:90.0:170.0, 90.0:90.0:150.0 @@ -39,6 +39,6 @@ $ ${bindir:=.}/energy-consumption ${platfdir}/energy_cluster.xml "--log=root.fmt > [ 20.000000] (1:dvfs_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated 2000 J so far. > [ 30.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2905 J > [ 30.000000] (0:maestro@) Total energy consumption: 5005.000000 Joules (used hosts: 2905.000000 Joules; unused/idle hosts: 2100.000000) -> [ 30.000000] (0:maestro@) Total simulation time: 30.00 +> [ 30.000000] (0:maestro@) End of simulation > [ 30.000000] (0:maestro@) Energy consumption of host MyHost1: 2905.000000 Joules > [ 30.000000] (0:maestro@) Energy consumption of host MyHost2: 2100.000000 Joules diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 96351f5765..0881eb084d 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -3,7 +3,7 @@ foreach(x async-wait cloud-capping cloud-migration cloud-two-tasks cloud-simple get_sender host_on_off host_on_off_recv process-lifetime - energy-consumption energy-ptask energy-pstate platform-properties + energy-ptask energy-pstate platform-properties io-file io-file-remote task-priority plugin-hostload @@ -94,7 +94,7 @@ if(enable_msg) get_sender task_destroy_cancel task_listen_from task_progress process-lifetime - energy-consumption energy-ptask + energy-ptask io-file io-file-remote platform-properties task-priority diff --git a/teshsuite/msg/energy-consumption/energy-consumption.c b/teshsuite/msg/energy-consumption/energy-consumption.c deleted file mode 100644 index e6b525c0a0..0000000000 --- a/teshsuite/msg/energy-consumption/energy-consumption.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (c) 2007-2020. 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/plugins/energy.h" -#include "simgrid/msg.h" - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -static int dvfs(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) -{ - msg_host_t host = MSG_host_by_name("MyHost1"); - - XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host, "wattage_per_state")); - XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_speed(host), - sg_host_get_consumed_energy(host)); - - double start = MSG_get_clock(); - XBT_INFO("Sleep for 10 seconds"); - MSG_process_sleep(10); - XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", - MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); - - // Run a task - start = MSG_get_clock(); - msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL); - XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); - MSG_task_execute(task1); - MSG_task_destroy(task1); - XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW" - " depending on load; Energy dissipated=%.0f J", - MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_wattmin_at(host, MSG_host_get_pstate(host)), - sg_host_get_wattmax_at(host, MSG_host_get_pstate(host)), sg_host_get_consumed_energy(host)); - - // ========= Change power peak ========= - int pstate = 2; - MSG_host_set_pstate(host, pstate); - XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, - MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host)); - - // Run a second task - start = MSG_get_clock(); - task1 = MSG_task_create("t2", 100E6, 0, NULL); - XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); - MSG_task_execute(task1); - MSG_task_destroy(task1); - XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", - MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); - - start = MSG_get_clock(); - XBT_INFO("Sleep for 4 seconds"); - MSG_process_sleep(4); - XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", - MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); - - // =========== Turn the other host off ========== - XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.", - sg_host_get_consumed_energy(MSG_host_by_name("MyHost2"))); - MSG_host_off(MSG_host_by_name("MyHost2")); - start = MSG_get_clock(); - MSG_process_sleep(10); - XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", - MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); - return 0; -} - -int main(int argc, char* argv[]) -{ - MSG_init(&argc, argv); - MSG_config("plugin", "host_energy"); - - 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("dvfs_test", dvfs, NULL, MSG_get_host_by_name("MyHost1")); - - msg_error_t res = MSG_main(); - - XBT_INFO("Total simulation time: %.2f", MSG_get_clock()); - - return res != MSG_OK; -} -- 2.20.1