Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/schedule/Scheduler.h @ 625:60aa3f241b10
64bit mode worked on Mac OS X.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 16 Nov 2009 10:59:55 +0900 |
parents | 5b178db5988a |
children | ab866bc8a624 |
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 */ | |
49 void* globalList[MAX_GLOBAL_AREA]; | |
50 | |
51 /* MainMemory Allocate Command List */ | |
52 void* mainMemList[MAX_MAINMEM_AREA]; | |
53 | |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
54 /* Code Area */ |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
55 MemList *code_segment_pool; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
56 |
109 | 57 // Task Object Table |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
58 // this is named TaskObjectRun but it is not an object. |
291 | 59 // 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
|
60 // 大きいので、SPEには置かない方が本当は良い... |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
61 typedef struct { |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
62 TaskObjectRun run; |
441 | 63 memaddr location; // location address in a.out |
64 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
|
65 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
|
66 MemorySegment *segment; |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
67 void (*load)(Scheduler *,int); |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
68 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
|
69 } TaskObject, *TaskObjectPtr; |
42 | 70 |
71 DmaManager* connector; | |
619 | 72 TaskManagerImpl* manager; |
109 | 73 |
74 // Pipeline Stage | |
42 | 75 SchedTaskBase* task1; |
76 SchedTaskBase* task2; | |
77 SchedTaskBase* task3; | |
78 | |
79 /* functions */ | |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
80 void init(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
81 void run(); |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
82 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
|
83 void finish(); |
42 | 84 |
403
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_curListBuf(); |
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_renewListBuf(); |
109 | 87 |
187 | 88 void set_backupTaskList(TaskListPtr cur_taskList); |
89 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
|
90 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
|
91 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
|
92 int get_backupTaskListIndex(); |
184 | 93 |
109 | 94 |
95 /* GlobalMemory */ | |
96 void* global_alloc(int id, int size); | |
97 void* global_get(int id); | |
373 | 98 void global_set(int id, void *addr); |
109 | 99 void global_free(int id); |
373 | 100 MemList* createMemList(int size, int count); |
109 | 101 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
|
102 void free_(void *p) { free(p); } |
109 | 103 |
104 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
|
105 virtual void mainMem_wait() {}; |
109 | 106 void *mainMem_get(int id); |
107 | |
389 | 108 MemorySegment * get_segment(memaddr addr, MemList *m); |
437 | 109 MemorySegment * get_segment(memaddr addr, MemList *m, int size); |
442 | 110 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
|
111 |
389 | 112 virtual uint32 get_tag(); |
113 void put_segment(MemorySegment *s); | |
114 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
|
115 |
109 | 116 /* DMA Transfer */ |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
117 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
|
118 void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask); |
109 | 119 void dma_wait(uint32 mask); |
255 | 120 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
|
121 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
|
122 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
|
123 memaddr mail_read(); |
109 | 124 void dma_loadList(ListDataPtr list, void *, uint32 mask); |
125 void dma_storeList(ListDataPtr list, void *, uint32 mask); | |
619 | 126 |
127 /* manager */ | |
128 | |
621 | 129 void set_manager(TaskManagerImpl *m) { manager = m; }; |
619 | 130 |
131 // user | |
621 | 132 HTask * create_task(int cmd); |
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) ; | |
136 void* allocate(int size,int align) ; | |
137 long get_random() ; | |
138 Scheduler *get_scheduler() { return this; }; | |
619 | 139 |
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 | |
42 | 155 #endif |
109 | 156 |
157 | |
373 | 158 #define SchedConstructor(str) \ |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
159 str() {} \ |
373 | 160 BASE_NEW_DELETE(str) \ |
109 | 161 |
468
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
162 #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
|
163 |
bd5b93d39597
test_nogl on Mac OS X worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
164 #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
|
165 static int run(SchedTask *smanager, void *rbuf, void *wbuf); \ |
460 | 166 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
167 int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \ |
373 | 168 { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
169 return run(smanager, rbuf, wbuf); \ |
460 | 170 } \ |
109 | 171 } |
172 | |
373 | 173 #define SchedExternTask(str) \ |
460 | 174 extern "C" { \ |
464
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
175 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
460 | 176 } |
109 | 177 |
373 | 178 #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
|
179 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
|
180 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
181 #define SchedRegister(str) \ |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
182 register_task(str, runTask_##str); |
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
183 |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
184 #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
|
185 SchedDefineTask(str) |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
186 |
437 | 187 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
188 #define SchedExternDynamicTask(str,segment) \ |
441 | 189 extern "C" { \ |
190 extern unsigned long long _EAR_; \ | |
191 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
|
192 extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ |
441 | 193 } |
437 | 194 #else |
439 | 195 #define SchedExternDynamicTask(str,segment) SchedExternTask(str) |
437 | 196 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
197 |
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
198 |
437 | 199 #ifndef NO_OVERLAY |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
200 #define SchedRegisterDynamicTask(cmd, str, segment) \ |
441 | 201 register_dynamic_task(cmd, _EAR_+_ovly_table[segment].file_offset, \ |
202 _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
|
203 runTask_##str, \ |
01b321c86747
task run is mere C function now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
460
diff
changeset
|
204 runTask_##str##_offset); |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
501
diff
changeset
|
205 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 206 #else |
207 #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
|
208 #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) |
437 | 209 #endif |
421
cd77224d4224
Code load implementation... (not yet tested)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
210 |
403
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
211 |
8611780d479f
clean up and add more info on task_list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
389
diff
changeset
|
212 /* end */ |