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