X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a3848e5ea6b2305d6059c89705edaccbec356455..bdfe4f8674f98efbf2d67ad854ef83a1d5f855ed:/examples/msg/energy/e1/e1.c?ds=sidebyside diff --git a/examples/msg/energy/e1/e1.c b/examples/msg/energy/e1/e1.c index b22013d68d..1f7dae7175 100644 --- a/examples/msg/energy/e1/e1.c +++ b/examples/msg/energy/e1/e1.c @@ -1,11 +1,8 @@ -/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2007-2010, 2013. 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 */ @@ -13,8 +10,20 @@ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); + +/** @addtogroup MSG_examples + * + * - energy/e1/e1.c Shows how a set of pstates can be defined + * for a host and how the current pstate can be accessed/changed + * with @ref MSG_get_host_current_power_peak and @ref + * MSG_set_host_power_peak_at. + * Make sure to read the platform XML file for details on how + * to declare the CPU capacity for each pstate. + * + */ + +XBT_LOG_NEW_DEFAULT_CATEGORY(test, + "Pstate properties test"); int dvfs(int argc, char *argv[]); @@ -24,9 +33,9 @@ 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"); + double workload = 100E6; + int new_peak_index=2; + host = MSG_host_self();; //MSG_get_host_by_name("MyHost1"); int nb = MSG_get_host_nb_pstates(host); XBT_INFO("Number of Processor states=%d", nb); @@ -35,31 +44,44 @@ int dvfs(int argc, char *argv[]) XBT_INFO("Current power peak=%lf", current_peak); // Run a task - task1 = MSG_task_create ("t1", 100E6, 0, NULL); + task1 = MSG_task_create ("t1", workload, 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); + // Change power peak + if ((new_peak_index >= nb) || (new_peak_index < 0)) + { + XBT_INFO("Cannot set pstate %d, host supports only %d pstates", new_peak_index, nb); + return 0; + } + + double peak_at = MSG_get_host_power_peak_at(host, new_peak_index); + XBT_INFO("Changing power peak value to %lf (at index %d)", peak_at, new_peak_index); - MSG_set_host_power_peak_at(host, peak_index); + MSG_set_host_power_peak_at(host, new_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); + task1 = MSG_task_create ("t1", workload, 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); + + // Verify the default pstate is set to 0 + host = MSG_get_host_by_name("MyHost2"); + int nb2 = MSG_get_host_nb_pstates(host); + XBT_INFO("Number of Processor states=%d", nb2); + + double current_peak2 = MSG_get_host_current_power_peak(host); + XBT_INFO("Current power peak=%lf", current_peak2); return 0; }