X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fcbe%2Ftemplate%2Fspu_process_wrapper_template.c;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fcbe%2Ftemplate%2Fspu_process_wrapper_template.c;h=703518ee0db68636c4f65f49f5e09906349d5053;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/cbe/template/spu_process_wrapper_template.c b/dol/src/dol/visitor/cbe/template/spu_process_wrapper_template.c new file mode 100644 index 0000000..703518e --- /dev/null +++ b/dol/src/dol/visitor/cbe/template/spu_process_wrapper_template.c @@ -0,0 +1,150 @@ +/**************************************************************** + * Process Wrapper file + * Creator: lschor, 2008-10-30 + * Description: Wrapper for a specific SPE process + * + * Revision: + * - 2008-10-30: Created + * - 2008-11-08: Update to Double Buffering + * - 2008-11-15: Added Performance Estimation methods + */ + +// General includes +#include +extern "C" { + #include +} +#include +#include +#include + +// Include to allocate/free using for DMA transfers +#include "lib/malloc_align.h" +#include "lib/free_align.h" + +// Local includes +#include "common.h" +#include "lib/ProcessWrapper.h" +#include "lib/estimation.h" + +// Context file +static parm_context ctx __attribute__ ((aligned (128))); + +// Include of the process +//#include "@PROCESSNAME@.c" + +// Main application +int main(int speid , uint64_t argp) +{ +#ifdef MEASURE + // Start the decrementer for time measurement + spu_write_decrementer(MEASURE_START); +#endif + +#ifdef MEASURE_SPE + double t_dol_spe = spu_read_decrementer(); +#endif + + // reserve DMA tag ID + uint32_t tag_id; + if((tag_id=mfc_tag_reserve())==MFC_TAG_INVALID){ + printf("SPE: ERROR - can't reserve a tag ID\n"); return 1; + } + + + // Get the context information for the whole system + mfc_get((void*) &ctx, argp, sizeof(ctx), tag_id, 0, 0); + mfc_write_tag_mask(1<number_of_ports = ctx.number_of_ports; + wrapper->port_id = port_id; + wrapper->port_queue_id = port_queue_id; + wrapper->is_detached = 0; + wrapper->name = (char *)_malloc_align((uint32_t)ctx.processNameLen, 4); + mfc_get((void *)wrapper->name, ctx.processName, ctx.processNameLen, tag_id, 0, 0); + waittag(tag_id); + + + //initialize the index array + int i; + wrapper->index = (uint32_t *)malloc(4 * sizeof(int)); + for (i = 0; i < 4; i++) + { + wrapper->index[i] = getIndex(wrapper->name, "_", i); + } + + // Init the queues for local buffering in the LS + // Only the queues we really need + initQueues(); + + // DOL process + DOLProcess* process; + struct _local_states *state; + + process = (DOLProcess *)malloc(sizeof(DOLProcess)); + state = (struct _local_states *)malloc(sizeof(struct _local_states)); + + memcpy(process, &@PROCESSNAME@, sizeof(DOLProcess)); + memcpy(state, @PROCESSNAME@.local, sizeof(struct _local_states)); + process->local = state; + process->wptr = wrapper; + + // Init the process +#ifdef MEASURE_DOL_INIT + double t_dol_init = spu_read_decrementer(); +#endif + process->init(process); +#ifdef MEASURE_DOL_INIT + t_dol_init -= spu_read_decrementer(); + printf("DOL_INIT;%f\n",t_dol_init * 1 / MEASURE_CPU); +#endif + + // Run the process + while (!wrapper->is_detached) + { + #ifdef MEASURE_DOL_FIRE + double t_dol_fire = spu_read_decrementer(); + #endif + + process->fire(process); + + #ifdef MEASURE_DOL_FIRE + t_dol_fire -= spu_read_decrementer(); + printf("DOL_FIRE;%f\n",t_dol_fire * 1 / MEASURE_CPU); + #endif + } + + // Delete all malloc memory + free(state); + free(process); + _free_align(wrapper->name); + free(wrapper); + + // release tag ID before exiting + mfc_tag_release(tag_id); + + + // Inform the main process that we have finished! + spu_write_out_mbox((uint32_t)(4)); + +#ifdef MEASURE_SPE + t_dol_spe -= spu_read_decrementer(); + printf("DOL_SPE_@PROCESSNAME@;%f\n",t_dol_spe * 1 / MEASURE_CPU); +#endif + + return 0; +} + +