Mercurial > hg > Game > Cerium
changeset 1106:a1c5d7c51db0 draft
merge resize ( this branch is not yet worked )
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 03 Jan 2011 18:04:08 +0900 |
parents | 1ef561eb1ef5 (current diff) f80524d00a2c (diff) |
children | 25d3cfb85439 |
files | |
diffstat | 21 files changed, 427 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/main.cc Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/main.cc Mon Jan 03 18:04:08 2011 +0900 @@ -35,6 +35,9 @@ { int machineNum = 1; int speIdle = 0; + + TaskManager *manager = new TaskManager(machineNum); + for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0) { machineNum = atoi(argv[++i]); @@ -43,22 +46,23 @@ } else if (strcmp(argv[i], "-speidle") == 0) { speIdle = atoi(argv[++i]); } + } - TaskManager *manager = new TaskManager(machineNum); manager->init(speIdle); + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-help") == 0) { + if (usr_help_str) { + manager->get_scheduler()->printf("%s", usr_help_str); + } + manager->get_scheduler()->printf("%s", help_str); + return EXIT_SUCCESS; + } + } + manager->set_TMend(defaultTMend); - for (int i = 1; argv[i]; ++i) { - if (strcmp(argv[i], "-help") == 0) { - if (usr_help_str) { - manager->get_scheduler()->printf("%s", usr_help_str); - } - manager->get_scheduler()->printf("%s", help_str); - return EXIT_SUCCESS; - } - } if (profile) manager->start_profile(); if (TMmain(manager, argc, argv) < 0) {
--- a/TaskManager/kernel/schedule/SchedTask.cc Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Mon Jan 03 18:04:08 2011 +0900 @@ -79,6 +79,11 @@ } +void +SchedTask::setup_outputData() +{ + writebuf = manager->allocate(task->w_size); +} void SchedTask::exec() @@ -86,7 +91,7 @@ task_list[task->command].wait(scheduler,task->command); TaskObjectRun run = task_list[task->command].run; if (task->w_size > 0) { - writebuf = manager->allocate(task->w_size); + setup_outputData(); } scheduler->dma_wait(DMA_READ + this->tag); run(this, readbuf, writebuf); @@ -181,6 +186,7 @@ void* SchedTask::get_output(void *buff, int index) {return writebuf; } memaddr SchedTask::get_outputAddr(int index) { return task->wbuf; } int SchedTask::get_outputSize(int index) { return task->w_size; } +void SchedTask::set_outputSize(int index, int size){task->w_size = size;} memaddr SchedTask::get_param(int index) { return task->param; }
--- a/TaskManager/kernel/schedule/SchedTask.h Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Mon Jan 03 18:04:08 2011 +0900 @@ -39,6 +39,7 @@ int read_size() { return task->r_size; } int write_size() { return task->w_size; } void set_write_size(int w) { task->w_size = w; } + void setup_outputData(); void* get_input(void *buff, int index); void* get_output(void *buff, int index); @@ -49,6 +50,8 @@ int get_inputSize(int index); int get_outputSize(int index); + void set_outputSize(int index, int size); + int get_cpuid(); void* global_alloc(int id, int size);
--- a/TaskManager/kernel/schedule/SchedTaskArray.cc Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.cc Mon Jan 03 18:04:08 2011 +0900 @@ -107,6 +107,23 @@ } +void +SchedTaskArray::setup_outputData() +{ + // allocate write buffer + outListData.length = atask->outData_count; + outListData.size = atask->outData_total_size(); + // atask->outData_offset += cur_index + 1 ; // to avoid compiler bug + outListData.element = atask->outData(0); + outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); + bound(&outListData); + + writebuf = manager->allocate(outListData.size); + //if (outListData.element == inListData.element ) { + // printf("bad %x\n",outListData.element); + //} +} + /** * Wait read data and execute task * Start write DMA @@ -117,18 +134,7 @@ task_list[atask->command].wait(scheduler,atask->command); TaskObjectRun run = task_list[atask->command].run; if (atask->outData_count > 0) { - // allocate write buffer - outListData.length = atask->outData_count; - outListData.size = atask->outData_total_size(); - // atask->outData_offset += cur_index + 1 ; // to avoid compiler bug - outListData.element = atask->outData(0); - outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); - bound(&outListData); - - writebuf = manager->allocate(outListData.size); - //if (outListData.element == inListData.element ) { - // printf("bad %x\n",outListData.element); - //} + setup_outputData(); } scheduler->dma_wait((DMA_READ + this->tag)); run(this, get_input(readbuf, 0), get_output(writebuf, 0)); @@ -247,6 +253,12 @@ return outListData.element[index].size; } +void +SchedTaskArray::set_outputSize(int index, int size) +{ + outListData.element[index].size = size; +} + memaddr SchedTaskArray::get_param(int index) {
--- a/TaskManager/kernel/schedule/SchedTaskArray.h Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.h Mon Jan 03 18:04:08 2011 +0900 @@ -30,12 +30,15 @@ void write(); SchedTaskBase* next(Scheduler *, SchedTaskBase *); + void setup_outputData(); + void* get_input(void*, int); memaddr get_inputAddr(int); int get_inputSize(int); void* get_output(void*, int); memaddr get_outputAddr(int); int get_outputSize(int); + void set_outputSize(int index, int size); memaddr get_param(int); int read_size();
--- a/TaskManager/kernel/schedule/SchedTaskBase.h Tue Dec 28 18:11:05 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskBase.h Mon Jan 03 18:04:08 2011 +0900 @@ -29,6 +29,8 @@ virtual void write() {} virtual SchedTaskBase* next(Scheduler *, SchedTaskBase*) {return 0;} + virtual void setup_outputData() {}; + /* functions */ virtual void* get_output(void *buff, int index) { return 0; } virtual void* get_input(void *buff, int index) { return 0;} @@ -40,6 +42,7 @@ virtual memaddr get_outputAddr(int index) {return 0;} virtual int get_inputSize(int index) {return 0;} virtual int get_outputSize(int index) {return 0;} + virtual void set_outputSize(int index, int size) {}; virtual int get_cpuid() {return 0;}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Container.h Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,6 @@ + +typedef struct Container { + int length; + + int data[1]; +} Container, *ContainerPtr;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Func.h Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,5 @@ +enum { +#include "SysTasks.h" + RESIZE, +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,24 @@ +default: macosx + +macosx: FORCE + @echo "Make for Mac OS X" + @$(MAKE) -f Makefile.macosx + +fifo64: FORCE + @echo "Make for Mac OS X 64bit mode" + @$(MAKE) -f Makefile.macosx ABIBIT=64 + +linux: FORCE + @echo "Make for Linux" + @$(MAKE) -f Makefile.linux + +cell: FORCE + @echo "Make for PS3 (Cell)" + @$(MAKE) -f Makefile.cell + +FORCE: + +clean: + @$(MAKE) -f Makefile.macosx clean + @$(MAKE) -f Makefile.linux clean + @$(MAKE) -f Makefile.cell clean \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.cell Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,45 @@ +include ./Makefile.def + +ABIBIT=32 +CFLAGS += -m$(ABIBIT) -D__CERIUM_CELL__ + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lCellManager -lspe2 -lpthread -Wl,--gc-sections + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) speobject + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +speobject: + cd spe; $(MAKE) ABIBIT=$(ABIBIT) + +run: + ./$(TARGET) -cpu 6 + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo ppu-gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + cd spe; $(MAKE) clean
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.def Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,14 @@ +TARGET = resize + +# include/library path +# ex macosx +#CERIUM = /Users/gongo/Source/Cerium + +# ex linux/ps3 +CERIUM = ../../../Cerium + +CC = g++ -m32 +CFLAGS = -g -Wall -O9 + +INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L${CERIUM}/TaskManager
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.linux Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,36 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lFifoManager + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + rm -f spe/*~ spe/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.macosx Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,36 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lFifoManager `sdl-config --libs` + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + rm -f spe/*~ spe/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/main.cc Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "TaskManager.h" +#include "Container.h" +#include "Func.h" + +#define CONTAINER_DATA_SIZE 4096 + +extern void task_init(void); + +static int count = 1; +static int spe_num = 1; +static int data_size = 10; +static int data_length = 1; + +extern TaskManager *manager; + +const char *usr_help_str = "Usage: ./resize [-cpu spe_num] [-count N]\n\ + -cpu Number of SPE (default 1) \n\ + -count Number of task is print \"Hello, World!!\""; + +int +init(int argc, char **argv) +{ + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-count") == 0) { + count = atoi(argv[++i]); + } else if (strcmp(argv[i], "-cpu") == 0) { + spe_num = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-length") == 0) { + data_length = atoi(argv[++i]); + } + } + + return 0; +} + + +static void +checkData(SchedTask *s, void *data, void *arg1) +{ + ContainerPtr obj = (ContainerPtr)data; + int data_length = obj->length; + + for(int i =0;i <data_length;i++) { + int idata = obj->data[i]; + printf("data[%d] = %d\n", i, idata); + } + + free(data); +} + + +static void +resize_init(TaskManager *manager) +{ + HTaskPtr resize_task = manager->create_task(RESIZE); + ContainerPtr obj = (ContainerPtr)manager->allocate(CONTAINER_DATA_SIZE); + obj->length = 0; + + resize_task->set_param(0, (memaddr)data_length); + resize_task->set_outData(0, obj, 0); + + resize_task->set_post(checkData, (void*)obj, NULL); + resize_task->set_cpu(SPE_ANY); + resize_task->spawn(); +} + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + if (init(argc, argv) < 0) { + return -1; + } + + // Task Register + // ppe/task_init.cc + task_init(); + + resize_init(manager); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/Resize.cc Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,26 @@ +#include <stdio.h> +#include "SchedTask.h" +#include "../Container.h" +#include "Resize.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask1(Resize,resize); + +static int +resize(SchedTask *smanager, void *rbuf, void *wbuf) +{ + long length = (long)smanager->get_param(0); + + smanager->set_outputSize(0, sizeof(Container)+sizeof(int)*(length-1)); + smanager->setup_outputData(); + + ContainerPtr wcontainer = (ContainerPtr)smanager->get_output(wbuf, 0); + + for (int i =0; i < length;i++){ + wcontainer->data[i] = i; + } + + wcontainer->length = length; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/Resize.h Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_RESIZE +#define INCLUDED_TASK_RESIZE + +#include "SchedTask.h" + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/task_init.cc Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Resize); + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init() +{ + SchedRegisterTask(RESIZE, Resize); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Makefile Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,26 @@ +include ../Makefile.def + +TARGET = ../spe-main + +SRCS_TMP = $(wildcard *.cc) +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +CC = spu-g++ -D__CERIUM_CELL__ -DABIBIT=$(ABIBIT) +CFLAGS = -O9 -g -Wall -fno-exceptions -fno-rtti#-DDEBUG +INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L../${CERIUM}/TaskManager -lspemanager -Wl,--gc-sections + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +clean: + rm -f $(TARGET) $(OBJS) + rm -f *~ \#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Resize.cc Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,26 @@ +#include <stdio.h> +#include "SchedTask.h" +#include "../Container.h" +#include "Resize.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask1(Resize,resize); + +static int +resize(SchedTask *smanager, void *rbuf, void *wbuf) +{ + long length = (long)smanager->get_param(0); + + smanager->set_outputSize(0, sizeof(Container)+sizeof(int)*(length-1)); + smanager->setup_outputData(); + + ContainerPtr wcontainer = (ContainerPtr)smanager->get_output(wbuf, 0); + + for (int i =0; i < length;i++){ + wcontainer->data[i] = i; + } + + wcontainer->length = length; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Resize.h Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_RESIZE +#define INCLUDED_TASK_RESIZE + +#include "SchedTask.h" + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/spe-main.cc Mon Jan 03 18:04:08 2011 +0900 @@ -0,0 +1,14 @@ +#include "Func.h" +#include "Scheduler.h" + +SchedExternTask(Resize); + +/** + * この関数は SpeScheduler から呼ばれるので + * 必ずこの関数名でお願いします。 + */ +void +task_init(Scheduler *s) +{ + SchedRegisterTask(RESIZE, Resize); +}