/* Guochun Shi * */ #include #include #include #include #include "spu/speinfo.h" #include #include #include #include extern spe_program_handle_t simple_spu; extern int ptn; #define SPU_THREADS 8 typedef struct pattern_s{ int id1; int id2; }pattern_t; pattern_t patterns[][4] ={ { {1, 3}, {5, 7}, {0, 2}, {4, 6} }, { {0,4}, {1,5}, {2,6}, {3,7} }, { {0,1}, {2,3}, {4,5}, {6,7} }, { {0,3}, {1,2}, {4,7}, {5,6}, }, { {0,7}, {1,6}, {2,5}, {3,4}, }, { {0,5}, {1,4}, {2,7}, {3,6}, }, { {0,6}, {1,7}, {2,4}, {3,5}, } }; int friend_spu[8]; void display_friend_spu(void) { int i; printf("We are testing pattern: \n"); for (i = 0; i < 4; i++){ printf("%d<->%d\n", i, friend_spu[i]); } } int process_pattern(pattern_t* p) { int i; for (i = 0; i < 4 ;i ++){ if (p[i].id1 < 0 || p[i].id1 > 7 || p[i].id2 < 0 || p[i].id2 > 7){ fprintf(stderr, "ERROR: invalid pattern\n"); return -1; } friend_spu[p[i].id1] = p[i].id2; friend_spu[p[i].id2] = p[i].id1; } return 0; } double gettime(void) { static struct timeval oldt; struct timeval t; double result; if (gettimeofday(&t, NULL) < 0){ fprintf(stderr, "ERROR: gettimeofday() failed\n"); return -1; } result = t.tv_sec - oldt.tv_sec + (t.tv_usec-oldt.tv_usec)*0.000001; oldt = t; return result; } int read_phys_id(long unsigned speid) { char filename[64]; FILE* file; int phys_id; char buf[32]; sprintf(filename, "/spu/spethread-%d-%lu/phys-id", getpid(), speid); file = fopen(filename, "r"); if (file == NULL){ fprintf(stderr, "ERROR: open file(%s) failed\n", filename); return -1; } if ( fread(buf,1, sizeof(buf), file) <= 0){ fprintf(stderr, "Reading file (%s) failed\n", filename); fclose(file); return -1; } if ( (sscanf(buf, "%x", &phys_id) <= 0) || (phys_id < 0)){ fprintf(stderr, "Scanning string (%s) failed\n", buf); fclose(file); return -1; } fclose(file); return phys_id; } int main(int argc, char **argv) { speid_t spe_ids[SPU_THREADS]; int i, status = 0; struct spe_info si[SPU_THREADS] __attribute__ ((aligned (128))); int phys_id; struct spe_event e = { .events = SPE_EVENT_MAILBOX, }; spe_gid_t gid; int msgdata; int ret; double t_start; double avetime; int bandwidth = 0; int maxpattern = sizeof(patterns)/sizeof(patterns[0]); (void)argc; (void)argv; processopt(argc, argv); if (ptn >= maxpattern){ printf("pattern out of range(%d, range[0-%d])\n", ptn, maxpattern-1); return -1; } process_pattern(patterns[ptn]); display_friend_spu(); gid = spe_create_group(SCHED_RR, 1, 1); if (gid == 0){ perror("Creating new group failed\n"); return 1; } for(i=0; i= 8 || phys_id < 0){ fprintf(stderr, "ERROR: undesired phys_id(%d)\n", phys_id); exit(1); } si[phys_id].rank = phys_id; si[phys_id].speid = (unsigned long)spe_ids[i]; si[phys_id].friend_spu = friend_spu[phys_id]; if ((si[phys_id].sig1 = spe_get_ps_area(spe_ids[i], SPE_SIG_NOTIFY_1_AREA)) == NULL){ printf("ERROR: spe_get_ps_area failed for sig1(%d)\n", errno); return -1; } /* if ((si[phys_id].control_area = spe_get_ps_area(spe_ids[i], SPE_CONTROL_AREA)) == NULL){ printf("ERROR: spe_get_ps_area failed for control area(%d)\n", errno); return -1; } */ if ( (si[phys_id].ls = spe_get_ls(spe_ids[i])) == NULL){ fprintf(stderr, "ERROR: get ls return NULL"); return -1; } } for (i = 0; i < SPU_THREADS; i++){ if (spe_write_in_mbox((speid_t)si[i].speid, SPU_THREADS) < 0 || spe_write_in_mbox((speid_t)si[i].speid, si[i].rank) < 0){ perror("ERROR: writing messages to spe failed\n"); exit(1); } } sleep(1); t_start = gettime(); for (i = 0; i < SPU_THREADS; i++){ if (spe_write_in_mbox((speid_t)si[i].speid, START_TEST) < 0 ){ perror("ERROR: writing Start test message to spe failed\n"); exit(1); } } bandwidth = 0; for ( i = 0 ; i < SPU_THREADS; i++){ e.gid = gid; ret = spe_get_event(&e, 1, -1); if (!ret ){ fprintf(stderr, "Got zero event\n"); exit(1); } if (e.revents != SPE_EVENT_MAILBOX){ fprintf(stderr, "spe_get_event: unexpected event%d\n", e.revents); exit(1); } msgdata = e.data; bandwidth += msgdata; } avetime = gettime(); //avetime = (gettime() - 0.000465)/NUM_TEST; printf("time spent %f, EIB bandwidth=%f GB/s\n", avetime, (8*BUFSIZE/avetime)*NUM_TEST*1.0e-9 ); /* Wait for SPU-thread to complete execution. */ for (i=0; i