void *worker_thread(void *pmyid) { long myid, validateLength, length, i, j, k, l, m; float sum; float *src1, *src2, *dst; float *asrc1, *asrc2, *adst; myid = (long) pmyid; printf("THREAD#%02ld START!!!\n", myid); //cpu affinity pinCPU(pmyid); //init and alloc mem_alloc_init(pmyid); //sync-point // worker_thread_sync(pmyid); //do-work matmul_c(pmyid); //validate matmul_validate(pmyid); //clean-up mem_dealloc(pmyid); if(DODEBUG) fflush(stdout); printf("THREAD#%02ld END!!!\n", myid); if(DODEBUG) fflush(stdout); if(myid) pthread_exit((void*)pmyid); }
int main(int argc, char** argv) { struct sched_param sp; pthread_t bgth; if ( argc != 3 && argc != 5 ) { usage(); return -1; } unsigned int coreID = 0; unsigned int startFreq = 0; unsigned int targetFreq = 0; unsigned int argcCounter = 1; // Option for core specification if ( strcmp(argv[1],"-c")==0 ) { if ( sscanf(argv[2],"%u",&coreID) != 1 ) { fprintf(stderr,"Fail to get the core ID argument\n"); return -2; } argcCounter +=2; if ( argc != 5 ) { fprintf(stderr,"Missing frequencies arguments\n"); usage(); return -1; } } if ( sscanf(argv[argcCounter],"%u",&startFreq) != 1 ) { fprintf(stderr,"Fail to get the start frequency argument\n"); return -3; } if ( sscanf(argv[argcCounter+1],"%u",&targetFreq) != 1 ) { fprintf(stderr,"Fail to get the target freq argument\n"); return -4; } // Additional checks if ( coreID >= getCoreNumber() ) { fprintf(stdout,"The core ID that user gave is invalid\n"); fprintf(stdout,"Core ID is set to 0\n"); coreID = 0; } initFreqInfo(); if ( isFreqAvailable(coreID,startFreq) == 0 ) { fprintf(stdout,"The starting frequency that you have entered (%d) is not available for the core %d\n",startFreq,coreID); fprintf(stdout,"Aborting"); cleanup(); return -6; } if ( isFreqAvailable(coreID,targetFreq) == 0 ) { fprintf(stdout,"The target frequency that you have entered (%d) is not available for the core %d\n",targetFreq,coreID); fprintf(stdout,"Aborting"); cleanup(); return -7; } initCoreRelations(); #ifdef _DUMP openDump("./results.dump",NB_TRY_REPET_LOOP*NB_VALIDATION_REPET); #endif // stay on cpu 2 pinCPU(coreID); // create a background task to keep CPU awaken pthread_create(&bgth, NULL, thfn, NULL); // go realtime, max prio sched_getparam(0, &sp); sp.sched_priority = sched_get_priority_max(SCHED_FIFO); if (sched_setscheduler(0, SCHED_FIFO, &sp)) { perror("setscheduler background"); } if ( setCPUGovernor("userspace") != 0 ) { fprintf(stderr,"We are unable to set \"userspace\" governor. Do you have cpufreq and permissions ?\n"); cleanup(); return -5; } // Set the minimal frequency if ( openFreqSetterFiles() != 0 ) { cleanup(); return -3; } setFreqForAllRelatedCore(coreID,getMinAvailableFreq(coreID)); runTest(startFreq, targetFreq, coreID); // kill bg thread pthread_cancel(bgth); cleanup(); return 0; }