1 /* Copyright (c) 2007-2010, 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/sysdep.h" /* calloc */
10 /* Create a log channel to have nice outputs. */
12 #include "xbt/asserts.h"
15 /** @addtogroup MSG_examples
17 * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined
18 * for a host and how the current pstate can be accessed/changed
19 * with @ref MSG_get_host_current_power_peak and @ref
20 * MSG_set_host_power_peak_at.
21 * Make sure to read the platform XML file for details on how
22 * to declare the CPU capacity for each pstate.
26 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
27 "Pstate properties test");
29 int dvfs(int argc, char *argv[]);
32 int dvfs(int argc, char *argv[])
34 msg_host_t host = NULL;
35 msg_task_t task1 = NULL;
37 double workload = 100E6;
39 host = MSG_host_self();; //MSG_get_host_by_name("MyHost1");
41 int nb = MSG_host_get_pstate_number(host);
42 XBT_INFO("Number of Processor states=%d", nb);
44 double current_peak = MSG_host_get_current_power_peak(host);
45 XBT_INFO("Current power peak=%f", current_peak);
48 task1 = MSG_task_create ("t1", workload, 0, NULL);
49 MSG_task_execute (task1);
50 MSG_task_destroy(task1);
52 task_time = MSG_get_clock();
53 XBT_INFO("Task1 simulation time: %e", task_time);
56 if ((new_peak_index >= nb) || (new_peak_index < 0))
58 XBT_INFO("Cannot set pstate %d, host supports only %d pstates", new_peak_index, nb);
62 double peak_at = MSG_host_get_power_peak_at(host, new_peak_index);
63 XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_peak_index);
65 MSG_host_set_pstate(host, new_peak_index);
67 current_peak = MSG_host_get_current_power_peak(host);
68 XBT_INFO("Current power peak=%f", current_peak);
71 task1 = MSG_task_create ("t1", workload, 0, NULL);
72 MSG_task_execute (task1);
73 MSG_task_destroy(task1);
75 task_time = MSG_get_clock() - task_time;
76 XBT_INFO("Task2 simulation time: %e", task_time);
79 // Verify the default pstate is set to 0
80 host = MSG_get_host_by_name("MyHost2");
81 int nb2 = MSG_host_get_pstate_number(host);
82 XBT_INFO("Number of Processor states=%d", nb2);
84 double current_peak2 = MSG_host_get_current_power_peak(host);
85 XBT_INFO("Current power peak=%f", current_peak2);
89 int main(int argc, char *argv[])
91 msg_error_t res = MSG_OK;
93 MSG_init(&argc, argv);
96 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
99 ("example: %s msg_platform.xml msg_deployment.xml\n",
104 MSG_create_environment(argv[1]);
106 /* Application deployment */
107 MSG_function_register("dvfs_test", dvfs);
109 MSG_launch_application(argv[2]);
113 XBT_INFO("Total simulation time: %e", MSG_get_clock());