Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/schedule/Scheduler.cc @ 1229:424c1f16e704 draft
add args useRefDma
author | Daichi TOMA <e085740@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 24 Aug 2011 07:45:27 +0900 |
parents | a49c02dffe6f |
children | 6b4a0846afcb |
rev | line source |
---|---|
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1124
diff
changeset
|
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" |
923
382a48afb061
fix DMA/Mail wait profiler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
893
diff
changeset
|
7 #include "SysFunc.h" |
42 | 8 #include "error.h" |
386 | 9 #include <assert.h> |
621 | 10 #include "TaskManagerImpl.h" |
42 | 11 |
313
25dfa7499162
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
12 /* |
25dfa7499162
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
13 * 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
|
14 * 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
|
15 */ |
25dfa7499162
fix ppu mail box waiting (mainMem allocate)
kono@localhost.localdomain
parents:
301
diff
changeset
|
16 |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
690
diff
changeset
|
17 TaskObject task_list[MAX_TASK_OBJECT]; |
109 | 18 |
1147 | 19 #ifndef NOT_CHECK |
20 int entry_cmd[MAX_TASK_OBJECT]; | |
21 int task_count = 0; | |
22 #endif | |
23 | |
501
7ddbe22d4cdb
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
24 Scheduler::~Scheduler() |
109 | 25 { |
26 delete connector; | |
27 } | |
28 | |
664 | 29 static int |
30 null_run(SchedTask* smanager, void* r, void *w) | |
31 { | |
923
382a48afb061
fix DMA/Mail wait profiler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
893
diff
changeset
|
32 smanager->printf("Calling Undefined Task %d\n", smanager->task->command==TaskArray1? smanager->atask->command: smanager->task->command); |
664 | 33 return 0; |
34 } | |
35 | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
36 static void null_loader(Scheduler *m, int task_id); |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
37 |
301
7f991471d43f
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
38 /*! @brief speTaskの入出力のパイプラインバッファを確保する |
7f991471d43f
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
39 */ |
7f991471d43f
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
40 |
1229
424c1f16e704
add args useRefDma
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1213
diff
changeset
|
41 //useRefDmaは、0という初期値が設定されている。 |
42 | 42 void |
1229
424c1f16e704
add args useRefDma
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1213
diff
changeset
|
43 Scheduler::init(TaskManagerImpl *m, int useRefDma) |
42 | 44 { |
388
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
45 hash = 0; |
664 | 46 |
1147 | 47 #ifndef NOT_CHECK |
48 task_count = 0; | |
49 #endif | |
50 | |
664 | 51 for (int i = 0; i< MAX_TASK_OBJECT; i++) { |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
52 task_list[i].run = null_run; |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
53 task_list[i].load = null_loader; |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
664
diff
changeset
|
54 task_list[i].wait = null_loader; |
1147 | 55 |
56 #ifndef NOT_CHECK | |
57 entry_cmd[i] = NULL; | |
58 #endif | |
59 | |
664 | 60 } |
61 | |
635
c56f6847fb87
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
62 set_manager(m); |
1229
424c1f16e704
add args useRefDma
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1213
diff
changeset
|
63 init_impl(useRefDma); |
109 | 64 |
65 for (int i = 0; i < 2; i++) { | |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
792
diff
changeset
|
66 buff_taskList[i] = (TaskListPtr)m->allocate(sizeof(TaskList)); |
109 | 67 } |
373 | 68 |
109 | 69 buffFlag_taskList = 0; |
70 | |
298 | 71 // bzero でもいいけど |
109 | 72 for (int i = 0; i < MAX_GLOBAL_AREA; i++) { |
373 | 73 globalList[i] = NULL; |
109 | 74 } |
75 | |
76 for (int i = 0; i < MAX_MAINMEM_AREA; i++) { | |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
77 mainMemList[i] = (memaddr)NULL; |
109 | 78 } |
373 | 79 |
42 | 80 } |
81 | |
82 void | |
690 | 83 Scheduler::run(SchedTaskBase* task1) |
42 | 84 { |
690 | 85 |
86 // Pipeline Stage | |
87 SchedTaskBase* task2 = new SchedNop(); | |
88 SchedTaskBase* task3 = new SchedNop(); | |
42 | 89 // main loop |
90 do { | |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
923
diff
changeset
|
91 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
923
diff
changeset
|
92 task1->read(); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
923
diff
changeset
|
93 task2->exec(); |
1015 | 94 task3->write(); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
923
diff
changeset
|
95 |
468
796f72cb21d9
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
96 delete task3; |
42 | 97 |
373 | 98 task3 = task2; |
99 task2 = task1; | |
1015 | 100 //SchedMailの場合、Mailの待ちが入る |
893
2faa1f62d925
fix SimpleTask alignment
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
874
diff
changeset
|
101 task1 = task1->next(this, 0); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
923
diff
changeset
|
102 |
42 | 103 } while (task1); |
104 | |
105 delete task3; | |
106 delete task2; | |
50 | 107 } |
48 | 108 |
50 | 109 |
110 void | |
501
7ddbe22d4cdb
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
111 Scheduler::finish() |
50 | 112 { |
109 | 113 free(buff_taskList[0]); |
114 free(buff_taskList[1]); | |
42 | 115 } |
116 | |
109 | 117 /** |
298 | 118 * あらかじめ memory allocte してある TaskList の領域を |
119 * パイプラインの各処理が交代して使う。 | |
109 | 120 */ |
42 | 121 TaskListPtr |
501
7ddbe22d4cdb
Cell inData/outData DMA removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
483
diff
changeset
|
122 Scheduler::get_curListBuf() |
42 | 123 { |
109 | 124 buffFlag_taskList ^= 1; |
125 | |
126 return buff_taskList[buffFlag_taskList]; | |
127 } | |
128 | |
871
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
129 |
386 | 130 /* |
131 ここから下は、memory 以下にあるべき | |
132 */ | |
133 | |
109 | 134 void* |
135 Scheduler::global_alloc(int id, int size) | |
136 { | |
792 | 137 |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
792
diff
changeset
|
138 globalList[id] = manager->allocate(size); |
792 | 139 |
109 | 140 return globalList[id]; |
141 } | |
142 | |
143 void* | |
144 Scheduler::global_get(int id) | |
145 { | |
146 return globalList[id]; | |
147 } | |
148 | |
149 void | |
373 | 150 Scheduler::global_set(int id, void *addr) |
151 { | |
152 globalList[id] = addr; | |
153 } | |
154 | |
155 void | |
109 | 156 Scheduler::global_free(int id) |
157 { | |
158 free(globalList[id]); | |
159 globalList[id] = NULL; | |
160 } | |
161 | |
162 /** | |
298 | 163 * mainMem_alloc で確保したメインメモリの領域アドレスを返す。 |
164 * これは Fifo, Cell で共通 | |
109 | 165 */ |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
166 memaddr |
109 | 167 Scheduler::mainMem_get(int id) |
168 { | |
169 return mainMemList[id]; | |
42 | 170 } |
171 | |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
172 /** |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
173 * Task load API |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
174 */ |
425 | 175 void |
872 | 176 Scheduler::allocate_code_segment(int size, int count, struct tbl *table) |
425 | 177 { |
437 | 178 // 既に overlay 領域があるので、それを追加する必要がある... |
442 | 179 code_segment_pool = createMemList(size, count); |
872 | 180 if (table) { |
181 MemorySegment* here = (MemorySegment*)( | |
182 manager->allocate(sizeof(MemorySegment))); | |
183 here->data = (void*)(table->vma); | |
184 here->size = size; | |
185 here->address = (memaddr)here; | |
186 code_segment_pool->addLast(here); | |
187 } | |
425 | 188 } |
42 | 189 |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
190 static void |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
191 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
|
192 { |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
193 MemorySegment *s = m->get_segment( |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
194 task_list[task_id].location, |
437 | 195 m->code_segment_pool, |
196 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
|
197 task_list[task_id].segment = s; |
871
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
198 // calcurate call address |
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
199 TaskObjectRun run = |
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
200 (TaskObjectRun)( |
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
201 (char*)task_list[task_id].segment->data + |
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
202 task_list[task_id].entry_offset); |
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
203 task_list[task_id].run = run; |
874 | 204 #if 0 |
873
c50f39fbb6ca
fix hash problem ( unsigned int-> long overflow )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
872
diff
changeset
|
205 m->printf("loadng task id %d at 0x%x entry 0x%x location 0x%x\n",task_id, |
461 | 206 (unsigned int)(task_list[task_id].segment->data ), |
207 (unsigned int)( | |
208 (char*)task_list[task_id].segment->data + | |
873
c50f39fbb6ca
fix hash problem ( unsigned int-> long overflow )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
872
diff
changeset
|
209 task_list[task_id].entry_offset), |
c50f39fbb6ca
fix hash problem ( unsigned int-> long overflow )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
872
diff
changeset
|
210 task_list[task_id].location); |
538 | 211 #endif |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
212 } |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
213 |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
214 static void |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
215 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
|
216 { |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
217 } |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
218 |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
219 static void |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
220 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
|
221 { |
555 | 222 #if 0 |
442 | 223 MemorySegment *s = task_list[task_id].segment; |
224 if (s) | |
736 | 225 m->printf("wait load task id %d 0x%x\n",task_id,(int)s->data); |
442 | 226 else |
736 | 227 m->printf("wait load task id %d 000000\n",task_id); |
538 | 228 #endif |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
229 // wait for code segment load |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
230 m->wait_segment(task_list[task_id].segment); |
538 | 231 #if 0 |
736 | 232 m->printf("wait load task id %d done. creator = 0x%x entry_offset = 0x%x\n",task_id, |
871
d30617ef4b20
fix get segment dma tag zero problem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
804
diff
changeset
|
233 (unsigned int)(task_list[task_id].run), |
439 | 234 task_list[task_id].entry_offset); |
538 | 235 #endif |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
236 } |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
237 |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
238 static void |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
239 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
|
240 { |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
241 } |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
242 |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
243 extern void |
1058
d3cb29f1eccb
create task_name_list array in Scheduler.h
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1024
diff
changeset
|
244 register_task(int cmd, TaskObjectRun run, const char *str) |
42 | 245 { |
464
0d64bdb63005
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
246 task_list[cmd].run = run; |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
247 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
|
248 task_list[cmd].wait = null_waiter; |
1147 | 249 task_list[cmd].name = str; |
250 | |
251 #ifndef NOT_CHECK | |
252 entry_cmd[task_count++] = cmd; | |
253 #endif | |
254 | |
42 | 255 } |
373 | 256 |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
257 extern void |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
258 register_dynamic_task(int cmd, |
441 | 259 memaddr start, int size, |
1058
d3cb29f1eccb
create task_name_list array in Scheduler.h
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1024
diff
changeset
|
260 TaskObjectRun run, int entry_offset, |
d3cb29f1eccb
create task_name_list array in Scheduler.h
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1024
diff
changeset
|
261 const char *str) |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
262 { |
464
0d64bdb63005
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
461
diff
changeset
|
263 task_list[cmd].run = run; |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
264 task_list[cmd].location = start; |
442 | 265 size &= 0xfffffffe; |
441 | 266 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
|
267 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
|
268 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
|
269 task_list[cmd].wait = wait_load; |
1147 | 270 task_list[cmd].name = str; |
271 | |
272 #ifndef NOT_CHECK | |
273 entry_cmd[task_count++] = cmd; | |
274 #endif | |
275 | |
538 | 276 #if 0 |
736 | 277 this->printf("cmd = %d\n",cmd); |
278 this->printf("locatation = 0x%x\n",start); | |
279 this->printf("end = 0x%x\n",start+size); | |
280 this->printf("size = 0x%x\n",size); | |
281 this->printf("entry = 0x%x\n",entry_offset); | |
538 | 282 #endif |
439 | 283 |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
284 } |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
285 |
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
286 |
373 | 287 /*! |
386 | 288 |
289 size 単位のMemory Segment を count 個作る | |
290 | |
373 | 291 @param [size] リストの要素1つのサイズ |
292 @param [count] 要素数 | |
293 @return allocate した領域のポインタ | |
294 | |
295 */ | |
296 MemList* | |
297 Scheduler::createMemList(int size, int count) | |
298 { | |
299 uint32 head_size = round_up16(sizeof(MemorySegment)); | |
300 uint32 seg_size = round_up16(head_size+size); | |
800
54f0180cea0f
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
792
diff
changeset
|
301 char* mseg = (char*)manager->allocate(seg_size*count); |
373 | 302 MemList* mlist = new MemList((MemorySegment*)mseg); |
303 | |
388
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
304 if (!hash) { |
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
305 hash = new MemHash(); |
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
306 } |
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
307 |
373 | 308 for(int i = 0; i < count; i++) { |
309 MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); | |
310 char* data = (char*)next+head_size; | |
311 next->data = (void*)data; | |
386 | 312 next->size = size; |
395 | 313 next->address = (memaddr)next; |
373 | 314 mlist->addLast(next); |
315 } | |
316 | |
317 return mlist; | |
318 } | |
386 | 319 |
320 /*! | |
321 | |
322 Main Memory のSegmentを取得する | |
323 | |
324 @param [addr] Main Memory のアドレス | |
325 @param [m] Mem List | |
326 @return allocate した領域のポインタ | |
327 memory directory にあるべきだが... | |
328 | |
329 */ | |
387
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
330 MemorySegment * |
386 | 331 Scheduler::get_segment(memaddr addr, MemList *m) |
332 { | |
1154 | 333 |
334 #ifdef USE_CACHE | |
335 | |
449
0bed2a9889f5
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(); |
0bed2a9889f5
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); |
1154 | 338 |
339 #else | |
340 | |
1161
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1156
diff
changeset
|
341 //addr が空だった場合はどうなるか |
1162 | 342 //こうすると単純にFIFOか |
1161
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1156
diff
changeset
|
343 |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1156
diff
changeset
|
344 MemorySegment *s = m->getLast(); |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1156
diff
changeset
|
345 m->moveToFirst(s); |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
346 s->tag = connector->get_tag(); |
1163 | 347 s->address = addr; |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
348 s->data = connector->dma_load(0, s->data, addr, s->size, s->tag); |
1154 | 349 |
350 return s; | |
351 | |
352 #endif | |
353 | |
437 | 354 } |
355 | |
1173 | 356 /*! |
357 | |
358 free な Segmentを取得する(SPEのLSから) | |
359 書き込み専用の場合、dma_loadは必要ないので | |
360 こういう感じになるのかな. | |
361 | |
362 @param [addr] Main Memory のアドレス | |
363 @param [m] Mem List | |
364 @return allocate した領域のポインタ | |
365 memory directory にあるべきだが... | |
366 | |
367 */ | |
368 | |
369 MemorySegment * | |
370 Scheduler::get_free_segment(memaddr addr, MemList *m) | |
371 { | |
372 | |
373 | |
374 if(addr == NULL) { | |
375 return NULL; | |
376 } | |
377 | |
378 MemorySegment *s = m->getLast(); | |
379 m->moveToFirst(s); | |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
380 s->tag = connector->get_tag(); |
1173 | 381 s->address = addr; |
382 | |
383 return s; | |
384 | |
385 } | |
386 | |
1175 | 387 /*! |
388 | |
389 指定した MemorySegment を上書きする | |
390 | |
391 @param [s] 上書きするMemorySegment | |
392 @param [addr] 上書きするdataへのアドレス | |
393 | |
394 */ | |
395 | |
396 void | |
397 Scheduler::overwrite_segment(MemorySegment *s, memaddr addr) | |
398 { | |
399 | |
400 if(addr == NULL) { | |
401 return; | |
402 } | |
403 | |
404 s->address = addr; | |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
405 s->data = connector->dma_load(0, s->data, addr, s->size, s->tag); |
1175 | 406 |
407 } | |
408 | |
1173 | 409 |
437 | 410 MemorySegment * |
411 Scheduler::get_segment(memaddr addr, MemList *m, int size) | |
412 { | |
1124 | 413 |
437 | 414 // memory segment のsizeをoverride する場合がある |
386 | 415 MemorySegment *s = hash->get(addr); |
1123 | 416 |
386 | 417 if (s) { |
1124 | 418 |
386 | 419 /* 既に load されている */ |
736 | 420 // this->printf("get_segement loaded %llx 0x%x size 0x%d\n",addr,s->data,size); |
391 | 421 m->moveToFirst(s); |
386 | 422 return s; |
423 } | |
1154 | 424 |
1121 | 425 |
386 | 426 /* LRU なので、もっとも使われてない segment を上書きする */ |
427 s = m->getLast(); | |
428 m->moveToFirst(s); | |
429 | |
430 memaddr old_addr = s->address; | |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
431 s->tag = connector->get_tag(); |
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
432 s->data = connector->dma_load(0, s->data, addr, size, s->tag); |
386 | 433 /* 前のをhashから削除 */ |
434 hash->remove(old_addr); | |
435 /* 新しいaddress を登録 */ | |
436 s->address = addr; | |
437 hash->put(s->address, s); | |
438 | |
736 | 439 // this->printf("get_segement %llx 0x%x size 0x%d\n",addr, s->data,size); |
439 | 440 |
386 | 441 return s; |
442 } | |
443 | |
423
609758f9f350
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
444 |
1173 | 445 |
386 | 446 /*! |
447 | |
448 Main Memory のSegmentを書き出す | |
449 Segment は get_segement されていて、 | |
450 追い出されていてはいけない。 | |
451 それを保証するのは難しい? | |
452 | |
453 @param [addr] Main Memory のアドレス | |
454 @param [m] Mem List | |
455 @return allocate した領域のポインタ | |
456 | |
457 */ | |
458 void | |
459 Scheduler::put_segment(MemorySegment *s) | |
460 { | |
1163 | 461 |
462 if (s == NULL) return; | |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
463 s->tag = connector->get_tag(); |
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
464 connector->dma_store(s->data, s->address, s->size, s->tag); |
386 | 465 } |
466 | |
467 /*! | |
468 | |
469 Main Memory のSegmentを読込、書き出しを待つ | |
470 | |
471 @param [id] MemorySegment のid | |
472 | |
473 */ | |
474 void | |
387
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
475 Scheduler::wait_segment(MemorySegment *s) |
386 | 476 { |
391 | 477 // えーと、dma してない時には、skip しないとだめなんじゃないの? |
478 | |
1163 | 479 if (s == NULL) return; |
1213
a49c02dffe6f
DMA connector reogranization
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1175
diff
changeset
|
480 if (s->tag) connector->dma_wait(s->tag); |
391 | 481 s->tag = 0; |
386 | 482 } |
483 | |
621 | 484 long Scheduler::get_random() { |
485 #if defined(__SPU__) | |
486 return 0; | |
487 #else | |
488 return random(); | |
489 #endif | |
490 | |
491 } | |
492 | |
736 | 493 int |
494 Scheduler::printf(const char * format, ...) | |
495 { | |
786
043c98537bc5
fix early free of TaskArray, add SchedTaskArrayNop stage.
yutaka@localhost.localdomain
parents:
743
diff
changeset
|
496 #if !defined(__SPU__) || 1 |
736 | 497 va_list ap; |
498 va_start(ap,format); | |
743 | 499 int ret= vprintf0(format, ap); |
736 | 500 va_end(ap); |
501 return ret; | |
502 #else | |
503 return 0; | |
504 #endif | |
505 } | |
506 | |
507 int | |
743 | 508 Scheduler::vprintf0(const char * format, va_list ap) |
736 | 509 { |
786
043c98537bc5
fix early free of TaskArray, add SchedTaskArrayNop stage.
yutaka@localhost.localdomain
parents:
743
diff
changeset
|
510 #if !defined(__SPU__) || 1 |
736 | 511 int ret= vprintf(format, ap); |
512 return ret; | |
513 #else | |
514 return 0; | |
515 #endif | |
516 } | |
517 | |
518 | |
386 | 519 /* end */ |