changeset 808:8a6f1fa038de

TaskListInfo version
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 22 May 2010 22:32:41 +0900
parents 3763d29f41a3
children 76a39ad68846
files TaskManager/Cell/CellTaskListInfo.cc TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Cell/CellTaskManagerImpl.h TaskManager/Fifo/FifoTaskManagerImpl.cc TaskManager/Fifo/FifoTaskManagerImpl.h TaskManager/kernel/ppe/TaskListInfo.cc TaskManager/kernel/ppe/TaskListInfo.h TaskManager/kernel/schedule/SchedTaskArray.cc
diffstat 8 files changed, 82 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskListInfo.cc	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/Cell/CellTaskListInfo.cc	Sat May 22 22:32:41 2010 +0900
@@ -6,28 +6,26 @@
     (TaskListPtr)((memaddr)(addr) + (size))
 
 int
-CellTaskListInfo::extend_pool(int num)
+TaskListInfo::extend_pool(int num)
 {
-    TaskListPtr q = NULL;
+    TaskListPtr q;
     int unit_size;
     
     unit_size = (ROUND_UP_ALIGN(sizeof(TaskList), DEFAULT_ALIGNMENT));
     posix_memalign((void**)&q, DEFAULT_ALIGNMENT, unit_size*(num+1));
 
-    if (q == NULL) {
-        return -1;
+    // First Queue is previous pool
+    q->waiter = waiter; waiter = q;
+    q++;
+
+    /* Connect all free queue in the pool */
+    TaskListPtr p = q;
+    for (; num-- > 0; p++) {
+	p->waiter = NULL;
+	taskListPool.addLast(p);
     }
-    
-    q->next = taskListPool;
-    taskListPool = q;
-    
-    /* Connect all free pack_list in the pool */
-    q = NEXT_ADDR(taskListPool, unit_size); // q = taskListPool + 1;
-    for (; --num > 0; q = NEXT_ADDR(q, unit_size)) {
-        q->next = NEXT_ADDR(q, unit_size); // q->next = q + 1;
-    }
-    q->next = freeTaskList;
-    freeTaskList = NEXT_ADDR(taskListPool, unit_size);
 
     return 0;
 }
+
+/* end */
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Sat May 22 22:32:41 2010 +0900
@@ -17,13 +17,6 @@
 {
     delete speThreads;
     delete [] speTaskList;
-    delete [] speTaskList_bg;
-    /**
-     * bufferManager は
-     * ppeManager のなかで delete してもらう
-     */
-    // delete bufferManager;
-    delete [] flag_sendTaskList;
 
     delete ppeManager;
 }
@@ -33,7 +26,7 @@
 {
     spe_running = 0;
     taskListImpl = new CellTaskListInfo;
-    taskListImpl->init(16);
+
 
     activeTaskQueue = new HTaskInfo();
 
@@ -42,18 +35,12 @@
     speThreads = new SpeThreads(machineNum);
     speThreads->init();
 
-    speTaskList  = new TaskListPtr[machineNum];
-    speTaskList_bg  = new TaskListPtr[machineNum];
+    speTaskList  = new TaskListInfoPtr[machineNum];
 
     for (int i = 0; i < machineNum; i++) {
-	speTaskList[i] = taskListImpl->create();
-	speTaskList_bg[i] = taskListImpl->create();
+	speTaskList[i] = new TaskListInfo();
     }
 
-    flag_sendTaskList = new int[machineNum];
-    for (int i = 0; i < machineNum; i++) {
-	flag_sendTaskList[i] = 1;
-    } 
     // PPE 側の管理をする Manager
     ppeManager = new FifoTaskManagerImpl(machineNum);
     // 大半のTaskQueueInfoは、共有される
@@ -114,9 +101,7 @@
 		speid %= machineNum;
 	    }
 	}
-
-	TaskListInfoPtr list = speTaskList_bg[speid];
-	set_taskList(htask, list);
+	set_taskList(htask, taskListInfo[speid]);
     }
 }
 
