Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
yet another cleaning pass
[simgrid.git] / examples / msg / energy / pstate / pstate.c
1 /* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid/msg.h"
8
9 /** @addtogroup MSG_examples
10  *
11  * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined for a host and how the current pstate can be
12  *     accessed/changed with @ref MSG_get_host_current_power_peak and @ref  MSG_set_host_pstate.
13  *     Make sure to read the platform XML file for details on how to declare the CPU capacity for each pstate.
14  */
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
17
18 static int dvfs(int argc, char *argv[])
19 {
20   double workload = 100E6;
21   int new_peak_index=2;
22   msg_host_t host = MSG_host_self();; //MSG_get_host_by_name("MyHost1");
23
24   int nb = MSG_host_get_nb_pstates(host);
25   XBT_INFO("Count of Processor states=%d", nb);
26
27   double current_peak = MSG_host_get_current_power_peak(host);
28   XBT_INFO("Current power peak=%f", current_peak);
29
30   // Run a task
31   msg_task_t task1 = MSG_task_create ("t1", workload, 0, NULL);
32   MSG_task_execute (task1);
33   MSG_task_destroy(task1);
34
35   double task_time = MSG_get_clock();
36   XBT_INFO("Task1 simulation time: %e", task_time);
37
38   // Change power peak
39   if ((new_peak_index >= nb) || (new_peak_index < 0)){
40     XBT_INFO("Cannot set pstate %d, host supports only %d pstates", new_peak_index, nb);
41     return 0;
42   }
43
44   double peak_at = MSG_host_get_power_peak_at(host, new_peak_index);
45   XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_peak_index);
46
47   MSG_host_set_pstate(host, new_peak_index);
48
49   current_peak = MSG_host_get_current_power_peak(host);
50   XBT_INFO("Current power peak=%f", current_peak);
51
52   // Run a second task
53   task1 = MSG_task_create ("t1", workload, 0, NULL);
54   MSG_task_execute (task1);
55   MSG_task_destroy(task1);
56
57   task_time = MSG_get_clock() - task_time;
58   XBT_INFO("Task2 simulation time: %e", task_time);
59
60   // Verify the default pstate is set to 0
61   host = MSG_host_by_name("MyHost2");
62   int nb2 = MSG_host_get_nb_pstates(host);
63   XBT_INFO("Count of Processor states=%d", nb2);
64
65   double current_peak2 = MSG_host_get_current_power_peak(host);
66   XBT_INFO("Current power peak=%f", current_peak2);
67   return 0;
68 }
69
70 int main(int argc, char *argv[])
71 {
72   msg_error_t res = MSG_OK;
73
74   MSG_init(&argc, argv);
75
76   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
77             "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
78
79   MSG_create_environment(argv[1]);
80
81   MSG_function_register("dvfs_test", dvfs);
82   MSG_launch_application(argv[2]);
83
84   res = MSG_main();
85
86   XBT_INFO("Total simulation time: %e", MSG_get_clock());
87
88   return res != MSG_OK;
89 }