Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.h @ 634:0558abba673c
SimpleTask start
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Nov 2009 17:29:14 +0900 |
parents | 8843edf37c0e |
children | 8cc609285bbe |
rev | line source |
---|---|
42 | 1 #ifndef INCLUDED_SCHEDULER |
2 #define INCLUDED_SCHEDULER | |
3 | |
621 | 4 #include <stdlib.h> |
301
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
5 #include "base.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
6 #include "TaskList.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
7 #include "ListData.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
8 #include "DmaManager.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
9 #include "SchedTaskBase.h" |
bcb81858aa62
remove deprecated source. not work.
tkaito@localhost.localdomain
parents:
298
diff
changeset
|
10 #include "SchedTaskList.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 |
621 | 29 extern "C" { |
30 extern long random(); | |
31 } | |
32 | |
42 | 33 class Scheduler { |
34 public: | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
35 virtual ~Scheduler(); |
109 | 36 |
37 BASE_NEW_DELETE(Scheduler); | |
42 | 38 |
39 /* variables */ | |
194 | 40 int id; |
387
5e2d30bfbf23
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
373
diff
changeset
|
41 MemHash *hash; |
109 | 42 |
43 // double buffering | |
44 TaskListPtr buff_taskList[2]; | |
45 | |
46 int buffFlag_taskList; | |
47 | |
48 /* GlobalMemoryList */ | |
629
8843edf37c0e
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
626
diff
changeset
|
49 /* global among Tasks in the same CPU */ |
109 | 50 void* globalList[MAX_GLOBAL_AREA]; |
51 | |
52 /* 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
|
53 memaddr mainMemList[MAX_MAINMEM_AREA]; |
109 | 54 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
55 /* Code Area */ |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
56 MemList *code_segment_pool; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
57 |
109 | 58 // Task Object Table |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
59 // this is named TaskObjectRun but it is not an object. |
291 | 60 // It is a pointer to an object creation function |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
61 // 大きいので、SPEには置かない方が本当は良い... |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
62 typedef struct { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
63 TaskObjectRun run; |
441 | 64 memaddr location; // location address in a.out |
65 memaddr end; | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
66 uint32 entry_offset; // offset for create(); |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
67 MemorySegment *segment; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
68 void (*load)(Scheduler *,int); |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
69 void (*wait)(Scheduler *,int); |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
70 } TaskObject, *TaskObjectPtr; |
42 | 71 |
72 DmaManager* connector; | |
619 | 73 TaskManagerImpl* manager; |
109 | 74 |
75 // Pipeline Stage | |
42 | 76 SchedTaskBase* task1; |
77 SchedTaskBase* task2; | |
78 SchedTaskBase* task3; | |
79 | |
80 /* functions */ | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
81 void init(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
82 void run(); |
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); |
373 | 101 MemList* createMemList(int size, int count); |
109 | 102 virtual void *allocate(int size) { return NULL; }; |
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); }; |
334
20f2459041cb
[in test_render] push L key , call show_dma_wait, but incomplete.
e065746@localhost.localdomain
parents:
302
diff
changeset
|
122 void show_dma_wait(int id) { connector->show_dma_wait(id); }; |
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 | |
621 | 130 void set_manager(TaskManagerImpl *m) { manager = m; }; |
619 | 131 |
132 // user | |
621 | 133 HTask * create_task(int cmd); |
634 | 134 HTask * create_task(int cmd, memaddr r, long rs, memaddr w, long ws); |
135 | |
621 | 136 void set_task_depend(HTask * master, HTask * slave) ; |
137 void spawn_task(HTask * t) ; | |
138 void set_task_cpu(HTask * t, CPU_TYPE cpu) ; | |
139 void* allocate(int size,int align) ; | |
140 long get_random() ; | |
141 Scheduler *get_scheduler() { return this; }; | |
619 | 142 |
143 | |
42 | 144 }; |
145 | |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
146 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
|
147 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
|
148 memaddr start, int size, TaskObjectRun run, |
439 | 149 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
|
150 |
441 | 151 struct tbl { |
152 unsigned int vma; | |
153 unsigned int size; | |
154 unsigned int file_offset; | |
155 unsigned int buf; | |
156 }; | |
157 | |
42 | 158 #endif |
109 | 159 |
160 | |
373 | 161 #define SchedConstructor(str) \ |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
162 str() {} \ |
373 | 163 BASE_NEW_DELETE(str) \ |
109 | 164 |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
165 #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
|
166 |
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
167 #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
|
168 static int run(SchedTask *smanager, void *rbuf, void *wbuf); \ |
460 | 169 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
170 int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \ |
373 | 171 { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
172 return run(smanager, rbuf, wbuf); \ |
460 | 173 } \ |
109 | 174 } |
175 | |
373 | 176 #define SchedExternTask(str) \ |
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 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
460 | 179 } |
109 | 180 |
373 | 181 #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
|
182 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
|
183 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
184 #define SchedRegister(str) \ |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
185 register_task(str, runTask_##str); |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
186 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
187 #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
|
188 SchedDefineTask(str) |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
189 |
437 | 190 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
191 #define SchedExternDynamicTask(str,segment) \ |
441 | 192 extern "C" { \ |
193 extern unsigned long long _EAR_; \ | |
194 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
|
195 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
441 | 196 } |
437 | 197 #else |
439 | 198 #define SchedExternDynamicTask(str,segment) SchedExternTask(str) |
437 | 199 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
200 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
201 |
437 | 202 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
203 #define SchedRegisterDynamicTask(cmd, str, segment) \ |
626
ab866bc8a624
64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
204 register_dynamic_task(cmd, (memaddr)(_EAR_+_ovly_table[segment].file_offset), \ |
441 | 205 _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
|
206 runTask_##str, \ |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
207 runTask_##str##_offset); |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
208 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 209 #else |
210 #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
|
211 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 212 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
213 |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
214 |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
215 /* end */ |