Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.h @ 836:cc06efc75ad9
example fix 50%
author | tkaito |
---|---|
date | Tue, 25 May 2010 19:13:28 +0900 |
parents | daab9cd6f91f |
children | e49c1b29c43d |
rev | line source |
---|---|
42 | 1 #ifndef INCLUDED_SCHEDULER |
2 #define INCLUDED_SCHEDULER | |
3 | |
621 | 4 #include <stdlib.h> |
736 | 5 #include <stdarg.h> |
301
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
6 #include "base.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
7 #include "TaskList.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
8 #include "ListData.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
9 #include "DmaManager.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
10 #include "SchedTaskBase.h" |
373 | 11 #include "MemList.h" |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
12 #include "MemHash.h" |
619 | 13 |
109 | 14 |
15 #define MAX_USER_TASK 32 | |
16 #define MAX_SYSTEM_TASK 2 | |
17 #define MAX_TASK_OBJECT MAX_USER_TASK + MAX_SYSTEM_TASK | |
18 #define MAX_GLOBAL_AREA 32 | |
19 #define MAX_MAINMEM_AREA 32 | |
20 | |
42 | 21 class SchedTaskBase; |
109 | 22 class SchedTask; |
184 | 23 class SchedTaskList; |
621 | 24 class TaskManagerImpl; |
25 class HTask; | |
42 | 26 |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
27 typedef int (*TaskObjectRun)(SchedTask* smanager, void* r, void *w); |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
28 |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
29 // Task Object Table |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
30 // this is named TaskObjectRun but it is not an object. |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
31 // It is a pointer to an object creation function |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
32 // 大きいので、SPEには置かない方が本当は良い... |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
33 // get_segment で取って来るのが、おそらくは正しい。 |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
34 typedef struct { |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
35 TaskObjectRun run; |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
36 memaddr location; // location address in a.out |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
37 memaddr end; |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
38 uint32 entry_offset; // offset for create(); |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
39 MemorySegment *segment; |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
40 void (*load)(Scheduler *,int); |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
41 void (*wait)(Scheduler *,int); |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
42 } TaskObject, *TaskObjectPtr; |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
43 |
621 | 44 extern "C" { |
45 extern long random(); | |
46 } | |
47 | |
42 | 48 class Scheduler { |
836 | 49 private: |
50 TaskManagerImpl* manager_tmp; | |
51 | |
42 | 52 public: |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
53 virtual ~Scheduler(); |
109 | 54 BASE_NEW_DELETE(Scheduler); |
42 | 55 |
56 /* variables */ | |
194 | 57 int id; |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
58 MemHash *hash; |
109 | 59 |
60 // double buffering | |
61 TaskListPtr buff_taskList[2]; | |
62 | |
63 int buffFlag_taskList; | |
64 | |
65 /* GlobalMemoryList */ | |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
626
diff
changeset
|
66 /* global among Tasks in the same CPU */ |
109 | 67 void* globalList[MAX_GLOBAL_AREA]; |
68 | |
69 /* MainMemory Allocate Command List */ | |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
626
diff
changeset
|
70 memaddr mainMemList[MAX_MAINMEM_AREA]; |
109 | 71 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
72 /* Code Area */ |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
73 MemList *code_segment_pool; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
74 |
42 | 75 DmaManager* connector; |
619 | 76 TaskManagerImpl* manager; |
109 | 77 |
42 | 78 |
79 /* functions */ | |
635
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
80 void init(TaskManagerImpl *m); |
697 | 81 void run(SchedTaskBase* task1); |
82 | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
83 virtual void init_impl() {}; |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
84 void finish(); |
42 | 85 |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
86 TaskListPtr get_curListBuf(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
87 TaskListPtr get_renewListBuf(); |
109 | 88 |
187 | 89 void set_backupTaskList(TaskListPtr cur_taskList); |
90 void set_backupTaskListIndex(int cur_index); | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
91 SchedTaskList* get_nextRenewTaskList(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
92 TaskListPtr get_backupTaskList(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
93 int get_backupTaskListIndex(); |
184 | 94 |
109 | 95 |
96 /* GlobalMemory */ | |
97 void* global_alloc(int id, int size); | |
98 void* global_get(int id); | |
373 | 99 void global_set(int id, void *addr); |
109 | 100 void global_free(int id); |
836 | 101 //MemList* createMemList(int size, int count); |
373 | 102 MemList* createMemList(int size, int count); |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
464
diff
changeset
|
103 void free_(void *p) { free(p); } |
109 | 104 |
105 virtual void mainMem_alloc(int id, int size) {}; | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
106 virtual void mainMem_wait() {}; |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
626
diff
changeset
|
107 memaddr mainMem_get(int id); |
109 | 108 |
389 | 109 MemorySegment * get_segment(memaddr addr, MemList *m); |
437 | 110 MemorySegment * get_segment(memaddr addr, MemList *m, int size); |
442 | 111 void allocate_code_segment(int size, int count); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
112 |
389 | 113 virtual uint32 get_tag(); |
114 void put_segment(MemorySegment *s); | |
115 void wait_segment(MemorySegment *s); | |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
116 |
109 | 117 /* DMA Transfer */ |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
118 void dma_load(void *buf, memaddr addr, uint32 size, uint32 mask); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
119 void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask); |
109 | 120 void dma_wait(uint32 mask); |
255 | 121 void show_dma_wait() { connector->show_dma_wait(id); }; |
672 | 122 void start_profile() { connector->start_profile(); }; |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
123 void mail_write(memaddr data); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
124 memaddr mail_read(); |
109 | 125 void dma_loadList(ListDataPtr list, void *, uint32 mask); |
126 void dma_storeList(ListDataPtr list, void *, uint32 mask); | |
619 | 127 |
128 /* manager */ | |
129 | |
836 | 130 void set_manager(TaskManagerImpl *m) { |
131 manager = m; | |
132 }; | |
619 | 133 |
800
2708c4a7bade
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
742
diff
changeset
|
134 /* user */ |
634 | 135 |
621 | 136 long get_random() ; |
137 Scheduler *get_scheduler() { return this; }; | |
736 | 138 int printf(const char *format, ...); |
742 | 139 int vprintf0(const char *format, va_list ap); |
619 | 140 |
42 | 141 }; |
142 | |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
143 extern void register_task(int cmd, TaskObjectRun run); |
430
fb62b7acc92b
code loading (on going...)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
426
diff
changeset
|
144 extern void register_dynamic_task(int cmd, |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
145 memaddr start, int size, TaskObjectRun run, |
439 | 146 int entry_offset); |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
147 |
441 | 148 struct tbl { |
149 unsigned int vma; | |
150 unsigned int size; | |
151 unsigned int file_offset; | |
152 unsigned int buf; | |
153 }; | |
154 | |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
155 extern TaskObject task_list[MAX_TASK_OBJECT]; |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
156 |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
157 inline void |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
158 loadSchedTask(Scheduler *scheduler,int command) |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
159 { |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
160 task_list[command].load(scheduler,command); |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
161 } |
109 | 162 |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
163 #endif |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
164 |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
165 |
109 | 166 |
373 | 167 #define SchedConstructor(str) \ |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
168 str() {} \ |
373 | 169 BASE_NEW_DELETE(str) \ |
109 | 170 |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
171 #define SchedDefineTask(str) SchedDefineTask1(str,run) \ |
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
172 |
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
173 #define SchedDefineTask1(str,run) \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
174 static int run(SchedTask *smanager, void *rbuf, void *wbuf); \ |
460 | 175 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
176 int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \ |
373 | 177 { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
178 return run(smanager, rbuf, wbuf); \ |
460 | 179 } \ |
109 | 180 } |
181 | |
373 | 182 #define SchedExternTask(str) \ |
460 | 183 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
184 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
460 | 185 } |
109 | 186 |
373 | 187 #define SchedRegisterTask(cmd, str) \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
188 register_task(cmd, runTask_##str); |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
189 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
190 #define SchedRegister(str) \ |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
191 register_task(str, runTask_##str); |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
192 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
193 #define SchedDefineDynamicTask(str,segment) \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
194 SchedDefineTask(str) |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
195 |
437 | 196 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
197 #define SchedExternDynamicTask(str,segment) \ |
441 | 198 extern "C" { \ |
199 extern unsigned long long _EAR_; \ | |
200 extern struct tbl _ovly_table[]; \ | |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
201 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
441 | 202 } |
437 | 203 #else |
439 | 204 #define SchedExternDynamicTask(str,segment) SchedExternTask(str) |
437 | 205 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
206 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
207 |
437 | 208 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
209 #define SchedRegisterDynamicTask(cmd, str, segment) \ |
626
ab866bc8a624
64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
210 register_dynamic_task(cmd, (memaddr)(_EAR_+_ovly_table[segment].file_offset), \ |
441 | 211 _ovly_table[segment].size, \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
212 runTask_##str, \ |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
213 runTask_##str##_offset); |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
214 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 215 #else |
216 #define SchedRegisterDynamicTask(cmd, str, segment) SchedRegisterTask(cmd, str) | |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
217 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 218 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
219 |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
220 |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
221 /* end */ |