changeset 1182:5a9bee9cc8c9 draft

add CpuThreads weit sem
author Daichi TOMA
date Tue, 28 Jun 2011 17:51:11 +0900
parents fa380908f801
children 8fd004a3f02c 4c209dd223cd
files TaskManager/CpuThreadsTest/CpuThreadsTest.cc TaskManager/Makefile TaskManager/Makefile.parallel TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h
diffstat 5 files changed, 42 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/CpuThreadsTest/CpuThreadsTest.cc	Mon Jun 27 03:03:55 2011 +0900
+++ b/TaskManager/CpuThreadsTest/CpuThreadsTest.cc	Tue Jun 28 17:51:11 2011 +0900
@@ -3,14 +3,42 @@
 #include "TaskManager/CellTaskManagerImpl.h"
 
 static void
+fail(const char *reason)
+{
+	printf("CpuThreadTest failed %s", reason);
+}
+
+static void
+tester(CpuThreadsPtr c, int num, int size)
+{
+	for(int id = 0; id < num; id++){
+		for(int i = 0; i < size; i++) {
+			c->send_mail(id, 1, (memaddr *) i); //mailqueue1に書き込む
+		}
+	}
+
+	for(int id = 0; id < num; id++){
+		for(int i = 0; i < size; i++) {
+			memaddr data;
+			if (c->has_mail(id, 1, &data) == 0) {
+				fail("early read fail\n");
+				break;
+			}
+			if (data != (memaddr)i) {
+				fail("read data fail\n");
+				break;
+			}
+		}
+	}
+}
+
+static void
 test1() {
 	int num = 1;
 	CpuThreadsPtr c = new CpuThreads(num);
 	c->init();
-	CellTaskManagerImpl *m = new CellTaskManagerImpl(num,c);
-	m->init(0);
+	tester(c,num,16);
 	delete c;
-	delete m;
 }
 
 int
--- a/TaskManager/Makefile	Mon Jun 27 03:03:55 2011 +0900
+++ b/TaskManager/Makefile	Tue Jun 28 17:51:11 2011 +0900
@@ -48,7 +48,6 @@
 	$(MAKE) -f Makefile.cell cellclean
 	$(MAKE) -f Makefile.fifo fifoclean
 	rm -rf *.a ../include	
-	cd $(IMPL_FIFO_DIR);    rm -f {ShowTime.cc,StartProfile.cc}	
 
 tags:
 	$(TAGS) $(TAGSOPTION)
--- a/TaskManager/Makefile.parallel	Mon Jun 27 03:03:55 2011 +0900
+++ b/TaskManager/Makefile.parallel	Tue Jun 28 17:51:11 2011 +0900
@@ -13,7 +13,10 @@
 all: default
 default: $(TARGET)
 
-ALL_OBJS = $(KERN_MAIN_OBJS) $(KERN_PPE_OBJS) $(KERN_SCHED_OBJS) $(KERN_SYSTASK_OBJS) $(IMPL_FIFO_OBJS) $(KERN_MEM_OBJS) Cell/spe/SpeTaskManagerImpl.o Cell/CellTaskManagerImpl.o
+ALL_OBJS = $(KERN_MAIN_OBJS) $(KERN_PPE_OBJS) $(KERN_SCHED_OBJS) \
+	$(KERN_SYSTASK_OBJS) $(IMPL_FIFO_OBJS) $(KERN_MEM_OBJS) \
+	Cell/spe/SpeTaskManagerImpl.o Cell/CellTaskManagerImpl.o \
+	Cell/spe/ShowTime.o Cell/spe/StartProfile.o
 
 Makefile.dep: 
 	make -f Makefile.parallel depend
--- a/TaskManager/kernel/ppe/CpuThreads.cc	Mon Jun 27 03:03:55 2011 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.cc	Tue Jun 28 17:51:11 2011 +0900
@@ -14,11 +14,12 @@
 
     threads = new pthread_t[cpu_num];
     args    = new cpu_thread_arg_t[cpu_num];
+    wait	= new Sem(0);
 
     for (int i = 0; i < cpu_num; i++) {
 	args[i].cpuid = i + id_offset;
 	args[i].scheduler = new MainScheduler();
-	args[i].run = 0;
+	args[i].wait = wait;
     }
 
 }
@@ -58,7 +59,7 @@
     //SchedRegister(ShowTime);
     //SchedRegister(StartProfile);
 
-    argt->run = 1;
+    argt->wait->sem_v();	//準備完了したスレッドができるたびに+1していく
 
     c_scheduler->run(new SchedNop());
     c_scheduler->finish();
@@ -76,8 +77,7 @@
     }
 
     for (int i = 0; i < cpu_num; i++) {
-    	while (args[i].run == 0){
-    	}
+    	wait->sem_p();
     }
 }
 
@@ -92,7 +92,6 @@
 int
 CpuThreads::get_mail(int cpuid, int count, memaddr *ret)
 {   
-    // need synchronization
     *ret = args[cpuid-id_offset].scheduler->mail_read_from_host();
     return 1;
 }
--- a/TaskManager/kernel/ppe/CpuThreads.h	Mon Jun 27 03:03:55 2011 +0900
+++ b/TaskManager/kernel/ppe/CpuThreads.h	Tue Jun 28 17:51:11 2011 +0900
@@ -5,13 +5,14 @@
 #include "Threads.h"
 #include "TaskManagerImpl.h"
 #include "MainScheduler.h"
+#include "Sem.h"
 
 typedef struct cpu_arg {
     int cpuid;
     // should be syncrhonized
     MainScheduler *scheduler;
     TaskManagerImpl *manager;
-    int run;
+    SemPtr wait;
 } cpu_thread_arg_t;
 
 class CpuThreads : Threads {
@@ -32,6 +33,7 @@
     /* variables */
     pthread_t *threads;
     cpu_thread_arg_t *args;
+    SemPtr wait; //スレッド生成時の待ち用
     int cpu_num;
     int id_offset;
 };