view TaskManager/Fifo/FifoDmaManager.cc @ 1312:d0c14093e019 draft

commented out
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Thu, 15 Dec 2011 17:00:07 +0900
parents 6941385ba022
children f53e986715fa
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "FifoDmaManager.h"
#include "Scheduler.h"
#include "TaskManagerImpl.h"
#include "rdtsc.h"

void *
FifoDmaManager::dma_load(Scheduler *s, void *buf, memaddr addr, uint32 size, uint32 mask)
{
    if (size == 0) return buf;

	//unsigned long long wait = 0;
	//(this->*start_dmawait_profile)();

    if (s) buf = s->manager->allocate(size);
    memcpy(buf, (void*)addr, size);

	//(this->*end_dmawait_profile)(&wait);
	//global_load_time += wait;
	//dma_load_time += wait;

    return buf;
}

void *
FifoDmaManager::get_writebuf(Scheduler *s,memaddr addr, uint32 size) 
{
    void *b = s->manager->allocate(size);
    return b;
}

void *
FifoDmaManager::dma_store(void *buf, memaddr addr, uint32 size, uint32 mask)
{
    if (size == 0) return buf;

	//unsigned long long wait = 0;
	//(this->*start_dmawait_profile)();

    memcpy((void*)addr, buf, size);

	//(this->*end_dmawait_profile)(&wait);
	//global_store_time += wait;
	//dma_store_time += wait;

    return buf;
}

/**
 * mask で設定した DMA 転送の完了を待つ
 */
void
FifoDmaManager::dma_wait(uint32 mask)
{
}


void *
FifoDmaManager::dma_loadList(Scheduler *s, ListDataPtr list, void *buff, uint32 mask)
{
	//unsigned long long wait = 0;
	//(this->*start_dmawait_profile)();

    int list_size = list->length;
    long bound;

    buff = s->manager->allocate(list->size);
    bound = (long)(buff);

    for (int i = 0; i < list_size; i++) {
	ListElementPtr elm = &list->element[i];
	memcpy((void*)bound, (void*)elm->addr, elm->size);
	bound += elm->size;
    }

	//(this->*end_dmawait_profile)(&wait);
	//global_load_time += wait;
	//dma_loadList_time += wait;

    return buff;
}


void *
FifoDmaManager::get_writebuf(Scheduler *s,ListDataPtr addr, uint32 size) 
{
    void *b = s->manager->allocate(addr->size);
    return b;
}

void
FifoDmaManager::dma_storeList(ListDataPtr list, void *buff, uint32 mask)
{
	//unsigned long long wait = 0;
	//(this->*start_dmawait_profile)();

    int list_size = list->length;
    memaddr bound;

    bound = (memaddr)(buff);

    for (int i = 0; i < list_size; i++) {
	ListElementPtr elm = &list->element[i];
	memcpy((void*)elm->addr, (void*)bound, elm->size);
	bound += elm->size;
    }

	//(this->*end_dmawait_profile)(&wait);
	//global_store_time += wait;
	//dma_storeList_time += wait;
}

void
FifoDmaManager::start_profile()
{
	global_busy_time = 0;
	global_load_time = 0;
	global_store_time = 0;
	dma_load_time = 0;
	dma_store_time = 0;
	dma_loadList_time = 0;
	dma_storeList_time = 0;

	start_dmawait_profile = &FifoDmaManager::do_start_dmawait_profile;
	end_dmawait_profile = &FifoDmaManager::do_end_dmawait_profile;

	stop_time = rdtsc();
}

void
FifoDmaManager::stop_profile()
{
	start_time = rdtsc();
	global_busy_time = stop_time - start_time;

	start_dmawait_profile = &FifoDmaManager::null_start_dmawait_profile;
	end_dmawait_profile = &FifoDmaManager::null_end_dmawait_profile;
}

void
FifoDmaManager::do_start_dmawait_profile()
{
	start_time = rdtsc();
	global_busy_time += stop_time - start_time;
}

void
FifoDmaManager::do_end_dmawait_profile(unsigned long long *counter)
{
	stop_time = rdtsc();
	*counter += stop_time - start_time;
}

void FifoDmaManager::null_start_dmawait_profile() {}
void FifoDmaManager::null_end_dmawait_profile(unsigned long long *counter) {}

void
FifoDmaManager::show_dma_wait(Scheduler *s, int cpu)
{
	unsigned long long all_time = global_busy_time + global_load_time + global_store_time;

	double busy = ((double)global_busy_time)/((double)all_time)*100.0;
	double load = ((double)global_load_time)/((double)all_time)*100.0;
	double store = ((double)global_store_time)/((double)all_time)*100.0;


	s->printf("cpu%d:\n busy_time = %.3g%%"
			" load_time = %.3g%%, "
			" store_time = %.3g%% "
			,cpu, busy, load, store);

	global_busy_time = 0;
	global_load_time = 0;
	global_store_time = 0;
	dma_load_time = 0;
	dma_store_time = 0;
	dma_loadList_time = 0;
	dma_storeList_time = 0;
}

uint32
FifoDmaManager::get_tag()
{
    static int tag = 16;
    tag ++;
    tag &= 0x0f;
    return tag+16;
}

/**
 *  DMA buffer offset in rbuf
 */
void
FifoDmaManager::bound(ListData *list)
{
    ListElement *elm = list->element;
    int *bound = list->bound;
    int offset=0;
    for(int i=0;i<list->length;i++) {
        bound[i] = offset;
        offset += elm[i].size;
    }
}

/* end */