[1500] | 1 | package experiments.simpat2014.models.basic; |
---|
[1469] | 2 | |
---|
| 3 | |
---|
| 4 | import schedframe.resources.StandardResourceType; |
---|
| 5 | import schedframe.resources.computing.Node; |
---|
| 6 | import schedframe.resources.computing.Processor; |
---|
| 7 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
| 8 | import schedframe.resources.devices.Device; |
---|
| 9 | import schedframe.resources.devices.Fan; |
---|
| 10 | import schedframe.resources.devices.PhysicalResource; |
---|
| 11 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 12 | import simulator.DataCenterWorkloadSimulator; |
---|
| 13 | import eduni.simjava.Sim_system; |
---|
| 14 | import example.energy.BaseEnergyEstimationPlugin; |
---|
[1500] | 15 | import experiments.simpat2014.EnvironmentConditions; |
---|
[1469] | 16 | |
---|
| 17 | public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
| 18 | |
---|
| 19 | private static double Tidle = 26; |
---|
| 20 | |
---|
| 21 | private double timestamp = 0; |
---|
| 22 | private double old_temperature = Tidle; |
---|
| 23 | private double new_temperature = -1; |
---|
| 24 | private double objective_temperature = Tidle; |
---|
| 25 | private boolean fan = false; |
---|
| 26 | |
---|
| 27 | private double next_timer = -1; |
---|
| 28 | |
---|
| 29 | private static double Pidle = 10; |
---|
| 30 | private static double Pfull = 76; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
| 34 | PhysicalResource resource) { |
---|
| 35 | Node node = (Node) resource; |
---|
| 36 | double powerConsumption = 0; |
---|
| 37 | |
---|
| 38 | /*double Pcpu = 0; |
---|
| 39 | for(Processor cpu: node.getProcessors()){ |
---|
| 40 | Pcpu = Pcpu + cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 41 | }*/ |
---|
| 42 | |
---|
| 43 | powerConsumption = Pidle + (Pfull- Pidle) * node.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
| 44 | double Pfan = 0; |
---|
| 45 | for(Device device: node.getResourceCharacteristic().getDevices()){ |
---|
| 46 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
| 47 | Fan fan = (Fan) device; |
---|
| 48 | Pfan = Pfan + fan.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | //powerConsumption = Pcpu + Pfan; |
---|
| 52 | powerConsumption = powerConsumption + Pfan; |
---|
| 53 | return powerConsumption; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | @Override |
---|
| 57 | public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { |
---|
| 58 | double future = -1; |
---|
| 59 | |
---|
| 60 | Node node = (Node) resource; |
---|
| 61 | Processor cpu = node.getProcessors().get(0); |
---|
| 62 | double Pserv = 0; |
---|
| 63 | |
---|
| 64 | double R = 0; |
---|
| 65 | try{ |
---|
| 66 | R = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); |
---|
| 67 | } catch (Exception e){ |
---|
| 68 | // |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | double C = 0; |
---|
| 72 | try{ |
---|
| 73 | C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); |
---|
| 74 | } catch (Exception e){ |
---|
| 75 | // |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | double K = 0; |
---|
| 79 | double V = 0; |
---|
| 80 | double Cair = EnvironmentConditions.AIR_HEAT_CAPACITY; |
---|
| 81 | double ro = EnvironmentConditions.AIR_DENSITY; |
---|
| 82 | |
---|
| 83 | for(Device device: node.getResourceCharacteristic().getDevices()){ |
---|
| 84 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
| 85 | Fan fan = (Fan) device; |
---|
| 86 | V = V + fan.getAirflowInterface().getRecentAirflow().getValue(); |
---|
| 87 | //double dp = EnvironmentConditions.AIR_PRESSURE; |
---|
| 88 | //V = fan.getPowerInterface().getRecentPowerUsage().getValue() * 0.6 /dp; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | K = V * Cair * ro; |
---|
| 93 | //System.out.println("-------A: " + A + "; V:" + V); |
---|
| 94 | // 1) look where we are |
---|
| 95 | double delta_t = Sim_system.clock() - timestamp; |
---|
| 96 | double currentCpuTemp = cpu.getThermalInterface().getRecentTemperature().getValue(); |
---|
| 97 | |
---|
| 98 | double Tin = EnvironmentConditions.ROOM_TEMPERATURE; |
---|
| 99 | Pserv = node.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 100 | double Pcpu = node.getProcessors().get(0).getPowerInterface().getRecentPowerUsage().getValue(); |
---|
| 101 | double objectiveCpuTemp = Pcpu * R + Tin; |
---|
| 102 | double targetTemp = Pserv/K + Tin; |
---|
| 103 | objective_temperature = targetTemp; |
---|
| 104 | //System.out.println("node: " + node.getFullName() + "; objective_temperature" + objective_temperature +" : currentCpuTemp + ; " +currentCpuTemp + "; targetCpuTemp: " +objectiveCpuTemp ); |
---|
| 105 | /*if(delta_t == 0) |
---|
| 106 | new_temperature =Tin + ((objectiveCpuTemp+ (currentCpuTemp-objectiveCpuTemp)* Math.exp(-delta_t/ (H * C)))/H)/A; |
---|
| 107 | else |
---|
| 108 | new_temperature =Tin + ((objectiveCpuTemp+ (currentCpuTemp-objectiveCpuTemp)* Math.exp(-delta_t/ (H * C)))/H + (C *(1/delta_t)))/A; |
---|
| 109 | */ |
---|
| 110 | |
---|
| 111 | //new_temperature =currentCpuTemp + (old_temperature-currentCpuTemp)* Math.exp(-delta_t/ (H * C)); |
---|
| 112 | new_temperature = objective_temperature + (old_temperature - objective_temperature) * Math.exp(-delta_t / (R * C)); |
---|
| 113 | //new_temperature = objective_temperature + 1/ (A *R) *(currentCpuTemp - objective_temperature)* Math.exp(-delta_t / (R * C)); |
---|
| 114 | |
---|
| 115 | //new_temperature = currentCpuTemp + (Tin - currentCpuTemp) * Math.exp(-delta_t / (R * A)); |
---|
| 116 | //System.out.println("***************" +new_temperature); |
---|
| 117 | //new_temperature = (Tin + Pserv/A + ((14.4 - Pserv/A) * Math.exp(- Sim_system.clock() * A / C))); |
---|
| 118 | //System.out.println("################" + new_temperature); |
---|
| 119 | //new_temperature =Tin + (currentCpuTemp - Tin)/(H * A) + (old_temperature-objective_temperature)* Math.exp(-delta_t * A/ C); |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | // 3) compute new objective |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | //System.out.println("=========== " + Sim_system.clock() + "; objective_temperature: " + objective_temperature + "; new_temperature: " + new_temperature + "; targetTemp: " + targetTemp); |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | // 4) check if we will need to tune fans |
---|
| 129 | if(fan && targetTemp < EnvironmentConditions.TFanLow) { |
---|
| 130 | double timer = Cair/K * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow)); |
---|
| 131 | if(future == -1 || future > timer) { |
---|
| 132 | future = timer; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | if(!fan && targetTemp > EnvironmentConditions.TFanHigh) { |
---|
| 136 | double timer = Cair/K * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanHigh)); |
---|
| 137 | if(future == -1 || future > timer) { |
---|
| 138 | future = timer; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | // 5) save everything |
---|
| 143 | timestamp = Sim_system.clock(); |
---|
| 144 | old_temperature = new_temperature; |
---|
| 145 | //objective_temperature = targetTemp; |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | if((future >= 0) && ((next_timer < Sim_system.clock()) || (next_timer >= future + Sim_system.clock()))) { |
---|
| 149 | //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(future, DCWormsTags.FANMGT, "Test"); |
---|
| 150 | next_timer = future + Sim_system.clock() - 0.01; |
---|
| 151 | } |
---|
| 152 | //System.out.println("------- " + new_temperature); |
---|
| 153 | return new_temperature; |
---|
| 154 | } |
---|
| 155 | } |
---|