Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/HTask.cc @ 1427:db5c022d871c draft
task array uses TaskList. (on going)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Mar 2012 00:51:03 +0900 |
parents | 8bd889db45a1 |
children | ae5fb867cf84 8cf62aea798f |
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 |
7 | |
293 | 8 /*! |
297 | 9 manager->set_task_depend(task1, task2); // task2 は task1 の終了を待つ |
293 | 10 |
297 | 11 ってやるより |
293 | 12 |
13 task2->set_depend(task1); | |
14 | |
297 | 15 ってやったほうがわかりやすいよねー的な話し合いで |
16 下のようなAPIを作りました | |
293 | 17 */ |
18 | |
109 | 19 void |
20 HTask::spawn(void) | |
21 { | |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
22 tasklog->create_time = rdtsc(); |
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
23 mimpl->spawn_task(this); |
109 | 24 } |
25 | |
293 | 26 /*! |
297 | 27 @brief この Task が待ち合わせする Task を指定する |
28 @param[in] master この Task が終了待ち合わせをする相手の Task | |
293 | 29 |
297 | 30 繰り返し使用する事で複数の Task を待ち合わせする事ができる。 |
293 | 31 |
297 | 32 wait_for している Task の入力バッファにこの Task から書き込みできる機能があると良い |
293 | 33 */ |
109 | 34 void |
293 | 35 HTask::wait_for(HTaskPtr master) |
109 | 36 { |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
37 waitTask *wait_task = new waitTask; |
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
38 wait_task->task_id = master->tasklog->mtask_id; |
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
39 wait_task->cmd = master->command; |
1424
0ce6c6880b4b
change to the queue form the list.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1423
diff
changeset
|
40 tasklog->wait_for_list.addLast(wait_task); |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
41 |
109 | 42 mimpl->set_task_depend(master, this); |
43 } | |
44 | |
814 | 45 /** |
46 * タスクが実行する CPU を選択する | |
47 * | |
48 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 | |
49 * types.h に書いてます。 | |
50 * | |
51 * mimpl によって使えるCPUが異なるので、mimpl に任せる必要がある | |
52 */ | |
547 | 53 void |
54 HTask::set_cpu(CPU_TYPE type) | |
55 { | |
109 | 56 mimpl->set_task_cpu(this, type); |
547 | 57 } |
58 | |
814 | 59 /*! |
60 @brief このTaskが終了した時に実行する関数 | |
61 @param arg1, arg2 の二つの引数を持つ (Task に合わせてある) | |
62 */ | |
547 | 63 void |
550 | 64 HTask::set_post(PostFunction func,void *arg1, void *arg2) |
547 | 65 { |
109 | 66 this->post_func = func; |
550 | 67 this->post_arg1 = arg1; |
68 this->post_arg2 = arg2; | |
547 | 69 } |
70 | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
71 |
814 | 72 /*! |
73 @brief まとまって実行されるTask である Task Array の作成 | |
74 @param id Task ID | |
75 @param num_task 実行する Task の数 | |
76 @param num_param 一つのTaskがset_paramする数 | |
77 @param num_inData 一つのTaskが読み込む Data の数、set_inData の数 | |
78 @param num_outData 一つのTaskが書き出す Data の数、set_outData の数 | |
79 @return Task Array へのポインタ | |
80 */ | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
81 Task * |
700 | 82 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
|
83 { |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
84 r_size = 0; |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
85 int sz = Task::calc_size(num_param, num_inData, num_outData); |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
86 TaskListPtr tl = mimpl->createTaskList(); |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
87 if (sz>tl-> sizeof(tl->tasks)) { |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
88 mimpl->get_scheduler()->printf("too large task array.\n"); |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
89 } |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
90 rbuf = (memaddr)tl; |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
954
diff
changeset
|
91 //printf("r_size %d\n",r_size); |
1191
bd4a27ae2524
success run to ballbound
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1179
diff
changeset
|
92 //bzeroするのはcostが高いので外したい |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
93 bzero(tl->tasks,sizeof(tasks)); |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
94 Task *task = tl->tasks; |
700 | 95 task->init(id, num_param,num_inData,num_outData); |
96 // task->print(); | |
97 return task; // first task | |
98 } | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
99 |
814 | 100 /*! |
101 @brief Task Array の次のTask | |
102 @param t 今のTaskのポインタ | |
103 0 の場合は最初のTask | |
104 @return 次のTaskへのポインタ | |
105 */ | |
700 | 106 Task * |
107 HTask::next_task_array(int id, Task *t) | |
108 { | |
109 Task *first = (Task*)rbuf; | |
110 if (t==0) { | |
111 // first->print(); | |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
112 first->init(id, param_count, inData_count, outData_count); |
700 | 113 return first; |
114 } | |
115 | |
116 Task *next = t->next(); | |
117 next->init(id, first->param_count, first->inData_count, first->outData_count); | |
118 if ((memaddr)next - (memaddr)rbuf > r_size) | |
736 | 119 mimpl->get_scheduler()->printf("too many task array used.\n"); |
700 | 120 return next; |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
121 } |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
122 |
814 | 123 /*! |
1425 | 124 @brief Task Array の次のTask |
125 @param t 今のTaskのポインタ | |
126 0 の場合は最初のTask | |
127 @return 次のTaskへのポインタ | |
128 */ | |
129 Task * | |
130 HTask::next_task_array(int id, Task *t, int param_count, int inData_count, int outData_count) | |
131 { | |
132 Task *first = (Task*)rbuf; | |
133 if (t==0) { | |
134 // first->print(); | |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
135 first->init(id, param_count, inData_count, outData_count); |
1425 | 136 return first; |
137 } | |
138 | |
139 Task *next = t->next(); | |
140 next->init(id, param_count, inData_count, outData_count); | |
141 if ((memaddr)next - (memaddr)rbuf > r_size) | |
142 mimpl->get_scheduler()->printf("too many task array used.\n"); | |
143 return next; | |
144 } | |
145 | |
146 | |
147 /*! | |
814 | 148 @brief Task Array の中のすべてのTaskが書き込まれたかどうかをチェックする |
149 TaskArray 自体の spawn() は別に必要 | |
150 @param last 今のTaskのポインタ (最後である必要がある) | |
151 */ | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
152 void |
700 | 153 HTask::spawn_task_array(Task * last) |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
154 { |
700 | 155 int size = (memaddr)last - rbuf; |
156 if (size!= r_size) { | |
736 | 157 mimpl->get_scheduler()->printf("spawn task array size differ size 0x%x r_size 0x%x\n", |
700 | 158 size, r_size); |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
159 } |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
160 } |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
161 |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
162 |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
163 |
954 | 164 |
547 | 165 /* end */ |