changeset 65:519d24aa7ac8

*** empty log message ***
author gongo
date Sun, 17 Feb 2008 18:06:53 +0900
parents eb2cb212881c
children 1034077dd217
files TaskManager/Cell/CellBufferManager.cc TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Cell/SpeThreads.cc TaskManager/kernel/ppe/HTaskInfo.cc TaskManager/kernel/ppe/TaskManagerImpl.cc include/TaskManager/CellBufferManager.h include/TaskManager/CellTaskManagerImpl.h include/TaskManager/HTaskInfo.h include/TaskManager/SpeThreads.h include/TaskManager/TaskManagerImpl.h include/TaskManager/types.h
diffstat 11 files changed, 175 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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)
 {
--- 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)
 {
--- /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;
+    }
+}
--- 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);
+}
--- 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)
 {
--- 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
 };
--- 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 <libspe2.h>
-#include <pthread.h>
-
 #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
--- 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 {
--- /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 <libspe2.h>
+#include <pthread.h>
+
+#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
--- 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...
--- 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