Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/TaskManagerImpl.cc @ 703:0c8ad8d99656 draft
compatibility
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 14 Dec 2009 18:34:46 +0900 |
parents | beb0f17c19f9 |
children | ec6c897448ca |
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(); |
639 | 33 #ifdef SIMPLE_TASK |
34 systask_start = create_task(StartTask,0,0,0,0); | |
35 systask_finish = create_task(FinishTask,0,0,0,0); | |
36 #else | |
634 | 37 systask_start = create_task(StartTask); |
38 systask_finish = create_task(FinishTask); | |
639 | 39 #endif |
220 | 40 |
41 systask_start->spawn(); | |
42 | |
634 | 43 // すべての Task が FinishTask を wait_for すると、 |
44 // あらゆる Task が FinishTask の waiting task queue を操作する | |
45 // ことになる。それは、重すぎる。PPE/SPE Task が終了した時点で、 | |
46 // TaskManager が実行する方が安い。 | |
47 // append_waitTask(systask_finish); | |
48 } | |
49 | |
50 HTaskPtr | |
636
aba1600e8f83
Cell Simple Task compiled. but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
635
diff
changeset
|
51 TaskManagerImpl::create_task(int cmd,memaddr rbuf, long r_size, memaddr wbuf, long w_size) |
634 | 52 { |
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; | |
58 | |
59 return new_task; | |
42 | 60 } |
61 | |
3 | 62 HTaskPtr |
109 | 63 TaskManagerImpl::create_task(int cmd) |
3 | 64 { |
65 HTaskPtr new_task; | |
66 | |
703 | 67 #ifdef SIMPLE_TASK |
68 // for compatibility | |
69 new_task = htaskImpl->create(TaskArray1); | |
70 new_task->post_func = noaction; | |
71 new_task->mimpl = this; | |
72 Task *task = new_task->create_task_array(cmd,1,8,8,8); | |
73 new_task->r_size = task->size(); | |
74 new_task->rbuf = (memaddr)task; | |
75 #else | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
76 new_task = htaskImpl->create(cmd); |
109 | 77 new_task->post_func = noaction; |
63 | 78 new_task->mimpl = this; |
703 | 79 #endif |
63 | 80 |
3 | 81 return new_task; |
82 } | |
83 | |
84 /** | |
298 | 85 * task の依存関係を設定 |
86 * master task が終わってから、slave task を実行するように | |
109 | 87 * master->wait_for(slave); |
3 | 88 */ |
89 void | |
90 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) | |
547 | 91 { |
3 | 92 TaskQueuePtr m, s; |
547 | 93 |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
94 m = taskQueueImpl->create(master); |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
95 s = taskQueueImpl->create(slave); |
547 | 96 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
97 master->wait_me->addLast(s); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
98 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
|
99 s->waiter = m; |
547 | 100 } |
101 | |
3 | 102 /** |
298 | 103 * タスクを実行可能キューまたは待機キューへ追加する。 |
104 * 依存関係が満たされていれば active, まだだったら wait へ。 | |
109 | 105 * task->spawn(); |
106 */ | |
3 | 107 void |
18 | 108 TaskManagerImpl::spawn_task(HTaskPtr task) |
3 | 109 { |
109 | 110 // waiter // master |
111 // waitee // slave | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
112 if (task->wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
113 append_activeTask(task); |
3 | 114 } else { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
115 append_waitTask(task); |
3 | 116 } |
109 | 117 |
635
c56f6847fb87
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
118 // systask_finish->wait_for(task); |
3 | 119 } |
42 | 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 /** |
298 | 146 * 終了したタスクから依存の処理とか |
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 |
109 | 174 |
175 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
176 TaskManagerImpl::append_waitTask(HTaskPtr q) |
109 | 177 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
178 waitTaskQueue ->addLast(q); |
109 | 179 } |
180 | |
181 /** | |
298 | 182 * waitQueue の中で依存関係を満たしたタスクは |
183 * activeQueue へ移す | |
109 | 184 */ |
185 void | |
499 | 186 TaskManagerImpl::wakeup_waitTask() |
109 | 187 { |
497 | 188 // done in check_task_finish |
109 | 189 } |
54 | 190 |
619 | 191 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
192 /* end */ |