Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/TaskManagerImpl.cc @ 897:6bd218d3f643 draft
add return address in SimpleTask for debugging.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 19:00:22 +0900 |
parents | 641451e6a95b |
children | aafa99c856a3 |
rev | line source |
---|---|
5 | 1 #include <stdio.h> |
3 | 2 #include "TaskManagerImpl.h" |
46 | 3 #include "types.h" |
4 #include "error.h" | |
546 | 5 #include "SchedTask.h" |
619 | 6 #include "Scheduler.h" |
634 | 7 #include "SysTask.h" |
8 #include "SysFunc.h" | |
806 | 9 #include <string.h> |
10 | |
619 | 11 |
220 | 12 static HTaskPtr systask_start; |
109 | 13 static HTaskPtr systask_finish; |
42 | 14 |
550 | 15 static void |
16 noaction(SchedTask *s, void *read, void *write) | |
3 | 17 { |
18 } | |
19 | |
835 | 20 TaskManagerImpl::TaskManagerImpl(int num) |
21 : machineNum(num){ | |
853 | 22 // 実行可能なHTaskのリスト |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
23 activeTaskQueue = new HTaskInfo(); |
853 | 24 // wait_forで止まっているHTaskのリスト。必要ないが、Dead lock detection に使う |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
25 waitTaskQueue = new HTaskInfo(); |
853 | 26 // HTask の factory. HTaskInfo ならなんでもいい。 |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
27 htaskImpl = waitTaskQueue ; // any HTaskInfo |
853 | 28 // Task の dependency を表現する double linked list. HTaskInfo とは別に必要。 |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
29 taskQueueImpl = new TaskQueueInfo(); |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
30 } |
50 | 31 |
220 | 32 /** |
298 | 33 * 一番最初に PPE で実行される systask_start |
220 | 34 */ |
42 | 35 void |
499 | 36 TaskManagerImpl::systask_init() |
42 | 37 { |
109 | 38 systask_register(); |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
39 systask_start = create_task(StartTask,0,0,0,0,__builtin_return_address(0)); |
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
40 systask_finish = create_task(FinishTask,0,0,0,0,__builtin_return_address(0)); |
220 | 41 |
42 systask_start->spawn(); | |
43 | |
634 | 44 // すべての Task が FinishTask を wait_for すると、 |
45 // あらゆる Task が FinishTask の waiting task queue を操作する | |
46 // ことになる。それは、重すぎる。PPE/SPE Task が終了した時点で、 | |
47 // TaskManager が実行する方が安い。 | |
48 // append_waitTask(systask_finish); | |
49 } | |
50 | |
51 HTaskPtr | |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
52 TaskManagerImpl::create_task(int cmd,memaddr rbuf, long r_size, memaddr wbuf, long w_size, void *from) { |
634 | 53 HTaskPtr new_task; |
54 | |
55 new_task = htaskImpl->create(cmd, rbuf, r_size, wbuf, w_size); | |
56 new_task->post_func = noaction; | |
57 new_task->mimpl = this; | |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
58 new_task->from = (memaddr)from; |
634 | 59 |
60 return new_task; | |
42 | 61 } |
62 | |
3 | 63 HTaskPtr |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
64 TaskManagerImpl::create_task(int cmd,void *from) |
3 | 65 { |
66 HTaskPtr new_task; | |
67 | |
703 | 68 // for compatibility |
69 new_task = htaskImpl->create(TaskArray1); | |
70 new_task->post_func = noaction; | |
71 new_task->mimpl = this; | |
736 | 72 new_task->create_task_array(cmd,1,8,8,8); |
713
97adb3fe85c6
remove SIMPLE_TASK conditional
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
73 // rbuf, r_size were set |
704
ec6c897448ca
Compatibility mode works.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
703
diff
changeset
|
74 new_task->command = TaskArray1; |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
75 new_task->from = (memaddr)from; |
63 | 76 |
3 | 77 return new_task; |
78 } | |
79 | |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
80 HTaskPtr |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
81 TaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData, void *from) |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
82 { |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
83 HTaskPtr ta = create_task(TaskArray,0,0,0,0, from); |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
84 ta->create_task_array(id, num_task, num_param, num_inData, num_outData) ; |
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
85 return ta; |
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
86 } |
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
87 |
3 | 88 /** |
298 | 89 * task の依存関係を設定 |
90 * master task が終わってから、slave task を実行するように | |
109 | 91 * master->wait_for(slave); |
3 | 92 */ |
93 void | |
94 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) | |
547 | 95 { |
3 | 96 TaskQueuePtr m, s; |
547 | 97 |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
98 m = taskQueueImpl->create(master); |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
99 s = taskQueueImpl->create(slave); |
547 | 100 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
101 master->wait_me->addLast(s); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
102 slave->wait_i->addLast(m); |
481
f9ffcffb6d09
Double linked list modification done (tested on Mac OS X)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
480
diff
changeset
|
103 s->waiter = m; |
547 | 104 } |
105 | |
3 | 106 /** |
298 | 107 * タスクを実行可能キューまたは待機キューへ追加する。 |
108 * 依存関係が満たされていれば active, まだだったら wait へ。 | |
109 | 109 * task->spawn(); |
110 */ | |
3 | 111 void |
18 | 112 TaskManagerImpl::spawn_task(HTaskPtr task) |
3 | 113 { |
109 | 114 // waiter // master |
115 // waitee // slave | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
116 if (task->wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
117 append_activeTask(task); |
3 | 118 } else { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
119 append_waitTask(task); |
3 | 120 } |
109 | 121 |
635
c56f6847fb87
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
122 // systask_finish->wait_for(task); |
3 | 123 } |
42 | 124 |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
125 |
109 | 126 /** |
298 | 127 * Task を実行可能キューに追加する |
109 | 128 */ |
129 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
130 TaskManagerImpl::append_activeTask(HTaskPtr q) |
109 | 131 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
132 activeTaskQueue->addLast(q); |
109 | 133 } |
134 | |
135 /** | |
298 | 136 * タスクが実行する CPU を選択する |
109 | 137 * |
298 | 138 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 |
139 * types.h に書いてます。 | |
109 | 140 */ |
65 | 141 void |
142 TaskManagerImpl::set_task_cpu(HTaskPtr task, CPU_TYPE type) | |
143 { | |
664 | 144 if (machineNum==0) |
145 task->cpu_type = CPU_PPE ; | |
146 else | |
147 task->cpu_type = type; | |
65 | 148 } |
149 | |
109 | 150 /** |
830 | 151 * @brief 終了したタスクから依存の処理とか |
298 | 152 * post_func() はこのタスクが終了したら実行する関数。 |
109 | 153 * |
298 | 154 * @param [task] 終了したタスク |
109 | 155 */ |
156 void | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
639
diff
changeset
|
157 TaskManagerImpl::check_task_finish(HTaskPtr me, HTaskInfo *wait_queue) |
42 | 158 { |
499 | 159 |
497 | 160 while(TaskQueue *p = me->wait_me->poll()) { |
499 | 161 HTaskPtr you = p->task; |
497 | 162 TaskQueueInfo *wait_i = you->wait_i; |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
163 // 相手の wait queue から自分(を指しているTaskQueue)を削除 |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
164 wait_i->remove(p->waiter); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
165 // queue を free する |
493 | 166 wait_i->free_(p->waiter); |
483
5f4ffff2c2aa
renew task worked. but not test_nogl...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
481
diff
changeset
|
167 |
497 | 168 if (wait_i->empty()) { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
639
diff
changeset
|
169 wait_queue->remove(you); |
499 | 170 append_activeTask(you); |
497 | 171 } |
172 | |
493 | 173 wait_i->free_(p); |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
174 } |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
175 |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
176 htaskImpl->free_(me); |
109 | 177 } |
42 | 178 |
830 | 179 /** |
180 * @brief 終了したタスクリストの依存の処理 | |
181 * @param [task] 終了したタスク | |
182 */ | |
183 void | |
184 TaskManagerImpl::check_task_list_finish(SchedTask *s, TaskListPtr list, HTaskInfo *wait_queue) | |
185 { | |
855 | 186 for(int i = 0;i<list->length;i++) { |
831
b3c004fe6bc3
CheckTaskList Mail working
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
187 SimpleTaskPtr task = &list->tasks[i]; |
830 | 188 HTask *me = (HTask*)task->self; |
189 me->post_func(s, me->post_arg1, me->post_arg2); | |
190 if (task->command==TaskArray1) { | |
831
b3c004fe6bc3
CheckTaskList Mail working
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
191 int next = ((task->r_size)/sizeof(SimpleTask))+1; |
830 | 192 // assert(next<list->length); |
193 i+=next; | |
194 } | |
833
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
831
diff
changeset
|
195 s->polling(); |
830 | 196 check_task_finish(me, wait_queue); |
197 } | |
198 } | |
109 | 199 |
830 | 200 /** |
201 * @brief waitTaskqueue への挿入 。必須ではない。 | |
202 * 現状では、dead lock 検出にしか使ってない | |
203 * | |
204 * @param [task] 終了したタスク | |
205 */ | |
109 | 206 void |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
207 TaskManagerImpl::append_waitTask(HTaskPtr q) |
109 | 208 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
209 waitTaskQueue ->addLast(q); |
109 | 210 } |
211 | |
830 | 212 /** |
213 @brief htask を DMA でCPUに渡すための TaskList に入れる (copy) | |
214 @param htask | |
215 @param taskList | |
216 TaskList は自動的に延長される | |
217 */ | |
806 | 218 void |
219 TaskManagerImpl::set_taskList(HTaskPtr htask, TaskListInfoPtr taskList) { | |
809 | 220 TaskListPtr list ; |
221 if ( taskList->empty() ) { | |
222 list = taskList->create(); | |
223 taskList->addLast(list); | |
224 } else | |
225 list = taskList->getLast(); | |
806 | 226 SimpleTaskPtr task = &list->tasks[list->length++]; |
227 if (htask->command==TaskArray1) { | |
228 // compatibility | |
229 int next = ((htask->r_size)/sizeof(SimpleTask))+1; | |
230 if (list->length+next>=TASK_MAX_SIZE) { | |
231 list->length--; | |
809 | 232 TaskListPtr newList = taskList->create(); |
806 | 233 taskList->addLast(newList); |
234 list = newList; | |
235 task = &list->tasks[list->length++]; | |
236 } | |
237 Task *array = (Task*)&list->tasks[list->length]; | |
238 list->length += next; | |
239 if (list->length>=TASK_MAX_SIZE) { | |
240 perror("task array1 overflow\n"); | |
241 } | |
242 memcpy(array, htask->rbuf, htask->r_size); | |
243 free(htask->rbuf); | |
831
b3c004fe6bc3
CheckTaskList Mail working
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
244 // htask->rbuf = 0; htask->r_size = 0; we need this... |
806 | 245 *task = *(SimpleTask*)htask; |
246 } else { | |
247 *task = *(SimpleTask*)htask; | |
248 } | |
249 if (list->length >= TASK_MAX_SIZE) { | |
809 | 250 TaskListPtr newList = taskList->create(); |
806 | 251 taskList->addLast(newList); |
252 list = newList; | |
253 } | |
254 } | |
255 | |
54 | 256 |
619 | 257 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
258 /* end */ |