1 /* Copyright (c) 2007-2020. 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 "simgrid/actor.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
10 #include "xbt/asserts.h"
11 #include "xbt/config.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
16 static void dvfs(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
18 sg_host_t host = sg_host_self();
20 int nb = sg_host_get_nb_pstates(host);
21 XBT_INFO("Count of Processor states=%d", nb);
23 double current_peak = sg_host_speed(host);
24 XBT_INFO("Current power peak=%f", current_peak);
26 sg_actor_execute(100E6);
28 double task_time = simgrid_get_clock();
29 XBT_INFO("Task1 simulation time: %e", task_time);
33 xbt_assert(new_pstate < nb, "Cannot set the host %s at pstate %d because it only provides %d pstates.",
34 sg_host_get_name(host), new_pstate, nb);
36 double peak_at = sg_host_get_pstate_speed(host, new_pstate);
37 XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_pstate);
39 sg_host_set_pstate(host, new_pstate);
41 current_peak = sg_host_speed(host);
42 XBT_INFO("Current power peak=%f", current_peak);
44 sg_actor_execute(100E6);
46 task_time = simgrid_get_clock() - task_time;
47 XBT_INFO("Task2 simulation time: %e", task_time);
49 // Verify the default pstate is set to 0
50 host = sg_host_by_name("MyHost2");
51 int nb2 = sg_host_get_nb_pstates(host);
52 XBT_INFO("Count of Processor states=%d", nb2);
54 double current_peak2 = sg_host_speed(host);
55 XBT_INFO("Current power peak=%f", current_peak2);
58 int main(int argc, char* argv[])
60 simgrid_init(&argc, argv);
62 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
64 simgrid_load_platform(argv[1]);
66 sg_actor_t a1 = sg_actor_init("dvfs_test", sg_host_by_name("MyHost1"));
67 sg_actor_start(a1, dvfs, 0, NULL);
69 sg_actor_t a2 = sg_actor_init("dvfs_test", sg_host_by_name("MyHost2"));
70 sg_actor_start(a2, dvfs, 0, NULL);
74 XBT_INFO("Total simulation time: %e", simgrid_get_clock());