# HG changeset patch # User hiroki@localhost.localdomain # Date 1260954266 -32400 # Node ID 974672c4ea2a77515b057a97a760eab3a9db13ee # Parent 0d8d2b7a343834394945badcb780bf4c8a9a7a4e# Parent c42cab5ad4c3add7412e02e7085996bbc304a3c6 merge diff -r 0d8d2b7a3438 -r 974672c4ea2a .hgtags --- a/.hgtags Wed Dec 16 16:29:31 2009 +0900 +++ b/.hgtags Wed Dec 16 18:04:26 2009 +0900 @@ -3,3 +3,6 @@ 30568cef3899caea3db0fb9e28b0e6f889c60679 double-linked-task-list 8fca17aa57dfe07aeff46a3ae1707c795c762d72 examples 9df0112f7ccfe03caffb06e64160ae2a6f3a22dd before_simple_task +a06eef665c455b4da8dbe05595a5628aedd3eb3a before-task-array +226d95fa26917a3242f7700916c3c9823bd2d33d TaskArray +e4d2b823903cc85f54fc47a685e955df8fa866f4 simple-task-regression diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Engine/Makefile.def --- a/Renderer/Engine/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/Renderer/Engine/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -6,7 +6,7 @@ ABI = -m$(ABIBIT) CC = g++ OPT = -g -CFLAGS = -g -Wall $(ABI) $(OPT) # -O9 -DDEBUG +CFLAGS = -g -Wall $(ABI) $(OPT) # -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. # LIBS = -L$(CERIUM)/TaskManager -m$(ABIBIT) diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Engine/task/CreateSpan.cc --- a/Renderer/Engine/task/CreateSpan.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/Renderer/Engine/task/CreateSpan.cc Wed Dec 16 18:04:26 2009 +0900 @@ -421,7 +421,7 @@ static int run(SchedTask *smanager, void *rbuf, void *wbuf) { - PolygonPack *pp = (PolygonPack*)smanager->get_input(0); + PolygonPack *pp = (PolygonPack*)smanager->get_input(rbuf, 0); PolygonPack *next_pp = (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); PolygonPack *free_pp = next_pp; @@ -432,8 +432,8 @@ VertexPackPtr vMid10 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); NormalPackPtr normal1,normal2, normal3; - SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); - spack = (SpanPackPtr)smanager->get_input(2); + SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(rbuf, 1); + spack = (SpanPackPtr)smanager->get_input(rbuf, 2); send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); prev_index = (long)smanager->get_param(0); diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Test/Makefile.cell --- a/Renderer/Test/Makefile.cell Wed Dec 16 16:29:31 2009 +0900 +++ b/Renderer/Test/Makefile.cell Wed Dec 16 18:04:26 2009 +0900 @@ -11,7 +11,7 @@ .cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -ALL = ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange +ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange all: $(ALL) speobject: diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Test/Makefile.def --- a/Renderer/Test/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/Renderer/Test/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -4,7 +4,7 @@ ABIBIT = 32 ABI = -m$(ABIBIT) CC = g++ -CFLAGS = -g -Wall $(ABI) # -O -DDEBUG +CFLAGS = -g -Wall $(ABI) # -O -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I$(CERIUM)/Renderer/Engine -I. -I$(CERIUM)/include/Cerium LIBS = -L$(CERIUM)/TaskManager -L$(CERIUM)/Renderer/Engine $(ABI) diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Test/property_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Test/property_test.cc Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,247 @@ +#include +#include +#include "SceneGraphRoot.h" +#include "SceneGraph.h" +#include "TaskManager.h" +#include "property_test.h" +#include "Func.h" + +ChainPropertyPtr properties[2]; +ChainProperty cv[CHAIN_LEN]; + + +void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv); + +void +init_chainold_vars(ChainPropertyPtr cv) { + cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; + cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; + cv->can_move = TRUE; +} + +void +set_old_vector(ChainPropertyPtr cv, SceneGraphPtr sg) { + sg->xyz[0] = (float)cv->next_x; + sg->xyz[1] = (float)cv->next_y; + sg->xyz[2] = 0.0f; +} + + +static void +chain_old_move_ope(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->cross.isHold()) { + cv[CHAIN_LEN-1].can_move = FALSE; + if (pad->left.isHold()) { + cv[CHAIN_LEN-1].x += -5.0; + } else if (pad->right.isHold()) { + cv[CHAIN_LEN-1].x += 5.0; + } + + if (pad->up.isHold()) { + cv[CHAIN_LEN-1].y += -5.0; + } else if (pad->down.isHold()) { + cv[CHAIN_LEN-1].y += 5.0; + } + } else { + cv[CHAIN_LEN-1].can_move = TRUE; + } +} +void +chain_old_move(ChainProperty cv, int w, int h) +{ +} +void +chain_old_move(SceneGraphPtr sg, int w, int h) +{ + int id = sg->id; + if(id == 0) { + for(int cnt = 0; cnt < 600; cnt++) { + for(int i = 0; i < CHAIN_LEN; i++) { + if(cv[i].can_move) { + double dx = cv[i-1].x - cv[i].x; + double dy = cv[i-1].y - cv[i].y; + double l = sqrt(dx * dx + dy * dy); + double a = k * (l - chain_width) / m; + double ax = a * dx / l; + double ay = a * dy / l; + if(i < CHAIN_LEN - 1) { + dx = cv[i+1].x - cv[i].x; + dy = cv[i+1].y - cv[i].y; + l = sqrt(dx * dx + dy * dy); + a = k * (l - chain_width) / m; + ax += a * dx / l; + ay += a * dy / l; + } + ay += g; + cv[i].vx *= safe; + cv[i].vy *= safe; + cv[i].next_vx = cv[i].vx + ax * dt; + cv[i].next_vy = cv[i].vy + ay * dt; + cv[i].next_x = cv[i].x + cv[i].vx * dt; + cv[i].next_y = cv[i].y + cv[i].vy * dt; + } else { + cv[i].next_x = cv[i].x; + cv[i].next_y = cv[i].y; + } + } + for(int i = 0; i < CHAIN_LEN; i++) { + cv[i].vx = cv[i].next_vx; + cv[i].vy = cv[i].next_vy; + cv[i].x = cv[i].next_x; + cv[i].y = cv[i].next_y; + } + } + // cout << id << ", " << sg->xyz[1] << endl; + } + set_old_vector(&cv[id], sg); + int p, n; + p = n = id; + if(p != 0) { + p--; + } + if(n != CHAIN_LEN - 1) { + n++; + } + sg->angle[2-(id%2)*2] + = 90 + atan((cv[p].next_y - cv[n].next_y) / (cv[p].next_x - cv[n].next_x)) * 180 / M_PI; +} + +/* +void +chain_old_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) +{ + +} +*/ + +void +spe_move_collision(ChainProperty cv, spe_move_func new_move, spe_move_func new_collision) +{ + + cv.move = new_move; + cv.collision = new_collision; + +} + + +void +chain_old_collision(void *cv, int w, int h, ChainPropertyPtr ocv) +{ + //createSceneGraphFromProperty(cv, cv); +} + + +void +property_swich() +{ + +} + + +void +createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv) +{ + SceneGraphPtr node; + + for(int i = 0; i < CHAIN_LEN; i++) { + node = sgroot->createSceneGraph(cv[i].objname); + /** + * move, collision は spe で実行される, task taskID を持たせればよい + * property が 対応する taskID を持つので set_move_collision() は不要 + * set_task_propety(move_taskID, collision_taskID) のようなものを作る + */ + node->set_move_collision(chain_old_move, chain_old_collision); + //spe_move_collision(cv[i], chain_old_move, chain_old_collision); + node->id = cv[i].id; + node->angle[1] = cv[i].angle[1]; + set_old_vector(&cv[i], node); + cv[i].parent->addChild(node); + } + sgroot->setSceneData(root); +} + + +void +set_properties(ChainPropertyPtr cv) +{ + properties[0] = cv; + properties[1] = cv; +} + +MainLoopPtr +Chain::init(Viewer *sgroot, int w, int h) +{ + SceneGraphPtr root, chain; + sgroot->createFromXMLfile("xml_file/chain.xml"); + + ChainProperty rcv; + init_chainold_vars(&rcv); + rcv.next_x = w / 2; + rcv.next_y = 0.0; + rcv.id = CHAIN_LEN; + + root = sgroot->createSceneGraph("CHAIN"); + root->set_move_collision(chain_old_move_ope, chain_old_collision); + set_old_vector(&rcv, root); + + chain = sgroot->createSceneGraph("CHAIN"); + chain->set_move_collision(chain_old_move, chain_old_collision); + + set_properties(cv); + + for(int i = 0; i < CHAIN_LEN; i++) { + init_chainold_vars(&cv[i]); + cv[i].x = 0; + cv[i].y = chain_width * i; + cv[i].angle[1] = -90 * (i % 2); + + chain->id = cv[i].id; + chain->angle[1] = cv[i].angle[1]; + set_old_vector(&cv[i], chain); + + cv[i].root = root; + cv[i].objname = "CHAIN"; + cv[i].id = i; + + cv[i].parent = root; + + } + + createSceneGraphFromProperty(root, cv); + cv[0].can_move = FALSE; + //sgroot->setSceneData(root); + + return sgroot; +} + +extern Application * +application() { + return new Chain(); +} + +const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; + +extern int init(TaskManager *manager, int argc, char *argv[]); +extern void task_initialize(); +static void TMend(TaskManager *manager); + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + task_initialize(); + manager->set_TMend(TMend); + return init(manager, argc, argv); + +} + +void +TMend(TaskManager *manager) +{ + printf("test_nogl end\n"); +} + +/* end */ + diff -r 0d8d2b7a3438 -r 974672c4ea2a Renderer/Test/property_test.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Test/property_test.h Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,47 @@ +#include "Application.h" + +typedef void (*spe_move_func)(void *cv, int screen_w, int screen_h); +typedef void (*spe_collision_func)(void *cv, int screen_w, int screen_h); + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + double angle[3]; + int can_move; + int id; + char *objname; + spe_move_func move; + spe_collision_func collision; + SceneGraphPtr parent; + SceneGraphPtr root; +} *ChainPropertyPtr, ChainProperty; + +#define FALSE 0 +#define TRUE !FALSE +#define CHAIN_LEN 50 + +static const double m = 100.0; +static const double k = 7000.0; +static const double g = 9.8; +static const double dt = 0.003; +static const double chain_width = 10; +static const double safe = 0.995; + +class Chain : public Application { +public: + Chain(){} + + SceneGraphPtr scenegraph_factory(void *p, int size); + SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list); + void init(TaskManager *manager, int w, int h); + void init_chain_vars(ChainPropertyPtr cv); + void chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h); + //void chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg); + void chain_collision(ChainPropertyPtr cv, int w, int h); + void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv); + //void property_swich(); + //void set_properties(ChainPropertyPtr cv); + MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h); + + +}; diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Cell/CellTaskManagerImpl.cc --- a/TaskManager/Cell/CellTaskManagerImpl.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.cc Wed Dec 16 18:04:26 2009 +0900 @@ -90,10 +90,8 @@ void CellTaskManagerImpl::set_runTaskList() { - // ここ...直すかな TaskListPtr list; - - TaskPtr task; + SimpleTaskPtr task; int speid; while (HTaskPtr htask = activeTaskQueue->poll()) { @@ -128,8 +126,29 @@ } task = &list->tasks[list->length++]; - TaskPtr stask = (TaskPtr) task; - *stask = *(TaskPtr) htask; + + if (htask->command==TaskArray1) { + // compatibility + // Task with ListData is stored in the ListData + int next = (htask->r_size+sizeof(SimpleTask))/sizeof(SimpleTask); + if (list->length+next>=TASK_MAX_SIZE) { + list->length--; + TaskListPtr newList = taskListImpl->create(); + newList = TaskListInfo::append(newList, speTaskList_bg[speid]); + speTaskList_bg[speid] = newList; + list = newList; + task = &list->tasks[list->length++]; + } + Task *array = (Task*)&list->tasks[list->length]; + list->length += next; + memcpy(array, htask->rbuf, htask->r_size); + free(htask->rbuf); + htask->rbuf = 0; htask->r_size = 0; + *task = *(SimpleTask*)htask; + } else { + *task = *(SimpleTask*)htask; + } + } } diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Cell/spe/TaskArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Cell/spe/TaskArray.cc Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,29 @@ +#include "Finish.h" +#include "SysFunc.h" +#include "Scheduler.h" +#include "Task.h" + + +SchedDefineTask(TaskArray); + +static Task * +next(Task *t) +{ + char *p = (char*)t; + p += t->size(); + return (Task*)p; +} + +static int +run(SchedTask *s,void *rbuf, void *wbuf) +{ + Task *task = (Task *)rbuf; + Task *last = ((char*)rbuf)+ s->read_size(); + + while( task < last) { + task->print(s); + task = next(task); + } + + return 0; +} diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Cell/spe/main.cc --- a/TaskManager/Cell/spe/main.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/Cell/spe/main.cc Wed Dec 16 18:04:26 2009 +0900 @@ -4,6 +4,8 @@ #include "spu_mfcio.h" #include "error.h" #include "SysFunc.h" +#include "SchedNop.h" + extern unsigned char _end[]; @@ -36,7 +38,7 @@ tm->set_scheduler(manager); - manager->run(); + manager->run(new SchedNop()); manager->finish(); diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/ChangeLog --- a/TaskManager/ChangeLog Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/ChangeLog Wed Dec 16 18:04:26 2009 +0900 @@ -1,3 +1,101 @@ +2009-12-15 Shinji KONO + + SimpleTask の実装が出来たので、TaskArray からは、 + PPU側に詳細な情報を返せる。と言うことは、SPU側から + PPU Task を投入出来る。実装すればだけど。 + + Task 側から書き出し情報を設定するAPIが必要。 + マニュアルも書くか。 + + Down cast をすべてなくしたい。Sched*.cc からは取れました。 + + まだ、いらないものが結構あるらしい... + +2009-12-14 Shinji KONO + + ようやっと動きました。SIMPLE_TASK でないのとの互換性 + を維持するべきか? 頑張れば出来ると思うけど... + + 方法は二つ。TaskList に無理矢理 Task を詰め込むか、 + 今までのHTaskを、TaskArray に読み変えるか。前者は変更が + 多い。後者は、wait_for が微妙。 + + 前者で実装しました。そのうち落すかも。エラーチェックと、 + エラー処理関数が必要。コメントを書かないと。 + +2009-12-12 Shinji KONO + + SchedTask::next で、TaskArray を認識して、そこで、 + SchedTaskArrayLoad を作る。次のSchedTask を用意して、 + SchedTaskArrayLoad にsavedSchedTaskとして引き渡す。 + + SchedTaskArrayLoad::read は、TaskArray をload する。 + SchedTaskArrayLoad::next は、SchedTaskArray を返す。 + この時に、saveedSchedTask を引き継ぐ。 + write/exec は何もしない。(これで、pipe line を空ける) + + SchedTaskArray::read は、List DMA をload する。 + SchedTaskArrayLoad::next は、TaskArray 上のTaskを返す。 + exec/write は、List DMA 対応で動作する。 + もうない場合には、SchedTaskArrayLoad から伝えられた + saveされた SchedTask を返す。mail も送る。 + +2009-12-7 Shinji KONO + + pipeline stageは、loop local だから、instance 変数である必 + 要はない。途中で中断することはない。これを一時変数にして、 + 再帰的にpipeline stage を呼び出せば良いらしい。 + + pipeline stage のtask1に引数で new SchedTaskList を渡すと、 + run()でtask1 = new SchedNop() するよりループ二回ぐらい高速 + になるらしい。が、おそらく、ほとんど影響はない。 + + pipelineで既に走っている次のTaskのreadを停める必要があるら + しい。前もってNopを入れて置く方法もあるが、TaskListの境界が + 問題になる。停めないとパイプラインバッファを新たに取る必要 + があり連鎖的にはまる。 + + writeしている奴もいるしな。スケジューラは一段しかネストしな + いから新しくバッファ取るか? いや、やっぱり許されないか。い + や、取るか。うーん、悩ましい。どうせ、Task list は確保しな + いとだめだから… 再帰しないで、もとのスケジューラで動かした + い + + そのためには、既に Pipeline に入っているTaskが邪魔か。2つTask + を投入して、間に TaskList read が入ってもなんとかなるように + 工夫するのが良いっぽい + + なんか、Renew Task の道を歩んでいる気もするが... + +2009-12-6 Shinji KONO + + やっぱり、Graphical なprofileが欲しいかな。どのDMA/Taskに時間がかかっている + かが見えるようなものが。profile で、メインメモリにlogを書き出すようなもの + が必要。deubg 用のデータ書き出しツールがいるな。 + + log header + command(16) cpu-id(16) event(32) time(64) + struct debug_log { + uint16 command; + uint16 cpu-id; + uint32 event; + uint32 time; + } + ぐらい? get_segment 使うべきか。連続領域に使える get_segement があると + 良いわけね。write とも言うが。 + + sort で、memcpy しているのは変。read/write buffer をflipしてやると + 良い。両方とも握っているんだから問題ない。ただし、read/write buffer + の大きさは等しい必要がある。SchedTask->flip_read_write_buffer(); か? + sort ちゃんとは動いているんだよ。 + + word_count_test の稼働率が10%なのはひどい。word_count の方だと偏りが + あって、一部が50%になるが10%ぐらい。DMA待ちではなくて、メール待ちに + なっている。PPUネックになっているっぽい。 + + TaskArray は、SchedTask を拡張して処理する。next で、次のTaskを + 用意する感じか。inData/outData の処理も。 + 2009-12-5 Shinji KONO なんかなぁ。一つの機能を付け加えようとすると、 @@ -34,7 +132,7 @@ なっているらしい。 実際、mail_sendQueue は、free list に置き換わってしまう。 - これまで、これがおかしならなかった理由は不明。 + これまで、これがおかしくならなかった理由は不明。 connector に外から手を入れないで、ちゃんとfunction callするべし。 @@ -95,6 +193,7 @@ 2009-11-14 Shinji KONO Scheduler / TaskManger / TaskManagerImpl の区別が不明 + HTask は、TaskManagerImpl を持ってる。 Scheduler は SchedTask から直接見えないはずだが、SchedTask は、 Scheduler は知っているが、TaskManager は知らない。これがかなりの diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Fifo/FifoTaskManagerImpl.cc --- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Wed Dec 16 18:04:26 2009 +0900 @@ -6,6 +6,8 @@ #include "SchedTask.h" #include "types.h" #include "error.h" +#include "SchedNop.h" +#include "SysFunc.h" FifoTaskManagerImpl::~FifoTaskManagerImpl() { @@ -84,11 +86,7 @@ FifoTaskManagerImpl::get_runTaskList() { TaskListPtr list, list_top; -#ifdef SIMPLE_TASK SimpleTaskPtr task; // Task (SPE に送る Task) -#else - TaskPtr task; // Task (SPE に送る Task) -#endif if (activeTaskQueue->empty()) { return NULL; @@ -104,11 +102,26 @@ // printf("active task queue length = %d\n",activeTaskQueue->length()); while (HTaskPtr htask = activeTaskQueue->poll()) { task = &list->tasks[list->length++]; -#ifdef SIMPLE_TASK - *task = *(SimpleTask*)htask; -#else - memcpy(task, (Task*)htask, sizeof(Task)); -#endif + + if (htask->command==TaskArray1) { + // compatibility + int next = (htask->r_size+sizeof(SimpleTask))/sizeof(SimpleTask); + if (list->length+next>=TASK_MAX_SIZE) { + list->length--; + TaskListPtr newList = taskListImpl->create(); + list_top = TaskListInfo::append(list_top, newList); + list = newList; + task = &list->tasks[list->length++]; + } + Task *array = (Task*)&list->tasks[list->length]; + list->length += next; + memcpy(array, htask->rbuf, htask->r_size); + free(htask->rbuf); + htask->rbuf = 0; htask->r_size = 0; + *task = *(SimpleTask*)htask; + } else { + *task = *(SimpleTask*)htask; + } if (list->length >= TASK_MAX_SIZE) { TaskListPtr newList = taskListImpl->create(); list_top = TaskListInfo::append(list_top, newList); @@ -162,7 +175,8 @@ mainScheduler->mail_write_from_host((memaddr)MY_SPE_COMMAND_EXIT); // scheduler は受け取ったメールを元に実行する - mainScheduler->run(); + // new SchedTaskList(list, mainScheduler) の方が良さそうだけど... + mainScheduler->run(new SchedNop()); } } diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Makefile.cell --- a/TaskManager/Makefile.cell Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/Makefile.cell Wed Dec 16 18:04:26 2009 +0900 @@ -11,6 +11,8 @@ $(CELL_SPE_DIR)/SchedTaskList.cc \ $(CELL_SPE_DIR)/SchedMail.cc \ $(CELL_SPE_DIR)/SchedTask.cc \ + $(CELL_SPE_DIR)/SchedTaskArray.cc \ + $(CELL_SPE_DIR)/SchedTaskArrayLoad.cc \ $(CELL_SPE_DIR)/Scheduler.cc\ $(CELL_SPE_DIR)/SchedNop.cc \ $(CELL_SPE_DIR)/MemList.cc \ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/Makefile.def --- a/TaskManager/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -29,14 +29,12 @@ ABIBIT = 32 -# SIMPLE_TASK=-DSIMPLE_TASK -SIMPLE_TASK= -#OPT = -O9 +# OPT = -O9 OPT = -g CC = g++ -CFLAGS = $(SIMPLE_TASK) -Wall `sdl-config --cflags` -m$(ABIBIT) $(OPT) +CFLAGS = -Wall `sdl-config --cflags` -m$(ABIBIT) $(OPT) LIBS = -m$(ABIBIT) INCLUDE = -I../include/TaskManager diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/HTask.cc --- a/TaskManager/kernel/ppe/HTask.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/HTask.cc Wed Dec 16 18:04:26 2009 +0900 @@ -1,6 +1,7 @@ #include "HTask.h" #include "ListData.h" #include "TaskManagerImpl.h" +#include "strings.h" /*! @@ -49,4 +50,45 @@ this->post_arg2 = arg2; } + +Task * +HTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) +{ + r_size = Task::calc_size(num_param, num_inData, num_outData)*num_task; + rbuf = (memaddr) mimpl->allocate(r_size); + bzero(rbuf,r_size); + Task *task = (Task*)rbuf; + task->init(id, num_param,num_inData,num_outData); +// task->print(); + return task; // first task +} + +Task * +HTask::next_task_array(int id, Task *t) +{ + Task *first = (Task*)rbuf; + if (t==0) { +// first->print(); + return first; + } + + Task *next = t->next(); + next->init(id, first->param_count, first->inData_count, first->outData_count); + if ((memaddr)next - (memaddr)rbuf > r_size) + printf("too many task array used.\n"); + return next; +} + +void +HTask::spawn_task_array(Task * last) +{ + int size = (memaddr)last - rbuf; + if (size!= r_size) { + printf("spawn task array size differ size 0x%x r_size 0x%x\n", + size, r_size); + } +} + + + /* end */ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/HTask.h --- a/TaskManager/kernel/ppe/HTask.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/HTask.h Wed Dec 16 18:04:26 2009 +0900 @@ -21,11 +21,10 @@ 特定の Task を待ち合わせる事が可能。 Task の入出力は dma などで copy される。 */ -#ifdef SIPMLE_TASK + +#include "SimpleTask.h" + class HTask : public SimpleTask { -#else -class HTask : public Task { -#endif public: BASE_NEW_DELETE(HTask); @@ -41,10 +40,71 @@ HTask *next; HTask *prev; - void spawn(void); + void spawn(); void wait_for(HTask *); void set_cpu(CPU_TYPE type); void set_post(PostFunction func, void *read, void *write); + Task *create_task_array(int task_id, int num_task, int num_param, int num_inData, int num_outData); + Task *next_task_array(int task_id, Task *t); + void spawn_task_array(Task *t); + + + private: + + int param_index; + int in_index; + int out_index; + +// compatibility + public: // functions + void add_inData_t(memaddr addr, int size) { + Task *t = (Task*)rbuf; + t->set_inData_t(in_index++, addr,size); + } + void add_outData_t(memaddr addr, int size) { + Task *t = (Task*)rbuf; + t->set_outData_t(out_index++, addr,size); + } + void set_inData_t(int index, memaddr addr, int size) { + Task *t = (Task*)rbuf; + t->set_inData_t(index, addr,size); + } + void set_outData_t(int index, memaddr addr, int size) { + Task *t = (Task*)rbuf; + t->set_inData_t(index, addr,size); + } + void add_param_t(memaddr param) { + Task *t = (Task*)rbuf; + t->set_param_t(param_index++, param); + } + void set_param_t(int index, memaddr param) { + Task *t = (Task*)rbuf; + t->set_param_t(index, param); + } + + void init(int cmd) { + next = prev = NULL; + waiter = NULL; + + command = cmd; + param_index = 0; + in_index = 0; + out_index = 0; + self = (memaddr) this; + + post_func = NULL; + mimpl = NULL; + cpu_type = CPU_PPE; + } +#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)); + + }; typedef HTask* HTaskPtr; diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/HTaskInfo.cc --- a/TaskManager/kernel/ppe/HTaskInfo.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/HTaskInfo.cc Wed Dec 16 18:04:26 2009 +0900 @@ -60,39 +60,17 @@ taskQueuePool.extend_pool(64); q = taskQueuePool.poll(); } - q->next = q->prev = NULL; - q->waiter = NULL; - - q->command = cmd; -#ifndef SIMPLE_TASK - q->inData.clear(); - q->outData.clear(); - q->param_size = 0; -#endif - q->self = (memaddr) q; - - q->post_func = NULL; - q->mimpl = NULL; - q->cpu_type = CPU_PPE; - - // q->wait_me.clear(); - // q->wait_i.clear(); - + q->init(cmd); return q; } HTaskPtr HTaskInfo::create(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws) { -#ifdef SIMPLE_TASK HTaskPtr task = create(cmd); task->set_input(rbuf, rs); task->set_output(wbuf, ws); return task; -#else - fprintf(stderr, "TaskManager is not SIMPLE_TASK mode\n"); - return 0; -#endif } diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/SimpleTask.h --- a/TaskManager/kernel/ppe/SimpleTask.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/SimpleTask.h Wed Dec 16 18:04:26 2009 +0900 @@ -13,18 +13,15 @@ int command; // 4 byte memaddr self; // 4 byte (or 8byte on 64bit mode) -#ifdef SIMPLE_TASK memaddr rbuf; memaddr wbuf; int r_size; int w_size; -#endif public: // functions SimpleTask() {}; -#ifdef SIMPLE_TASK SimpleTask(int r, memaddr read, int w, memaddr write) { r_size = r; rbuf = read; w_size = w; wbuf = write; @@ -32,7 +29,6 @@ void set_input(memaddr i,int size) { r_size = size; rbuf= i; } void set_output(memaddr o,int size) { w_size = size; wbuf= o; } -#endif }; diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/Task.cc --- a/TaskManager/kernel/ppe/Task.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/Task.cc Wed Dec 16 18:04:26 2009 +0900 @@ -1,96 +1,18 @@ #include "Task.h" -/** - * タスクの入力データを追加する - * - * @param [addr] add input data - * @param [size] size of data at [addr] - * - * @return if ([ret] == 0) ? success : failuer; - */ -int -Task::add_inData_t(memaddr addr, int size) +void +Task::print() { -#ifdef SIMPLE_TASK - return 0; -#else - return add_data(inData, addr, size); -#endif -} + printf("task id %d task size = %d param size %d " + "inData size %d " + "outData size %d\n", command, size(), param_count, inData_count, outData_count + ); + for(int i=0; i< param_count && i<5; i++) { + // large param_count shall be a bug + printf("param %d = 0x%ld\n", i, (long)param(i)); + } -/** - * タスクの出力先を追加する - * - * @param[in] addr Address at out data - * @param[in] size Size of data transfer - * - * @return if ([ret] == 0) ? success : failuer; - */ -int -Task::add_outData_t(memaddr addr, int size) -{ -#ifdef SIMPLE_TASK - return 0; -#else - return add_data(outData, addr, size); -#endif } -/** - * エラーの時に -1 を返す、ってことするよりは - * perror みたいにしたほうがわかりやすいかな。 - * - * 現在は MAX_PARAMS 個まで。 - * 本当は、MAX_PARAMS個以上にすると task->param[] には アドレスが入り - * そのアドレスは メインメモリでアロケートされた int の集合。 - */ -// こちらのAPIは、受け側と出力側での対応を良く見れない。廃止の方向。 -int -Task::add_param0(memaddr _param) -{ -#ifndef SIMPLE_TASK - if (param_size >= MAX_PARAMS) return -1; - - this->param[param_size++] = _param; -#endif - return 0; -} - -int -Task::set_param0(int index, memaddr _param) -{ -#ifndef SIMPLE_TASK - if (index >= MAX_PARAMS) return -1; - - this->param[index] = _param; -#endif - return 0; -} - -/* - * エラーの時に -1 を返す、ってことするよりは - * perror みたいにしたほうがわかりやすいかな。 - */ -int -Task::add_data(ListData& list, memaddr addr, int size) -{ -#ifndef SIMPLE_TASK - if (list.length >= MAX_LIST_DMA_SIZE) return -1; - - list.bound[list.length] = list.size; - - // size でも制限かけるべき? - list.size += size; - - ListElementPtr elm = &list.element[list.length++]; -#ifdef __CERIUM_CELL__ - elm->addr = (uint32)(unsigned long)addr; -#else - elm->addr = addr; -#endif - elm->size = size; -#endif - - return 0; -} +/* end */ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/Task.h --- a/TaskManager/kernel/ppe/Task.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/Task.h Wed Dec 16 18:04:26 2009 +0900 @@ -6,33 +6,119 @@ #include "ListData.h" #include "SimpleTask.h" -#define MAX_PARAMS 8 -class Task : public SimpleTask { -public: // variables +class SchedTask; - BASE_NEW_DELETE(Task); -#ifndef SIMPLE_TASK - int param_size; // 4 byte - memaddr param[MAX_PARAMS]; // 4*MAX_PARAMS byte - ListData inData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); - ListData outData __attribute__ ((aligned (DEFAULT_ALIGNMENT))); -#endif +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))); 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_param0(memaddr param); // obsolete. do not use. - int set_param0(int index, memaddr param); + + void print(); + + memaddr *param(int index) { + memaddr p = (memaddr)data + sizeof(memaddr)*index; + return (memaddr *)p; + } + + ListElement *inData(int index) { + memaddr p = (memaddr)data + inData_offset; + p += sizeof(ListElement)*index; + return (ListElement*)p; + } + + ListElement *outData(int index) { + memaddr p = (memaddr)data + outData_offset; + p += sizeof(ListElement)* index; + return (ListElement*)p; + } + + 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; + } + + void init(int task_id, int params, int ins, int outs) { + set_task_id(task_id); + param_count = params; + inData_count = ins; + outData_count = outs; + inData_offset = round_up16(sizeof(memaddr)*params); + outData_offset = round_up16(inData_offset+sizeof(ListElement)*ins); + task_size = round_up16(sizeof(Task)+outData_offset+sizeof(ListElement)*outs); + } + + int size() { + return task_size; + } -#define add_param(param) add_param0((memaddr)(param)) -#define set_param(index,param) set_param0(index, (memaddr) (param)) + int inData_total_size() { + int size = 0; + ListElement *in= inData(0); + for(int i=0; i< inData_count; i++) { + size += in[i].size; + } + return size; + } + int outData_total_size() { + int size = 0; + ListElement *out= outData(0); + for(int i=0; i< outData_count; i++) { + size += out[i].size; + } + return size; + } + + void set_inData_t( int index, memaddr addr, int size) { + ListElement *list = inData(index); +#ifdef __CERIUM_CELL__ + list->addr = (uint32)addr; +#else + list->addr = addr; +#endif + list->size = size; + } -#define add_inData(addr, size) \ - add_inData_t((memaddr)(addr), (size)); -#define add_outData(addr, size) \ - add_outData_t((memaddr)(addr), (size)); + void set_outData_t(int index, memaddr addr, int size) { + ListElement *list = outData(index); +#ifdef __CERIUM_CELL__ + list->addr = (uint32)addr; +#else + list->addr = addr; +#endif + list->size = 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; + } + + Task * next() + { + char *p = (char*)this; + p += size(); + return (Task*)p; + } + + +#define set_param(index,param) set_param_t(index, (memaddr) (param)) + +#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)); }; typedef Task* TaskPtr; diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/TaskList.h --- a/TaskManager/kernel/ppe/TaskList.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskList.h Wed Dec 16 18:04:26 2009 +0900 @@ -5,19 +5,15 @@ #include "Task.h" -#define TASK_MAX_SIZE 16 +#define TASK_MAX_SIZE 32 -class TaskList { // 528byte +class TaskList { // 784 byte public: BASE_NEW_DELETE(TaskList); int length; // 4 byte TaskList *next; // 4 byte -#ifdef SIMPLE_TASK - SimpleTask tasks[TASK_MAX_SIZE]; // 512 -#else - Task tasks[TASK_MAX_SIZE]; // 512 -#endif + SimpleTask tasks[TASK_MAX_SIZE]; // 24*TASK_MAX_SIZE TaskList *output; // 4 byte int a[1]; // padding diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/TaskManager.cc --- a/TaskManager/kernel/ppe/TaskManager.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.cc Wed Dec 16 18:04:26 2009 +0900 @@ -1,5 +1,8 @@ #include "TaskManager.h" #include "Scheduler.h" +#include "HTask.h" +#include "Task.h" +#include "SysFunc.h" TaskManager::TaskManager(int num) : machineNum(num) { @@ -59,6 +62,12 @@ return m_impl->create_task(cmd,r,rs,w,ws); } +HTaskPtr +TaskManager::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { + HTaskPtr ta = create_task(TaskArray,0,0,0,0); + ta->create_task_array(id, num_task, num_param, num_inData, num_outData) ; + return ta; +} /** * TaskManaer 終了時に実行される関数の設定 diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/TaskManager.h --- a/TaskManager/kernel/ppe/TaskManager.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.h Wed Dec 16 18:04:26 2009 +0900 @@ -36,11 +36,12 @@ void init(); void finish(); + HTask *create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData); + + private: int machineNum; }; #endif -//extern TaskManager *manager; - diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/ppe/TaskManagerImpl.cc --- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Wed Dec 16 18:04:26 2009 +0900 @@ -30,13 +30,8 @@ TaskManagerImpl::systask_init() { systask_register(); -#ifdef SIMPLE_TASK systask_start = create_task(StartTask,0,0,0,0); systask_finish = create_task(FinishTask,0,0,0,0); -#else - systask_start = create_task(StartTask); - systask_finish = create_task(FinishTask); -#endif systask_start->spawn(); @@ -64,9 +59,13 @@ { HTaskPtr new_task; - new_task = htaskImpl->create(cmd); + // for compatibility + new_task = htaskImpl->create(TaskArray1); new_task->post_func = noaction; new_task->mimpl = this; + Task *task = new_task->create_task_array(cmd,1,8,8,8); + // rbuf, r_size were set + new_task->command = TaskArray1; return new_task; } diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/ListData.h --- a/TaskManager/kernel/schedule/ListData.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/ListData.h Wed Dec 16 18:04:26 2009 +0900 @@ -27,14 +27,20 @@ int length; // The number of data (4) int size; // Total size of data (4) - int a[2]; // for alignment - int bound[MAX_LIST_DMA_SIZE]; // (4 * MAX_LIST_DMA_SIZE) - ListElement element[MAX_LIST_DMA_SIZE]; // (8 * MAX_LIST_DMA_SIZE) + int *bound; + ListElement *element; void clear(void) { length = 0; size = 0; } + + void print() { + printf("inList length %d size %d\n",length, size); + for(int i=0;i #include #include "SchedTask.h" +#include "SysFunc.h" #include "SchedTaskList.h" +#include "SchedTaskArrayLoad.h" #include "SchedNop2Ready.h" #include "DmaManager.h" #include "error.h" #include "TaskManager.h" #include -extern Scheduler::TaskObject task_list[MAX_TASK_OBJECT]; - -/** - Task Object を作る - */ - - -SchedTask * -createSchedTask(Scheduler *scheduler, TaskPtr task) -{ - return new SchedTask(); -} +#include "SchedTaskArray.h" +#define Task SimpleTask +#define TaskPtr SimpleTaskPtr +extern TaskObject task_list[MAX_TASK_OBJECT]; -/** - code load を始める。既に get_segment hash に入っていれば何もしない。 - 最初の一回は SchedTaskList:: next から呼ばれる。 - この段階では、SchedTask object は、まだ作られてない。 - */ -static void -loadSchedTask(Scheduler *scheduler,TaskPtr task) -{ -// fprintf(stderr,"loadSchedTask %d\n",task->command); - task_list[task->command].load(scheduler,task->command); -} SchedTask::SchedTask() { list = NULL; task = NULL; -#ifndef SIMPLE_TASK - inListData = NULL; - outListData = NULL; -#endif readbuf = NULL; writebuf = NULL; scheduler = NULL; @@ -63,16 +42,10 @@ void -SchedTask::init(TaskListPtr _list, TaskPtr _task, int index, - // ListDataPtr rbuf, ListDataPtr wbuf, - Scheduler* sc) +SchedTask::init(TaskListPtr _list, TaskPtr _task, int index, Scheduler* sc) { list = _list; task = _task; -#ifndef SIMPLE_TASK - inListData = &_task->inData; - outListData = &_task->outData; -#endif scheduler = sc; cur_index = index; @@ -88,27 +61,13 @@ // object creation をSchedTask生成時にやらないので、 // exec の直前のread で十分に間に合う - if (cur_index < list->length) { - // load next task - loadSchedTask(scheduler, &list->tasks[cur_index]); - } -#ifdef SIMPLE_TASK - writebuf = scheduler->allocate(task->w_size); + loadSchedTask(scheduler, task->command); + // 読むデータが一つもなければ無視 if (task->r_size == 0) return; // load Input Data readbuf = scheduler->allocate(task->r_size); scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); -#else - writebuf = scheduler->allocate(outListData->size); - - // 読むデータが一つもなければ無視 - if (inListData->length == 0) return; - - // load Input Data - readbuf = scheduler->allocate(inListData->size); - scheduler->dma_loadList(inListData, readbuf, DMA_READ); -#endif } @@ -119,21 +78,20 @@ { __debug("[SchedTask:%s]\n", __FUNCTION__); + if (task->w_size > 0) { + writebuf = scheduler->allocate(task->w_size); + } scheduler->dma_wait(DMA_READ); task_list[task->command].wait(scheduler,task->command); task_list[task->command].run(this, readbuf, writebuf); free(readbuf); // 書き込む領域がなければ無視 -#ifdef SIMPLE_TASK + if (task->w_size > 0) { + writebuf = scheduler->allocate(task->w_size); scheduler->dma_store(writebuf, task->wbuf,task->w_size, DMA_WRITE); } -#else - if (outListData->length > 0) { - scheduler->dma_storeList(outListData, writebuf, DMA_WRITE); - } -#endif } void @@ -147,7 +105,6 @@ scheduler->mail_write((memaddr)task->self); } - SchedTaskBase* SchedTask::next(Scheduler *scheduler, SchedTaskBase *p) { @@ -157,10 +114,17 @@ // Task List が残っているので、次を準備 TaskPtr nextTask = &list->tasks[cur_index++]; - SchedTaskBase *nextSched = createSchedTask(scheduler, nextTask); - // この up cast は汚い... - ((SchedTask*)nextSched)->init(list, nextTask, cur_index, - scheduler); + SchedTask *nextSched = new SchedTask(); + nextSched->init(list, nextTask, cur_index, scheduler); + + if (nextTask->command==TaskArray1) { + // compatibility + return new SchedTaskArray(scheduler, nextSched); + } + if (nextTask->command==TaskArray) { + // Start Task Array + return new SchedTaskArrayLoad(scheduler, nextSched); + } return nextSched; } else { memaddr nextList = (memaddr)list->next; @@ -169,7 +133,7 @@ return new SchedNop2Ready(scheduler); } else { // 新しいリストに取り掛かる - return createSchedTaskList(nextList, scheduler, 0); + return new SchedTaskList(nextList, scheduler); } } } @@ -181,84 +145,21 @@ return scheduler->id; } -#ifndef SIMPLE_TASK -/** - * task->add_inData で与えられた順番に対応する index (0〜n-1) で、 - * buffer から対応するデータを返す。 - */ -void* -SchedTask::get_input(void *buff, int index) -{ - if (buff != NULL) { - return (void*)((char*)buff + inListData->bound[index]); - } else { - return NULL; - } -} - -/** - * get_input(index) のアドレスを返す - */ -memaddr -SchedTask::get_inputAddr(int index) -{ -#ifdef __CERIUM_CELL__ - return (memaddr)inListData->element[index].addr; -#else - return inListData->element[index].addr; -#endif -} - -/** - * get_input(index) のサイズを返す - */ -int -SchedTask::get_inputSize(int index) -{ - return inListData->element[index].size; +void SchedTask::free_(void *p) { + scheduler->free_(p); } -/** - * write buffer の領域を返す。 - */ -void* -SchedTask::get_output(void *buff, int index) -{ - if (buff != NULL) { - return (void*)((char *)buff + outListData->bound[index]); - } else { - return NULL; - } -} -/** - * get_output(index) のアドレスを返す - */ -memaddr -SchedTask::get_outputAddr(int index) -{ -#ifdef __CERIUM_CELL__ - return (memaddr)outListData->element[index].addr; -#else - return outListData->element[index].addr; -#endif -} +void* SchedTask::get_input(void *buff, int index) { + printf("Cannot use inData in SimpleTask use TaskArray\n"); + return NULL; } +memaddr SchedTask::get_inputAddr(int index) { return 0; } +int SchedTask::get_inputSize(int index) {return 0; } +void* SchedTask::get_output(void *buff, int index) {return 0; } +memaddr SchedTask::get_outputAddr(int index) { return 0; } +int SchedTask::get_outputSize(int index) { return 0; } +memaddr SchedTask::get_param(int index) { return 0; } -/** - * get_output(index) のサイズを返す - */ -int -SchedTask::get_outputSize(int index) -{ - return outListData->element[index].size; -} - -memaddr -SchedTask::get_param(int index) -{ - return task->param[index]; -} -#endif void* SchedTask::global_alloc(int id, int size) { diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTask.h --- a/TaskManager/kernel/schedule/SchedTask.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Wed Dec 16 18:04:26 2009 +0900 @@ -10,10 +10,6 @@ #include "HTask.h" #include "MemList.h" -#ifdef SIMPLE_TASK -#define Task SimpleTask -#define TaskPtr SimpleTaskPtr -#endif class SchedTask : public SchedTaskBase { public: @@ -23,22 +19,13 @@ BASE_NEW_DELETE(SchedTask); -private: + // Task Array しか使わないが、たいした大きさではないのでいいか... + ListData inListData; + ListData outListData; + /* variables */ - // Task を実行するスケジューラ自身 - Scheduler *scheduler; - - // 現在スケジューラが実行している TaskList と、このタスクに対応する Task - TaskListPtr list; - TaskPtr task; - - // read/write 用の ListData - ListDataPtr inListData; - ListDataPtr outListData; -#ifndef SIMPLE_TASK - memaddr *param; -#endif +private: /** * read データ、write 用のバッファ @@ -49,8 +36,6 @@ void *readbuf; void *writebuf; - // Task の、Tasklist での位置。(task = &list[cur_index-1]) - int cur_index; /* functions */ @@ -69,25 +54,22 @@ public: /* functions */ - void init(TaskListPtr _list, TaskPtr _task, int index, - // ListDataPtr rbuf, ListDataPtr wbuf, + void init(TaskListPtr _list, SimpleTaskPtr _task, int index, Scheduler* sc); //--- User API --- -#ifdef SIMPLE_TASK int read_size() { return task->r_size; } int write_size() { return task->w_size; } void set_write_size(int w) { task->w_size = w; } -#else - void* get_input(void *buff, int index); - void* get_output(void *buff, int index); + + virtual void* get_input(void *buff, int index); + virtual void* get_output(void *buff, int index); + virtual memaddr get_param(int index); memaddr get_inputAddr(int index); memaddr get_outputAddr(int index); // 書き出しを追加する API がない... int get_inputSize(int index); int get_outputSize(int index); - memaddr get_param(int index); -#endif int get_cpuid(); @@ -109,9 +91,7 @@ void *allocate(int size); - void free_(void *p) { - scheduler->free_(p); - } + void free_(void *p) ; /* これは禁止するべき */ void dma_load(void *buf, memaddr addr, uint32 size, uint32 mask); @@ -125,7 +105,6 @@ /*! SPU用の get_input, get_output */ -#ifndef SIMPLE_TASK void* get_input(int index) { return get_input(readbuf, index); } @@ -133,7 +112,6 @@ void* get_output(int index) { return get_output(writebuf, index); } -#endif // user HTaskPtr create_task(int cmd); @@ -158,8 +136,7 @@ }; -extern SchedTask* createSchedTask(Scheduler *,TaskPtr); - +extern void loadSchedTask(Scheduler *scheduler,TaskPtr task); #endif diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/schedule/SchedTaskArray.cc Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,243 @@ +#include "SchedTaskArray.h" +#include "Scheduler.h" + + +SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_, Task *curTask_, Task *_array) +{ + savedTask = savedTask_; + atask = curTask_; + array = _array; + scheduler = s; + + inListData.bound = 0; + inListData.size = 0; + inListData.length = 0; + inListData.element = 0; + outListData.bound = 0; + outListData.size = 0; + outListData.length = 0; + outListData.element = 0; +} + +/** + Constructor for old Task with ListData + next TaskList entry contains Task object. + savedTask->rbuf is 0, it has only one Task. + */ + +SchedTaskArray::SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_) +{ + savedTask = savedTask_; + scheduler = s; + + inListData.bound = 0; + inListData.size = 0; + inListData.length = 0; + inListData.element = 0; + outListData.bound = 0; + outListData.size = 0; + outListData.length = 0; + outListData.element = 0; + + atask = (TaskPtr)&savedTask->list->tasks[savedTask->cur_index]; + array = 0; + savedTask->cur_index += (atask->size()+sizeof(SimpleTask))/sizeof(SimpleTask); + +} + +/** + */ +SchedTaskArray::~SchedTaskArray() +{ +} + +/** + * DMA buffer offset in rbuf + */ +static void +bound(ListData *list) +{ + ListElement *elm = list->element; + int *bound = list->bound; + int offset=0; + for(int i=0;ilength;i++) { + bound[i] = offset; + offset += elm[i].size; + } +} + +/** + * Task data / code read + */ +void +SchedTaskArray::read() +{ + + // object creation をSchedTaskArray生成時にやらないので、 + // exec の直前のread で十分に間に合う + loadSchedTask(scheduler, atask->command); + + // 読むデータが一つもなければ無視 + if (atask->inData_count == 0) return; + + inListData.length = atask->inData_count; + inListData.size = atask->inData_total_size(); + inListData.element = atask->inData(0); + inListData.bound = (int*)scheduler->allocate(inListData.length*sizeof(int)); + + // load Input Data + readbuf = scheduler->allocate(inListData.size); + // inListData.print(); + scheduler->dma_loadList(&inListData, readbuf, DMA_READ); + bound(&inListData); + +} + +/** + * Wait read data and execute task + * Start write DMA + */ +void +SchedTaskArray::exec() +{ + + if (atask->outData_count > 0) { + outListData.length = atask->outData_count; + outListData.size = atask->outData_total_size(); + outListData.element = atask->outData(0); + outListData.bound = (int*)scheduler->allocate(outListData.length*sizeof(int)); + bound(&outListData); + + writebuf = scheduler->allocate(outListData.size); + } + + scheduler->dma_wait(DMA_READ); + task_list[atask->command].wait(scheduler,atask->command); + task_list[atask->command].run(this, readbuf, writebuf); + free(readbuf); + // 書き込む領域がなければ無視 + + // User 側で作る方法が必要... + + if (atask->outData_count > 0) { + // outListData.print(); + scheduler->dma_storeList(&outListData, writebuf, DMA_WRITE); + } +} + +/** + * Wait write DMA + * send finish mail + */ +void +SchedTaskArray::write() +{ + + scheduler->dma_wait(DMA_WRITE); + free(writebuf); + free(inListData.bound); + free(outListData.bound); + + // このTaskArrayは終り。終了を知らせる。 + if (!array || atask->next() >= last()) { + SchedTask *s = (SchedTask *)savedTask; + scheduler->mail_write((memaddr)s->task->self); + free(array); + } + +} + +Task *SchedTaskArray::last() +{ + SchedTask *s = (SchedTask *)savedTask; + return (Task*)(((char*)array)+ s->read_size()); +} + +SchedTaskBase* +SchedTaskArray::next(Scheduler *scheduler, SchedTaskBase *p) +{ + + Task *next = atask->next(); + if (next < last()) { + // Task List が残っているので、次を準備 + return new SchedTaskArray(scheduler, savedTask, next, array); + } else { + // このTaskArrayは終り。save していた Task の次を返す。 + // savedTask の read/exec は実行されない (command = TaskArray) + return savedTask->next(scheduler, savedTask); + } +} + + + +/** + * task->add_inData で与えられた順番に対応する index (0〜n-1) で、 + * buffer から対応するデータを返す。 + */ +void* +SchedTaskArray::get_input(void *buff, int index) +{ + return (void*)((char*)readbuf + inListData.bound[index]); +} + +/** + * get_input(index) のアドレスを返す + */ +memaddr +SchedTaskArray::get_inputAddr(int index) +{ +#ifdef __CERIUM_CELL__ + return (memaddr)inListData.element[index].addr; +#else + return inListData.element[index].addr; +#endif +} + +/** + * get_input(index) のサイズを返す + */ +int +SchedTaskArray::get_inputSize(int index) +{ + return inListData.element[index].size; +} + +/** + * write buffer の領域を返す。 + */ +void* +SchedTaskArray::get_output(void *buff, int index) +{ + return (void*)((char *)writebuf + outListData.bound[index]); +} + +/** + * get_output(index) のアドレスを返す + */ +memaddr +SchedTaskArray::get_outputAddr(int index) +{ +#ifdef __CERIUM_CELL__ + return (memaddr)outListData.element[index].addr; +#else + return outListData.element[index].addr; +#endif +} + +/** + * get_output(index) のサイズを返す + */ +int +SchedTaskArray::get_outputSize(int index) +{ + return outListData.element[index].size; +} + +memaddr +SchedTaskArray::get_param(int index) +{ + return *atask->param(index); +} + + +/* end */ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/schedule/SchedTaskArray.h Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,52 @@ +#ifndef INCLUDED_SCHED_TASK_ARRAY +#define INCLUDED_SCHED_TASK_ARRAY + +#include "base.h" +#include "Scheduler.h" +#include "SchedTask.h" + + +class SchedTaskArray : public SchedTask { +public: + BASE_NEW_DELETE(SchedTaskArray); + + /* constructor */ + SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_, Task *task_, Task *array_); + /* constructor for old style task */ + SchedTaskArray(Scheduler *s, SchedTaskBase *savedTask_); + + virtual ~SchedTaskArray(); + + + SchedTaskBase *savedTask; + Task *array; + +private: + /* variables */ + + TaskPtr atask; + void *readbuf; + void *writebuf; + + /* functions */ + Task *last(); + + // override + void read(); + void exec(); + void write(); + SchedTaskBase* next(Scheduler *, SchedTaskBase *); + + void* get_input(void*, int); + memaddr get_inputAddr(int); + int get_inputSize(int); + void* get_output(void*, int); + memaddr get_outputAddr(int); + int get_outputSize(int); + memaddr get_param(int); + +}; + + +#endif + diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskArrayLoad.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/schedule/SchedTaskArrayLoad.cc Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,40 @@ +#include "SchedTaskArrayLoad.h" +#include "SchedTaskArray.h" +#include "Task.h" + + +SchedTaskArrayLoad::SchedTaskArrayLoad(Scheduler *s, SchedTaskBase *savedTask_) +{ + scheduler = s; + savedTask = savedTask_; + task = savedTask->task; +} + +SchedTaskArrayLoad::~SchedTaskArrayLoad() {} + +void +SchedTaskArrayLoad::read() +{ + // if (task->r_size == 0) return; cannot happen... + // load Task Array Data + readbuf = scheduler->allocate(task->r_size); + scheduler->dma_load(readbuf, task->rbuf,task->r_size, DMA_READ); +} + +void +SchedTaskArrayLoad::exec() { + // もっと、はやめに DMA_READ して、最初のcodeをloadするべきか? + scheduler->dma_wait(DMA_READ); +} // to empty the pipeline + +void +SchedTaskArrayLoad::write() {} // to empty the pipeline + +SchedTaskBase* +SchedTaskArrayLoad::next(Scheduler *scheduler, SchedTaskBase *p) +{ + Task *nextTask = (Task *)readbuf; + return new SchedTaskArray(scheduler, savedTask, nextTask, nextTask); +} + +/* end */ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskArrayLoad.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/schedule/SchedTaskArrayLoad.h Wed Dec 16 18:04:26 2009 +0900 @@ -0,0 +1,37 @@ +#ifndef INCLUDED_SCHED_TASK_ARRAY_LOAD +#define INCLUDED_SCHED_TASK_ARRAY_LOAD + +#include "base.h" +#include "Scheduler.h" +#include "SchedTask.h" + +class SchedTaskArrayLoad : public SchedTask { +public: + /* constructor */ + SchedTaskArrayLoad(Scheduler *s, SchedTaskBase *savedTask_); + virtual ~SchedTaskArrayLoad(); + + BASE_NEW_DELETE(SchedTaskArrayLoad); + + SchedTaskBase *savedTask; + +private: + /* variables */ + + void *readbuf; + SimpleTask *task; + + /* functions */ + + // override + void read(); + void exec(); + void write(); + SchedTaskBase* next(Scheduler *, SchedTaskBase *); + + +}; + + +#endif + diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskBase.h --- a/TaskManager/kernel/schedule/SchedTaskBase.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskBase.h Wed Dec 16 18:04:26 2009 +0900 @@ -22,6 +22,20 @@ /* functions */ virtual SchedTaskBase* next(Scheduler *, SchedTaskBase*) {return 0;} + + /* variables */ + + // Task を実行するスケジューラ自身 + Scheduler *scheduler; + + SimpleTaskPtr task; + + // 現在スケジューラが実行している TaskList と、このタスクに対応する Task + TaskListPtr list; + // Task の、Tasklist での位置。(task = &list[cur_index-1]) + int cur_index; + + }; #endif diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskList.cc --- a/TaskManager/kernel/schedule/SchedTaskList.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskList.cc Wed Dec 16 18:04:26 2009 +0900 @@ -2,6 +2,9 @@ #include #include "SchedTaskList.h" #include "SchedTask.h" +#include "SysFunc.h" +#include "SchedTaskArray.h" +#include "SchedTaskArrayLoad.h" #include "SchedNop2Ready.h" #include "DmaManager.h" #include "error.h" @@ -15,18 +18,13 @@ * SPE で生成されている場合、DMA の必要は無い * 0: メインメモリ, 1: SPE */ -SchedTaskList* -createSchedTaskList(memaddr next_list, Scheduler* scheduler, int renew_flag) -{ - SchedTaskList* sched = new SchedTaskList(next_list, scheduler); - return sched; -} SchedTaskList::SchedTaskList(memaddr addr, Scheduler *sched) { params_addr = addr; list = NULL; scheduler = sched; + cur_index = 0; } @@ -36,29 +34,24 @@ { __debug("[SchedTaskList:%s]\n", __FUNCTION__); - list = scheduler->get_curListBuf(); - scheduler->dma_load(list, params_addr, - sizeof(TaskList), DMA_READ_TASKLIST); + list = scheduler->get_curListBuf(); + scheduler->dma_load(list, params_addr, + sizeof(TaskList), DMA_READ_TASKLIST); } -SchedTaskBase* -SchedTaskList::next(Scheduler *scheduler, SchedTaskBase *p) +void +SchedTaskList::exec() {} + +void +SchedTaskList::write() { - SchedTaskBase *nextSched; - __debug("[SchedTaskList:%s]\n", __FUNCTION__); scheduler->dma_wait(DMA_READ_TASKLIST); - if (list->length < 1) { - nextSched = new SchedNop2Ready(scheduler); - } else { - TaskPtr nextTask = &list->tasks[0]; - nextSched = createSchedTask(scheduler, nextTask); - ((SchedTask*)nextSched)->init(list, nextTask, 1, - scheduler); - } - - return nextSched; } +/** + * next は、SchedTask のものが使われる。 + */ + /* end */ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/SchedTaskList.h --- a/TaskManager/kernel/schedule/SchedTaskList.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskList.h Wed Dec 16 18:04:26 2009 +0900 @@ -3,11 +3,11 @@ #include "base.h" #include "Scheduler.h" -#include "SchedTaskBase.h" +#include "SchedTask.h" #include "error.h" -class SchedTaskList : public SchedTaskBase { +class SchedTaskList : public SchedTask { public: /* constructor */ SchedTaskList(memaddr addr, Scheduler *sched); @@ -16,23 +16,15 @@ /* variables */ memaddr params_addr; - TaskListPtr list; - Scheduler *scheduler; - /* functions */ - SchedTaskBase* next(Scheduler *, SchedTaskBase *); - /* override functions */ - void read(void); + void read(); + void exec(); + void write(); -#ifdef DEBUG - void exec(void) { __debug("[SchedTaskList:%s]\n", __FUNCTION__); } - void write(void) { __debug("[SchedTaskList:%s]\n", __FUNCTION__); } -#endif }; -extern SchedTaskList* createSchedTaskList(memaddr, Scheduler*, int); #endif diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/Scheduler.cc --- a/TaskManager/kernel/schedule/Scheduler.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Wed Dec 16 18:04:26 2009 +0900 @@ -11,7 +11,7 @@ * Do not edit Cell/spe/xx.cc unless there is no kernel/schedule/xx.cc files. */ -Scheduler::TaskObject task_list[MAX_TASK_OBJECT]; +TaskObject task_list[MAX_TASK_OBJECT]; Scheduler::~Scheduler() { @@ -25,6 +25,8 @@ return 0; } +static void null_loader(Scheduler *m, int task_id); + /*! @brief speTaskの入出力のパイプラインバッファを確保する */ @@ -34,7 +36,9 @@ hash = 0; for (int i = 0; i< MAX_TASK_OBJECT; i++) { - task_list[0].run = null_run; + task_list[i].run = null_run; + task_list[i].load = null_loader; + task_list[i].wait = null_loader; } set_manager(m); @@ -59,11 +63,12 @@ } void -Scheduler::run() +Scheduler::run(SchedTaskBase* task1) { - task1 = new SchedNop(); - task2 = new SchedNop(); - task3 = new SchedNop(); + + // Pipeline Stage + SchedTaskBase* task2 = new SchedNop(); + SchedTaskBase* task3 = new SchedNop(); // main loop do { diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/schedule/Scheduler.h --- a/TaskManager/kernel/schedule/Scheduler.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Wed Dec 16 18:04:26 2009 +0900 @@ -7,7 +7,6 @@ #include "ListData.h" #include "DmaManager.h" #include "SchedTaskBase.h" -#include "SchedTaskList.h" #include "MemList.h" #include "MemHash.h" @@ -26,6 +25,21 @@ typedef int (*TaskObjectRun)(SchedTask* smanager, void* r, void *w); +// Task Object Table +// this is named TaskObjectRun but it is not an object. +// It is a pointer to an object creation function +// 大きいので、SPEには置かない方が本当は良い... +// get_segment で取って来るのが、おそらくは正しい。 +typedef struct { + TaskObjectRun run; + memaddr location; // location address in a.out + memaddr end; + uint32 entry_offset; // offset for create(); + MemorySegment *segment; + void (*load)(Scheduler *,int); + void (*wait)(Scheduler *,int); +} TaskObject, *TaskObjectPtr; + extern "C" { extern long random(); } @@ -55,31 +69,14 @@ /* Code Area */ MemList *code_segment_pool; - // Task Object Table - // this is named TaskObjectRun but it is not an object. - // It is a pointer to an object creation function - // 大きいので、SPEには置かない方が本当は良い... - typedef struct { - TaskObjectRun run; - memaddr location; // location address in a.out - memaddr end; - uint32 entry_offset; // offset for create(); - MemorySegment *segment; - void (*load)(Scheduler *,int); - void (*wait)(Scheduler *,int); - } TaskObject, *TaskObjectPtr; - DmaManager* connector; TaskManagerImpl* manager; - // Pipeline Stage - SchedTaskBase* task1; - SchedTaskBase* task2; - SchedTaskBase* task3; /* functions */ void init(TaskManagerImpl *m); - void run(); + void run(SchedTaskBase* task1); + virtual void init_impl() {}; void finish(); @@ -155,9 +152,19 @@ unsigned int buf; }; +extern TaskObject task_list[MAX_TASK_OBJECT]; + +inline void +loadSchedTask(Scheduler *scheduler,int command) +{ +// fprintf(stderr,"loadSchedTask %d\n",task->command); + task_list[command].load(scheduler,command); +} + #endif + #define SchedConstructor(str) \ str() {} \ BASE_NEW_DELETE(str) \ diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/sys_task/SysTasks.h --- a/TaskManager/kernel/sys_task/SysTasks.h Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/sys_task/SysTasks.h Wed Dec 16 18:04:26 2009 +0900 @@ -3,3 +3,5 @@ ShowTime, StartProfile, #define Dummy StartTask +#define TaskArray (-1) +#define TaskArray1 (-2) diff -r 0d8d2b7a3438 -r 974672c4ea2a TaskManager/kernel/sys_task/systask_register.cc --- a/TaskManager/kernel/sys_task/systask_register.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/TaskManager/kernel/sys_task/systask_register.cc Wed Dec 16 18:04:26 2009 +0900 @@ -3,10 +3,12 @@ SchedExternTask(StartTask); SchedExternTask(FinishTask); +// SchedExternTask(TaskArray); void systask_register() { SchedRegister(StartTask); SchedRegister(FinishTask); +// SchedRegister(TaskArray); } diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/Makefile.def --- a/example/Bulk/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -8,7 +8,8 @@ CERIUM = ../../../Cerium CC = g++ -CFLAGS = -g -Wall -O9 +OPT = -g +CFLAGS = -Wall $(OPT) ABIBIT = 32 diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/main.cc --- a/example/Bulk/main.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/main.cc Wed Dec 16 18:04:26 2009 +0900 @@ -2,20 +2,23 @@ #include #include #include "TaskManager.h" +#include "Task.h" +#include "ListData.h" #include "Func.h" extern void task_init(void); static int length = DATA_NUM; -static int task = 1; -static int count = 1; +static int task = 3; +static int count = 3; +static int data_count = 3; const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ -length Number of data (default DATA_NUM (Func.h))\n\ -count Number of task (default 1)\n"; -void +static void print_data(int *data, int size, const char *title) { printf("%s ---\n", title); @@ -28,79 +31,107 @@ /** * タスク終了後の data1, data2 の確認 */ -void +static void twice_result(SchedTask *s, void *a, void *b) { int* data = (int*)a; - print_data(data, length, "after"); + int* task_buf = (int*)b; + print_data(data, length*count, "after"); free(data); + free(task_buf); } -int +static int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-length") == 0) { length = atoi(argv[++i]); - } else if (strcmp(argv[i], "-count") == 0) { + } else if (strcmp(argv[i], "-task") == 0) { task = atoi(argv[++i]); - } else if (strcmp(argv[i], "-bluk") == 0) { + } else if (strcmp(argv[i], "-count") == 0) { count = atoi(argv[++i]); + } else if (strcmp(argv[i], "-data_count") == 0) { + data_count = atoi(argv[++i]); } } return 0; } -void -twice_init(TaskManager *manager) +#if 0 +static void print_ListData(int size, ListElement *t) { - TaskArray *twice; + for(int i = 0;iallocate(sizeof(int)*length); +void +twice_init(TaskManager *manager,int *data, int length) +{ - for (int i = 0; i < length; i++) { + + for (int i = 0; i < length*count; i++) { data[i] = i; } - print_data(data, length, "before"); + print_data(data, length*count, "before"); /** * Create Task * create_task(Task ID); */ - twice = manager->create_bulk_task(count); + + HTask *twice_main = manager->create_task_array(Twice,count,data_count+1,data_count,data_count); + Task *t = twice_main->next_task_array(Twice, 0); +#if 0 + printf("allocate task size 0x%0x\n",t->size()); + printf("allocate task total size 0x%0x = 0x%0x * %d\n",twice_main->r_size, + t->size(), count); +#endif + void *task_buf = twice_main->rbuf; + twice_main->set_post(twice_result, (void*)data, task_buf); + + t = 0; for(int i = 0;icreate_stask(Twice); - int length2 = length/2; - /** - * Set 32bits parameter - * add_param(32bit parameter); - */ - t->set_param(0, (memaddr)length2); - t->set_param(1, (memaddr)length2); - /** - * Set of Input Data - * add_inData(address of input data, size of input data); - */ - t->add_inData(data, sizeof(int)*length2); - t->add_inData(data+length2, sizeof(int)*length2); - /** - * Set of OutPut area - * add_outData(address of output area, size of output area); - */ - t->add_outData(data, sizeof(int)*length2); - t->add_outData(data+length2, sizeof(int)*length2); + t = twice_main->next_task_array(Twice, t); + int length2 = length/data_count; + t->set_param(0, (memaddr)data_count); + + for(int j = 0;jset_param(j+1, (memaddr)length2); + /** + * Set of Input Data + * add_inData(address of input data, size of input data); + */ + t->set_inData(j,data, sizeof(int)*length2); + /** + * Set of Output area + * add_outData(address of output area, size of output area); + */ + t->set_outData(j,data, sizeof(int)*length2); + data += length2; + } +#if 0 + print_ListData(data_count,t->inData(0)); + print_ListData(data_count,t->outData(0)); + printf("pos 0x%0lx size 0x%0x\n",(unsigned long)t, t->size()); +#endif } + twice_main->spawn_task_array(t->next()); + twice_main->set_cpu(SPE_ANY); - /* * set_post() で ppe task を渡せるようにしたい */ - twice->set_post(twice_result, (void*)data, 0); - // add Active Queue - twice->spawn_bulk(); + twice_main->spawn(); } int @@ -115,7 +146,8 @@ task_init(); for (int i = 0; i < task; ++i) { - twice_init(manager); + int *data = (int*)manager->allocate(sizeof(int)*length*count); + twice_init(manager, data, length); } return 0; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/ppe/Twice.cc --- a/example/Bulk/ppe/Twice.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/ppe/Twice.cc Wed Dec 16 18:04:26 2009 +0900 @@ -1,5 +1,5 @@ #include -#include "SchedTask.h" +#include "SchedTaskArray.h" #include "Twice.h" #include "Func.h" @@ -9,16 +9,21 @@ static int run(SchedTask *s,void *rbuf, void *wbuf) { + // SchedTaskArray *a = (SchedTaskArray *)s; + int *i_data; int *o_data; long length; + int count = (int)s->get_param(0); - i_data = (int*)s->get_input(rbuf, 0); - o_data = (int*)s->get_output(wbuf, 0); - length = (long)s->get_param(0); - - for (int i = 0; i < length; i++) { - o_data[i] = i_data[i] * 2; + for(int j = 0; jget_input(rbuf, j); + o_data = (int*)s->get_output(wbuf, j); + length = (long)s->get_param(j+1); + + for (int i = 0; i < length; i++) { + o_data[i] = i_data[i] * 2; + } } return 0; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/ppe/task_init.cc --- a/example/Bulk/ppe/task_init.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/ppe/task_init.cc Wed Dec 16 18:04:26 2009 +0900 @@ -13,5 +13,5 @@ void task_init(void) { - SchedRegisterTask(TWICE_TASK, Twice); + SchedRegister(Twice); } diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/spe/Twice.cc --- a/example/Bulk/spe/Twice.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/spe/Twice.cc Wed Dec 16 18:04:26 2009 +0900 @@ -1,5 +1,5 @@ #include -#include "SchedTask.h" +#include "SchedTaskArray.h" #include "Twice.h" #include "Func.h" @@ -7,18 +7,23 @@ SchedDefineTask(Twice); static int -run(SchedTask *s, void *rbuf, void *wbuf) +run(SchedTask *s,void *rbuf, void *wbuf) { + // SchedTaskArray *a = (SchedTaskArray *)s; + int *i_data; int *o_data; - int length; + long length; + int count = (int)s->get_param(0); - i_data = (int*)s->get_input(rbuf, 0); - o_data = (int*)s->get_output(wbuf, 0); - length = (long)s->get_param(0); - - for (int i = 0; i < length; i++) { - o_data[i] = i_data[i] * 2; + for(int j = 0; jget_input(rbuf, j); + o_data = (int*)s->get_output(wbuf, j); + length = (long)s->get_param(j+1); + + for (int i = 0; i < length; i++) { + o_data[i] = i_data[i] * 2; + } } return 0; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Bulk/spe/spe-main.cc --- a/example/Bulk/spe/spe-main.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Bulk/spe/spe-main.cc Wed Dec 16 18:04:26 2009 +0900 @@ -10,5 +10,5 @@ void task_init(Scheduler *s) { - SchedRegisterTask(TWICE_TASK, Twice); + SchedRegister(Twice); } diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Simple/Makefile.def --- a/example/Simple/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Simple/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -5,11 +5,11 @@ # ex linux/ps3 CERIUM = ../../../Cerium -SIMPLE_TASK=-DSIMPLE_TASK -# SIMPLE_TASK= + +OPT= -g CC = g++ -CFLAGS = -g -Wall -O9 $(SIMPLE_TASK) +CFLAGS = -Wall $(OPT) INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. LIBS = -L${CERIUM}/TaskManager diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Simple/Makefile.macosx --- a/example/Simple/Makefile.macosx Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Simple/Makefile.macosx Wed Dec 16 18:04:26 2009 +0900 @@ -22,7 +22,7 @@ all: $(TARGET) $(TARGET): $(OBJS) $(TASK_OBJS) - $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) $(OPT) link: $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Simple/spe/Makefile --- a/example/Simple/spe/Makefile Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Simple/spe/Makefile Wed Dec 16 18:04:26 2009 +0900 @@ -6,7 +6,7 @@ SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) OBJS = $(SRCS:.cc=.o) -CC = spu-g++ -DABIBIT=$(ABIBIT) $(SIMPLE_TASK) +CC = spu-g++ -DABIBIT=$(ABIBIT) $(OPT) CFLAGS = -g -Wall -fno-exceptions -fno-rtti #-DDEBUG INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. LIBS = -L../${CERIUM}/TaskManager -lspemanager @@ -19,7 +19,7 @@ all: $(TARGET) $(TARGET): $(OBJS) - $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) $(OPT) clean: rm -f $(TARGET) $(OBJS) diff -r 0d8d2b7a3438 -r 974672c4ea2a example/Simple/spe/Twice.cc --- a/example/Simple/spe/Twice.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/Simple/spe/Twice.cc Wed Dec 16 18:04:26 2009 +0900 @@ -7,11 +7,11 @@ SchedDefineTask(Twice); static int -run(SchedTask *s, void *rbuf, void *wbuf) +run(SchedTask *s,void *rbuf, void *wbuf) { int *i_data; int *o_data; - int length; + long length; i_data = (int*)rbuf; o_data = (int*)wbuf; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/basic/Makefile.def --- a/example/basic/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/example/basic/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -8,7 +8,8 @@ CERIUM = ../../../Cerium CC = g++ -CFLAGS = -g -Wall -O9 +OPT = -g +CFLAGS = $(OPT) -Wall ABIBIT = 32 diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/Makefile.def --- a/example/word_count_test/Makefile.def Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/Makefile.def Wed Dec 16 18:04:26 2009 +0900 @@ -7,14 +7,12 @@ # ex linux/ps3 CERIUM = ../../../Cerium -# SIMPLE_TASK= -DSIMPLE_TASK -SIMPLE_TASK= OPT = -O9 # OPT = -g CC = g++ -CFLAGS = -Wall $(OPT) $(SIMPLE_TASK) +CFLAGS = -Wall $(OPT) INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. LIBS = -L${CERIUM}/TaskManager diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/main.cc --- a/example/word_count_test/main.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/main.cc Wed Dec 16 18:04:26 2009 +0900 @@ -73,19 +73,10 @@ { for (int j = 0; j < task_count && w->size>0; j++) { int i = w->task_spwaned++; -#ifdef SIMPLE_TASK // printf("div %0x\n", (w->file_mmap + i*w->division_size)); HTaskPtr t_exec = manager->create_task(TASK_EXEC, (memaddr)(w->file_mmap + i*w->division_size), size, (memaddr)(w->o_data + i*w->out_size), w->division_out_size); -#else - HTaskPtr t_exec = manager->create_task(TASK_EXEC); - if (size>w->size) size = w->size; - t_exec->add_inData(w->file_mmap + i*w->division_size, size); - t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); - t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); - t_exec->add_param(size); -#endif t_exec->set_cpu(SPE_ANY); t_next->wait_for(t_exec); t_exec->spawn(); @@ -99,11 +90,7 @@ static int run16(SchedTask *manager, void *in, void *out) { -#ifdef SIMPLE_TASK WordCount *w = *(WordCount **)in; -#else - WordCount *w = (WordCount *)manager->get_param(0); -#endif if (w->task_num < w->task_blocks) { if (w->size >= w->division_size) @@ -112,13 +99,8 @@ run_tasks(manager,w,1, w->t_print, w->size); // printf("run16 last %d\n",w->task_num); } else { -#ifdef SIMPLE_TASK HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, (memaddr)&w->self,sizeof(memaddr),0,0); -#else - HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); - t_next->set_param(0,(void*)w); -#endif w->t_print->wait_for(t_next); run_tasks(manager,w, w->task_blocks, t_next, w->division_size); @@ -172,52 +154,24 @@ /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ -#ifdef SIMPLE_TASK w-> division_out_size = sizeof(unsigned long long)*4; int out_size = w->division_out_size*out_task_num; w->o_data = (unsigned long long *)manager->allocate(out_size); w-> out_size = 4; -#else - w-> division_out_size = 16; - int out_size = w->division_out_size*out_task_num; - /* out用のデータのサイズ。*/ - caddr_t p = (caddr_t) manager->allocate(out_size*2); - w->o_data = (unsigned long long*)p; - //bzero(w->o_data,out_size); - - w-> pad = 2; - w->head_tail_flag = (unsigned long long*)(p+out_size); - // bzero(w->head_tail_flag,out_size); -#endif printf("out size %d\n",out_size); /*各SPEの結果を合計して出力するタスク*/ -#ifdef SIMPLE_TASK t_print = manager->create_task(TASK_PRINT, (memaddr)&w->self,sizeof(memaddr),0,0); -#else - t_print = manager->create_task(TASK_PRINT); - t_print->add_inData(w->o_data, out_size); - t_print->add_inData(w->head_tail_flag, out_size); - t_print->add_param(out_task_num); - t_print->add_param(w->status_num); - t_print->add_param(out_task_num); - t_print->add_param(w->pad); -#endif w->t_print = t_print; for(int i = 0;i<1;i++) { /* Task を task_blocks ずつ起動する Task */ /* serialize されていると仮定する... */ - #ifdef SIMPLE_TASK HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, (memaddr)&w->self,sizeof(memaddr),0,0); - #else - HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS); - t_exec->set_param(0,(void*)w); - #endif t_exec->spawn(); t_print->wait_for(t_exec); } diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/ppe/Exec.cc --- a/example/word_count_test/ppe/Exec.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/ppe/Exec.cc Wed Dec 16 18:04:26 2009 +0900 @@ -9,18 +9,11 @@ static int run(SchedTask *s, void *rbuf, void *wbuf) { -#ifdef SIMPLE_TASK char *i_data = (char *)rbuf; unsigned long long *o_data = (unsigned long long*)wbuf; unsigned long long *head_tail_flag = o_data +2; int length = s->read_size(); -#else - char *i_data = (char*)s->get_input(rbuf, 0); - unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); - /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ - unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); - int length = (long)s->get_param(0); -#endif + int word_flag = 0; int word_num = 0; int line_num = 0; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/ppe/Print.cc --- a/example/word_count_test/ppe/Print.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/ppe/Print.cc Wed Dec 16 18:04:26 2009 +0900 @@ -10,7 +10,6 @@ static int run_print(SchedTask *s, void *rbuf, void *wbuf) { -#ifdef SIMPLE_TASK WordCount *w = *(WordCount**)rbuf; unsigned long long *idata = w->o_data; // long task_num = w->task_num; @@ -23,14 +22,6 @@ * o_data[1] * */ -#else - unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0); - unsigned long long *head_tail_flag = (unsigned long long*)s->get_input(rbuf, 1); - // long task_num = (long)s->get_param(0); - long status_num = (long)s->get_param(1); - int out_task_num = (int)s->get_param(2); - int pad = (int)s->get_param(3); -#endif unsigned long long word_data[2]; int flag_cal_sum = 0; @@ -75,7 +66,6 @@ word_data[i] = 0; } -#ifdef SIMPLE_TASK for (int i = 0; i < out_task_num ; i++) { word_data[0] += idata[i*w->out_size+0]; word_data[1] += idata[i*w->out_size+1]; @@ -86,21 +76,6 @@ flag_cal_sum++; } } -#else - for (int i = 1; i < out_task_num * pad - pad; i += pad) { - //printf("%llu ",head_tail_flag[i]); - //printf("%llu\n",head_tail_flag[i+1]); - if((head_tail_flag[i] == 1) && (head_tail_flag[i+1] == 0)) { - flag_cal_sum++; - } - } - - for (int i = 0; i < out_task_num*status_num; i += status_num) { - for (int j = 0; j < status_num; j++) { - word_data[j] += idata[i+j]; - } - } -#endif word_data[0] += flag_cal_sum; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/spe/Exec.cc --- a/example/word_count_test/spe/Exec.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/spe/Exec.cc Wed Dec 16 18:04:26 2009 +0900 @@ -9,18 +9,10 @@ static int run(SchedTask *s, void *rbuf, void *wbuf) { -#ifdef SIMPLE_TASK char *i_data = (char *)rbuf; unsigned long long *o_data = (unsigned long long*)wbuf; unsigned long long *head_tail_flag = o_data +2; int length = s->read_size(); -#else - char *i_data = (char*)s->get_input(rbuf, 0); - unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); - /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ - unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); - int length = (long)s->get_param(0); -#endif int word_flag = 0; int word_num = 0; int line_num = 0; diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/spe/Makefile --- a/example/word_count_test/spe/Makefile Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/spe/Makefile Wed Dec 16 18:04:26 2009 +0900 @@ -7,7 +7,7 @@ OBJS = $(SRCS:.cc=.o) CC = spu-g++ -CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT) $(SIMPLE_TASK) #-DDEBUG +CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT) INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. LIBS = -L../${CERIUM}/TaskManager -lspemanager diff -r 0d8d2b7a3438 -r 974672c4ea2a example/word_count_test/spe/Print.cc --- a/example/word_count_test/spe/Print.cc Wed Dec 16 16:29:31 2009 +0900 +++ b/example/word_count_test/spe/Print.cc Wed Dec 16 18:04:26 2009 +0900 @@ -10,7 +10,6 @@ static int run_print(SchedTask *s, void *rbuf, void *wbuf) { -#ifdef SIMPLE_TASK WordCount *w = *(WordCount**)rbuf; unsigned long long *idata = w->o_data; // long task_num = w->task_num; @@ -23,14 +22,6 @@ * o_data[1] * */ -#else - unsigned long long *idata = (unsigned long long*)s->get_input(rbuf, 0); - unsigned long long *head_tail_flag = (unsigned long long*)s->get_input(rbuf, 1); - // long task_num = (long)s->get_param(0); - long status_num = (long)s->get_param(1); - int out_task_num = (int)s->get_param(2); - int pad = (int)s->get_param(3); -#endif unsigned long long word_data[2]; int flag_cal_sum = 0; @@ -75,7 +66,6 @@ word_data[i] = 0; } -#ifdef SIMPLE_TASK for (int i = 0; i < out_task_num ; i++) { word_data[0] += idata[i*w->out_size+0]; word_data[1] += idata[i*w->out_size+1]; @@ -86,21 +76,6 @@ flag_cal_sum++; } } -#else - for (int i = 1; i < out_task_num * pad - pad; i += pad) { - //printf("%llu ",head_tail_flag[i]); - //printf("%llu\n",head_tail_flag[i+1]); - if((head_tail_flag[i] == 1) && (head_tail_flag[i+1] == 0)) { - flag_cal_sum++; - } - } - - for (int i = 0; i < out_task_num*status_num; i += status_num) { - for (int j = 0; j < status_num; j++) { - word_data[j] += idata[i+j]; - } - } -#endif word_data[0] += flag_cal_sum;