3 import org.simgrid.surf.*;
4 import org.simgrid.msg.Msg;
6 import java.util.ArrayList;
8 public class CpuConstantModel extends CpuModel {
10 private List<CpuConstant> cpus = new ArrayList<CpuConstant>();
12 public CpuConstantModel() {
13 Msg.info("Initialize Cpu Constant Model");
16 public Cpu createCpu(String name, double[] power_peak, int pstate, double power_scale, TmgrTrace power_trace, int core, ResourceState state_initial, TmgrTrace state_trace, XbtDict cpu_properties) {
17 Msg.info("New Cpu("+name+", "+power_peak[pstate]+", "+power_scale+")");
19 CpuConstant res = new CpuConstant(this, name, cpu_properties, core, power_peak[pstate], power_scale);
24 public double shareResources(double now) {
26 for (int i=0; i<cpus.size();i++){
27 double tmp = cpus.get(i).share(now);
28 if (tmp!=-1 && (res==-1 || tmp<res))
31 Msg.info("ShareResources at time "+res);
35 public void updateActionsState(double now, double delta) {
36 Action[] actions = getRunningActionSet().getArray();
37 Msg.info("UpdateActionState of "+actions.length+" actions");
38 for (int i=0; i<actions.length; i++) {
39 CpuConstantAction action = (CpuConstantAction)actions[i];
41 if (!action.sleeping()) {
42 Msg.info("action remains "+action.getRemains()+" after delta of "+delta);
43 if (action.getRemains()==0.0){
44 action.setState(ActionState.SURF_ACTION_DONE);
45 Msg.info("action DONE");
51 public void addTraces() {
54 public class CpuConstant extends Cpu {
55 private List<CpuConstantAction> actions = new ArrayList<CpuConstantAction>();
57 public CpuConstant(CpuConstantModel model, String name, XbtDict props,
58 int core, double powerPeak, double powerScale) {
59 super(model, name, props, core, powerPeak, powerScale);
62 public void remove(CpuConstantAction action){
63 actions.remove(action);
66 public CpuAction execute(double size) {
67 CpuConstantAction res = new CpuConstantAction(getModel(), size, false, false, this);
68 Msg.info("Execute action of size "+size+" sleeping "+res.sleeping());
73 public CpuAction sleep(double duration) {
74 CpuConstantAction res = new CpuConstantAction(getModel(), duration, false, true, this);
75 Msg.info("Sleep action of duration "+duration+" sleeping "+res.sleeping());
79 public double share(double now){
81 for (int i=0; i<actions.size();i++){
82 double tmp = actions.get(i).getRemains()/getCurrentPowerPeak();
83 Msg.info("Share action with new time "+tmp);
84 if (res==-1 || tmp<res)
90 public ResourceState getState(){
91 return ResourceState.SURF_RESOURCE_ON;
95 public class CpuConstantAction extends CpuAction {
98 public CpuConstantAction(Model model, double cost, boolean failed, boolean sleep, CpuConstant cpu) {
99 super(model, cost, failed);
104 public void update(double delta){
105 updateRemains(delta*cpu.getCurrentPowerPeak());
107 public synchronized void delete() {
112 public boolean sleeping() {return sleep;}
113 public void setPriority(double priority) {}