Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Fifo/FifoTaskManagerImpl.cc @ 491:7cd207691af1
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 06 Oct 2009 17:14:05 +0900 |
parents | bfbad00ed9be |
children | 9522c376a9fe |
rev | line source |
---|---|
3 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "FifoTaskManagerImpl.h" | |
373 | 5 #include "Scheduler.h" |
47 | 6 #include "types.h" |
109 | 7 #include "error.h" |
3 | 8 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
9 FifoTaskManagerImpl::~FifoTaskManagerImpl() |
109 | 10 { |
11 delete mailManager; | |
12 delete scheduler; | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
13 |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
14 delete taskListImpl ; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
15 delete taskQueueImpl ; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
16 delete htaskImpl ; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
17 |
109 | 18 } |
19 | |
20 /** | |
321 | 21 * MailManager は PPE スケジューラとのメール交換、 |
22 * FifoScheduler は PPE 側のスケジューラ | |
23 * BufferManager は Task、TaskList などのメモリ管理(大層なことしてないが | |
109 | 24 */ |
3 | 25 void |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
26 FifoTaskManagerImpl::init() |
3 | 27 { |
109 | 28 mailManager = new MailManager(); |
29 mailManager->init(20); | |
30 | |
31 scheduler = new MainScheduler(); | |
32 scheduler->init(); | |
33 scheduler->set_mailManager(mailManager); | |
194 | 34 scheduler->id = 0; |
42 | 35 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
36 taskListImpl = new TaskListInfo; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
37 taskQueueImpl = new TaskQueueInfo; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
38 htaskImpl = new HTaskInfo; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
39 |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
40 taskQueueImpl->init(TASK_MAX_SIZE*4); |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
41 htaskImpl->init(TASK_MAX_SIZE*2); |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
42 |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
43 mainTaskList = taskListImpl->create(); |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
44 |
109 | 45 } |
46 | |
47 /** | |
321 | 48 * これは CellTaskManagerImpl から呼ばれる。 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
49 * TaskList等 は共用で使うので引数に。 |
321 | 50 * CellTaskManagerImpl と FifoTaskManagerImpl が同時に |
373 | 51 * 上のデータにアクセスする事は(今は)ないのでこれでおk |
109 | 52 */ |
53 void | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
54 FifoTaskManagerImpl::init(MainScheduler *_sched, TaskManagerImpl *tm) |
109 | 55 { |
56 mailManager = new MailManager(); | |
57 mailManager->init(20); | |
58 | |
59 //scheduler = new MainScheduler(); | |
60 scheduler = _sched; | |
61 scheduler->init(); | |
62 scheduler->set_mailManager(mailManager); | |
63 | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
64 taskListImpl = tm-> taskListImpl ; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
65 taskQueueImpl = tm-> taskQueueImpl ; |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
66 htaskImpl = tm-> htaskImpl ; |
485 | 67 waitTaskQueue = NULL; // mail_check で外から設定される |
486
bfbad00ed9be
activeTaskQueue on Fifo is necessary on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
485
diff
changeset
|
68 // waitTaskQueue = tm->waitTaskQueue; |
bfbad00ed9be
activeTaskQueue on Fifo is necessary on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
485
diff
changeset
|
69 // activeTaskQueue = NULL; // CellTaskManagerImple 側を使う |
485 | 70 |
71 // waitTaskQueue = tm->waitTaskQueue; | |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
72 // activeQueue は? |
109 | 73 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
74 mainTaskList = taskListImpl->create(); |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
75 |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
76 |
109 | 77 } |
78 | |
79 /** | |
321 | 80 * スケジューラに渡す TaskList を取得する。 |
109 | 81 * |
321 | 82 * @return 実行タスクリスト |
109 | 83 * |
321 | 84 * ActiveTaskQueue (依存条件は満たし済み) のタスクを |
85 * 実行タスクリストに入れる | |
109 | 86 */ |
87 TaskListPtr | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
88 FifoTaskManagerImpl::get_runTaskList() |
109 | 89 { |
90 TaskListPtr list, list_top; | |
321 | 91 HTaskPtr htask; // HTask (PPE にある) |
92 TaskPtr task; // Task (SPE に送る Task) | |
109 | 93 |
480
46464727d825
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
94 if (activeTaskQueue->empty()) { |
373 | 95 return NULL; |
109 | 96 } |
97 | |
321 | 98 // PPE 側で実行される TaskList |
109 | 99 list_top = mainTaskList; |
100 | |
321 | 101 // list_top->clear() とかの方がいいかもしれん。 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
102 list_top = taskListImpl->clear_taskList(list_top); |
109 | 103 list = list_top; |
104 | |
480
46464727d825
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
105 while (TaskQueuePtr queue = activeTaskQueue->poll()) { |
373 | 106 htask = (HTaskPtr)queue->task; |
109 | 107 |
373 | 108 task = &list->tasks[list->length++]; |
491 | 109 #if 1 |
110 task->command = htask->command; | |
111 task->inData = htask->inData; | |
112 task->outData = htask->outData; | |
113 task->self = (unsigned int)htask; | |
114 #else | |
115 memcpy(task, (Task*)htask, sizeof(Task)); | |
116 #endif | |
109 | 117 |
118 | |
373 | 119 if (list->length >= TASK_MAX_SIZE) { |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
120 TaskListPtr newList = taskListImpl->create(); |
373 | 121 list_top = TaskListInfo::append(list_top, newList); |
122 list = newList; | |
123 } | |
109 | 124 |
481
4896dffad67c
Double linked list modification done (tested on Mac OS X)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
480
diff
changeset
|
125 activeTaskQueue->free(queue); |
109 | 126 } |
127 | |
128 mainTaskList = list_top; | |
129 | |
130 return list_top; | |
131 } | |
132 | |
133 | |
134 void | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
135 FifoTaskManagerImpl::run() |
109 | 136 { |
137 TaskListPtr list; | |
138 MailQueuePtr mail; | |
139 | |
140 list = get_runTaskList(); | |
141 | |
142 do { | |
373 | 143 // list を実行する |
144 mail = schedule(list); | |
109 | 145 |
373 | 146 // mail には、ppe scheduler からの mail がある |
147 mail_check(mail); | |
109 | 148 |
373 | 149 // 依存関係を満たしたものは実行可能キューへ |
150 wakeup_waitTask(); | |
151 list = get_runTaskList(); | |
109 | 152 } while (list); |
153 } | |
154 | |
155 /** | |
321 | 156 * @param [list] 実行タスクリスト |
157 * @return FifoScheduler からのメール | |
109 | 158 * |
321 | 159 * [Tasklist] -> [番兵] -> scheduler->run を抜ける |
109 | 160 */ |
161 MailQueuePtr | |
162 FifoTaskManagerImpl::schedule(TaskListPtr list) | |
163 { | |
164 MailQueuePtr list_mail; // task list | |
321 | 165 MailQueuePtr sentinel; // 番兵 |
109 | 166 MailQueuePtr in_mail_list = NULL; |
167 MailQueuePtr out_mail_list = NULL; | |
168 | |
321 | 169 // TaskList のアドレス |
373 | 170 list_mail = mailManager->create((unsigned int)list); |
109 | 171 in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail); |
172 | |
321 | 173 // EXIT_COMMAND (番兵的な意味で) |
109 | 174 sentinel = mailManager->create(MY_SPE_COMMAND_EXIT); |
175 in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel); | |
373 | 176 |
321 | 177 // scheduler は受け取ったメールを元に実行する |
109 | 178 scheduler->send_mailList(in_mail_list); |
179 scheduler->run(); | |
373 | 180 out_mail_list = scheduler->recv_mailList(); |
109 | 181 |
182 return out_mail_list; | |
183 } | |
184 | |
185 /** | |
321 | 186 * PPE Scheduler からのメールをチェックする |
109 | 187 * |
188 * @param [mail_list] | |
321 | 189 * PPE 側で動く Scheduler からのメールリスト |
190 * 終了した Task や、その他(今はまだ実装してないけど)の情報が入ってる | |
109 | 191 * |
373 | 192 * @return Scheduler が次に実行する Task List |
321 | 193 * NULL なら全てのタスクが実行終了したということ |
109 | 194 */ |
195 void | |
485 | 196 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueueInfo *waitQueue) |
197 { | |
198 waitTaskQueue = waitQueue; | |
199 mail_check(mail_list); | |
200 } | |
201 | |
202 void | |
109 | 203 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list) |
204 { | |
205 MailQueuePtr q = mail_list; | |
206 MailQueuePtr d; | |
207 unsigned int data; | |
208 | |
209 while (q) { | |
373 | 210 data = q->data; |
109 | 211 |
373 | 212 /** |
213 * MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了 | |
214 * MY_SPE_NOP: 特に意味のないコマンド | |
215 * それ以外:終了したタスク(PPEにあるのでアドレス | |
216 * | |
217 * MY_SPE_NOP が 0 なので、 | |
218 * 下のように data > MY_SPE_NOP とかしています。 | |
219 * 一目でよくわからない書き方なんで、直したいところですが。。。 | |
220 */ | |
221 if (data == MY_SPE_STATUS_READY) { | |
222 __debug_ppe("mail_check(): Task List finish\n"); | |
223 } else if (data > MY_SPE_NOP) { | |
224 __debug_ppe("mail_check(): recv from 0x%x\n", data); | |
225 check_task_finish((HTaskPtr)data); | |
226 } | |
109 | 227 |
373 | 228 d = q; |
229 q = q->next; | |
109 | 230 |
373 | 231 mailManager->free(d); |
109 | 232 } |
3 | 233 } |
234 | |
109 | 235 void* |
236 FifoTaskManagerImpl::allocate(int size) | |
237 { | |
238 return malloc(size); | |
239 } | |
240 | |
373 | 241 Scheduler* |
242 FifoTaskManagerImpl::get_scheduler() { | |
243 return scheduler; | |
244 } | |
245 | |
109 | 246 /** |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
247 * # # # # # # # # |
109 | 248 * Abstract Factory Pattern |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
249 * # # # # # # # |
109 | 250 */ |
251 #ifdef __CERIUM_FIFO__ | |
373 | 252 TaskManagerImpl* |
3 | 253 create_impl(int num) |
254 { | |
255 return new FifoTaskManagerImpl(); | |
256 } | |
109 | 257 #endif // __CERIUM_FIFO__ |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
258 |