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.PowerInterface; |
---|
9 | import test.rewolucja.energy.profile.implementation.CPUPowerProfile; |
---|
10 | import test.rewolucja.extensions.ExtensionType; |
---|
11 | import test.rewolucja.resources.ResourceCharacteristics; |
---|
12 | import test.rewolucja.resources.description.ExecResourceDescription; |
---|
13 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
14 | import test.rewolucja.resources.properties.CpuPropertiesBuilder; |
---|
15 | import test.rewolucja.resources.properties.PropertiesDirector; |
---|
16 | |
---|
17 | public class Processor extends ComputingResource{ |
---|
18 | |
---|
19 | |
---|
20 | public Processor (ExecResourceDescription resDesc) { |
---|
21 | super(resDesc); |
---|
22 | accept(resDesc.getPowerProfile()); |
---|
23 | } |
---|
24 | |
---|
25 | /*public CPU (String resourceName, ResourceCharacteristics resourceCharacteristic) { |
---|
26 | super(resourceName, ResourceType.CPU, resourceCharacteristic); |
---|
27 | extensionList.add(new EnergyExtension(this, "example.energy.CPUEnergyEstimationPlugin")); |
---|
28 | }*/ |
---|
29 | |
---|
30 | public ComputingNode getComputingNode(){ |
---|
31 | return (ComputingNode)parent; |
---|
32 | } |
---|
33 | |
---|
34 | public int getMIPS(){ |
---|
35 | return getSpeedUnit().getAmount(); |
---|
36 | } |
---|
37 | |
---|
38 | public int getAvailableMIPS(){ |
---|
39 | return getSpeedUnit().getFreeAmount(); |
---|
40 | } |
---|
41 | |
---|
42 | private CpuSpeed getSpeedUnit(){ |
---|
43 | return (CpuSpeed) getResourceCharacteristic().getResourceUnit(ResourceParameterName.CPUSPEED); |
---|
44 | } |
---|
45 | |
---|
46 | public CPUPowerProfile getPowerInterface(){ |
---|
47 | if (extensionList != null) { |
---|
48 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
49 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
50 | return (CPUPowerProfile)ee.getPowerInterface(); |
---|
51 | } |
---|
52 | } |
---|
53 | return null; |
---|
54 | } |
---|
55 | |
---|
56 | public void initCharacteristics(ExecResourceDescription resDesc){ |
---|
57 | resourceCharacteristic = new ResourceCharacteristics(); |
---|
58 | |
---|
59 | int speed = 1000; |
---|
60 | if( resDesc.getCategory().getName().equals("A")) |
---|
61 | speed = 2000; |
---|
62 | |
---|
63 | resourceCharacteristic.addResourceUnit(new CpuSpeed(name, speed, 0)); |
---|
64 | } |
---|
65 | |
---|
66 | public Properties getProperties(){ |
---|
67 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
68 | propDirector.setPropertiesBuilder(new CpuPropertiesBuilder()); |
---|
69 | propDirector.constructProperties(this); |
---|
70 | return propDirector.getProperties(); |
---|
71 | } |
---|
72 | |
---|
73 | public void accept(PowerInterface powIntVis){ |
---|
74 | extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.CPUEnergyEstimationPlugin")); |
---|
75 | powIntVis.visit(this); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|