Mercurial > hg > Game > Cerium
changeset 672:27fec8c70c9c draft
add profiling code
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h Sat Dec 05 17:26:58 2009 +0900 +++ b/Renderer/Engine/RenderingTasks.h Sat Dec 05 20:20:08 2009 +0900 @@ -22,7 +22,6 @@ UpdateKey, InitKey, - ShowTime, Switch, ChainMove,
--- a/Renderer/Engine/spe/ShowTime.cc Sat Dec 05 17:26:58 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#include "ShowTime.h" -#include "stdio.h" - -SchedDefineTask(ShowTime); - -static int -run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - /* - * ここで show_dma_wait() を呼びたい - */ - smanager->show_dma_wait(); - //printf("Show Time !\n"); - - return 0; -} -
--- a/Renderer/Engine/spe/ShowTime.h Sat Dec 05 17:26:58 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef INCLUDED_TASK_SHOW_TIME -#define INCLUDED_TASK_SHOW_TIME - -#include "SchedTask.h" - - -#endif
--- a/Renderer/Engine/task/ShowTime.cc Sat Dec 05 17:26:58 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#include "ShowTime.h" -#include "stdio.h" - -SchedDefineTask(ShowTime); - -static int -run(SchedTask *s,void *rbuf, void *wbuf) -{ - /* - * ここで show_dma_wait() を呼びたい - */ - //printf("Show Time !\n"); - - return 0; -} -
--- a/Renderer/Engine/task/ShowTime.h Sat Dec 05 17:26:58 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef INCLUDED_TASK_SHOW_TIME -#define INCLUDED_TASK_SHOW_TIME - -#include "SchedTask.h" - - -#endif
--- a/TaskManager/Cell/CellTaskManagerImpl.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.cc Sat Dec 05 20:20:08 2009 +0900 @@ -9,6 +9,8 @@ #include "SchedTask.h" #include "MainScheduler.h" #include "types.h" +#include "SysFunc.h" + CellTaskManagerImpl::~CellTaskManagerImpl() { @@ -285,6 +287,22 @@ flag_sendTaskList[id] = 0; } +void CellTaskManagerImpl::show_profile() { + for (int id = 0; id < machineNum; id++) { + HTaskPtr t = create_task(ShowTime); + t->set_cpu((CPU_TYPE)(id+2)); + t->spawn(); + } +} + +void CellTaskManagerImpl::start_profile() { + for (int id = 0; id < machineNum; id++) { + HTaskPtr t = create_task(StartProfile); + t->set_cpu((CPU_TYPE)(id+2)); + t->spawn(); + } +} + #ifdef __CERIUM_CELL__ TaskManagerImpl*
--- a/TaskManager/Cell/CellTaskManagerImpl.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.h Sat Dec 05 20:20:08 2009 +0900 @@ -27,9 +27,11 @@ TaskListPtr mail_check(HTaskInfo *); void set_runTaskList(); void append_activeTask(HTaskPtr); + void show_profile() ; + void start_profile() ; // user - int add_data(ListDataPtr, uint32, int); + // int add_data(ListDataPtr, uint32, int); #if 0 void* allocate(int size); void* allocate(int size,int align);
--- a/TaskManager/Cell/spe/CellDmaManager.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/spe/CellDmaManager.cc Sat Dec 05 20:20:08 2009 +0900 @@ -2,6 +2,8 @@ #include <stdlib.h> #include "CellDmaManager.h" + + /** * DMA Load * @@ -10,8 +12,7 @@ * @param[in] size Size of Load Data * @param[in] mask DMA tag */ -void -CellDmaManager::dma_load(void *buf, memaddr addr, uint32 size, uint32 mask) +void CellDmaManager::dma_load(void *buf, memaddr addr, uint32 size, uint32 mask) { if (size == 0) return ; mfc_get((volatile void *)buf, addr, size, mask, 0, 0); @@ -25,20 +26,82 @@ * @param[in] size Size of Store Data * @param[in] mask DMA tag */ -void -CellDmaManager::dma_store(void *buf, memaddr addr, uint32 size, uint32 mask) +void CellDmaManager::dma_store(void *buf, memaddr addr, uint32 size, uint32 mask) { if (size == 0) return ; mfc_put((volatile void *)buf, addr, size, mask, 0, 0); } +void CellDmaManager::dma_wait(uint32 mask) +{ + (this->*start_dmawait_profile)(); + mfc_write_tag_mask(1 << mask); + mfc_write_tag_update_all(); + mfc_read_tag_status(); + (this->*end_dmawait_profile)(); +} + +void CellDmaManager::mail_write(memaddr data) +{ + (this->*start_dmawait_profile)(); + spu_write_out_mbox((uint32)data); + if (ABIBIT>32) { + unsigned long data0 = (unsigned long)data; + spu_write_out_mbox((uint32)(data0>>4)); + } + (this->*end_dmawait_profile)(); +} + +memaddr CellDmaManager::mail_read() +{ + (this->*start_dmawait_profile)(); + memaddr data = (memaddr)spu_read_in_mbox(); + if (ABIBIT>32) { + data += (spu_read_in_mbox()<<4); + } + (this->*end_dmawait_profile)(); + return data; +} + +void CellDmaManager::dma_loadList(ListDataPtr list, void *buff, uint32 mask) +{ + mfc_getl(buff, 0, list->element, sizeof(mfc_list_element_t)*list->length, + mask, 0, 0); +} + +void CellDmaManager::dma_storeList(ListDataPtr list, void *buff, uint32 mask) +{ + mfc_putl(buff, 0, list->element, sizeof(mfc_list_element_t)*list->length, + mask, 0, 0); +} + + +CellDmaManager::CellDmaManager() +{ + stop_profile(); +} + +void +CellDmaManager::start_profile() +{ + start_dmawait_profile = &CellDmaManager::do_start_dmawait_profile; + end_dmawait_profile = &CellDmaManager::do_end_dmawait_profile; +} + +void +CellDmaManager::stop_profile() +{ + start_dmawait_profile = &CellDmaManager::null_start_dmawait_profile; + end_dmawait_profile = &CellDmaManager::null_end_dmawait_profile; +} + /** * DMA Wait * * @param[in] mask Tag for Wait DMA process */ void -CellDmaManager::start_dmawait_profile() +CellDmaManager::do_start_dmawait_profile() { wait_time = spu_readch(SPU_RdDec); global_busy_time += busy_time - wait_time; @@ -46,13 +109,16 @@ } void -CellDmaManager::end_dmawait_profile() +CellDmaManager::do_end_dmawait_profile() { wait_time = spu_readch(SPU_RdDec); global_wait_time += 0xffffffff - wait_time; busy_time = wait_time; } +void CellDmaManager::null_start_dmawait_profile() {} +void CellDmaManager::null_end_dmawait_profile() {} + void CellDmaManager::show_dma_wait(int cpu) { @@ -63,52 +129,5 @@ ((double)global_busy_time)/((double)(global_busy_time+global_wait_time))*100.0); } -void -CellDmaManager::dma_wait(uint32 mask) -{ -#ifdef SPU_PROFILE - start_dmawait_profile(); -#endif - mfc_write_tag_mask(1 << mask); - mfc_write_tag_update_all(); - mfc_read_tag_status(); -#ifdef SPU_PROFILE - end_dmawait_profile(); -#endif -} - -void -CellDmaManager::mail_write(memaddr data) -{ - spu_write_out_mbox((uint32)data); - if (ABIBIT>32) { - unsigned long data0 = (unsigned long)data; - spu_write_out_mbox((uint32)(data0>>4)); - } -} - -memaddr -CellDmaManager::mail_read() -{ - memaddr data = (memaddr)spu_read_in_mbox(); - if (ABIBIT>32) { - data += (spu_read_in_mbox()<<4); - } - return data; -} - -void -CellDmaManager::dma_loadList(ListDataPtr list, void *buff, uint32 mask) -{ - mfc_getl(buff, 0, list->element, sizeof(mfc_list_element_t)*list->length, - mask, 0, 0); -} - -void -CellDmaManager::dma_storeList(ListDataPtr list, void *buff, uint32 mask) -{ - mfc_putl(buff, 0, list->element, sizeof(mfc_list_element_t)*list->length, - mask, 0, 0); -} /* end */
--- a/TaskManager/Cell/spe/CellDmaManager.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/spe/CellDmaManager.h Sat Dec 05 20:20:08 2009 +0900 @@ -18,6 +18,9 @@ uint32 size; } DmaList, *DmaListPtr; + + CellDmaManager() ; + /* variables */ unsigned int wait_time, busy_time; unsigned long long global_busy_time, global_wait_time; @@ -26,14 +29,28 @@ void dma_load(void *buf, memaddr addr, uint32 size, uint32 mask); void dma_store(void *buf, memaddr addr, uint32 size, uint32 mask); void dma_wait(uint32 mask) ; - void start_dmawait_profile(); - void end_dmawait_profile(); + void (CellDmaManager::*start_dmawait_profile)(); + void (CellDmaManager::*end_dmawait_profile)(); + void start_profile(); + void stop_profile(); + + void show_dma_wait(int cpu); void mail_write(memaddr data); memaddr mail_read(); void dma_loadList(ListDataPtr list, void *buff, uint32 mask); void dma_storeList(ListDataPtr, void *buff, uint32 mask); + + private: + + void do_start_dmawait_profile(); + void do_end_dmawait_profile(); + void null_start_dmawait_profile(); + void null_end_dmawait_profile(); + + +/* end */ }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Cell/spe/ShowTime.cc Sat Dec 05 20:20:08 2009 +0900 @@ -0,0 +1,18 @@ +#include "ShowTime.h" +#include "stdio.h" +#include "SchedTask.h" + +SchedDefineTask(ShowTime); + +static int +run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + /* + * ここで show_dma_wait() を呼びたい + */ + smanager->show_dma_wait(); + //printf("Show Time !\n"); + + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Cell/spe/ShowTime.h Sat Dec 05 20:20:08 2009 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_SHOW_TIME +#define INCLUDED_TASK_SHOW_TIME + +#include "SchedTask.h" + + +#endif
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.cc Sat Dec 05 20:20:08 2009 +0900 @@ -14,10 +14,16 @@ void SpeTaskManagerImpl::spawn_task(HTaskPtr) {} void SpeTaskManagerImpl::set_task_cpu(HTaskPtr, CPU_TYPE) {} +void SpeTaskManagerImpl::show_profile() {} +void SpeTaskManagerImpl::start_profile() {} + +// Odd + TaskManagerImpl::TaskManagerImpl(int i) {} void TaskManagerImpl::append_activeTask(HTask* p) {} void TaskManagerImpl::append_waitTask(HTask* p) {} + HTaskPtr TaskManagerImpl::create_task(int cmd) {return 0;} HTaskPtr TaskManagerImpl::create_task(int cmd, memaddr rbuf, long rs, memaddr wbuf, long ws) { return 0; } void TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave) {}
--- a/TaskManager/Cell/spe/SpeTaskManagerImpl.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/spe/SpeTaskManagerImpl.h Sat Dec 05 20:20:08 2009 +0900 @@ -17,6 +17,8 @@ // call by system void init(); void run(); + void start_profile(); + void show_profile(); HTaskPtr create_task(int cmd); HTaskPtr create_task(int cmd, memaddr rbuf, long r_size, memaddr wbuf, long w_size); void set_task_depend(HTaskPtr master, HTaskPtr slave);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Cell/spe/StartProfile.cc Sat Dec 05 20:20:08 2009 +0900 @@ -0,0 +1,14 @@ +#include "StartProfile.h" +#include "SchedTask.h" +#include "stdio.h" + +SchedDefineTask(StartProfile); + +static int +run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + smanager->start_profile(); + + return 0; +} +
--- a/TaskManager/Cell/spe/main.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Cell/spe/main.cc Sat Dec 05 20:20:08 2009 +0900 @@ -3,9 +3,14 @@ #include "SpeTaskManagerImpl.h" #include "spu_mfcio.h" #include "error.h" +#include "SysFunc.h" extern unsigned char _end[]; +SchedExternTask(ShowTime); +SchedExternTask(StartProfile); + + int main(unsigned long long speid, unsigned long long argc, unsigned long long argv) @@ -22,19 +27,16 @@ TaskManagerImpl *tm = new SpeTaskManagerImpl(); + SchedRegister(ShowTime); + SchedRegister(StartProfile); + manager = new CellScheduler(); manager->init(tm); manager->id = (int)argc; tm->set_scheduler(manager); - spu_write_decrementer(0x7FFFFFFFU); - unsigned int prof = spu_read_decrementer(); manager->run(); - - prof -= spu_read_decrementer(); - - //printf("%f\n", prof/79800000.0f*1000.0f); manager->finish();
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Sat Dec 05 20:20:08 2009 +0900 @@ -65,6 +65,9 @@ } +void FifoTaskManagerImpl::show_profile() {} +void FifoTaskManagerImpl::start_profile() {} + /** * スケジューラに渡す TaskList を取得する。 *
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Sat Dec 05 20:20:08 2009 +0900 @@ -23,6 +23,9 @@ void init(void); void init(MainScheduler*, TaskManagerImpl*); void run(void); + void show_profile() ; + void start_profile() ; + void mail_check(); void mail_check(HTaskInfo *waitQueue);
--- a/TaskManager/Makefile.cell Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/Makefile.cell Sat Dec 05 20:20:08 2009 +0900 @@ -21,6 +21,8 @@ $(CELL_SPE_DIR)/CellDmaManager.cc \ $(CELL_SPE_DIR)/CellScheduler.cc \ $(CELL_SPE_DIR)/SpeTaskManagerImpl.cc \ + $(CELL_SPE_DIR)/ShowTime.cc \ + $(CELL_SPE_DIR)/StartProfile.cc \ $(CELL_SPE_DIR)/main.cc CELL_SPE_TASK_SRCS = \
--- a/TaskManager/kernel/ppe/TaskManager.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.h Sat Dec 05 20:20:08 2009 +0900 @@ -29,6 +29,9 @@ Scheduler *get_scheduler(); MemList* createMemList(int size, int count); + void start_profile() { m_impl->start_profile(); } + void show_profile() { m_impl->show_profile(); } + /* functions */ void init(); void finish();
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Sat Dec 05 20:20:08 2009 +0900 @@ -34,6 +34,8 @@ // system virtual void init() = 0; virtual void run() = 0; + virtual void start_profile() = 0; + virtual void show_profile() = 0; virtual void append_activeTask(HTaskPtr); virtual void append_waitTask(HTaskPtr);
--- a/TaskManager/kernel/schedule/DmaManager.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/schedule/DmaManager.h Sat Dec 05 20:20:08 2009 +0900 @@ -24,6 +24,7 @@ virtual void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask) {} virtual void dma_wait(uint32 mask) {} virtual void show_dma_wait(int cpu) {} + virtual void start_profile() {} // API for SPU inbound/outbound mailbox virtual void mail_write(memaddr data) {}
--- a/TaskManager/kernel/schedule/SchedTask.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Sat Dec 05 20:20:08 2009 +0900 @@ -321,6 +321,11 @@ scheduler->show_dma_wait(); } +void +SchedTask::start_profile() { + scheduler->start_profile(); +} + MemorySegment * SchedTask::get_segment(memaddr addr, MemList *m) { return scheduler->get_segment(addr,m); }
--- a/TaskManager/kernel/schedule/SchedTask.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Sat Dec 05 20:20:08 2009 +0900 @@ -118,6 +118,7 @@ void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask); void dma_wait(uint32 mask); void show_dma_wait(); + void start_profile(); /*! SPU用の get_input, get_output @@ -142,6 +143,7 @@ void* allocate(int size,int align); Scheduler* get_scheduler(); + /* system call */ FILE *stdout_;
--- a/TaskManager/kernel/schedule/Scheduler.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.h Sat Dec 05 20:20:08 2009 +0900 @@ -118,7 +118,7 @@ void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask); void dma_wait(uint32 mask); void show_dma_wait() { connector->show_dma_wait(id); }; - void show_dma_wait(int id) { connector->show_dma_wait(id); }; + void start_profile() { connector->start_profile(); }; void mail_write(memaddr data); memaddr mail_read(); void dma_loadList(ListDataPtr list, void *, uint32 mask);
--- a/TaskManager/kernel/sys_task/SysTasks.h Sat Dec 05 17:26:58 2009 +0900 +++ b/TaskManager/kernel/sys_task/SysTasks.h Sat Dec 05 20:20:08 2009 +0900 @@ -1,2 +1,4 @@ StartTask, FinishTask, +ShowTime, +StartProfile,
--- a/example/word_count_test/main.cc Sat Dec 05 17:26:58 2009 +0900 +++ b/example/word_count_test/main.cc Sat Dec 05 20:20:08 2009 +0900 @@ -132,6 +132,7 @@ static int blocks = 48; static int division = 16; // in Kbyte +static int profile = 0; static void run_start(TaskManager *manager, char *filename) @@ -192,6 +193,10 @@ /*各SPEの結果を合計して出力するタスク*/ + if (profile) { + manager->start_profile(); + } + #ifdef SIMPLE_TASK t_print = manager->create_task(TASK_PRINT, (memaddr)&w->self,sizeof(memaddr),0,0); @@ -237,6 +242,8 @@ division = atoi(argv[i+1]); } else if (strcmp(argv[i], "-block") == 0) { blocks = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-p") == 0) { + profile = 1; } } if (filename==0) { @@ -247,6 +254,12 @@ return filename; } +static void +myTMend(TaskManager *manager) +{ + manager->show_profile(); +} + int TMmain(TaskManager *manager, int argc, char *argv[]) { @@ -257,6 +270,7 @@ if (filename < 0) { return -1; } + manager->set_TMend(myTMend); task_init(); run_start(manager, filename);