Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/schedule/SchedTaskArray.cc @ 708:d41c62201b1e draft
cleean up SchedTasks.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Dec 2009 10:49:30 +0900 |
parents | b2b4a1243961 |
children | 97adb3fe85c6 |
rev | line source |
---|---|
695 | 1 #include "SchedTaskArray.h" |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
2 #include "Scheduler.h" |
695 | 3 |
706
b2b4a1243961
no compile error on Cell. Regression Test.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
4 #ifdef SIMPLE_TASK |
695 | 5 |
699 | 6 SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_, Task *curTask_, Task *_array) |
695 | 7 { |
8 savedTask = savedTask_; | |
708 | 9 atask = curTask_; |
695 | 10 array = _array; |
699 | 11 scheduler = s; |
695 | 12 |
696 | 13 inListData.bound = 0; |
14 inListData.size = 0; | |
15 inListData.length = 0; | |
16 inListData.element = 0; | |
17 outListData.bound = 0; | |
18 outListData.size = 0; | |
19 outListData.length = 0; | |
20 outListData.element = 0; | |
21 } | |
22 | |
697 | 23 /** |
703 | 24 Constructor for old Task with ListData |
25 next TaskList entry contains Task object. | |
26 savedTask->rbuf is 0, it has only one Task. | |
27 */ | |
28 | |
29 SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_) | |
30 { | |
31 savedTask = savedTask_; | |
32 scheduler = s; | |
33 | |
34 inListData.bound = 0; | |
35 inListData.size = 0; | |
36 inListData.length = 0; | |
37 inListData.element = 0; | |
38 outListData.bound = 0; | |
39 outListData.size = 0; | |
40 outListData.length = 0; | |
41 outListData.element = 0; | |
42 | |
708 | 43 atask = (TaskPtr)&savedTask->list->tasks[savedTask->cur_index]; |
704
ec6c897448ca
Compatibility mode works.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
703
diff
changeset
|
44 array = 0; |
708 | 45 savedTask->cur_index += (atask->size()+sizeof(SimpleTask))/sizeof(SimpleTask); |
703 | 46 |
47 } | |
48 | |
49 /** | |
697 | 50 */ |
51 SchedTaskArray::~SchedTaskArray() | |
696 | 52 { |
697 | 53 } |
54 | |
708 | 55 /** |
56 * DMA buffer offset in rbuf | |
57 */ | |
697 | 58 static void |
59 bound(ListData *list) | |
60 { | |
61 ListElement *elm = list->element; | |
62 int *bound = list->bound; | |
63 int offset=0; | |
696 | 64 for(int i=0;i<list->length;i++) { |
697 | 65 bound[i] = offset; |
66 offset += elm[i].size; | |
696 | 67 } |
695 | 68 } |
69 | |
708 | 70 /** |
71 * Task data / code read | |
72 */ | |
695 | 73 void |
74 SchedTaskArray::read() | |
75 { | |
76 | |
77 // object creation をSchedTaskArray生成時にやらないので、 | |
78 // exec の直前のread で十分に間に合う | |
708 | 79 loadSchedTask(scheduler, atask->command); |
695 | 80 |
81 // 読むデータが一つもなければ無視 | |
708 | 82 if (atask->inData_count == 0) return; |
696 | 83 |
708 | 84 inListData.length = atask->inData_count; |
85 inListData.size = atask->inData_total_size(); | |
86 inListData.element = atask->inData(0); | |
697 | 87 inListData.bound = (int*)scheduler->allocate(inListData.length*sizeof(int)); |
695 | 88 |
89 // load Input Data | |
696 | 90 readbuf = scheduler->allocate(inListData.size); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
91 // inListData.print(); |
696 | 92 scheduler->dma_loadList(&inListData, readbuf, DMA_READ); |
697 | 93 bound(&inListData); |
695 | 94 |
95 } | |
96 | |
708 | 97 /** |
98 * Wait read data and execute task | |
99 * Start write DMA | |
100 */ | |
695 | 101 void |
102 SchedTaskArray::exec() | |
103 { | |
104 | |
708 | 105 if (atask->outData_count > 0) { |
106 outListData.length = atask->outData_count; | |
107 outListData.size = atask->outData_total_size(); | |
108 outListData.element = atask->outData(0); | |
699 | 109 outListData.bound = (int*)scheduler->allocate(outListData.length*sizeof(int)); |
110 bound(&outListData); | |
111 | |
112 writebuf = scheduler->allocate(outListData.size); | |
113 } | |
114 | |
695 | 115 scheduler->dma_wait(DMA_READ); |
708 | 116 task_list[atask->command].wait(scheduler,atask->command); |
117 task_list[atask->command].run(this, readbuf, writebuf); | |
695 | 118 free(readbuf); |
119 // 書き込む領域がなければ無視 | |
697 | 120 |
121 // User 側で作る方法が必要... | |
122 | |
708 | 123 if (atask->outData_count > 0) { |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
124 // outListData.print(); |
696 | 125 scheduler->dma_storeList(&outListData, writebuf, DMA_WRITE); |
695 | 126 } |
127 } | |
128 | |
708 | 129 /** |
130 * Wait write DMA | |
131 * send finish mail | |
132 */ | |
695 | 133 void |
134 SchedTaskArray::write() | |
135 { | |
136 | |
137 scheduler->dma_wait(DMA_WRITE); | |
138 free(writebuf); | |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
139 free(inListData.bound); |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
140 free(outListData.bound); |
695 | 141 |
142 // このTaskArrayは終り。終了を知らせる。 | |
708 | 143 if (!array || atask->next() >= last()) { |
697 | 144 SchedTask *s = (SchedTask *)savedTask; |
145 scheduler->mail_write((memaddr)s->task->self); | |
695 | 146 free(array); |
147 } | |
148 | |
149 } | |
150 | |
151 Task *SchedTaskArray::last() | |
152 { | |
697 | 153 SchedTask *s = (SchedTask *)savedTask; |
154 return (Task*)(((char*)array)+ s->read_size()); | |
695 | 155 } |
156 | |
157 SchedTaskBase* | |
697 | 158 SchedTaskArray::next(Scheduler *scheduler, SchedTaskBase *p) |
695 | 159 { |
160 | |
708 | 161 Task *next = atask->next(); |
697 | 162 if (next < last()) { |
695 | 163 // Task List が残っているので、次を準備 |
708 | 164 return new SchedTaskArray(scheduler, savedTask, next, array); |
695 | 165 } else { |
166 // このTaskArrayは終り。save していた Task の次を返す。 | |
167 // savedTask の read/exec は実行されない (command = TaskArray) | |
697 | 168 return savedTask->next(scheduler, savedTask); |
695 | 169 } |
170 } | |
171 | |
172 | |
173 | |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
174 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
175 * task->add_inData で与えられた順番に対応する index (0〜n-1) で、 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
176 * buffer から対応するデータを返す。 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
177 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
178 void* |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
179 SchedTaskArray::get_input(void *buff, int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
180 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
181 return (void*)((char*)readbuf + inListData.bound[index]); |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
182 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
183 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
184 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
185 * get_input(index) のアドレスを返す |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
186 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
187 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
188 SchedTaskArray::get_inputAddr(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
189 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
190 #ifdef __CERIUM_CELL__ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
191 return (memaddr)inListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
192 #else |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
193 return inListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
194 #endif |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
195 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
196 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
197 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
198 * get_input(index) のサイズを返す |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
199 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
200 int |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
201 SchedTaskArray::get_inputSize(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
202 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
203 return inListData.element[index].size; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
204 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
205 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
206 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
207 * write buffer の領域を返す。 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
208 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
209 void* |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
210 SchedTaskArray::get_output(void *buff, int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
211 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
212 return (void*)((char *)writebuf + outListData.bound[index]); |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
213 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
214 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
215 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
216 * get_output(index) のアドレスを返す |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
217 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
218 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
219 SchedTaskArray::get_outputAddr(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
220 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
221 #ifdef __CERIUM_CELL__ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
222 return (memaddr)outListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
223 #else |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
224 return outListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
225 #endif |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
226 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
227 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
228 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
229 * get_output(index) のサイズを返す |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
230 */ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
231 int |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
232 SchedTaskArray::get_outputSize(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
233 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
234 return outListData.element[index].size; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
235 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
236 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
237 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
238 SchedTaskArray::get_param(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
239 { |
708 | 240 return *atask->param(index); |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
241 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
242 |
706
b2b4a1243961
no compile error on Cell. Regression Test.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
243 #endif |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
244 |
695 | 245 /* end */ |