Mercurial > hg > Members > kono > Cerium
comparison TaskManager/kernel/schedule/SchedTask.cc @ 713:f725c6455d19
remove SIMPLE_TASK conditional
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Dec 2009 15:27:46 +0900 |
parents | 56487849ea2d |
children | 4c12f679a0fa |
comparison
equal
deleted
inserted
replaced
712:4661eaa48b77 | 713:f725c6455d19 |
---|---|
8 #include "DmaManager.h" | 8 #include "DmaManager.h" |
9 #include "error.h" | 9 #include "error.h" |
10 #include "TaskManager.h" | 10 #include "TaskManager.h" |
11 #include <stdarg.h> | 11 #include <stdarg.h> |
12 | 12 |
13 #ifdef SIMPLE_TASK | |
14 #include "SchedTaskArray.h" | 13 #include "SchedTaskArray.h" |
15 #define Task SimpleTask | 14 #define Task SimpleTask |
16 #define TaskPtr SimpleTaskPtr | 15 #define TaskPtr SimpleTaskPtr |
17 #endif | |
18 | 16 |
19 extern TaskObject task_list[MAX_TASK_OBJECT]; | 17 extern TaskObject task_list[MAX_TASK_OBJECT]; |
20 | 18 |
21 | |
22 #if 0 | |
23 /** | |
24 code load を始める。既に get_segment hash に入っていれば何もしない。 | |
25 */ | |
26 extern void | |
27 loadSchedTask(Scheduler *scheduler,TaskPtr task) | |
28 { | |
29 // fprintf(stderr,"loadSchedTask %d\n",task->command); | |
30 task_list[task->command].load(scheduler,task->command); | |
31 } | |
32 #endif | |
33 | 19 |
34 | 20 |
35 SchedTask::SchedTask() | 21 SchedTask::SchedTask() |
36 { | 22 { |
37 list = NULL; | 23 list = NULL; |
38 task = NULL; | 24 task = NULL; |
39 #ifndef SIMPLE_TASK | |
40 inListData = NULL; | |
41 outListData = NULL; | |
42 #endif | |
43 readbuf = NULL; | 25 readbuf = NULL; |
44 writebuf = NULL; | 26 writebuf = NULL; |
45 scheduler = NULL; | 27 scheduler = NULL; |
46 cur_index = 0; | 28 cur_index = 0; |
47 this->stdout_ = stdout; | 29 this->stdout_ = stdout; |
62 void | 44 void |
63 SchedTask::init(TaskListPtr _list, TaskPtr _task, int index, Scheduler* sc) | 45 SchedTask::init(TaskListPtr _list, TaskPtr _task, int index, Scheduler* sc) |
64 { | 46 { |
65 list = _list; | 47 list = _list; |
66 task = _task; | 48 task = _task; |
67 #ifndef SIMPLE_TASK | |
68 inListData = &_task->inData; | |
69 outListData = &_task->outData; | |
70 #endif | |
71 scheduler = sc; | 49 scheduler = sc; |
72 cur_index = index; | 50 cur_index = index; |
73 | 51 |
74 scheduler->mainMem_wait(); | 52 scheduler->mainMem_wait(); |
75 | 53 |
82 __debug("[SchedTask:%s]\n", __FUNCTION__); | 60 __debug("[SchedTask:%s]\n", __FUNCTION__); |
83 | 61 |
84 // object creation をSchedTask生成時にやらないので、 | 62 // object creation をSchedTask生成時にやらないので、 |
85 // exec の直前のread で十分に間に合う | 63 // exec の直前のread で十分に間に合う |
86 loadSchedTask(scheduler, task->command); | 64 loadSchedTask(scheduler, task->command); |
87 #ifdef SIMPLE_TASK | 65 |
88 // 読むデータが一つもなければ無視 | 66 // 読むデータが一つもなければ無視 |
89 if (task->r_size == 0) return; | 67 if (task->r_size == 0) return; |
90 // load Input Data | 68 // load Input Data |
91 readbuf = scheduler->allocate(task->r_size); | 69 readbuf = scheduler->allocate(task->r_size); |
92 scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); | 70 scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); |
93 #else | |
94 | |
95 // 読むデータが一つもなければ無視 | |
96 if (inListData->length == 0) return; | |
97 | |
98 // load Input Data | |
99 readbuf = scheduler->allocate(inListData->size); | |
100 scheduler->dma_loadList(inListData, readbuf, DMA_READ); | |
101 #endif | |
102 | 71 |
103 | 72 |
104 } | 73 } |
105 | 74 |
106 | 75 |
107 void | 76 void |
108 SchedTask::exec() | 77 SchedTask::exec() |
109 { | 78 { |
110 __debug("[SchedTask:%s]\n", __FUNCTION__); | 79 __debug("[SchedTask:%s]\n", __FUNCTION__); |
111 | 80 |
112 #ifdef SIMPLE_TASK | |
113 if (task->w_size > 0) { | 81 if (task->w_size > 0) { |
114 writebuf = scheduler->allocate(task->w_size); | 82 writebuf = scheduler->allocate(task->w_size); |
115 } | 83 } |
116 #else | |
117 if (outListData->length > 0) { | |
118 writebuf = scheduler->allocate(outListData->size); | |
119 } | |
120 #endif | |
121 scheduler->dma_wait(DMA_READ); | 84 scheduler->dma_wait(DMA_READ); |
122 task_list[task->command].wait(scheduler,task->command); | 85 task_list[task->command].wait(scheduler,task->command); |
123 task_list[task->command].run(this, readbuf, writebuf); | 86 task_list[task->command].run(this, readbuf, writebuf); |
124 free(readbuf); | 87 free(readbuf); |
125 | 88 |
126 // 書き込む領域がなければ無視 | 89 // 書き込む領域がなければ無視 |
127 #ifdef SIMPLE_TASK | 90 |
128 if (task->w_size > 0) { | 91 if (task->w_size > 0) { |
129 writebuf = scheduler->allocate(task->w_size); | 92 writebuf = scheduler->allocate(task->w_size); |
130 scheduler->dma_store(writebuf, task->wbuf,task->w_size, DMA_WRITE); | 93 scheduler->dma_store(writebuf, task->wbuf,task->w_size, DMA_WRITE); |
131 } | 94 } |
132 #else | |
133 if (outListData->length > 0) { | |
134 writebuf = scheduler->allocate(outListData->size); | |
135 scheduler->dma_storeList(outListData, writebuf, DMA_WRITE); | |
136 } | |
137 #endif | |
138 } | 95 } |
139 | 96 |
140 void | 97 void |
141 SchedTask::write() | 98 SchedTask::write() |
142 { | 99 { |
157 // Task List が残っているので、次を準備 | 114 // Task List が残っているので、次を準備 |
158 | 115 |
159 TaskPtr nextTask = &list->tasks[cur_index++]; | 116 TaskPtr nextTask = &list->tasks[cur_index++]; |
160 SchedTask *nextSched = new SchedTask(); | 117 SchedTask *nextSched = new SchedTask(); |
161 nextSched->init(list, nextTask, cur_index, scheduler); | 118 nextSched->init(list, nextTask, cur_index, scheduler); |
162 #ifdef SIMPLE_TASK | 119 |
163 if (nextTask->command==TaskArray1) { | 120 if (nextTask->command==TaskArray1) { |
164 // compatibility | 121 // compatibility |
165 return new SchedTaskArray(scheduler, nextSched); | 122 return new SchedTaskArray(scheduler, nextSched); |
166 } | 123 } |
167 if (nextTask->command==TaskArray) { | 124 if (nextTask->command==TaskArray) { |
168 // Start Task Array | 125 // Start Task Array |
169 return new SchedTaskArrayLoad(scheduler, nextSched); | 126 return new SchedTaskArrayLoad(scheduler, nextSched); |
170 } | 127 } |
171 #endif | |
172 return nextSched; | 128 return nextSched; |
173 } else { | 129 } else { |
174 memaddr nextList = (memaddr)list->next; | 130 memaddr nextList = (memaddr)list->next; |
175 if (nextList == 0) { | 131 if (nextList == 0) { |
176 // もう何もする必要がない | 132 // もう何もする必要がない |
191 | 147 |
192 void SchedTask::free_(void *p) { | 148 void SchedTask::free_(void *p) { |
193 scheduler->free_(p); | 149 scheduler->free_(p); |
194 } | 150 } |
195 | 151 |
196 #ifndef SIMPLE_TASK | |
197 /** | |
198 * task->add_inData で与えられた順番に対応する index (0〜n-1) で、 | |
199 * buffer から対応するデータを返す。 | |
200 */ | |
201 void* | |
202 SchedTask::get_input(void *buff, int index) | |
203 { | |
204 if (buff != NULL) { | |
205 return (void*)((char*)buff + inListData->bound[index]); | |
206 } else { | |
207 return NULL; | |
208 } | |
209 } | |
210 | |
211 /** | |
212 * get_input(index) のアドレスを返す | |
213 */ | |
214 memaddr | |
215 SchedTask::get_inputAddr(int index) | |
216 { | |
217 #ifdef __CERIUM_CELL__ | |
218 return (memaddr)inListData->element[index].addr; | |
219 #else | |
220 return inListData->element[index].addr; | |
221 #endif | |
222 } | |
223 | |
224 /** | |
225 * get_input(index) のサイズを返す | |
226 */ | |
227 int | |
228 SchedTask::get_inputSize(int index) | |
229 { | |
230 return inListData->element[index].size; | |
231 } | |
232 | |
233 /** | |
234 * write buffer の領域を返す。 | |
235 */ | |
236 void* | |
237 SchedTask::get_output(void *buff, int index) | |
238 { | |
239 if (buff != NULL) { | |
240 return (void*)((char *)buff + outListData->bound[index]); | |
241 } else { | |
242 return NULL; | |
243 } | |
244 } | |
245 | |
246 /** | |
247 * get_output(index) のアドレスを返す | |
248 */ | |
249 memaddr | |
250 SchedTask::get_outputAddr(int index) | |
251 { | |
252 #ifdef __CERIUM_CELL__ | |
253 return (memaddr)outListData->element[index].addr; | |
254 #else | |
255 return outListData->element[index].addr; | |
256 #endif | |
257 } | |
258 | |
259 /** | |
260 * get_output(index) のサイズを返す | |
261 */ | |
262 int | |
263 SchedTask::get_outputSize(int index) | |
264 { | |
265 return outListData->element[index].size; | |
266 } | |
267 | |
268 memaddr | |
269 SchedTask::get_param(int index) | |
270 { | |
271 return task->param[index]; | |
272 } | |
273 | |
274 #else | |
275 | 152 |
276 void* SchedTask::get_input(void *buff, int index) { | 153 void* SchedTask::get_input(void *buff, int index) { |
277 printf("Cannot use inData in SimpleTask use TaskArray\n"); | 154 printf("Cannot use inData in SimpleTask use TaskArray\n"); |
278 return NULL; } | 155 return NULL; } |
279 memaddr SchedTask::get_inputAddr(int index) { return 0; } | 156 memaddr SchedTask::get_inputAddr(int index) { return 0; } |
281 void* SchedTask::get_output(void *buff, int index) {return 0; } | 158 void* SchedTask::get_output(void *buff, int index) {return 0; } |
282 memaddr SchedTask::get_outputAddr(int index) { return 0; } | 159 memaddr SchedTask::get_outputAddr(int index) { return 0; } |
283 int SchedTask::get_outputSize(int index) { return 0; } | 160 int SchedTask::get_outputSize(int index) { return 0; } |
284 memaddr SchedTask::get_param(int index) { return 0; } | 161 memaddr SchedTask::get_param(int index) { return 0; } |
285 | 162 |
286 #endif | |
287 | 163 |
288 void* | 164 void* |
289 SchedTask::global_alloc(int id, int size) { | 165 SchedTask::global_alloc(int id, int size) { |
290 return scheduler->global_alloc(id, size); | 166 return scheduler->global_alloc(id, size); |
291 } | 167 } |