@@ -124,7 +109,7 @@
 CellTaskManagerImpl::sendTaskList()
 {
     for (int i = 0; i < machineNum; i++)  {
-	if (flag_sendTaskList[i] == 1 && speTaskList_bg[i]->length >= 1 ) {
+	if ( taskListInfo[i]->length() > 0 ) {
 	    send_taskList(i);
 	    spe_running++;
 	}
@@ -132,25 +117,26 @@
 }
 
 void
+CellTaskManagerImpl::poll()
+{
+    mail_check();
+    // SPE に送る TaskList の準備
+    set_runTaskList();
+    // TaskList 待ちの SPE に TaskList を送る
+    sendTaskList();
+}
+
+void
 CellTaskManagerImpl::run()
 {
-    TaskListPtr ppeTaskList = NULL;
-
     do {
         // PPE side
-	ppeTaskList =  ppeManager->set_runTaskList();
-	if (ppeTaskList)
-	    ppeManager->sendTaskList(ppeTaskList);
-	ppeManager->mail_check();
+	ppeManager->poll();
         // SPE side
 	do {
-	    mail_check();
-	    // SPE に送る TaskList の準備
-	    set_runTaskList();
-	    // TaskList 待ちの SPE に TaskList を送る
-	    sendTaskList();
+	    poll();
 	} while (ppeManager->activeTaskQueue->empty() && spe_running >0 );
-    } while (ppeTaskList || spe_running >0); 
+    } while (!ppeManager->taskListInfo->empty() || spe_running >0); 
     if (!waitTaskQueue->empty()) {
 	get_scheduler()->printf("Dead lock detected\n");
     }
@@ -170,7 +156,7 @@
 	while (speThreads->has_mail(id, 1, &data)) {				
 	    if (data == (memaddr)MY_SPE_STATUS_READY) {
 		//  MY_SPE_STATUS_READY: SPE が持ってた Task 全て終了
-		flag_sendTaskList[id] = 1;
+	        speTaskList[id]->freeAll();
 		spe_running--;
 	    } else if (data == (memaddr)MY_SPE_COMMAND_MALLOC) {
 	        // MY_SPE_COMMAND_MALLOC   SPE からのmain memory request
@@ -218,22 +204,18 @@
  * 条件1. SPE が持ってた TaskList を終了して、次の TaskList を待ってる
  * 条件2. SPE に送る TaskList に Task がある
  *
- * SPE で実行終了した TaskList [speTaskList] と
- * これから実行する TaskList [speTaskList_bg] のバッファを入れ替える
- * ついでに実行終了したやつは clear しておく。
+ * SPE で実行終了した speTaskList  と
+ * これから実行する taskListInfo  のバッファを入れ替える
  */
 void
 CellTaskManagerImpl::send_taskList(int id)
 {
-    TaskListPtr tmp;
+    if (taskListInfo[id]->empty()) return;
+    TaskListInfoPtr tmp = taskListInfo[id];
+    taskListInfo[id] = speTaskList[id];
+    speTaskList[id] = tmp;
 
-    tmp = speTaskList[id];
-    speTaskList[id]  = speTaskList_bg[id];
-    speTaskList_bg[id] = tmp;
-
-    taskListImpl->clear_taskList(speTaskList_bg[id]);
-
-    speThreads->send_mail(id, 1, (memaddr *)&speTaskList[id]);
+    speThreads->send_mail(id, 1, (memaddr *)tmp->getFirst());
 }
 
 void CellTaskManagerImpl::show_profile() {
--- a/TaskManager/Cell/CellTaskManagerImpl.h	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.h	Sat May 22 22:32:41 2010 +0900
@@ -12,11 +12,10 @@
     ~CellTaskManagerImpl();
 
     /* variables */
-    TaskListPtr *speTaskList;
-    TaskListPtr *speTaskList_bg;
+    TaskListInfoPtr *taskListInfo;
+    TaskListInfoPtr *speTaskList;  // running task
 
     SpeThreads *speThreads;
-    int *flag_sendTaskList;
     FifoTaskManagerImpl *ppeManager;
     int spe_running;
 
@@ -24,6 +23,7 @@
     // system
     void init();
     void run();
+    void poll();
     void mail_check();
     void set_runTaskList();
     void sendTaskList();
@@ -31,14 +31,6 @@
     void show_profile() ;
     void start_profile() ;
 
-    // user
-    // int add_data(ListDataPtr, uint32, int);
-#if 0
-    void* allocate(int size);
-    void* allocate(int size,int align);
-    Scheduler* get_scheduler();
-#endif
-
 private:
     void send_taskList(int id);
 };
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc	Sat May 22 22:32:41 2010 +0900
@@ -38,6 +38,7 @@
     set_scheduler(mainScheduler);
 
     taskListInfo  = new TaskListInfo;
+    ppeTaskList  = new TaskListInfo;
 
     schedTaskManager = new SchedTask();
     schedTaskManager->init(0,0,0,mainScheduler);
@@ -64,6 +65,7 @@
     waitTaskQueue     = tm->waitTaskQueue;   
 
     taskListInfo  = new TaskListInfo;
+    ppeTaskList  = new TaskListInfo;
 
     schedTaskManager = new SchedTask();
     schedTaskManager->init(0,0,0,mainScheduler);
@@ -81,32 +83,32 @@
  * ActiveTaskQueue (依存条件は満たし済み) のタスクを
  * 実行タスクリストに入れる
  */
-TaskListPtr
+void
 FifoTaskManagerImpl::set_runTaskList()
 {
-    if (activeTaskQueue->empty()) {
-        return NULL;
-    }
-
     // printf("active task queue length = %d\n",activeTaskQueue->length());
     while (HTaskPtr htask = activeTaskQueue->poll()) {
 	set_taskList(htask, taskListInfo );
     }
-    return taskListInfo->getFirst();
 }
 
+void
+FifoTaskManagerImpl::poll()
+{
+    set_runTaskList();
+    // list を実行する
+    sendTaskList();
+    // ppe scheduler からの mail を調べる
+    mail_check();
+}
 
 void
 FifoTaskManagerImpl::run()
 {
-    TaskListPtr list;
+    do {
+	poll();
+    } while(!taskListInfo->empty()) ;
 
-    while((list = set_runTaskList())) {
-        // list を実行する
-        sendTaskList(list);
-        // ppe scheduler からの mail を調べる
-        mail_check();
-    }
     if (!waitTaskQueue->empty()) {
         get_scheduler()->printf("Dead lock detected\n");
     }
@@ -119,10 +121,14 @@
  * [Tasklist] -> [番兵] -> scheduler->run を抜ける
  */
 void
-FifoTaskManagerImpl::sendTaskList(TaskListPtr list)
+FifoTaskManagerImpl::sendTaskList()
 {
+    if (taskListInfo->empty()) return;
+    TaskListInfoPtr tmp = ppeTaskList;
+    ppeTaskList = taskListInfo;
+    taskListInfo = tmp;
     // TaskList のアドレスを送る
-    mainScheduler->mail_write_from_host((memaddr)list);
+    mainScheduler->mail_write_from_host((memaddr)ppeTaskList->getFirst());
 
     // EXIT_COMMAND (番兵的な意味で)
     //   これを読むと、mainScheduler->run() から抜けて来る。
@@ -151,6 +157,7 @@
 
         if (data == (memaddr)MY_SPE_STATUS_READY) {
             __debug_ppe("mail_check(): Task List finish\n");
+	    ppeTaskList->freeAll(); 
         } else if (data == (memaddr)MY_SPE_COMMAND_EXIT) {
             __debug_ppe("mail_check(): Task List finish COMMAND\n");
 	} else if (data == (memaddr)MY_SPE_COMMAND_MALLOC) {
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.h	Sat May 22 22:32:41 2010 +0900
@@ -13,25 +13,26 @@
 
     /* variables */
     int machineNum;
-    TaskListPtr mainTaskList;  // activeTask であるべきなんじゃないの?
-    TaskListInfoPtr taskListInfo;  // activeTask であるべきなんじゃないの?
+    TaskListInfoPtr taskListInfo;  
+    TaskListInfoPtr ppeTaskList;  // running task
 
     MailManager *mailManager;
     MainScheduler *mainScheduler;
 
     /* functions */
     // call by system
-    void init(void);
+    void init();
     void init(MainScheduler*, TaskManagerImpl*);
-    void run(void);
+    void poll();  // called from CellTaskManagerImpl
+    void run();
     void show_profile()  {};
     void start_profile()  {};
 
 
     void mail_check();
 
-    TaskListPtr set_runTaskList();
-    void sendTaskList(TaskListPtr);
+    void set_runTaskList();
+    void sendTaskList();
 
     // call by user
 
--- a/TaskManager/kernel/ppe/TaskListInfo.cc	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/kernel/ppe/TaskListInfo.cc	Sat May 22 22:32:41 2010 +0900
@@ -66,6 +66,13 @@
     taskListPool.addLast(q);
 }
 
+void
+TaskListInfo::freeAll()
+{
+    TaskListPtr t;
+    while((t=poll())) free_(t);
+}
+
 
 /*!
   TaskListInfo は空にならない。最低1個は要素が入っていて
--- a/TaskManager/kernel/ppe/TaskListInfo.h	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/kernel/ppe/TaskListInfo.h	Sat May 22 22:32:41 2010 +0900
@@ -15,6 +15,7 @@
     TaskListPtr create();
 
     void free_(TaskListPtr queue);
+    void freeAll();
 
     void addFirst(TaskList* e);
     void addLast(TaskList* e);
@@ -31,11 +32,11 @@
     // Iterator
     TaskList* getNext(TaskList* q) ;
     int length();
+    static TaskListInfo taskListPool;
 
 private:
     /* variables */
 
-    static TaskListInfo taskListPool;
     TaskList* first;
     TaskList* last;
 
--- a/TaskManager/kernel/schedule/SchedTaskArray.cc	Sat May 22 18:21:13 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTaskArray.cc	Sat May 22 22:32:41 2010 +0900
@@ -41,7 +41,8 @@
     outListData.length = 0;
     outListData.element = 0;
 
-    atask = (TaskPtr)&savedTask->list->tasks[savedTask->cur_index];
+    SimpleTaskPtr st = &savedTask->list->tasks[savedTask->cur_index];
+    atask = (TaskPtr)st;
     array = 0;
     savedTask->cur_index += (atask->size()+sizeof(SimpleTask))/sizeof(SimpleTask);