634
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include "TaskManager.h"
|
|
5 #include "Func.h"
|
|
6
|
|
7 #define DATA_NUM 12
|
|
8
|
|
9 extern void task_init();
|
|
10
|
|
11 static int task = 1;
|
|
12
|
|
13 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
|
|
14 -length Number of data (default DATA_NUM (Func.h))\n\
|
|
15 -count Number of task (default 1)\n";
|
|
16
|
|
17
|
|
18 void
|
|
19 print_data(int *data, int size, const char *title)
|
|
20 {
|
|
21 printf("%s ---\n", title);
|
|
22 for (int i = 0; i < size; i++) {
|
|
23 printf("%2d ", data[i]);
|
|
24 }
|
|
25 printf("\n");
|
|
26 }
|
|
27
|
|
28 /**
|
|
29 * タスク終了後の data1, data2 の確認
|
|
30 */
|
|
31 void
|
|
32 twice_result(SchedTask *s, void *a, void *b)
|
|
33 {
|
|
34 int* data = (int*)a;
|
|
35 int length = (long)b;
|
|
36 print_data(data, length, "after");
|
|
37 free(data);
|
|
38 }
|
|
39
|
|
40 int length = DATA_NUM;
|
|
41
|
|
42 int
|
|
43 init(int argc, char **argv)
|
|
44 {
|
|
45 for (int i = 1; argv[i]; ++i) {
|
|
46 if (strcmp(argv[i], "-length") == 0) {
|
|
47 length = atoi(argv[++i]);
|
|
48 } else if (strcmp(argv[i], "-count") == 0) {
|
|
49 task = atoi(argv[++i]);
|
|
50 }
|
|
51 }
|
|
52
|
|
53 return 0;
|
|
54 }
|
|
55
|
|
56 void
|
|
57 twice_init(TaskManager *manager)
|
|
58 {
|
|
59 HTask *twice;
|
|
60
|
|
61 int *data = (int*)manager->allocate(sizeof(int)*length);
|
|
62 int *out = (int*)manager->allocate(sizeof(int)*length);
|
|
63
|
|
64 for (int i = 0; i < length; i++) {
|
|
65 data[i] = i;
|
|
66 }
|
|
67
|
|
68 print_data(data, length, "before");
|
|
69
|
|
70 /**
|
|
71 * Create Task
|
|
72 * create_task(Task ID);
|
|
73 */
|
|
74 twice = manager->create_task(Twice,(memaddr)data,sizeof(int)*length, (memaddr)out, sizeof(int)*length);
|
|
75 twice->set_cpu(SPE_ANY);
|
|
76
|
|
77 twice->set_post(twice_result, (void*)out, (void*)length);
|
|
78
|
|
79 // add Active Queue
|
|
80 twice->spawn();
|
|
81 }
|
|
82
|
|
83 int
|
|
84 TMmain(TaskManager *manager,int argc, char *argv[])
|
|
85 {
|
|
86 if (init(argc, argv) < 0) {
|
|
87 return -1;
|
|
88 }
|
|
89
|
|
90 // Task Register
|
|
91 // ppe/task_init.cc
|
|
92 task_init();
|
|
93
|
|
94 for (int i = 0; i < task; ++i) {
|
|
95 twice_init(manager);
|
|
96 }
|
|
97
|
|
98 return 0;
|
|
99 }
|
|
100
|
|
101 /* end */
|