/* author: Guochun Shi */ #include #include #include #include #include #include #include #include extern spe_program_handle_t simple_spu; double gettime(void) { struct timeval t; double result; if (gettimeofday(&t, NULL) < 0){ fprintf(stderr, "ERROR: gettimeofday() failed\n"); return -1; } result = t.tv_sec + t.tv_usec*0.000001; return result; } pthread_t spe_pthread_ids; spe_context_ptr_t spe; void* my_spe_thread(void* _arg){ spe_context_ptr_t specontext = (spe_context_ptr_t)_arg; unsigned int runflags = 0; unsigned int entry = SPE_DEFAULT_ENTRY; spe_context_run(specontext, &entry, runflags, NULL, NULL, NULL); pthread_exit(NULL); return NULL; } int main() { int i; double t0, t1; int iterations = 1000000; int rc; spe = spe_context_create( SPE_MAP_PS, NULL); spe_program_load(spe, &simple_spu); rc = pthread_create(&spe_pthread_ids, NULL, &my_spe_thread, spe); if (rc != 0){ perror("Unable to create pthread for spe"); return -1; } spe_spu_control_area_t* ps_area; ps_area = (spe_spu_control_area_t *)spe_ps_area_get(spe, SPE_CONTROL_AREA); t0 = gettime(); /* now start the latency test*/ for (i =0;i < iterations; i++){ _spe_in_mbox_write(ps_area, 0); _spe_out_mbox_read(ps_area); } t1 = gettime(); printf("latency=%.2f us\n", 1000000*(t1 - t0)/iterations); return (0); }