Mercurial > hg > Members > e085722 > Cerium
comparison TaskManager/kernel/schedule/SchedTaskArray.cc @ 0:04e28d8d3c6f
first commit
author | Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Nov 2010 01:23:25 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:04e28d8d3c6f |
---|---|
1 #include "SchedTaskArray.h" | |
2 #include "SchedTaskArrayNop.h" | |
3 #include "Scheduler.h" | |
4 #include "TaskManagerImpl.h" | |
5 | |
6 | |
7 SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_, Task *curTask_, Task *_array, int tag) | |
8 { | |
9 savedTask = savedTask_; | |
10 atask = curTask_; | |
11 array = _array; | |
12 scheduler = s; | |
13 | |
14 inListData.bound = 0; | |
15 inListData.size = 0; | |
16 inListData.length = 0; | |
17 inListData.element = 0; | |
18 outListData.bound = 0; | |
19 outListData.size = 0; | |
20 outListData.length = 0; | |
21 outListData.element = 0; | |
22 | |
23 cur_index = -1; | |
24 task = 0; | |
25 | |
26 this->tag = tag; | |
27 | |
28 } | |
29 | |
30 /** | |
31 Constructor for old Task with ListData | |
32 next TaskList entry contains Task object. | |
33 savedTask->rbuf is 0, it has only one Task. | |
34 */ | |
35 | |
36 SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_) | |
37 { | |
38 savedTask = savedTask_; | |
39 scheduler = s; | |
40 | |
41 inListData.bound = 0; | |
42 inListData.size = 0; | |
43 inListData.length = 0; | |
44 inListData.element = 0; | |
45 outListData.bound = 0; | |
46 outListData.size = 0; | |
47 outListData.length = 0; | |
48 outListData.element = 0; | |
49 | |
50 SimpleTaskPtr st = &savedTask->list->tasks[savedTask->cur_index]; | |
51 atask = (TaskPtr)st; | |
52 array = 0; | |
53 savedTask->cur_index += (atask->size()+sizeof(SimpleTask))/sizeof(SimpleTask); | |
54 cur_index = -1; | |
55 task = 0; | |
56 | |
57 this->tag = 0; | |
58 | |
59 } | |
60 | |
61 /** | |
62 */ | |
63 SchedTaskArray::~SchedTaskArray() | |
64 { | |
65 } | |
66 | |
67 /** | |
68 * DMA buffer offset in rbuf | |
69 */ | |
70 static void | |
71 bound(ListData *list) | |
72 { | |
73 ListElement *elm = list->element; | |
74 int *bound = list->bound; | |
75 int offset=0; | |
76 for(int i=0;i<list->length;i++) { | |
77 bound[i] = offset; | |
78 offset += elm[i].size; | |
79 } | |
80 } | |
81 | |
82 | |
83 /** | |
84 * Task data / code read | |
85 */ | |
86 void | |
87 SchedTaskArray::read() | |
88 { | |
89 | |
90 // object creation をSchedTaskArray生成時にやらないので、 | |
91 // exec の直前のread で十分に間に合う | |
92 loadSchedTask(scheduler, atask->command); | |
93 | |
94 // 読むデータが一つもなければ無視 | |
95 if (atask->inData_count == 0) return; | |
96 | |
97 inListData.length = atask->inData_count; | |
98 inListData.size = atask->inData_total_size(); | |
99 inListData.element = atask->inData(0); | |
100 inListData.bound = (int*)manager->allocate(inListData.length*sizeof(int)); | |
101 | |
102 // load Input Data | |
103 readbuf = manager->allocate(inListData.size); | |
104 // inListData.print(); | |
105 scheduler->dma_loadList(&inListData, readbuf, (DMA_READ + this->tag)); | |
106 bound(&inListData); | |
107 | |
108 } | |
109 | |
110 /** | |
111 * Wait read data and execute task | |
112 * Start write DMA | |
113 */ | |
114 void | |
115 SchedTaskArray::exec() | |
116 { | |
117 task_list[atask->command].wait(scheduler,atask->command); | |
118 TaskObjectRun run = task_list[atask->command].run; | |
119 if (atask->outData_count > 0) { | |
120 // allocate write buffer | |
121 outListData.length = atask->outData_count; | |
122 outListData.size = atask->outData_total_size(); | |
123 // atask->outData_offset += cur_index + 1 ; // to avoid compiler bug | |
124 outListData.element = atask->outData(0); | |
125 outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); | |
126 bound(&outListData); | |
127 | |
128 writebuf = manager->allocate(outListData.size); | |
129 //if (outListData.element == inListData.element ) { | |
130 // printf("bad %x\n",outListData.element); | |
131 //} | |
132 } | |
133 scheduler->dma_wait((DMA_READ + this->tag)); | |
134 run(this, get_input(readbuf, 0), get_output(writebuf, 0)); | |
135 free(readbuf); | |
136 // 書き込む領域がなければ無視 | |
137 | |
138 // User 側で作る方法が必要... | |
139 | |
140 if (atask->outData_count > 0) { | |
141 // outListData.print(); | |
142 scheduler->dma_storeList(&outListData, writebuf, DMA_WRITE); | |
143 } | |
144 } | |
145 | |
146 /** | |
147 * Wait write DMA | |
148 * send finish mail | |
149 */ | |
150 void | |
151 SchedTaskArray::write() | |
152 { | |
153 | |
154 scheduler->dma_wait(DMA_WRITE); | |
155 free(writebuf); | |
156 free(inListData.bound); | |
157 free(outListData.bound); | |
158 } | |
159 | |
160 Task *SchedTaskArray::last() | |
161 { | |
162 SchedTask *s = (SchedTask *)savedTask; | |
163 return (Task*)(((char*)array)+ s->read_size()); | |
164 } | |
165 | |
166 SchedTaskBase* | |
167 SchedTaskArray::next(Scheduler *scheduler, SchedTaskBase *p) | |
168 { | |
169 | |
170 Task *next = atask->next(); | |
171 if (next < last()) { | |
172 // Task List が残っているので、次を準備 | |
173 //scheduler->printf("hog\n"); | |
174 return new SchedTaskArray(scheduler, savedTask, next, array, this->tag^1); | |
175 } else { | |
176 | |
177 //このTaskArrayは終わったが、Pipeline 上にread の TaskArray が残っているので | |
178 //1ステージを稼ぐ必要がある | |
179 //scheduler->printf("auau\n"); | |
180 return new SchedTaskArrayNop(scheduler, savedTask, next, array); | |
181 | |
182 } | |
183 } | |
184 | |
185 | |
186 | |
187 /** | |
188 * task->add_inData で与えられた順番に対応する index (0〜n-1) で、 | |
189 * buffer から対応するデータを返す。 | |
190 */ | |
191 void* | |
192 SchedTaskArray::get_input(void *buff, int index) | |
193 { | |
194 return (void*)((char*)readbuf + inListData.bound[index]); | |
195 } | |
196 | |
197 /** | |
198 * get_input(index) のアドレスを返す | |
199 */ | |
200 memaddr | |
201 SchedTaskArray::get_inputAddr(int index) | |
202 { | |
203 #ifdef __CERIUM_CELL__ | |
204 return (memaddr)inListData.element[index].addr; | |
205 #else | |
206 return inListData.element[index].addr; | |
207 #endif | |
208 } | |
209 | |
210 /** | |
211 * get_input(index) のサイズを返す | |
212 */ | |
213 int | |
214 SchedTaskArray::get_inputSize(int index) | |
215 { | |
216 return inListData.element[index].size; | |
217 } | |
218 | |
219 /** | |
220 * write buffer の領域を返す。 | |
221 */ | |
222 void* | |
223 SchedTaskArray::get_output(void *buff, int index) | |
224 { | |
225 return (void*)((char *)writebuf + outListData.bound[index]); | |
226 } | |
227 | |
228 /** | |
229 * get_output(index) のアドレスを返す | |
230 */ | |
231 memaddr | |
232 SchedTaskArray::get_outputAddr(int index) | |
233 { | |
234 #ifdef __CERIUM_CELL__ | |
235 return (memaddr)outListData.element[index].addr; | |
236 #else | |
237 return outListData.element[index].addr; | |
238 #endif | |
239 } | |
240 | |
241 /** | |
242 * get_output(index) のサイズを返す | |
243 */ | |
244 int | |
245 SchedTaskArray::get_outputSize(int index) | |
246 { | |
247 return outListData.element[index].size; | |
248 } | |
249 | |
250 memaddr | |
251 SchedTaskArray::get_param(int index) | |
252 { | |
253 return *atask->param(index); | |
254 } | |
255 | |
256 int | |
257 SchedTaskArray::read_size() | |
258 { | |
259 return get_inputSize(0); | |
260 } | |
261 | |
262 | |
263 /* end */ |