Mercurial > hg > Game > Cerium
annotate TaskManager/Fifo/FifoTaskManagerImpl.cc @ 1067:5ad8fb1dc70f draft
print_arch add.
author | tkaito |
---|---|
date | Fri, 17 Dec 2010 19:59:24 +0900 |
parents | 8cd123d2f3ca |
children | 325b6c6d7d65 |
rev | line source |
---|---|
3 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "FifoTaskManagerImpl.h" | |
955 | 5 #include "QueueInfo.h" |
6 #include "TaskList.h" | |
373 | 7 #include "Scheduler.h" |
619 | 8 #include "SchedTask.h" |
47 | 9 #include "types.h" |
109 | 10 #include "error.h" |
690 | 11 #include "SchedNop.h" |
703 | 12 #include "SysFunc.h" |
3 | 13 |
955 | 14 extern QueueInfo<TaskList> *taskListPool; |
15 | |
721 | 16 // static void send_alloc_reply(FifoTaskManagerImpl *tm, int id, MainScheduler *s); |
17 | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
18 FifoTaskManagerImpl::~FifoTaskManagerImpl() |
109 | 19 { |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
20 delete mainScheduler; |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
21 |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
22 delete taskQueueImpl ; |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
23 delete htaskImpl ; |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
24 |
109 | 25 } |
26 | |
27 /** | |
853 | 28 * FifoTaskManager 単独で走るときの初期化 |
321 | 29 * MailManager は PPE スケジューラとのメール交換、 |
30 * FifoScheduler は PPE 側のスケジューラ | |
109 | 31 */ |
3 | 32 void |
1057
8cd123d2f3ca
debug_check_spu_idle add. commandline option [-spuidle].
tkaito@henri
parents:
972
diff
changeset
|
33 FifoTaskManagerImpl::init(int spuIdle_) |
3 | 34 { |
719
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
35 // TaskManager から呼ばれるので、かなりの部分は初期化されている。 |
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
36 |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
37 mainScheduler = new MainScheduler(); |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
38 mainScheduler->init(this); |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
39 mainScheduler->id = 0; |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
40 set_scheduler(mainScheduler); |
42 | 41 |
955 | 42 taskListInfo = new QueueInfo<TaskList>(taskListPool); |
43 ppeTaskList = new QueueInfo<TaskList>(taskListPool); | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
44 |
619 | 45 schedTaskManager = new SchedTask(); |
835 | 46 others = 0; |
972 | 47 schedTaskManager->init(0,0,0,mainScheduler,0); |
619 | 48 |
109 | 49 } |
50 | |
51 /** | |
321 | 52 * これは CellTaskManagerImpl から呼ばれる。 |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
53 * TaskList等 は共用で使うので引数に。 |
321 | 54 * CellTaskManagerImpl と FifoTaskManagerImpl が同時に |
373 | 55 * 上のデータにアクセスする事は(今は)ないのでこれでおk |
109 | 56 */ |
57 void | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
58 FifoTaskManagerImpl::init(MainScheduler *_sched, TaskManagerImpl *tm) |
109 | 59 { |
60 | |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
61 mainScheduler = _sched; |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
62 mainScheduler->init(this); |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
63 set_scheduler(mainScheduler); |
109 | 64 |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
65 taskQueueImpl = tm-> taskQueueImpl ; |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
66 htaskImpl = tm-> htaskImpl ; |
719
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
67 waitTaskQueue = tm->waitTaskQueue; |
109 | 68 |
955 | 69 taskListInfo = new QueueInfo<TaskList>(taskListPool); |
70 ppeTaskList = new QueueInfo<TaskList>(taskListPool); | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
71 |
936
178fbcc81fda
dead lock on spu/ppu mail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
853
diff
changeset
|
72 // schedTaskManager = new SchedTask(); |
835 | 73 others = tm; |
936
178fbcc81fda
dead lock on spu/ppu mail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
853
diff
changeset
|
74 // schedTaskManager->init(0,0,0,mainScheduler); |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
75 |
109 | 76 } |
77 | |
721 | 78 // void FifoTaskManagerImpl::show_profile() {} |
79 // void FifoTaskManagerImpl::start_profile() {} | |
672 | 80 |
109 | 81 /** |
321 | 82 * スケジューラに渡す TaskList を取得する。 |
109 | 83 * |
321 | 84 * @return 実行タスクリスト |
109 | 85 * |
321 | 86 * ActiveTaskQueue (依存条件は満たし済み) のタスクを |
87 * 実行タスクリストに入れる | |
109 | 88 */ |
808 | 89 void |
806 | 90 FifoTaskManagerImpl::set_runTaskList() |
109 | 91 { |
499 | 92 // printf("active task queue length = %d\n",activeTaskQueue->length()); |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
494
diff
changeset
|
93 while (HTaskPtr htask = activeTaskQueue->poll()) { |
806 | 94 set_taskList(htask, taskListInfo ); |
109 | 95 } |
96 } | |
97 | |
808 | 98 void |
99 FifoTaskManagerImpl::poll() | |
100 { | |
101 set_runTaskList(); | |
102 // list を実行する | |
103 sendTaskList(); | |
104 // ppe scheduler からの mail を調べる | |
105 mail_check(); | |
106 } | |
109 | 107 |
108 void | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
109 FifoTaskManagerImpl::run() |
109 | 110 { |
808 | 111 do { |
112 poll(); | |
809 | 113 } while(!activeTaskQueue->empty()) ; |
109 | 114 |
721 | 115 if (!waitTaskQueue->empty()) { |
736 | 116 get_scheduler()->printf("Dead lock detected\n"); |
721 | 117 } |
109 | 118 } |
119 | |
120 /** | |
321 | 121 * @param [list] 実行タスクリスト |
122 * @return FifoScheduler からのメール | |
109 | 123 * |
321 | 124 * [Tasklist] -> [番兵] -> scheduler->run を抜ける |
109 | 125 */ |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
126 void |
808 | 127 FifoTaskManagerImpl::sendTaskList() |
109 | 128 { |
808 | 129 if (taskListInfo->empty()) return; |
853 | 130 // ppeTaskList は走り終わった ppe の Task の List. |
131 // taskListInfo はこれから走る Task の List. | |
132 // 交換して実行する | |
955 | 133 QueueInfo<TaskList>* tmp = ppeTaskList; |
808 | 134 ppeTaskList = taskListInfo; |
135 taskListInfo = tmp; | |
853 | 136 // ppeTaskList は本来は循環リストなのだけど、実行中は線形リストである。 |
137 // なので、最後に 0 を代入する. 後でなおす。 | |
809 | 138 ppeTaskList->getLast()->next = 0; |
721 | 139 // TaskList のアドレスを送る |
808 | 140 mainScheduler->mail_write_from_host((memaddr)ppeTaskList->getFirst()); |
109 | 141 |
721 | 142 // EXIT_COMMAND (番兵的な意味で) |
143 // これを読むと、mainScheduler->run() から抜けて来る。 | |
144 mainScheduler->mail_write_from_host((memaddr)MY_SPE_COMMAND_EXIT); | |
373 | 145 |
721 | 146 // scheduler は受け取ったメールを元に実行する |
147 mainScheduler->run(new SchedNop()); | |
148 // すべてのlistを実行するまで戻らない | |
853 | 149 |
150 ppeTaskList->getLast()->next = ppeTaskList; | |
151 | |
109 | 152 } |
153 | |
154 /** | |
321 | 155 * PPE Scheduler からのメールをチェックする |
109 | 156 * |
157 * @param [mail_list] | |
321 | 158 * PPE 側で動く Scheduler からのメールリスト |
159 * 終了した Task や、その他(今はまだ実装してないけど)の情報が入ってる | |
109 | 160 * |
373 | 161 * @return Scheduler が次に実行する Task List |
321 | 162 * NULL なら全てのタスクが実行終了したということ |
109 | 163 */ |
164 void | |
719
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
165 FifoTaskManagerImpl::mail_check() |
485 | 166 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
167 while (mainScheduler->has_mail_from_host()) { |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
168 memaddr data = mainScheduler->mail_read_from_host(); |
109 | 169 |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
170 if (data == (memaddr)MY_SPE_STATUS_READY) { |
373 | 171 __debug_ppe("mail_check(): Task List finish\n"); |
808 | 172 ppeTaskList->freeAll(); |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
173 } else if (data == (memaddr)MY_SPE_COMMAND_EXIT) { |
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
638
diff
changeset
|
174 __debug_ppe("mail_check(): Task List finish COMMAND\n"); |
721 | 175 } else if (data == (memaddr)MY_SPE_COMMAND_MALLOC) { |
176 // MY_SPE_COMMAND_MALLOC PPE からのmain memory request | |
177 // 本来は呼ばれないはず... | |
736 | 178 get_scheduler()->printf("error: MY_SPE_COMMAND_MALLOC from PPE\n"); |
721 | 179 // send_alloc_reply(this, 0, mainScheduler); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
180 } else if (data != (memaddr)MY_SPE_NOP) { |
373 | 181 __debug_ppe("mail_check(): recv from 0x%x\n", data); |
619 | 182 // post_func を先に実行しないと、systask_finish が active_queue |
183 // 移されてから、wait_for されるという事態が起きることがある。 | |
830 | 184 #ifdef TASK_LIST_MAIL |
185 TaskListPtr list = (TaskListPtr)data; | |
186 check_task_list_finish(schedTaskManager, list, waitTaskQueue); | |
187 #else | |
619 | 188 HTaskPtr task = (HTaskPtr)data; |
189 task->post_func(schedTaskManager, task->post_arg1, task->post_arg2); | |
719
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
190 check_task_finish(task, waitTaskQueue); |
830 | 191 #endif |
373 | 192 } |
109 | 193 } |
3 | 194 } |
195 | |
833
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
196 void |
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
197 FifoTaskManagerImpl::polling() |
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
198 { |
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
199 if (others!=0) |
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
200 others->polling(); |
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
201 } |
373 | 202 |
1067 | 203 void |
204 FifoTaskManagerImpl::print_arch() | |
205 { | |
206 printf("FifoTaskManagerImpl\n"); | |
207 } | |
208 | |
109 | 209 /** |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
210 * # # # # # # # # |
109 | 211 * Abstract Factory Pattern |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
212 * # # # # # # # |
109 | 213 */ |
214 #ifdef __CERIUM_FIFO__ | |
373 | 215 TaskManagerImpl* |
3 | 216 create_impl(int num) |
217 { | |
218 return new FifoTaskManagerImpl(); | |
219 } | |
109 | 220 #endif // __CERIUM_FIFO__ |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
221 |