changeset 1189:898fdcf53c31 draft

add SemMailManager
author Daichi TOMA
date Fri, 08 Jul 2011 18:34:18 +0900
parents ad64e2b20a9f
children cfbf4f264829 bd4a27ae2524
files TaskManager/Cell/CellTaskManagerImpl.h TaskManager/Fifo/FifoDmaManager.h TaskManager/Makefile.parallel TaskManager/kernel/ppe/CpuThreads.h TaskManager/kernel/ppe/MailManager.cc TaskManager/kernel/ppe/MailManager.h TaskManager/kernel/ppe/SemMailManager.cc TaskManager/kernel/ppe/SemMailManager.h TaskManager/test/CpuThreadsTest/CpuThreadsTest.cc TaskManager/test/SemMailManagerTest/MailManagerTest.cc example/Prime/Makefile.def example/Prime/ppe/Prime.cc example/Prime/ppe/PrintTask.cc
diffstat 13 files changed, 152 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.h	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.h	Fri Jul 08 18:34:18 2011 +0900
@@ -3,8 +3,11 @@
 
 #include "TaskManagerImpl.h"
 #include "FifoTaskManagerImpl.h"
+#ifdef __CERIUM_CELL__
+#include "SpeThreads.h"
+#else
 #include "CpuThreads.h"
