source: DCWoRMS/branches/coolemall/src/test/simpat/models/basic/CpuEnergyEstimationPlugin.java @ 1469

Revision 1469, 6.6 KB checked in by wojtekp, 10 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.simpat.models.basic;
2
3import schedframe.resources.StandardResourceType;
4import schedframe.resources.computing.Processor;
5import schedframe.resources.computing.profiles.energy.ResourceEvent;
6import schedframe.resources.devices.Device;
7import schedframe.resources.devices.Fan;
8import schedframe.resources.devices.PhysicalResource;
9import schedframe.scheduling.manager.tasks.JobRegistry;
10import simulator.DataCenterWorkloadSimulator;
11import test.simpat.EnvironmentConditions;
12import eduni.simjava.Sim_system;
13import example.energy.BaseEnergyEstimationPlugin;
14import gridsim.dcworms.DCWormsTags;
15
16public class CpuEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
17
18        private static double Pidle = 4;
19        private static double Pfull = 50;
20
21        private static int Tidle = 33;
22       
23        private double timestamp = 0;
24        private double old_temperature = Tidle;
25        private double new_temperature = -1;
26        private double objective_temperature = Tidle;
27       
28        private boolean fan = false;
29       
30        private double next_timer = -1;   
31       
32        private int cpu_temp_monitor = 0;
33        public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
34                        PhysicalResource resource) {
35                double powerConsumption = 0;
36
37                Processor cpu = (Processor)resource;
38                powerConsumption = Pidle + (Pfull- Pidle) * cpu.getLoadInterface().getRecentUtilization().getValue()/100;                       
39
40                return powerConsumption;
41        }
42       
43        @Override
44        public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
45                double future = -1;
46
47                Processor cpu = (Processor) resource;
48
49                double R = 0;
50                double Rb = 0;
51                double Rcv = 0;
52                try{
53                        Rb = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue();
54                } catch (Exception e){
55                        //
56                }
57               
58                double k = 0;
59                try{
60                        k = Double.valueOf(cpu.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue();
61                } catch (Exception e){
62                        //
63                }
64               
65                double a = 0;
66                try{
67                        a = Double.valueOf(cpu.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue();
68                } catch (Exception e){
69                        a = 1;
70                }
71
72                double V = 0;
73       
74                for(Device device: cpu.getParent().getResourceCharacteristic().getDevices()){
75                        if(device.getType().equals(StandardResourceType.Fan)){
76                                Fan fan = (Fan) device;
77                                V = fan.getAirflowInterface().getRecentAirflow().getValue();
78                        }
79                }
80
81                Rcv =  1/ (k * Math.pow(V, a));
82                R = Rb + Rcv;
83               
84                double C = 0;
85                try{
86                        C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue();
87                } catch (Exception e){
88                        //
89                }
90                // 1) look where we are
91                double delta_t = Sim_system.clock() - timestamp;
92                /***************model1*************/
93                //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/sink);
94               
95                /***************model2*************/
96                new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C));
97                 
98
99                // 2) calculate if fan is needed ?
100                if(new_temperature <= EnvironmentConditions.TFanLow) {
101                        fan = false;
102                }
103                if(new_temperature >= EnvironmentConditions.TFanHigh) {
104                        fan = true;
105                }
106               
107                // 3) compute new objective
108                double Tin = EnvironmentConditions.ROOM_TEMPERATURE;
109                double Pcpu = cpu.getPowerInterface().getRecentPowerUsage().getValue();
110                new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C));
111                //new_temperature = (Pcpu * R + Tin) - (Pcpu * R + Tin - Tidle) * Math.exp(-Sim_system.clock()/(R * C));;
112               
113                /***************model1 - GEO1*************/
114                //double cpuLoad = cpu.getLoadInterface().getRecentUtilization().getValue();
115                //double targetTemp = Tidle + cpuLoad/100 * dTfull;
116                //if(fan) {
117                //      targetTemp = targetTemp - dTfan;
118                //}
119               
120               
121                /***************model2 - GEO2*************/
122                //Node node = (Node) cpu.getParent();
123                //Pserv = node.getPowerInterface().getRecentPowerUsage().getValue();
124                //double targetTemp = Pcpu * R + Tin;
125               
126                /***************model3 - GEO1 + GEO2*************/
127                /*double targetTemp = Pcpu * R + Tin;
128                if(fan) {
129                        targetTemp = targetTemp - dTfan;
130                }*/
131       
132                /***************model4 - WP*************/
133                double targetTemp = Pcpu * R + Tin;
134               
135                // 4) check if we will need to tune fans
136                if(fan && targetTemp < EnvironmentConditions.TFanLow) {
137                        double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow));
138                        if(future == -1 || future > timer) {
139                                future = timer;
140                        }
141                }
142                if(!fan && targetTemp > EnvironmentConditions.TFanHigh) {
143                        double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanHigh));
144                        if(future == -1 || future > timer) {
145                                future = timer;
146                        }
147                }
148
149                // 5) save everything
150                timestamp = Sim_system.clock();
151                old_temperature = new_temperature;
152                objective_temperature = targetTemp;
153
154
155                if((future >= 0) && ((next_timer < Sim_system.clock()) || (next_timer >= future + Sim_system.clock()))) {
156                        //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(future, DCWormsTags.FANMGT, "Test");
157                        next_timer = future + Sim_system.clock() - 0.01;
158                }               
159               
160                if(new_temperature > EnvironmentConditions.tempLevelMedium2Low && new_temperature < EnvironmentConditions.tempLevelLow2Medium){
161                        if(cpu_temp_monitor != 1){
162                                cpu_temp_monitor = 1;
163                                DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName());
164                        }
165                } else if(new_temperature > EnvironmentConditions.tempLevelLow2Medium && new_temperature < EnvironmentConditions.tempLevelHigh2Medium){
166                        if(cpu_temp_monitor != 2){
167                                cpu_temp_monitor = 2;
168                                DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName());
169                        }
170                } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Medium && new_temperature < EnvironmentConditions.tempLevelMedium2High){
171                        if(cpu_temp_monitor != 3){
172                                cpu_temp_monitor = 3;
173                                DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName());
174                        }
175                } else if(new_temperature > EnvironmentConditions.tempLevelMedium2High){
176                        if(cpu_temp_monitor != 4){
177                                cpu_temp_monitor = 4;
178                                DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName());
179                        }
180                }
181                //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName());
182
183                return new_temperature;
184        }
185}
Note: See TracBrowser for help on using the repository browser.