Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/TaskManagerImpl.cc @ 1228:98094b0f1b01 draft
fix
author | Daichi TOMA <e085740@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 02 Aug 2011 09:55:55 +0900 |
parents | bb75ee244826 |
children | e3bd6cf5fd5a |
rev | line source |
---|---|
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1064
diff
changeset
|
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 | |
955 | 11 // singleton |
12 QueueInfo<TaskQueue> *taskQueuePool = new QueueInfo<TaskQueue>() ; | |
13 QueueInfo<HTask> *htaskPool = new QueueInfo<HTask>() ; | |
14 QueueInfo<TaskList> *taskListPool = new QueueInfo<TaskList>() ; | |
15 | |
619 | 16 |
220 | 17 static HTaskPtr systask_start; |
109 | 18 static HTaskPtr systask_finish; |
42 | 19 |
550 | 20 static void |
21 noaction(SchedTask *s, void *read, void *write) | |
3 | 22 { |
23 } | |
24 | |
835 | 25 TaskManagerImpl::TaskManagerImpl(int num) |
26 : machineNum(num){ | |
853 | 27 // 実行可能なHTaskのリスト |
955 | 28 activeTaskQueue = new QueueInfo<HTask>(htaskPool); |
853 | 29 // wait_forで止まっているHTaskのリスト。必要ないが、Dead lock detection に使う |
955 | 30 waitTaskQueue = new QueueInfo<HTask>(htaskPool); |
31 // HTask の factory. QueueInfo<HTask> ならなんでもいい。 | |
32 htaskImpl = waitTaskQueue ; // any QueueInfo<HTask> | |
33 // Task の dependency を表現する double linked list. QueueInfo<HTask> とは別に必要。 | |
34 taskQueueImpl = new QueueInfo<TaskQueue>(taskQueuePool); | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
35 } |
50 | 36 |
220 | 37 /** |
298 | 38 * 一番最初に PPE で実行される systask_start |
220 | 39 */ |
42 | 40 void |
499 | 41 TaskManagerImpl::systask_init() |
42 | 42 { |
109 | 43 systask_register(); |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
44 systask_start = create_task(StartTask,0,0,0,0,__builtin_return_address(0)); |
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
45 systask_finish = create_task(FinishTask,0,0,0,0,__builtin_return_address(0)); |
220 | 46 |
47 systask_start->spawn(); | |
48 | |
634 | 49 // すべての Task が FinishTask を wait_for すると、 |
50 // あらゆる Task が FinishTask の waiting task queue を操作する | |
51 // ことになる。それは、重すぎる。PPE/SPE Task が終了した時点で、 | |
52 // TaskManager が実行する方が安い。 | |
53 // append_waitTask(systask_finish); | |
54 } | |
55 | |
945
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
56 /** |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
57 * Create Simple Task |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
58 */ |
634 | 59 HTaskPtr |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
60 TaskManagerImpl::create_task(int cmd,memaddr rbuf, long r_size, memaddr wbuf, long w_size, void *from) { |
634 | 61 HTaskPtr new_task; |
62 | |
955 | 63 new_task = htaskImpl->create(); |
64 new_task->init(cmd, rbuf, r_size, wbuf, w_size); | |
634 | 65 new_task->post_func = noaction; |
66 new_task->mimpl = this; | |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
67 new_task->from = (memaddr)from; |
949 | 68 #ifdef EARLY_TOUCH |
69 if (rbuf) { | |
70 if ((unsigned long)rbuf&0xf) { | |
1152 | 71 printf("Data is not aligned. command = %d, addr = 0x%lx, size = %ld\n", |
949 | 72 cmd, (unsigned long)rbuf, r_size); |
73 } | |
74 char *p = (char *)rbuf; char b = *p; | |
75 p = (char *)(rbuf+r_size-1); b += *p; | |
76 } | |
77 if (wbuf) { | |
78 if ((unsigned long)wbuf&0xf) { | |
1152 | 79 printf("Data is not aligned. command = %d, addr = 0x%lx, size = %ld\n", |
949 | 80 cmd, (unsigned long)wbuf, w_size); |
81 } | |
82 char *p = (char *)wbuf; char b = *p; | |
83 p = (char *)(wbuf+w_size-1); b += *p; | |
84 } | |
85 #endif | |
634 | 86 |
87 return new_task; | |
42 | 88 } |
89 | |
945
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
90 /** |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
91 * Create Compatible Task (TaskArray1) |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
92 */ |
3 | 93 HTaskPtr |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
94 TaskManagerImpl::create_task(int cmd,void *from) |
3 | 95 { |
96 HTaskPtr new_task; | |
97 | |
703 | 98 // for compatibility |
955 | 99 new_task = htaskImpl->create(); new_task->init(TaskArray1); |
703 | 100 new_task->post_func = noaction; |
101 new_task->mimpl = this; | |
736 | 102 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
|
103 // rbuf, r_size were set |
704
ec6c897448ca
Compatibility mode works.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
703
diff
changeset
|
104 new_task->command = TaskArray1; |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
105 new_task->from = (memaddr)from; |
63 | 106 |
3 | 107 return new_task; |
108 } | |
109 | |
945
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
110 /** |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
111 * Create Task Array |
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
941
diff
changeset
|
112 */ |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
113 HTaskPtr |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
114 TaskManagerImpl::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData, void *from) |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
115 { |
897
6bd218d3f643
add return address in SimpleTask for debugging.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
855
diff
changeset
|
116 HTaskPtr ta = create_task(TaskArray,0,0,0,0, from); |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
117 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
|
118 return ta; |
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
119 } |
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
120 |
1062
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
121 /* call get_task_name from ppu only */ |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
122 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
123 TaskManagerImpl::get_task_name(int cmd) { |
1147 | 124 |
125 if (0 <= cmd && cmd < MAX_TASK_OBJECT) { | |
126 | |
127 #ifndef NOT_CHECK | |
128 | |
129 int flag = 0; | |
130 | |
131 for (int i = 0; i < MAX_TASK_OBJECT; i++) { | |
132 if (entry_cmd[i] == cmd) { | |
133 flag = 1; | |
134 break; | |
135 } | |
136 } | |
137 | |
138 if (flag == 0) { | |
139 printf("cmd %d is not registered on task_list\n", cmd); | |
140 return NULL; | |
141 } | |
142 | |
143 #endif | |
144 return task_list[cmd].name; | |
145 } | |
146 else { | |
147 return NULL; | |
148 } | |
1062
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
149 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
150 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
151 TaskManagerImpl::get_task_name(TaskPtr task) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
152 return task != NULL ? get_task_name(task->command) : NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
153 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
154 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
155 TaskManagerImpl::get_task_name(SimpleTaskPtr simple_task) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
156 return simple_task != NULL ? get_task_name(simple_task->command) : NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
157 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
158 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
159 TaskManagerImpl::get_task_name(SchedTaskBase *sched_task) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
160 if (sched_task == NULL) return NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
161 if (sched_task->task != NULL) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
162 return get_task_name(sched_task->task->command); |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
163 } else if (sched_task->atask != NULL) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
164 return get_task_name(sched_task->atask->command); |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
165 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
166 return NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
167 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
168 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
169 TaskManagerImpl::get_task_name(HTaskPtr htask) { |
1147 | 170 |
171 return get_task_name(htask, 0); | |
172 | |
1062
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
173 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
174 const char * |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
175 TaskManagerImpl::get_task_name(HTaskPtr htask, int index) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
176 if (!htask) return NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
177 switch (htask->command) { |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
178 case TaskArray1: |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
179 return get_task_name((TaskPtr)htask->rbuf); |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
180 break; |
1064
23dab670c5aa
TaskManagerImpl::get_task_name() fix in header file...
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1062
diff
changeset
|
181 case TaskArray: { |
1147 | 182 |
183 TaskPtr tmp = (TaskPtr)htask->rbuf; | |
184 return get_task_name(tmp[0].command); | |
185 | |
1064
23dab670c5aa
TaskManagerImpl::get_task_name() fix in header file...
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1062
diff
changeset
|
186 } |
1062
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
187 default: |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
188 return get_task_name(htask->command); |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
189 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
190 return NULL; |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
191 } |
f994f5032299
add TaskManagerImpl::get_task_name()
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
955
diff
changeset
|
192 |
3 | 193 /** |
298 | 194 * task の依存関係を設定 |
195 * master task が終わってから、slave task を実行するように | |
109 | 196 * master->wait_for(slave); |
3 | 197 */ |
198 void | |
199 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) | |
547 | 200 { |
3 | 201 TaskQueuePtr m, s; |
941
fc6cfaae6de7
add no_auto_free flag on HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
940
diff
changeset
|
202 if (!master->self) return; |
547 | 203 |
955 | 204 m = taskQueueImpl->create(); m->init(master); |
205 s = taskQueueImpl->create(); s->init(slave); | |
547 | 206 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
207 master->wait_me->addLast(s); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
208 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
|
209 s->waiter = m; |
547 | 210 } |
211 | |
3 | 212 /** |
298 | 213 * タスクを実行可能キューまたは待機キューへ追加する。 |
214 * 依存関係が満たされていれば active, まだだったら wait へ。 | |
109 | 215 * task->spawn(); |
216 */ | |
3 | 217 void |
18 | 218 TaskManagerImpl::spawn_task(HTaskPtr task) |
3 | 219 { |
109 | 220 // waiter // master |
221 // waitee // slave | |
480
75e4afa40da2
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
222 if (task->wait_i->empty()) { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
223 append_activeTask(task); |
3 | 224 } else { |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
225 append_waitTask(task); |
3 | 226 } |
227 } | |
42 | 228 |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
736
diff
changeset
|
229 |
109 | 230 /** |
298 | 231 * Task を実行可能キューに追加する |
109 | 232 */ |
233 void | |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
234 TaskManagerImpl::append_activeTask(HTaskPtr q) |
109 | 235 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
236 activeTaskQueue->addLast(q); |
109 | 237 } |
238 | |
239 /** | |
298 | 240 * タスクが実行する CPU を選択する |
109 | 241 * |
298 | 242 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 |
243 * types.h に書いてます。 | |
109 | 244 */ |
65 | 245 void |
246 TaskManagerImpl::set_task_cpu(HTaskPtr task, CPU_TYPE type) | |
247 { | |
664 | 248 if (machineNum==0) |
249 task->cpu_type = CPU_PPE ; | |
250 else | |
251 task->cpu_type = type; | |
65 | 252 } |
253 | |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
254 #if 0 |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
255 static void |
955 | 256 check_wait(TaskManagerImpl *tm, QueueInfo<TaskQueue> *wait_i) { |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
257 for(TaskQueue *t = wait_i->getFirst(); t; t = wait_i->getNext(t)) { |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
258 if (!tm->waitTaskQueue->find(t->task)) { |
1152 | 259 //this->printf("stray waiting task%d %lx\n",t->task->command, (long)t->task); |
260 printf("stray waiting task%d %lx\n",t->task->command, (long)t->task); | |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
261 } else if (tm->activeTaskQueue->find(t->task)) { |
1152 | 262 //this->printf(" active task%d in waiting queue %lx\n",t->task->command, (long)t->task); |
263 printf(" active task%d in waiting queue %lx\n",t->task->command, (long)t->task); | |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
264 } else |
1152 | 265 printf("."); |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
266 } |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
267 } |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
268 #endif |
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
269 |
109 | 270 /** |
830 | 271 * @brief 終了したタスクから依存の処理とか |
298 | 272 * post_func() はこのタスクが終了したら実行する関数。 |
109 | 273 * |
298 | 274 * @param [task] 終了したタスク |
109 | 275 */ |
276 void | |
955 | 277 TaskManagerImpl::check_task_finish(HTaskPtr me, QueueInfo<HTask> *wait_queue) |
42 | 278 { |
497 | 279 while(TaskQueue *p = me->wait_me->poll()) { |
499 | 280 HTaskPtr you = p->task; |
955 | 281 QueueInfo<TaskQueue> *wait_i = you->wait_i; |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
282 // 相手の wait queue から自分(を指しているTaskQueue)を削除 |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
283 wait_i->remove(p->waiter); |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
284 // queue を free する |
493 | 285 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
|
286 |
497 | 287 if (wait_i->empty()) { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
639
diff
changeset
|
288 wait_queue->remove(you); |
499 | 289 append_activeTask(you); |
497 | 290 } |
291 | |
940
e01b551f25d6
unknown dead lock still...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
939
diff
changeset
|
292 wait_i->free_(p); // p->wait_i, p->wait_me は再利用される |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
293 } |
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
294 |
1169 | 295 // TaskArray1 の場合、Task,rbuf共にtasklistに入る。 |
296 // tasklistはどこかでfreeされてるはずなので、メモリリークしない。 | |
297 // TaskArray の rbuf はfreeされない見たいなので、ここでfreeしてみる。 | |
1227
bb75ee244826
exile free on fifo
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1169
diff
changeset
|
298 |
1228 | 299 |
300 //;TODO | |
301 //ReferencedDmaManagerを使う場合ここでfreeすると、wordcountが動かない | |
302 // if (me->command == TaskArray) { | |
303 // free(me->rbuf); | |
304 // } | |
1169 | 305 |
939 | 306 // me を誰かが持っていて、me が finish した後に、 |
307 // me->wait_for(i) とか、やられると気まずい。 | |
308 // 特に、me が他人に再利用されていると。そういう時には、 | |
309 // このfreeをコメントアウトしてみる。 | |
310 | |
311 // id かななんかでチェックした方が良いが... | |
312 | |
313 me->self = 0; | |
941
fc6cfaae6de7
add no_auto_free flag on HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
940
diff
changeset
|
314 if (!me->flag.no_auto_free) |
fc6cfaae6de7
add no_auto_free flag on HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
940
diff
changeset
|
315 htaskImpl->free_(me); |
109 | 316 } |
42 | 317 |
830 | 318 /** |
319 * @brief 終了したタスクリストの依存の処理 | |
320 * @param [task] 終了したタスク | |
321 */ | |
322 void | |
955 | 323 TaskManagerImpl::check_task_list_finish(SchedTask *s, TaskListPtr list, QueueInfo<HTask> *wait_queue) |
830 | 324 { |
855 | 325 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
|
326 SimpleTaskPtr task = &list->tasks[i]; |
830 | 327 HTask *me = (HTask*)task->self; |
328 me->post_func(s, me->post_arg1, me->post_arg2); | |
329 if (task->command==TaskArray1) { | |
831
b3c004fe6bc3
CheckTaskList Mail working
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
330 int next = ((task->r_size)/sizeof(SimpleTask))+1; |
830 | 331 // assert(next<list->length); |
332 i+=next; | |
333 } | |
833
577bde5d0cec
poling (may recurse..)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
831
diff
changeset
|
334 s->polling(); |
830 | 335 check_task_finish(me, wait_queue); |
336 } | |
337 } | |
109 | 338 |
830 | 339 /** |
340 * @brief waitTaskqueue への挿入 。必須ではない。 | |
341 * 現状では、dead lock 検出にしか使ってない | |
342 * | |
343 * @param [task] 終了したタスク | |
344 */ | |
109 | 345 void |
498
bce667ff20b9
double linked HTaskInfo/HTask
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
497
diff
changeset
|
346 TaskManagerImpl::append_waitTask(HTaskPtr q) |
109 | 347 { |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
348 waitTaskQueue ->addLast(q); |
109 | 349 } |
350 | |
830 | 351 /** |
352 @brief htask を DMA でCPUに渡すための TaskList に入れる (copy) | |
353 @param htask | |
354 @param taskList | |
355 TaskList は自動的に延長される | |
356 */ | |
806 | 357 void |
955 | 358 TaskManagerImpl::set_taskList(HTaskPtr htask, QueueInfo<TaskList> * taskList) { |
1147 | 359 |
809 | 360 TaskListPtr list ; |
361 if ( taskList->empty() ) { | |
362 list = taskList->create(); | |
363 taskList->addLast(list); | |
364 } else | |
365 list = taskList->getLast(); | |
806 | 366 SimpleTaskPtr task = &list->tasks[list->length++]; |
367 if (htask->command==TaskArray1) { | |
368 // compatibility | |
369 int next = ((htask->r_size)/sizeof(SimpleTask))+1; | |
370 if (list->length+next>=TASK_MAX_SIZE) { | |
371 list->length--; | |
809 | 372 TaskListPtr newList = taskList->create(); |
806 | 373 taskList->addLast(newList); |
374 list = newList; | |
375 task = &list->tasks[list->length++]; | |
376 } | |
377 Task *array = (Task*)&list->tasks[list->length]; | |
378 list->length += next; | |
379 if (list->length>=TASK_MAX_SIZE) { | |
380 perror("task array1 overflow\n"); | |
381 } | |
382 memcpy(array, htask->rbuf, htask->r_size); | |
383 free(htask->rbuf); | |
831
b3c004fe6bc3
CheckTaskList Mail working
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
830
diff
changeset
|
384 // htask->rbuf = 0; htask->r_size = 0; we need this... |
806 | 385 *task = *(SimpleTask*)htask; |
386 } else { | |
387 *task = *(SimpleTask*)htask; | |
388 } | |
389 if (list->length >= TASK_MAX_SIZE) { | |
809 | 390 TaskListPtr newList = taskList->create(); |
806 | 391 taskList->addLast(newList); |
392 list = newList; | |
393 } | |
394 } | |
395 | |
54 | 396 |
619 | 397 |
479
bf2d2625485e
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
475
diff
changeset
|
398 /* end */ |