view TaskManager/Gpu/GpuTaskManagerImpl.cc @ 1445:ef6933a92fff draft

debug GpuTaskManagerImpl
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Mon, 23 Apr 2012 22:01:08 +0900
parents db8a954fcfb3
children bde20cca45ae
line wrap: on
line source

#include "GpuTaskManagerImpl.h"
#include "MainScheduler.h"
#include "SchedTask.h"


GpuTaskManagerImpl::~GpuTaskManagerImpl() {

}

void GpuTaskManagerImpl::init(int spuIdle,int useRefDma) {

    gpuTaskList = new QueueInfo<TaskList>;
    taskListInfo = new QueueInfo<TaskList>;

    ppeManager = new FifoTaskManagerImpl(machineNum);
    MainScheduler *mscheduler = new MainScheduler;
    set_scheduler(mscheduler);
    ppeManager->init(mscheduler, this, useRefDma);

    htaskImpl = activeTaskQueue;
    mscheduler->set_manager(this);

    gpuThreads->init();

    schedTaskManager = new SchedTask();
    schedTaskManager->init(0, 0, 0, ppeManager->get_scheduler(), 0);
    ppeManager->schedTaskManager = schedTaskManager;
}

void GpuTaskManagerImpl::run() {
    do {
        ppeManager->poll();
        do {
            poll();
        } while (ppeManager->activeTaskQueue->empty());
        // ちゃんと最後のタスクまで実行される?
    } while (!ppeManager->activeTaskQueue->empty() || !activeTaskQueue->empty());
}

void GpuTaskManagerImpl::poll() {
    set_runTaskList();
    sendTaskList();
}

void GpuTaskManagerImpl::set_runTaskList() {
    HTaskPtr htask = activeTaskQueue->getFirst();
    while (htask != NULL) {
        if (htask->cpu_type == CPU_PPE) {
            htask = activeTaskQueue->getNext(htask);
        } else {
            set_taskList(htask, taskListInfo);

            HTaskPtr next = activeTaskQueue->getNext(htask);
            activeTaskQueue->remove(htask);
            htask = next;
        }
    }
}

void GpuTaskManagerImpl::sendTaskList() {
    mail_check();
    if (!gpuTaskList->empty()) {
    }
    if (!taskListInfo->empty()) {
        send_taskList();
    }
}

void GpuTaskManagerImpl::send_taskList() {
    // swap gpuTaskList for taskListInfo
    QueueInfo<TaskList> *tmp = taskListInfo;
    taskListInfo = gpuTaskList;
    gpuTaskList = tmp;

    gpuTaskList->getLast()->next = 0;
    TaskListPtr p = gpuTaskList->getFirst();

    // send taskList
    gpuThreads->send_mail(0, 0, (memaddr *) &p);
}

void GpuTaskManagerImpl::mail_check() {
    memaddr data;
    while (gpuThreads->has_mail(0, 0, &data)) {
        //どのメールが必要かよく考える

        //check_task_finish
    }
}

#ifdef __CERIUM_GPU__
TaskManagerImpl*
create_impl(int num, int useRefDma)
{
    GpuThreads *gpus = GpuThreads::getInstance();
    return new GpuTaskManagerImpl(num, gpus);
}
#endif