# HG changeset patch # User gongo # Date 1203239213 -32400 # Node ID 519d24aa7ac837ab64f122e62874bead005f5e8e # Parent eb2cb212881c8abf63a10ac26bd0d5d36682d674 *** empty log message *** diff -r eb2cb212881c -r 519d24aa7ac8 TaskManager/Cell/CellBufferManager.cc --- a/TaskManager/Cell/CellBufferManager.cc Sun Feb 17 11:19:25 2008 +0900 +++ b/TaskManager/Cell/CellBufferManager.cc Sun Feb 17 18:06:53 2008 +0900 @@ -6,7 +6,7 @@ void CellBufferManager::init(void) { - BufferManager::init(void); + BufferManager::init(); cellTaskListImpl = new CellTaskListInfo; machineTaskList = new TaskListPtr[machineNum]; @@ -16,16 +16,24 @@ } } -#if 0 // 継承するかもしれないので保存 +/** + * task の cpu type によって + * それぞれの cpu に対応する active queue に task を追加する。 + */ void CellBufferManager::append_activeTask(HTaskPtr task) { TaskQueuePtr q; q = taskQueueImpl->create(task); - activeTaskQueue = taskQueueImpl->append(activeTaskQueue, q); + if (task->cpu_type == CPU_PPE) { + activeTaskQueue = TaskQueueInfo::append(activeTaskQueue, q); + } else { + speActiveTaskQueue = TaskQueueInfo::append(speActiveTaskQueue, q); + } } +#if 0 // 継承するかもしれないので保存 void CellBufferManager::append_waitTask(HTaskPtr task) { diff -r eb2cb212881c -r 519d24aa7ac8 TaskManager/Cell/CellTaskManagerImpl.cc --- a/TaskManager/Cell/CellTaskManagerImpl.cc Sun Feb 17 11:19:25 2008 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.cc Sun Feb 17 18:06:53 2008 +0900 @@ -4,6 +4,7 @@ #include "CellTaskManagerImpl.h" #include "CellBufferManager.h" #include "types.h" +#include "error.h" void CellTaskManagerImpl::init(void) @@ -12,15 +13,39 @@ bufferManager = new CellBufferManager(); bufferManager->init(); + + speThreads = new SpeThreads(machineNum); + speThreads->init(); } -void -CellTaskManagerImpl::spawn_task(HTaskPtr task) +/** + * mail_list は ppe 側の mail なので、変更せず渡す。 + * その前に spe からのメールをチェックする + */ +MailQueuePtr +CellTaskManagerImpl::mail_check(MailQueuePtr mail_list) { - TaskManagerImpl::spawn_task(task); - //run(); + int id; + int data; + + for (id = 0; id < machineNum; id++) { + while (1) { + data = speThreads->get_mail(id); + if (data < 0) break; + + // 名前あとでちゃんと決めよう => MY_SPE_... とかじゃなくて + if (data == MY_SPE_STATUS_READY) { + __debug_ppe("[SPE %d] finish\n", id); + } else { + __debug_ppe("[PPE] recv from [SPE %d] : 0x%x\n", data, id); + bufferManager->check_task_finish((HTaskPtr)data); + } + } + } + return TaskManagerImpl::mail_check(mail_list); } + TaskManagerImpl* create_impl(int num) { diff -r eb2cb212881c -r 519d24aa7ac8 TaskManager/Cell/SpeThreads.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Cell/SpeThreads.cc Sun Feb 17 18:06:53 2008 +0900 @@ -0,0 +1,61 @@ +#include "SpeThreads.h" + +SpeThreads::SpeThreads(int num) : spe_num(num) {} + +void* +SpeThreads::spe_thread_run(void *arg) +{ + unsigned int entry = SPE_DEFAULT_ENTRY; + spe_context_ptr_t ctx = (spe_context_ptr_t)arg; + + spe_context_run(ctx, &entry, 0, NULL, NULL, NULL); + + pthread_exit(NULL); +} + +void* +SpeThreads::frontend_thread_run(void *arg) +{ + pthread_t thread; + thread_arg_t *arg_t = (thread_arg_t *)arg; + + pthread_create(&thread, NULL, &spe_thread_run, (void*)arg_t->ctx); + + pthread_exit(NULL); +} + +void +SpeThreads::init(void) +{ + int i; + + spe_handle = spe_image_open(SPE_ELF); + + spe_ctx = new spe_context_ptr_t[spe_num]; + threads = new pthread_t[spe_num]; + args = new thread_arg_t[spe_num]; + + for (i = 0; i < spe_num; i++) { + args[i].speid = i; + spe_ctx[i] = spe_context_create(0, NULL); + spe_program_load(spe_ctx[i], spe_handle); + args[i].ctx = spe_ctx[i]; + } + + for (i = 0; i < spe_num; i++) { + pthread_create(&threads[i], NULL, + &frontend_thread_run, (void*)&args[i]); + } +} + +int +SpeThreads::get_mail(int speid) +{ + unsigned int ret; + + if (spe_out_mbox_read(spe_ctx[speid], &ret, 1) > 0) { + return (int)ret; + } else { + return -1; + } +} diff -r eb2cb212881c -r 519d24aa7ac8 TaskManager/kernel/ppe/HTaskInfo.cc --- a/TaskManager/kernel/ppe/HTaskInfo.cc Sun Feb 17 11:19:25 2008 +0900 +++ b/TaskManager/kernel/ppe/HTaskInfo.cc Sun Feb 17 18:06:53 2008 +0900 @@ -64,6 +64,7 @@ q->wait_i = NULL; q->post_func = NULL; q->mimpl = NULL; + q->cpu_type = CPU_PPE; return q; } @@ -109,3 +110,9 @@ { mimpl->set_task_depend(master, this); } + +void +HTask::set_cpu(CPU_TYPE type) +{ + mimpl->set_task_cpu(this, type); +} diff -r eb2cb212881c -r 519d24aa7ac8 TaskManager/kernel/ppe/TaskManagerImpl.cc --- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Feb 17 11:19:25 2008 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Feb 17 18:06:53 2008 +0900 @@ -73,6 +73,12 @@ } } +void +TaskManagerImpl::set_task_cpu(HTaskPtr task, CPU_TYPE type) +{ + task->cpu_type = type; +} + TaskListPtr TaskManagerImpl::set_task(void) { diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/CellBufferManager.h --- a/include/TaskManager/CellBufferManager.h Sun Feb 17 11:19:25 2008 +0900 +++ b/include/TaskManager/CellBufferManager.h Sun Feb 17 18:06:53 2008 +0900 @@ -5,16 +5,23 @@ # include "BufferManager.h" #endif +#ifndef INCLUDED_CELL_TASK_LIST_INFO +# include "CellTaskListInfo.h" +#endif + class CellBufferManager : public BufferManager { public: + CellTaskListInfo *cellTaskListImpl; TaskListPtr *machineTaskList; + TaskQueuePtr speActiveTaskQueue; + TaskQueuePtr speWaitTaskQueue; void init(void); + void append_activeTask(HTaskPtr); #if 0 virtual TaskListPtr get_available_taskList(void); virtual void clear_taskList(void); - virtual void append_activeTask(HTaskPtr); virtual void append_waitTask(HTaskPtr); #endif }; diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/CellTaskManagerImpl.h --- a/include/TaskManager/CellTaskManagerImpl.h Sun Feb 17 11:19:25 2008 +0900 +++ b/include/TaskManager/CellTaskManagerImpl.h Sun Feb 17 18:06:53 2008 +0900 @@ -1,19 +1,23 @@ #ifndef INCLUDED_CELL_TASK_MANAGER_IMPL #define INCLUDED_CELL_TASK_MANAGER_IMPL -#include -#include - #ifndef INCLUDED_TASK_MANAGER_IMPL # include "TaskManagerImpl.h" #endif +#ifndef INCLUDED_SPE_THREADS +# include "SpeThreads.h" +#endif + class CellTaskManagerImpl : public TaskManagerImpl { public: + /* variables */ + SpeThreads *speThreads; + /* functions */ void init(void); void run(void); - void spawn_task(HTaskPtr); + MailQueuePtr mail_check(MailQueuePtr mail_list); }; #endif diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/HTaskInfo.h --- a/include/TaskManager/HTaskInfo.h Sun Feb 17 11:19:25 2008 +0900 +++ b/include/TaskManager/HTaskInfo.h Sun Feb 17 18:06:53 2008 +0900 @@ -24,13 +24,14 @@ DmaBuffer *out_addr; TaskQueuePtr wait_me; // List of task waiting for me TaskQueuePtr wait_i; // List of task for which I am waiting - void (*post_func)(void); + void (*post_func)(void); + CPU_TYPE cpu_type; struct htask *next; TaskManagerImpl *mimpl; void spawn(void); void set_depend(struct htask *); - //void (*set_cpu)(int); + void set_cpu(CPU_TYPE type); }; class HTaskInfo { diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/SpeThreads.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/SpeThreads.h Sun Feb 17 18:06:53 2008 +0900 @@ -0,0 +1,34 @@ +#ifndef INCLUDED_SPE_THREADS +#define INCLUDED_SPE_THREADS + +#include +#include + +#define SPE_ELF "spe-main" + +typedef struct arg { + int speid; + spe_context_ptr_t ctx; +} thread_arg_t; + +class SpeThreads { +public: + /* constructor */ + SpeThreads(int num = 1); + + /* functions */ + void init(void); + int get_mail(int speid); + static void *spe_thread_run(void *arg); + static void *frontend_thread_run(void *arg); + +private: + /* variables */ + spe_program_handle_t *spe_handle; + spe_context_ptr_t *spe_ctx; + pthread_t *threads; + thread_arg_t *args; + int spe_num; +}; + +#endif diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/TaskManagerImpl.h --- a/include/TaskManager/TaskManagerImpl.h Sun Feb 17 11:19:25 2008 +0900 +++ b/include/TaskManager/TaskManagerImpl.h Sun Feb 17 18:06:53 2008 +0900 @@ -29,13 +29,14 @@ /* functions */ virtual void init(void); void run(void); - MailQueuePtr mail_check(MailQueuePtr mail_list); + virtual MailQueuePtr mail_check(MailQueuePtr mail_list); HTaskPtr create_task(int cmd, int siz, DmaBuffer *in_addr, DmaBuffer *out_addr, void (*func)(void)); void set_task_depend(HTaskPtr master, HTaskPtr slave); TaskListPtr set_task(void); virtual void spawn_task(HTaskPtr); + void set_task_cpu(HTaskPtr, CPU_TYPE); // Fixme // アライメントとか、インスタンス用の new 使える奴とか、etc... diff -r eb2cb212881c -r 519d24aa7ac8 include/TaskManager/types.h --- a/include/TaskManager/types.h Sun Feb 17 11:19:25 2008 +0900 +++ b/include/TaskManager/types.h Sun Feb 17 18:06:53 2008 +0900 @@ -4,7 +4,6 @@ typedef unsigned int uint32; typedef unsigned long long uint64; - #define SPE_ALIGNMENT 16 #define SPE_ALIGNMENT_FULL 128 #define SPE_ALIGN __attribute__((aligned(SPE_ALIGNMENT))) @@ -15,6 +14,7 @@ #define DMA_MAX_SIZE 16384 +// ここも typedef しとくか? enum { MY_SPE_COMMAND_EXIT, MY_SPE_COMMAND_GO, @@ -23,4 +23,9 @@ MY_SPE_STATUS_READY }; +typedef enum { + CPU_PPE, // default + CPU_SPE +} CPU_TYPE; + #endif