Mercurial > hg > Members > kono > Cerium
changeset 498:cb5ecfc5aaa3
double linked HTaskInfo/HTask
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 11 Oct 2009 11:46:41 +0900 |
parents | 9d225ba0c34f |
children | eacbcdb23986 |
files | TaskManager/Fifo/FifoTaskManagerImpl.cc TaskManager/Fifo/FifoTaskManagerImpl.h TaskManager/kernel/ppe/HTask.h TaskManager/kernel/ppe/HTaskInfo.cc TaskManager/kernel/ppe/HTaskInfo.h TaskManager/kernel/ppe/Task.cc TaskManager/kernel/ppe/Task.h TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskManagerImpl.h TaskManager/kernel/ppe/TaskQueueInfo.cc TaskManager/kernel/schedule/SchedTask.cc |
diffstat | 11 files changed, 248 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Sun Oct 11 11:46:41 2009 +0900 @@ -35,9 +35,7 @@ taskListImpl = new TaskListInfo; taskQueueImpl = new TaskQueueInfo; - htaskImpl = new HTaskInfo; - - htaskImpl->init(TASK_MAX_SIZE*2); + htaskImpl = new HTaskInfo(); mainTaskList = taskListImpl->create(); @@ -87,7 +85,6 @@ FifoTaskManagerImpl::get_runTaskList() { TaskListPtr list, list_top; - HTaskPtr htask; // HTask (PPE にある) TaskPtr task; // Task (SPE に送る Task) if (activeTaskQueue->empty()) { @@ -101,9 +98,7 @@ list_top = taskListImpl->clear_taskList(list_top); list = list_top; - while (TaskQueuePtr queue = activeTaskQueue->poll()) { - htask = (HTaskPtr)queue->task; - + while (HTaskPtr htask = activeTaskQueue->poll()) { task = &list->tasks[list->length++]; #if 0 task->command = htask->command; @@ -122,7 +117,7 @@ list = newList; } - activeTaskQueue->free_(queue); + activeTaskQueue->free_(htask); } mainTaskList = list_top; @@ -193,7 +188,7 @@ * NULL なら全てのタスクが実行終了したということ */ void -FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueueInfo *waitQueue) +FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, HTaskInfo *waitQueue) { waitTaskQueue = waitQueue; mail_check(mail_list);
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Sun Oct 11 11:46:41 2009 +0900 @@ -24,7 +24,7 @@ void init(MainScheduler*, TaskManagerImpl*); void run(void); void mail_check(MailQueuePtr mail_list); - void mail_check(MailQueuePtr mail_list, TaskQueueInfo *waitQueue); + void mail_check(MailQueuePtr mail_list, HTaskInfo *waitQueue); TaskListPtr get_runTaskList(void); MailQueuePtr schedule(TaskListPtr);
--- a/TaskManager/kernel/ppe/HTask.h Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/HTask.h Sun Oct 11 11:46:41 2009 +0900 @@ -6,7 +6,6 @@ #include "Task.h" #include "TaskQueueInfo.h" -class TaskQueueInfo; class TaskManagerImpl; /*! @@ -29,9 +28,13 @@ void (*post_func)(void *arg); void *post_arg; CPU_TYPE cpu_type; - HTask *next; // free list 用 TaskManagerImpl *mimpl; + Task *task; + HTask *waiter; + HTask *next; + HTask *prev; + void spawn(void); void wait_for(HTask *); void set_cpu(CPU_TYPE type);
--- a/TaskManager/kernel/ppe/HTaskInfo.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/HTaskInfo.cc Sun Oct 11 11:46:41 2009 +0900 @@ -2,53 +2,47 @@ #include <stdlib.h> #include "TaskManagerImpl.h" #include "HTaskInfo.h" +#include "TaskQueueInfo.h" -HTaskInfo::HTaskInfo(void) - :htaskPool(NULL), freeHTask(NULL) {} - -HTaskInfo::~HTaskInfo(void) { destroy(); } +// Singleton HTask Pool +HTaskInfo HTaskInfo::taskQueuePool; -int -HTaskInfo::init(int num) -{ - if (htaskPool == NULL) { - return extend_pool(num); - } - return 0; +HTaskInfo::HTaskInfo() { + // 最初の一つは自分 + first = last = this; + next = prev = this; + waiter = NULL; } -/** - * Fix me - * extend できる限界を設定するべき? - */ +void +HTaskInfo::freePool() { + for(HTaskPtr p = taskQueuePool.waiter; p; ) { + HTaskPtr next = p->waiter; + p->waiter = NULL; + delete p->wait_me; + delete p->wait_i; + free(p); + p = next; + } +} + int HTaskInfo::extend_pool(int num) { - HTaskPtr q = NULL; - - q = (HTaskPtr)malloc(sizeof(HTask)*(num+1)); + HTaskPtr q = (HTaskPtr)malloc(sizeof(HTask)*(num+1)); - if (q == NULL) { - return -1; - } - q->next = htaskPool; - htaskPool = q; + // First Queue is previous pool + q->waiter = waiter; waiter = q; + q++; /* Connect all free queue in the pool */ - for (q = htaskPool + 1; --num > 0; q++) { - q->next = q + 1; - q->wait_me = new TaskQueueInfo(); - q->wait_i = new TaskQueueInfo(); - q->inData = (ListDataPtr)malloc(sizeof(ListData)); - q->outData = (ListDataPtr)malloc(sizeof(ListData)); + HTaskPtr p = q; + for (; --num > 0; p++) { + p->waiter = NULL; + p->wait_me = new TaskQueueInfo(); + p->wait_i = new TaskQueueInfo(); + addLast(p); } - q->next = freeHTask; - q->inData = (ListDataPtr)malloc(sizeof(ListData)); - q->outData = (ListDataPtr)malloc(sizeof(ListData)); - q->wait_me = new TaskQueueInfo(); - q->wait_i = new TaskQueueInfo(); - - freeHTask = htaskPool + 1; return 0; } @@ -61,52 +55,162 @@ HTaskPtr HTaskInfo::create(int cmd) { - HTaskPtr q; - - if (freeHTask == NULL) { - extend_pool(100); + HTaskPtr q = taskQueuePool.poll(); + if (! q) { + taskQueuePool.extend_pool(64); + q = taskQueuePool.poll(); } - - q = freeHTask; - freeHTask = freeHTask->next; + q->next = q->prev = NULL; + q->waiter = NULL; q->command = cmd; - q->inData->clear(); - q->outData->clear(); - q->self = (TaskQueuePtr) q; + q->inData.clear(); + q->outData.clear(); + q->self = (int) q; q->param_size = 0; q->post_func = NULL; q->mimpl = NULL; q->cpu_type = CPU_PPE; + // q->wait_me.clear(); + // q->wait_i.clear(); + return q; } void -HTaskInfo::free(HTaskPtr q) +HTaskInfo::free_(HTaskPtr q) { - q->next = freeHTask; - freeHTask = q; + q->waiter = NULL; + taskQueuePool.addLast(q); +} + + +/*! + HTaskInfo は空にならない。最低1個は要素が入っていて + 1個目は特別扱いする。getFirst すると first->next を返す + */ + +/*! + 最初の1個は特別扱いなので、それの後に追加していく + */ +void +HTaskInfo::addFirst(HTask* e) +{ + e->prev = first; + e->next = first->next; + first->next->prev = e; + first->next = e; } void -HTaskInfo::destroy(void) +HTaskInfo::addLast(HTask* e) +{ + e->next = first; + e->prev = last; + last->next = e; + last = e; +} + +HTask* +HTaskInfo::getFirst() +{ + if (empty()) return NULL; + return first->next; +} + +HTask* +HTaskInfo::getLast() { - HTaskPtr q, tmp; + if (empty()) return NULL; + return last; +} + +int +HTaskInfo::remove(HTask* e) +{ + e->prev->next = e->next; + e->next->prev = e->prev; + + if (first->next == e) { + first->next = e->next; + } + if (last == e) { + last = e->prev; + } + + e->prev = NULL; + e->next = NULL; + + return 1; +} + +/*! + リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 + */ -#if 1 - q = htaskPool; - while (q) { - tmp = q->next; - free(q); - q = tmp; +HTask* +HTaskInfo::poll() +{ + HTask* e = first->next; + if (e == this) { + return NULL; + } + remove(e); + return e; +} + +void +HTaskInfo::moveToFirst(HTask* e) +{ + remove(e); + addFirst(e); +} + +/*! + リスト内の指定された位置にある要素を返す。 + 要素数を超えた位置を指定した場合 NULL を返す。 + */ + +HTask* +HTaskInfo::get(int index) +{ + HTask* e = first->next; + for (int i = 0; i < index; i++) { + if (e == this) return NULL; + e = e->next; } -#else - for (q = htaskPool; q; q = q->next) { - free(q); + return e; +} + +HTask* +HTaskInfo::find(Task* task) +{ + HTask* e = first->next; + for(;;) { + if (e == this) return NULL; + if (e->task == task) return e; + e = e->next; } -#endif + return e; +} + +int +HTaskInfo::empty() +{ + return next == this; +} - freeHTask = htaskPool = NULL; +HTask* +HTaskInfo::getNext(HTask* q) +{ + if (q->next==this) return NULL; + return q->next; } + + + +/* end */ + +
--- a/TaskManager/kernel/ppe/HTaskInfo.h Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/HTaskInfo.h Sun Oct 11 11:46:41 2009 +0900 @@ -1,29 +1,48 @@ #ifndef INCLUDED_HTASK_INFO #define INCLUDED_HTASK_INFO +#include "Task.h" #include "HTask.h" -class HTaskInfo { +class HTaskInfo : public HTask { + public: /* constructor */ - HTaskInfo(void); - virtual ~HTaskInfo(void); + HTaskInfo(); + + BASE_NEW_DELETE(HTaskInfo); /* functions */ - int init(int num); - HTaskPtr create(int cmd); - void free(HTaskPtr q); - virtual int extend_pool(int num); + HTaskPtr HTaskInfo::create(int cmd); + + void free_(HTaskPtr queue); -protected: + void addFirst(HTask* e); + void addLast(HTask* e); + HTask* getFirst(); + HTask* getLast(); + int remove(HTask* e); + HTask* poll(); + void moveToFirst(HTask* e); // or use(); + HTask* get(int index); + HTask* find(Task *task); + int empty(); + void freePool() ; + + // Iterator + HTask* getNext(HTask* q) ; + int hasNext(HTask* q); + +private: /* variables */ - HTaskPtr htaskPool; - HTaskPtr freeHTask; + + static HTaskInfo taskQueuePool; + HTask* first; + HTask* last; /* functions */ - void destroy(void); - -private: + int extend_pool(int num); + void destroy(); }; #endif
--- a/TaskManager/kernel/ppe/Task.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/Task.cc Sun Oct 11 11:46:41 2009 +0900 @@ -11,7 +11,7 @@ int Task::add_inData_t(unsigned int addr, int size) { - return add_data(this->inData, addr, size); + return add_data(inData, addr, size); } /** @@ -25,7 +25,7 @@ int Task::add_outData_t(unsigned int addr, int size) { - return add_data(this->outData, addr, size); + return add_data(outData, addr, size); } /** @@ -50,16 +50,16 @@ * perror みたいにしたほうがわかりやすいかな。 */ int -Task::add_data(ListDataPtr list, uint32 addr, int size) +Task::add_data(ListData& list, uint32 addr, int size) { - if (list->length >= MAX_LIST_DMA_SIZE) return -1; + if (list.length >= MAX_LIST_DMA_SIZE) return -1; - list->bound[list->length] = list->size; + list.bound[list.length] = list.size; // size でも制限かけるべき? - list->size += size; + list.size += size; - ListElementPtr elm = &list->element[list->length++]; + ListElementPtr elm = &list.element[list.length++]; elm->addr = addr; elm->size = size;
--- a/TaskManager/kernel/ppe/Task.h Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/Task.h Sun Oct 11 11:46:41 2009 +0900 @@ -15,9 +15,9 @@ BASE_NEW_DELETE(Task); int command; // 4 byte - ListDataPtr inData; // 4 byte 64bit であるべき - ListDataPtr outData; // 4 byte 64bit であるべき - TaskQueue *self; // 4 byte + ListData inData; // 4 byte 64bit であるべき + ListData outData; // 4 byte 64bit であるべき + int self; // 4 byte int param_size; // 4 byte int param[MAX_PARAMS]; // 4*MAX_PARAMS byte @@ -25,7 +25,7 @@ public: // functions int add_inData_t(unsigned int addr, int size); // unsigned int ではなく 64bit int add_outData_t(unsigned int addr, int size); // unsigned int ではなく 64bit - int add_data(ListDataPtr list, unsigned int addr, int size); + int add_data(ListData &list, unsigned int addr, int size); int add_param(int param); #define add_inData(addr, size) \
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Oct 11 11:46:41 2009 +0900 @@ -14,9 +14,10 @@ TaskManagerImpl::TaskManagerImpl(int num) : machineNum(num) { - activeTaskQueue = new TaskQueueInfo(); - waitTaskQueue = new TaskQueueInfo(); - taskQueueImpl = new TaskQueueInfo(); + activeTaskQueue = new HTaskInfo(); + waitTaskQueue = new HTaskInfo(); + htaskImpl = waitTaskQueue ; // any HTaskInfo + taskQueueImpl = new TaskQueueInfo(); } /** @@ -38,8 +39,7 @@ // systask_finish->wait_for(systask_finish); // とかなって無限ループになるので、 // これだけは明示的に append_waitTask() で - TaskQueuePtr q = taskQueueImpl->create(systask_finish); - append_waitTask(q); + append_waitTask(systask_start); } HTaskPtr @@ -82,11 +82,10 @@ { // waiter // master // waitee // slave - TaskQueuePtr q = taskQueueImpl->create(task); if (task->wait_i->empty()) { - append_activeTask(q); + append_activeTask(task); } else { - append_waitTask(q); + append_waitTask(task); } systask_finish->wait_for(task); @@ -96,7 +95,7 @@ * Task を実行可能キューに追加する */ void -TaskManagerImpl::append_activeTask(TaskQueuePtr q) +TaskManagerImpl::append_activeTask(HTaskPtr q) { activeTaskQueue->addLast(q); } @@ -131,20 +130,20 @@ wait_i->free_(p->waiter); if (wait_i->empty()) { - waitTaskQueue->remove(you->self); - append_activeTask(you->self); + waitTaskQueue->remove((HTaskPtr)you->task); + append_activeTask((HTaskPtr)you->task); } wait_i->free_(p); } me->post_func(me->post_arg); - htaskImpl->free(me); + htaskImpl->free_(me); } void -TaskManagerImpl::append_waitTask(TaskQueuePtr q) +TaskManagerImpl::append_waitTask(HTaskPtr q) { waitTaskQueue ->addLast(q); }
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Sun Oct 11 11:46:41 2009 +0900 @@ -14,10 +14,9 @@ /* variables */ int machineNum; - TaskQueueInfo *activeTaskQueue; - TaskQueueInfo *waitTaskQueue; + HTaskInfo *activeTaskQueue; + HTaskInfo *waitTaskQueue; - /* variables */ TaskListInfo *taskListImpl; TaskQueueInfo *taskQueueImpl; HTaskInfo *htaskImpl; @@ -31,8 +30,8 @@ // system virtual void init() = 0; virtual void run() = 0; - virtual void append_activeTask(TaskQueuePtr); - virtual void append_waitTask(TaskQueuePtr); + virtual void append_activeTask(HTaskPtr); + virtual void append_waitTask(HTaskPtr); void check_task_finish(HTaskPtr task); void wakeup_waitTask();
--- a/TaskManager/kernel/ppe/TaskQueueInfo.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskQueueInfo.cc Sun Oct 11 11:46:41 2009 +0900 @@ -53,7 +53,7 @@ q->next = q->prev = NULL; q->waiter = NULL; q->task = task; - task->self = q; + task->self = (int)q; return q; }
--- a/TaskManager/kernel/schedule/SchedTask.cc Sat Oct 10 21:05:55 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Sun Oct 11 11:46:41 2009 +0900 @@ -126,9 +126,9 @@ void SchedTask::ex_init_normal() { - scheduler->dma_load(inListData, (uint32)task->inData, + scheduler->dma_load(inListData, (uint32)&task->inData, sizeof(ListData), DMA_READ_IN_LIST); - scheduler->dma_load(outListData, (uint32)task->outData, + scheduler->dma_load(outListData, (uint32)&task->outData, sizeof(ListData), DMA_READ_OUT_LIST); #if defined(NO_PIPELINE) scheduler->dma_wait(DMA_READ_IN_LIST); @@ -147,8 +147,8 @@ void SchedTask::ex_init_renew() { - inListData = task->inData; - outListData = task->outData; + inListData = &task->inData; + outListData = &task->outData; taskGroup = (TaskGroupPtr)task->self; } @@ -202,7 +202,7 @@ free(readbuf); if (taskGroup->status() != 0) { - task->self = (TaskQueuePtr)taskGroup->command; + task->self = (int)taskGroup->command; delete taskGroup; taskGroup = NULL; } @@ -508,13 +508,14 @@ TaskPtr p = &taskList->tasks[taskList->length++]; p->command = cmd; - p->inData = (ListData*)scheduler->allocate(sizeof(ListData)); - p->outData = (ListData*)scheduler->allocate(sizeof(ListData)); + // already allocated + // p->inData = (ListData*)scheduler->allocate(sizeof(ListData)); + // p->outData = (ListData*)scheduler->allocate(sizeof(ListData)); - p->inData->clear(); - p->outData->clear(); + p->inData.clear(); + p->outData.clear(); - p->self = (TaskQueuePtr)MY_SPE_NOP; + p->self = (int)MY_SPE_NOP; p->param_size = 0; return p; @@ -527,7 +528,7 @@ void SchedTask::wait_task(TaskPtr waitTask) { - waitTask->self = (TaskQueuePtr)taskGroup; + waitTask->self = (int)taskGroup; scheduler->add_groupTask(taskGroup, waitTask);