Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.h @ 899:586b4f825f24
minor fix..
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 22:20:02 +0900 |
parents | bed529c55eda |
children | e015a4e5e4b0 |
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 で取って来るのが、おそらくは正しい。 |
887
1c12673c11be
remove run variable to avoid SPU compiler bug from SchedTaskArray::exec().
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
872
diff
changeset
|
34 typedef struct task_object { |
698
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); |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
887
diff
changeset
|
42 } __attribute__ ((aligned (DEFAULT_ALIGNMENT))) |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
887
diff
changeset
|
43 TaskObject, *TaskObjectPtr; |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
44 |
621 | 45 extern "C" { |
46 extern long random(); | |
47 } | |
48 | |
42 | 49 class Scheduler { |
836 | 50 private: |
51 TaskManagerImpl* manager_tmp; | |
52 | |
42 | 53 public: |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
54 virtual ~Scheduler(); |
109 | 55 BASE_NEW_DELETE(Scheduler); |
42 | 56 |
57 /* variables */ | |
194 | 58 int id; |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
59 MemHash *hash; |
109 | 60 |
61 // double buffering | |
62 TaskListPtr buff_taskList[2]; | |
63 | |
64 int buffFlag_taskList; | |
65 | |
66 /* GlobalMemoryList */ | |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
626
diff
changeset
|
67 /* global among Tasks in the same CPU */ |
109 | 68 void* globalList[MAX_GLOBAL_AREA]; |
69 | |
70 /* 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
|
71 memaddr mainMemList[MAX_MAINMEM_AREA]; |
109 | 72 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
73 /* Code Area */ |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
74 MemList *code_segment_pool; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
75 |
42 | 76 DmaManager* connector; |
619 | 77 TaskManagerImpl* manager; |
109 | 78 |
42 | 79 |
80 /* functions */ | |
635
8cc609285bbe
SimpleTask worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
81 void init(TaskManagerImpl *m); |
697 | 82 void run(SchedTaskBase* task1); |
83 | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
84 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
|
85 void finish(); |
42 | 86 |
403
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_curListBuf(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
88 TaskListPtr get_renewListBuf(); |
109 | 89 |
187 | 90 void set_backupTaskList(TaskListPtr cur_taskList); |
91 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
|
92 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
|
93 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
|
94 int get_backupTaskListIndex(); |
184 | 95 |
109 | 96 |
97 /* GlobalMemory */ | |
98 void* global_alloc(int id, int size); | |
99 void* global_get(int id); | |
373 | 100 void global_set(int id, void *addr); |
109 | 101 void global_free(int id); |
836 | 102 //MemList* createMemList(int size, int count); |
373 | 103 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
|
104 void free_(void *p) { free(p); } |
109 | 105 |
106 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
|
107 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
|
108 memaddr mainMem_get(int id); |
109 | 109 |
389 | 110 MemorySegment * get_segment(memaddr addr, MemList *m); |
437 | 111 MemorySegment * get_segment(memaddr addr, MemList *m, int size); |
872 | 112 void allocate_code_segment(int size, int count,struct tbl *table); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
113 |
389 | 114 virtual uint32 get_tag(); |
115 void put_segment(MemorySegment *s); | |
116 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
|
117 |
109 | 118 /* DMA Transfer */ |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
119 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
|
120 void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask); |
109 | 121 void dma_wait(uint32 mask); |
255 | 122 void show_dma_wait() { connector->show_dma_wait(id); }; |
672 | 123 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
|
124 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
|
125 memaddr mail_read(); |
109 | 126 void dma_loadList(ListDataPtr list, void *, uint32 mask); |
127 void dma_storeList(ListDataPtr list, void *, uint32 mask); | |
619 | 128 |
129 /* manager */ | |
130 | |
836 | 131 void set_manager(TaskManagerImpl *m) { |
132 manager = m; | |
133 }; | |
619 | 134 |
800
2708c4a7bade
run16 word count ( not yet worked. )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
742
diff
changeset
|
135 /* user */ |
634 | 136 |
621 | 137 long get_random() ; |
138 Scheduler *get_scheduler() { return this; }; | |
736 | 139 int printf(const char *format, ...); |
742 | 140 int vprintf0(const char *format, va_list ap); |
619 | 141 |
899 | 142 } ; |
42 | 143 |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
144 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
|
145 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
|
146 memaddr start, int size, TaskObjectRun run, |
439 | 147 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
|
148 |
441 | 149 struct tbl { |
150 unsigned int vma; | |
151 unsigned int size; | |
152 unsigned int file_offset; | |
153 unsigned int buf; | |
154 }; | |
155 | |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
156 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
|
157 |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
158 inline void |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
159 loadSchedTask(Scheduler *scheduler,int command) |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
160 { |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
161 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
|
162 } |
109 | 163 |
698
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
164 #endif |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
165 |
dcaa40ec963d
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
697
diff
changeset
|
166 |
109 | 167 |
373 | 168 #define SchedConstructor(str) \ |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
169 str() {} \ |
373 | 170 BASE_NEW_DELETE(str) \ |
109 | 171 |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
172 #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
|
173 |
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
174 #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
|
175 static int run(SchedTask *smanager, void *rbuf, void *wbuf); \ |
460 | 176 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
177 int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \ |
373 | 178 { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
179 return run(smanager, rbuf, wbuf); \ |
460 | 180 } \ |
109 | 181 } |
182 | |
373 | 183 #define SchedExternTask(str) \ |
460 | 184 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
185 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
460 | 186 } |
109 | 187 |
373 | 188 #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
|
189 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
|
190 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
191 #define SchedRegister(str) \ |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
192 register_task(str, runTask_##str); |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
193 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
194 #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
|
195 SchedDefineTask(str) |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
196 |
437 | 197 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
198 #define SchedExternDynamicTask(str,segment) \ |
441 | 199 extern "C" { \ |
200 extern unsigned long long _EAR_; \ | |
201 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
|
202 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
441 | 203 } |
437 | 204 #else |
439 | 205 #define SchedExternDynamicTask(str,segment) SchedExternTask(str) |
437 | 206 #endif |
421
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 |
437 | 209 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
210 #define SchedRegisterDynamicTask(cmd, str, segment) \ |
626
ab866bc8a624
64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
211 register_dynamic_task(cmd, (memaddr)(_EAR_+_ovly_table[segment].file_offset), \ |
441 | 212 _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
|
213 runTask_##str, \ |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
214 runTask_##str##_offset); |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
215 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 216 #else |
217 #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
|
218 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 219 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
220 |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
221 |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
222 /* end */ |