void simulate(FILE* fp, int setIndex, int lines, int blockBits) { //simulate cache memory struct cache_line** cache = build_cache(setIndex, lines); char blank; char Op; int addressVal; int offset; char buf[1000]; int hit = 0, miss = 0, eviction = 0; int setNumber; int tag; int tempHit, tempMiss, tempEvict; while (fgets(buf, sizeof(buf), fp) != NULL) { tempHit = tempMiss = tempEvict = 0; sscanf(buf, "%c %c %x,%d",&blank, &Op, &addressVal, &offset); if (blank == 'I') continue; setNumber = getSetIndex(addressVal, setIndex, blockBits); tag = addressVal >> (setIndex + blockBits); if (findCache(cache, setNumber, lines, tag)) { hit ++; tempHit ++; updateCache(setNumber, tag); } else { miss ++; tempMiss ++; tempEvict += replaceCache(cache, setNumber, lines, tag); } if (Op == 'M') { //if the operation is M, need to find cache again if (findCache(cache, setNumber, lines, tag)) { hit ++; tempHit ++; updateCache(setNumber, tag); } else { miss ++; tempMiss ++; tempEvict += replaceCache(cache, setNumber, lines, tag); } } eviction += tempEvict; if (verbose) printVerboseInfo(buf, tempHit, tempMiss, tempEvict); } //printf("%d %d %d\n", hit, miss, eviction); freeCache(cache); freeQueue(); printSummary(hit, miss, eviction); }
/*! \reimp */ void QModemPhoneBook::requestLimits( const QString& store ) { QModemPhoneBookCache *cache; // Find the cache entry associated with this store. cache = findCache( store ); // If the cache is fully loaded, then emit the result now. // If there is a password, then force a re-get of the phone book // because the new password may not be the same as the original. if ( cache->fullyLoaded && cache->passwd.isEmpty() ) { emit limits( store, cache->limits ); return; } // We need to requery the extents if the phone book was previously loaded. if ( cache->fullyLoaded ) { cache->fullyLoaded = false; cache->entries.clear(); cache->limits = QPhoneBookLimits(); sendQuery( cache ); } // We'll need a signal to be emitted once it is fully loaded. cache->needLimitEmit = true; }
/*! \reimp */ void QModemPhoneBook::flush( const QString& store ) { QModemPhoneBookCache *cache = findCache( store ); if ( cache->fullyLoaded ) { flushOperations( cache ); } }
/*! \reimp */ void QModemPhoneBook::setPassword ( const QString& store, const QString& password ) { QModemPhoneBookCache *cache = findCache( store, true, password ); cache->passwd = password; // Force the storage to be reselected upon the next operation, // to force the password to be sent. forceStorageUpdate(); }
/*! \reimp */ void QModemPhoneBook::remove( uint index, const QString& store, bool flush ) { QModemPhoneBookCache *cache = findCache( store ); QPhoneBookEntry entry; entry.setIndex( index ); cache->opers = new QModemPhoneBookOperation ( QModemPhoneBookOperation::Remove, entry, cache->opers ); if ( cache->fullyLoaded && flush ) { flushOperations( cache ); } }
/*! \reimp */ void QModemPhoneBook::update ( const QPhoneBookEntry& entry, const QString& store, bool flush ) { QModemPhoneBookCache *cache = findCache( store ); QPhoneBookEntry newEntry( entry ); newEntry.setNumber( fixPhoneBookNumber( entry.number() ) ); cache->opers = new QModemPhoneBookOperation ( QModemPhoneBookOperation::Update, newEntry, cache->opers ); if ( cache->fullyLoaded && flush ) { flushOperations( cache ); } }
/*! \reimp */ void QModemPhoneBook::clearPassword( const QString& store ) { QModemPhoneBookCache *cache = findCache( store ); cache->passwd = QString(); }