From 080dc09df11aea380c679d3b3ae257826c5cbd44 Mon Sep 17 00:00:00 2001 From: acarpena Date: Sun, 30 Jun 2013 17:04:23 -0700 Subject: [PATCH 1/1] added dvfs support --- examples/msg/energy/e1/CMakeLists.txt | 20 ++++ examples/msg/energy/e1/deployment_e1.xml | 7 ++ examples/msg/energy/e1/e1.c | 97 +++++++++++++++++ examples/msg/energy/e1/platform_e1.xml | 10 ++ examples/msg/energy/e2/CMakeLists.txt | 20 ++++ examples/msg/energy/e2/deployment_e2.xml | 7 ++ examples/msg/energy/e2/e2.c | 107 +++++++++++++++++++ examples/msg/energy/e2/platform_e2.xml | 10 ++ examples/msg/energy/e3/CMakeLists.txt | 20 ++++ examples/msg/energy/e3/deployment_e3.xml | 7 ++ examples/msg/energy/e3/e3.c | 130 +++++++++++++++++++++++ examples/msg/energy/e3/platform_e3.xml | 10 ++ src/surf/cpu_cas01_private.h | 50 +++++++++ 13 files changed, 495 insertions(+) create mode 100644 examples/msg/energy/e1/CMakeLists.txt create mode 100644 examples/msg/energy/e1/deployment_e1.xml create mode 100644 examples/msg/energy/e1/e1.c create mode 100644 examples/msg/energy/e1/platform_e1.xml create mode 100644 examples/msg/energy/e2/CMakeLists.txt create mode 100644 examples/msg/energy/e2/deployment_e2.xml create mode 100644 examples/msg/energy/e2/e2.c create mode 100644 examples/msg/energy/e2/platform_e2.xml create mode 100644 examples/msg/energy/e3/CMakeLists.txt create mode 100644 examples/msg/energy/e3/deployment_e3.xml create mode 100644 examples/msg/energy/e3/e3.c create mode 100644 examples/msg/energy/e3/platform_e3.xml create mode 100644 src/surf/cpu_cas01_private.h diff --git a/examples/msg/energy/e1/CMakeLists.txt b/examples/msg/energy/e1/CMakeLists.txt new file mode 100644 index 0000000000..613f2d9617 --- /dev/null +++ b/examples/msg/energy/e1/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.6) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(e1 e1.c) + +### Add definitions for compile +target_link_libraries(e1 simgrid ) + +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/deployment_e1.xml + ${CMAKE_CURRENT_SOURCE_DIR}/platform_e1.xml + PARENT_SCOPE + ) + +set(bin_files + ${bin_files} + PARENT_SCOPE + ) diff --git a/examples/msg/energy/e1/deployment_e1.xml b/examples/msg/energy/e1/deployment_e1.xml new file mode 100644 index 0000000000..b9c8941609 --- /dev/null +++ b/examples/msg/energy/e1/deployment_e1.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/msg/energy/e1/e1.c b/examples/msg/energy/e1/e1.c new file mode 100644 index 0000000000..b22013d68d --- /dev/null +++ b/examples/msg/energy/e1/e1.c @@ -0,0 +1,97 @@ +/* Copyright (c) 2007, 2008, 2009, 2010. 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 "msg/msg.h" +#include "xbt/sysdep.h" /* calloc */ + +/* 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"); + +int dvfs(int argc, char *argv[]); + + +int dvfs(int argc, char *argv[]) +{ + msg_host_t host = NULL; + msg_task_t task1 = NULL; + double task_time = 0; + host = MSG_get_host_by_name("MyHost1"); + + XBT_INFO("dvfs start"); + + int nb = MSG_get_host_nb_pstates(host); + XBT_INFO("Number of Processor states=%d", nb); + + double current_peak = MSG_get_host_current_power_peak(host); + XBT_INFO("Current power peak=%lf", current_peak); + + // Run a task + task1 = MSG_task_create ("t1", 100E6, 0, NULL); + MSG_task_execute (task1); + MSG_task_destroy(task1); + + task_time = MSG_get_clock(); + XBT_INFO("Task1 simulation time: %le", task_time); + + // ========= Change power peak ========= + int peak_index=2; + double peak_at = MSG_get_host_power_peak_at(host, peak_index); + XBT_INFO("=========Changing power peak value to %lf (at index %d)", peak_at, peak_index); + + MSG_set_host_power_peak_at(host, peak_index); + + current_peak = MSG_get_host_current_power_peak(host); + XBT_INFO("Current power peak=%lf", current_peak); + + // Run a second task + task1 = MSG_task_create ("t1", 100E6, 0, NULL); + MSG_task_execute (task1); + MSG_task_destroy(task1); + + task_time = MSG_get_clock() - task_time; + XBT_INFO("Task2 simulation time: %le", task_time); + + return 0; +} + +int main(int argc, char *argv[]) +{ + msg_error_t res = MSG_OK; + + 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("dvfs_test", dvfs); + + MSG_launch_application(argv[2]); + + res = MSG_main(); + + XBT_INFO("Total simulation time: %le", MSG_get_clock()); + + if (res == MSG_OK) + return 0; + else + return 1; +} + diff --git a/examples/msg/energy/e1/platform_e1.xml b/examples/msg/energy/e1/platform_e1.xml new file mode 100644 index 0000000000..3d04bd29dd --- /dev/null +++ b/examples/msg/energy/e1/platform_e1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/examples/msg/energy/e2/CMakeLists.txt b/examples/msg/energy/e2/CMakeLists.txt new file mode 100644 index 0000000000..e42902c4e9 --- /dev/null +++ b/examples/msg/energy/e2/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.6) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(e2 e2.c) + +### Add definitions for compile +target_link_libraries(e2 simgrid ) + +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/deployment_e2.xml + ${CMAKE_CURRENT_SOURCE_DIR}/platform_e2.xml + PARENT_SCOPE + ) + +set(bin_files + ${bin_files} + PARENT_SCOPE + ) diff --git a/examples/msg/energy/e2/deployment_e2.xml b/examples/msg/energy/e2/deployment_e2.xml new file mode 100644 index 0000000000..b9c8941609 --- /dev/null +++ b/examples/msg/energy/e2/deployment_e2.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/msg/energy/e2/e2.c b/examples/msg/energy/e2/e2.c new file mode 100644 index 0000000000..5e9bc42483 --- /dev/null +++ b/examples/msg/energy/e2/e2.c @@ -0,0 +1,107 @@ +/* Copyright (c) 2007, 2008, 2009, 2010. 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 "msg/msg.h" +#include "xbt/sysdep.h" /* calloc */ + +/* 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"); + +int dvfs(int argc, char *argv[]); + + +int dvfs(int argc, char *argv[]) +{ + msg_host_t host = NULL; + msg_task_t task1 = NULL; + double task_time = 0; + host = MSG_get_host_by_name("MyHost1"); + + + double current_peak = MSG_get_host_current_power_peak(host); + XBT_INFO("Current power peak=%lf", current_peak); + + double consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + // Run a task + task1 = MSG_task_create ("t1", 100E6, 0, NULL); + MSG_task_execute (task1); + MSG_task_destroy(task1); + + task_time = MSG_get_clock(); + XBT_INFO("Task1 simulation time: %le", task_time); + consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + // ========= Change power peak ========= + int peak_index=2; + double peak_at = MSG_get_host_power_peak_at(host, peak_index); + XBT_INFO("=========Changing power peak value to %lf (at index %d)", peak_at, peak_index); + + MSG_set_host_power_peak_at(host, peak_index); + + // Run a second task + task1 = MSG_task_create ("t2", 100E6, 0, NULL); + MSG_task_execute (task1); + MSG_task_destroy(task1); + + task_time = MSG_get_clock() - task_time; + XBT_INFO("Task2 simulation time: %le", task_time); + + consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + + MSG_process_sleep(3); + + task_time = MSG_get_clock() - task_time; + XBT_INFO("Task3 (sleep) simulation time: %le", task_time); + consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + + return 0; +} + +int main(int argc, char *argv[]) +{ + msg_error_t res = MSG_OK; + + 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("dvfs_test", dvfs); + + MSG_launch_application(argv[2]); + + res = MSG_main(); + + XBT_INFO("Total simulation time: %le", MSG_get_clock()); + + if (res == MSG_OK) + return 0; + else + return 1; +} + diff --git a/examples/msg/energy/e2/platform_e2.xml b/examples/msg/energy/e2/platform_e2.xml new file mode 100644 index 0000000000..c74c361b37 --- /dev/null +++ b/examples/msg/energy/e2/platform_e2.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/examples/msg/energy/e3/CMakeLists.txt b/examples/msg/energy/e3/CMakeLists.txt new file mode 100644 index 0000000000..19803f401e --- /dev/null +++ b/examples/msg/energy/e3/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.6) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(e3 e3.c) + +### Add definitions for compile +target_link_libraries(e3 simgrid ) + +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/deployment_e3.xml + ${CMAKE_CURRENT_SOURCE_DIR}/platform_e3.xml + PARENT_SCOPE + ) + +set(bin_files + ${bin_files} + PARENT_SCOPE + ) diff --git a/examples/msg/energy/e3/deployment_e3.xml b/examples/msg/energy/e3/deployment_e3.xml new file mode 100644 index 0000000000..b9c8941609 --- /dev/null +++ b/examples/msg/energy/e3/deployment_e3.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/msg/energy/e3/e3.c b/examples/msg/energy/e3/e3.c new file mode 100644 index 0000000000..2b88444d1d --- /dev/null +++ b/examples/msg/energy/e3/e3.c @@ -0,0 +1,130 @@ +/* Copyright (c) 2007, 2008, 2009, 2010. 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 "msg/msg.h" +#include "xbt/sysdep.h" /* calloc */ + +/* 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 int dvfs(int argc, char *argv[]); +static int process_code(int argc, char *argv[]); + +static int process_code(int argc, char *argv[]) +{ + msg_task_t task1 = NULL; + double cpu_task = 0; + double task_time = MSG_get_clock(); + + if (argc == 2) + { + /* Run a sleep task */ + double sleep_task = atof(argv[1]); + + MSG_process_sleep(sleep_task); + task_time = MSG_get_clock() - task_time; + XBT_INFO("Process %s executed task sleep cpu=%lf, duration = %lf", + MSG_process_get_name(MSG_process_self()), 0.0, task_time); + XBT_INFO("=================================================="); + } + + + // Run a task + cpu_task = atof(argv[0]); + task1 = MSG_task_create ("task", cpu_task, 0, NULL); + MSG_task_execute (task1); + MSG_task_destroy(task1); + + task_time = MSG_get_clock() - task_time; + XBT_INFO("Process %s executed task cpu=%lf, duration = %lf", + MSG_process_get_name(MSG_process_self()), cpu_task, task_time); + XBT_INFO("=================================================="); + return 0; +} + + +static int dvfs(int argc, char *argv[]) +{ + msg_host_t host = NULL; + double task_time = 0; + host = MSG_host_self(); + + double current_peak = MSG_get_host_current_power_peak(host); + + XBT_INFO("Current power peak=%lf", current_peak); + double consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + // Process 1 - long CPU task + int argc1 = 1; + char** params1 = xbt_malloc0(sizeof(char *) * argc1); + params1[0] = xbt_strdup("400.0E6"); + MSG_process_create_with_arguments("proc1", process_code, NULL, host, argc1, params1); + + // Process 2 - sleep 2 sec + CPU task + int argc2 = 2; + char** params2 = xbt_malloc0(sizeof(char *) * argc2); + params2[0] = xbt_strdup("100.0E6"); + params2[1] = xbt_strdup("2"); + MSG_process_create_with_arguments("proc2", process_code, NULL, host, argc2, params2); + + // Process 3 - sleep 2 sec + CPU task + int argc3 = 2; + char** params3 = xbt_malloc0(sizeof(char *) * argc3); + params3[0] = xbt_strdup("100.0E6"); + params3[1] = xbt_strdup("2"); + MSG_process_create_with_arguments("proc3", process_code, NULL, host, argc3, params3); + + + // Main process + MSG_process_sleep(8); + + task_time = MSG_get_clock() - task_time; + XBT_INFO("Task simulation time: %le", task_time); + consumed_energy = MSG_get_host_consumed_energy(host); + XBT_INFO("Total energy (Joules): %lf", consumed_energy); + + return 0; +} + +int main(int argc, char *argv[]) +{ + msg_error_t res = MSG_OK; + + 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("dvfs_test", dvfs); + + MSG_launch_application(argv[2]); + + res = MSG_main(); + + XBT_INFO("Total simulation time: %le", MSG_get_clock()); + + if (res == MSG_OK) + return 0; + else + return 1; +} + diff --git a/examples/msg/energy/e3/platform_e3.xml b/examples/msg/energy/e3/platform_e3.xml new file mode 100644 index 0000000000..c74c361b37 --- /dev/null +++ b/examples/msg/energy/e3/platform_e3.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/surf/cpu_cas01_private.h b/src/surf/cpu_cas01_private.h new file mode 100644 index 0000000000..7a31628e3d --- /dev/null +++ b/src/surf/cpu_cas01_private.h @@ -0,0 +1,50 @@ + +/* Copyright (c) 2009, 2010. 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. */ + +#ifndef _SURF_CPU_CAS01_PRIVATE_H +#define _SURF_CPU_CAS01_PRIVATE_H + +#undef GENERIC_LMM_ACTION +#undef GENERIC_ACTION +#undef ACTION_GET_CPU +#define GENERIC_LMM_ACTION(action) action->generic_lmm_action +#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action +#define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_t) action)->cpu + +typedef struct surf_action_cpu_cas01 { + s_surf_action_lmm_t generic_lmm_action; +} s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t; + + +typedef struct energy_cpu_cas01 { + xbt_dynar_t power_range_watts_list; + double total_energy; + double last_updated; +} s_energy_cpu_cas01_t, *energy_cpu_cas01_t; + + +typedef struct cpu_Cas01 { + s_surf_resource_t generic_resource; + s_xbt_swag_hookup_t modified_cpu_hookup; + double power_peak; + double power_scale; + tmgr_trace_event_t power_event; + int core; + e_surf_resource_state_t state_current; + tmgr_trace_event_t state_event; + lmm_constraint_t constraint; + + xbt_dynar_t power_peak_list; + int pstate; + energy_cpu_cas01_t energy; + +} s_cpu_Cas01_t, *cpu_Cas01_t; + +xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model); +void cpu_update_energy(cpu_Cas01_t cpu_model, double cpu_load); + +#endif /* _SURF_CPU_CAS01_PRIVATE_H */ -- 2.20.1