Mercurial > hg > Game > Cerium
changeset 373:205e4a4af635 draft
MemList not working
line wrap: on
line diff
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Fri Jul 31 17:52:27 2009 +0900 @@ -2,6 +2,7 @@ #include <stdlib.h> #include <string.h> #include "FifoTaskManagerImpl.h" +#include "Scheduler.h" #include "types.h" #include "error.h" @@ -38,7 +39,7 @@ * これは CellTaskManagerImpl から呼ばれる。 * BufferManager は共用で使うので引数に。 * CellTaskManagerImpl と FifoTaskManagerImpl が同時に - * 上のデータにアクセスする事は(今は)ないのでこれでおk + * 上のデータにアクセスする事は(今は)ないのでこれでおk */ void FifoTaskManagerImpl::init(MainScheduler *_sched, BufferManager *buff) @@ -75,7 +76,7 @@ queue = activeTaskQueue; if (queue == NULL) { - return NULL; + return NULL; } // PPE 側で実行される TaskList @@ -86,28 +87,28 @@ list = list_top; while (queue) { - htask = (HTaskPtr)queue->task; - d = queue; - queue = queue->next; + htask = (HTaskPtr)queue->task; + d = queue; + queue = queue->next; - task = &list->tasks[list->length++]; + task = &list->tasks[list->length++]; #if 0 - task->command = htask->command; - task->inData = htask->inData; - task->outData = htask->outData; - task->self = (unsigned int)htask; + task->command = htask->command; + task->inData = htask->inData; + task->outData = htask->outData; + task->self = (unsigned int)htask; #else - memcpy(task, htask, sizeof(Task)); + memcpy(task, htask, sizeof(Task)); #endif - if (list->length >= TASK_MAX_SIZE) { - TaskListPtr newList = bufferManager->create_taskList(); - list_top = TaskListInfo::append(list_top, newList); - list = newList; - } + if (list->length >= TASK_MAX_SIZE) { + TaskListPtr newList = bufferManager->create_taskList(); + list_top = TaskListInfo::append(list_top, newList); + list = newList; + } - bufferManager->free_taskQueue(d); + bufferManager->free_taskQueue(d); } activeTaskQueue = NULL; @@ -126,15 +127,15 @@ list = get_runTaskList(); do { - // list を実行する - mail = schedule(list); + // list を実行する + mail = schedule(list); - // mail には、ppe scheduler からの mail がある - mail_check(mail); + // mail には、ppe scheduler からの mail がある + mail_check(mail); - // 依存関係を満たしたものは実行可能キューへ - wakeup_waitTask(); - list = get_runTaskList(); + // 依存関係を満たしたものは実行可能キューへ + wakeup_waitTask(); + list = get_runTaskList(); } while (list); } @@ -153,17 +154,17 @@ MailQueuePtr out_mail_list = NULL; // TaskList のアドレス - list_mail = mailManager->create((unsigned int)list); + list_mail = mailManager->create((unsigned int)list); in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail); // EXIT_COMMAND (番兵的な意味で) sentinel = mailManager->create(MY_SPE_COMMAND_EXIT); in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel); - + // scheduler は受け取ったメールを元に実行する scheduler->send_mailList(in_mail_list); scheduler->run(); - out_mail_list = scheduler->recv_mailList(); + out_mail_list = scheduler->recv_mailList(); return out_mail_list; } @@ -175,7 +176,7 @@ * PPE 側で動く Scheduler からのメールリスト * 終了した Task や、その他(今はまだ実装してないけど)の情報が入ってる * - * @return Scheduler が次に実行する Task List + * @return Scheduler が次に実行する Task List * NULL なら全てのタスクが実行終了したということ */ void @@ -186,28 +187,28 @@ unsigned int data; while (q) { - data = q->data; + data = q->data; - /** - * MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了 - * MY_SPE_NOP: 特に意味のないコマンド - * それ以外:終了したタスク(PPEにあるのでアドレス - * - * MY_SPE_NOP が 0 なので、 - * 下のように data > MY_SPE_NOP とかしています。 - * 一目でよくわからない書き方なんで、直したいところですが。。。 - */ - if (data == MY_SPE_STATUS_READY) { - __debug_ppe("mail_check(): Task List finish\n"); - } else if (data > MY_SPE_NOP) { - __debug_ppe("mail_check(): recv from 0x%x\n", data); - check_task_finish((HTaskPtr)data); - } + /** + * MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了 + * MY_SPE_NOP: 特に意味のないコマンド + * それ以外:終了したタスク(PPEにあるのでアドレス + * + * MY_SPE_NOP が 0 なので、 + * 下のように data > MY_SPE_NOP とかしています。 + * 一目でよくわからない書き方なんで、直したいところですが。。。 + */ + if (data == MY_SPE_STATUS_READY) { + __debug_ppe("mail_check(): Task List finish\n"); + } else if (data > MY_SPE_NOP) { + __debug_ppe("mail_check(): recv from 0x%x\n", data); + check_task_finish((HTaskPtr)data); + } - d = q; - q = q->next; + d = q; + q = q->next; - mailManager->free(d); + mailManager->free(d); } } @@ -224,13 +225,18 @@ return malloc(size); } +Scheduler* +FifoTaskManagerImpl::get_scheduler() { + return scheduler; +} + /** * こういう使い方を * Abstract Factory Pattern * というらしい。 */ #ifdef __CERIUM_FIFO__ -TaskManagerImpl* +TaskManagerImpl* create_impl(int num) { return new FifoTaskManagerImpl();
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Fri Jul 31 17:52:27 2009 +0900 @@ -3,6 +3,7 @@ #include "TaskManagerImpl.h" #include "MainScheduler.h" +#include "Scheduler.h" class FifoTaskManagerImpl : public TaskManagerImpl { public: @@ -30,6 +31,7 @@ // call by user int add_data(ListDataPtr, uint32, int); void* allocate(int size); + Scheduler* get_scheduler(); }; #ifndef Cerium_malloc
--- a/TaskManager/Test/test_render/Makefile.def Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/Makefile.def Fri Jul 31 17:52:27 2009 +0900 @@ -3,7 +3,7 @@ CERIUM = ../../.. CC = g++ -CFLAGS = -O9 -g -Wall# -DDEBUG +CFLAGS = -O9 -g -Wall -D USE_MEMLIST=1 # -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. LIBS = -L$(CERIUM)/TaskManager \ No newline at end of file
--- a/TaskManager/Test/test_render/SGList.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/SGList.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -1,5 +1,5 @@ #include "SGList.h" const char *sglist_table[SGLIST_LENGTH] = { - "Ball", "LongCube", "Venus000", "Venus001", "Venus002", "Venus008", "Venus003", "Venus007", "Venus006", "Venus004", "Venus005", "Venus009", "BLAST8", "BLAST7", "BLAST6", "BLAST5", "BLAST4", "BLAST3", "BLAST2", "BLAST1", "BOSS1", "BOSS1_L", "BOSS1_R", "Cube", "BigCube", "Plane", "SmallCube", "Diry", "Dirz", "Dirx", "LOCK", "ENEMY", "REDCUBE", "BIGCUBE", "GAMEOVER", "arm_L_D", "foot_L_B", "foot_L_E", "foot_L_C", "shield_L_C", "arm_L_G", "arm_L_E", "arm_R_F", "arm_R_A", "arm_R_E", "shoulder_R_C", "shoulder_R_B", "chest_L_A", "shoulder_R_A", "head_E", "shield_L_E", "shield_L_D", "shield_R_D", "shield_L_A", "arm_R_C", "arm_R_B", "arm_L_C", "eye", "booster_B", "booster_A", "chest_R_A", "chest_center_A", "shoulder_L_A", "body_A", "body_B", "body_C", "chest_center_B", "chest_R_C", "chest_L_C", "chest_L_B", "chest_R_B", "west_D", "west_A", "west_B", "body_L_A", "body_R_A", "chest_center_C", "chest_B", "head_C", "head_F", "head_D", "head_R_B", "head_L_B", "head_L_A", "head_R_A", "head_B", "head_A", "shoulder_L_B", "shoulder_L_C", "arm_L_A", "arm_L_B", "arm_R_D", "arm_L_F", "arm_R_G", "shield_R_C", "shield_R_E", "shield_L_B", "shield_R_B", "shield_R_A", "west_C", "foot_L_D", "foot_R_D", "foot_L_F", "foot_R_F", "foot_R_C", "foot_R_E", "foot_R_A", "foot_R_B", "chest_A", "foot_L_A", "IEBOSS", "IEJIKI", "IETAMA", "MCUBE_BACK", "MCUBE", "BIGMCUBE", "CUBE", "arm", "skirt", "leg", "hand", "right_eye", "left_eye", "twin_tail", "hair_band", "hair", "body", "P_SHOT1", "PANEL_1024", "PANEL_2048", "PANEL_512", "BACK", "BULEBULLET", "E_PLANE", "IDLE", "PLAYER", "PLAYER_L", "PLAYER_LL", "PLAYER_R", "PLAYER_RR", "Sphere", "BigSphere", "Cube", "TITLE", "Earth", "Moon" + "Ball", "LongCube", "Venus000", "Venus001", "Venus002", "Venus008", "Venus003", "Venus007", "Venus006", "Venus004", "Venus005", "Venus009", "BLAST8", "BLAST7", "BLAST6", "BLAST5", "BLAST4", "BLAST3", "BLAST2", "BLAST1", "BOSS1", "BOSS1_L", "BOSS1_R", "CHAIN", "Cube", "BigCube", "Plane", "SmallCube", "Diry", "Dirz", "Dirx", "LOCK", "ENEMY", "REDCUBE", "BIGCUBE", "GAMEOVER", "arm_L_D", "foot_L_B", "foot_L_E", "foot_L_C", "shield_L_C", "arm_L_G", "arm_L_E", "arm_R_F", "arm_R_A", "arm_R_E", "shoulder_R_C", "shoulder_R_B", "chest_L_A", "shoulder_R_A", "head_E", "shield_L_E", "shield_L_D", "shield_R_D", "shield_L_A", "arm_R_C", "arm_R_B", "arm_L_C", "eye", "booster_B", "booster_A", "chest_R_A", "chest_center_A", "shoulder_L_A", "body_A", "body_B", "body_C", "chest_center_B", "chest_R_C", "chest_L_C", "chest_L_B", "chest_R_B", "west_D", "west_A", "west_B", "body_L_A", "body_R_A", "chest_center_C", "chest_B", "head_C", "head_F", "head_D", "head_R_B", "head_L_B", "head_L_A", "head_R_A", "head_B", "head_A", "shoulder_L_B", "shoulder_L_C", "arm_L_A", "arm_L_B", "arm_R_D", "arm_L_F", "arm_R_G", "shield_R_C", "shield_R_E", "shield_L_B", "shield_R_B", "shield_R_A", "west_C", "foot_L_D", "foot_R_D", "foot_L_F", "foot_R_F", "foot_R_C", "foot_R_E", "foot_R_A", "foot_R_B", "chest_A", "foot_L_A", "IEBOSS", "IEJIKI", "IETAMA", "MCUBE_BACK", "MCUBE", "BIGMCUBE", "CUBE", "P_SHOT1", "PANEL_1024", "PANEL_2048", "PANEL_512", "BACK", "BULEBULLET", "E_PLANE", "IDLE", "PLAYER", "PLAYER_L", "PLAYER_LL", "PLAYER_R", "PLAYER_RR", "Sphere", "BigSphere", "TITLE", "Earth", "Moon" };
--- a/TaskManager/Test/test_render/SGList.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/SGList.h Fri Jul 31 17:52:27 2009 +0900 @@ -34,177 +34,165 @@ #define BOSS1_L 21 #define BOSS1_R 22 +/* xml_file/chain.xml */ +#define CHAIN 23 + /* xml_file/cube.xml */ -#define Cube 23 +#define Cube 24 /* xml_file/cube_big.xml */ -#define BigCube 24 +#define BigCube 25 /* xml_file/cube_split.xml */ -#define Plane 25 -#define SmallCube 26 +#define Plane 26 +#define SmallCube 27 /* xml_file/direction.xml */ -#define Diry 27 -#define Dirz 28 -#define Dirx 29 +#define Diry 28 +#define Dirz 29 +#define Dirx 30 /* xml_file/gamecube.xml */ -#define LOCK 30 -#define ENEMY 31 -#define REDCUBE 32 -#define BIGCUBE 33 +#define LOCK 31 +#define ENEMY 32 +#define REDCUBE 33 +#define BIGCUBE 34 /* xml_file/gameover.xml */ -#define GAMEOVER 34 +#define GAMEOVER 35 /* xml_file/gap_plane_test.xml */ -#define arm_L_D 35 -#define foot_L_B 36 -#define foot_L_E 37 -#define foot_L_C 38 -#define shield_L_C 39 -#define arm_L_G 40 -#define arm_L_E 41 -#define arm_R_F 42 -#define arm_R_A 43 -#define arm_R_E 44 -#define shoulder_R_C 45 -#define shoulder_R_B 46 -#define chest_L_A 47 -#define shoulder_R_A 48 -#define head_E 49 -#define shield_L_E 50 -#define shield_L_D 51 -#define shield_R_D 52 -#define shield_L_A 53 -#define arm_R_C 54 -#define arm_R_B 55 -#define arm_L_C 56 -#define eye 57 -#define booster_B 58 -#define booster_A 59 -#define chest_R_A 60 -#define chest_center_A 61 -#define shoulder_L_A 62 -#define body_A 63 -#define body_B 64 -#define body_C 65 -#define chest_center_B 66 -#define chest_R_C 67 -#define chest_L_C 68 -#define chest_L_B 69 -#define chest_R_B 70 -#define west_D 71 -#define west_A 72 -#define west_B 73 -#define body_L_A 74 -#define body_R_A 75 -#define chest_center_C 76 -#define chest_B 77 -#define head_C 78 -#define head_F 79 -#define head_D 80 -#define head_R_B 81 -#define head_L_B 82 -#define head_L_A 83 -#define head_R_A 84 -#define head_B 85 -#define head_A 86 -#define shoulder_L_B 87 -#define shoulder_L_C 88 -#define arm_L_A 89 -#define arm_L_B 90 -#define arm_R_D 91 -#define arm_L_F 92 -#define arm_R_G 93 -#define shield_R_C 94 -#define shield_R_E 95 -#define shield_L_B 96 -#define shield_R_B 97 -#define shield_R_A 98 -#define west_C 99 -#define foot_L_D 100 -#define foot_R_D 101 -#define foot_L_F 102 -#define foot_R_F 103 -#define foot_R_C 104 -#define foot_R_E 105 -#define foot_R_A 106 -#define foot_R_B 107 -#define chest_A 108 -#define foot_L_A 109 +#define arm_L_D 36 +#define foot_L_B 37 +#define foot_L_E 38 +#define foot_L_C 39 +#define shield_L_C 40 +#define arm_L_G 41 +#define arm_L_E 42 +#define arm_R_F 43 +#define arm_R_A 44 +#define arm_R_E 45 +#define shoulder_R_C 46 +#define shoulder_R_B 47 +#define chest_L_A 48 +#define shoulder_R_A 49 +#define head_E 50 +#define shield_L_E 51 +#define shield_L_D 52 +#define shield_R_D 53 +#define shield_L_A 54 +#define arm_R_C 55 +#define arm_R_B 56 +#define arm_L_C 57 +#define eye 58 +#define booster_B 59 +#define booster_A 60 +#define chest_R_A 61 +#define chest_center_A 62 +#define shoulder_L_A 63 +#define body_A 64 +#define body_B 65 +#define body_C 66 +#define chest_center_B 67 +#define chest_R_C 68 +#define chest_L_C 69 +#define chest_L_B 70 +#define chest_R_B 71 +#define west_D 72 +#define west_A 73 +#define west_B 74 +#define body_L_A 75 +#define body_R_A 76 +#define chest_center_C 77 +#define chest_B 78 +#define head_C 79 +#define head_F 80 +#define head_D 81 +#define head_R_B 82 +#define head_L_B 83 +#define head_L_A 84 +#define head_R_A 85 +#define head_B 86 +#define head_A 87 +#define shoulder_L_B 88 +#define shoulder_L_C 89 +#define arm_L_A 90 +#define arm_L_B 91 +#define arm_R_D 92 +#define arm_L_F 93 +#define arm_R_G 94 +#define shield_R_C 95 +#define shield_R_E 96 +#define shield_L_B 97 +#define shield_R_B 98 +#define shield_R_A 99 +#define west_C 100 +#define foot_L_D 101 +#define foot_R_D 102 +#define foot_L_F 103 +#define foot_R_F 104 +#define foot_R_C 105 +#define foot_R_E 106 +#define foot_R_A 107 +#define foot_R_B 108 +#define chest_A 109 +#define foot_L_A 110 /* xml_file/ieboss.xml */ -#define IEBOSS 110 +#define IEBOSS 111 /* xml_file/iejiki.xml */ -#define IEJIKI 111 +#define IEJIKI 112 /* xml_file/ietama.xml */ -#define IETAMA 112 +#define IETAMA 113 /* xml_file/mcube.xml */ -#define MCUBE_BACK 113 -#define MCUBE 114 -#define BIGMCUBE 115 -#define CUBE 116 - -/* xml_file/nendoLoid.xml */ -#define arm 117 -#define skirt 118 -#define leg 119 -#define hand 120 -#define right_eye 121 -#define left_eye 122 -#define twin_tail 123 -#define hair_band 124 -#define hair 125 -#define body 126 +#define MCUBE_BACK 114 +#define MCUBE 115 +#define BIGMCUBE 116 +#define CUBE 117 /* xml_file/p_shot.xml */ -#define P_SHOT1 127 +#define P_SHOT1 118 /* xml_file/panel_1024.xml */ -#define PANEL_1024 128 +#define PANEL_1024 119 /* xml_file/panel_2048.xml */ -#define PANEL_2048 129 +#define PANEL_2048 120 /* xml_file/panel_512.xml */ -#define PANEL_512 130 +#define PANEL_512 121 /* xml_file/player.xml */ -#define BACK 131 -#define BULEBULLET 132 -#define E_PLANE 133 -#define IDLE 134 +#define BACK 122 +#define BULEBULLET 123 +#define E_PLANE 124 +#define IDLE 125 /* xml_file/player1.xml */ -#define PLAYER 135 -#define PLAYER_L 136 -#define PLAYER_LL 137 -#define PLAYER_R 138 -#define PLAYER_RR 139 +#define PLAYER 126 +#define PLAYER_L 127 +#define PLAYER_LL 128 +#define PLAYER_R 129 +#define PLAYER_RR 130 /* xml_file/sphere.xml */ -#define Sphere 140 +#define Sphere 131 /* xml_file/sphere_big.xml */ -#define BigSphere 141 - -/* xml_file/test_eye.xml */ -#define Cube 142 +#define BigSphere 132 /* xml_file/title.xml */ -#define TITLE 143 +#define TITLE 133 /* xml_file/universe.xml */ -#define Earth 144 -#define Moon 145 +#define Earth 134 +#define Moon 135 /* Number of Scene */ -#define SGLIST_LENGTH 146 +#define SGLIST_LENGTH 136 /* Scene Table */ extern const char *sglist_table[SGLIST_LENGTH];
--- a/TaskManager/Test/test_render/Tapestry.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/Tapestry.h Fri Jul 31 17:52:27 2009 +0900 @@ -1,20 +1,17 @@ #ifndef INCLUDED_TAPESTRY #define INCLUDED_TAPESTRY -#ifndef INCLUDED_TYPES -# include "types.h" -#endif - -#ifndef INCLUDED_VIEWER_TYPES -# include "viewer_types.h" -#endif +#include "types.h" +#include "viewer_types.h" +#include "MemorySegment.h" +#include "MemList.h" /** * image file name と tapestry DB の binary tree * * // PPE * main memory の tapestry DB (Array) - * tapestry DB への accessor + * tapestry DB への accessor * * TapestryPtr getTapestry(int TapestryID); * TilePtr getTile(TapestryPtr tapsetry, int tx, int ty, int scale); @@ -27,7 +24,7 @@ * px, py : texture の分割数 * * @out (TilePtr, tix1, tiy1, tix2, tiy2)* - * + * * * SPE に渡す tapestry List * @in Tile @@ -43,7 +40,7 @@ * if (TileEntry == NULL) { * DMA read * } - * + * * * Rendering * 1pass Zbuffer と Texture の有無の判定 @@ -71,7 +68,7 @@ * */ struct texture_block { - + }; #ifdef USE_MEMLIST @@ -92,7 +89,9 @@ * freelist は double linked list で、LRU をサポートする */ #ifdef USE_MEMLIST -class TileList : MemList { +class TileList : public MemList { + TileList(MemorySegment* ms) : MemList(ms) {} + /*! 中身は同じ */ @@ -105,7 +104,7 @@ Tile tile[MAX_TILE]; TileList(void) { - curIndex = 0; + curIndex = 0; } /** @@ -117,9 +116,9 @@ * FIFO を実現することに。 */ TilePtr nextTile(void) { - TilePtr t = &tile[curIndex]; - curIndex = (curIndex + 1) % MAX_TILE; - return t; + TilePtr t = &tile[curIndex]; + curIndex = (curIndex + 1) % MAX_TILE; + return t; } /** @@ -128,7 +127,7 @@ * あるかもしれない */ void clear(void) { - curIndex = 0; + curIndex = 0; } }; #endif
--- a/TaskManager/Test/test_render/cube.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/cube.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -6,7 +6,7 @@ void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { if (node->frame > 120) { cube_split(node,tree); @@ -20,11 +20,11 @@ node->xyz[1] += node->stack_xyz[1]; if (node->xyz[0] < 0) { - node->set_move_collision(cube_move_right, cube_collision); + node->set_move_collision(cube_move_right, cube_collision); } if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; + node->stack_xyz[1] = -node->stack_xyz[1]; } } @@ -41,13 +41,13 @@ { node->xyz[0] += node->stack_xyz[0]; node->xyz[1] += node->stack_xyz[1]; - + if (node->xyz[0] > screen_w) { - node->set_move_collision(cube_move_left, cube_collision); + node->set_move_collision(cube_move_left, cube_collision); } if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; + node->stack_xyz[1] = -node->stack_xyz[1]; } } @@ -58,8 +58,8 @@ { SceneGraphPtr p; - SceneGraphPtr common_move = sgroot->createSceneGraph(); - SceneGraphPtr root_common_move = root->parent; + // SceneGraphPtr common_move = sgroot->createSceneGraph(); + // SceneGraphPtr root_common_move = root->parent; if(random()%SELECT) { p = sgroot->createSceneGraph(REDCUBE); @@ -95,38 +95,38 @@ void collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node) { - float dx, dy,ddx,ddy, r; + float dx, dy,ddx,ddy, r; float q = 0; - - for (; it->hasNext(REDCUBE);) { + + for (; it->hasNext(REDCUBE);) { - it->next(REDCUBE); - SceneGraphPtr mcube = it->get(); + it->next(REDCUBE); + SceneGraphPtr mcube = it->get(); dx = node->xyz[0] - mcube->xyz[0]; - dy = node->xyz[1] - mcube->xyz[1]; - + dy = node->xyz[1] - mcube->xyz[1]; + ddx = dx*dx; - ddy = dy*dy; - + ddy = dy*dy; + if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { mcube->remove(); continue; - } - r = sqrt(ddx + ddy); + } + r = sqrt(ddx + ddy); if (r >= 1) q = 200/r; if (dx == 0) { if(mcube->xyz[1] > node->xyz[1]) { - mcube->stack_xyz[1] -= q; + mcube->stack_xyz[1] -= q; } else if(mcube->xyz[1] < node->xyz[1]) { - mcube->stack_xyz[1] += q; + mcube->stack_xyz[1] += q; } } else { if(mcube->xyz[0] > node->xyz[0]) { - mcube->xyz[0] -= q*cos(atan(dy/dx)); - mcube->xyz[1] -= q*sin(atan(dy/dx)); + mcube->xyz[0] -= q*cos(atan(dy/dx)); + mcube->xyz[1] -= q*sin(atan(dy/dx)); } else if(mcube->xyz[0] < node->xyz[0]) { - mcube->xyz[0] += q*cos(atan(dy/dx)); - mcube->xyz[1] += q*sin(atan(dy/dx)); + mcube->xyz[0] += q*cos(atan(dy/dx)); + mcube->xyz[1] += q*sin(atan(dy/dx)); } } } @@ -137,12 +137,12 @@ { float dx, dy,ddx,ddy, r; float q = 0; - + for (; it->hasNext(ENEMY);) { - it->next(ENEMY); - SceneGraphPtr mcube = it->get(); - - dx = node->xyz[0] - mcube->xyz[0]; + it->next(ENEMY); + SceneGraphPtr mcube = it->get(); + + dx = node->xyz[0] - mcube->xyz[0]; dy = node->xyz[1] - mcube->xyz[1]; ddx = dx*dx; ddy = dy*dy; @@ -152,22 +152,22 @@ node->remove(); break; } - r = sqrt(ddx + ddy); + r = sqrt(ddx + ddy); if (r >= 1) q = 200/r; if (dx == 0) { if(mcube->xyz[1] > node->xyz[1]) { - mcube->stack_xyz[1] -= q; + mcube->stack_xyz[1] -= q; } else if(mcube->xyz[1] < node->xyz[1]) { - mcube->stack_xyz[1] += q; + mcube->stack_xyz[1] += q; } } else { if(mcube->xyz[0] > node->xyz[0]) { - mcube->xyz[0] -= q*cos(atan(dy/dx)); - mcube->xyz[1] -= q*sin(atan(dy/dx)); - } else if(mcube->xyz[0] < node->xyz[0]) { - mcube->xyz[0] += q*cos(atan(dy/dx)); - mcube->xyz[1] += q*sin(atan(dy/dx)); + mcube->xyz[0] -= q*cos(atan(dy/dx)); + mcube->xyz[1] -= q*sin(atan(dy/dx)); + } else if(mcube->xyz[0] < node->xyz[0]) { + mcube->xyz[0] += q*cos(atan(dy/dx)); + mcube->xyz[1] += q*sin(atan(dy/dx)); } } }
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -72,11 +72,11 @@ * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address * @return block ID */ -uint32* -DrawSpan::getTile(int tx, int ty, int tw, uint32 *tex_addr_top) +memaddr +DrawSpan::getTile(int tx, int ty, int tw, memaddr tex_addr_top) { int block = getTexBlock(tx, ty, tw); - return tex_addr_top + block*TEXTURE_BLOCK_SIZE; + return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); } /** @@ -127,13 +127,13 @@ * @retval NULL 存在しない */ TilePtr -DrawSpan::isAvailableTile(uint32 *addr) -{ +DrawSpan::isAvailableTile(memaddr addr) +{ return hash->get(addr); } TilePtr -DrawSpan::set_rgb(uint32 *addr, int tag) +DrawSpan::set_rgb(memaddr addr, int tag) { TilePtr tile; @@ -144,9 +144,9 @@ tile = tileList->nextTile(); #endif - uint32 *old_addr = tile->address; - smanager->dma_load(tile->data, (uint32)addr, - sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); + memaddr old_addr = tile->address; + smanager->dma_load(tile->data, addr, + sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); /** * FIFO なので、もし前のが残っていれば削除 */ @@ -163,7 +163,8 @@ uint32 DrawSpan::get_rgb(int tx, int ty, TilePtr tile) { - return tile->data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; + uint32 *data = (uint32 *)tile->data; + return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; } /** @@ -292,7 +293,7 @@ */ int tex_localx; int tex_localy; - uint32 *tex_addr; + memaddr tex_addr; if (span->x < startx || endx < span->x) { return -1; @@ -303,20 +304,20 @@ if (zpos < zRow[localx + (rangex*localy)]) { tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + span->tex_width, (memaddr)span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - TilePtr tile; - if (!(tile = isAvailableTile(tex_addr))) { + TilePtr tile; + if (!(tile = isAvailableTile(tex_addr))) { tile = set_rgb(tex_addr, wait_tag); smanager->dma_wait(wait_tag); //return startx; } #ifdef USE_MEMLIST - else { - tileList->moveToFirst(tile); - } + else { + tileList->moveToFirst(tile); + } #endif updateBuffer(zpos, rangex, localx, localy, @@ -405,24 +406,24 @@ if (tex_z < zRow[localx + (rangex*localy)]) { // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と // そのブロックのアドレス(MainMemory) - uint32 *tex_addr; + memaddr tex_addr; int tex_localx; int tex_localy; tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + span->tex_width, (memaddr)span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - TilePtr tile; + TilePtr tile; if (!(tile = isAvailableTile(tex_addr))) { tile = set_rgb(tex_addr, wait_tag); smanager->dma_wait(wait_tag); } #ifdef USE_MEMLIST - else { - tileList->moveToFirst(tile); - } + else { + tileList->moveToFirst(tile); + } #endif updateBuffer(tex_z, rangex, localx, localy,
--- a/TaskManager/Test/test_render/task/DrawSpan.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.h Fri Jul 31 17:52:27 2009 +0900 @@ -1,21 +1,10 @@ #ifndef INCLUDED_TASK_DRAW_SPAN #define INCLUDED_TASK_DRAW_SPAN -#ifndef INCLUDED_SCHED_TASK -# include "SchedTask.h" -#endif - -#ifndef INCLUDED_TAPESTRY -# include "Tapestry.h" -#endif - -#ifndef INCLUDED_SPAN_PACK -# include "SpanPack.h" -#endif - -#ifndef INCLUDED_TEXTURE_HASH -# include "TileHash.h" -#endif +#include "SchedTask.h" +#include "Tapestry.h" +#include "SpanPack.h" +#include "TileHash.h" class DrawSpan : public SchedTask { public: @@ -33,16 +22,16 @@ int* linebuf_init(int width, int height, int rgb); float* zRow_init(int width, int height); - TilePtr set_rgb(uint32 *addr, int wait_tag); - void set_rgbs(uint32 *addr, uint32 *max_addr, int wait_tag); + TilePtr set_rgb(memaddr addr, int wait_tag); + void set_rgbs(memaddr addr, uint32 *max_addr, int wait_tag); uint32 get_rgb(int tx, int ty, TilePtr tile); - TilePtr isAvailableTile(uint32 *addr); - uint32* getTile(int tx, int ty, int tw, uint32 *tex_addr_top); + TilePtr isAvailableTile(memaddr addr); + memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top); int getTexBlock(int tx, int ty, int twidth); void writebuffer(unsigned int display, int width, int height, - int screen_width); + int screen_width); void updateBuffer(float zpos, int rangex, int x, int y, - int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, TilePtr tile); + int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, TilePtr tile); void reboot(SpanPackPtr spack, int cur_span_x);
--- a/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -112,7 +112,7 @@ */ int tex_localx; int tex_localy; - uint32 *tex_addr; + memaddr tex_addr; int x = span->x; int y = span->y; @@ -134,11 +134,11 @@ if (zpos < zRow[localx + (rangex * localy)]) { tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + span->tex_width, (memaddr)span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - TilePtr tile; + TilePtr tile; if (!(tile = isAvailableTile(tex_addr))) { tile = set_rgb(tex_addr, 0); smanager->dma_wait(0); @@ -178,11 +178,11 @@ if (tex_z < zRow[localx + (rangex*localy)]) { tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, span->tex_addr); + span->tex_width, (memaddr)span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - TilePtr tile; + TilePtr tile; if (!(tile = isAvailableTile(tex_addr))) { spack->info.start = t; tile = set_rgb(tex_addr, TEX_LOAD);
--- a/TaskManager/Test/test_render/task/Load_Texture.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/Load_Texture.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -5,6 +5,7 @@ #include "TileHash.h" #include "Func.h" #include "global_alloc.h" +#include "Tapestry.h" SchedDefineTask(LoadTexture); @@ -23,9 +24,14 @@ = smanager->global_alloc(GLOBAL_TEXTURE_HASH, sizeof(TileHash)); new(hash_tmp) TileHash; +#if USE_MEMLIST + MemList *ml = smanager->createMemList(sizeof(Tile), MAX_TILE); + smanager->global_set(GLOBAL_TILE_LIST, (void *)ml); + +#else void *tileList_tmp = smanager->global_alloc(GLOBAL_TILE_LIST, sizeof(TileList)); new(tileList_tmp) TileList; - +#endif return 0; }
--- a/TaskManager/Test/test_render/task/Load_Texture.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/Load_Texture.h Fri Jul 31 17:52:27 2009 +0900 @@ -1,13 +1,8 @@ #ifndef INCLUDED_TASK_LOAD_TEXTURE #define INCLUDED_TASK_LOAD_TEXTURE -#ifndef INCLUDED_SCHED_TASK -#include "SchedTask.h" -#endif - -#ifndef INCLUDED_TAPESTRY -# include "Tapestry.h" -#endif +#include "SchedTask.h" +#include "Tapestry.h" class LoadTexture : public SchedTask { public:
--- a/TaskManager/Test/test_render/task/TileHash.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/TileHash.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -8,16 +8,16 @@ }; int -TileHash::hash(uint32 data) +TileHash::hash(memaddr data) { int value = 0; int n = 0; int key; - for (int i = 0; i < 8; i ++) { - key = data & 0xf; - value += key * PRIME[n++]; - data >>= 4; + for (unsigned int i = 0; i < sizeof(memaddr) * 2; i ++) { + key = data & 0xf; + value += key * PRIME[n++ & 7]; + data >>= 4; } return value % hashSize; @@ -33,51 +33,51 @@ } int -TileHash::put(uint32 *key, TilePtr data) +TileHash::put(memaddr key, TilePtr data) { - int hashval = hash((uint32)key); + int hashval = hash(key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; + int index = (hashval + i*i)%hashSize; - if (table[index] == 0) { // 空の table に入れる - table[index] = data; - return index; - } + if (table[index] == 0) { // 空の table に入れる + table[index] = data; + return index; + } } return -1; } TilePtr -TileHash::get(uint32 *key) +TileHash::get(memaddr key) { - int hashval = hash((uint32)key); + int hashval = hash(key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->address == key) { - return table[index]; - } + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + return table[index]; + } } return NULL; } void -TileHash::remove(uint32 *key) +TileHash::remove(memaddr key) { - int hashval = hash((uint32)key); + int hashval = hash(key); for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->address == key) { - table[index] = NULL; - } + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + table[index] = NULL; + } } }
--- a/TaskManager/Test/test_render/task/TileHash.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/task/TileHash.h Fri Jul 31 17:52:27 2009 +0900 @@ -16,10 +16,10 @@ public: void clear(void); - int hash(uint32 data); - int put(uint32 *addr, TilePtr tile); - TilePtr get(uint32 *addr); - void remove(uint32 *addr); + int hash(memaddr data); + int put(memaddr addr, TilePtr tile); + TilePtr get(memaddr addr); + void remove(memaddr addr); }; typedef TileHash* TileHashPtr;
--- a/TaskManager/Test/test_render/vacuum.cpp Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/Test/test_render/vacuum.cpp Fri Jul 31 17:52:27 2009 +0900 @@ -29,7 +29,7 @@ void vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { Pad *pad = sgroot->getController(); @@ -64,7 +64,7 @@ SceneGraphPtr near_enemy = NULL; float dx,dy,r,range = 100; // Pad *pad = sgroot->getController(); - + for(;it->hasNext(ENEMY);) { it->next(ENEMY); @@ -72,10 +72,10 @@ dx = enemy->xyz[0] - node->xyz[0]; dy = enemy->xyz[1] - node->xyz[1]; r = sqrt(dx*dx+dy*dy); - + if(range > r && enemy->stack_xyz[2] == 0) { - range = r; - near_enemy = enemy; + range = r; + near_enemy = enemy; } } @@ -83,7 +83,7 @@ if(near_enemy != NULL) { /*stack_xyz[2]をlockonフラグとして使うかな?*/ SceneGraphPtr lockon; - SceneGraphPtr near_enemy_common_move = near_enemy->parent; + // SceneGraphPtr near_enemy_common_move = near_enemy->parent; near_enemy->stack_xyz[2] = 1; lockon = sgroot->createSceneGraph(LOCK); lockon->set_move_collision(no_move_idle,lockon_collision); @@ -95,18 +95,18 @@ void lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) { - + Pad *pad = sgroot->getController(); SceneGraphPtr lockon_enemy = node->parent; /* node->angle[0] = -lockon_enemy->angle[0]; node->angle[1] = -lockon_enemy->angle[1]; node->angle[2] = -lockon_enemy->angle[2];*/ - + if(pad->circle.isRelease()) { lockon_enemy->remove(); } - + } @@ -114,7 +114,7 @@ vacuum_move(SceneGraphPtr node , int w, int h) { Pad *pad = sgroot->getController(); - + if (pad->right.isHold() && w > node->xyz[0]) { node->xyz[0] += vacuum_speed; node->angle[0] += 2; @@ -122,7 +122,7 @@ node->xyz[0] -= vacuum_speed; node->angle[0] -= 2; } - + if (pad->up.isHold() && 0 < node->xyz[1]) { node->xyz[1] -= vacuum_speed; node->angle[1] -= 2; @@ -130,7 +130,7 @@ node->xyz[1] += vacuum_speed; node->angle[1] += 2; } - + if (pad->start.isPush()) { node->xyz[0] = w/2; node->xyz[1] = h*0.8; @@ -145,14 +145,14 @@ { SceneGraphPtr object; SceneGraphPtr common_move; - + common_move = sgroot->createSceneGraph(); object = sgroot->createSceneGraph(id); object->xyz[0] = random()%w; object->xyz[1] = random()%h; object->set_move_collision(no_move_idle,cube_collision); //common_move->addChild(object); - root->addBrother(object); + root->addBrother(object); }
--- a/TaskManager/kernel/memory/MemList.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/memory/MemList.h Fri Jul 31 17:52:27 2009 +0900 @@ -4,22 +4,23 @@ #include <stdlib.h> #include "MemorySegment.h" -class MemList : MemorySegment { +class MemList : public MemorySegment { public: MemorySegment* pool; MemorySegment* first; MemorySegment* last; - + // TaskManager 側で create する //MemList* createMemList(uint32 size, uint32 count); + MemList(MemorySegment* ms) { - first = last = this; - next = prev = this; - pool = ms; + first = last = this; + next = prev = this; + pool = ms; } ~MemList() { - free(pool); + free(pool); } void addFirst(MemorySegment* e); @@ -28,7 +29,7 @@ MemorySegment* getLast(); int remove(MemorySegment* e); MemorySegment* poll(); - void moveToFirst(MemorySegment* e); // or use(); + void moveToFirst(MemorySegment* e); // or use(); MemorySegment* get(int index); };
--- a/TaskManager/kernel/ppe/TaskManager.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.cc Fri Jul 31 17:52:27 2009 +0900 @@ -86,26 +86,7 @@ return gen_random->getData(); } -/*! - @param [size] リストの要素1つのサイズ - @param [count] 要素数 - @return allocate した領域のポインタ - - */ -MemList* -TaskManager::createMemList(uint32 size, uint32 count) -{ - uint32 head_size = round_up16(sizeof(MemorySegment)); - uint32 seg_size = round_up16(head_size+size); - char* mseg = (char*)m_impl->allocate(seg_size*count); - MemList* mlist = new MemList((MemorySegment*)mseg); - - for(uint32 i = 0; i < count; i++) { - MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); - char* data = (char*)next+head_size; - next->data = (void*)data; - mlist->addLast(next); - } - - return mlist; +Scheduler* +TaskManager::get_scheduler() { + return m_impl->get_scheduler(); }
--- a/TaskManager/kernel/ppe/TaskManager.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.h Fri Jul 31 17:52:27 2009 +0900 @@ -4,6 +4,7 @@ #include "TaskManagerImpl.h" #include "Random.h" #include "MemList.h" +#include "Scheduler.h" class TaskManager { public: @@ -12,7 +13,7 @@ ~TaskManager(void); /* variables */ - TaskManagerImpl *m_impl; + TaskManagerImpl *m_impl; void (*tm_end)(void); RandomPtr gen_random; @@ -23,7 +24,7 @@ void set_TMend(void (*endf)(void)); int get_cpuNum(void); int get_random(void); - MemList* createMemList(uint32 size, uint32 count); + Scheduler *get_scheduler(); /* functions */ void init(void);
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Fri Jul 31 17:52:27 2009 +0900 @@ -77,9 +77,9 @@ // waiter // master // waitee // slave if (task->wait_i == NULL) { - append_activeTask(task); + append_activeTask(task); } else { - append_waitTask(task); + append_waitTask(task); } systask_finish->wait_for(task); @@ -132,14 +132,14 @@ TaskManagerImpl::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list) { TaskQueuePtr p; - HTaskPtr task; + HTaskPtr task; p = list; // wait task list while (p) { - task = (HTaskPtr)p->task; - task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend); - p = p->next; + task = (HTaskPtr)p->task; + task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend); + p = p->next; } remove_taskQueue_all(list); @@ -165,13 +165,13 @@ p = waitTaskQueue; while (p) { - HTaskPtr task = (HTaskPtr)p->task; - tmp = p; - p = p->next; - if (task->wait_i == NULL) { - append_activeTask(task); - waitTaskQueue = remove_taskQueue(waitTaskQueue, tmp); - } + HTaskPtr task = (HTaskPtr)p->task; + tmp = p; + p = p->next; + if (task->wait_i == NULL) { + append_activeTask(task); + waitTaskQueue = remove_taskQueue(waitTaskQueue, tmp); + } } } @@ -182,9 +182,9 @@ TaskQueuePtr p1; while (p != NULL) { - p1 = p->next; - bufferManager->free_taskQueue(p); - p = p1; + p1 = p->next; + bufferManager->free_taskQueue(p); + p = p1; } } @@ -198,25 +198,25 @@ { TaskQueuePtr p = list; TaskQueuePtr p1; - + if (p == NULL) return p; if (p->task == task) { - list = list->next; - bufferManager->free_taskQueue(p); + list = list->next; + bufferManager->free_taskQueue(p); } else { - p1 = p->next; - while (p1 && p1->task && p1->task != task) { - p1 = p1->next; - p = p->next; - } - if (p1) { - p->next = p1->next; - bufferManager->free_taskQueue(p1); - } + p1 = p->next; + while (p1 && p1->task && p1->task != task) { + p1 = p1->next; + p = p->next; + } + if (p1) { + p->next = p1->next; + bufferManager->free_taskQueue(p1); + } } - return list; + return list; } TaskQueuePtr @@ -228,18 +228,18 @@ if (!p) return p; if (p == q) { - list = list->next; - bufferManager->free_taskQueue(p); + list = list->next; + bufferManager->free_taskQueue(p); } else { - p1 = p->next; - while (p1 && p1 != q) { - p1 = p1->next; - p = p->next; - } - if (p1) { - p->next = p1->next; - bufferManager->free_taskQueue(p1); - } + p1 = p->next; + while (p1 && p1 != q) { + p1 = p1->next; + p = p->next; + } + if (p1) { + p->next = p1->next; + bufferManager->free_taskQueue(p1); + } } return list;
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Fri Jul 31 17:52:27 2009 +0900 @@ -4,6 +4,7 @@ #include "MailManager.h" #include "BufferManager.h" #include "ListData.h" +#include "Scheduler.h" class TaskManagerImpl { public: @@ -39,5 +40,6 @@ void spawn_task(HTaskPtr); void set_task_cpu(HTaskPtr, CPU_TYPE); virtual void* allocate(int size) = 0; + virtual Scheduler* get_scheduler() = 0; }; #endif
--- a/TaskManager/kernel/schedule/SchedTask.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Fri Jul 31 17:52:27 2009 +0900 @@ -1,7 +1,6 @@ #include <stdlib.h> #include <string.h> #include "SchedTask.h" -#include "SchedTask.h" #include "SchedTaskList.h" #include "SchedNop2Ready.h" #include "DmaManager.h" @@ -10,7 +9,7 @@ extern Scheduler::TaskObject task_list[MAX_TASK_OBJECT]; -//#define NO_PIPELINE +//#define NO_PIPELINE SchedTask * createSchedTask(TaskPtr task) @@ -18,7 +17,7 @@ return task_list[task->command](); } - + SchedTask::SchedTask() { __list = NULL; @@ -32,7 +31,7 @@ __renew_flag = 0; __cur_index = 0; __flag_renewTask = SCHED_TASK_NORMAL; - + ex_init = &SchedTask::ex_init_normal; ex_read = &SchedTask::ex_read_normal; ex_exec = &SchedTask::ex_exec_normal; @@ -40,7 +39,7 @@ ex_next = &SchedTask::ex_next_normal; run_func = &SchedTask::run; - run_func1 = &SchedTask::run; + run_func1 = &SchedTask::run; } /** @@ -53,24 +52,24 @@ SchedTask::~SchedTask(void) { if (__flag_renewTask == SCHED_TASK_RENEW) { - free(__inListData); + free(__inListData); free(__outListData); - - /** - * __list != NULL の場合、 - * この Task が __list の最後の Task になるので (SchedTask::next 参照) - * このタイミングで __list を解放する - * (free に渡されるアドレスが正しいものとなる)。 - * それ以外の Task では当然解放しない。 - * __list == NULL なので、free に渡しても無問題 - */ - free(__list); + + /** + * __list != NULL の場合、 + * この Task が __list の最後の Task になるので (SchedTask::next 参照) + * このタイミングで __list を解放する + * (free に渡されるアドレスが正しいものとなる)。 + * それ以外の Task では当然解放しない。 + * __list == NULL なので、free に渡しても無問題 + */ + free(__list); } } -/** +/** * このタスクを Renew Task とし、それに応じた関数をセットする */ void @@ -81,13 +80,13 @@ ex_init = &SchedTask::ex_init_renew; ex_read = &SchedTask::ex_read_renew; ex_exec = &SchedTask::ex_exec_renew; - ex_write = &SchedTask::ex_write_renew; + ex_write = &SchedTask::ex_write_renew; ex_next = &SchedTask::ex_next_renew; } void SchedTask::__init__(TaskListPtr _list, TaskPtr _task, int index, - ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc) + ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc) { __list = _list; __task = _task; @@ -110,14 +109,14 @@ SchedTask::ex_init_normal(void) { __scheduler->dma_load(__inListData, (uint32)__task->inData, - sizeof(ListData), DMA_READ_IN_LIST); + sizeof(ListData), DMA_READ_IN_LIST); __scheduler->dma_load(__outListData, (uint32)__task->outData, - sizeof(ListData), DMA_READ_OUT_LIST); + sizeof(ListData), DMA_READ_OUT_LIST); #if defined(NO_PIPELINE) __scheduler->dma_wait(DMA_READ_IN_LIST); __scheduler->dma_wait(DMA_READ_OUT_LIST); #endif - + __taskGroup = new TaskGroup; __taskGroup->command = __task->self; } @@ -132,7 +131,7 @@ { __inListData = __task->inData; __outListData = __task->outData; - __taskGroup = (TaskGroupPtr)__task->self; + __taskGroup = (TaskGroupPtr)__task->self; } /** @@ -146,7 +145,7 @@ */ void SchedTask::read(void) -{ +{ __debug("[SchedTask:%s]\n", __FUNCTION__); #if !defined(NO_PIPELINE) @@ -155,7 +154,7 @@ #endif __writebuf = __scheduler->allocate(__outListData->size); - + // 読むデータが一つもなければ無視 if (__inListData->length == 0) return; @@ -186,19 +185,19 @@ free(__readbuf); if (__taskGroup->status() != 0) { - __task->self = __taskGroup->command; - delete __taskGroup; - __taskGroup = NULL; + __task->self = __taskGroup->command; + delete __taskGroup; + __taskGroup = NULL; } // 書き込む領域がなければ無視 if (__outListData->length > 0) { - __scheduler->dma_storeList(__outListData, __writebuf, DMA_WRITE); + __scheduler->dma_storeList(__outListData, __writebuf, DMA_WRITE); #if defined(NO_PIPELINE) - __scheduler->dma_wait(DMA_WRITE); - free(__writebuf); + __scheduler->dma_wait(DMA_WRITE); + free(__writebuf); #endif } @@ -209,7 +208,7 @@ SchedTask::write(void) { __debug("[SchedTask:%s]\n", __FUNCTION__); - + #if !defined(NO_PIPELINE) __scheduler->dma_wait(DMA_WRITE); free(__writebuf); @@ -256,7 +255,7 @@ /** * PPE 内で生成されたタスクの ex_write() - * + * * このタスク内で新たにタスクが生成され、 * 且つそのタスクの終了を待つ必要がある場合、 * PPE に終了したことは知らせない(command は送信しない) @@ -269,7 +268,7 @@ * or 生成されたが、そのタスクの終了を待つ必要は無い */ if (__renew_flag == 0) { - __scheduler->mail_write(__task->self); + __scheduler->mail_write(__task->self); } } @@ -289,17 +288,17 @@ SchedTask::ex_write_renew(void) { uint32 cmd; - + __taskGroup->remove(__task); - cmd = __taskGroup->status(); + cmd = __taskGroup->status(); // タスク内で作られた全てのタスクが終了した if (cmd != 0) { - delete __taskGroup; - __scheduler->mail_write(cmd); + delete __taskGroup; + __scheduler->mail_write(cmd); } } - + SchedTaskBase* SchedTask::next(Scheduler *m, SchedTaskBase *p) { @@ -314,33 +313,33 @@ SchedTask::ex_next_normal(void) { if (__cur_index < __list->length) { - SchedTaskBase *nextSched; + SchedTaskBase *nextSched; + + nextSched = __scheduler->get_nextRenewTaskList(); - nextSched = __scheduler->get_nextRenewTaskList(); - - // RenewTask がある - if (nextSched) { - __scheduler->set_backupTaskList(__list); - __scheduler->set_backupTaskListIndex(__cur_index); - return nextSched; - } else { - TaskPtr nextTask = &__list->tasks[__cur_index++]; - nextSched = createSchedTask(nextTask); - ((SchedTask*)nextSched)->__init__(__list, nextTask, __cur_index, - __scheduler->get_curReadBuf(), - __scheduler->get_curWriteBuf(), - __scheduler); - return nextSched; - } + // RenewTask がある + if (nextSched) { + __scheduler->set_backupTaskList(__list); + __scheduler->set_backupTaskListIndex(__cur_index); + return nextSched; + } else { + TaskPtr nextTask = &__list->tasks[__cur_index++]; + nextSched = createSchedTask(nextTask); + ((SchedTask*)nextSched)->__init__(__list, nextTask, __cur_index, + __scheduler->get_curReadBuf(), + __scheduler->get_curWriteBuf(), + __scheduler); + return nextSched; + } } else { - uint32 nextList = (uint32)__list->next; - - if (nextList == 0) { - return new SchedNop2Ready(__scheduler); - } else { - return createSchedTaskList(nextList, __scheduler, - SCHED_TASKLIST_NORMAL); - } + uint32 nextList = (uint32)__list->next; + + if (nextList == 0) { + return new SchedNop2Ready(__scheduler); + } else { + return createSchedTaskList(nextList, __scheduler, + SCHED_TASKLIST_NORMAL); + } } } @@ -354,47 +353,47 @@ SchedTask *nextSched; if (__cur_index < __list->length) { - nextTask = &__list->tasks[__cur_index++]; - nextSched = createSchedTask(nextTask); + nextTask = &__list->tasks[__cur_index++]; + nextSched = createSchedTask(nextTask); - // RenewTaskList を実行中なので - nextSched->__setRenew(); - nextSched->__init__(__list, nextTask, __cur_index, - __scheduler->get_curReadBuf(), - __scheduler->get_curWriteBuf(), - __scheduler); + // RenewTaskList を実行中なので + nextSched->__setRenew(); + nextSched->__init__(__list, nextTask, __cur_index, + __scheduler->get_curReadBuf(), + __scheduler->get_curWriteBuf(), + __scheduler); - /** - * この理由は SchedTask:~SchedTask() で - */ - __list = NULL; - return nextSched; + /** + * この理由は SchedTask:~SchedTask() で + */ + __list = NULL; + return nextSched; } else { - SchedTaskBase *nextList; - - nextList = __scheduler->get_nextRenewTaskList(); - - if (nextList) { - return nextList; - } else { - TaskListPtr nextList = __scheduler->get_backupTaskList(); + SchedTaskBase *nextList; + + nextList = __scheduler->get_nextRenewTaskList(); + + if (nextList) { + return nextList; + } else { + TaskListPtr nextList = __scheduler->get_backupTaskList(); + + // 中断した TaskList がある + if (nextList) { + __cur_index = __scheduler->get_backupTaskListIndex(); - // 中断した TaskList がある - if (nextList) { - __cur_index = __scheduler->get_backupTaskListIndex(); - - nextTask = &nextList->tasks[__cur_index++]; - nextSched = createSchedTask(nextTask); - - nextSched->__init__(nextList, nextTask, __cur_index, - __scheduler->get_curReadBuf(), - __scheduler->get_curWriteBuf(), - __scheduler); - return nextSched; - } else { - return new SchedNop2Ready(__scheduler); - } - } + nextTask = &nextList->tasks[__cur_index++]; + nextSched = createSchedTask(nextTask); + + nextSched->__init__(nextList, nextTask, __cur_index, + __scheduler->get_curReadBuf(), + __scheduler->get_curWriteBuf(), + __scheduler); + return nextSched; + } else { + return new SchedNop2Ready(__scheduler); + } + } } } @@ -412,9 +411,9 @@ SchedTask::get_input(void *buff, int index) { if (buff != NULL) { - return (void*)((int)buff + __inListData->bound[index]); + return (void*)((int)buff + __inListData->bound[index]); } else { - return NULL; + return NULL; } } @@ -443,9 +442,9 @@ SchedTask::get_output(void *buff, int index) { if (buff != NULL) { - return (void*)((int)buff + __outListData->bound[index]); + return (void*)((int)buff + __outListData->bound[index]); } else { - return NULL; + return NULL; } } @@ -519,10 +518,20 @@ } void +SchedTask::global_set(int id, void *addr) { + __scheduler->global_set(id, addr); +} + +void SchedTask::global_free(int id) { __scheduler->global_free(id); } +MemList* +SchedTask::createMemList(int size, int count) { + return __scheduler->createMemList(size, count); +} + void SchedTask::mainMem_alloc(int id, int size) { __scheduler->mainMem_alloc(id, size);
--- a/TaskManager/kernel/schedule/SchedTask.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Fri Jul 31 17:52:27 2009 +0900 @@ -6,6 +6,7 @@ #include "SchedTaskBase.h" #include "ListData.h" #include "TaskGroup.h" +#include "MemList.h" class SchedTask : public SchedTaskBase { public: @@ -61,7 +62,7 @@ void (SchedTask::*ex_exec)(); void (SchedTask::*ex_write)(); SchedTaskBase* (SchedTask::*ex_next)(); - + /* functions */ // override @@ -80,7 +81,7 @@ //--- System API --- SchedTask* get_nextTask(TaskListPtr list); - + /** * PPE で生成されたタスクに対する * __init__, read,exec,write,next の付属(?)処理 @@ -106,7 +107,7 @@ void __setRenew(); void __init__(TaskListPtr _list, TaskPtr _task, int index, - ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc); + ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc); //--- User API --- int get_cpuid(); @@ -124,7 +125,9 @@ void* global_alloc(int id, int size); void* global_get(int id); + void global_set(int id, void *addr); void global_free(int id); + MemList* createMemList(int size, int count); void mainMem_alloc(int id, int size); void mainMem_wait(); @@ -136,7 +139,7 @@ void dma_store(void *buf,uint32 addr, uint32 size, uint32 mask); void dma_wait(uint32 mask); void show_dma_wait(); - + /*! SPU用の get_input, get_output */ @@ -144,10 +147,10 @@ void* get_input(int index) { return get_input(__readbuf, index); } - + void* get_output(int index) { return get_output(__writebuf, index); - } + } }; const int SCHED_TASK_NORMAL = 0;
--- a/TaskManager/kernel/schedule/Scheduler.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Fri Jul 31 17:52:27 2009 +0900 @@ -25,11 +25,11 @@ init_impl(); for (int i = 0; i < 2; i++) { - buff_taskList[i] = (TaskListPtr)allocate(sizeof(TaskList)); - buff_inListData[i] = (ListDataPtr)allocate(sizeof(ListData)); - buff_outListData[i] = (ListDataPtr)allocate(sizeof(ListData)); + buff_taskList[i] = (TaskListPtr)allocate(sizeof(TaskList)); + buff_inListData[i] = (ListDataPtr)allocate(sizeof(ListData)); + buff_outListData[i] = (ListDataPtr)allocate(sizeof(ListData)); } - + buffFlag_taskList = 0; buffFlag_inListData = 0; buffFlag_outListData = 0; @@ -37,13 +37,13 @@ // bzero でもいいけど for (int i = 0; i < MAX_GLOBAL_AREA; i++) { - globalList[i] = NULL; + globalList[i] = NULL; } for (int i = 0; i < MAX_MAINMEM_AREA; i++) { - mainMemList[i] = NULL; + mainMemList[i] = NULL; } - + taskGroup = new TaskGroup; renewTop_taskList = NULL; @@ -61,15 +61,15 @@ // main loop do { - __debug("----------\n"); - task3->write(); - task2->exec(); - task1->read(); + __debug("----------\n"); + task3->write(); + task2->exec(); + task1->read(); - taskTmp = task3; - task3 = task2; - task2 = task1; - task1 = task1->next(this, taskTmp); + taskTmp = task3; + task3 = task2; + task2 = task1; + task1 = task1->next(this, taskTmp); } while (task1); delete task3; @@ -133,14 +133,14 @@ Scheduler::get_renewListBuf(void) { if (renewCur_taskList && renewCur_taskList->length < TASK_MAX_SIZE) { - return renewCur_taskList; + return renewCur_taskList; } else { - TaskListPtr newList = (TaskListPtr)allocate(sizeof(TaskList)); - newList->length = 0; - newList->next = NULL; - renewTop_taskList = TaskList::append(renewTop_taskList, newList); - renewCur_taskList = newList; - return newList; + TaskListPtr newList = (TaskListPtr)allocate(sizeof(TaskList)); + newList->length = 0; + newList->next = NULL; + renewTop_taskList = TaskList::append(renewTop_taskList, newList); + renewCur_taskList = newList; + return newList; } } @@ -156,16 +156,16 @@ Scheduler::get_nextRenewTaskList(void) { if (renewTop_taskList) { - TaskListPtr list = renewTop_taskList; - renewTop_taskList = renewTop_taskList->next; - renewCur_taskList = NULL; + TaskListPtr list = renewTop_taskList; + renewTop_taskList = renewTop_taskList->next; + renewCur_taskList = NULL; - list->next = NULL; - SchedTaskList *sched - = createSchedTaskList((uint32)list, this, SCHED_TASKLIST_RENEW); - return sched; + list->next = NULL; + SchedTaskList *sched + = createSchedTaskList((uint32)list, this, SCHED_TASKLIST_RENEW); + return sched; } else { - return NULL; + return NULL; } } @@ -191,7 +191,7 @@ Scheduler::get_backupTaskList(void) { TaskListPtr ret = bak_curTaskList; - + bak_curTaskList = NULL; return ret; } @@ -297,6 +297,12 @@ } void +Scheduler::global_set(int id, void *addr) +{ + globalList[id] = addr; +} + +void Scheduler::global_free(int id) { free(globalList[id]); @@ -323,3 +329,27 @@ { task_list[cmd] = task; } + +/*! + @param [size] リストの要素1つのサイズ + @param [count] 要素数 + @return allocate した領域のポインタ + + */ +MemList* +Scheduler::createMemList(int size, int count) +{ + uint32 head_size = round_up16(sizeof(MemorySegment)); + uint32 seg_size = round_up16(head_size+size); + char* mseg = (char*)allocate(seg_size*count); + MemList* mlist = new MemList((MemorySegment*)mseg); + + for(int i = 0; i < count; i++) { + MemorySegment* next = (MemorySegment*)(mseg+seg_size*i); + char* data = (char*)next+head_size; + next->data = (void*)data; + mlist->addLast(next); + } + + return mlist; +}
--- a/TaskManager/kernel/schedule/Scheduler.h Fri Jul 31 01:44:06 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Fri Jul 31 17:52:27 2009 +0900 @@ -8,7 +8,7 @@ #include "SchedTaskBase.h" #include "SchedTaskList.h" #include "TaskGroup.h" - +#include "MemList.h" #define MAX_USER_TASK 32 #define MAX_SYSTEM_TASK 2 @@ -42,7 +42,7 @@ /** * 実行中 TaskList の現在の位置 (list->tasks[index]) - * + * * bakIndex_taskList がある理由 * taskList の途中で renew task が作られたとき、 * 即座に実行するため、TaskList -> RenewTaskList と移って処理する。 @@ -53,7 +53,7 @@ */ int bakIndex_taskList; TaskListPtr bak_curTaskList; - + /** * タスク内で生成されたタスクを入れる @@ -126,8 +126,9 @@ /* GlobalMemory */ void* global_alloc(int id, int size); void* global_get(int id); + void global_set(int id, void *addr); void global_free(int id); - + MemList* createMemList(int size, int count); virtual void *allocate(int size) { return NULL; }; virtual void mainMem_alloc(int id, int size) {}; @@ -150,19 +151,19 @@ #endif -#define SchedConstructor(str) \ - str(void) {} \ - BASE_NEW_DELETE(str) \ +#define SchedConstructor(str) \ + str(void) {} \ + BASE_NEW_DELETE(str) \ -#define SchedDefineTask(str) \ - SchedTask* createTask_##str(void) \ - { \ - return new str(); \ +#define SchedDefineTask(str) \ + SchedTask* createTask_##str(void) \ + { \ + return new str(); \ } -#define SchedExternTask(str) \ - extern \ +#define SchedExternTask(str) \ + extern \ SchedTask* createTask_##str(void); -#define SchedRegisterTask(cmd, str) \ +#define SchedRegisterTask(cmd, str) \ register_task(cmd, createTask_##str);
--- a/example/MemList/Makefile.cell Fri Jul 31 01:44:06 2009 +0900 +++ b/example/MemList/Makefile.cell Fri Jul 31 17:52:27 2009 +0900 @@ -38,5 +38,3 @@ clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#* - rm -f ppe/*~ ppe/\#* - cd spe; $(MAKE) clean
--- a/example/MemList/Makefile.linux Fri Jul 31 01:44:06 2009 +0900 +++ b/example/MemList/Makefile.linux Fri Jul 31 17:52:27 2009 +0900 @@ -32,5 +32,3 @@ clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#* - rm -f ppe/*~ ppe/\#* - rm -f spe/*~ spe/\#*
--- a/example/MemList/Makefile.macosx Fri Jul 31 01:44:06 2009 +0900 +++ b/example/MemList/Makefile.macosx Fri Jul 31 17:52:27 2009 +0900 @@ -1,13 +1,13 @@ include ./Makefile.def SRCS_TMP = $(wildcard *.cc) -SRCS_EXCLUDE = # ե +SRCS_EXCLUDE = SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) OBJS = $(SRCS:.cc=.o) TASK_DIR = ppe TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) -TASK_SRCS_EXCLUDE = +TASK_SRCS_EXCLUDE = TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) TASK_OBJS = $(TASK_SRCS:.cc=.o) @@ -18,10 +18,10 @@ .cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -all: $(TARGET) +all: $(TARGET) -#MemList.o: ${CERIUM}/kernel/memory/MemList.cc - +#MemList.o: ${CERIUM}/kernel/memory/MemList.cc + $(TARGET): $(OBJS) $(TASK_OBJS) $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) @@ -30,10 +30,8 @@ $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) debug: $(TARGET) - sudo gdb ./$(TARGET) + sudo gdb ./$(TARGET) clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#* - rm -f ppe/*~ ppe/\#* - rm -f spe/*~ spe/\#*
--- a/example/MemList/main.cc Fri Jul 31 01:44:06 2009 +0900 +++ b/example/MemList/main.cc Fri Jul 31 17:52:27 2009 +0900 @@ -13,7 +13,7 @@ extern TaskManager *manager; const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\ - -cpu Number of SPE (default 1) \n \ + -cpu Number of SPE (default 1) \n \ -count Number of task is print \"Hello, World!!\""; void @@ -22,33 +22,33 @@ /*! active からランダムに要素を取り出してそこの size の領域を書き潰す そこを moveToFirst を繰り返すテスト - */ + */ for (uint32 i = 0; i < count; i++) { - int index = manager->get_random()%count; - MemorySegment* e = active->get(index); - active->moveToFirst(e); - bzero(e->data, size); + int index = manager->get_random()%count; + MemorySegment* e = active->get(index); + active->moveToFirst(e); + bzero(e->data, size); } - printf("test1\n"); + printf("test1\n"); } int TMmain(int argc, char *argv[]) { uint32 size = 128; - uint32 count = 64; - - MemList* active = manager->createMemList(size, 0); - MemList* freelist = manager->createMemList(size, count); - + uint32 count = 64; + + MemList* active = manager->get_scheduler()->createMemList(size, 0); + MemList* freelist = manager->get_scheduler()->createMemList(size, count); + // 配列! uint32 i = 0; for (;; i++) { - MemorySegment* m = freelist->poll(); - if (m == 0) { - break; - } - active->addFirst(m); + MemorySegment* m = freelist->poll(); + if (m == 0) { + break; + } + active->addFirst(m); } assert(i==count); @@ -57,6 +57,6 @@ test1(active, freelist, size, count); delete active; delete freelist; - + return 0; }