Mercurial > hg > Members > kono > Cerium
changeset 421:cd77224d4224
Code load implementation... (not yet tested)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 24 Sep 2009 16:04:23 +0900 |
parents | 90d677a9c00b |
children | 960471b7ee54 |
files | TaskManager/kernel/schedule/SchedTask.cc TaskManager/kernel/schedule/SchedTask.h TaskManager/kernel/schedule/SchedTaskList.cc TaskManager/kernel/schedule/Scheduler.cc TaskManager/kernel/schedule/Scheduler.h example/get_segment/spe/Hello.cc example/get_segment/spe/spe-main.cc |
diffstat | 7 files changed, 114 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/schedule/SchedTask.cc Wed Sep 23 21:29:30 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Thu Sep 24 16:04:23 2009 +0900 @@ -11,13 +11,31 @@ //#define NO_PIPELINE +/** + Task Object を作る + code loading ならば、loading の終了を待つ + */ + SchedTask * createSchedTask(Scheduler *scheduler, TaskPtr task) { + task_list[task->command].wait(scheduler,task->command); return task_list[task->command].creator(scheduler); } +/** + code load を始める。既に get_segment hash に入っていれば何もしない。 + 最初の一回は SchedTaskList:: next から呼ばれる。 + この段階では、SchedTask object は、まだ作られてない。 + */ +void +loadSchedTask(Scheduler *scheduler,TaskPtr task) +{ + task_list[task->command].load(scheduler,task->command); +} + + SchedTask::SchedTask() { __list = NULL; @@ -322,6 +340,10 @@ return nextSched; } else { TaskPtr nextTask = &__list->tasks[__cur_index++]; + if (__cur_index < __list->length) { + // load next task + loadSchedTask(__scheduler, &__list->tasks[__cur_index]); + } nextSched = createSchedTask(__scheduler, nextTask); ((SchedTask*)nextSched)->__init__(__list, nextTask, __cur_index, __scheduler->get_curReadBuf(),
--- a/TaskManager/kernel/schedule/SchedTask.h Wed Sep 23 21:29:30 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Thu Sep 24 16:04:23 2009 +0900 @@ -162,6 +162,8 @@ const int SCHED_TASK_RENEW = 1; extern SchedTask* createSchedTask(Scheduler *,TaskPtr); +extern void loadSchedTask(Scheduler *scheduler,TaskPtr task); + #endif
--- a/TaskManager/kernel/schedule/SchedTaskList.cc Wed Sep 23 21:29:30 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskList.cc Thu Sep 24 16:04:23 2009 +0900 @@ -67,6 +67,8 @@ } else { TaskPtr nextTask = &list->tasks[0]; + // code load を開始する。 + loadSchedTask(scheduler, nextTask); nextSched = createSchedTask(scheduler, nextTask); if (flag_renewTaskList == SCHED_TASKLIST_RENEW) {
--- a/TaskManager/kernel/schedule/Scheduler.cc Wed Sep 23 21:29:30 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Thu Sep 24 16:04:23 2009 +0900 @@ -325,16 +325,63 @@ return mainMemList[id]; } +/** + * Task load API + */ -/** - * 本当は Scheduler クラスに入れるべきなんだろうか。。。 - * なんか手抜きの感がある - */ -void register_task(int cmd, TaskObjectCreator creator) +static void +load_task(Scheduler *m, int task_id) +{ + MemorySegment *s = m->get_segment( + task_list[task_id].location, + m->code_segment_pool); + task_list[task_id].segment = s; +} + +static void +null_loader(Scheduler *m, int task_id) +{ +} + +static void +wait_load(Scheduler *m, int task_id) +{ + // wait for code segment load + m->wait_segment(task_list[task_id].segment); + // calcurate call address + TaskObjectCreator creator = + (TaskObjectCreator)( + (char*)task_list[task_id].segment->data + + task_list[task_id].entry_offset); + task_list[task_id].creator = creator; +} + +static void +null_waiter(Scheduler *m, int task_id) +{ +} + +extern void +register_task(int cmd, TaskObjectCreator creator) { task_list[cmd].creator = creator; + task_list[cmd].load = null_loader; + task_list[cmd].wait = null_waiter; } +extern void +register_dynamic_task(int cmd, + memaddr start, memaddr end, int entry_offset) +{ + task_list[cmd].creator = 0; + task_list[cmd].location = start; + task_list[cmd].end = end; + task_list[cmd].entry_offset = entry_offset; + task_list[cmd].load = load_task; + task_list[cmd].wait = wait_load; +} + + /*! size 単位のMemory Segment を count 個作る @@ -405,6 +452,7 @@ return s; } + uint32 Scheduler::get_tag() {
--- a/TaskManager/kernel/schedule/Scheduler.h Wed Sep 23 21:29:30 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Thu Sep 24 16:04:23 2009 +0900 @@ -90,13 +90,21 @@ /* MainMemory Allocate Command List */ void* mainMemList[MAX_MAINMEM_AREA]; + /* Code Area */ + MemList *code_segment_pool; + // Task Object Table // this is named TaskObject but it is not an object. // It is a pointer to an object creation function + // 大きいので、SPEには置かない方が本当は良い... typedef struct { TaskObjectCreator creator; uint64 location; // location address in a.out + uint64 end; uint32 entry_offset; // offset for create(); + MemorySegment *segment; + void (*load)(Scheduler *,int); + void (*wait)(Scheduler *,int); } TaskObject, *TaskObjectPtr; DmaManager* connector; @@ -144,6 +152,8 @@ void *mainMem_get(int id); MemorySegment * get_segment(memaddr addr, MemList *m); + MemorySegment * Scheduler::load_task(memaddr task); + virtual uint32 get_tag(); void put_segment(MemorySegment *s); void wait_segment(MemorySegment *s); @@ -161,26 +171,43 @@ }; extern void register_task(int cmd, TaskObjectCreator creator); +extern void register_dynamic_task(int cmd, TaskObjectCreator creator, + memaddr start, memaddr end, int entry_offset); #endif #define SchedConstructor(str) \ - str() {} \ + str() {} \ BASE_NEW_DELETE(str) \ #define SchedDefineTask(str) \ - SchedTask* createTask_##str(Scheduler *manager) \ + SchedTask* createTask_##str(Scheduler *manager) \ { \ return new str(); \ } #define SchedExternTask(str) \ - extern \ - SchedTask* createTask_##str(Scheduler *manager); + extern SchedTask* createTask_##str(Scheduler *manager) ; #define SchedRegisterTask(cmd, str) \ register_task(cmd, createTask_##str); +#define SchedDefineDynamicTask(str,segment) \ + SchedTask* createTask_##str(Scheduler *manager) \ + { \ + return new str(); \ + } + +#define SchedExternDynamicTask(str,segment) \ + extern memaddr __load_start_##segment, \ + memaddr __loat_stop_##segment, \ + spe_load_entry; \ + extern SchedTask* createTask_##str(Scheduler *manager) + + +#define SchedRegisterDynamicTask(cmd, str, segment) \ + register_dynamic_task(cmd, __load_start_##segment, __loat_stop_##segment, createTask__#str-spe_load_entry); + /* end */
--- a/example/get_segment/spe/Hello.cc Wed Sep 23 21:29:30 2009 +0900 +++ b/example/get_segment/spe/Hello.cc Thu Sep 24 16:04:23 2009 +0900 @@ -3,7 +3,7 @@ #include "Func.h" /* これは必須 */ -SchedDefineTask(Hello); +SchedDefineDynamicTask(Hello,Segment1); #define PP_STORE 3 #define SIZE (4096*sizeof(int)) @@ -12,37 +12,8 @@ Hello::run(void *rbuf, void *wbuf) { int task_id = get_param(0); - int *ptr = 0; -#if 1 - ptr = (int*)smanager->allocate(SIZE); - - smanager->mainMem_alloc(0, SIZE); - - int i; - for(i=0;i<4096;i++) { - ptr[i] = i; - } -#endif - memaddr *next = 0; -#if 1 - smanager->mainMem_wait(); - next = (memaddr*)smanager->mainMem_get(0); + fprintf(stderr,"Hello!\n"); - smanager->dma_wait(PP_STORE); - smanager->dma_store(ptr, (uint32)next, - SIZE, PP_STORE); - smanager->dma_wait(PP_STORE); - uint32 wait_id = smanager->get_segment(next, SIZE); - void* cur = smanager->wait_segment(wait_id); - //smanager->put_segment(wait_id); - //comparePtr *next; -#endif - - - fprintf(stderr,"sizeof(int) = [%d] sizeof(void*)=[%d]\n", (int)sizeof(int),(int)sizeof(void*)); - fprintf(stderr,"[%d] Main Mem %0x len %d\n", task_id, (unsigned int)next,(int)SIZE); - - free(ptr); return 0; }
--- a/example/get_segment/spe/spe-main.cc Wed Sep 23 21:29:30 2009 +0900 +++ b/example/get_segment/spe/spe-main.cc Thu Sep 24 16:04:23 2009 +0900 @@ -1,7 +1,7 @@ #include "Func.h" #include "Scheduler.h" -SchedExternTask(Hello); +SchedExternDynamicTask(Hello); /** * この関数は SpeScheduler から呼ばれるので @@ -10,5 +10,5 @@ void task_init(void) { - SchedRegisterTask(HELLO_TASK, Hello); + SchedRegisterDynamicTask(HELLO_TASK, Hello, Segment1); }