1 | package test.simpat.models.article; |
---|
2 | |
---|
3 | import schedframe.resources.StandardResourceType; |
---|
4 | import schedframe.resources.computing.ComputingResource; |
---|
5 | import schedframe.resources.computing.Node; |
---|
6 | import schedframe.resources.computing.Processor; |
---|
7 | import schedframe.resources.computing.coolemall.NodeGroup; |
---|
8 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
9 | import schedframe.resources.computing.profiles.energy.power.PState; |
---|
10 | import schedframe.resources.devices.Device; |
---|
11 | import schedframe.resources.devices.Fan; |
---|
12 | import schedframe.resources.devices.PhysicalResource; |
---|
13 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
14 | import simulator.DataCenterWorkloadSimulator; |
---|
15 | import test.simpat.EnvironmentConditions; |
---|
16 | import example.energy.BaseEnergyEstimationPlugin; |
---|
17 | import gridsim.dcworms.DCWormsTags; |
---|
18 | |
---|
19 | public class NodeGroupEnergyEstimationPluginPowerCapping extends BaseEnergyEstimationPlugin{ |
---|
20 | |
---|
21 | double powerCapLevel = -1; |
---|
22 | double powerUpgradeLevel = -1; |
---|
23 | |
---|
24 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
25 | PhysicalResource resource) { |
---|
26 | |
---|
27 | |
---|
28 | loadThresholds((ComputingResource)resource); |
---|
29 | |
---|
30 | double powerConsumption = 0; |
---|
31 | NodeGroup nodeGroup = (NodeGroup)resource; |
---|
32 | for(Node node: nodeGroup.getNodes()){ |
---|
33 | try{ |
---|
34 | powerConsumption = powerConsumption + node.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
35 | powerConsumption = powerConsumption + node.getProcessors().get(0).getResourceCharacteristic().getDevices().get(0).getPowerInterface().getRecentPowerUsage().getValue(); |
---|
36 | |
---|
37 | } catch (Exception e){ |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | for(Device device: nodeGroup.getResourceCharacteristic().getDevices()){ |
---|
42 | if(device.getType().equals(StandardResourceType.Fan)){ |
---|
43 | Fan fan = (Fan) device; |
---|
44 | powerConsumption = powerConsumption + fan.getPowerInterface().getRecentPowerUsage().getValue(); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | if(powerCapLevel!= -1 && powerConsumption > powerCapLevel){ |
---|
49 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_POWER_LIMIT_EXCEEDED, resource.getFullName()); |
---|
50 | } |
---|
51 | else if(powerUpgradeLevel != -1 && powerConsumption < powerUpgradeLevel){ |
---|
52 | DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(0, DCWormsTags.RESOURCE_POWER_LIMIT_EXCEEDED, resource.getFullName()); |
---|
53 | } |
---|
54 | |
---|
55 | return powerConsumption; |
---|
56 | } |
---|
57 | |
---|
58 | private void loadThresholds(ComputingResource compResource){ |
---|
59 | |
---|
60 | NodeGroup ng = (NodeGroup) compResource; |
---|
61 | double pcLevel = 0; |
---|
62 | double puLevel = 0; |
---|
63 | for(Processor proc: ng.getProcessors()){ |
---|
64 | PState highestPState = proc.getPowerInterface().getHighestPState(); |
---|
65 | PState secondHighestPState = proc.getPowerInterface().getLowestPState(); |
---|
66 | for(String pStateName: proc.getPowerInterface().getSupportedPStates().keySet()){ |
---|
67 | PState pState = proc.getPowerInterface().getSupportedPStates().get(pStateName); |
---|
68 | if(pState.getFrequency() < secondHighestPState.getFrequency() && pState.getFrequency() > highestPState.getFrequency()){ |
---|
69 | secondHighestPState = pState; |
---|
70 | } |
---|
71 | } |
---|
72 | double maxMinPowerUsage = 0; |
---|
73 | double powerUsage = 0; |
---|
74 | |
---|
75 | for(Double load: highestPState.getLoadPowerUsage().keySet()){ |
---|
76 | powerUsage = highestPState.getLoadPowerUsage().get(load); |
---|
77 | if(powerUsage > maxMinPowerUsage){ |
---|
78 | maxMinPowerUsage= powerUsage; |
---|
79 | } |
---|
80 | } |
---|
81 | pcLevel = pcLevel + maxMinPowerUsage; |
---|
82 | |
---|
83 | maxMinPowerUsage = 0; |
---|
84 | powerUsage = 0; |
---|
85 | |
---|
86 | for(Double load: secondHighestPState.getLoadPowerUsage().keySet()){ |
---|
87 | powerUsage = secondHighestPState.getLoadPowerUsage().get(load); |
---|
88 | if(powerUsage > maxMinPowerUsage){ |
---|
89 | maxMinPowerUsage= powerUsage; |
---|
90 | } |
---|
91 | } |
---|
92 | puLevel = puLevel + maxMinPowerUsage; |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | puLevel = (pcLevel * pcLevel / puLevel); |
---|
97 | |
---|
98 | //powerCapLevel = pcLevel; |
---|
99 | //powerUpgradeLevel = puLevel; |
---|
100 | |
---|
101 | powerCapLevel = EnvironmentConditions.powerCapLevel; |
---|
102 | powerUpgradeLevel = EnvironmentConditions.powerUpgradeLevel; |
---|
103 | } |
---|
104 | } |
---|