-#include "SpeThreads.h"
+#endif
 
 class CellTaskManagerImpl : public TaskManagerImpl {
 public:
--- a/TaskManager/Fifo/FifoDmaManager.h	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/Fifo/FifoDmaManager.h	Fri Jul 08 18:34:18 2011 +0900
@@ -4,6 +4,7 @@
 #include "base.h"
 #include "DmaManager.h"
 #include "MailManager.h"
+#include "SemMailManager.h"
 
 class FifoDmaManager : public DmaManager {
 
@@ -16,8 +17,13 @@
     BASE_NEW_DELETE(FifoDmaManager);
 
     FifoDmaManager() {
-	mail_queue1 = new MailManager();
-	mail_queue2 = new MailManager();
+#ifdef __CERIUM_PARALLEL__
+    		mail_queue1 = new SemMailManager();
+    		mail_queue2 = new SemMailManager();
+#else
+    		mail_queue1 = new MailManager();
+    		mail_queue2 = new MailManager();
+#endif
     }
 
     ~FifoDmaManager() {
--- a/TaskManager/Makefile.parallel	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/Makefile.parallel	Fri Jul 08 18:34:18 2011 +0900
@@ -4,7 +4,7 @@
 
 .SUFFIXES: .cc .o
 
-EXTRA_CFLAGS = -D__CERIUM_FIFO__ 
+EXTRA_CFLAGS = -D__CERIUM_FIFO__ -D__CERIUM_PARALLEL__
 
 .cc.o:
 	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@
--- a/TaskManager/kernel/ppe/CpuThreads.h	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.h	Fri Jul 08 18:34:18 2011 +0900
@@ -38,6 +38,4 @@
     int id_offset;
 };
 
-typedef CpuThreads *CpuThreadsPtr;
-
 #endif
--- a/TaskManager/kernel/ppe/MailManager.cc	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/kernel/ppe/MailManager.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -16,48 +16,51 @@
     read = write = 0;
     calc_mask(qsize);
     queue = Newq(memaddr,size);
+}
 
-    queue_remain  = new Sem(size-1);			//queue内に入る残りの数
-    queue_count	= new Sem(0);				//queue内に現在入っている数
+MailManager::~MailManager() { free(queue); }
 
+int
+MailManager::count()
+{
+    return (write+size-read)&mask;
 }
 
-MailManager::~MailManager()
+void
+MailManager::extend()
 {
-	free(queue);
-	delete queue_remain;
-	delete queue_count;
-}
-
-int 
-MailManager::count()
-{
-    return queue_count->count();
+    memaddr *newq = Newq(memaddr,size*2);
+    unsigned int i = 0;
+    while(i<size) {
+	newq[i++] = queue[read++];
+	read &= mask;
+    }
+    read = 0; write = i;
+    calc_mask(size*2);
+    free(queue);
+    queue = newq;
 }
 
 void 
 MailManager::send(memaddr data)
 {
-	queue_remain->sem_p();	//資源-1
-
     queue[write++] = data;
-    //maskの範囲を超えた場合、0に戻す
     write &= mask;
-
-    queue_count->sem_v();		//資源+1
+    if (write==read) {
+	extend();
+    }
 }
 
 memaddr 
 MailManager::recv()
 {
-	queue_count->sem_p();		//資源-1
-
     memaddr data;
+    if (count()>0) {
 	data = queue[read++];
 	read &= mask;
-
-	queue_remain->sem_v();	//資源+1
-
+    } else {
+	data = 0;
+    }
     return data;
 }
 
--- a/TaskManager/kernel/ppe/MailManager.h	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/kernel/ppe/MailManager.h	Fri Jul 08 18:34:18 2011 +0900
@@ -1,27 +1,23 @@
 #ifndef INCLUDED_MAIL_MANAGER
 #define INCLUDED_MAIL_MANAGER
 
-#include <pthread.h>
 #include "types.h"
-#include "Sem.h"
 
 class MailManager {
 public:
     /* constructor */
     MailManager(unsigned int qsize = 32) ;
 
-    ~MailManager();
+    virtual ~MailManager();
 
     /* functions */
-    void send(memaddr data);
-    memaddr recv();
-    int count();
+    virtual void send(memaddr data);
+    virtual memaddr recv();
+    virtual int count();
 
 private:
     /* variables */
     memaddr *queue;
-    SemPtr queue_remain;
-    SemPtr queue_count;
     unsigned int size;
     unsigned int read;
     unsigned int write;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/kernel/ppe/SemMailManager.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+#include "SemMailManager.h"
+
+void
+SemMailManager::calc_mask(unsigned int qsize)
+{
+    mask = 1;
+    while(qsize>mask) {
+	mask <<= 1;
+    }
+    size = mask;
+    mask--;
+}
+
+SemMailManager::SemMailManager(unsigned int qsize) {
+    read = write = 0;
+    calc_mask(qsize);
+    queue = Newq(memaddr,size);
+
+    queue_remain  = new Sem(size-1);			//queue内に入る残りの数
+    queue_count	= new Sem(0);				//queue内に現在入っている数
+
+}
+
+SemMailManager::~SemMailManager()
+{
+	free(queue);
+	delete queue_remain;
+	delete queue_count;
+}
+
+int 
+SemMailManager::count()
+{
+    return queue_count->count();
+}
+
+void 
+SemMailManager::send(memaddr data)
+{
+	queue_remain->sem_p();	//資源-1
+
+    queue[write++] = data;
+    //maskの範囲を超えた場合、0に戻す
+    write &= mask;
+
+    queue_count->sem_v();		//資源+1
+}
+
+memaddr 
+SemMailManager::recv()
+{
+	queue_count->sem_p();		//資源-1
+
+    memaddr data;
+	data = queue[read++];
+	read &= mask;
+
+	queue_remain->sem_v();	//資源+1
+
+    return data;
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/kernel/ppe/SemMailManager.h	Fri Jul 08 18:34:18 2011 +0900
@@ -0,0 +1,37 @@
+#ifndef INCLUDED_SEM_MAIL_MANAGER
+#define INCLUDED_SEM_MAIL_MANAGER
+
+#include <pthread.h>
+#include "MailManager.h"
+#include "types.h"
+#include "Sem.h"
+
+class SemMailManager : public MailManager {
+public:
+    /* constructor */
+    SemMailManager(unsigned int qsize = 32) ;
+
+    ~SemMailManager();
+
+    /* functions */
+    void send(memaddr data);
+    memaddr recv();
+    int count();
+
+private:
+    /* variables */
+    memaddr *queue;
+    SemPtr queue_remain;
+    SemPtr queue_count;
+    unsigned int size;
+    unsigned int read;
+    unsigned int write;
+    unsigned int mask;
+
+    void calc_mask(unsigned int qsize);
+    void extend();
+}  ;
+
+typedef SemMailManager *SemMailManagerPtr;
+
+#endif
--- a/TaskManager/test/CpuThreadsTest/CpuThreadsTest.cc	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/test/CpuThreadsTest/CpuThreadsTest.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -9,7 +9,7 @@
 }
 
 static void
-tester(CpuThreadsPtr c, int num, int size)
+tester(CpuThreads* c, int num, int size)
 {
 	for(int id = 0; id < num; id++){
 		for(int i = 0; i < size; i++) {
@@ -35,7 +35,7 @@
 static void
 test1() {
 	int num = 1;
-	CpuThreadsPtr c = new CpuThreads(num);
+	CpuThreads* c = new CpuThreads(num);
 	c->init();
 	tester(c,num,16);
 	delete c;
--- a/TaskManager/test/SemMailManagerTest/MailManagerTest.cc	Thu Jul 07 13:50:56 2011 +0900
+++ b/TaskManager/test/SemMailManagerTest/MailManagerTest.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include "TaskManager/MailManager.h"
+#include "TaskManager/SemMailManager.h"
 
 typedef struct _thread_arg {
 	MailManagerPtr m;
@@ -63,12 +64,12 @@
 
 static void
 test1() {
-    MailManagerPtr m = new MailManager(2);
+    MailManagerPtr m = new SemMailManager(2);
     tester(m,16);
     tester(m,32);
     tester(m,48);
     delete m; 
-    MailManagerPtr m1 = new MailManager(32);
+    MailManagerPtr m1 = new SemMailManager(32);
     tester(m1,16);
     tester(m1,48);
     delete m1;
--- a/example/Prime/Makefile.def	Thu Jul 07 13:50:56 2011 +0900
+++ b/example/Prime/Makefile.def	Fri Jul 08 18:34:18 2011 +0900
@@ -7,7 +7,7 @@
 # ex  linux/ps3
 CERIUM = ../../../Cerium
 
-CC      = g++ -m32
+CC      = g++ -m64
 CFLAGS  = -O9 -Wall
 #CFLAGS  = -g -Wall
 
--- a/example/Prime/ppe/Prime.cc	Thu Jul 07 13:50:56 2011 +0900
+++ b/example/Prime/ppe/Prime.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -9,8 +9,8 @@
 	static int
 prime(SchedTask *smanager, void *rbuf, void *wbuf)
 {
-	int start = (int)smanager->get_param(0);	/* 素数判定の開始地点 */
-	int end   = (int)smanager->get_param(1);	/* 素数判定の終了地点 */
+	int start = (long)smanager->get_param(0);	/* 素数判定の開始地点 */
+	int end   = (long)smanager->get_param(1);	/* 素数判定の終了地点 */
 	int range = end - start;					/* 判定する範囲		  */
 
 	/* 判定結果を収める配列を受け取る */
--- a/example/Prime/ppe/PrintTask.cc	Thu Jul 07 13:50:56 2011 +0900
+++ b/example/Prime/ppe/PrintTask.cc	Fri Jul 08 18:34:18 2011 +0900
@@ -8,7 +8,7 @@
 	static int
 print(SchedTask *smanager, void *rbuf, void *wbuf)
 {
-	int length = (int)smanager->get_param(0);			/* 出力する範囲 */
+	int length = (long)smanager->get_param(0);			/* 出力する範囲 */
 	int *input = (int*)smanager->get_input(rbuf, 0);	/* 出力する配列 */
 
 	/* 素数の判定結果が1ならば出力する */