Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/TaskManagerImpl.cc @ 636:aba1600e8f83 draft
Cell Simple Task compiled. but not worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Nov 2009 19:09:40 +0900 |
parents | c56f6847fb87 |
children | 91d03774c407 |
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" | |
619 | 9 |
220 | 10 static HTaskPtr systask_start; |
109 | 11 static HTaskPtr systask_finish; |
42 | 12 |
550 | 13 static void |
14 noaction(SchedTask *s, void *read, void *write) | |
3 | 15 { |
16 } | |
17 | |
109 | 18 TaskManagerImpl::TaskManagerImpl(int num) |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
19 : machineNum(num) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
20 activeTaskQueue = new HTaskInfo(); |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
21 waitTaskQueue = new HTaskInfo(); |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
22 htaskImpl = waitTaskQueue ; // any HTaskInfo |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
23 taskQueueImpl = new TaskQueueInfo(); |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
24 } |
50 | 25 |
220 | 26 /** |
298 | 27 * 一番最初に PPE で実行される systask_start |
220 | 28 */ |
42 | 29 void |
499 | 30 TaskManagerImpl::systask_init() |
42 | 31 { |
109 | 32 systask_register(); |
42 | 33 |
634 | 34 systask_start = create_task(StartTask); |
35 systask_finish = create_task(FinishTask); | |
220 | 36 |
37 systask_start->spawn(); | |
38 | |
634 | 39 // すべての Task が FinishTask を wait_for すると、 |
40 // あらゆる Task が FinishTask の waiting task queue を操作する | |
41 // ことになる。それは、重すぎる。PPE/SPE Task が終了した時点で、 | |
42 // TaskManager が実行する方が安い。 | |
43 // append_waitTask(systask_finish); | |
44 } | |
45 | |
46 HTaskPtr | |
636
aba1600e8f83
Cell Simple Task compiled. but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
635
diff
changeset
|
47 TaskManagerImpl::create_task(int cmd,memaddr rbuf, long r_size, memaddr wbuf, long w_size) |
634 | 48 { |
49 HTaskPtr new_task; | |
50 | |
51 new_task = htaskImpl->create(cmd, rbuf, r_size, wbuf, w_size); | |
52 new_task->post_func = noaction; | |
53 new_task->mimpl = this; | |
54 | |
55 return new_task; | |
42 | 56 } |
57 | |
3 | 58 HTaskPtr |
109 | 59 TaskManagerImpl::create_task(int cmd) |
3 | 60 { |
61 HTaskPtr new_task; | |
62 | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
63 new_task = htaskImpl->create(cmd); |
109 | 64 new_task->post_func = noaction; |
63 | 65 new_task->mimpl = this; |
66 | |
3 | 67 return new_task; |
68 } | |
69 | |
70 /** | |
298 | 71 * task の依存関係を設定 |
72 * master task が終わってから、slave task を実行するように | |
109 | 73 * master->wait_for(slave); |
3 | 74 */ |
75 void | |
76 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) | |
547 | 77 { |
3 | 78 TaskQueuePtr m, s; |
547 | 79 |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
80 m = taskQueueImpl->create(master); |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
81 s = taskQueueImpl->create(slave); |
547 | 82 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
83 master->wait_me->addLast(s); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
84 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
|
85 s->waiter = m; |
547 | 86 } |
87 | |
3 | 88 /** |
298 | 89 * タスクを実行可能キューまたは待機キューへ追加する。 |
90 * 依存関係が満たされていれば active, まだだったら wait へ。 | |
109 | 91 * task->spawn(); |
92 */ | |
3 | 93 void |
18 | 94 TaskManagerImpl::spawn_task(HTaskPtr task) |
3 | 95 { |
109 | 96 // waiter // master |
97 // waitee // slave | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
98 if (task->wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
99 append_activeTask(task); |
3 | 100 } else { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
101 append_waitTask(task); |
3 | 102 } |
109 | 103 |
635
c56f6847fb87
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
104 // systask_finish->wait_for(task); |
3 | 105 } |
42 | 106 |
109 | 107 /** |
298 | 108 * Task を実行可能キューに追加する |
109 | 109 */ |
110 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
111 TaskManagerImpl::append_activeTask(HTaskPtr q) |
109 | 112 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
113 activeTaskQueue->addLast(q); |
109 | 114 } |
115 | |
116 /** | |
298 | 117 * タスクが実行する CPU を選択する |
109 | 118 * |
298 | 119 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 |
120 * types.h に書いてます。 | |
109 | 121 */ |
65 | 122 void |
123 TaskManagerImpl::set_task_cpu(HTaskPtr task, CPU_TYPE type) | |
124 { | |
125 task->cpu_type = type; | |
126 } | |
127 | |
109 | 128 /** |
298 | 129 * 終了したタスクから依存の処理とか |
130 * post_func() はこのタスクが終了したら実行する関数。 | |
109 | 131 * |
298 | 132 * @param [task] 終了したタスク |
109 | 133 */ |
134 void | |
497 | 135 TaskManagerImpl::check_task_finish(HTaskPtr me) |
42 | 136 { |
499 | 137 |
497 | 138 while(TaskQueue *p = me->wait_me->poll()) { |
499 | 139 HTaskPtr you = p->task; |
497 | 140 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
|
141 // 相手の wait queue から自分(を指しているTaskQueue)を削除 |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
142 wait_i->remove(p->waiter); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
143 // queue を free する |
493 | 144 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
|
145 |
497 | 146 if (wait_i->empty()) { |
499 | 147 waitTaskQueue->remove(you); |
148 append_activeTask(you); | |
497 | 149 } |
150 | |
493 | 151 wait_i->free_(p); |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
152 } |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
153 |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
154 htaskImpl->free_(me); |
109 | 155 } |
42 | 156 |
109 | 157 |
158 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
159 TaskManagerImpl::append_waitTask(HTaskPtr q) |
109 | 160 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
161 waitTaskQueue ->addLast(q); |
109 | 162 } |
163 | |
164 /** | |
298 | 165 * waitQueue の中で依存関係を満たしたタスクは |
166 * activeQueue へ移す | |
109 | 167 */ |
168 void | |
499 | 169 TaskManagerImpl::wakeup_waitTask() |
109 | 170 { |
497 | 171 // done in check_task_finish |
109 | 172 } |
54 | 173 |
619 | 174 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
175 /* end */ |