package experiments.simpat2014.models.basic; import schedframe.resources.StandardResourceType; 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; import gridsim.dcworms.DCWormsTags; public class CpuEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { private static double Pidle = 4; private static double Pfull = 50; private static int Tidle = 33; 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 int cpu_temp_monitor = 0; public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { double powerConsumption = 0; Processor cpu = (Processor)resource; powerConsumption = Pidle + (Pfull- Pidle) * cpu.getLoadInterface().getRecentUtilization().getValue()/100; return powerConsumption; } @Override public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { double future = -1; Processor cpu = (Processor) resource; double R = 0; double Rb = 0; double Rcv = 0; try{ Rb = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue(); } catch (Exception e){ // } double k = 0; try{ k = Double.valueOf(cpu.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue(); } catch (Exception e){ // } double a = 0; try{ a = Double.valueOf(cpu.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue(); } catch (Exception e){ a = 1; } double V = 0; for(Device device: cpu.getParent().getResourceCharacteristic().getDevices()){ if(device.getType().equals(StandardResourceType.Fan)){ Fan fan = (Fan) device; V = fan.getAirflowInterface().getRecentAirflow().getValue(); } } Rcv = 1/ (k * Math.pow(V, a)); R = Rb + Rcv; double C = 0; try{ C = Double.valueOf(cpu.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue(); } catch (Exception e){ // } // 1) look where we are double delta_t = Sim_system.clock() - timestamp; /***************model1*************/ //new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/sink); /***************model2*************/ new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); // 2) calculate if fan is needed ? if(new_temperature <= EnvironmentConditions.TFanLow) { fan = false; } if(new_temperature >= EnvironmentConditions.TFanHigh) { fan = true; } // 3) compute new objective double Tin = EnvironmentConditions.ROOM_TEMPERATURE; double Pcpu = cpu.getPowerInterface().getRecentPowerUsage().getValue(); new_temperature = objective_temperature - (objective_temperature - old_temperature) * Math.exp(-delta_t/(R * C)); //new_temperature = (Pcpu * R + Tin) - (Pcpu * R + Tin - Tidle) * Math.exp(-Sim_system.clock()/(R * C));; /***************model1 - GEO1*************/ //double cpuLoad = cpu.getLoadInterface().getRecentUtilization().getValue(); //double targetTemp = Tidle + cpuLoad/100 * dTfull; //if(fan) { // targetTemp = targetTemp - dTfan; //} /***************model2 - GEO2*************/ //Node node = (Node) cpu.getParent(); //Pserv = node.getPowerInterface().getRecentPowerUsage().getValue(); //double targetTemp = Pcpu * R + Tin; /***************model3 - GEO1 + GEO2*************/ /*double targetTemp = Pcpu * R + Tin; if(fan) { targetTemp = targetTemp - dTfan; }*/ /***************model4 - WP*************/ double targetTemp = Pcpu * R + Tin; // 4) check if we will need to tune fans if(fan && targetTemp < EnvironmentConditions.TFanLow) { double timer = C * R * Math.log((new_temperature - targetTemp)/(targetTemp - EnvironmentConditions.TFanLow)); if(future == -1 || future > timer) { future = timer; } } if(!fan && targetTemp > EnvironmentConditions.TFanHigh) { double timer = C * R * 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; } if(new_temperature > EnvironmentConditions.tempLevelMedium2Low && new_temperature < EnvironmentConditions.tempLevelLow2Medium){ if(cpu_temp_monitor != 1){ cpu_temp_monitor = 1; DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); } } else if(new_temperature > EnvironmentConditions.tempLevelLow2Medium && new_temperature < EnvironmentConditions.tempLevelHigh2Medium){ if(cpu_temp_monitor != 2){ cpu_temp_monitor = 2; DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); } } else if(new_temperature > EnvironmentConditions.tempLevelHigh2Medium && new_temperature < EnvironmentConditions.tempLevelMedium2High){ if(cpu_temp_monitor != 3){ cpu_temp_monitor = 3; DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); } } else if(new_temperature > EnvironmentConditions.tempLevelMedium2High){ if(cpu_temp_monitor != 4){ cpu_temp_monitor = 4; DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); } } //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_TEMPERATURE_LIMIT_EXCEEDED, resource.getFullName()); return new_temperature; } }