annotate example/task_queue/main.cc @ 625:94d82f2c842f draft

64bit mode worked on Mac OS X.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 16 Nov 2009 10:59:55 +0900
parents 278db3ca751d
children 5d48fa762a24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <string.h>
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "TaskManager.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "Func.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "main.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern void task_init(void);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 static int count = 1;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 extern TaskManager *manager;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 -cpu Number of SPE (default 1) \n\
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 -count Number of task is print \"Hello, World!!\"";
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 int
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 init(int argc, char **argv)
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 for (int i = 1; argv[i]; ++i) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if (strcmp(argv[i], "-count") == 0) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 count = atoi(argv[++i]);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 return 0;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Queues queues;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 static void
619
278db3ca751d RenewTask removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 496
diff changeset
34 repeat(SchedTask *s, void *arg, void *dm)
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 static int count = 4;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 QueuePtr q = (QueuePtr) arg;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 TaskManager *manager = q->m;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 if (count-->0) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 HTask *t = manager->create_task(HELLO_TASK);
619
278db3ca751d RenewTask removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 496
diff changeset
42 t->set_post(repeat, arg, 0);
625
94d82f2c842f 64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 619
diff changeset
43 t->set_param(0,(memaddr)q->i);
94d82f2c842f 64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 619
diff changeset
44 t->set_param(1,(memaddr)arg);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 t->spawn();
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 printf("[PPE] Create Task : Hello count=%d id=%d\n\n",count, q->i);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 } else {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 printf("[PPE] End Task : Hello id=%d\n\n", q->i);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 hello_init(TaskManager *manager)
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 if (count >MAX_QUEUE) return;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 queues.m = manager;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 queues.i = 0;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 for (int i = 0; i < MAX_QUEUE; i++) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 TaskQueueInfo *q = new TaskQueueInfo() ;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 queues.q[i] = q;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 for (int i = 0; i < count; i++) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /**
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 * Create Task
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 * create_task(Task ID);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 */
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 HTask *hello = manager->create_task(HELLO_TASK);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 /**
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 * Select CPU
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 * if you do not call this, execute PPE.
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 */
496
67fb962f58fa PS3 double linked TaskQueue worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 492
diff changeset
78 hello->set_cpu(SPE_ANY);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 /**
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 * Set 32bits parameter
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 * add_param(32bit parameter);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 */
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 QueuePtr q = (QueuePtr) manager->allocate(sizeof(Queues));
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 q->i = i;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 q->m = manager;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 for (int j = 0; j < MAX_QUEUE; j++) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 q->q[j] = queues.q[j];
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
625
94d82f2c842f 64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 619
diff changeset
92 hello->set_param(0,(memaddr)i);
94d82f2c842f 64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 619
diff changeset
93 hello->set_param(1,(memaddr)&queues);
619
278db3ca751d RenewTask removal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 496
diff changeset
94 hello->set_post(repeat, (void*) &queues, 0);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 hello->spawn();
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 int
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 TMmain(TaskManager *manager, int argc, char *argv[])
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 if (init(argc, argv) < 0) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 return -1;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 // Task Register
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 // ppe/task_init.cc
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 task_init();
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 hello_init(manager);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 return 0;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }