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