Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/Task.h @ 699:8ece2ac85149 draft
....
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 13 Dec 2009 22:46:15 +0900 |
parents | 72b2da99e875 |
children | ef08dd70eafb |
line wrap: on
line source
#ifndef INCLUDED_TASK #define INCLUDED_TASK #include "base.h" #include "types.h" #include "ListData.h" #include "SimpleTask.h" #define MAX_PARAMS 8 #ifndef SIMPLE_TASK class Task : public SimpleTask { public: // variables BASE_NEW_DELETE(Task); int param_count; // 4 byte memaddr param[MAX_PARAMS]; // 4*MAX_PARAMS byte ListData inData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); ListData outData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); public: // functions int add_inData_t(memaddr addr, int size); // unsigned int ではなく 64bit int add_outData_t(memaddr addr, int size); // unsigned int ではなく 64bit int add_data(ListData &list, memaddr addr, int size); int add_param_t(memaddr param); // obsolete. do not use. int set_param_t(int index, memaddr param); #define add_param(param) add_param_t((memaddr)(param)) #define set_param(index,param) set_param_t(index, (memaddr) (param)) #define add_inData(addr, size) \ add_inData_t((memaddr)(addr), (size)); #define add_outData(addr, size) \ add_outData_t((memaddr)(addr), (size)); }; #else class SchedTask; class Task { public: // variables int task_size; int command; int param_count; int inData_count; int outData_count; int inData_offset; int outData_offset; void *data[] __attribute__ ((aligned (DEFAULT_ALIGNMENT))); // memaddr param[param_count]; // ListEelemnt inData[inData_count]; // ListElement outData[outData_count]; public: // functions // int add_inData_t(memaddr addr, int size); // int add_outData_t(memaddr addr, int size); void print(); int const offset() { return (memaddr)data-(memaddr)&task_size; } // on host memaddr param(int index) { return (memaddr)data + sizeof(memaddr)*index; } // on host memaddr inData(int index) { memaddr p = (memaddr)data + inData_offset; return p + sizeof(ListElement)*index; } // on host memaddr outData(int index) { memaddr p = (memaddr)data + outData_offset; return p + sizeof(ListElement)* index; } // on client memaddr get_param(int index) { memaddr data = (memaddr)this + offset(); return (memaddr)data + sizeof(memaddr)*index; } // on client ListElement *inListData() { memaddr data = (memaddr)this + offset(); ListElement *list = (ListElement *)(data+inData_offset); return list; } // on client ListElement *outListData() { memaddr data = (memaddr)this + offset(); ListElement *list = (ListElement *)(data+outData_offset); return list; } void set_param_length(int i) { param_count = i; inData_offset = round_up16(sizeof(Task))+param_count*sizeof(memaddr); } void set_inData_length(int length) { inData_count = length; if (inData_offset==0) { printf("call set_param_length before\n"); } outData_offset = round_up16(inData_offset+inData_count*sizeof(ListElement)); } void set_outData_length(int length) { outData_count = length; if (outData_offset==0) { printf("call set_outData_length before\n"); } task_size = round_up16(outData_offset+outData_count*sizeof(ListElement)); } int size() { if (task_size==0) { printf("call set_outData_length before\n"); } return task_size; } int inData_total_size() { int size = 0; ListElement *inData = inListData(); for(int i=0; i< inData_count; i++) { size += inData[i].size; } return size; } int outData_total_size() { int size = 0; ListElement *outData = inListData(); for(int i=0; i< outData_count; i++) { size += outData[i].size; } return size; } void set_inData_t( int index, memaddr addr, int size); void set_outData_t(int index, memaddr addr, int size); void set_task_id(int id) { command = id; } void set_param_t(int index, memaddr param) { memaddr *p = (memaddr*)this->param(index); *p = param; } static int calc_size(int params, int ins, int outs) { int size = round_up16(sizeof(Task)) + round_up16(sizeof(memaddr)*params) + round_up16(sizeof(ListElement)*ins) + round_up16(sizeof(ListElement)*outs); return size; } Task * next() { char *p = (char*)this; p += size(); return (Task*)p; } // #define add_param(param) add_param_t((memaddr)(param)) #define set_param(index,param) set_param_t(index, (memaddr) (param)) // #define add_inData(addr, size) // add_inData_t((memaddr)(addr), (size)); // #define add_outData(addr, size) // add_outData_t((memaddr)(addr), (size)); #define set_inData(index, addr, size) \ set_inData_t(index, (memaddr)(addr), (size)); #define set_outData(index, addr, size) \ set_outData_t(index, (memaddr)(addr), (size)); }; #endif typedef Task* TaskPtr; #endif