void AdvDiffPredictorCorrectorHierarchyIntegrator::integrateHierarchy( const double current_time, const double new_time, const int cycle_num) { AdvDiffHierarchyIntegrator::integrateHierarchy(current_time, new_time, cycle_num); const double dt = new_time - current_time; const double half_time = current_time+0.5*dt; const int coarsest_ln = 0; const int finest_ln = d_hierarchy->getFinestLevelNumber(); const bool initial_time = MathUtilities<double>::equalEps(d_integrator_time, d_start_time); VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); // Check to make sure that the number of cycles is what we expect it to be. const int expected_num_cycles = getNumberOfCycles(); if (d_current_num_cycles != expected_num_cycles) { IBAMR_DO_ONCE( { pout << "AdvDiffPredictorCorrectorHierarchyIntegrator::integrateHierarchy():\n" << " WARNING: num_cycles = " << d_current_num_cycles << " but expected num_cycles = " << expected_num_cycles << ".\n"; } );
int main(int argc, char **argv){ __u32 *pSrc; __u32 rawData; __u16 *pTgt, *pTgtoutput, *pRawData, *pErrFileDataoutput,*pErrFileData; __u32 *pRBData; //for the files that are opened int block, major, minor; FILE *frames; FILE *logfile; FILE *errfile; FILE *rbrawfile; FILE *rawfile; char pathandfilename[96]=""; char errpathandfilename[96]; char line[255]; char putline[255]; char foldername[96]=""; int data[212]; int frameaddress[3]; int *pframeaddress; __u16 rawdata[212]; int errfiledata[212]; int cycles, result,n, linecounter, cyclestoreach, i,erroroccured, cycleserrors, linenumber, linenumbercount, overallerrors; //for the time struct tm *l_time; time_t now; char mytime[20]; //for the Hardwareerrorregisters unsigned short hwnoferrorsreg; unsigned short hwnoflastframewitherr; unsigned short hwnoflastframe; unsigned short hwnofcycles; unsigned short hwstatusreg; unsigned short hwerrreg; char ReadbackRawFrameFilename[64]; char RawFrameFilename[64]; char ErrorFrameFilename[64]; pframeaddress = &frameaddress[0]; block = -1; major = -1; minor = -1; cycles = 0; cyclestoreach = 0; n = 0; i = 0; linecounter = 0; hwnoferrorsreg = 0; hwnoflastframewitherr = 0; hwnoflastframe = 0; hwnofcycles = 0; hwerrreg = 0; hwstatusreg = 0; erroroccured = 0; cycleserrors = 0; linenumber = 0; linenumbercount = 0; overallerrors = 0; //enable writing to the RCU initRcuAccess(NULL); //initialization of the registers result = init(); if(result < 0){ printf("Initialization failed: %d\n", result); return EXIT_FAILURE; } //create a logfile and write a header to it writeHeaderToLogfile(); // test for the number of parameters if((argc != 2) && (argc != 3)) { perror("usage: framever <frames> [Cycles]\n"); return EXIT_FAILURE; } // if no number of cycles is given use a default if(argv[2] == NULL){ cyclestoreach = 2; printf("No Parameter for Cycles given, using Cycles = 2\n"); } else{ cyclestoreach = atoi(argv[2]); printf("Using given parameter %d for Cycles.\n", cyclestoreach); } printf("CyclestoReach: %d\n", cyclestoreach); // count the number of frames to be handled linenumbercount = linenumber = getLinesnumberFromFile(argv[1]); //open frames.txt for reading if((frames=fopen(argv[1],"r")) < 0){ printf("Could not open %s for reading!\n",argv[1]); return EXIT_FAILURE; } //open logfile for writing if((logfile=fopen("log.txt","a+b")) < 0){ printf("Could not open %s for reading!\n",argv[1]); return EXIT_FAILURE; } else{ printf("writing to logfile log.txt.\n"); } sprintf(putline,"framever working on %d cycles.\n", cyclestoreach); fwrite(putline, strlen(putline), 1, logfile); //read and show the status registers hwnoferrorsreg = getErrorcounterReg(); hwnoflastframewitherr = getLastErrorFramenumber(); hwnoflastframe = getLastFramenumber(); hwnofcycles = getNumberOfCycles(); hwerrreg = readErrReg(); hwstatusreg = readStatusReg(); //printf("noferr: %d, lastframewitherr: %d, lastframe: %d, nofcycles: %d, ErrReg: %d, StatusReg: %d\n",hwnoferrorsreg, hwnoflastframewitherr, hwnoflastframe, hwnofcycles, hwerrreg, hwstatusreg); sprintf(putline,"Overview about the hardwareregisters before the actual work started:\n"); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Read Error Counter Register (0xb104) : %d\n", hwnoferrorsreg); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Last Frame with error (0xb105) : %d\n", hwnoflastframewitherr); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Last read out frame(0xb106) : %d\n",hwnoflastframe); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Error register (0xb101) : %#x\n", hwerrreg); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Status register (0xb100) : %#x\n\n", hwstatusreg); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Number of Frames found in %s : %d\n\n", argv[1], linenumber); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); //as long as there are frames to be read if(frames!=NULL){ //and as long as we havent reached the number of cycles to reach while(cycles < cyclestoreach){ //read out time for for the folder generation time(&now); l_time = localtime(&now); strftime(mytime, sizeof mytime, "%T", l_time); //generate the folder for this cycle sprintf(foldername,"cycle_%d_%s",cycles, mytime); result = mkdir(foldername, S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IROTH | S_IWOTH | S_IXOTH); if(result < 0){ printf("failed creating folder %s - Error %d\n",foldername, result); } sprintf(putline, "current cycle: %d\n=============================\n", cycles); //printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); strftime(mytime, sizeof mytime, "%D - %T%n", l_time); sprintf(putline,"%s", mytime); //printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); linenumbercount = linenumber; //if there is something to readout while(fgets(line,255,frames)!=NULL){ //read line from framesfile pframeaddress = &frameaddress[0]; getFrameAddressFromLine(line, pframeaddress); pframeaddress = &frameaddress[0]; block = frameaddress[0]; major = frameaddress[1]; minor = frameaddress[2]; if(block != -1){ //printf("processing %d, %d, %d\n",block, major, minor); sprintf(ReadbackRawFrameFilename,"frame%d.%d.%d.hex",block,major,minor); sprintf(ErrorFrameFilename,"Err_frame%d.%d.%d.hex",block,major,minor); sprintf(RawFrameFilename,"raw/frame%d.%d.%d.hex",block,major,minor); //prepare for reading out result = step(); if(result < 0) printf("rcuSingleWrite failed (0xb000, 0x0100), Error: %d\n",result); //read the data result = rcuMultipleRead(0xb41c, 212, data); //printf("read %d bytes from memory.\n",result); //get rid of the unused 16bit pSrc = (__u32*)&data[0]; pTgtoutput = pTgt = (__u16*)malloc(212*sizeof(__u16)); for(n=0;n<212;n++){ *pTgt=*((__u16*)pSrc); pTgt++; pSrc++; } //printf("%s\n",foldername); // generate the filename the data will be written to strcpy(pathandfilename,foldername); strcat(pathandfilename,"/"); strcat(pathandfilename,ReadbackRawFrameFilename); //printf("\n%s\n",pathandfilename); //write the readout data if((rbrawfile=fopen(pathandfilename,"w+b")) < 0){ printf("Error opening %s for ascii writing!\n",pathandfilename); return EXIT_FAILURE; } //printf("done writing raw data to %s.\n", pathandfilename); //clear the filename strcpy(pathandfilename,"\0"); //write the data to the file fwrite(pTgtoutput, sizeof(__u16), 212, rbrawfile); fclose(rbrawfile); //open the raw File for reading and comparison if((rawfile=fopen(RawFrameFilename,"r")) < 0){ printf("Error opening %s for reading!\n",RawFrameFilename); return EXIT_FAILURE; } fread(rawdata, sizeof(__u16), 212, rawfile); fclose(rawfile); // do an XOR with the read out data and the correct framefiles pRBData = (__u32*)&data[0]; pRawData = &rawdata[0]; pErrFileDataoutput = pErrFileData = (__u16*)&errfiledata[0]; for(i = 0; i < 212; i++){ *pErrFileData = ((*pRawData++))^((*pRBData++)); //analyze for errors and count them erroroccured += analyze16bit(*pErrFileData); *pErrFileData++; //fprintf(stderr, "data=%#x rawdata=%#x errordata=%#x\n", data[i], rawdata[i], errfiledata[i]); } //if a bitflip was detected create an Errorfile wich contains the XOR data if(erroroccured > 0){ //write the Errorfile strcpy(errpathandfilename,foldername); strcat(errpathandfilename,"/"); strcat(errpathandfilename,ErrorFrameFilename); printf("found error in frame %d,%d,%d, writing errors to file %s\n", block, major, minor, errpathandfilename); if((errfile=fopen(errpathandfilename,"w+b")) < 0){ printf("Error opening %s for reading!\n",ErrorFrameFilename); return EXIT_FAILURE; } fwrite(pErrFileDataoutput, sizeof(__u16), 212, errfile); fclose(errfile); } //read the status registers hwnoferrorsreg = getErrorcounterReg(); hwnoflastframewitherr = getLastErrorFramenumber(); hwnoflastframe = getLastFramenumber(); hwnofcycles = getNumberOfCycles(); hwerrreg = readErrReg(); hwstatusreg = readStatusReg(); /* if(hwerrreg != 0){ printf("Hardware Error Register shows %d! - aborting.",hwerrreg); return EXIT_FAILURE; } */ //print the Errorregisters to the logfile sprintf(putline, "current frame: %d, %d, %d - Framenumber: %d\n----------------------------\n", block, major, minor, linenumbercount-1); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Last read out frame(0xb106) : %d\n",hwnoflastframe); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Read Error Counter Register (0xb104): %d\n", hwnoferrorsreg); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Last Frame with error (0xb105) : %d\n", hwnoflastframewitherr); fwrite(putline, strlen(putline), 1, logfile); //sprintf(putline, "Error register (0xb101) : %#x %s\n", hwerrreg, getMeaningOfErrReg(hwerrreg)); sprintf(putline, "Error register (0xb101) : %#x\n", hwerrreg); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Status register (0xb100) : %#x\n", hwstatusreg); fwrite(putline, strlen(putline), 1, logfile); sprintf(putline, "Bitflips found in this frame : %d\n\n", erroroccured); fwrite(putline, strlen(putline), 1, logfile); //add up the errors for the whole cycle cycleserrors+=erroroccured; erroroccured = 0; // printf("Cycle: %d, noferr: %d, lastframewitherr: %d, lastframe: %d, nofcycles: %d, ErrReg: %d, StatusReg: %d\n",cycles, hwnoferrorsreg, hwnoflastframewitherr, hwnoflastframe, hwnofcycles, hwerrreg, hwstatusreg); //count the line Framenumbers like the hardware does linenumbercount--; clearErrReg(); } } //print detected bitflips to screen and logfile sprintf(putline, "Bitflips found in cycle %d : %d\n", cycles, cycleserrors); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); overallerrors+=cycleserrors; sprintf(putline, "Bitflips found so far : %d\n",overallerrors); printf("%s", putline); //reset and start new cycle cycleserrors=0; cycles++; rewind(frames); } } //print all detected erorrs and clean up sprintf(putline, "Bitflips found during %d cycles with %d frames : %d\n\n", cyclestoreach, linenumber, overallerrors); printf("%s", putline); fwrite(putline, strlen(putline), 1, logfile); fclose(logfile); printf("closed logfile\n"); free(pTgtoutput); printf("freed memory\n"); fclose(frames); printf("closed framefile\n"); // printf("closed rawfile\n"); releaseRcuAccess(); return EXIT_SUCCESS; }