Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/TaskManagerImpl.cc @ 498:bce667ff20b9 draft
double linked HTaskInfo/HTask
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 11 Oct 2009 11:46:41 +0900 |
parents | 3429986b8a28 |
children | 981aa2f89a80 |
rev | line source |
---|---|
5 | 1 #include <stdio.h> |
3 | 2 #include "TaskManagerImpl.h" |
46 | 3 #include "types.h" |
4 #include "error.h" | |
109 | 5 #include "../sys_task/SysTask.h" |
6 | |
220 | 7 static HTaskPtr systask_start; |
109 | 8 static HTaskPtr systask_finish; |
42 | 9 |
3 | 10 void |
109 | 11 noaction(void *p) |
3 | 12 { |
13 } | |
14 | |
109 | 15 TaskManagerImpl::TaskManagerImpl(int num) |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
16 : machineNum(num) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
17 activeTaskQueue = new HTaskInfo(); |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
18 waitTaskQueue = new HTaskInfo(); |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
19 htaskImpl = waitTaskQueue ; // any HTaskInfo |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
20 taskQueueImpl = new TaskQueueInfo(); |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
21 } |
50 | 22 |
220 | 23 /** |
298 | 24 * 一番最初に PPE で実行される systask_start |
25 * 一番最後に、全てのタスクの終了を待つ systask_finish | |
26 * 番兵的な意味で実装 | |
220 | 27 */ |
42 | 28 void |
109 | 29 TaskManagerImpl::systask_init(void) |
42 | 30 { |
109 | 31 systask_register(); |
42 | 32 |
220 | 33 systask_start = create_task(SYSTASK_START); |
109 | 34 systask_finish = create_task(SYSTASK_FINISH); |
220 | 35 |
36 systask_start->spawn(); | |
37 | |
298 | 38 // systask_finish で spawn すると |
220 | 39 // systask_finish->wait_for(systask_finish); |
298 | 40 // とかなって無限ループになるので、 |
41 // これだけは明示的に append_waitTask() で | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
42 append_waitTask(systask_start); |
42 | 43 } |
44 | |
3 | 45 HTaskPtr |
109 | 46 TaskManagerImpl::create_task(int cmd) |
3 | 47 { |
48 HTaskPtr new_task; | |
49 | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
50 new_task = htaskImpl->create(cmd); |
109 | 51 new_task->post_func = noaction; |
63 | 52 new_task->mimpl = this; |
53 | |
3 | 54 return new_task; |
55 } | |
56 | |
57 /** | |
298 | 58 * task の依存関係を設定 |
59 * master task が終わってから、slave task を実行するように | |
109 | 60 * master->wait_for(slave); |
3 | 61 */ |
62 void | |
63 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) | |
64 { | |
65 TaskQueuePtr m, s; | |
66 | |
475
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
67 m = taskQueueImpl->create(master); |
4e0308d2ba73
BufferManager removed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
68 s = taskQueueImpl->create(slave); |
3 | 69 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
70 master->wait_me->addLast(s); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
71 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
|
72 s->waiter = m; |
3 | 73 } |
74 | |
109 | 75 /** |
298 | 76 * タスクを実行可能キューまたは待機キューへ追加する。 |
77 * 依存関係が満たされていれば active, まだだったら wait へ。 | |
109 | 78 * task->spawn(); |
79 */ | |
3 | 80 void |
18 | 81 TaskManagerImpl::spawn_task(HTaskPtr task) |
3 | 82 { |
109 | 83 // waiter // master |
84 // waitee // slave | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
85 if (task->wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
86 append_activeTask(task); |
3 | 87 } else { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
88 append_waitTask(task); |
3 | 89 } |
109 | 90 |
91 systask_finish->wait_for(task); | |
3 | 92 } |
42 | 93 |
109 | 94 /** |
298 | 95 * Task を実行可能キューに追加する |
109 | 96 */ |
97 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
98 TaskManagerImpl::append_activeTask(HTaskPtr q) |
109 | 99 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
100 activeTaskQueue->addLast(q); |
109 | 101 } |
102 | |
103 /** | |
298 | 104 * タスクが実行する CPU を選択する |
109 | 105 * |
298 | 106 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 |
107 * types.h に書いてます。 | |
109 | 108 */ |
65 | 109 void |
110 TaskManagerImpl::set_task_cpu(HTaskPtr task, CPU_TYPE type) | |
111 { | |
112 task->cpu_type = type; | |
113 } | |
114 | |
109 | 115 /** |
298 | 116 * 終了したタスクから依存の処理とか |
117 * post_func() はこのタスクが終了したら実行する関数。 | |
109 | 118 * |
298 | 119 * @param [task] 終了したタスク |
109 | 120 */ |
121 void | |
497 | 122 TaskManagerImpl::check_task_finish(HTaskPtr me) |
42 | 123 { |
497 | 124 while(TaskQueue *p = me->wait_me->poll()) { |
125 HTaskPtr you = (HTaskPtr)p->task; | |
126 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
|
127 // 相手の wait queue から自分(を指しているTaskQueue)を削除 |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
128 wait_i->remove(p->waiter); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
129 // queue を free する |
493 | 130 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
|
131 |
497 | 132 if (wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
133 waitTaskQueue->remove((HTaskPtr)you->task); |
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
134 append_activeTask((HTaskPtr)you->task); |
497 | 135 } |
136 | |
493 | 137 wait_i->free_(p); |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
138 } |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
139 |
497 | 140 me->post_func(me->post_arg); |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
141 htaskImpl->free_(me); |
109 | 142 } |
42 | 143 |
109 | 144 |
145 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
146 TaskManagerImpl::append_waitTask(HTaskPtr q) |
109 | 147 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
148 waitTaskQueue ->addLast(q); |
109 | 149 } |
150 | |
151 /** | |
298 | 152 * waitQueue の中で依存関係を満たしたタスクは |
153 * activeQueue へ移す | |
109 | 154 */ |
155 void | |
156 TaskManagerImpl::wakeup_waitTask(void) | |
157 { | |
497 | 158 // done in check_task_finish |
109 | 159 } |
54 | 160 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
161 /* end */ |