bool ReadAheadDecisionMaker::statCacheAccess(qulonglong address)
{
    qDebug() << "RA_try "<< address;
    if (address == getLastAddress()+1){
        // Sequental pattern match
        incrementCurrentAccessSequence();
        if ( isCurrentAccessSequenceEnughForRA()  ){
            // RA is turned ON
            enableReadAhead(true);
            setCurrentAccessSequence(0);
        }
    }else{
        // Sequental pattern breack
        setCurrentAccessSequence(0);
    }

    setLastAddress(address);

    checkReadAheadAddress(address);


    return isReadAheadOn();
}
Пример #2
0
/**
 * load
 * This function takes a command line argument containing
 * the name of a file and loads the contents of the file
 * into memory byte by byte until there is an error
 * @param: argc: the number of args
 *         args: the name of the file
 * @return: goodLine: returns false if an error was found
 */
bool load(int argc, char *args) {
    bool goodLine = TRUE; 
    int lineNumber = 1;
    if(validFileName(args)){
        FILE * fi;
        fi = fopen(args,"r");
        char record[80];      
        int prevAdr = -1,startAdr,lineSize;
        int firstLine = 0;
        int loop;
        int dataLoc,byteLoc;
        int dataLength;
        bool lastLineData;
        bool memError;
        while(fgets(record,80,fi)!=NULL && goodLine){
            dataLoc = 9;  //Where data starts
            byteLoc = 0;  //Which byte of data to get
            if (isAddress(record)){ 
                startAdr=setLastAddress(record); //Address in a record
            }
            int lineSize = lineLength(record); //Length of record
                
            if(record[lineSize]!='\n') {
                discardRest(record,fi);
            }
            
            //Calls the checkLine
            if(checkLine(record)) {
                dataLength = lengthOfData(record); //Length of data in a record
                
                //If the record isn't the first line of the file
                if(firstLine==1) {
                   if(!(lastLineData&&startAdr>prevAdr)) { //If there was data on the last line make sure the address is bigger
                      goodLine = FALSE;
                      //printf("Error on line %d\n",lineNumber);
                   }
                }
                //If the record is the first line
                else{
                    if(isAddress(record)) {
                        firstLine = 1;
                    }
                }
            }
            
            //checkLine returns false
            else{ 
                //printf("Error on line %d\n",lineNumber);
                goodLine = FALSE;
            }
            
            //If all checks have passed
            if(goodLine){
                //Goes through the data
                for(loop = 0; loop < dataLength;loop+=2){
                    //Adds the byte to memory
                    putByte(startAdr,grabDataByte(record,byteLoc),&memError);
                    //printf("%x\n",grabDataByte(record,byteLoc));
                    startAdr++;
                    byteLoc+=2;
                }
                //puts(record); //Output record
                prevAdr = startAdr - 1;
                lineNumber++;
                lastLineData = isData(record);
           } 
           else if(goodLine == FALSE){
               printf("Error on line %d\n", lineNumber);
               puts(record);
           }
      }   
        fclose(fi);
     }
     
     
     //If the file didn't open   
     else{
         goodLine = FALSE;
         printf("Error opening file");
     }
     
     
     return goodLine;

     
}