Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/schedule/SchedTaskArray.cc @ 777:c38799cc3f60 draft
fix memory coruption on task self
send mail on write is a bad idea.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Mar 2010 12:48:02 +0900 |
parents | 922c0133c61c |
children | 836ca3419f9d |
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 | |
142 Task *SchedTaskArray::last() | |
143 { | |
697 | 144 SchedTask *s = (SchedTask *)savedTask; |
145 return (Task*)(((char*)array)+ s->read_size()); | |
695 | 146 } |
147 | |
148 SchedTaskBase* | |
697 | 149 SchedTaskArray::next(Scheduler *scheduler, SchedTaskBase *p) |
695 | 150 { |
151 | |
708 | 152 Task *next = atask->next(); |
697 | 153 if (next < last()) { |
695 | 154 // Task List が残っているので、次を準備 |
708 | 155 return new SchedTaskArray(scheduler, savedTask, next, array); |
695 | 156 } else { |
157 // このTaskArrayは終り。save していた Task の次を返す。 | |
158 // savedTask の read/exec は実行されない (command = TaskArray) | |
777
c38799cc3f60
fix memory coruption on task self
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
776
diff
changeset
|
159 SchedTask *s = (SchedTask *)savedTask; |
776
922c0133c61c
heap corruption in TaskArray1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
160 SchedTaskBase *n = savedTask->next(scheduler, savedTask); |
777
c38799cc3f60
fix memory coruption on task self
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
776
diff
changeset
|
161 scheduler->mail_write((memaddr)savedTask->task->self); |
c38799cc3f60
fix memory coruption on task self
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
776
diff
changeset
|
162 free(array); |
776
922c0133c61c
heap corruption in TaskArray1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
163 delete savedTask; |
922c0133c61c
heap corruption in TaskArray1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
713
diff
changeset
|
164 return n; |
695 | 165 } |
166 } | |
167 | |
168 | |
169 | |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
170 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
171 * 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
|
172 * buffer から対応するデータを返す。 |
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 void* |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
175 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
|
176 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
177 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
|
178 } |
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 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
181 * get_input(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 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
184 SchedTaskArray::get_inputAddr(int 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 #ifdef __CERIUM_CELL__ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
187 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
|
188 #else |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
189 return inListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
190 #endif |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
191 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
192 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
193 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
194 * get_input(index) のサイズを返す |
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 int |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
197 SchedTaskArray::get_inputSize(int 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 return inListData.element[index].size; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
200 } |
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 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
203 * write buffer の領域を返す。 |
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 void* |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
206 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
|
207 { |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
208 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
|
209 } |
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 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
212 * get_output(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 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
215 SchedTaskArray::get_outputAddr(int 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 #ifdef __CERIUM_CELL__ |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
218 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
|
219 #else |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
220 return outListData.element[index].addr; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
221 #endif |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
222 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
223 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
224 /** |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
225 * get_output(index) のサイズを返す |
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 int |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
228 SchedTaskArray::get_outputSize(int 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 return outListData.element[index].size; |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
231 } |
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 memaddr |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
234 SchedTaskArray::get_param(int index) |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
235 { |
708 | 236 return *atask->param(index); |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
237 } |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
238 |
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
239 |
695 | 240 /* end */ |