00001 #include <malloc_align.h>
00002 #include <free_align.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005
00006 #include <moc.h>
00007 #include <ppu/moc.h>
00008 #include <internal/imoc.h>
00009 #include <internal/ppu/imoc_core_ppu.h>
00010
00011 int MOC_Init(int *argc __attribute__((unused)), char ***argv __attribute__((unused)) )
00012 {
00013 int i;
00014 char temp[16];
00015 uint32_t temp2[1];
00016
00017 node_handle.rank = 0;
00018 node_handle.comm_size = moc_spu_thread_count + 1;
00019 node_handle.queue_size = moc_spu_queue_size;
00020 node_handle.message_queue_base = _malloc_align(
00021 sizeof(moc_message_envelope_t) * (node_handle.comm_size - 1)
00022 * node_handle.queue_size, 4);
00023 if (node_handle.message_queue_base == 0)
00024 return MOC_ERR_NO_MEMORY;
00025 node_handle.status_array_base = _malloc_align(sizeof(moc_message_status_t)
00026 * (node_handle.comm_size - 1) * node_handle.queue_size, 4);
00027 if (node_handle.status_array_base == 0)
00028 return MOC_ERR_NO_MEMORY;
00029 node_handle.buffer_base = _malloc_align(moc_spu_buffer_size, 4);
00030 if (node_handle.buffer_base == 0)
00031 return MOC_ERR_NO_MEMORY;
00032 node_handle.buffer_size = moc_spu_buffer_size;
00033 node_handle.signal_area = _malloc_align(16, 4);
00034 if (node_handle.signal_area == 0)
00035 return MOC_ERR_NO_MEMORY;
00036
00037 node_handle.moc_process_list = _malloc_align(sizeof(moc_process_t)
00038 * node_handle.comm_size, 7);
00039 if (node_handle.moc_process_list == 0)
00040 return MOC_ERR_NO_MEMORY;
00041 node_handle.moc_process_list[0].type = MOC_PPU_PROCESS;
00042 node_handle.moc_process_list[0].inbox_queue_base
00043 = (uint64_t) node_handle.message_queue_base;
00044 node_handle.moc_process_list[0].stat_array_base
00045 = (uint64_t) node_handle.status_array_base;
00046 node_handle.moc_process_list[0].ps_base
00047 = (uint64_t) node_handle.signal_area;
00048 moc_ppu_thread_count = 1;
00049
00050 for (i = 0; i < moc_spu_thread_count; i++)
00051 {
00052 moc_spu_thread_list[i].envp = NULL;
00053 moc_spu_thread_list[i].rank = i + moc_ppu_thread_count;
00054
00055 if (pthread_create(&moc_spu_thread_list[i].pthread, NULL,
00056 &moc_spe_pthread_func, &moc_spu_thread_list[i]) != 0)
00057 return MOC_ERR_INTERN;
00058
00059 moc_spu_thread_list[i].buffer_base = _malloc_align(moc_spu_buffer_size,
00060 4);
00061 if (moc_spu_thread_list[i].buffer_base == 0)
00062 return MOC_ERR_NO_MEMORY;
00063 moc_spu_thread_list[i].buffer_size = moc_spu_buffer_size;
00064
00065 node_handle.moc_process_list[i + moc_ppu_thread_count].type
00066 = MOC_SPU_PROCESS;
00067 node_handle.moc_process_list[i + moc_ppu_thread_count].ps_base
00068 = (uint64_t) spe_ps_area_get(moc_spu_thread_list[i].speid,
00069 SPE_MSSYNC_AREA);
00070 if (node_handle.moc_process_list[i + moc_ppu_thread_count].ps_base == 0)
00071 return MOC_ERR_INTERN;
00072 moc_spu_thread_list[i].ls_base = (uint64_t) spe_ls_area_get(
00073 moc_spu_thread_list[i].speid);
00074 if (moc_spu_thread_list[i].ls_base == 0)
00075 return MOC_ERR_INTERN;
00076 node_handle.moc_process_list[i + moc_ppu_thread_count].inbox_queue_base
00077 = (uint64_t) moc_spu_thread_list[i].ls_base;
00078 node_handle.moc_process_list[i + moc_ppu_thread_count].stat_array_base
00079 = (uint64_t) moc_spu_thread_list[i].ls_base;
00080
00081
00082
00083 temp[0] = i + moc_ppu_thread_count;
00084 temp[1] = node_handle.comm_size;
00085 temp[2] = node_handle.queue_size;
00086 *((uint32_t*) &temp[4]) = moc_spu_thread_list[i].buffer_size;
00087 *((uint64_t*) &temp[8]) = (uint64_t) moc_spu_thread_list[i].buffer_base;
00088 if (spe_in_mbox_write(moc_spu_thread_list[i].speid, (uint32_t*) temp,
00089 4, SPE_MBOX_ALL_BLOCKING) != 4)
00090 return MOC_ERR_INTERN;
00091
00092 *((uint64_t*) temp) = (uint64_t) spe_ls_area_get(
00093 moc_spu_thread_list[i].speid);
00094 if (spe_in_mbox_write(moc_spu_thread_list[i].speid, (uint32_t*) temp,
00095 2, SPE_MBOX_ALL_BLOCKING) != 2)
00096 return MOC_ERR_INTERN;
00097
00098 while (spe_out_mbox_status(moc_spu_thread_list[i].speid) < 1)
00099 ;
00100 if (spe_out_mbox_read(moc_spu_thread_list[i].speid, temp2, 1) != 1)
00101 return MOC_ERR_INTERN;
00102
00103 node_handle.moc_process_list[i + moc_ppu_thread_count].inbox_queue_base
00104 += temp2[0];
00105 moc_spu_thread_list[i].queue_base_in_ls = temp2[0];
00106
00107 while (spe_out_mbox_status(moc_spu_thread_list[i].speid) < 1)
00108 ;
00109 if (spe_out_mbox_read(moc_spu_thread_list[i].speid, temp2, 1) != 1)
00110 return MOC_ERR_INTERN;
00111
00112 node_handle.moc_process_list[i + moc_ppu_thread_count].stat_array_base
00113 += temp2[0];
00114 moc_spu_thread_list[i].status_base_in_ls = temp2[0];
00115 }
00116
00117 for (i = 0; i < moc_spu_thread_count; i++)
00118 {
00119 *((uint64_t*) temp2) = (uint64_t) node_handle.moc_process_list;
00120 if (spe_in_mbox_write(moc_spu_thread_list[i].speid, temp2, 2,
00121 SPE_MBOX_ALL_BLOCKING) != 2)
00122 return MOC_ERR_INTERN;
00123 }
00124 return 0;
00125 }
00126