1 package Analysis.Scheduling;
3 import java.util.Hashtable;
4 import java.util.Queue;
5 import java.util.Vector;
7 import Analysis.TaskStateAnalysis.FlagState;
8 import IR.TaskDescriptor;
10 public class CoreSimulator {
11 Vector<TaskSimulator> tasks;
12 RuntimeSchedule rSchedule;
14 Hashtable<FlagState, Queue<Integer>> targetCSimulator;
15 Hashtable<FlagState, Vector<Integer>> allyCSimulator;
16 Hashtable<FlagState, FlagState> targetFState;
20 public CoreSimulator(RuntimeSchedule schedule, int coreNum) {
23 this.rSchedule = schedule;
24 this.coreNum = coreNum;
27 public CoreSimulator(int coreNum) {
30 this.coreNum = coreNum;
36 this.targetCSimulator = null;
37 this.targetFState = null;
38 this.rSchedule = null;
42 public void deployTasks(Vector<TaskDescriptor> tasks) {
47 if(this.tasks == null) {
48 this.tasks = new Vector<TaskSimulator>();
53 for(int i = 0; i < tasks.size(); i++) {
54 TaskDescriptor td = tasks.elementAt(i);
55 this.tasks.add(new TaskSimulator(td, this));
59 public Queue<Integer> getTargetCores(FlagState fstate) {
60 if(targetCSimulator == null) {
63 return targetCSimulator.get(fstate);
66 public void setTargetCSimulator(Hashtable<FlagState, Queue<Integer>> targetCSimulator) {
67 this.targetCSimulator = targetCSimulator;
70 public Vector<Integer> getAllyCores(FlagState fstate) {
71 if(allyCSimulator == null) {
74 return allyCSimulator.get(fstate);
77 public void setAllyCSimulator(Hashtable<FlagState, Vector<Integer>> allyCSimulator) {
78 this.allyCSimulator = allyCSimulator;
81 public FlagState getTargetFState(FlagState fstate) {
82 if(targetFState == null) {
85 return targetFState.get(fstate);
88 public void setTargetFState(Hashtable<FlagState, FlagState> targetFState) {
89 this.targetFState = targetFState;
92 public int getActiveTime() {
96 public int getCoreNum() {
100 public Vector<TaskSimulator> getTasks() {
104 public RuntimeSchedule getRSchedule() {
108 public void setRSchedule(RuntimeSchedule schedule) {
109 rSchedule = schedule;
112 public TaskSimulator getRtask() {
116 public void addObject(ObjectSimulator newObj) {
117 if(this.tasks == null) {
120 for(int i = 0; i < this.tasks.size(); i++) {
121 this.tasks.elementAt(i).enquePara(newObj, null, 0, true);
125 public void addObject(ObjectSimulator newObj, FlagState fs, int version) {
126 if(this.tasks == null) {
129 for(int i = 0; i < this.tasks.size(); i++) {
130 this.tasks.elementAt(i).enquePara(newObj, fs, version, false);
134 public Vector<ObjectSimulator> finishTask() {
135 assert(this.rtask != null);
137 Vector<ObjectSimulator> transObjs = null;
138 Vector<Queue<ObjectSimulator>> paraQueues = this.rtask.getParaQueues();
139 for(int i = 0; i < paraQueues.size(); i++) {
140 ObjectSimulator obj = paraQueues.elementAt(i).poll();
142 boolean remove = false;
143 if((this.targetFState != null) && (this.targetFState.containsKey(obj.getCurrentFS()))) {
144 if(transObjs == null) {
145 transObjs = new Vector<ObjectSimulator>();
147 if(!transObjs.contains(obj)) {
152 // check if this object becoming shared or not
153 Vector<Integer> allycores = this.getAllyCores(obj.getCurrentFS());
154 if(allycores != null) {
156 for(int k = 0; k < allycores.size(); ++k) {
157 Integer allyCore = allycores.elementAt(k);
158 if(transObjs == null) {
159 transObjs = new Vector<ObjectSimulator>();
161 if(!transObjs.contains(obj)) {
167 for(int j = 0; j < this.tasks.size(); j++) {
168 this.tasks.elementAt(j).refreshPara(obj, remove);
171 this.activeTime += this.rtask.getCurrentRun().getFinishTime();
177 public void updateTask(int time) {
178 this.activeTime += time;
179 this.rtask.updateFinishTime(time);
182 public TaskSimulator process() {
183 TaskSimulator next = rSchedule.schedule(tasks);