changeset 492:9522c376a9fe

memcpy for param
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 09 Oct 2009 11:18:42 +0900
parents 7cd207691af1
children dd091fe6128e
files TaskManager/Cell/CellTaskManagerImpl.cc TaskManager/Fifo/FifoTaskManagerImpl.cc TaskManager/kernel/ppe/TaskQueueInfo.h example/task_queue/Func.h example/task_queue/Makefile example/task_queue/Makefile.cell example/task_queue/Makefile.def example/task_queue/Makefile.linux example/task_queue/Makefile.macosx example/task_queue/README example/task_queue/main.cc example/task_queue/main.h example/task_queue/ppe/.#Hello.cc example/task_queue/ppe/Hello.cc example/task_queue/ppe/Hello.h example/task_queue/ppe/task_init.cc example/task_queue/spe/Hello.cc example/task_queue/spe/Hello.h example/task_queue/spe/Makefile example/task_queue/spe/spe-main.cc
diffstat 20 files changed, 431 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Tue Oct 06 17:14:05 2009 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -129,7 +129,7 @@
 	}
 
 	task = &list->tasks[list->length++];
-#if 1
+#if 0
 	task->command  = htask->command;
 	task->inData   = htask->inData;
 	task->outData  = htask->outData;
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc	Tue Oct 06 17:14:05 2009 +0900
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -106,11 +106,12 @@
         htask = (HTaskPtr)queue->task;
 
         task = &list->tasks[list->length++];
-#if 1
+#if 0
         task->command  = htask->command;
         task->inData   = htask->inData;
         task->outData  = htask->outData;
         task->self     = (unsigned int)htask;
+	// param は?
 #else
         memcpy(task, (Task*)htask, sizeof(Task));
 #endif
