Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.cc @ 437:fd44dbd049aa
overlay...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 24 Sep 2009 22:40:58 +0900 |
parents | 799071db126e |
children | 95c0457a7d31 |
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; | |
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 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
328 /** |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
329 * Task load API |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
330 */ |
425 | 331 void |
332 Scheduler::allocate_code_segment(int count, int size) | |
333 { | |
437 | 334 // 既に overlay 領域があるので、それを追加する必要がある... |
425 | 335 code_segment_pool = createMemList(count, size); |
336 } | |
42 | 337 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
338 static void |
cd77224d4224
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) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
340 { |
437 | 341 fprintf(stderr,"loadng task id %d\n",task_id); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
342 MemorySegment *s = m->get_segment( |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
343 task_list[task_id].location, |
437 | 344 m->code_segment_pool, |
345 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
|
346 task_list[task_id].segment = s; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
347 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
348 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
349 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
350 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
|
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 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
354 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
355 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
|
356 { |
437 | 357 fprintf(stderr,"wait load task id %d\n",task_id); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
358 // wait for code segment load |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
359 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
|
360 // calcurate call address |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
361 TaskObjectCreator creator = |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
362 (TaskObjectCreator)( |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
363 (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
|
364 task_list[task_id].entry_offset); |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
365 task_list[task_id].creator = creator; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
366 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
367 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
368 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
369 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
|
370 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
371 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
372 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
373 extern void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
374 register_task(int cmd, TaskObjectCreator creator) |
42 | 375 { |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
395
diff
changeset
|
376 task_list[cmd].creator = creator; |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
377 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
|
378 task_list[cmd].wait = null_waiter; |
42 | 379 } |
373 | 380 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
381 extern void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
382 register_dynamic_task(int cmd, |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
383 memaddr start, memaddr end, int entry_offset) |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
384 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
385 task_list[cmd].creator = 0; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
386 task_list[cmd].location = start; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
387 task_list[cmd].end = end; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
388 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
|
389 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
|
390 task_list[cmd].wait = wait_load; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
391 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
392 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
393 |
373 | 394 /*! |
386 | 395 |
396 size 単位のMemory Segment を count 個作る | |
397 | |
373 | 398 @param [size] リストの要素1つのサイズ |
399 @param [count] 要素数 | |
400 @return allocate した領域のポインタ | |
401 | |
402 */ | |
403 MemList* | |
404 Scheduler::createMemList(int size, int count) | |
405 { | |
406 uint32 head_size = round_up16(sizeof(MemorySegment)); | |
407 uint32 seg_size = round_up16(head_size+size); | |
408 char* mseg = (char*)allocate(seg_size*count); | |
409 MemList* mlist = new MemList((MemorySegment*)mseg); | |
410 | |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
411 if (!hash) { |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
412 hash = new MemHash(); |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
413 } |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
414 |
373 | 415 for(int i = 0; i < count; i++) { |
416 MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); | |
417 char* data = (char*)next+head_size; | |
418 next->data = (void*)data; | |
386 | 419 next->size = size; |
395 | 420 next->address = (memaddr)next; |
373 | 421 mlist->addLast(next); |
422 } | |
423 | |
424 return mlist; | |
425 } | |
386 | 426 |
427 /*! | |
428 | |
429 Main Memory のSegmentを取得する | |
430 | |
431 @param [addr] Main Memory のアドレス | |
432 @param [m] Mem List | |
433 @return allocate した領域のポインタ | |
434 memory directory にあるべきだが... | |
435 | |
436 */ | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
437 MemorySegment * |
386 | 438 Scheduler::get_segment(memaddr addr, MemList *m) |
439 { | |
437 | 440 return get_segment(addr, m, m->size); |
441 } | |
442 | |
443 MemorySegment * | |
444 Scheduler::get_segment(memaddr addr, MemList *m, int size) | |
445 { | |
446 // memory segment のsizeをoverride する場合がある | |
386 | 447 MemorySegment *s = hash->get(addr); |
448 if (s) { | |
449 /* 既に load されている */ | |
391 | 450 m->moveToFirst(s); |
386 | 451 return s; |
452 } | |
453 | |
454 /* LRU なので、もっとも使われてない segment を上書きする */ | |
455 s = m->getLast(); | |
456 m->moveToFirst(s); | |
457 | |
458 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
|
459 s->tag = get_tag(); |
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
460 dma_load(s->data, addr, |
437 | 461 size, s->tag); |
386 | 462 /* 前のをhashから削除 */ |
463 hash->remove(old_addr); | |
464 /* 新しいaddress を登録 */ | |
465 s->address = addr; | |
466 hash->put(s->address, s); | |
467 | |
468 return s; | |
469 } | |
470 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
471 |
386 | 472 uint32 |
473 Scheduler::get_tag() | |
474 { | |
475 return 0; | |
476 } | |
477 | |
478 /*! | |
479 | |
480 Main Memory のSegmentを書き出す | |
481 Segment は get_segement されていて、 | |
482 追い出されていてはいけない。 | |
483 それを保証するのは難しい? | |
484 | |
485 @param [addr] Main Memory のアドレス | |
486 @param [m] Mem List | |
487 @return allocate した領域のポインタ | |
488 | |
489 */ | |
490 void | |
491 Scheduler::put_segment(MemorySegment *s) | |
492 { | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
493 dma_store(s->data, s->address, |
386 | 494 s->size, s->tag); |
495 } | |
496 | |
497 /*! | |
498 | |
499 Main Memory のSegmentを読込、書き出しを待つ | |
500 | |
501 @param [id] MemorySegment のid | |
502 | |
503 */ | |
504 void | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
505 Scheduler::wait_segment(MemorySegment *s) |
386 | 506 { |
391 | 507 // えーと、dma してない時には、skip しないとだめなんじゃないの? |
508 | |
509 if (s->tag) dma_wait(s->tag); | |
510 s->tag = 0; | |
386 | 511 } |
512 | |
513 /* end */ |