/************************************************************ * returns the victim page that is to be removed. This will be * used bu LRU algorithm. *************************************************************/ char findVictimPage(){ struct frames *refFrame; refFrame = head; while (refFrame->next != NULL){ refFrame->refBitDecimalValue = binToDecimal(refFrame->refBitArray); refFrame = refFrame->next; } refFrame = head; int minimumVal = refFrame->refBitDecimalValue; char victim = refFrame->pageNum; while (refFrame->next != NULL){ if (minimumVal > refFrame->refBitDecimalValue){ minimumVal = refFrame->refBitDecimalValue; victim = refFrame->pageNum; } refFrame = refFrame->next; } return victim; }
/************************************************************* ************** LRU Page Replacement Algorithm **************** *************************************************************/ void LRURefPageReplacement(){ int numberOfPageFaults = 0,j; frame = malloc(sizeof(struct frames)); head = malloc(sizeof(struct frames)); tail = malloc(sizeof(struct frames)); head = frame; tail = frame; frame->next = NULL; frame->prev = head; frame->pageNum = inputSeq[0]; for (j=0;j<8;j++) frame->refBitArray[j] = 0; int i, isPageAlreadyExists = 0; frame->refBitDecimalValue = binToDecimal(frame->refBitArray); numberOfPageFaults += 1; for (i=0; i<strlen(inputSeq); i++){ if (isspace(inputSeq[i]) == 0){ isPageAlreadyExists = findPage(inputSeq[i]); if (isPageAlreadyExists == 1){ shiftBits(inputSeq[i]); }else if (isPageAlreadyExists == 0 && isFrameAvailable() == 1){ numberOfPageFaults += 1; framesLeft -= 1; addPageToTailOfFrame(inputSeq[i]); addShiftBits(inputSeq[i]); }else if (isPageAlreadyExists == 0 && isFrameAvailable() == 0){ numberOfPageFaults += 1; char victimPage = findVictimPage(); removeNodeFromFrame(victimPage); addPageToTailOfFrame(inputSeq[i]); addShiftBits(inputSeq[i]); } } } printf("\n# of page replacements with LRU-REF8 = %d\n",numberOfPageFaults-availableFrames); nbOfPageReplacementByAlgo = numberOfPageFaults-availableFrames; }
void MainWindow::obtainOptionsSelectedMainWindow() { // check binning int v = 0; if( ui->binningHorizontalRadio->isChecked() ) { v+=binToDecimal(7); } if( ui->mirrorRadio->isChecked() ) // mirror Additional 1 { v+=binToDecimal(5); } v += binToDecimal(4); // default createParameter(hBinR, v, hBinDV, parameters); if( ui->binningVerticalRadio->isChecked() ) { v+=binToDecimal(6); } v += vBinDV; // default createParameter(vBinR, v, vBinDV, parameters); // mirror and flip if( ui->mirrorRadio->isChecked() ) { createParameter(mirrorAdditionalR2, v+=binToDecimal(5)+binToDecimal(4), 0xB4, parameters); // mirror Addiontal 2 v+=binToDecimal(6); } if( ui->flipRadio->isChecked() ) { v+=binToDecimal(5); } // compression if( ui->compressionRadio->isChecked() ) { v+=binToDecimal(3); } v += mirrorVFlipDV; createParameter(mirrorVFlipR, v, mirrorVFlipDV, parameters); // nightmode if( ui->nightModeRadio->isChecked() ) { v+=binToDecimal(2); } v += nightModeDV; // default value createParameter(nightModeR, v, nightModeDV, parameters); //createParameter(compressionR, v, compressionDV, parameters); // AEC/AGC if( ui->manualModeAECRadio->isChecked() ) { v+=binToDecimal(2); v+=binToDecimal(0); } if( ui->manualModeAGCRadio->isChecked() ) { v+=binToDecimal(1); } createParameter(aecAGCVTSControlR, v, manualAECAGCDV, parameters); if( ui->manualModeAECRadio->isChecked() ) // check sliders/spin AEC : first with AEC { int vts = round( ( ui->automaticControlVTSSpin->text().toInt() ) * 25.0 * 1000 / 1944 ); int aec = round( ( ui->automaticControlAECSpin->text().toInt() ) * 25.0 * 1000 / 1944 ); std::string bVTS = decToBinaryString( vts ); std::string bAEC = decToBinaryString( aec ); // split binary string int temp = 0; // first 4 aec for( int i = 0; i < 4; i++ ) { if( bAEC.at(i) == '1' ) { v += binToDecimal(4-i); } } createParameter( aeclR1, v, manualAECAGCDV, parameters ); // vts with aec for( int i = 4; i < 12; i++ ) { if( bVTS.at(i-4) == '1' ) { temp += binToDecimal(11-i); } if( bAEC.at(i) == '1' ) { v += binToDecimal(11-i); } } createParameter( aeclR2, v, manualAECAGCDV, parameters ); createParameter( vtsR1, temp, manualVTSR1DV, parameters ); for( int i = 12; i < 16; i++ ) { if( bVTS.at(i-4) == '1' ) { temp += binToDecimal(19-i); } if( bAEC.at(i) == '1' ) { v += binToDecimal(19-i); } } createParameter( aeclR3, v, manualAECAGCDV, parameters ); // finish vts for( int i = 12; i < 16; i++ ) { if( bVTS.at(i) == '1' ) { temp += binToDecimal(15-i); } } createParameter( vtsR2, temp, manualVTSR2DV, parameters ); } if( ui->manualModeAGCRadio->isChecked() ) // AGC { std::string bAGC = decToBinaryString( ui->automaticControlAGCSpin->text().toInt() ); for( unsigned int i = 0; i < bAGC.length(); i++ ) { if( bAGC.at(i) == '1' ) { v += binToDecimal(16-i); } } createParameter( agcAECadjR2, v, manualAECAGCDV, parameters ); } }