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