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