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