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