package experiments.simpat2014.models.basic; import schedframe.resources.StandardResourceType; import schedframe.resources.computing.Node; import schedframe.resources.computing.Processor; import schedframe.resources.computing.profiles.energy.ResourceEvent; import schedframe.resources.devices.Device; import schedframe.resources.devices.Fan; import schedframe.resources.devices.PhysicalResource; import schedframe.scheduling.manager.tasks.JobRegistry; import simulator.DataCenterWorkloadSimulator; import eduni.simjava.Sim_system; import example.energy.BaseEnergyEstimationPlugin; import experiments.simpat2014.EnvironmentConditions; public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { private static double Tidle = 26; private double timestamp = 0; private double old_temperature = Tidle; private double new_temperature = -1; private double objective_temperature = Tidle; private boolean fan = false; private double next_timer = -1; private static double Pidle = 10; private static double Pfull = 76; public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { Node node = (Node) resource; double powerConsumption = 0; /*double Pcpu = 0; for(Processor cpu: node.getProcessors()){ Pcpu = Pcpu + cpu.getPowerInterface().getRecentPowerUsage().getValue(); }*/ powerConsumption = Pidle + (Pfull- Pidle) * node.getLoadInterface().getRecentUtilization().getValue()/100; double Pfan = 0; for(Device device: node.getResourceCharacteristic().getDevices()){ if(device.getType().equals(StandardResourceType.Fan)){ Fan fan = (Fan) device; Pfan = Pfan + fan.getPowerInterface().getRecentPowerUsage().getValue(); } } //powerConsumption = Pcpu + Pfan; powerConsumption = powerConsumption + Pfan; return powerConsumption; } @Override public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { double future = -1; Node node = (Node) resource; Processor cpu = node.getProcessors().get(0); double Pserv = 0; double R = 0; try{ R = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); } catch (Exception e){ // } double C = 0; try{ C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); } catch (Exception e){ // } double K = 0; double V = 0; double Cair = EnvironmentConditions.AIR_HEAT_CAPACITY; double ro = EnvironmentConditions.AIR_DENSITY; for(Device device: node.getResourceCharacteristic().getDevices()){ if(device.getType().equals(StandardResourceType.Fan)){ Fan fan = (Fan) device; V = V + fan.getAirflowInterface().getRecentAirflow().getValue(); //double dp = EnvironmentConditions.AIR_PRESSURE; //V = fan.getPowerInterface().getRecentPowerUsage().getValue() * 0.6 /dp; } } K = V * Cair * ro; //System.out.println("-------A: " + A + "; V:" + V); // 1) look where we are double delta_t = Sim_system.clock() - timestamp; double currentCpuTemp = cpu.getThermalInterface().getRecentTemperature().getValue(); double Tin = EnvironmentConditions.ROOM_TEMPERATURE; Pserv = node.getPowerInterface().getRecentPowerUsage().getValue(); double Pcpu = node.getProcessors().get(0).getPowerInterface().getRecentPowerUsage().getValue(); double objectiveCpuTemp = Pcpu * R + Tin; double targetTemp = Pserv/K + Tin; objective_temperature = targetTemp; //System.out.println("node: " + node.getFullName() + "; objective_temperature" + objective_temperature +" : currentCpuTemp + ; " +currentCpuTemp + "; targetCpuTemp: " +objectiveCpuTemp ); /*if(delta_t == 0) new_temperature =Tin + ((objectiveCpuTemp+ (currentCpuTemp-objectiveCpuTemp)* Math.exp(-delta_t/ (H * C)))/H)/A; else new_temperature =Tin + ((objectiveCpuTemp+ (currentCpuTemp-objectiveCpuTemp)* Math.exp(-delta_t/ (H * C)))/H + (C *(1/delta_t)))/A; */ //new_temperature =currentCpuTemp + (old_temperature-currentCpuTemp)* Math.exp(-delta_t/ (H * C)); new_temperature = objective_temperature + (old_temperature - objective_temperature) * Math.exp(-delta_t / (R * C)); //new_temperature = objective_temperature + 1/ (A *R) *(currentCpuTemp - objective_temperature)* Math.exp(-delta_t / (R * C)); //new_temperature = currentCpuTemp + (Tin - currentCpuTemp) * Math.exp(-delta_t / (R * A)); //System.out.println("***************" +new_temperature); //new_temperature = (Tin + Pserv/A + ((14.4 - Pserv/A) * Math.exp(- Sim_system.clock() * A / C))); //System.out.println("################" + new_temperature); //new_temperature =Tin + (currentCpuTemp - Tin)/(H * A) + (old_temperature-objective_temperature)* Math.exp(-delta_t * A/ C); // 3) compute new objective //System.out.println("=========== " + Sim_system.clock() + "; objective_temperature: " + objective_temperature + "; new_temperature: " + new_temperature + "; targetTemp: " + targetTemp); // 4) check if we will need to tune fans if(fan && targetTemp < EnvironmentConditions.TFanLow) { double timer = Cair/K * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow)); if(future == -1 || future > timer) { future = timer; } } if(!fan && targetTemp > EnvironmentConditions.TFanHigh) { double timer = Cair/K * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanHigh)); if(future == -1 || future > timer) { future = timer; } } // 5) save everything timestamp = Sim_system.clock(); old_temperature = new_temperature; //objective_temperature = targetTemp; if((future >= 0) && ((next_timer < Sim_system.clock()) || (next_timer >= future + Sim_system.clock()))) { //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(future, DCWormsTags.FANMGT, "Test"); next_timer = future + Sim_system.clock() - 0.01; } //System.out.println("------- " + new_temperature); return new_temperature; } }