Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.cc @ 483:0b933bef0328
renew task worked. but not test_nogl...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 05 Oct 2009 20:29:28 +0900 |
parents | bd5b93d39597 |
children | 4a2c9ff53605 |
rev | line source |
---|---|
48 | 1 #include <stdio.h> |
50 | 2 #include <stdlib.h> |
42 | 3 #include "Scheduler.h" |
4 #include "SchedNop.h" | |
5 #include "error.h" | |
386 | 6 #include <assert.h> |
42 | 7 |
313
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
8 /* |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
9 * Edit kernel/schedule/xx.cc, Cell/spe/xx.cc will be over writen by this. |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
10 * Do not edit Cell/spe/xx.cc unless there is no kernel/schedule/xx.cc files. |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
11 */ |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
12 |
109 | 13 Scheduler::TaskObject task_list[MAX_TASK_OBJECT]; |
14 | |
15 Scheduler::~Scheduler(void) | |
16 { | |
17 delete connector; | |
18 } | |
19 | |
301
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
20 /*! @brief speTaskの入出力のパイプラインバッファを確保する |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
21 */ |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
22 |
42 | 23 void |
24 Scheduler::init(void) | |
25 { | |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
26 hash = 0; |
42 | 27 init_impl(); |
109 | 28 |
29 for (int i = 0; i < 2; i++) { | |
373 | 30 buff_taskList[i] = (TaskListPtr)allocate(sizeof(TaskList)); |
31 buff_inListData[i] = (ListDataPtr)allocate(sizeof(ListData)); | |
32 buff_outListData[i] = (ListDataPtr)allocate(sizeof(ListData)); | |
109 | 33 } |
373 | 34 |
109 | 35 buffFlag_taskList = 0; |
36 buffFlag_inListData = 0; | |
37 buffFlag_outListData = 0; | |
38 flag_renewTaskList = 0; | |
39 | |
298 | 40 // bzero でもいいけど |
109 | 41 for (int i = 0; i < MAX_GLOBAL_AREA; i++) { |
373 | 42 globalList[i] = NULL; |
109 | 43 } |
44 | |
45 for (int i = 0; i < MAX_MAINMEM_AREA; i++) { | |
373 | 46 mainMemList[i] = NULL; |
109 | 47 } |
373 | 48 |
109 | 49 |
50 taskGroup = new TaskGroup; | |
51 renewTop_taskList = NULL; | |
52 renewCur_taskList = NULL; | |
483
0b933bef0328
renew task worked. but not test_nogl...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
468
diff
changeset
|
53 bak_curTaskList = NULL; |
42 | 54 } |
55 | |
56 void | |
57 Scheduler::run(void) | |
58 { | |
59 task1 = new SchedNop(); | |
60 task2 = new SchedNop(); | |
61 task3 = new SchedNop(); | |
62 | |
63 // main loop | |
64 do { | |
373 | 65 __debug("----------\n"); |
66 task3->write(); | |
67 task2->exec(); | |
68 task1->read(); | |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
69 delete task3; |
42 | 70 |
373 | 71 task3 = task2; |
72 task2 = task1; | |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
73 task1 = task1->next(this, 0); |
42 | 74 } while (task1); |
75 | |
76 delete task3; | |
77 delete task2; | |
50 | 78 } |
48 | 79 |
50 | 80 |
81 void | |
82 Scheduler::finish(void) | |
83 { | |
109 | 84 free(buff_taskList[0]); |
85 free(buff_taskList[1]); | |
86 free(buff_inListData[0]); | |
87 free(buff_inListData[1]); | |
88 free(buff_outListData[0]); | |
89 free(buff_outListData[1]); | |
42 | 90 } |
91 | |
109 | 92 /** |
298 | 93 * あらかじめ memory allocte してある TaskList の領域を |
94 * パイプラインの各処理が交代して使う。 | |
109 | 95 */ |
42 | 96 TaskListPtr |
97 Scheduler::get_curListBuf(void) | |
98 { | |
109 | 99 buffFlag_taskList ^= 1; |
100 | |
101 return buff_taskList[buffFlag_taskList]; | |
102 } | |
103 | |
104 | |
105 /** | |
298 | 106 * あらかじめ memory allocte してある ListData の領域を |
107 * パイプラインの各処理が交代して使う。 | |
109 | 108 */ |
109 ListDataPtr | |
110 Scheduler::get_curWriteBuf(void) | |
111 { | |
112 buffFlag_outListData ^= 1; | |
113 return buff_outListData[buffFlag_outListData]; | |
114 } | |
115 | |
116 | |
117 ListDataPtr | |
118 Scheduler::get_curReadBuf(void) | |
119 { | |
120 buffFlag_inListData ^= 1; | |
121 return buff_inListData[buffFlag_inListData]; | |
122 } | |
123 | |
124 /** | |
298 | 125 * タスク内で生成されたタスクを格納する TaskList を取得する |
126 * 現在格納に使っている TaskList (renewCur_taskList) が使えるならそれを返す | |
127 * もしそうでないなら、新しく TaskList を allocate してそれを返す | |
128 * コード中で renewCur_taskList が NULL になるのは | |
129 * - プログラム開始時 | |
130 * - タスク内生成タスクがある TaskList の実行を新しく始める (Nop2Ready 参照) | |
131 * 以上の場合です | |
109 | 132 */ |
133 TaskListPtr | |
134 Scheduler::get_renewListBuf(void) | |
135 { | |
136 if (renewCur_taskList && renewCur_taskList->length < TASK_MAX_SIZE) { | |
373 | 137 return renewCur_taskList; |
109 | 138 } else { |
373 | 139 TaskListPtr newList = (TaskListPtr)allocate(sizeof(TaskList)); |
140 newList->length = 0; | |
141 newList->next = NULL; | |
142 renewTop_taskList = TaskList::append(renewTop_taskList, newList); | |
143 renewCur_taskList = newList; | |
144 return newList; | |
109 | 145 } |
146 } | |
147 | |
184 | 148 /** |
298 | 149 * 次に実行する Renew Task List を返す |
184 | 150 * |
298 | 151 * @param[in] curList 現在実行中の TaskList |
152 * 中断して RenewTaskList を行うため | |
153 * バックアップを取っておく | |
184 | 154 * @return next RenewTaskList |
155 */ | |
156 SchedTaskList* | |
187 | 157 Scheduler::get_nextRenewTaskList(void) |
184 | 158 { |
159 if (renewTop_taskList) { | |
373 | 160 TaskListPtr list = renewTop_taskList; |
161 renewTop_taskList = renewTop_taskList->next; | |
162 renewCur_taskList = NULL; | |
233 | 163 |
373 | 164 list->next = NULL; |
165 SchedTaskList *sched | |
166 = createSchedTaskList((uint32)list, this, SCHED_TASKLIST_RENEW); | |
167 return sched; | |
184 | 168 } else { |
373 | 169 return NULL; |
184 | 170 } |
171 } | |
172 | |
187 | 173 void |
174 Scheduler::set_backupTaskList(TaskListPtr cur_taskList) | |
175 { | |
176 bak_curTaskList = cur_taskList; | |
177 } | |
178 | |
179 void | |
180 Scheduler::set_backupTaskListIndex(int cur_index) | |
181 { | |
182 bakIndex_taskList = cur_index; | |
183 } | |
184 | |
184 | 185 /** |
298 | 186 * RenewTaskList 実行前に中断した TaskList を返す |
187 * NULL の場合、中断した TaskList は無い。 | |
184 | 188 * |
189 * @return TaskList | |
190 */ | |
191 TaskListPtr | |
192 Scheduler::get_backupTaskList(void) | |
193 { | |
187 | 194 TaskListPtr ret = bak_curTaskList; |
373 | 195 |
187 | 196 bak_curTaskList = NULL; |
197 return ret; | |
198 } | |
199 | |
200 int | |
201 Scheduler::get_backupTaskListIndex(void) | |
202 { | |
203 int ret = bakIndex_taskList; | |
204 | |
205 bakIndex_taskList = 0; | |
206 return ret; | |
184 | 207 } |
208 | |
109 | 209 void |
210 Scheduler::dma_load(void *buf, uint32 addr, uint32 size, uint32 mask) | |
211 { | |
212 connector->dma_load(buf, addr, size, mask); | |
213 } | |
214 | |
215 void | |
216 Scheduler::dma_store(void *buf, uint32 addr, uint32 size, uint32 mask) | |
217 { | |
218 connector->dma_store(buf, addr, size, mask); | |
219 } | |
220 | |
221 void | |
222 Scheduler::dma_wait(uint32 mask) | |
223 { | |
224 connector->dma_wait(mask); | |
225 } | |
226 | |
227 void | |
228 Scheduler::dma_loadList(ListDataPtr list, void *buff, uint32 mask) | |
229 { | |
230 connector->dma_loadList(list, buff, mask); | |
42 | 231 } |
232 | |
233 | |
109 | 234 void |
235 Scheduler::dma_storeList(ListDataPtr list, void *buff, uint32 mask) | |
236 { | |
237 return connector->dma_storeList(list, buff, mask); | |
238 } | |
239 | |
240 void | |
241 Scheduler::mail_write(uint32 data) | |
242 { | |
243 connector->mail_write(data); | |
244 } | |
245 | |
246 uint32 | |
247 Scheduler::mail_read(void) | |
248 { | |
249 return connector->mail_read(); | |
250 } | |
251 | |
252 TaskGroupPtr | |
253 Scheduler::set_groupTask(uint32 command) | |
254 { | |
255 TaskGroupPtr ret = taskGroup; | |
256 | |
257 reload_groupTask(); | |
258 | |
259 ret->command = command; | |
260 return ret; | |
261 } | |
262 | |
263 void | |
264 Scheduler::add_groupTask(TaskGroupPtr group, TaskPtr task) | |
265 { | |
266 group->add(task); | |
267 } | |
268 | |
269 void | |
270 Scheduler::remove_groupTask(TaskGroupPtr group, TaskPtr task) | |
42 | 271 { |
109 | 272 group->remove(task); |
273 } | |
274 | |
275 void | |
276 Scheduler::reload_groupTask(void) | |
277 { | |
278 taskGroup = new TaskGroup; | |
279 } | |
280 | |
281 uint32 | |
282 Scheduler::status_groupTask(TaskGroupPtr group) | |
283 { | |
284 return group->status(); | |
285 } | |
286 | |
386 | 287 /* |
288 ここから下は、memory 以下にあるべき | |
289 */ | |
290 | |
109 | 291 void* |
292 Scheduler::global_alloc(int id, int size) | |
293 { | |
294 globalList[id] = allocate(size); | |
295 return globalList[id]; | |
296 } | |
297 | |
298 void* | |
299 Scheduler::global_get(int id) | |
300 { | |
301 return globalList[id]; | |
302 } | |
303 | |
304 void | |
373 | 305 Scheduler::global_set(int id, void *addr) |
306 { | |
307 globalList[id] = addr; | |
308 } | |
309 | |
310 void | |
109 | 311 Scheduler::global_free(int id) |
312 { | |
313 free(globalList[id]); | |
314 globalList[id] = NULL; | |
315 } | |
316 | |
317 /** | |
298 | 318 * mainMem_alloc で確保したメインメモリの領域アドレスを返す。 |
319 * これは Fifo, Cell で共通 | |
109 | 320 */ |
321 void* | |
322 Scheduler::mainMem_get(int id) | |
323 { | |
324 return mainMemList[id]; | |
42 | 325 } |
326 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
327 /** |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
328 * Task load API |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
329 */ |
425 | 330 void |
442 | 331 Scheduler::allocate_code_segment(int size, int count) |
425 | 332 { |
437 | 333 // 既に overlay 領域があるので、それを追加する必要がある... |
442 | 334 code_segment_pool = createMemList(size, count); |
425 | 335 } |
42 | 336 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
337 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
338 load_task(Scheduler *m, int task_id) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
339 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
340 MemorySegment *s = m->get_segment( |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
341 task_list[task_id].location, |
437 | 342 m->code_segment_pool, |
343 task_list[task_id].end-task_list[task_id].location); | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
344 task_list[task_id].segment = s; |
461 | 345 |
346 fprintf(stderr,"loadng task id %d at 0x%x entry 0x%x\n",task_id, | |
347 (unsigned int)(task_list[task_id].segment->data ), | |
348 (unsigned int)( | |
349 (char*)task_list[task_id].segment->data + | |
350 task_list[task_id].entry_offset)); | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
351 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
352 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
353 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
354 null_loader(Scheduler *m, int task_id) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
355 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
356 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
357 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
358 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
359 wait_load(Scheduler *m, int task_id) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
360 { |
442 | 361 MemorySegment *s = task_list[task_id].segment; |
362 if (s) | |
363 fprintf(stderr,"wait load task id %d 0x%x\n",task_id,(int)s->data); | |
364 else | |
365 fprintf(stderr,"wait load task id %d 000000\n",task_id); | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
366 // wait for code segment load |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
367 m->wait_segment(task_list[task_id].segment); |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
368 // calcurate call address |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
369 TaskObjectRun run = |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
370 (TaskObjectRun)( |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
371 (char*)task_list[task_id].segment->data + |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
372 task_list[task_id].entry_offset); |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
373 task_list[task_id].run = run; |
439 | 374 fprintf(stderr,"wait load task id %d done. creator = 0x%x entry_offset = 0x%x\n",task_id, |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
375 (unsigned int)run, |
439 | 376 task_list[task_id].entry_offset); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
377 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
378 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
379 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
380 null_waiter(Scheduler *m, int task_id) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
381 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
382 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
383 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
384 extern void |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
385 register_task(int cmd, TaskObjectRun run) |
42 | 386 { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
387 task_list[cmd].run = run; |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
388 task_list[cmd].load = null_loader; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
389 task_list[cmd].wait = null_waiter; |
42 | 390 } |
373 | 391 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
392 extern void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
393 register_dynamic_task(int cmd, |
441 | 394 memaddr start, int size, |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
395 TaskObjectRun run, int entry_offset) |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
396 { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
397 task_list[cmd].run = run; |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
398 task_list[cmd].location = start; |
442 | 399 size &= 0xfffffffe; |
441 | 400 task_list[cmd].end = start+size; |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
401 task_list[cmd].entry_offset = entry_offset; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
402 task_list[cmd].load = load_task; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
403 task_list[cmd].wait = wait_load; |
439 | 404 fprintf(stderr,"cmd = %d\n",cmd); |
441 | 405 fprintf(stderr,"locatation = 0x%x\n",start); |
406 fprintf(stderr,"end = 0x%x\n",start+size); | |
407 fprintf(stderr,"size = 0x%x\n",size); | |
439 | 408 fprintf(stderr,"entry = 0x%x\n",entry_offset); |
409 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
410 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
411 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
412 |
373 | 413 /*! |
386 | 414 |
415 size 単位のMemory Segment を count 個作る | |
416 | |
373 | 417 @param [size] リストの要素1つのサイズ |
418 @param [count] 要素数 | |
419 @return allocate した領域のポインタ | |
420 | |
421 */ | |
422 MemList* | |
423 Scheduler::createMemList(int size, int count) | |
424 { | |
425 uint32 head_size = round_up16(sizeof(MemorySegment)); | |
426 uint32 seg_size = round_up16(head_size+size); | |
427 char* mseg = (char*)allocate(seg_size*count); | |
428 MemList* mlist = new MemList((MemorySegment*)mseg); | |
429 | |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
430 if (!hash) { |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
431 hash = new MemHash(); |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
432 } |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
433 |
373 | 434 for(int i = 0; i < count; i++) { |
435 MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); | |
436 char* data = (char*)next+head_size; | |
437 next->data = (void*)data; | |
386 | 438 next->size = size; |
395 | 439 next->address = (memaddr)next; |
373 | 440 mlist->addLast(next); |
441 } | |
442 | |
443 return mlist; | |
444 } | |
386 | 445 |
446 /*! | |
447 | |
448 Main Memory のSegmentを取得する | |
449 | |
450 @param [addr] Main Memory のアドレス | |
451 @param [m] Mem List | |
452 @return allocate した領域のポインタ | |
453 memory directory にあるべきだが... | |
454 | |
455 */ | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
456 MemorySegment * |
386 | 457 Scheduler::get_segment(memaddr addr, MemList *m) |
458 { | |
449
4f11245e3504
get_segment fixed. and test_nogl rollback to 426. move!
kazz@henri.cr.ie.u-ryukyu.ac.jp
parents:
442
diff
changeset
|
459 MemorySegment *s = m->getFirst(); |
4f11245e3504
get_segment fixed. and test_nogl rollback to 426. move!
kazz@henri.cr.ie.u-ryukyu.ac.jp
parents:
442
diff
changeset
|
460 return get_segment(addr, m, s->size); |
437 | 461 } |
462 | |
463 MemorySegment * | |
464 Scheduler::get_segment(memaddr addr, MemList *m, int size) | |
465 { | |
466 // memory segment のsizeをoverride する場合がある | |
386 | 467 MemorySegment *s = hash->get(addr); |
468 if (s) { | |
469 /* 既に load されている */ | |
439 | 470 // fprintf(stderr,"get_segement loaded %llx 0x%x size 0x%d\n",addr,s->data,size); |
391 | 471 m->moveToFirst(s); |
386 | 472 return s; |
473 } | |
474 | |
475 /* LRU なので、もっとも使われてない segment を上書きする */ | |
476 s = m->getLast(); | |
477 m->moveToFirst(s); | |
478 | |
479 memaddr old_addr = s->address; | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
480 s->tag = get_tag(); |
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
481 dma_load(s->data, addr, |
437 | 482 size, s->tag); |
386 | 483 /* 前のをhashから削除 */ |
484 hash->remove(old_addr); | |
485 /* 新しいaddress を登録 */ | |
486 s->address = addr; | |
487 hash->put(s->address, s); | |
488 | |
439 | 489 // fprintf(stderr,"get_segement %llx 0x%x size 0x%d\n",addr, s->data,size); |
490 | |
386 | 491 return s; |
492 } | |
493 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
494 |
386 | 495 uint32 |
496 Scheduler::get_tag() | |
497 { | |
458 | 498 static int tag = 16; |
499 tag ++; | |
500 tag &= 0x0f; | |
501 return tag+16; | |
386 | 502 } |
503 | |
504 /*! | |
505 | |
506 Main Memory のSegmentを書き出す | |
507 Segment は get_segement されていて、 | |
508 追い出されていてはいけない。 | |
509 それを保証するのは難しい? | |
510 | |
511 @param [addr] Main Memory のアドレス | |
512 @param [m] Mem List | |
513 @return allocate した領域のポインタ | |
514 | |
515 */ | |
516 void | |
517 Scheduler::put_segment(MemorySegment *s) | |
518 { | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
519 dma_store(s->data, s->address, |
386 | 520 s->size, s->tag); |
521 } | |
522 | |
523 /*! | |
524 | |
525 Main Memory のSegmentを読込、書き出しを待つ | |
526 | |
527 @param [id] MemorySegment のid | |
528 | |
529 */ | |
530 void | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
531 Scheduler::wait_segment(MemorySegment *s) |
386 | 532 { |
391 | 533 // えーと、dma してない時には、skip しないとだめなんじゃないの? |
534 | |
535 if (s->tag) dma_wait(s->tag); | |
536 s->tag = 0; | |
386 | 537 } |
538 | |
539 /* end */ |