Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/HTask.cc @ 1551:57317332f6ef draft
create fft example
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 17 Feb 2013 12:59:12 +0900 |
parents | 163220e54cc0 |
children | 806b4658ced6 |
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 { | |
1479
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
22 if (export_task_log) |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
23 tasklog->create_time = rdtsc(); |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
24 |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
25 TaskList *tl = (TaskList*)rbuf; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
26 tl->self = this; |
1466 | 27 tl->set_last(last); |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
28 mimpl->spawn_task(this); |
109 | 29 } |
30 | |
293 | 31 /*! |
297 | 32 @brief この Task が待ち合わせする Task を指定する |
33 @param[in] master この Task が終了待ち合わせをする相手の Task | |
293 | 34 |
297 | 35 繰り返し使用する事で複数の Task を待ち合わせする事ができる。 |
293 | 36 |
297 | 37 wait_for している Task の入力バッファにこの Task から書き込みできる機能があると良い |
293 | 38 */ |
109 | 39 void |
293 | 40 HTask::wait_for(HTaskPtr master) |
109 | 41 { |
1479
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
42 if (export_task_log) { |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
43 waitTask *wait_task = new waitTask; |
163220e54cc0
remove hard code for TaskLog
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1474
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 } |
1423
515a0f15b5d2
add to log taskdependency
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
1191
diff
changeset
|
48 |
109 | 49 mimpl->set_task_depend(master, this); |
50 } | |
51 | |
814 | 52 /** |
53 * タスクが実行する CPU を選択する | |
54 * | |
55 * 現在は CPU_PPE, CPU_SPE, SPE_ANY, SPE_0, SPE_1, ..., SPE_5 | |
56 * types.h に書いてます。 | |
57 * | |
58 * mimpl によって使えるCPUが異なるので、mimpl に任せる必要がある | |
59 */ | |
547 | 60 void |
61 HTask::set_cpu(CPU_TYPE type) | |
62 { | |
109 | 63 mimpl->set_task_cpu(this, type); |
547 | 64 } |
65 | |
814 | 66 /*! |
67 @brief このTaskが終了した時に実行する関数 | |
68 @param arg1, arg2 の二つの引数を持つ (Task に合わせてある) | |
69 */ | |
547 | 70 void |
550 | 71 HTask::set_post(PostFunction func,void *arg1, void *arg2) |
547 | 72 { |
109 | 73 this->post_func = func; |
550 | 74 this->post_arg1 = arg1; |
75 this->post_arg2 = arg2; | |
547 | 76 } |
77 | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
78 |
814 | 79 /*! |
80 @brief まとまって実行されるTask である Task Array の作成 | |
81 @param id Task ID | |
82 @param num_task 実行する Task の数 | |
83 @param num_param 一つのTaskがset_paramする数 | |
84 @param num_inData 一つのTaskが読み込む Data の数、set_inData の数 | |
85 @param num_outData 一つのTaskが書き出す Data の数、set_outData の数 | |
86 @return Task Array へのポインタ | |
1432 | 87 */ |
1468 | 88 |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
89 Task * |
700 | 90 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
|
91 { |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
92 r_size = 0; |
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
93 TaskListPtr tl = mimpl->createTaskList(); |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
94 tl->self = 0; |
1427
db5c022d871c
task array uses TaskList. (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1425
diff
changeset
|
95 rbuf = (memaddr)tl; |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
96 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
|
97 Task *task = tl->tasks; |
1474 | 98 task->init(id, num_param,num_inData,num_outData); // next_task_array が呼ばれれば、これは不要 |
99 last = task->next(); // | |
700 | 100 return task; // first task |
101 } | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
102 |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
103 |
814 | 104 /*! |
105 @brief Task Array の次のTask | |
106 @param t 今のTaskのポインタ | |
107 0 の場合は最初のTask | |
108 @return 次のTaskへのポインタ | |
109 */ | |
700 | 110 Task * |
111 HTask::next_task_array(int id, Task *t) | |
112 { | |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
113 TaskPtr t1 = t; |
700 | 114 if (t==0) { |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
115 TaskList *tl = (TaskList*)rbuf; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
116 t1 = tl->tasks; |
700 | 117 } |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
118 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
|
119 } |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
120 |
814 | 121 /*! |
1425 | 122 @brief Task Array の次のTask |
123 @param t 今のTaskのポインタ | |
124 0 の場合は最初のTask | |
125 @return 次のTaskへのポインタ | |
126 */ | |
127 Task * | |
128 HTask::next_task_array(int id, Task *t, int param_count, int inData_count, int outData_count) | |
129 { | |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
130 TaskList *tl = (TaskList*)rbuf; |
1425 | 131 if (t==0) { |
1474 | 132 TaskPtr task = tl->tasks; |
133 task->init(id, param_count, inData_count, outData_count); | |
134 last = task->next(); | |
135 return task; | |
1425 | 136 } |
137 Task *next = t->next(); | |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
138 if (next >= tl->last()) { |
1466 | 139 tl->set_last(t); |
1462
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
140 TaskListPtr nextTaskList = mimpl->createTaskList(); |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
141 nextTaskList->prev = tl; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
142 tl->next = nextTaskList; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
143 tl = nextTaskList; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
144 next = tl->tasks; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
145 tl->self = 0; |
8cf62aea798f
HTask/TaskList fix (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1427
diff
changeset
|
146 rbuf = (memaddr)tl; |
1464
3f2230d79eba
TaskList no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1463
diff
changeset
|
147 } |
1425 | 148 next->init(id, param_count, inData_count, outData_count); |
1474 | 149 last = next->next(); |
1425 | 150 return next; |
151 } | |
152 | |
153 /*! | |
814 | 154 @brief Task Array の中のすべてのTaskが書き込まれたかどうかをチェックする |
155 TaskArray 自体の spawn() は別に必要 | |
156 @param last 今のTaskのポインタ (最後である必要がある) | |
157 */ | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
158 void |
700 | 159 HTask::spawn_task_array(Task * last) |
689
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 |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
163 |
547 | 164 /* end */ |