--- a/TaskManager/kernel/ppe/TaskQueueInfo.h	Tue Oct 06 17:14:05 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskQueueInfo.h	Fri Oct 09 11:18:42 2009 +0900
@@ -5,6 +5,9 @@
 #include "TaskQueue.h"
 
 class TaskQueueInfo : public TaskQueue {
+
+    BASE_NEW_DELETE(TaskQueueInfo);
+
 public:
     /* constructor */
     TaskQueueInfo();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Func.h	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,5 @@
+enum {
+    HELLO_TASK,
+    RUN_FINISH,
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Makefile	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,20 @@
+default: macosx
+
+macosx: FORCE
+	@echo "Make for Mac OS X"
+	@$(MAKE) -f Makefile.macosx
+
+linux: FORCE
+	@echo "Make for Linux"
+	@$(MAKE) -f Makefile.linux
+
+cell: FORCE
+	@echo "Make for PS3 (Cell)"
+	@$(MAKE) -f Makefile.cell
+
+FORCE:
+
+clean:
+	@$(MAKE) -f Makefile.macosx clean
+	@$(MAKE) -f Makefile.linux clean
+	@$(MAKE) -f Makefile.cell clean
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Makefile.cell	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,42 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ե
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lCellManager -lspe2 -lpthread -Wl,--gc-sections 
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET) speobject
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+speobject:
+	cd spe; $(MAKE)
+
+run:
+	./$(TARGET) -cpu 6 
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo ppu-gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	cd spe; $(MAKE) clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Makefile.def	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,14 @@
+TARGET = task_queue
+
+# include/library path
+# ex: macosx
+#CERIUM = /Users/gongo/Source/Cerium
+
+# ex: linux/ps3
+CERIUM = ../../../Cerium
+
+CC      = g++
+CFLAGS  = -g -Wall -O9
+
+INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L${CERIUM}/TaskManager
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Makefile.linux	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,36 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ե
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/Makefile.macosx	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,36 @@
+include ./Makefile.def
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # ե
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+TASK_DIR  = ppe
+TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc)
+TASK_SRCS_EXCLUDE = 
+TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP))
+TASK_OBJS = $(TASK_SRCS:.cc=.o)
+
+LIBS += -lFifoManager `sdl-config --libs`
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(TASK_OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
+
+debug: $(TARGET)
+	sudo gdb ./$(TARGET) 
+
+clean:
+	rm -f $(TARGET) $(OBJS) $(TASK_OBJS)
+	rm -f *~ \#*
+	rm -f ppe/*~ ppe/\#*
+	rm -f spe/*~ spe/\#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/README	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,4 @@
+Tue Oct  6 17:17:09 JST 2009
+
+TaskQueueu は、本来、内部で使う double linked list なので、
+ユーザには関係ない。ここでテストするのは変だが。
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/main.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,114 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "TaskManager.h"
+#include "Func.h"
+#include "main.h"
+
+extern void task_init(void);
+
+static int count = 1;
+
+extern TaskManager *manager;
+
+const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\
+  -cpu    Number of SPE (default 1) \n\
+  -count  Number of task is print \"Hello, World!!\"";
+
+int
+init(int argc, char **argv)
+{
+    for (int i = 1; argv[i]; ++i) {
+	if (strcmp(argv[i], "-count") == 0) {
+            count = atoi(argv[++i]);
+        }
+
+    }
+
+    return 0;
+}
+
+Queues queues;
+
+static void
+repeat(void *arg)
+{
+    static int count = 4;
+    QueuePtr q = (QueuePtr) arg;
+    TaskManager *manager = q->m;
+
+    if (count-->0) {
+        HTask *t = manager->create_task(HELLO_TASK);
+        t->set_post(repeat, arg);
+        t->add_param(q->i);
+        t->add_param((int)arg);
+        t->spawn();
+
+        printf("[PPE] Create Task : Hello count=%d id=%d\n\n",count, q->i);
+    } else {
+        printf("[PPE] End Task : Hello id=%d\n\n", q->i);
+    }
+}
+
+void
+hello_init(TaskManager *manager)
+{
+
+    if (count >MAX_QUEUE) return;
+
+    queues.m = manager;
+    queues.i = 0;
+    for (int i = 0; i < MAX_QUEUE; i++) {
+	TaskQueueInfo *q = new TaskQueueInfo() ;
+	queues.q[i] = q;
+    }
+
+    for (int i = 0; i < count; i++) {
+	/**
+	 * Create Task
+	 *   create_task(Task ID);
+	 */
+	HTask *hello = manager->create_task(HELLO_TASK);
+
+	/**
+	 * Select CPU
+	 *   SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY
+	 *   if you do not call this, execute PPE.
+	 */
+	// hello->set_cpu(SPE_ANY);
+
+	/**
+	 * Set 32bits parameter
+	 *   add_param(32bit parameter);
+	 */
+	QueuePtr q = (QueuePtr) manager->allocate(sizeof(Queues));
+
+	q->i = i;
+	q->m = manager;
+	for (int j = 0; j < MAX_QUEUE; j++) {
+	    q->q[j] = queues.q[j];
+	}
+
+	hello->add_param(i);
+	hello->add_param((int)&queues);
+	hello->set_post(repeat, (void*) &queues);
+
+	hello->spawn();
+    }
+}
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    if (init(argc, argv) < 0) {
+	return -1;
+    }
+
+    // Task Register
+    //   ppe/task_init.cc
+    task_init();
+
+    hello_init(manager);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/main.h	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,10 @@
+#include "TaskQueueInfo.h"
+#include "TaskManager.h"
+
+#define MAX_QUEUE 4
+
+typedef struct queues {
+    int i;
+    TaskManager *m;
+    TaskQueueInfo *q[MAX_QUEUE];
+} Queues, *QueuePtr;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/ppe/.#Hello.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,1 @@
+e065746@nakasone-hiroki-no-macbook.local.1456
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/ppe/Hello.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include "SchedTask.h"
+#include "Hello.h"
+#include "Func.h"
+#include "main.h"
+
+/* これは必須 */
+SchedDefineTask(Hello);
+
+
+
+static int
+run(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+    int task_id = smanager->get_param(0);
+    QueuePtr q = (QueuePtr) smanager->get_param(1);
+
+    smanager->printf("[%d] Hello, World!!\n", task_id);
+
+    for(int i=0;i<100;i++) {
+	TaskQueueInfo *i0 = q->q[i%MAX_QUEUE];
+	TaskQueueInfo *i1 = q->q[(i+1)%MAX_QUEUE];
+
+	switch(q->m->get_random() % 4) {
+	case 0:
+	    TaskQueue *q0 = i0->create(0);
+	    i1->addLast(q0);
+	    TaskQueue *q1 = i1->create(0);
+	    i0->addLast(q1);
+	    break;
+	case 1:
+	    if (TaskQueue *p = i0->poll()) {
+		i1->addLast(p);
+	    }
+	    break;
+	case 2:
+	    if (TaskQueue *p = i1->poll()) {
+		i0->addLast(p);
+	    }
+	    break;
+	case 3:
+	    if (TaskQueue *p = i0->poll()) {
+		i0->free(p);
+	    }
+	    if (TaskQueue *p = i1->poll()) {
+		i1->free(p);
+	    }
+	    break;
+	}
+    }
+
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/ppe/Hello.h	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,7 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#include "SchedTask.h"
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/ppe/task_init.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,17 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+/* 必ずこの位置に書いて */
+SchedExternTask(Hello);
+
+/**
+ * この関数は ../spe/spe-main と違って
+ * 自分で呼び出せばいい関数なので
+ * 好きな関数名でおk (SchedRegisterTask は必須)
+ */
+
+void
+task_init()
+{
+  SchedRegisterTask(HELLO_TASK, Hello);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/spe/Hello.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include "Hello.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(Hello);
+
+static int
+run(SchedTask *smanager, void *rbuf, void *wbuf)
+{
+    int task_id = smanager->get_param(0);
+
+    smanager->printf("[%d] Hello, World!!\n", task_id);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/spe/Hello.h	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_HELLO
+#define INCLUDED_TASK_HELLO
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/spe/Makefile	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,26 @@
+include ../Makefile.def
+
+TARGET = ../spe-main
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+CC      = spu-g++
+CFLAGS  = -O9 -g -Wall -fno-exceptions -fno-rtti#-DDEBUG
+INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I..
+LIBS = -L../${CERIUM}/TaskManager -lspemanager  -Wl,--gc-sections 
+
+.SUFFIXES: .cc .o
+
+.cc.o:
+	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	$(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS)
+
+clean:
+	rm -f $(TARGET) $(OBJS)
+	rm -f *~ \#*
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/task_queue/spe/spe-main.cc	Fri Oct 09 11:18:42 2009 +0900
@@ -0,0 +1,14 @@
+#include "Func.h"
+#include "Scheduler.h"
+
+SchedExternTask(Hello);
+
+/**
+ * この関数は SpeScheduler から呼ばれるので
+ * 必ずこの関数名でお願いします。
+ */
+void
+task_init(Scheduler *s)
+{
+    SchedRegisterTask(HELLO_TASK, Hello);
+}