Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.cc @ 685:b386522827ae
Bulk task on going.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 07 Dec 2009 00:32:34 +0900 |
parents | 458a1ad91427 |
children | dcaa40ec963d |
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> |
621 | 7 #include "TaskManagerImpl.h" |
42 | 8 |
313
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
9 /* |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
10 * 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
|
11 * 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
|
12 */ |
c9f8cfcdc5c2
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
13 |
109 | 14 Scheduler::TaskObject task_list[MAX_TASK_OBJECT]; |
15 | |
501
4a2c9ff53605
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
16 Scheduler::~Scheduler() |
109 | 17 { |
18 delete connector; | |
19 } | |
20 | |
664 | 21 static int |
22 null_run(SchedTask* smanager, void* r, void *w) | |
23 { | |
24 printf("Calling Undefined Task\n"); | |
25 return 0; | |
26 } | |
27 | |
684
458a1ad91427
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
28 static void null_loader(Scheduler *m, int task_id); |
458a1ad91427
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
29 |
301
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
30 /*! @brief speTaskの入出力のパイプラインバッファを確保する |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
31 */ |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
32 |
42 | 33 void |
635
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
34 Scheduler::init(TaskManagerImpl *m) |
42 | 35 { |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
36 hash = 0; |
664 | 37 |
38 for (int i = 0; i< MAX_TASK_OBJECT; i++) { | |
684
458a1ad91427
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
39 task_list[i].run = null_run; |
458a1ad91427
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
40 task_list[i].load = null_loader; |
458a1ad91427
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
41 task_list[i].wait = null_loader; |
664 | 42 } |
43 | |
635
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
44 set_manager(m); |
42 | 45 init_impl(); |
109 | 46 |
47 for (int i = 0; i < 2; i++) { | |
373 | 48 buff_taskList[i] = (TaskListPtr)allocate(sizeof(TaskList)); |
109 | 49 } |
373 | 50 |
109 | 51 buffFlag_taskList = 0; |
52 | |
298 | 53 // bzero でもいいけど |
109 | 54 for (int i = 0; i < MAX_GLOBAL_AREA; i++) { |
373 | 55 globalList[i] = NULL; |
109 | 56 } |
57 | |
58 for (int i = 0; i < MAX_MAINMEM_AREA; i++) { | |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
59 mainMemList[i] = (memaddr)NULL; |
109 | 60 } |
373 | 61 |
109 | 62 |
42 | 63 } |
64 | |
65 void | |
685 | 66 Scheduler::run(SchedTaskBase* task1) |
42 | 67 { |
685 | 68 |
69 // Pipeline Stage | |
70 SchedTaskBase* task2 = new SchedNop(); | |
71 SchedTaskBase* task3 = new SchedNop(); | |
42 | 72 |
73 // main loop | |
74 do { | |
373 | 75 __debug("----------\n"); |
76 task3->write(); | |
77 task2->exec(); | |
78 task1->read(); | |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
79 delete task3; |
42 | 80 |
373 | 81 task3 = task2; |
82 task2 = task1; | |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
83 task1 = task1->next(this, 0); |
42 | 84 } while (task1); |
85 | |
86 delete task3; | |
87 delete task2; | |
50 | 88 } |
48 | 89 |
50 | 90 |
91 void | |
501
4a2c9ff53605
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
92 Scheduler::finish() |
50 | 93 { |
109 | 94 free(buff_taskList[0]); |
95 free(buff_taskList[1]); | |
42 | 96 } |
97 | |
109 | 98 /** |
298 | 99 * あらかじめ memory allocte してある TaskList の領域を |
100 * パイプラインの各処理が交代して使う。 | |
109 | 101 */ |
42 | 102 TaskListPtr |
501
4a2c9ff53605
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
103 Scheduler::get_curListBuf() |
42 | 104 { |
109 | 105 buffFlag_taskList ^= 1; |
106 | |
107 return buff_taskList[buffFlag_taskList]; | |
108 } | |
109 | |
110 | |
111 void | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
112 Scheduler::dma_load(void *buf, memaddr addr, uint32 size, uint32 mask) |
109 | 113 { |
114 connector->dma_load(buf, addr, size, mask); | |
115 } | |
116 | |
117 void | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
118 Scheduler::dma_store(void *buf, memaddr addr, uint32 size, uint32 mask) |
109 | 119 { |
120 connector->dma_store(buf, addr, size, mask); | |
121 } | |
122 | |
123 void | |
124 Scheduler::dma_wait(uint32 mask) | |
125 { | |
126 connector->dma_wait(mask); | |
127 } | |
128 | |
129 void | |
130 Scheduler::dma_loadList(ListDataPtr list, void *buff, uint32 mask) | |
131 { | |
132 connector->dma_loadList(list, buff, mask); | |
42 | 133 } |
134 | |
135 | |
109 | 136 void |
137 Scheduler::dma_storeList(ListDataPtr list, void *buff, uint32 mask) | |
138 { | |
139 return connector->dma_storeList(list, buff, mask); | |
140 } | |
141 | |
142 void | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
143 Scheduler::mail_write(memaddr data) |
109 | 144 { |
145 connector->mail_write(data); | |
146 } | |
147 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
148 memaddr |
501
4a2c9ff53605
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
149 Scheduler::mail_read() |
109 | 150 { |
151 return connector->mail_read(); | |
152 } | |
153 | |
154 | |
386 | 155 /* |
156 ここから下は、memory 以下にあるべき | |
157 */ | |
158 | |
109 | 159 void* |
160 Scheduler::global_alloc(int id, int size) | |
161 { | |
162 globalList[id] = allocate(size); | |
163 return globalList[id]; | |
164 } | |
165 | |
166 void* | |
167 Scheduler::global_get(int id) | |
168 { | |
169 return globalList[id]; | |
170 } | |
171 | |
172 void | |
373 | 173 Scheduler::global_set(int id, void *addr) |
174 { | |
175 globalList[id] = addr; | |
176 } | |
177 | |
178 void | |
109 | 179 Scheduler::global_free(int id) |
180 { | |
181 free(globalList[id]); | |
182 globalList[id] = NULL; | |
183 } | |
184 | |
185 /** | |
298 | 186 * mainMem_alloc で確保したメインメモリの領域アドレスを返す。 |
187 * これは Fifo, Cell で共通 | |
109 | 188 */ |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
189 memaddr |
109 | 190 Scheduler::mainMem_get(int id) |
191 { | |
192 return mainMemList[id]; | |
42 | 193 } |
194 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
195 /** |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
196 * Task load API |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
197 */ |
425 | 198 void |
442 | 199 Scheduler::allocate_code_segment(int size, int count) |
425 | 200 { |
437 | 201 // 既に overlay 領域があるので、それを追加する必要がある... |
442 | 202 code_segment_pool = createMemList(size, count); |
425 | 203 } |
42 | 204 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
205 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
206 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
|
207 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
208 MemorySegment *s = m->get_segment( |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
209 task_list[task_id].location, |
437 | 210 m->code_segment_pool, |
211 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
|
212 task_list[task_id].segment = s; |
506 | 213 #if 0 |
461 | 214 fprintf(stderr,"loadng task id %d at 0x%x entry 0x%x\n",task_id, |
215 (unsigned int)(task_list[task_id].segment->data ), | |
216 (unsigned int)( | |
217 (char*)task_list[task_id].segment->data + | |
218 task_list[task_id].entry_offset)); | |
506 | 219 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
220 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
221 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
222 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
223 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
|
224 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
225 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
226 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
227 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
228 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
|
229 { |
523 | 230 #if 0 |
442 | 231 MemorySegment *s = task_list[task_id].segment; |
232 if (s) | |
233 fprintf(stderr,"wait load task id %d 0x%x\n",task_id,(int)s->data); | |
234 else | |
235 fprintf(stderr,"wait load task id %d 000000\n",task_id); | |
506 | 236 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
237 // wait for code segment load |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
238 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
|
239 // calcurate call address |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
240 TaskObjectRun run = |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
241 (TaskObjectRun)( |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
242 (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
|
243 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
|
244 task_list[task_id].run = run; |
506 | 245 #if 0 |
439 | 246 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
|
247 (unsigned int)run, |
439 | 248 task_list[task_id].entry_offset); |
506 | 249 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
250 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
251 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
252 static void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
253 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
|
254 { |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
255 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
256 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
257 extern void |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
258 register_task(int cmd, TaskObjectRun run) |
42 | 259 { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
260 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
|
261 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
|
262 task_list[cmd].wait = null_waiter; |
42 | 263 } |
373 | 264 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
265 extern void |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
266 register_dynamic_task(int cmd, |
441 | 267 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
|
268 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
|
269 { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
270 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
|
271 task_list[cmd].location = start; |
442 | 272 size &= 0xfffffffe; |
441 | 273 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
|
274 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
|
275 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
|
276 task_list[cmd].wait = wait_load; |
506 | 277 #if 0 |
439 | 278 fprintf(stderr,"cmd = %d\n",cmd); |
441 | 279 fprintf(stderr,"locatation = 0x%x\n",start); |
280 fprintf(stderr,"end = 0x%x\n",start+size); | |
281 fprintf(stderr,"size = 0x%x\n",size); | |
439 | 282 fprintf(stderr,"entry = 0x%x\n",entry_offset); |
506 | 283 #endif |
439 | 284 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
285 } |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
286 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
287 |
373 | 288 /*! |
386 | 289 |
290 size 単位のMemory Segment を count 個作る | |
291 | |
373 | 292 @param [size] リストの要素1つのサイズ |
293 @param [count] 要素数 | |
294 @return allocate した領域のポインタ | |
295 | |
296 */ | |
297 MemList* | |
298 Scheduler::createMemList(int size, int count) | |
299 { | |
300 uint32 head_size = round_up16(sizeof(MemorySegment)); | |
301 uint32 seg_size = round_up16(head_size+size); | |
302 char* mseg = (char*)allocate(seg_size*count); | |
303 MemList* mlist = new MemList((MemorySegment*)mseg); | |
304 | |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
305 if (!hash) { |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
306 hash = new MemHash(); |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
307 } |
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
308 |
373 | 309 for(int i = 0; i < count; i++) { |
310 MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); | |
311 char* data = (char*)next+head_size; | |
312 next->data = (void*)data; | |
386 | 313 next->size = size; |
395 | 314 next->address = (memaddr)next; |
373 | 315 mlist->addLast(next); |
316 } | |
317 | |
318 return mlist; | |
319 } | |
386 | 320 |
321 /*! | |
322 | |
323 Main Memory のSegmentを取得する | |
324 | |
325 @param [addr] Main Memory のアドレス | |
326 @param [m] Mem List | |
327 @return allocate した領域のポインタ | |
328 memory directory にあるべきだが... | |
329 | |
330 */ | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
331 MemorySegment * |
386 | 332 Scheduler::get_segment(memaddr addr, MemList *m) |
333 { | |
449
4f11245e3504
get_segment fixed. and test_nogl rollback to 426. move!
kazz@henri.cr.ie.u-ryukyu.ac.jp
parents:
442
diff
changeset
|
334 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
|
335 return get_segment(addr, m, s->size); |
437 | 336 } |
337 | |
338 MemorySegment * | |
339 Scheduler::get_segment(memaddr addr, MemList *m, int size) | |
340 { | |
341 // memory segment のsizeをoverride する場合がある | |
386 | 342 MemorySegment *s = hash->get(addr); |
343 if (s) { | |
344 /* 既に load されている */ | |
439 | 345 // fprintf(stderr,"get_segement loaded %llx 0x%x size 0x%d\n",addr,s->data,size); |
391 | 346 m->moveToFirst(s); |
386 | 347 return s; |
348 } | |
349 | |
350 /* LRU なので、もっとも使われてない segment を上書きする */ | |
351 s = m->getLast(); | |
352 m->moveToFirst(s); | |
353 | |
354 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
|
355 s->tag = get_tag(); |
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
356 dma_load(s->data, addr, |
437 | 357 size, s->tag); |
386 | 358 /* 前のをhashから削除 */ |
359 hash->remove(old_addr); | |
360 /* 新しいaddress を登録 */ | |
361 s->address = addr; | |
362 hash->put(s->address, s); | |
363 | |
439 | 364 // fprintf(stderr,"get_segement %llx 0x%x size 0x%d\n",addr, s->data,size); |
365 | |
386 | 366 return s; |
367 } | |
368 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
369 |
386 | 370 uint32 |
371 Scheduler::get_tag() | |
372 { | |
458 | 373 static int tag = 16; |
374 tag ++; | |
375 tag &= 0x0f; | |
376 return tag+16; | |
386 | 377 } |
378 | |
379 /*! | |
380 | |
381 Main Memory のSegmentを書き出す | |
382 Segment は get_segement されていて、 | |
383 追い出されていてはいけない。 | |
384 それを保証するのは難しい? | |
385 | |
386 @param [addr] Main Memory のアドレス | |
387 @param [m] Mem List | |
388 @return allocate した領域のポインタ | |
389 | |
390 */ | |
391 void | |
392 Scheduler::put_segment(MemorySegment *s) | |
393 { | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
394 dma_store(s->data, s->address, |
386 | 395 s->size, s->tag); |
396 } | |
397 | |
398 /*! | |
399 | |
400 Main Memory のSegmentを読込、書き出しを待つ | |
401 | |
402 @param [id] MemorySegment のid | |
403 | |
404 */ | |
405 void | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
406 Scheduler::wait_segment(MemorySegment *s) |
386 | 407 { |
391 | 408 // えーと、dma してない時には、skip しないとだめなんじゃないの? |
409 | |
410 if (s->tag) dma_wait(s->tag); | |
411 s->tag = 0; | |
386 | 412 } |
413 | |
621 | 414 HTask * Scheduler::create_task(int cmd) { return manager->create_task(cmd); } |
634 | 415 HTaskPtr Scheduler::create_task(int cmd, memaddr r, long rs, memaddr w, long ws) { |
416 return manager->create_task(cmd,r,rs,w,ws); | |
417 } | |
418 | |
621 | 419 void Scheduler::set_task_depend(HTask * master, HTask * slave) { |
420 manager->set_task_depend(master, slave) ; | |
421 } | |
422 void Scheduler::spawn_task(HTask * t) { manager->spawn_task(t); } | |
423 void Scheduler::set_task_cpu(HTask * t, CPU_TYPE cpu) { manager->set_task_cpu(t,cpu); } | |
635
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
424 void* Scheduler::allocate(int size,int align) { return manager->allocate(size,align); } |
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
425 void* Scheduler::allocate(int size) { return manager->allocate(size,DEFAULT_ALIGNMENT); } |
621 | 426 long Scheduler::get_random() { |
427 #if defined(__SPU__) | |
428 return 0; | |
429 #else | |
430 return random(); | |
431 #endif | |
432 | |
433 } | |
434 | |
386 | 435 /* end */ |