# HG changeset patch # User game@henri.cr.ie.u-ryukyu.ac.jp # Date 1253781898 -32400 # Node ID a6e893105097ac9ae9e02cc58b956190a9b439a9 # Parent ead3024bcc3cad88b22d0add303dc1043c8a7670# Parent cebb48da955e6b5f212e672ef73b02cb4830b04b merge diff -r ead3024bcc3c -r a6e893105097 TaskManager/kernel/schedule/SchedTask.cc --- a/TaskManager/kernel/schedule/SchedTask.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Thu Sep 24 17:44:58 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(), diff -r ead3024bcc3c -r a6e893105097 TaskManager/kernel/schedule/SchedTask.h --- a/TaskManager/kernel/schedule/SchedTask.h Thu Sep 24 17:44:09 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Thu Sep 24 17:44:58 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 diff -r ead3024bcc3c -r a6e893105097 TaskManager/kernel/schedule/SchedTaskList.cc --- a/TaskManager/kernel/schedule/SchedTaskList.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskList.cc Thu Sep 24 17:44:58 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) { diff -r ead3024bcc3c -r a6e893105097 TaskManager/kernel/schedule/Scheduler.cc --- a/TaskManager/kernel/schedule/Scheduler.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Thu Sep 24 17:44:58 2009 +0900 @@ -325,16 +325,68 @@ return mainMemList[id]; } +/** + * Task load API + */ +void +Scheduler::allocate_code_segment(int count, int size) +{ + code_segment_pool = createMemList(count, size); +} -/** - * 本当は 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 +457,7 @@ return s; } + uint32 Scheduler::get_tag() { diff -r ead3024bcc3c -r a6e893105097 TaskManager/kernel/schedule/Scheduler.h --- a/TaskManager/kernel/schedule/Scheduler.h Thu Sep 24 17:44:09 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Thu Sep 24 17:44:58 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,9 @@ void *mainMem_get(int id); MemorySegment * get_segment(memaddr addr, MemList *m); + void allocate_code_segment(int count, int size); + MemorySegment * Scheduler::load_task(memaddr task); + virtual uint32 get_tag(); void put_segment(MemorySegment *s); void wait_segment(MemorySegment *s); @@ -161,26 +172,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 */ diff -r ead3024bcc3c -r a6e893105097 example/get_segment/ppe/Hello.cc --- a/example/get_segment/ppe/Hello.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/example/get_segment/ppe/Hello.cc Thu Sep 24 17:44:58 2009 +0900 @@ -9,7 +9,7 @@ #define SIZE (4096*sizeof(int)) int -Hello::run(void *rbuf, void *wbuf) +Hello::run(SchedTask *smanager, void *rbuf, void *wbuf) { int task_id = get_param(0); int *ptr = 0; diff -r ead3024bcc3c -r a6e893105097 example/get_segment/ppe/Hello.h --- a/example/get_segment/ppe/Hello.h Thu Sep 24 17:44:09 2009 +0900 +++ b/example/get_segment/ppe/Hello.h Thu Sep 24 17:44:58 2009 +0900 @@ -9,7 +9,7 @@ public: SchedConstructor(Hello); - int run(void *r, void *w); + int run(SchedTask *smanager, void *r, void *w); }; #endif diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/Hello.cc --- a/example/get_segment/spe/Hello.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/example/get_segment/spe/Hello.cc Thu Sep 24 17:44:58 2009 +0900 @@ -3,46 +3,17 @@ #include "Func.h" /* これは必須 */ -SchedDefineTask(Hello); +SchedDefineDynamicTask(Hello,Segment1); #define PP_STORE 3 #define SIZE (4096*sizeof(int)) int -Hello::run(void *rbuf, void *wbuf) +Hello::run(ShcedTask *smanager, 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; } diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/Hello.h --- a/example/get_segment/spe/Hello.h Thu Sep 24 17:44:09 2009 +0900 +++ b/example/get_segment/spe/Hello.h Thu Sep 24 17:44:58 2009 +0900 @@ -9,7 +9,7 @@ public: SchedConstructor(Hello); - int run(void *r, void *w); + int run(SchedTask *smanager, void *r, void *w); }; #endif diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/LoadEntry.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/get_segment/spe/LoadEntry.cc Thu Sep 24 17:44:58 2009 +0900 @@ -0,0 +1,4 @@ + +void spe_load_entry() +{ +} diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/LoadEntry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/get_segment/spe/LoadEntry.h Thu Sep 24 17:44:58 2009 +0900 @@ -0,0 +1,6 @@ +#ifndef INCLUDED_LOAD_ENTRY +#define INCLUDED_LOAD_ENTRY + +extern void spe_load_entry(); + +#endif diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/fixpic.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/get_segment/spe/fixpic.pl Thu Sep 24 17:44:58 2009 +0900 @@ -0,0 +1,58 @@ +#!/usr/bin/perl +# +# Author: Shinji KONO +# v.0.1 Sat May 30 04:41:18 JST 2009 +# +# fix spu-gcc assembler soruce for DMA loadable PIC code +# +#$(OVLOBJS): %.o : %.cc +# $(SPECC) $(SPECFLAGS) -c $< -S -o $(<:.cc=.s) +# perl spe/fixpic.pl $(<:.cc=.s) | $(SPECC) $(SPECFLAGS) -x assembler -c -o $@ - + +use strict; + +my %global; +my %local; +my %weak; +my @line; + +# Basically SPU code is PIC. But linked library is in the fixed +# address space. +# +# rewrite relative to absolute for global branch address +# +# Target instruction +# hbrr -> hbra +# br -> bra +# brsl -> brasl +# brnz cannot be global + +while(<>) { + push(@line,$_); + if(/\.global\s+([^\s]+)/) { + $global{$1} = 1; + } + if(/\.weak\s+([^\s]+)/) { + $weak{$1} = 1; + next; + } + if(/^([^\s]+):/) { + $local{$1} = 1; + } +} + +for(@line) { + if (! /^#/) { + if(/\s(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) { + my $name = $2; + if (! defined $local{$name} || defined $weak{$name} ) { + s/hbrr/hbra/ || + s/brsl/brasl/ || + s/br/bra/ ; + } + } + } + print ; +} + +# end diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/ld.script.ed --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/get_segment/spe/ld.script.ed Thu Sep 24 17:44:58 2009 +0900 @@ -0,0 +1,14 @@ +/ \.text / +/\*(\.text/ +s/\*(\.text/*( EXCLUDE_FILE(spe\/olay\/*.o) .text/ +/} =0/ +a + OVERLAY : + { + .segment1 { spe/olay/add.o(.text) } + .segment2 { spe/olay/mul.o(.text) } + .segment3 { spe/olay/div.o(.text) } + .segment4 { spe/olay/sub.o(.text) } + } +. +w diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/ld.script.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/get_segment/spe/ld.script.orig Thu Sep 24 17:44:58 2009 +0900 @@ -0,0 +1,193 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-spu", "elf32-spu", + "elf32-spu") +OUTPUT_ARCH(spu) +ENTRY(_start) +SEARCH_DIR("/usr/spu/lib"); +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = 0); . = 0; + .interrupt : { KEEP(*(.interrupt)) } + .interp : { *(.interp) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } + .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } + .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } + .rel.data.rel.ro : { *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) } + .rela.data.rel.ro : { *(.rela.data.rel.ro* .rela.gnu.linkonce.d.rel.ro.*) } + .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } + .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } + .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } + .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } + .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } + .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } + .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .text : + { + *(.text .stub .text.* .gnu.linkonce.t.*) + KEEP (*(.text.*personality*)) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(0x80); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got.plt) *(.got) } + .data : + { + *(.data .data.* .gnu.linkonce.d.*) + KEEP (*(.gnu.linkonce.d.*personality*)) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 16 : 1); + } + .toe ALIGN(128) : { *(.toe) } = 0 + . = ALIGN(16); + . = ALIGN(16); + PROVIDE (__stack = 0x3fff0); + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .note.spu_name 0 : { KEEP(*(.note.spu_name)) } + /DISCARD/ : { *(.note.GNU-stack) } +} diff -r ead3024bcc3c -r a6e893105097 example/get_segment/spe/spe-main.cc --- a/example/get_segment/spe/spe-main.cc Thu Sep 24 17:44:09 2009 +0900 +++ b/example/get_segment/spe/spe-main.cc Thu Sep 24 17:44:58 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); }