1 | package test.stencils.plugins; |
---|
2 | |
---|
3 | import example.energy.BaseEnergyEstimationPlugin; |
---|
4 | import gridsim.dcworms.DCWormsTags; |
---|
5 | import schedframe.resources.computing.Node; |
---|
6 | import schedframe.resources.computing.Processor; |
---|
7 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
8 | import schedframe.resources.computing.profiles.energy.power.plugin.EnergyPluginConfiguration; |
---|
9 | import schedframe.resources.devices.Device; |
---|
10 | import schedframe.resources.devices.PhysicalResource; |
---|
11 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
12 | import simulator.DataCenterWorkloadSimulator; |
---|
13 | |
---|
14 | public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
15 | |
---|
16 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
17 | PhysicalResource resource) { |
---|
18 | double powerConsumption = 0; |
---|
19 | EnergyPluginConfiguration epConf = (EnergyPluginConfiguration) getConfiguration(); |
---|
20 | Node node = (Node) resource; |
---|
21 | for(Processor cpu: node.getProcessors()){ |
---|
22 | try{ |
---|
23 | powerConsumption = powerConsumption + cpu.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
24 | } catch (Exception e){ |
---|
25 | |
---|
26 | } |
---|
27 | } |
---|
28 | try { |
---|
29 | powerConsumption = powerConsumption + node.getPowerInterface().getPowerConsumption(node.getPowerInterface().getPowerState()); |
---|
30 | for(Device dev: node.getResourceCharacteristic().getDevices()){ |
---|
31 | if(dev.getPowerInterface().getRecentPowerUsage().getValue() != -1) |
---|
32 | powerConsumption = powerConsumption + dev.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
33 | } |
---|
34 | } catch (NoSuchFieldException e) { |
---|
35 | } |
---|
36 | |
---|
37 | if(epConf.getPowerCapLevel() != -1 && powerConsumption > epConf.getPowerCapLevel()){ |
---|
38 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_POWER_LIMIT_EXCEEDED, node.getFullName()); |
---|
39 | } |
---|
40 | return powerConsumption; |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|