[477] | 1 | package example.energy; |
---|
| 2 | |
---|
[580] | 3 | import schedframe.resources.ResourceStatus; |
---|
[477] | 4 | import schedframe.resources.computing.Processor; |
---|
[1415] | 5 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
[477] | 6 | import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName; |
---|
[1207] | 7 | import schedframe.resources.devices.PhysicalResource; |
---|
[477] | 8 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
| 9 | |
---|
[901] | 10 | public class ProcessorEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
[477] | 11 | |
---|
[1415] | 12 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
[1207] | 13 | PhysicalResource resource) { |
---|
[1555] | 14 | double powerConsumption = 0; |
---|
[1207] | 15 | |
---|
[477] | 16 | Processor cpu = (Processor)resource; |
---|
[497] | 17 | if(resource.getPowerInterface().getPowerState().equals(StandardPowerStateName.OFF)) |
---|
[532] | 18 | powerConsumption = 0; |
---|
[497] | 19 | else { |
---|
[883] | 20 | if(resource.getStatus() == ResourceStatus.BUSY){ |
---|
| 21 | try { |
---|
| 22 | |
---|
[580] | 23 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState()); |
---|
[883] | 24 | } catch (NoSuchFieldException e) { |
---|
| 25 | try { |
---|
[1555] | 26 | if(cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPowerState()) != -1) |
---|
| 27 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPowerState()); |
---|
[883] | 28 | } catch (NoSuchFieldException e1) { |
---|
| 29 | powerConsumption = 10; |
---|
| 30 | } |
---|
[580] | 31 | } |
---|
[883] | 32 | } else{ |
---|
[497] | 33 | try { |
---|
[1555] | 34 | if(cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPowerState()) != -1) |
---|
| 35 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPowerState()); |
---|
| 36 | } catch (NoSuchFieldException e1) { |
---|
| 37 | powerConsumption = 0; |
---|
[497] | 38 | } |
---|
[477] | 39 | } |
---|
[883] | 40 | |
---|
[497] | 41 | } |
---|
[1415] | 42 | if(cpu.getLoadInterface().getRecentUtilization().getValue() != 0.0){ |
---|
| 43 | powerConsumption = powerConsumption * cpu.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
| 44 | } |
---|
[532] | 45 | return powerConsumption; |
---|
[477] | 46 | } |
---|
| 47 | |
---|
| 48 | } |
---|