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,
24 this.rSchedule = schedule;
25 this.coreNum = coreNum;
28 public CoreSimulator(int coreNum) {
31 this.coreNum = coreNum;
37 this.targetCSimulator = null;
38 this.targetFState = null;
39 this.rSchedule = null;
43 public void deployTasks(Vector<TaskDescriptor> tasks) {
48 if(this.tasks == null) {
49 this.tasks = new Vector<TaskSimulator>();
54 for(int i = 0; i < tasks.size(); i++) {
55 TaskDescriptor td = tasks.elementAt(i);
56 this.tasks.add(new TaskSimulator(td, this));
60 public Queue<Integer> getTargetCores(FlagState fstate) {
61 if(targetCSimulator == null) {
64 return targetCSimulator.get(fstate);
67 public void setTargetCSimulator(Hashtable<FlagState,
68 Queue<Integer>> targetCSimulator) {
69 this.targetCSimulator = targetCSimulator;
72 public Vector<Integer> getAllyCores(FlagState fstate) {
73 if(allyCSimulator == null) {
76 return allyCSimulator.get(fstate);
79 public void setAllyCSimulator(Hashtable<FlagState,
80 Vector<Integer>> allyCSimulator) {
81 this.allyCSimulator = allyCSimulator;
84 public FlagState getTargetFState(FlagState fstate) {
85 if(targetFState == null) {
88 return targetFState.get(fstate);
91 public void setTargetFState(Hashtable<FlagState, FlagState> targetFState) {
92 this.targetFState = targetFState;
95 public long getActiveTime() {
99 public int getCoreNum() {
103 public Vector<TaskSimulator> getTasks() {
107 public RuntimeSchedule getRSchedule() {
111 public void setRSchedule(RuntimeSchedule schedule) {
112 rSchedule = schedule;
115 public TaskSimulator getRtask() {
119 public void addObject(ObjectSimulator newObj) {
120 if(this.tasks == null) {
123 for(int i = 0; i < this.tasks.size(); i++) {
124 this.tasks.elementAt(i).enquePara(newObj, null, 0, true);
128 public void addObject(ObjectSimulator newObj,
131 if(this.tasks == null) {
134 for(int i = 0; i < this.tasks.size(); i++) {
135 this.tasks.elementAt(i).enquePara(newObj, fs, version, false);
139 public Vector<ObjectSimulator> finishTask() {
140 assert(this.rtask != null);
142 Vector<ObjectSimulator> transObjs = null;
143 if(this.rtask.currentRun.getExetype() == 0) {
144 Vector<Queue<ObjectSimulator>> paraQueues = this.rtask.getParaQueues();
145 for(int i = 0; i < paraQueues.size(); i++) {
146 ObjectSimulator obj = paraQueues.elementAt(i).poll();
148 boolean remove = false;
149 if((this.targetFState != null)
150 && (this.targetFState.containsKey(obj.getCurrentFS()))) {
151 if(transObjs == null) {
152 transObjs = new Vector<ObjectSimulator>();
154 if(!transObjs.contains(obj)) {
159 // check if this object becoming shared or not
160 Vector<Integer> allycores = this.getAllyCores(obj.getCurrentFS());
161 if(allycores != null) {
163 //for(int k = 0; k < allycores.size(); ++k) {
164 //Integer allyCore = allycores.elementAt(k);
165 if(transObjs == null) {
166 transObjs = new Vector<ObjectSimulator>();
168 if(!transObjs.contains(obj)) {
175 // check if need to transfer to other cores
176 Queue<Integer> targetcores = this.getTargetCores(obj.getCurrentFS());
177 if(targetcores != null) {
178 if(transObjs == null) {
179 transObjs = new Vector<ObjectSimulator>();
181 if(!transObjs.contains(obj)) {
186 for(int j = 0; j < this.tasks.size(); j++) {
187 this.tasks.elementAt(j).refreshPara(obj, remove);
192 this.activeTime += this.rtask.getCurrentRun().getFinishTime();
198 public void updateTask(long time) {
199 this.activeTime += time;
200 this.rtask.updateFinishTime(time);
203 public TaskSimulator process() {
204 TaskSimulator next = rSchedule.schedule(tasks);