Mercurial > hg > Members > yutaka > manager
annotate spe/SpeSentry.cc @ 3:8b4d6bf8c43d
add entry_head function
author | yutaka@localhost.localdomain |
---|---|
date | Wed, 07 Apr 2010 17:35:34 +0900 |
parents | 1e1b0d280427 |
children | 39d405bc46b7 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <malloc.h> | |
3 #include <spu_intrinsics.h> | |
4 #include <spu_mfcio.h> | |
5 #include "SpeSentry.h" | |
6 #include "MailCommand.h" | |
7 #include "Dma.h" | |
8 #include "Run.h" | |
9 | |
10 void* | |
2 | 11 fix_type(task_t *task, void* buff) |
0 | 12 { |
13 | |
14 char *p; | |
15 p = (char*)buff; | |
2 | 16 p = p + sizeof(task_head_t); |
0 | 17 |
2 | 18 task->head = (task_head_t*)buff; |
19 task->input = p; | |
0 | 20 |
21 } | |
22 | |
23 void* | |
24 allocate(int size) | |
25 { | |
26 | |
27 int alignment = 16; | |
28 return memalign(alignment, size); | |
29 | |
30 } | |
31 | |
2 | 32 task_t |
0 | 33 task_allocate(int size) |
34 { | |
35 | |
36 if (size % 16) { | |
37 //printf("allocate size is not multiple of 16\n"); | |
38 } | |
39 | |
40 char *buff; | |
2 | 41 task_t task; |
0 | 42 |
43 void *head; | |
44 head = memalign(16, size); | |
45 | |
46 buff = (char*)head; | |
2 | 47 buff = buff + sizeof(task_head_t); |
0 | 48 |
2 | 49 task.head = (task_head_t*)head; |
50 task.input = buff; | |
0 | 51 |
2 | 52 return task; |
0 | 53 |
54 } | |
55 | |
56 int | |
57 main(unsigned long long spe, unsigned long long argp, unsigned long long envp) | |
58 { | |
59 | |
60 uint32_t data; | |
61 int buff_num = 2; | |
2 | 62 unsigned int dma_wait_time = 0; |
0 | 63 |
64 int in_tag[buff_num]; | |
65 int out_tag[buff_num]; | |
66 | |
67 in_tag[0] = 0; | |
68 in_tag[1] = 1; | |
69 | |
70 out_tag[0] = 2; | |
71 out_tag[1] = 3; | |
72 | |
73 int head_tag = 4; | |
74 | |
2 | 75 task_head_t *head = (task_head_t*)allocate(sizeof(task_head_t)); |
76 task_t *send_params = (task_t*)allocate(sizeof(task_t)); | |
0 | 77 void *input_buff[buff_num]; |
78 void *output_buff[buff_num]; | |
79 | |
80 int cur; | |
81 | |
82 spu_write_out_mbox(WANT_DATA); | |
83 | |
84 while(1) { | |
85 | |
86 //mail check start | |
87 if(spu_stat_in_mbox()) { | |
88 | |
89 data = spu_read_in_mbox(); | |
90 | |
91 if (data == SPE_RUN_END) { | |
92 | |
93 break; | |
94 | |
95 } else { | |
96 | |
97 //printf("[SPE] data %p\n",data); | |
98 | |
2 | 99 dma_get(head, data, sizeof(task_head_t), head_tag); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
100 dma_wait_time += dma_wait(head_tag); |
0 | 101 |
102 input_buff[0] = allocate(head->next_task_size); | |
103 | |
104 dma_get(input_buff[0], head->next_task, head->next_task_size, in_tag[0]); | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
105 dma_wait_time += dma_wait(in_tag[0]); |
0 | 106 |
107 fix_type(send_params,input_buff[0]); | |
108 | |
109 cur = 0; | |
110 | |
111 while(1) { | |
112 | |
113 input_buff[cur^1] = allocate(send_params->head->next_task_size); | |
114 dma_get(input_buff[cur^1], send_params->head->next_task, send_params->head->next_task_size, in_tag[cur^1]); | |
115 | |
2 | 116 void *in = send_params->input; |
0 | 117 |
118 //printf("hoge"); | |
119 output_buff[cur] = allocate(send_params->head->size_out); | |
120 | |
3 | 121 int size_in = send_params->head->size_in; |
122 int size_out = send_params->head->size_out; | |
0 | 123 |
124 //task******************************************** | |
125 | |
3 | 126 run(in, output_buff[cur], size_in, size_out); |
127 | |
0 | 128 //end********************************************* |
129 | |
130 dma_put(output_buff[cur], send_params->head->ea_out, send_params->head->size_out, out_tag[cur]); | |
131 | |
132 free(input_buff[cur]); | |
133 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
134 dma_wait_time += dma_wait(in_tag[cur^1]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
135 dma_wait_time += dma_wait(out_tag[cur^1]); |
0 | 136 //printf("hoge"); |
137 | |
138 free(output_buff[cur^1]); | |
139 | |
140 cur ^= 1; | |
141 | |
142 fix_type(send_params,input_buff[cur]); | |
143 | |
144 if ((unsigned long)send_params->head->next_task == 0) { | |
145 break; | |
146 } | |
147 | |
148 }//while | |
149 | |
150 | |
2 | 151 void *in = send_params->input; |
0 | 152 |
153 //printf("hoge"); | |
154 output_buff[cur] = allocate(send_params->head->size_out); | |
3 | 155 int size_in = send_params->head->size_in; |
156 int size_out = send_params->head->size_out; | |
0 | 157 |
158 //task******************************************** | |
159 | |
3 | 160 run(in, output_buff[cur], size_in, size_out); |
0 | 161 |
162 //end********************************************* | |
163 | |
164 dma_put(output_buff[cur], send_params->head->ea_out, send_params->head->size_out, out_tag[cur]); | |
165 | |
166 free(input_buff[cur]); | |
167 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
168 dma_wait_time += dma_wait(out_tag[cur] | out_tag[cur^1] ); |
0 | 169 free(output_buff[cur]); |
170 free(output_buff[cur^1]); | |
171 | |
172 spu_write_out_mbox(WANT_DATA); | |
173 //printf("[SPE] send mail\n"); | |
174 | |
175 }//if | |
176 }//if | |
177 //mail check end | |
178 | |
179 | |
180 }//while | |
181 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
182 printf("dma_wait_time %d\n",dma_wait_time); |
0 | 183 |
184 return 0; | |
185 | |
186 } | |
187 | |
188 | |
189 /*end*/ |