1 | package test.rewolucja.resources.physical.implementation; |
---|
2 | |
---|
3 | import java.util.Properties; |
---|
4 | |
---|
5 | import schedframe.resources.units.CpuSpeed; |
---|
6 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
7 | import test.rewolucja.energy.extension.EnergyExtension; |
---|
8 | import test.rewolucja.energy.profile.CPUPowerProfile; |
---|
9 | import test.rewolucja.energy.profile.PowerInterface; |
---|
10 | import test.rewolucja.extensions.ExtensionType; |
---|
11 | import test.rewolucja.resources.ResourceCharacteristics; |
---|
12 | import test.rewolucja.resources.ResourceStatus; |
---|
13 | import test.rewolucja.resources.description.ExecResourceDescription; |
---|
14 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
15 | import test.rewolucja.resources.properties.CpuPropertiesBuilder; |
---|
16 | import test.rewolucja.resources.properties.PropertiesDirector; |
---|
17 | |
---|
18 | public class CPU extends ComputingResource{ |
---|
19 | |
---|
20 | |
---|
21 | public CPU (ExecResourceDescription resDesc) { |
---|
22 | super(resDesc); |
---|
23 | accept(resDesc.getPowerProfile()); |
---|
24 | } |
---|
25 | |
---|
26 | /*public CPU (String resourceName, ResourceCharacteristics resourceCharacteristic) { |
---|
27 | super(resourceName, ResourceType.CPU, resourceCharacteristic); |
---|
28 | extensionList.add(new EnergyExtension(this, "example.energy.CPUEnergyEstimationPlugin")); |
---|
29 | }*/ |
---|
30 | |
---|
31 | public ComputingNode getComputingNode(){ |
---|
32 | return (ComputingNode)parent; |
---|
33 | } |
---|
34 | |
---|
35 | public double getUtilization(){ |
---|
36 | if(getStatus() == ResourceStatus.BUSY) |
---|
37 | return 1; |
---|
38 | else |
---|
39 | return 0; |
---|
40 | } |
---|
41 | |
---|
42 | public int getMIPS(){ |
---|
43 | return getProcessorSpeed().getAmount(); |
---|
44 | } |
---|
45 | |
---|
46 | public int getAvailableMIPS(){ |
---|
47 | return getProcessorSpeed().getFreeAmount(); |
---|
48 | } |
---|
49 | |
---|
50 | protected CpuSpeed getProcessorSpeed(){ |
---|
51 | return (CpuSpeed) getResourceCharacteristic().getResourceUnit(ResourceParameterName.CPUSPEED); |
---|
52 | } |
---|
53 | |
---|
54 | public CPUPowerProfile getPowerInterface(){ |
---|
55 | if (extensionList != null) { |
---|
56 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
57 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
58 | return (CPUPowerProfile)ee.getPowerInterface(); |
---|
59 | } |
---|
60 | } |
---|
61 | return null; |
---|
62 | } |
---|
63 | |
---|
64 | public void initCharacteristics(ExecResourceDescription resDesc){ |
---|
65 | resourceCharacteristic = new ResourceCharacteristics(); |
---|
66 | resourceCharacteristic.addResourceUnit(new CpuSpeed(name, 1, 0)); |
---|
67 | } |
---|
68 | |
---|
69 | public Properties getProperties(){ |
---|
70 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
71 | propDirector.setPropertiesBuilder(new CpuPropertiesBuilder()); |
---|
72 | propDirector.constructProperties(this); |
---|
73 | return propDirector.getProperties(); |
---|
74 | } |
---|
75 | |
---|
76 | public void accept(PowerInterface powIntVis){ |
---|
77 | extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.CPUEnergyEstimationPlugin")); |
---|
78 | powIntVis.visit(this); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|