Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Fifo/FifoTaskManagerImpl.cc @ 475:e083c4ff91c1
BufferManager removed.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 04 Oct 2009 11:29:50 +0900 |
parents | eab18aa0c7f6 |
children | 5bda98b0b56d |
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 ; |
109 | 69 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
70 mainTaskList = taskListImpl->create(); |
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
71 |
109 | 72 } |
73 | |
74 /** | |
321 | 75 * スケジューラに渡す TaskList を取得する。 |
109 | 76 * |
321 | 77 * @return 実行タスクリスト |
109 | 78 * |
321 | 79 * ActiveTaskQueue (依存条件は満たし済み) のタスクを |
80 * 実行タスクリストに入れる | |
109 | 81 */ |
82 TaskListPtr | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
83 FifoTaskManagerImpl::get_runTaskList() |
109 | 84 { |
85 TaskListPtr list, list_top; | |
86 TaskQueuePtr queue; | |
87 TaskQueuePtr d; | |
321 | 88 HTaskPtr htask; // HTask (PPE にある) |
89 TaskPtr task; // Task (SPE に送る Task) | |
109 | 90 |
91 queue = activeTaskQueue; | |
92 if (queue == NULL) { | |
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 | |
103 while (queue) { | |
373 | 104 htask = (HTaskPtr)queue->task; |
105 d = queue; | |
106 queue = queue->next; | |
109 | 107 |
373 | 108 task = &list->tasks[list->length++]; |
109 | 109 |
373 | 110 memcpy(task, htask, sizeof(Task)); |
109 | 111 |
373 | 112 if (list->length >= TASK_MAX_SIZE) { |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
113 TaskListPtr newList = taskListImpl->create(); |
373 | 114 list_top = TaskListInfo::append(list_top, newList); |
115 list = newList; | |
116 } | |
109 | 117 |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
118 taskQueueImpl->free(d); |
109 | 119 } |
120 | |
121 activeTaskQueue = NULL; | |
122 mainTaskList = list_top; | |
123 | |
124 return list_top; | |
125 } | |
126 | |
127 | |
128 void | |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
129 FifoTaskManagerImpl::run() |
109 | 130 { |
131 TaskListPtr list; | |
132 MailQueuePtr mail; | |
133 | |
134 list = get_runTaskList(); | |
135 | |
136 do { | |
373 | 137 // list を実行する |
138 mail = schedule(list); | |
109 | 139 |
373 | 140 // mail には、ppe scheduler からの mail がある |
141 mail_check(mail); | |
109 | 142 |
373 | 143 // 依存関係を満たしたものは実行可能キューへ |
144 wakeup_waitTask(); | |
145 list = get_runTaskList(); | |
109 | 146 } while (list); |
147 } | |
148 | |
149 /** | |
321 | 150 * @param [list] 実行タスクリスト |
151 * @return FifoScheduler からのメール | |
109 | 152 * |
321 | 153 * [Tasklist] -> [番兵] -> scheduler->run を抜ける |
109 | 154 */ |
155 MailQueuePtr | |
156 FifoTaskManagerImpl::schedule(TaskListPtr list) | |
157 { | |
158 MailQueuePtr list_mail; // task list | |
321 | 159 MailQueuePtr sentinel; // 番兵 |
109 | 160 MailQueuePtr in_mail_list = NULL; |
161 MailQueuePtr out_mail_list = NULL; | |
162 | |
321 | 163 // TaskList のアドレス |
373 | 164 list_mail = mailManager->create((unsigned int)list); |
109 | 165 in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail); |
166 | |
321 | 167 // EXIT_COMMAND (番兵的な意味で) |
109 | 168 sentinel = mailManager->create(MY_SPE_COMMAND_EXIT); |
169 in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel); | |
373 | 170 |
321 | 171 // scheduler は受け取ったメールを元に実行する |
109 | 172 scheduler->send_mailList(in_mail_list); |
173 scheduler->run(); | |
373 | 174 out_mail_list = scheduler->recv_mailList(); |
109 | 175 |
176 return out_mail_list; | |
177 } | |
178 | |
179 /** | |
321 | 180 * PPE Scheduler からのメールをチェックする |
109 | 181 * |
182 * @param [mail_list] | |
321 | 183 * PPE 側で動く Scheduler からのメールリスト |
184 * 終了した Task や、その他(今はまだ実装してないけど)の情報が入ってる | |
109 | 185 * |
373 | 186 * @return Scheduler が次に実行する Task List |
321 | 187 * NULL なら全てのタスクが実行終了したということ |
109 | 188 */ |
189 void | |
190 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list) | |
191 { | |
192 MailQueuePtr q = mail_list; | |
193 MailQueuePtr d; | |
194 unsigned int data; | |
195 | |
196 while (q) { | |
373 | 197 data = q->data; |
109 | 198 |
373 | 199 /** |
200 * MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了 | |
201 * MY_SPE_NOP: 特に意味のないコマンド | |
202 * それ以外:終了したタスク(PPEにあるのでアドレス | |
203 * | |
204 * MY_SPE_NOP が 0 なので、 | |
205 * 下のように data > MY_SPE_NOP とかしています。 | |
206 * 一目でよくわからない書き方なんで、直したいところですが。。。 | |
207 */ | |
208 if (data == MY_SPE_STATUS_READY) { | |
209 __debug_ppe("mail_check(): Task List finish\n"); | |
210 } else if (data > MY_SPE_NOP) { | |
211 __debug_ppe("mail_check(): recv from 0x%x\n", data); | |
212 check_task_finish((HTaskPtr)data); | |
213 } | |
109 | 214 |
373 | 215 d = q; |
216 q = q->next; | |
109 | 217 |
373 | 218 mailManager->free(d); |
109 | 219 } |
3 | 220 } |
221 | |
14 | 222 void |
109 | 223 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueuePtr *wait) |
14 | 224 { |
109 | 225 waitTaskQueue = *wait; |
226 mail_check(mail_list); | |
14 | 227 } |
228 | |
109 | 229 void* |
230 FifoTaskManagerImpl::allocate(int size) | |
231 { | |
232 return malloc(size); | |
233 } | |
234 | |
373 | 235 Scheduler* |
236 FifoTaskManagerImpl::get_scheduler() { | |
237 return scheduler; | |
238 } | |
239 | |
109 | 240 /** |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
241 * # # # # # # # # |
109 | 242 * Abstract Factory Pattern |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
243 * # # # # # # # |
109 | 244 */ |
245 #ifdef __CERIUM_FIFO__ | |
373 | 246 TaskManagerImpl* |
3 | 247 create_impl(int num) |
248 { | |
249 return new FifoTaskManagerImpl(); | |
250 } | |
109 | 251 #endif // __CERIUM_FIFO__ |
475
e083c4ff91c1
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
252 |