[477] | 1 | package schedframe.resources.computing; |
---|
| 2 | |
---|
| 3 | import java.util.List; |
---|
| 4 | import java.util.Properties; |
---|
| 5 | |
---|
[869] | 6 | import schedframe.resources.ResourceStatus; |
---|
[477] | 7 | import schedframe.resources.StandardResourceType; |
---|
| 8 | import schedframe.resources.computing.description.ComputingResourceDescription; |
---|
| 9 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
| 10 | import schedframe.resources.computing.profiles.energy.EnergyExtension; |
---|
| 11 | import schedframe.resources.computing.profiles.energy.power.ui.ProcessorPowerInterface; |
---|
| 12 | import schedframe.resources.computing.properties.CpuPropertiesBuilder; |
---|
| 13 | import schedframe.resources.computing.properties.PropertiesDirector; |
---|
| 14 | import schedframe.resources.units.CpuSpeed; |
---|
| 15 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 16 | |
---|
| 17 | public class Processor extends ComputingResource{ |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | public Processor (ComputingResourceDescription resDesc) { |
---|
| 21 | super(resDesc); |
---|
| 22 | //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin())); |
---|
[756] | 23 | //PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile()); |
---|
| 24 | //accept(new EnergyExtension(pi, resDesc.getPowerProfile())); |
---|
[477] | 25 | } |
---|
| 26 | |
---|
[1247] | 27 | public Node getNode(){ |
---|
[1207] | 28 | ComputingResource compRes = parent; |
---|
| 29 | while(compRes != null && !compRes.getType().equals(StandardResourceType.Node)){ |
---|
| 30 | compRes = compRes.getParent(); |
---|
| 31 | } |
---|
[1247] | 32 | Node compNode = null; |
---|
[1207] | 33 | try{ |
---|
[1247] | 34 | compNode = (Node)compRes; |
---|
[1207] | 35 | } catch(Exception e) { |
---|
| 36 | } |
---|
| 37 | return compNode; |
---|
[477] | 38 | } |
---|
| 39 | |
---|
| 40 | @SuppressWarnings("unchecked") |
---|
| 41 | public List<Core> getCores(){ |
---|
| 42 | return (List<Core>) getDescendantsByType(StandardResourceType.Core); |
---|
| 43 | } |
---|
| 44 | |
---|
[869] | 45 | @SuppressWarnings("unchecked") |
---|
| 46 | public List<Core> getFreeCores(){ |
---|
| 47 | return (List<Core>) getDescendantsByTypeAndStatus(StandardResourceType.Core, ResourceStatus.FREE); |
---|
| 48 | } |
---|
| 49 | |
---|
[477] | 50 | public int getMIPS(){ |
---|
| 51 | int mips; |
---|
| 52 | try { |
---|
| 53 | mips = getSpeedUnit().getAmount(); |
---|
| 54 | } catch (NoSuchFieldException e) { |
---|
| 55 | mips = 1; |
---|
| 56 | } |
---|
| 57 | return mips; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public int getAvailableMIPS(){ |
---|
| 61 | int mips; |
---|
| 62 | try { |
---|
| 63 | mips = getSpeedUnit().getFreeAmount(); |
---|
| 64 | } catch (NoSuchFieldException e) { |
---|
| 65 | mips = 1; |
---|
| 66 | } |
---|
| 67 | return mips; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | private CpuSpeed getSpeedUnit() throws NoSuchFieldException{ |
---|
[1207] | 71 | return (CpuSpeed) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.CPUSPEED); |
---|
[477] | 72 | } |
---|
| 73 | |
---|
| 74 | public ProcessorPowerInterface getPowerInterface(){ |
---|
| 75 | if (extensionList != null) { |
---|
| 76 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
| 77 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
| 78 | return (ProcessorPowerInterface)ee.getPowerInterface(); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | return null; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public void initCharacteristics(ComputingResourceDescription resDesc){ |
---|
| 85 | //resourceCharacteristic = new ResourceCharacteristics.Builder().resourceUnits().build(); |
---|
| 86 | super.initCharacteristics(resDesc); |
---|
| 87 | try{ |
---|
[1207] | 88 | ((ComputingResourceCharacteristics)resourceCharacteristic).addResourceUnit(new CpuSpeed(name, Integer.valueOf(resDesc.getCompResourceParameterValue("speed")) * 1, 0)); |
---|
[477] | 89 | } catch(Exception e){ |
---|
[1207] | 90 | ((ComputingResourceCharacteristics)resourceCharacteristic).addResourceUnit(new CpuSpeed(name, 1, 0)); |
---|
[477] | 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | public Properties getProperties(){ |
---|
| 95 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
| 96 | propDirector.setPropertiesBuilder(new CpuPropertiesBuilder()); |
---|
| 97 | propDirector.constructProperties(this); |
---|
| 98 | return propDirector.getProperties(); |
---|
| 99 | } |
---|
| 100 | |
---|
[756] | 101 | /*private void accept(EnergyExtension e){ |
---|
[477] | 102 | extensionList.add(e); |
---|
| 103 | e.setResource(this); |
---|
[756] | 104 | }*/ |
---|
[477] | 105 | } |
---|
| 106 | |
---|