# HG changeset patch # User gongo # Date 1202210570 -32400 # Node ID 2356238ebea7ba377f1c33b74901cdd3ad349d9d # Parent 70e9baa00f516c036ab727aad62cab58a7c2e2f2 *** empty log message *** diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoDmaManager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoDmaManager.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,54 @@ +#include +#include +#include "FifoDmaManager.h" + +void +FifoDmaManager::dma_load(void *buf, unsigned int addr, int size, int mask) +{ + memcpy(buf, (void*)addr, size); +} + +void +FifoDmaManager::dma_store(void *buf, unsigned int addr, int size, int mask) +{ + memcpy((void*)addr, buf, size); +} + +/** + * mask で設定した DMA 転送の完了を待つ + */ +void +FifoDmaManager::dma_wait(int mask) +{ + //spu_writech(MFC_WrTagMask, 1 << mask); + //spu_mfcstat(MFC_TAG_UPDATE_ALL); +} + +void +FifoDmaManager::mail_write(unsigned int data) +{ + //spu_writech(SPU_WrOutMbox, data); + + mail_sendQueue = append_mailQueue(mail_sendQueue, + mailManager->create_mail(data)); +} + +unsigned int +FifoDmaManager::mail_read(void) +{ + MailQueuePtr q; + unsigned int ret; + + q = mail_recvQueue; + + if (q == NULL) { + return 0; // error か 正しい値か判断できないな・・・ + } + + mail_recvQueue = mail_recvQueue->next; + + ret = q->data; + mailManager->free_mailQueue(q); + + return ret; +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoDmaManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoDmaManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,28 @@ +#ifndef INCLUDED_FIFO_DMA_MANAGER +#define INCLUDED_FIFO_DMA_MANAGER + +#ifndef INCLUDED_DMA_MANAGER +# include "DmaManager.h" +#endif + +#ifndef INCLUDED_MAIL_MANAGER +# include "MailManager.h" +#endif + +class FifoDmaManager : public DmaManager { +public: + /* variables */ + MailManager *mailManager; + MailQueuePtr mail_recvQueue; + MailQueuePtr mail_sendQueue; + + /* functions */ + void dma_load(void *buf, unsigned int addr, int size, int mask); + void dma_store(void *buf, unsigned int addr, int size, int mask); + void dma_wait(int mask) ; + + void mail_write(unsigned int data); + unsigned int mail_read(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoTaskInfo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoTaskInfo.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,71 @@ +#include +#include +#include "FifoTaskInfo.h" + +void +FifoTaskInfo::init(void) +{ + init_pool_taskQueue(TASK_MAX_SIZE*4); + init_pool_task(TASK_MAX_SIZE*2); + init_pool_taskList(2); + + machineTaskList = get_free_taskList(); +} + +int +FifoTaskInfo::extend_pool_taskList(int num) +{ + TaskListPtr q; + + q = (TaskListPtr)malloc(sizeof(TaskList)*(num+1)); + + if (q == NULL) { + return -1; + } + + q->next = taskListPool; + taskListPool = q; + + /* Connect all free pack_list in the pool */ + q = taskListPool + 1; + for (q = taskListPool + 1; num-- > 0; q++) { + q->next = q + 1; + } + q->next = freeTaskList; + freeTaskList = taskListPool + 1; + + return 0; +} + +TaskListPtr +FifoTaskInfo::get_available_taskList(void) +{ + TaskListPtr list, q; + + list = machineTaskList; + + while (list->next) list = list->next; + + if (list->length < TASK_MAX_SIZE) { + return list; + } else { + q = get_free_taskList(); + machineTaskList = append_taskList(machineTaskList, q); + return q; + } +} + +void +FifoTaskInfo::clear_taskList(void) +{ + TaskListPtr p, p1; + + machineTaskList->length = 0; + + p = machineTaskList->next; + while (p) { + p1 = p; + p = p->next; + free_taskList(p1); + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoTaskInfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoTaskInfo.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,20 @@ +#ifndef INCLUDED_FIFO_TASK_INFO +#define INCLUDED_FIFO_TASK_INFO + +#ifndef INCLUDED_TASK_INFO +# include "TaskInfo.h" +#endif + +class FifoTaskInfo : public TaskInfo { +public: + /* function */ + void init(void); + int extend_pool_taskList(int num); + TaskListPtr get_available_taskList(void); + void clear_taskList(void); + + /* variables */ + TaskListPtr machineTaskList; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoTaskManagerImpl.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,128 @@ +#include +#include +#include +#include "FifoTaskManagerImpl.h" +#include "ppe_spe.h" + +void +FifoTaskManagerImpl::init(void) +{ + taskInfo = new FifoTaskInfo(); + taskInfo->init(); + + mailManager = new MailManager(); + mailManager->init_pool_mailQueue(20); +} + +TaskListPtr +FifoTaskManagerImpl::set_task(void) +{ + // ここ...直すかな + FifoTaskInfo *info = (FifoTaskInfo*)taskInfo; + TaskListPtr list = info->machineTaskList; + TaskQueuePtr queue = info->activeTaskQueue; + TaskQueuePtr d; + HTaskPtr htask; + TaskPtr task; + + if (queue == NULL) { + return NULL; + } + + // Fixme + // ここは、clear_taskList とか? + list->length = 0; + + while (queue) { + htask = queue->task; + d = queue; + queue = queue->next; + + task = &list->tasks[list->length++]; + task->command = htask->command; + task->in_addr = htask->in_addr; + task->out_addr = htask->out_addr; + task->in_size = htask->in_size; + task->self = htask; + + info->free_taskQueue(d); + } + + info->activeTaskQueue = NULL; + + return list; +} + +// ../spe/main.cpp +extern MailQueuePtr spe_main(MailManager*, MailQueuePtr); + +/** + * spe 側は MY_SPE_COMMAND_EXIT を受け取るまでは別スレッドで動き続ける。 + * fifo version では sequential に動かすため、 + * mail list の最後に番兵として MY_SPE_COMMAND_EXIT のメールを入れる。 + * これで、fifo での spe 側は、mail で受け取った task_list を処理した後 + * EXIT を受け取って終了する・・・といいな + */ +void +FifoTaskManagerImpl::run(void) +{ + TaskListPtr list; + MailQueuePtr mail_list = NULL; + MailQueuePtr list_mail = NULL; // task list + MailQueuePtr sentinel = NULL; // 番兵 + + // 暫定 + list = set_task(); + + list_mail = mailManager->create_mail((unsigned int)list); + mail_list = append_mailQueue(mail_list, list_mail); + + do { + sentinel = mailManager->create_mail(MY_SPE_COMMAND_EXIT); + mail_list = append_mailQueue(mail_list, sentinel); + + // 返って来た mail_list には、spe からの mail がある + mail_list = spe_main(mailManager, mail_list); + mail_list = mail_check(mail_list); + } while (mail_list); +} + +MailQueuePtr +FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list) +{ + MailQueuePtr q = mail_list; + MailQueuePtr d; + MailQueuePtr ret = NULL; + unsigned int data; + TaskListPtr next_list; + + while (q) { + data = q->data; + + if (data == MY_SPE_STATUS_READY) { + printf("[FIFO] finish\n"); + next_list = set_task(); + if (next_list != NULL) { + d = mailManager->create_mail((unsigned int)next_list); + ret = append_mailQueue(ret, d); + } + } else { + printf("[PPE] recv from : 0x%x\n", data); + taskInfo->check_task_finish((HTaskPtr)data); + } + + d = q; + q = q->next; + + mailManager->free_mailQueue(d); + } + + return ret; +} + + +TaskManagerImpl* +create_impl(int num) +{ + return new FifoTaskManagerImpl(); +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/FifoTaskManagerImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,32 @@ +#ifndef INCLUDED_FIFO_TASK_MANAGER_IMPL +#define INCLUDED_FIFO_TASK_MANAGER_IMPL + +#ifndef INCLUDED_FIFO_TASK_INFO +# include "FifoTaskInfo.h" +#endif + +#ifndef INCLUDED_TASK_MANAGER_IMPL +# include "TaskManagerImpl.h" +#endif + +#ifndef INCLUDED_MAIL_MANAGER +# include "MailManager.h" +#endif + +class FifoTaskManagerImpl : public TaskManagerImpl { +public: + /* functions */ + void init(void); + void run(void); + + TaskListPtr set_task(void); + +private: + /* variables */ + MailManager *mailManager; + + /* functions */ + MailQueuePtr mail_check(MailQueuePtr mail_list); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/MailManager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/MailManager.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,80 @@ +#include +#include "MailManager.h" + +int +MailManager::init_pool_mailQueue(int num) +{ + if (!mailQueuePool) { + return extend_pool_mailQueue(num); + } + return 0; +} + +int +MailManager::extend_pool_mailQueue(int num) +{ + MailQueuePtr q; + + q = new MailQueue[num+1]; + + if (q == NULL) { + return -1; + } + q->next = mailQueuePool; + mailQueuePool = q; + + /* Connect all free queue in the pool */ + q = mailQueuePool + 1; + for (q = mailQueuePool + 1; num-- > 0; q++) { + q->next = q + 1; + } + q->next = freeMailQueue; + freeMailQueue = mailQueuePool + 1; + + return 0; +} + +MailQueuePtr +MailManager::create_mail(unsigned int data) +{ + return get_free_mailQueue(data); +} + +MailQueuePtr +MailManager::get_free_mailQueue(unsigned int data) +{ + MailQueuePtr q; + + if (!freeMailQueue) { + extend_pool_mailQueue(30); + } + q = freeMailQueue; + freeMailQueue = freeMailQueue->next; + + q->data = data; + q->next = NULL; + + return q; +} + +void +MailManager::free_mailQueue(MailQueuePtr q) +{ + q->next = freeMailQueue; + freeMailQueue = q; +} + + +MailQueuePtr +append_mailQueue(MailQueuePtr list, MailQueuePtr q) +{ + MailQueuePtr p = list; + + if (p == NULL) { + return q; + } else { + while(p->next) p = p->next; + p->next = q; + return list; + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/MailManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/MailManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,26 @@ +#ifndef INCLUDED_MAIL_MANAGER +#define INCLUDED_MAIL_MANAGER + +typedef struct mail_queue { + unsigned int data; + struct mail_queue *next; +} MailQueue, *MailQueuePtr; + +class MailManager { +public: + /* functions */ + int init_pool_mailQueue(int num); + int extend_pool_mailQueue(int num); + MailQueuePtr create_mail(unsigned int data); + MailQueuePtr get_free_mailQueue(unsigned int data); + void free_mailQueue(MailQueuePtr q); + +private: + /* variables */ + MailQueuePtr mailQueuePool; + MailQueuePtr freeMailQueue; +}; + +extern MailQueuePtr append_mailQueue(MailQueuePtr list, MailQueuePtr q); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/Makefile Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,17 @@ +SRCS = $(wildcard *.cpp) +OBJS = $(SRCS:.cpp=.o) + +CC = g++ +CFLAGS = -Wall -g -O2 +LIBS = + +.SUFFIXES: .cpp .o + +.cpp.o: + $(CC) $(CFLAGS) -c $< + +all: $(OBJS) + +clean: + rm -f *~ \#* + rm -f $(OBJS) \ No newline at end of file diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Fifo/spe-main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Fifo/spe-main.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,35 @@ +#include +#include +#include "SpeManager.h" +#include "FifoDmaManager.h" +#include "MailManager.h" + + +/** + * src/ppe/fifo/fifo_manager_impl.cpp から extern でリンクされる(はず... + */ +MailQueuePtr +spe_main(MailManager* _mailManager, MailQueuePtr mail_list) +{ + SpeManager *manager = new SpeManager(); + FifoDmaManager *connect = new FifoDmaManager(); + MailQueuePtr ret; + + connect->mail_recvQueue = mail_list; + connect->mail_sendQueue = NULL; + connect->mailManager = _mailManager; + manager->set_connect((DmaManager*)connect); + + printf("[FIFO] start\n"); + + manager->init(); + manager->run(); + manager->finish(); + + ret = connect->mail_sendQueue; + + delete connect; + delete manager; + + return ret; +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Makefile Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,31 @@ +include ./Makefile.def + +TAGS = gtags +TAGSOPTION = +TAGSFILE = GPATH GRTAGS GSYMS GTAGS + +default: fifo + +fifo: FORCE + @$(MAKE) -f Makefile.fifo + +cell: FORCE + @$(MAKE) -f Makefile.cell + +FORCE: + +distclean: clean + rm -f $(TAGSFILE) + +clean: + rm -f *~ \#* + rm -f $(TARGET) + cd $(KERN_PPE_DIR); rm -f *~ \#* + cd $(KERN_SPE_DIR); rm -f *~ \#* + cd $(IMPL_FIFO_DIR); rm -f *~ \#* + cd $(IMPL_CELL_DIR); rm -f *~ \#* + rm -f $(KERN_PPE_OBJS) $(KERN_SPE_OBJS) + rm -f $(IMPL_FIFO_OBJS) $(IMPL_CELL_OBJS) + +tags: + $(TAGS) $(TAGSOPTION) \ No newline at end of file diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Makefile.def --- a/TaskManager/Makefile.def Tue Feb 05 20:22:50 2008 +0900 +++ b/TaskManager/Makefile.def Tue Feb 05 20:22:50 2008 +0900 @@ -23,4 +23,4 @@ CFLAGS = -Wall -O2 -g LIBS = -INCLUDE = -I../include \ No newline at end of file +INCLUDE = -I../include/TaskManager \ No newline at end of file diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Makefile.fifo --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Makefile.fifo Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,12 @@ +include ./Makefile.def + +.SUFFIXES: .cpp .o + +.cpp.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: default +default: $(TARGET) + +$(TARGET): $(KERN_PPE_OBJS) $(KERN_SPE_OBJS) $(IMPL_FIFO_OBJS) + ar crus $@ $(KERN_PPE_OBJS) $(KERN_SPE_OBJS) $(IMPL_FIFO_OBJS) diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Test/Sum/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/Sum/Makefile Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,19 @@ +TARGET = main + +CC = g++ +CFLAGS = -Wall -O2 -g +LIBS = -L../../ -lmanager +INCLUDE = -I../../../include/TaskManager + + +all: $(TARGET) + +$(TARGET): main.o + $(CC) $< -o $@ $(LIBS) + +main.o: main.cpp + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -f main.o $(TARGET) + rm -f *~ \#* \ No newline at end of file diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/Test/Sum/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/Sum/main.cpp Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,79 @@ +#include +#include "TaskManager.h" +//#include "ppe_prof.h" + +#define MAX 1024 + +int data[MAX] __attribute__((aligned(16))); +int buff[MAX] __attribute__((aligned(16))); +int out[MAX] __attribute__((aligned(16))); + + +typedef unsigned long long Uint64; +typedef unsigned int Uint32; + +int +main(void) +{ + int i; + int div = MAX/16; + + TaskManager *manager; + HTaskPtr *task = new HTaskPtr[div]; + HTaskPtr last; + + //unsigned int ts, te; + + manager = new TaskManager(1); + manager->init(); + + for (i = 0; i < MAX; i++) { + data[i] = i; + } + + memset(buff, 0, sizeof(int)*1024); + memset(out, 0, sizeof(int)*1024); + + for (i = 0; i < div; i++) { + task[i] = manager->create_task(4, sizeof(int)*16, + (Uint32)&data[i*16], + (Uint32)&buff[i*4], + NULL); + } + + last = manager->create_task(5, sizeof(int)*256, + (Uint32)buff, (Uint32)&out[0], NULL); + +#if 0 + for (i = 0; i < div-1; i++) { + manager->set_task_depend(task[i], task[i+1]); + } + manager->set_task_depend(task[div-1], last); + + for (i = 0; i < div; i++) { + manager->run_task(task[i]); + } + manager->run_task(last); +#else + for (i = 0; i < div; i++) { + manager->set_task_depend(task[i], last); + } + for (i = 0; i < div; i++) { + manager->run_task(task[i]); + } + manager->run_task(last); +#endif + + manager->run(); + + printf("manager : %d\n", out[0]); + + out[0] = 0; + for (i = 0; i < MAX; i++) { + out[0] += i; + } + + printf("for : %d\n", out[0]); + + return 0; +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/Makefile Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,35 @@ + + +PPEDIR = ppe +PPESRCS = $(wildcard $(PPEDIR)/*.cpp) +PPEOBJS = $(PPESRCS:.cpp=.o) +PPECC = g++ +PPECFLAGS = -Wall -g -O2 +PPELIBS = + +SPEDIR = spe +SPESRCS = $(wildcard $(SPEDIR)/*.cpp) +SPEOBJS = $(SPESRCS:.cpp=.o) +SPECC = $(PPECC) +SPECFLAGS = $(PPECFLAGS) +SPELIBS = $(PPELIBS) + +IMPLDIR = ../Fifo +IMPLSRCS = $(wildcard $(IMPLDIR)/*.cpp) +IMPLOBJS = $(IMPLSRCS:.cpp=.o) +IMPLCC = $(PPECC) +IMPLCFLAGS = $(PPECFLAGS) +IMPLLIBS = $(PPELIBS) + +.SUFFIXES: .cpp .o + +.cpp.o: + $(CC) $(CFLAGS) -c $< + + + +clean: + rm -f *~ \#* + rm -f $(PPEDIR)/*~ $(PPEDIR)/\#* + rm -f $(SPEDIR)/*~ $(SPEDIR)/\#* + rm -f $(PPEOBJS) $(SPEOBJS) \ No newline at end of file diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskInfo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskInfo.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,288 @@ +#include "TaskInfo.h" + +TaskInfo::TaskInfo(int num) +{ + machineNum = num; +} + +/** + * initialize pool of task_pack_list + * @return if (success) ? 0 : -1 + */ +int +TaskInfo::init_pool_taskList(int num) +{ + if (!taskListPool) { + return extend_pool_taskList(num); + } + return 0; +} + +/** + * @return free list from pool of task_pack_list + */ +TaskListPtr +TaskInfo::get_free_taskList(void) +{ + TaskListPtr q; + + if (!freeTaskList) { + extend_pool_taskList(10); + } + q = freeTaskList; + freeTaskList = (TaskListPtr)freeTaskList->next; + + q->length = 0; + q->next = 0; + + return q; +} + +/** + * initialize pool of task_queue + * @return if (success) ? 0 : -1 + */ +int +TaskInfo::init_pool_taskQueue(int num) +{ + if (!taskQueuePool) { + return extend_pool_taskQueue(num); + } + return 0; +} + +int +TaskInfo::extend_pool_taskQueue(int num) +{ + TaskQueuePtr q; + + q = new TaskQueue[num+1]; + + if (q == NULL) { + return -1; + } + q->next = taskQueuePool; + taskQueuePool = q; + + /* Connect all free queue in the pool */ + q = taskQueuePool + 1; + for (q = taskQueuePool + 1; num-- > 0; q++) { + q->next = q + 1; + } + q->next = freeTaskQueue; + freeTaskQueue = taskQueuePool + 1; + + return 0; +} + +TaskQueuePtr +TaskInfo::get_free_taskQueue(HTaskPtr task) +{ + TaskQueuePtr q; + + if (!freeTaskQueue) { + extend_pool_taskQueue(100); + } + q = freeTaskQueue; + freeTaskQueue = freeTaskQueue->next; + + q->task = task; + q->next = NULL; + + return q; +} + +/** + * initialize pool of task_queue + * @return if (success) ? 0 : -1 + */ +int +TaskInfo::init_pool_task(int num) +{ +#if 0 + taskPool = new Task[num]; + + if (!taskPool) { + return -1; + } else { + return 0; + } +#endif + + HTask::initMemPool(); + return 0; +} + +HTaskPtr +TaskInfo::get_free_task(int cmd, int size, + unsigned long long in_addr, + unsigned long long out_addr) +{ + HTaskPtr q; + + q = new HTask; // from memorypool + q->command = cmd; + q->in_addr = in_addr; + q->out_addr = out_addr; + q->in_size = size; + q->wait_me = NULL; + q->wait_i = NULL; + q->post_func = NULL; + + return q; +} + +void +TaskInfo::free_taskList(TaskListPtr q) +{ + q->next = freeTaskList; + freeTaskList = q; +} + +void +TaskInfo::free_taskQueue(TaskQueuePtr q) +{ + q->next = freeTaskQueue; + freeTaskQueue = q; +} + +void +TaskInfo::free_task(HTaskPtr q) +{ + delete q; +} + +/** + * [task] is added to active_task + */ +void +TaskInfo::append_activeTask(HTaskPtr task) +{ + TaskQueuePtr q; + + q = get_free_taskQueue(task); + activeTaskQueue = append_taskQueue(activeTaskQueue, q); +} + +/** + * [task] is added to wait_task + */ +void +TaskInfo::append_waitTask(HTaskPtr task) +{ + TaskQueuePtr q; + + q = get_free_taskQueue(task); + waitTaskQueue = append_taskQueue(waitTaskQueue, q); +} + +void +TaskInfo::check_task_finish(HTaskPtr task) +{ + notify_wait_taskQueue(task, task->wait_me); + task->post_func(); + + free_task(task); +} + +void +TaskInfo::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list) +{ + TaskQueuePtr p, d; + HTaskPtr task; + + p = list; // wait task list + + while (p) { + task = p->task; + task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend); + if (task->wait_i == NULL) { + d = p; + p = p->next; + append_activeTask(task); + waitTaskQueue = remove_taskQueue(waitTaskQueue, d); + } else { + p = p->next; + } + } +} + +TaskQueuePtr +TaskInfo::remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task) +{ + TaskQueuePtr p = list; + TaskQueuePtr p1; + + if (!p) return p; + + if (p->task == task) { + list = list->next; + free_taskQueue(p); + } else { + p1 = p->next; + while (p1 && p1->task && p1->task != task) { + p1 = p1->next; + p = p->next; + } + if (p1) { + p->next = p1->next; + free_taskQueue(p1); + } + } + + return list; +} + +TaskQueuePtr +TaskInfo::remove_taskQueue(TaskQueuePtr list, TaskQueuePtr q) +{ + TaskQueuePtr p = list; + TaskQueuePtr p1; + + if (!p) return p; + + if (p == q) { + list = list->next; + free_taskQueue(p); + } else { + p1 = p->next; + while (p1 && p1 != q) { + p1 = p1->next; + p = p->next; + } + if (p1) { + p->next = p1->next; + free_taskQueue(p1); + } + } + + return list; +} + +TaskListPtr +append_taskList(TaskListPtr list, TaskListPtr q) +{ + TaskListPtr p = list; + + if (!p) { + return q; + } else { + while (p->next) p = p->next; + p->next = q; + return list; + } +} + +TaskQueuePtr +append_taskQueue(TaskQueuePtr list, TaskQueuePtr q) +{ + TaskQueuePtr p = list; + + if (!p) { + return q; + } else { + while(p->next) p = p->next; + p->next = q; + return list; + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskInfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskInfo.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,64 @@ +#ifndef INCLUDED_TASK_INFO +#define INCLUDED_TASK_INFO + +#ifndef INCLUDED_TASK +# include "task.h" +#endif + +class TaskInfo { +public: + /* constructor */ + TaskInfo(int num = 1); + virtual ~TaskInfo(void) {} + + /* variables */ + TaskListPtr taskListPool; + TaskListPtr freeTaskList; + + TaskQueuePtr taskQueuePool; + TaskQueuePtr freeTaskQueue; + TaskQueuePtr waitTaskQueue; + TaskQueuePtr activeTaskQueue; + + /* function */ + virtual void init(void) = 0; + + // task list + int init_pool_taskList(int num); + virtual int extend_pool_taskList(int num) = 0; + virtual TaskListPtr get_available_taskList(void) = 0; + TaskListPtr get_free_taskList(void); + + // task queue + int init_pool_taskQueue(int num); + TaskQueuePtr get_free_taskQueue(HTaskPtr); + int extend_pool_taskQueue(int num); + + // task + int init_pool_task(int num); + HTaskPtr get_free_task(int cmd, int size, + unsigned long long in_addr, + unsigned long long out_addr); + + virtual void clear_taskList(void) = 0; + + void append_activeTask(HTaskPtr); + void append_waitTask(HTaskPtr); + + void free_taskList(TaskListPtr q); + void free_taskQueue(TaskQueuePtr q); + void free_task(HTaskPtr q); + + void check_task_finish(HTaskPtr task); + void notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list); + TaskQueuePtr remove_taskQueue(TaskQueuePtr list, TaskQueuePtr task); + TaskQueuePtr remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task); + +private: + int machineNum; +}; + +extern TaskQueuePtr append_taskQueue(TaskQueuePtr, TaskQueuePtr); +extern TaskListPtr append_taskList(TaskListPtr list, TaskListPtr q); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskManager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskManager.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,66 @@ +#include "TaskManager.h" + +TaskManager::TaskManager(int num) +{ + machineNum = num; +} + +/** + * create_impl(int); + * + * [cell版] ../../Cell/SpeTaskManagerImpl.cpp + * [fifo版] ../../Fifo/FifoTaskManagerImpl.cpp + * で定義されています。コンパイル時に + * + * % make cell ってすると cell 版が、 + * % make fifo ってすると fifo 版 がリンクされるようにしているので + * それに応じて create_impl が返す値を変えています。 + * cell だったら SpeManagerImpl, fifo だったら FifoManagerImpl です。 + * + * 今までは ifdef CELL とか書いてましたわ。どっちがいいかね + * + * てか、普通に TaskManagerImpl に関数持たせた方が早いか・・・? + */ +extern TaskManagerImpl* create_impl(int); + +void +TaskManager::init(void) +{ + m_impl = create_impl(machineNum); + m_impl->init(); +} + +/** + * @param command Task executes method number + * @param in_size Size of data + * @param in_addr Input address of data + * @param out_addr Output address of data + * @param func When this task ends, func execute. + * + * @return this task + */ + +HTaskPtr +TaskManager::create_task(int cmd, int size, unsigned long long in_addr, + unsigned long long out_addr, void (*func)(void)) +{ + return m_impl->create_task(cmd, size, in_addr, out_addr, func); +} + +void +TaskManager::set_task_depend(HTaskPtr master, HTaskPtr slave) +{ + m_impl->set_task_depend(master, slave); +} + +void +TaskManager::run_task(HTaskPtr task) +{ + m_impl->run_task(task); +} + +void +TaskManager::run(void) +{ + m_impl->run(); +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,28 @@ +#ifndef INCLUDED_TASK_MANAGER +#define INCLUDED_TASK_MANAGER + +#ifndef INCLUDED_TASK_MANAGER_IMPL +# include "TaskManagerImpl.h" +#endif + +class TaskManager { +public: + /* constructor */ + TaskManager(int num = 1); // The number of threads + + /* variables */ + TaskManagerImpl *m_impl; + + /* functions */ + void init(void); + HTaskPtr create_task(int cmd, int siz, unsigned long long in_addr, + unsigned long long out_addr, void (*func)(void)); + void set_task_depend(HTaskPtr master, HTaskPtr slave); + void run_task(HTaskPtr); + void run(void); + +private: + int machineNum; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskManagerImpl.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,56 @@ +#include "TaskManagerImpl.h" + +void +noaction(void) +{ +} + +TaskManagerImpl::TaskManagerImpl(int num) +{ + machineNum = num; +} + +HTaskPtr +TaskManagerImpl::create_task(int cmd, int size, + unsigned long long in_addr, + unsigned long long out_addr, + void (*func)(void)) +{ + HTaskPtr new_task; + + new_task = taskInfo->get_free_task(cmd, size, in_addr, out_addr); + + if (func == NULL) { + new_task->post_func = noaction; + } else { + new_task->post_func = func; + } + + return new_task; +} + +/** + * task の依存関係を設定 + * master task が終わってから、slave task を実行するように + */ +void +TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) +{ + TaskQueuePtr m, s; + + m = taskInfo->get_free_taskQueue(master); + s = taskInfo->get_free_taskQueue(slave); + + master->wait_me = append_taskQueue(master->wait_me, s); + slave->wait_i = append_taskQueue(slave->wait_i, m); +} + +void +TaskManagerImpl::run_task(HTaskPtr task) +{ + if (task->wait_i == NULL) { + taskInfo->append_activeTask(task); + } else { + taskInfo->append_waitTask(task); + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/ppe/TaskManagerImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,29 @@ +#ifndef INCLUDED_TASK_MANAGER_IMPL +#define INCLUDED_TASK_MANAGER_IMPL + +#ifndef INCLUDED_TASK_INFO +# include "TaskInfo.h" +#endif + +class TaskManagerImpl { +public: + /* constructor */ + TaskManagerImpl(int num = 1); + virtual ~TaskManagerImpl(void) {} + + /* variables */ + int machineNum; + TaskInfo* taskInfo; + + /* functions */ + virtual void init(void) = 0; + virtual void run(void) = 0; + + HTaskPtr create_task(int cmd, int siz, + unsigned long long in_addr, + unsigned long long out_addr, + void (*func)(void)); + void set_task_depend(HTaskPtr master, HTaskPtr slave); + void run_task(HTaskPtr); +}; +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/DmaManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/DmaManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,23 @@ +#ifndef INCLUDED_DMA_MANAGER +#define INCLUDED_DMA_MANAGER + +enum dma_tag { + DMA_READ, + DMA_WRITE +}; + +#include "ppe_spe.h" + +class DmaManager { +public: + virtual ~DmaManager(void) {}; + + virtual void dma_load(void *buf, unsigned int addr,int size, int mask) = 0; + virtual void dma_store(void *buf,unsigned int addr,int size, int mask) = 0; + virtual void dma_wait(int mask) = 0; + + virtual void mail_write(unsigned int data) = 0; + virtual unsigned int mail_read(void) = 0; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeExit.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeExit.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,13 @@ +#include +#include "SpeExit.h" +#include "error.h" + +SpeTaskBase* +SpeExit::next(SpeManager *m, SpeTaskBase *p) +{ + delete p; + + __debug("SpeExit::next()\n"); + + return NULL; +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeExit.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeExit.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,19 @@ +#ifndef INCLUDED_SPE_EXIT +#define INCLUDED_SPE_EXIT + +#ifndef INCLUDED_SPEMANAGER +# include "SpeManager.h" +#endif + +class SpeExit : public SpeTaskBase { +public: + /* constructor */ + SpeExit(void) {} + + /* variables */ + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeMail.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeMail.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,52 @@ +#include +#include "SpeMail.h" +#include "SpeTaskList.h" +#include "SpeExit.h" +#include "error.h" + +SpeMail::SpeMail(DmaManager *cn) +{ + connector = cn; +} + +void +SpeMail::read(void) +{ + + __debug("SpeMail::read()"); + + params_addr = connector->mail_read(); + +#ifdef DEBUG + printf("[SPE] SpeMail:[read] params_addr = 0x%x\n", params_addr); +#endif +} + +#ifdef DEBUG +void +SpeMail::exec(void) +{ + printf("SpeMail::exec()\n"); +} + +void +SpeMail::write(void) +{ + printf("SpeMail::write()\n"); +} +#endif + +SpeTaskBase* +SpeMail::next(SpeManager *m, SpeTaskBase *p) +{ + delete p; + + __debug("SpeMail::next()"); + + // if 文なくすには・・・関数ポインタ? + if ((int)params_addr == MY_SPE_COMMAND_EXIT) { + return new SpeExit(); + } else { + return new SpeTaskList(params_addr, m->get_curListBuf(), connector); + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeMail.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeMail.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,29 @@ +#ifndef INCLUDED_SPE_MAIL +#define INCLUDED_SPE_MAIL + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeMail : public SpeTaskBase{ +public: + /* constructor */ + SpeMail(DmaManager *); + + /* variables */ + unsigned int params_addr; + DmaManager* connector; + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + /* override functions */ + void read(void); // overwride + +#ifdef DEBUG + void exec(void); + void write(void); +#endif +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeManager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeManager.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,125 @@ +#include + +// 絶対 Fix me +// memalign のためにこんなことに・・・ +// ここもオブジェクトでやるべきだよなー +#ifdef CELL +# include +#else +# include +# include +#endif + +#include "SpeManager.h" +#include "SpeNop.h" +#include "error.h" + +SpeManager::SpeManager(void) +{ +} + +void +SpeManager::init(void) +{ + int i; + + /** + * memalign だと、なぜか同じアドレスしか帰ってこないあげく + * task3->exec のところで、 _start に飛んで最初からになって + * だけどループしなくて止まるとかよくわからん + * + * new すりゃあ大丈夫っぽい。が、アライメント云々で + * 最悪でも readBuf や writeBuf は memalign でしたいんだけどどうして? + * + * 追記 + * アライメントを128じゃなくて16にしたら通った。 + * ppe側も128にしてるんだけどなー + * 128にしたせいで、どっかサイズずれた? + */ + + for (i = 0; i < 2; i++) { +#ifdef CELL + listBuf[i] = + (TaskListPtr)memalign(DEFAULT_ALIGNMENT, sizeof(TaskList)); + readBuf[i] = memalign(DEFAULT_ALIGNMENT, 4*1024); + writeBuf[i] = memalign(DEFAULT_ALIGNMENT, 4*1024); +#else + listBuf[i] = new TaskList; + readBuf[i] = malloc(4*1024); + writeBuf[i] = malloc(4*1024); +#endif + } + + listBufFlg = 0; + readBufFlg = 0; + writeBufFlg = 0; + + task1 = new SpeNop(); + task2 = new SpeNop(); + task3 = new SpeNop(); +} + +void +SpeManager::set_connect(DmaManager* cn) +{ + connector = cn; +} + +void +SpeManager::run(void) +{ + SpeTaskBase* taskTmp; + + // main loop + do { + __debug("----------"); + task3->write(); + task2->exec(); + task1->read(); + + taskTmp = task3; + task3 = task2; + task2 = task1; + task1 = task1->next(this, taskTmp); + } while (task1); + + delete task3; + delete task2; +} + +void +SpeManager::finish(void) +{ + int i; + + for (i = 0; i < 2; i++) { +#ifdef CELL + free(listBuf[i]); +#else + delete listBuf[i]; +#endif + free(readBuf[i]); + free(writeBuf[i]); + } +} + +TaskListPtr +SpeManager::get_curListBuf(void) +{ + listBufFlg ^= 1; + return listBuf[listBufFlg]; +} + +void* +SpeManager::get_curReadBuf(void) +{ + readBufFlg ^= 1; + return readBuf[readBufFlg]; +} + +void* +SpeManager::get_curWriteBuf(void) +{ + writeBufFlg ^= 1; + return writeBuf[writeBufFlg]; +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,63 @@ +#ifndef INCLUDED_SPE_MANAGER +#define INCLUDED_SPE_MANAGER + +#ifndef INCLUDED_TASK +# include "task.h" +#endif + +#ifndef INCLUDED_DMA_MANAGER +# include "DmaManager.h" +#endif + +class SpeTaskBase; +class SpeManager; + +class SpeTaskBase { +public: + /* constructor */ + SpeTaskBase(void) {} + virtual ~SpeTaskBase(void) {} + + /* variables */ + + // noaction in default + virtual void load(void) {} + virtual void read(void) {} + virtual void exec(void) {} + virtual void write(void) {} + + /* functions */ + virtual SpeTaskBase* next(SpeManager *, SpeTaskBase *) = 0; +}; + + +class SpeManager { +public: + SpeManager(void); + + /* variables */ + int listBufFlg; + int readBufFlg; + int writeBufFlg; + TaskListPtr listBuf[2]; + void *readBuf[2]; + void *writeBuf[2]; + + DmaManager* connector; + + SpeTaskBase* task1; + SpeTaskBase* task2; + SpeTaskBase* task3; + + /* functions */ + void init(void); + void set_connect(DmaManager*); + void run(void); + void finish(void); + + TaskListPtr get_curListBuf(void); + void* get_curReadBuf(void); + void* get_curWriteBuf(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeNop.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeNop.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,37 @@ +#include +#include "SpeNop.h" +#include "SpeMail.h" +#include "error.h" + +SpeNop::SpeNop(void) +{ +} + +void +SpeNop::read(void) +{ + __debug("SpeNop::read()"); +} + +void +SpeNop::exec(void) +{ + __debug("SpeNop::exec()"); +} + +void +SpeNop::write(void) +{ + __debug("SpeNop::write()"); +} + + +SpeTaskBase* +SpeNop::next(SpeManager *m, SpeTaskBase *p) +{ + __debug("SpeNop::next()"); + + delete p; + + return new SpeMail(m->connector); +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeNop.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeNop.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,22 @@ +#ifndef INCLUDED_SPE_NOP +#define INCLUDED_SPE_NOP + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeNop : public SpeTaskBase { +public: + /* constructor */ + SpeNop(void); + + /* variables */ + + /* functions */ + void read(void); + void exec(void); + void write(void); + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeNop2Ready.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeNop2Ready.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,40 @@ +#include +#include "SpeNop2Ready.h" +#include "SpeMail.h" +#include "error.h" + +SpeNop2Ready::SpeNop2Ready(DmaManager *cn) +{ + connector = cn; +} + +void +SpeNop2Ready::read(void) +{ + __debug("SpeNop2Ready::read()"); +} + +void +SpeNop2Ready::exec(void) +{ + __debug("SpeNop2Ready::exec()"); + + connector->mail_write(MY_SPE_STATUS_READY); +} + +void +SpeNop2Ready::write(void) +{ + __debug("SpeNopReady::write()"); +} + + +SpeTaskBase* +SpeNop2Ready::next(SpeManager *m, SpeTaskBase *p) +{ + __debug("SpeNop2Ready::next()"); + + delete p; + + return new SpeMail(connector); +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeNop2Ready.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeNop2Ready.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,27 @@ +#ifndef INCLUDED_SPE_NOP2READY +#define INCLUDED_SPE_NOP2READY + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +#ifndef INCLUDED_SPE_NOP +# include "SpeNop.h" +#endif + +class SpeNop2Ready : public SpeNop { +public: + /* constructor */ + SpeNop2Ready(DmaManager*); + + /* variables */ + DmaManager* connector; + + /* functions */ + void read(void); + void exec(void); + void write(void); + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeTask.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeTask.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,161 @@ +#include +#include "SpeTask.h" +#include "SpeTaskList.h" +#include "SpeNop2Ready.h" +#include "DmaManager.h" +#include "error.h" + +int add(void*, void*); +int sub(void*, void*); +int mul(void*, void*); +int div(void*, void*); +int sum(void*, void*); +int sum2(void*, void*); + +int (*func_list[16])(void* wbuf, void* rbuf) = {add, sub, mul, div, sum, sum2, 0}; + +int +add(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0] + data[1]; + + return sizeof(int); +} + +int +sub(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]-data[1]; + + return sizeof(int); +} + +int +mul(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]*data[1]; + + return sizeof(int); +} + +int +div(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]/data[1]; + + return sizeof(int); +} + +int +sum(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + int i; + + *ret = 0; + + printf("[FIFO] sum\n"); + + for (i = 0; i < 16; i++) { + *ret += data[i]; + } + + return sizeof(int); +} + +int +sum2(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + int i; + + *ret = 0; + + for (i = 0; i < 64; i++) { + *ret += data[i*4]; + } + + return sizeof(int); +} + + +SpeTask::SpeTask(TaskListPtr _list, void *rbuf, void *wbuf, DmaManager* cn) +{ + list = _list; + readbuf = rbuf; + writebuf = wbuf; + connector = cn; +} + +void +SpeTask::read(void) +{ + __debug("SpeTask::read()"); + + task = &list->tasks[--list->length]; + connector->dma_load(readbuf, task->in_addr, task->in_size, DMA_READ); +} + +void +SpeTask::exec(void) +{ + __debug("SpeTask::exec()"); + + connector->dma_wait(DMA_READ); + +#ifdef DEBUG + printf(" task->command = %d\n", task->command); + printf(" task->in_size = %d\n", task->in_size); + printf(" task->in_addr = 0x%x\n", task->in_addr); + printf(" task->out_addr = 0x%x\n", task->out_addr); + printf(" list->next = 0x%x\n", (unsigned int)list->next); + printf(" list->length = 0x%x\n", (unsigned int)list->length); +#endif + + task->in_size = func_list[task->command](writebuf, readbuf); + connector->dma_store(writebuf, task->out_addr, task->in_size, DMA_WRITE); +} + +void +SpeTask::write(void) +{ + __debug("SpeTask::write()"); + + connector->dma_wait(DMA_WRITE); + connector->mail_write((unsigned int)task->self); +} + +SpeTaskBase* +SpeTask::next(SpeManager *m, SpeTaskBase *p) +{ + __debug("SpeTask::next()"); + + delete p; + + // ここ直さねば。どうやって if 文消そう? + // オブジェクト増やせばいいのかな + if (list->length == 0) { + if (list->next == 0) { + return new SpeNop2Ready(connector); + } else { + return new SpeTaskList((unsigned int)list->next, m->get_curListBuf(), connector); + } + } else { + return new SpeTask(list, m->get_curReadBuf(), + m->get_curWriteBuf(), connector); + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeTask.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeTask.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,37 @@ +#ifndef INCLUDED_SPE_TASK +#define INCLUDED_SPE_TASK + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeTask : public SpeTaskBase { +public: + /* constructor */ + SpeTask(TaskListPtr, void*, void*, DmaManager*); + + /* variables */ + TaskListPtr list; + TaskPtr task; + void *readbuf; + void *writebuf; + + DmaManager* connector; + + // work area + // global variable 用とか + // 次の task に引き渡したり + // size : デフォルトで 4k + // ppuから教えてもらう? task に入れる + void (*func)(void *wbuf, void *rbuf); + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + // override + void read(void); + void exec(void); + void write(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeTaskList.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeTaskList.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,53 @@ +#include +#include "SpeTaskList.h" +#include "SpeTask.h" +#include "SpeNop2Ready.h" +#include "DmaManager.h" +#include "error.h" + +SpeTaskList::SpeTaskList(unsigned int addr, TaskListPtr listbuf, DmaManager* c) +{ + params_addr = addr; + list = listbuf; + connector = c; +} + +void +SpeTaskList::read(void) +{ + __debug("SpeTaskList::read()"); + + connector->dma_load(list, params_addr, sizeof(TaskList), DMA_READ); + connector->dma_wait(DMA_READ); +} + +void +SpeTaskList::exec(void) +{ + __debug("SpeTaskList::exec()"); +} + +#ifdef DEBUG +void +SpeTaskList::write(void) +{ + printf("SpeTaskList::exec()\n"); +} +#endif + + + +SpeTaskBase* +SpeTaskList::next(SpeManager *m, SpeTaskBase *p) +{ + __debug("SpeTaskList::next()"); + + delete p; + + if (list->length < 1) { + return new SpeNop2Ready(connector); + } else { + return new SpeTask(list, m->get_curReadBuf(), + m->get_curWriteBuf(), connector); + } +} diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/SpeTaskList.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/SpeTaskList.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,34 @@ +#ifndef INCLUDED_SPE_TASKLIST +#define INCLUDED_SPE_TASKLIST + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeTaskList : public SpeTaskBase { +public: + /* constructor */ + SpeTaskList(unsigned int addr, TaskListPtr list, DmaManager* c); + + /* variables */ + unsigned int params_addr; + TaskListPtr list; + DmaManager* connector; + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + /* override functions */ + void read(void); + void exec(void); + +#ifdef DEBUG + void write(void); +#endif + +}; + +//extern void get_task_list(); +//extern void print_task_list(); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/error.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/error.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,13 @@ +#include +#include "error.h" + +#ifdef DEBUG +void +__debug(char *s) +{ + fprintf(stderr, "%s\n", s); +} + +#else +void __debug(char *s){} +#endif /* CELL */ diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/error.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/error.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,1 @@ +extern void __debug(char *str); diff -r 70e9baa00f51 -r 2356238ebea7 TaskManager/kernel/spe/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/spe/main.cc Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,112 @@ +#include +#include +#include "SpeManager.h" + +int add(void*, void*); +int sub(void*, void*); +int mul(void*, void*); +int div(void*, void*); +int sum(void*, void*); +int sum2(void*, void*); + +int (*func_list[16])(void* wbuf, void* rbuf) = {add, sub, mul, div, sum, sum2, 0}; + +int +add(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0] + data[1]; + + return sizeof(int); +} + +int +sub(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]-data[1]; + + return sizeof(int); +} + +int +mul(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]*data[1]; + + return sizeof(int); +} + +int +div(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + + *ret = data[0]/data[1]; + + return sizeof(int); +} + +int +sum(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + int i; + + *ret = 0; + + for (i = 0; i < 16; i++) { + *ret += data[i]; + } + + return sizeof(int); +} + +int +sum2(void *wbuf, void *rbuf) +{ + int *ret = (int*)wbuf; + int *data = (int*)rbuf; + int i; + + *ret = 0; + + for (i = 0; i < 64; i++) { + *ret += data[i*4]; + } + + return sizeof(int); +} + +#ifdef CELL + +#include "dma_spe.h" + +int +main(unsigned long long speid, + unsigned long long argc, unsigned long long argv) +{ + SpeManager *manager = new SpeManager(); + DmaManager *connect = new SpeDmaManager(); + manager->set_connect(connect); + + printf("[SPE] start\n"); + + manager->init(); + manager->run(); + manager->finish(); + + return 0; +} +#else + +#endif /* CELL */ diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/DmaManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/DmaManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,23 @@ +#ifndef INCLUDED_DMA_MANAGER +#define INCLUDED_DMA_MANAGER + +enum dma_tag { + DMA_READ, + DMA_WRITE +}; + +#include "ppe_spe.h" + +class DmaManager { +public: + virtual ~DmaManager(void) {}; + + virtual void dma_load(void *buf, unsigned int addr,int size, int mask) = 0; + virtual void dma_store(void *buf,unsigned int addr,int size, int mask) = 0; + virtual void dma_wait(int mask) = 0; + + virtual void mail_write(unsigned int data) = 0; + virtual unsigned int mail_read(void) = 0; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/FifoDmaManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/FifoDmaManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,28 @@ +#ifndef INCLUDED_FIFO_DMA_MANAGER +#define INCLUDED_FIFO_DMA_MANAGER + +#ifndef INCLUDED_DMA_MANAGER +# include "DmaManager.h" +#endif + +#ifndef INCLUDED_MAIL_MANAGER +# include "MailManager.h" +#endif + +class FifoDmaManager : public DmaManager { +public: + /* variables */ + MailManager *mailManager; + MailQueuePtr mail_recvQueue; + MailQueuePtr mail_sendQueue; + + /* functions */ + void dma_load(void *buf, unsigned int addr, int size, int mask); + void dma_store(void *buf, unsigned int addr, int size, int mask); + void dma_wait(int mask) ; + + void mail_write(unsigned int data); + unsigned int mail_read(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/FifoTaskInfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/FifoTaskInfo.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,20 @@ +#ifndef INCLUDED_FIFO_TASK_INFO +#define INCLUDED_FIFO_TASK_INFO + +#ifndef INCLUDED_TASK_INFO +# include "TaskInfo.h" +#endif + +class FifoTaskInfo : public TaskInfo { +public: + /* function */ + void init(void); + int extend_pool_taskList(int num); + TaskListPtr get_available_taskList(void); + void clear_taskList(void); + + /* variables */ + TaskListPtr machineTaskList; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/FifoTaskManagerImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/FifoTaskManagerImpl.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,32 @@ +#ifndef INCLUDED_FIFO_TASK_MANAGER_IMPL +#define INCLUDED_FIFO_TASK_MANAGER_IMPL + +#ifndef INCLUDED_FIFO_TASK_INFO +# include "FifoTaskInfo.h" +#endif + +#ifndef INCLUDED_TASK_MANAGER_IMPL +# include "TaskManagerImpl.h" +#endif + +#ifndef INCLUDED_MAIL_MANAGER +# include "MailManager.h" +#endif + +class FifoTaskManagerImpl : public TaskManagerImpl { +public: + /* functions */ + void init(void); + void run(void); + + TaskListPtr set_task(void); + +private: + /* variables */ + MailManager *mailManager; + + /* functions */ + MailQueuePtr mail_check(MailQueuePtr mail_list); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/MailManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/MailManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,26 @@ +#ifndef INCLUDED_MAIL_MANAGER +#define INCLUDED_MAIL_MANAGER + +typedef struct mail_queue { + unsigned int data; + struct mail_queue *next; +} MailQueue, *MailQueuePtr; + +class MailManager { +public: + /* functions */ + int init_pool_mailQueue(int num); + int extend_pool_mailQueue(int num); + MailQueuePtr create_mail(unsigned int data); + MailQueuePtr get_free_mailQueue(unsigned int data); + void free_mailQueue(MailQueuePtr q); + +private: + /* variables */ + MailQueuePtr mailQueuePool; + MailQueuePtr freeMailQueue; +}; + +extern MailQueuePtr append_mailQueue(MailQueuePtr list, MailQueuePtr q); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeExit.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeExit.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,19 @@ +#ifndef INCLUDED_SPE_EXIT +#define INCLUDED_SPE_EXIT + +#ifndef INCLUDED_SPEMANAGER +# include "SpeManager.h" +#endif + +class SpeExit : public SpeTaskBase { +public: + /* constructor */ + SpeExit(void) {} + + /* variables */ + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeMail.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeMail.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,29 @@ +#ifndef INCLUDED_SPE_MAIL +#define INCLUDED_SPE_MAIL + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeMail : public SpeTaskBase{ +public: + /* constructor */ + SpeMail(DmaManager *); + + /* variables */ + unsigned int params_addr; + DmaManager* connector; + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + /* override functions */ + void read(void); // overwride + +#ifdef DEBUG + void exec(void); + void write(void); +#endif +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,63 @@ +#ifndef INCLUDED_SPE_MANAGER +#define INCLUDED_SPE_MANAGER + +#ifndef INCLUDED_TASK +# include "task.h" +#endif + +#ifndef INCLUDED_DMA_MANAGER +# include "DmaManager.h" +#endif + +class SpeTaskBase; +class SpeManager; + +class SpeTaskBase { +public: + /* constructor */ + SpeTaskBase(void) {} + virtual ~SpeTaskBase(void) {} + + /* variables */ + + // noaction in default + virtual void load(void) {} + virtual void read(void) {} + virtual void exec(void) {} + virtual void write(void) {} + + /* functions */ + virtual SpeTaskBase* next(SpeManager *, SpeTaskBase *) = 0; +}; + + +class SpeManager { +public: + SpeManager(void); + + /* variables */ + int listBufFlg; + int readBufFlg; + int writeBufFlg; + TaskListPtr listBuf[2]; + void *readBuf[2]; + void *writeBuf[2]; + + DmaManager* connector; + + SpeTaskBase* task1; + SpeTaskBase* task2; + SpeTaskBase* task3; + + /* functions */ + void init(void); + void set_connect(DmaManager*); + void run(void); + void finish(void); + + TaskListPtr get_curListBuf(void); + void* get_curReadBuf(void); + void* get_curWriteBuf(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeNop.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeNop.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,22 @@ +#ifndef INCLUDED_SPE_NOP +#define INCLUDED_SPE_NOP + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeNop : public SpeTaskBase { +public: + /* constructor */ + SpeNop(void); + + /* variables */ + + /* functions */ + void read(void); + void exec(void); + void write(void); + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeNop2Ready.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeNop2Ready.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,27 @@ +#ifndef INCLUDED_SPE_NOP2READY +#define INCLUDED_SPE_NOP2READY + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +#ifndef INCLUDED_SPE_NOP +# include "SpeNop.h" +#endif + +class SpeNop2Ready : public SpeNop { +public: + /* constructor */ + SpeNop2Ready(DmaManager*); + + /* variables */ + DmaManager* connector; + + /* functions */ + void read(void); + void exec(void); + void write(void); + SpeTaskBase* next(SpeManager *, SpeTaskBase *); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeTask.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeTask.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,37 @@ +#ifndef INCLUDED_SPE_TASK +#define INCLUDED_SPE_TASK + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeTask : public SpeTaskBase { +public: + /* constructor */ + SpeTask(TaskListPtr, void*, void*, DmaManager*); + + /* variables */ + TaskListPtr list; + TaskPtr task; + void *readbuf; + void *writebuf; + + DmaManager* connector; + + // work area + // global variable 用とか + // 次の task に引き渡したり + // size : デフォルトで 4k + // ppuから教えてもらう? task に入れる + void (*func)(void *wbuf, void *rbuf); + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + // override + void read(void); + void exec(void); + void write(void); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/SpeTaskList.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeTaskList.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,34 @@ +#ifndef INCLUDED_SPE_TASKLIST +#define INCLUDED_SPE_TASKLIST + +#ifndef INCLUDED_SPE_MANAGER +# include "SpeManager.h" +#endif + +class SpeTaskList : public SpeTaskBase { +public: + /* constructor */ + SpeTaskList(unsigned int addr, TaskListPtr list, DmaManager* c); + + /* variables */ + unsigned int params_addr; + TaskListPtr list; + DmaManager* connector; + + /* functions */ + SpeTaskBase* next(SpeManager *, SpeTaskBase *); + + /* override functions */ + void read(void); + void exec(void); + +#ifdef DEBUG + void write(void); +#endif + +}; + +//extern void get_task_list(); +//extern void print_task_list(); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/Sum.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/Sum.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,12 @@ +#ifndef INCLUDED_TASK_MANAGER +# include "TaskManager.h" +#endif + +class Sum { +public: + void init(void); + void run(void); + +private: + TaskManager *manager; +}; diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/TaskInfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/TaskInfo.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,64 @@ +#ifndef INCLUDED_TASK_INFO +#define INCLUDED_TASK_INFO + +#ifndef INCLUDED_TASK +# include "task.h" +#endif + +class TaskInfo { +public: + /* constructor */ + TaskInfo(int num = 1); + virtual ~TaskInfo(void) {} + + /* variables */ + TaskListPtr taskListPool; + TaskListPtr freeTaskList; + + TaskQueuePtr taskQueuePool; + TaskQueuePtr freeTaskQueue; + TaskQueuePtr waitTaskQueue; + TaskQueuePtr activeTaskQueue; + + /* function */ + virtual void init(void) = 0; + + // task list + int init_pool_taskList(int num); + virtual int extend_pool_taskList(int num) = 0; + virtual TaskListPtr get_available_taskList(void) = 0; + TaskListPtr get_free_taskList(void); + + // task queue + int init_pool_taskQueue(int num); + TaskQueuePtr get_free_taskQueue(HTaskPtr); + int extend_pool_taskQueue(int num); + + // task + int init_pool_task(int num); + HTaskPtr get_free_task(int cmd, int size, + unsigned long long in_addr, + unsigned long long out_addr); + + virtual void clear_taskList(void) = 0; + + void append_activeTask(HTaskPtr); + void append_waitTask(HTaskPtr); + + void free_taskList(TaskListPtr q); + void free_taskQueue(TaskQueuePtr q); + void free_task(HTaskPtr q); + + void check_task_finish(HTaskPtr task); + void notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list); + TaskQueuePtr remove_taskQueue(TaskQueuePtr list, TaskQueuePtr task); + TaskQueuePtr remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task); + +private: + int machineNum; +}; + +extern TaskQueuePtr append_taskQueue(TaskQueuePtr, TaskQueuePtr); +extern TaskListPtr append_taskList(TaskListPtr list, TaskListPtr q); + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/TaskManager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/TaskManager.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,28 @@ +#ifndef INCLUDED_TASK_MANAGER +#define INCLUDED_TASK_MANAGER + +#ifndef INCLUDED_TASK_MANAGER_IMPL +# include "TaskManagerImpl.h" +#endif + +class TaskManager { +public: + /* constructor */ + TaskManager(int num = 1); // The number of threads + + /* variables */ + TaskManagerImpl *m_impl; + + /* functions */ + void init(void); + HTaskPtr create_task(int cmd, int siz, unsigned long long in_addr, + unsigned long long out_addr, void (*func)(void)); + void set_task_depend(HTaskPtr master, HTaskPtr slave); + void run_task(HTaskPtr); + void run(void); + +private: + int machineNum; +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/TaskManagerImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/TaskManagerImpl.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,29 @@ +#ifndef INCLUDED_TASK_MANAGER_IMPL +#define INCLUDED_TASK_MANAGER_IMPL + +#ifndef INCLUDED_TASK_INFO +# include "TaskInfo.h" +#endif + +class TaskManagerImpl { +public: + /* constructor */ + TaskManagerImpl(int num = 1); + virtual ~TaskManagerImpl(void) {} + + /* variables */ + int machineNum; + TaskInfo* taskInfo; + + /* functions */ + virtual void init(void) = 0; + virtual void run(void) = 0; + + HTaskPtr create_task(int cmd, int siz, + unsigned long long in_addr, + unsigned long long out_addr, + void (*func)(void)); + void set_task_depend(HTaskPtr master, HTaskPtr slave); + void run_task(HTaskPtr); +}; +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/dma_spe.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/dma_spe.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,12 @@ +#include +#include "dma.h" + +class SpeDmaManager : public DmaManager { +public: + void dma_load(void *buf, unsigned int addr, int size, int mask); + void dma_store(void *buf, unsigned int addr, int size, int mask); + void dma_wait(int mask) ; + + void mail_write(unsigned int data); + unsigned int mail_read(void); +}; diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/error.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/error.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,1 @@ +extern void __debug(char *str); diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/memorypool.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/memorypool.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,86 @@ +#ifndef MEMORY_POOL_H_ +#define MEMORY_POOL_H_ + +#include +#include + +const int DEFAULT_EXPAND_SIZE = 32; + +template +class MemoryPool { +public: + typedef MemoryPool self_type; + + MemoryPool(void) { + next_ = NULL; + expandTheFreeList(size_); + } + + ~MemoryPool(void) { + MemoryPool * nextPtr = next_; + + while (nextPtr == 0) { + next_ = next_->next_; + delete [] nextPtr; + nextPtr = next_; + } + } + + void* alloc(size_t) { + if (!next_) expandTheFreeList(size_); + + self_type* head = next_; + next_ = head->next_; + + return head; + } + + void free(void* doomed) { + self_type* head = static_cast(doomed); + head->next_ = next_; + next_ = head; + } + +private: + void expandTheFreeList(int howMany); + +private: + self_type* next_; +}; + +template +void MemoryPool::expandTheFreeList(int howMany) +{ + size_t size = (sizeof(T_) > sizeof(self_type*)) + ? sizeof(T_) : sizeof(self_type*); + + self_type* runner = (self_type*)malloc(size); + + next_ = runner; + for (int i = 0; i < howMany; i++) { + runner->next_ = (self_type*)malloc(size); + runner = runner->next_; + } + runner->next_ = 0; +} + +template +class UseMemoryPool { +public: + void* operator new(size_t size) { return pool_->alloc(size); } + void operator delete(void* doomed, size_t) { pool_->free(doomed); } + +public: + static void initMemPool() { + pool_.reset(new MemoryPool); + } + +private: + static std::auto_ptr > pool_; + +}; + +template +std::auto_ptr > UseMemoryPool::pool_; + +#endif // ! MEMORY_POOL_H_ diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/ppe_spe.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/ppe_spe.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,18 @@ +/** + * Alignment value and macro for DMA transfer in SPE + */ +#define SPE_ALIGNMENT 16 +#define SPE_ALIGNMENT_FULL 128 +#define SPE_ALIGN __attribute__((aligned(SPE_ALIGNMENT))) +#define SPE_ALIGN_FULL __attribute__((aligned(SPE_ALIGNMENT_FULL)) +#define ROUND_UP_ALIGN(value, alignment) \ + (((value) + ((alignment) - 1))&(~((alignment)-1))) +#define DEFAULT_ALIGNMENT SPE_ALIGNMENT + +enum { + MY_SPE_COMMAND_EXIT, + MY_SPE_COMMAND_GO, + + MY_SPE_STATUS_BUSY, + MY_SPE_STATUS_READY +}; diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/spe_taskinfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/spe_taskinfo.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,15 @@ +#ifndef INCLUDED_SPETASKINFO +#define INCLUDED_SPETASKINFO + +#ifndef INCLUDED_TASKINFO +# include "../taskinfo.h" +#endif + +class SpeTaskInfo : public TaskInfo { +public: + SpeTaskInfo(int num); + + int extend_pool_taskList(int num); +}; + +#endif diff -r 70e9baa00f51 -r 2356238ebea7 include/TaskManager/task.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/task.h Tue Feb 05 20:22:50 2008 +0900 @@ -0,0 +1,42 @@ +#ifndef INCLUDED_TASK +#define INCLUDED_TASK + +#include "memorypool.h" + +#define TASK_MAX_SIZE 100 + +typedef struct task_queue TaskQueue, *TaskQueuePtr; +typedef struct htask HTask, *HTaskPtr; + +typedef struct task { + int command; + int in_size; // DMA_GET size + unsigned int in_addr; // DMA_GET address + unsigned int out_addr; // DMA_PUT address + HTaskPtr self; +} Task, *TaskPtr; + +struct htask : public UseMemoryPool { + int command; + int in_size; + unsigned int in_addr; + unsigned int out_addr; + TaskQueuePtr wait_me; // List of task waiting for me + TaskQueuePtr wait_i; // List of task for which I am waiting + void (*post_func)(void); +}; + +struct task_queue { + HTaskPtr task; + TaskQueuePtr next; +}; + +typedef struct task_list { + int length; + struct task_list *next; + //unsigned int next; + Task tasks[TASK_MAX_SIZE]; +} TaskList, *TaskListPtr; + + +#endif