Mercurial > hg > Game > Cerium
annotate TaskManager/Cell/SpeThreads.cc @ 1015:29355ae40e6c draft
debug mail timing.
author | yutaka@localhost.localdomain |
---|---|
date | Fri, 05 Nov 2010 22:25:33 +0900 |
parents | a75ccd570a57 |
children | 806b4658ced6 |
rev | line source |
---|---|
109 | 1 #include <stdlib.h> |
76 | 2 #include "types.h" |
65 | 3 #include "SpeThreads.h" |
736 | 4 #include "Scheduler.h" |
65 | 5 |
824 | 6 |
806 | 7 SpeThreads::SpeThreads(int num) : cpu_num(num) {} |
65 | 8 |
76 | 9 SpeThreads::~SpeThreads(void) |
10 { | |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
11 memaddr mail = (memaddr)MY_SPE_COMMAND_EXIT; |
76 | 12 int ret; |
13 | |
806 | 14 for (int i = 0; i < cpu_num; i++) { |
244 | 15 send_mail(i, 1, &mail); |
76 | 16 } |
17 | |
806 | 18 for (int i = 0; i < cpu_num; i++) { |
76 | 19 pthread_join(threads[i], NULL); |
20 ret = spe_context_destroy(spe_ctx[i]); | |
21 if (ret) { | |
22 perror("[~SpeThreads] spe_context_destroy"); | |
23 } | |
24 } | |
25 | |
26 spe_image_close(spe_handle); | |
27 | |
28 delete [] spe_ctx; | |
29 delete [] threads; | |
30 delete [] args; | |
31 } | |
32 | |
65 | 33 void* |
34 SpeThreads::spe_thread_run(void *arg) | |
35 { | |
36 unsigned int entry = SPE_DEFAULT_ENTRY; | |
109 | 37 //spe_context_ptr_t ctx = (spe_context_ptr_t)arg; |
38 thread_arg_t *arg_t = (thread_arg_t *)arg; | |
39 | |
40 spe_stop_info_t stop_info; | |
41 unsigned long long status; | |
42 | |
43 spe_context_run(arg_t->ctx, &entry, 0, (void*)arg_t->speid, NULL, &stop_info); | |
65 | 44 |
109 | 45 status = ((stop_info.result.spe_exit_code & 0xff) << 8) |
46 | (stop_info.result.spe_signal_code & 0xff); | |
47 | |
48 switch(stop_info.stop_reason) { | |
736 | 49 case SPE_EXIT: |
109 | 50 break; |
51 case SPE_STOP_AND_SIGNAL: | |
194 | 52 printf("[SPE %d] SPE_STOP_AND_SIGNAL stop_info.result.stop_signal_code=%d\n", arg_t->speid, stop_info.result.spe_signal_code); |
109 | 53 break; |
54 case SPE_RUNTIME_ERROR: | |
194 | 55 printf("[SPE %d] SPE_RUNTIME_ERROR stop_info.result.spe_runtime_error=%d\n", arg_t->speid, stop_info.result.spe_runtime_error); |
109 | 56 break; |
57 case SPE_RUNTIME_EXCEPTION: | |
194 | 58 printf("[SPE %d] SPE_RUNTIME_EXCEPTION stop_info.result.spe_runtime_exception=%d\n", arg_t->speid, stop_info.result.spe_runtime_exception); |
109 | 59 break; |
60 } | |
65 | 61 |
62 pthread_exit(NULL); | |
63 } | |
64 | |
65 void* | |
66 SpeThreads::frontend_thread_run(void *arg) | |
67 { | |
68 pthread_t thread; | |
69 thread_arg_t *arg_t = (thread_arg_t *)arg; | |
70 | |
71 pthread_create(&thread, NULL, &spe_thread_run, (void*)arg_t->ctx); | |
72 | |
321 | 73 // mail read の blocking ができれば |
74 // ここで呼んだ方が早い。 | |
76 | 75 |
65 | 76 pthread_exit(NULL); |
77 } | |
78 | |
79 void | |
80 SpeThreads::init(void) | |
81 { | |
109 | 82 spe_handle = spe_image_open(SPE_ELF); |
65 | 83 |
109 | 84 if (spe_handle == NULL) { |
85 perror("spe_image_open"); | |
86 exit(EXIT_FAILURE); | |
87 } | |
65 | 88 |
806 | 89 spe_ctx = new spe_context_ptr_t[cpu_num]; |
90 threads = new pthread_t[cpu_num]; | |
91 args = new thread_arg_t[cpu_num]; | |
65 | 92 |
806 | 93 for (int i = 0; i < cpu_num; i++) { |
65 | 94 args[i].speid = i; |
95 spe_ctx[i] = spe_context_create(0, NULL); | |
96 spe_program_load(spe_ctx[i], spe_handle); | |
97 args[i].ctx = spe_ctx[i]; | |
98 } | |
99 | |
806 | 100 for (int i = 0; i < cpu_num; i++) { |
109 | 101 pthread_create(&threads[i], NULL, |
102 &spe_thread_run, (void*)&args[i]); | |
65 | 103 } |
104 } | |
105 | |
244 | 106 |
109 | 107 /** |
321 | 108 * SPE からのメールを受信する。 |
109 | 109 * |
110 * @param [speid] SPE ID | |
111 * | |
112 * @return Received 32-bit mailbox messages | |
113 * if ([ret] < 0) no data read | |
114 */ | |
621 | 115 int |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
116 SpeThreads::get_mail(int speid, int count, memaddr *ret) |
244 | 117 { |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
118 // only used in CellTaskManagerImpl (should be removed?) |
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
119 return spe_out_mbox_read(spe_ctx[speid], (unsigned int*)ret, count*(sizeof(memaddr)/sizeof(int))); |
244 | 120 } |
121 | |
621 | 122 int |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
631
diff
changeset
|
123 SpeThreads::has_mail(int speid, int count, memaddr *ret) |
65 | 124 { |
321 | 125 /* |
126 * spe_out_mbox_status return only 1, waiting for multiple length | |
127 * does not work. | |
128 */ | |
604 | 129 if (spe_out_mbox_status(spe_ctx[speid]) >= 1) { |
1015 | 130 return spe_out_mbox_read(spe_ctx[speid], (unsigned int*)ret, count*(sizeof(memaddr)/sizeof(int))); |
244 | 131 } else { |
132 return 0; | |
133 } | |
65 | 134 } |
66 | 135 |
109 | 136 /** |
137 * Inbound Mailbox | |
321 | 138 * メール送信 PPE -> SPE |
109 | 139 * |
321 | 140 * なるべく NONBLOCKING なんだけど、 |
141 * Inbound Mailbox キューに空きがないと送信できないので | |
142 * 送信する数だけ空いているか確認してから送る。空いて無い場合は待つ。 | |
161
18c42658e0e7
texture の座標がマイナスになったあと、それを 0 にし忘れてた
gongo@localhost.localdomain
parents:
109
diff
changeset
|
143 * |
321 | 144 * 結局待つんだよな。しかも ALL_BLOCKING って実は busy wait だったりするし |
109 | 145 * |
146 * @param [speid] SPE ID | |
147 * @param [data] Send 32-bit mailbox messages | |
148 * @param [num] The number of messages | |
149 */ | |
66 | 150 void |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
151 SpeThreads::send_mail(int speid, int num, memaddr *data) |
614 | 152 |
244 | 153 { |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
154 spe_in_mbox_write(spe_ctx[speid], (unsigned int *)data, num*(sizeof(memaddr)/sizeof(int)), SPE_MBOX_ALL_BLOCKING); |
244 | 155 } |
156 | |
157 void | |
631
30dd8a3deb4a
Cell 64 bit tried, but not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
158 SpeThreads::add_output_tasklist(int command, memaddr buff, int alloc_size) |
66 | 159 { |
244 | 160 /* |
321 | 161 * output TaskList が無ければ新しく作る |
162 * あれば TaskList に allocate した Task を追加 | |
163 * command に対応した Task の初期化を実行する | |
164 * SPE に data が書き出し終わった後に PPE 側で初期化 | |
244 | 165 */ |
166 | |
66 | 167 } |
604 | 168 |
169 /* end */ |