Logo AND Algorithmique Numérique Distribuée

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