Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8001cbf98037703216391bd1a0b36e5a008687f2
[simgrid.git] / examples / java / energy / pstate / PstateRunner.java
1 /* Copyright (c) 2016. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 package energy.pstate;
7
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.HostFailureException;
10 import org.simgrid.msg.HostNotFoundException;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.NativeException;
13 import org.simgrid.msg.Process;
14 import org.simgrid.msg.Task;
15 import org.simgrid.msg.TaskCancelledException;
16
17 /* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
18 public class PstateRunner extends Process {
19
20         public class DVFS extends Process {
21                 public  DVFS (Host host, String name) {
22                         super(host, name); 
23                 }
24
25                 @Override
26                 public void main(String[] strings) throws HostNotFoundException, HostFailureException, TaskCancelledException {
27                         double workload = 100E6;
28                         int newPstate = 2;
29                         Host host = getHost();
30
31                         int nb = host.getPstatesCount();
32                         Msg.info("Count of Processor states="+ nb);
33
34                         double currentPeak = host.getCurrentPowerPeak();
35                         Msg.info("Current power peak=" + currentPeak);
36
37                         // Run a task
38                         Task task1 = new Task("t1", workload, 0);
39                         task1.execute();
40
41                         double taskTime = Msg.getClock();
42                         Msg.info("Task1 simulation time: "+ taskTime);
43
44                         // Change power peak
45                         if ((newPstate >= nb) || (newPstate < 0)){
46                                 Msg.info("Cannot set pstate "+newPstate+"%d, host supports only "+nb+" pstates.");
47                                 return;
48                         }
49
50                         double peakAt = host.getPowerPeakAt(newPstate);
51                         Msg.info("Changing power peak value to "+peakAt+" (at index "+newPstate+")");
52
53                         host.setPstate(newPstate);
54
55                         currentPeak = host.getCurrentPowerPeak();
56                         Msg.info("Current power peak="+ currentPeak);
57
58                         // Run a second task
59                         new Task("t1", workload, 0).execute();
60
61                         taskTime = Msg.getClock() - taskTime;
62                         Msg.info("Task2 simulation time: "+ taskTime);
63
64                         // Verify the default pstate is set to 0
65                         host = Host.getByName("MyHost2");
66                         int nb2 = host.getPstatesCount();
67                         Msg.info("Count of Processor states="+ nb2);
68
69                         double currentPeak2 = host.getCurrentPowerPeak();
70                         Msg.info("Current power peak=" + currentPeak2);
71                 }
72         }
73
74         PstateRunner(Host host, String name, String[] args) throws NativeException  {
75                 super(host, name, args);
76         }
77
78         @Override
79         public void main(String[] strings) throws HostNotFoundException, HostFailureException {
80
81             new DVFS (Host.getByName("MyHost1"), "dvfs_test").start(); 
82             new DVFS (Host.getByName("MyHost2"), "dvfs_test").start(); 
83
84         }
85 }