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