1 /* Copyright (c) 2007-2010, 2013. 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. */
7 #include "xbt/sysdep.h" /* calloc */
9 /* Create a log channel to have nice outputs. */
11 #include "xbt/asserts.h"
14 /** @addtogroup MSG_examples
16 * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined
17 * for a host and how the current pstate can be accessed/changed
18 * with @ref MSG_get_host_current_power_peak and @ref
19 * MSG_set_host_power_peak_at.
20 * Make sure to read the platform XML file for details on how
21 * to declare the CPU capacity for each pstate.
25 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
26 "Pstate properties test");
28 int dvfs(int argc, char *argv[]);
31 int dvfs(int argc, char *argv[])
33 msg_host_t host = NULL;
34 msg_task_t task1 = NULL;
36 double workload = 100E6;
38 host = MSG_host_self();; //MSG_get_host_by_name("MyHost1");
40 int nb = MSG_get_host_nb_pstates(host);
41 XBT_INFO("Number of Processor states=%d", nb);
43 double current_peak = MSG_get_host_current_power_peak(host);
44 XBT_INFO("Current power peak=%lf", current_peak);
47 task1 = MSG_task_create ("t1", workload, 0, NULL);
48 MSG_task_execute (task1);
49 MSG_task_destroy(task1);
51 task_time = MSG_get_clock();
52 XBT_INFO("Task1 simulation time: %le", task_time);
55 if ((new_peak_index >= nb) || (new_peak_index < 0))
57 XBT_INFO("Cannot set pstate %d, host supports only %d pstates", new_peak_index, nb);
61 double peak_at = MSG_get_host_power_peak_at(host, new_peak_index);
62 XBT_INFO("Changing power peak value to %lf (at index %d)", peak_at, new_peak_index);
64 MSG_set_host_power_peak_at(host, new_peak_index);
66 current_peak = MSG_get_host_current_power_peak(host);
67 XBT_INFO("Current power peak=%lf", current_peak);
70 task1 = MSG_task_create ("t1", workload, 0, NULL);
71 MSG_task_execute (task1);
72 MSG_task_destroy(task1);
74 task_time = MSG_get_clock() - task_time;
75 XBT_INFO("Task2 simulation time: %le", task_time);
78 // Verify the default pstate is set to 0
79 host = MSG_get_host_by_name("MyHost2");
80 int nb2 = MSG_get_host_nb_pstates(host);
81 XBT_INFO("Number of Processor states=%d", nb2);
83 double current_peak2 = MSG_get_host_current_power_peak(host);
84 XBT_INFO("Current power peak=%lf", current_peak2);
88 int main(int argc, char *argv[])
90 msg_error_t res = MSG_OK;
92 MSG_init(&argc, argv);
95 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
98 ("example: %s msg_platform.xml msg_deployment.xml\n",
103 MSG_create_environment(argv[1]);
105 /* Application deployment */
106 MSG_function_register("dvfs_test", dvfs);
108 MSG_launch_application(argv[2]);
112 XBT_INFO("Total simulation time: %le", MSG_get_clock());