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