Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/HTask.cc @ 1602:e33e106ca3e0 draft
change default make parallel from fifo
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 06 Apr 2013 17:27:30 +0900 |
parents | 40a3504126a4 |
children | 5b99bcc6bdb0 |
rev | line source |
---|---|
109 | 1 #include "HTask.h" |
2 #include "ListData.h" | |
3 #include "TaskManagerImpl.h" | |
704
ec6c897448ca
Compatibility mode works.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
4 #include "strings.h" |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
5 #include "rdtsc.h" |
109 | 6 |
293 | 7 /*! |
297 | 8 manager->set_task_depend(task1, task2); // task2 は task1 の終了を待つ |
293 | 9 |
297 | 10 ってやるより |
293 | 11 |
12 task2->set_depend(task1); | |
13 | |
297 | 14 ってやったほうがわかりやすいよねー的な話し合いで |
15 下のようなAPIを作りました | |
293 | 16 */ |
17 | |
109 | 18 void |
19 HTask::spawn(void) | |
20 { | |
1479
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
21 if (export_task_log) |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
22 tasklog->create_time = rdtsc(); |
1583 | 23 |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
24 TaskList *tl = (TaskList*)rbuf; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
25 tl->self = this; |
1466 | 26 tl->set_last(last); |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
27 mimpl->spawn_task(this); |
109 | 28 } |
29 | |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
30 void |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
31 HTask::iterate(long x) { |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
32 TaskList *tl = (TaskList*)rbuf; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
33 tl->dim=1; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
34 tl->x=x; |
1583 | 35 tl->self = this; |
36 tl->set_last(last); | |
37 mimpl->spawn_task(this); | |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
38 } |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
39 |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
40 void |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
41 HTask::iterate(long x, long y) { |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
42 TaskList *tl = (TaskList*)rbuf; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
43 tl->dim=2; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
44 tl->x=x; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
45 tl->y=y; |
1583 | 46 tl->self = this; |
47 tl->set_last(last); | |
48 mimpl->spawn_task(this); | |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
49 } |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
50 |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
51 void |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
52 HTask::iterate(long x, long y, long z) { |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
53 TaskList *tl = (TaskList*)rbuf; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
54 tl->dim=3; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
55 tl->x=x; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
56 tl->y=y; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
57 tl->z=z; |
1583 | 58 tl->self = this; |
59 tl->set_last(last); | |
60 mimpl->spawn_task(this); | |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
61 } |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
62 |
293 | 63 /*! |
297 | 64 @brief この Task が待ち合わせする Task を指定する |
65 @param[in] master この Task が終了待ち合わせをする相手の Task | |
293 | 66 |
297 | 67 繰り返し使用する事で複数の Task を待ち合わせする事ができる。 |
293 | 68 |
297 | 69 wait_for している Task の入力バッファにこの Task から書き込みできる機能があると良い |
293 | 70 */ |
109 | 71 void |
293 | 72 HTask::wait_for(HTaskPtr master) |
109 | 73 { |
1479
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
74 if (export_task_log) { |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
75 waitTask *wait_task = new waitTask; |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
76 wait_task->task_id = master->tasklog->mtask_id; |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
77 wait_task->cmd = master->tasklog->cmd; |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
78 tasklog->wait_for_list.addLast(wait_task); |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
79 } |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
80 |
109 | 81 mimpl->set_task_depend(master, this); |
82 } | |
83 | |
814 | 84 /** |
85 * タスクが実行する CPU を選択する | |
86 * | |
87 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 | |
88 * types.h に書いてます。 | |
89 * | |
90 * mimpl によって使えるCPUが異なるので、mimpl に任せる必要がある | |
91 */ | |
547 | 92 void |
93 HTask::set_cpu(CPU_TYPE type) | |
94 { | |
109 | 95 mimpl->set_task_cpu(this, type); |
547 | 96 } |
97 | |
814 | 98 /*! |
99 @brief このTaskが終了した時に実行する関数 | |
100 @param arg1, arg2 の二つの引数を持つ (Task に合わせてある) | |
101 */ | |
547 | 102 void |
550 | 103 HTask::set_post(PostFunction func,void *arg1, void *arg2) |
547 | 104 { |
109 | 105 this->post_func = func; |
550 | 106 this->post_arg1 = arg1; |
107 this->post_arg2 = arg2; | |
547 | 108 } |
109 | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
110 |
814 | 111 /*! |
112 @brief まとまって実行されるTask である Task Array の作成 | |
113 @param id Task ID | |
114 @param num_task 実行する Task の数 | |
115 @param num_param 一つのTaskがset_paramする数 | |
116 @param num_inData 一つのTaskが読み込む Data の数、set_inData の数 | |
117 @param num_outData 一つのTaskが書き出す Data の数、set_outData の数 | |
118 @return Task Array へのポインタ | |
1432 | 119 */ |
1468 | 120 |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
121 Task * |
700 | 122 HTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
123 { |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
124 r_size = 0; |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
125 TaskListPtr tl = mimpl->createTaskList(); |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
126 tl->self = 0; |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
127 rbuf = (memaddr)tl; |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
128 bzero(tl->tasks,sizeof(Task)*TASK_MAX_SIZE); |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
129 Task *task = tl->tasks; |
1474 | 130 task->init(id, num_param,num_inData,num_outData); // next_task_array が呼ばれれば、これは不要 |
131 last = task->next(); // | |
700 | 132 return task; // first task |
133 } | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
134 |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
135 |
814 | 136 /*! |
137 @brief Task Array の次のTask | |
138 @param t 今のTaskのポインタ | |
139 0 の場合は最初のTask | |
140 @return 次のTaskへのポインタ | |
141 */ | |
700 | 142 Task * |
143 HTask::next_task_array(int id, Task *t) | |
144 { | |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
145 TaskPtr t1 = t; |
700 | 146 if (t==0) { |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
147 TaskList *tl = (TaskList*)rbuf; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
148 t1 = tl->tasks; |
700 | 149 } |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
150 return next_task_array(id,t,t1->param_count,t1->inData_count,t1->outData_count); |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
151 } |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
152 |
814 | 153 /*! |
1425 | 154 @brief Task Array の次のTask |
155 @param t 今のTaskのポインタ | |
156 0 の場合は最初のTask | |
157 @return 次のTaskへのポインタ | |
158 */ | |
159 Task * | |
160 HTask::next_task_array(int id, Task *t, int param_count, int inData_count, int outData_count) | |
161 { | |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
162 TaskList *tl = (TaskList*)rbuf; |
1425 | 163 if (t==0) { |
1474 | 164 TaskPtr task = tl->tasks; |
165 task->init(id, param_count, inData_count, outData_count); | |
166 last = task->next(); | |
167 return task; | |
1425 | 168 } |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
169 Task *next=get_nextTaskArea(t,tl); |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
170 last = next->next(); |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
171 next->init(id, param_count, inData_count, outData_count); |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
172 return next; |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
173 } |
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
174 |
1581
8ee897303cd0
fix multi_dimention
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1580
diff
changeset
|
175 Task * |
8ee897303cd0
fix multi_dimention
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1580
diff
changeset
|
176 HTask::get_nextTaskArea(Task *t, TaskList *tl) { |
1425 | 177 Task *next = t->next(); |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
178 if (next >= tl->last()) { |
1466 | 179 tl->set_last(t); |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
180 TaskListPtr nextTaskList = mimpl->createTaskList(); |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
181 nextTaskList->prev = tl; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
182 tl->next = nextTaskList; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
183 tl = nextTaskList; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
184 next = tl->tasks; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
185 tl->self = 0; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
186 rbuf = (memaddr)tl; |
1464
3f2230d79eba
TaskList no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1463
diff
changeset
|
187 } |
1580
806b4658ced6
add multi dimension
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1479
diff
changeset
|
188 |
1425 | 189 return next; |
190 } | |
191 /*! | |
814 | 192 @brief Task Array の中のすべてのTaskが書き込まれたかどうかをチェックする |
193 TaskArray 自体の spawn() は別に必要 | |
194 @param last 今のTaskのポインタ (最後である必要がある) | |
195 */ | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
196 void |
700 | 197 HTask::spawn_task_array(Task * last) |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
198 { |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
199 } |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
200 |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
201 |
547 | 202 /* end */ |