112601Sodanrc@yahoo.com.br/** 212601Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312601Sodanrc@yahoo.com.br * All rights reserved. 412601Sodanrc@yahoo.com.br * 512601Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612601Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712601Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812601Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912601Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012601Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112601Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212601Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312601Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412601Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512601Sodanrc@yahoo.com.br * 1612601Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712601Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812601Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912601Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012601Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112601Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212601Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312601Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412601Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512601Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612601Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712601Sodanrc@yahoo.com.br * 2812601Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912601Sodanrc@yahoo.com.br */ 3012601Sodanrc@yahoo.com.br 3112601Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/mru_rp.hh" 3212601Sodanrc@yahoo.com.br 3312727Snikos.nikoleris@arm.com#include <cassert> 3412684Sodanrc@yahoo.com.br#include <memory> 3512601Sodanrc@yahoo.com.br 3612727Snikos.nikoleris@arm.com#include "params/MRURP.hh" 3712727Snikos.nikoleris@arm.com 3812601Sodanrc@yahoo.com.brMRURP::MRURP(const Params *p) 3912601Sodanrc@yahoo.com.br : BaseReplacementPolicy(p) 4012601Sodanrc@yahoo.com.br{ 4112601Sodanrc@yahoo.com.br} 4212601Sodanrc@yahoo.com.br 4312601Sodanrc@yahoo.com.brvoid 4412684Sodanrc@yahoo.com.brMRURP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data) 4512684Sodanrc@yahoo.com.brconst 4612601Sodanrc@yahoo.com.br{ 4712684Sodanrc@yahoo.com.br // Reset last touch timestamp 4812684Sodanrc@yahoo.com.br std::static_pointer_cast<MRUReplData>( 4912684Sodanrc@yahoo.com.br replacement_data)->lastTouchTick = Tick(0); 5012601Sodanrc@yahoo.com.br} 5112601Sodanrc@yahoo.com.br 5212601Sodanrc@yahoo.com.brvoid 5312684Sodanrc@yahoo.com.brMRURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const 5412601Sodanrc@yahoo.com.br{ 5512684Sodanrc@yahoo.com.br // Update last touch timestamp 5612684Sodanrc@yahoo.com.br std::static_pointer_cast<MRUReplData>( 5712684Sodanrc@yahoo.com.br replacement_data)->lastTouchTick = curTick(); 5812601Sodanrc@yahoo.com.br} 5912601Sodanrc@yahoo.com.br 6012684Sodanrc@yahoo.com.brvoid 6112684Sodanrc@yahoo.com.brMRURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const 6212684Sodanrc@yahoo.com.br{ 6312684Sodanrc@yahoo.com.br // Set last touch timestamp 6412684Sodanrc@yahoo.com.br std::static_pointer_cast<MRUReplData>( 6512684Sodanrc@yahoo.com.br replacement_data)->lastTouchTick = curTick(); 6612684Sodanrc@yahoo.com.br} 6712684Sodanrc@yahoo.com.br 6812684Sodanrc@yahoo.com.brReplaceableEntry* 6912684Sodanrc@yahoo.com.brMRURP::getVictim(const ReplacementCandidates& candidates) const 7012601Sodanrc@yahoo.com.br{ 7112601Sodanrc@yahoo.com.br // There must be at least one replacement candidate 7212601Sodanrc@yahoo.com.br assert(candidates.size() > 0); 7312601Sodanrc@yahoo.com.br 7412601Sodanrc@yahoo.com.br // Visit all candidates to find victim 7512684Sodanrc@yahoo.com.br ReplaceableEntry* victim = candidates[0]; 7612601Sodanrc@yahoo.com.br for (const auto& candidate : candidates) { 7712684Sodanrc@yahoo.com.br // Update victim entry if necessary 7812684Sodanrc@yahoo.com.br if (std::static_pointer_cast<MRUReplData>( 7912684Sodanrc@yahoo.com.br candidate->replacementData)->lastTouchTick > 8012684Sodanrc@yahoo.com.br std::static_pointer_cast<MRUReplData>( 8112684Sodanrc@yahoo.com.br victim->replacementData)->lastTouchTick) { 8212684Sodanrc@yahoo.com.br victim = candidate; 8312601Sodanrc@yahoo.com.br } 8412601Sodanrc@yahoo.com.br } 8512601Sodanrc@yahoo.com.br 8612684Sodanrc@yahoo.com.br return victim; 8712684Sodanrc@yahoo.com.br} 8812601Sodanrc@yahoo.com.br 8912684Sodanrc@yahoo.com.brstd::shared_ptr<ReplacementData> 9012684Sodanrc@yahoo.com.brMRURP::instantiateEntry() 9112684Sodanrc@yahoo.com.br{ 9212684Sodanrc@yahoo.com.br return std::shared_ptr<ReplacementData>(new MRUReplData()); 9312601Sodanrc@yahoo.com.br} 9412601Sodanrc@yahoo.com.br 9512601Sodanrc@yahoo.com.brMRURP* 9612601Sodanrc@yahoo.com.brMRURPParams::create() 9712601Sodanrc@yahoo.com.br{ 9812601Sodanrc@yahoo.com.br return new MRURP(this); 9912601Sodanrc@yahoo.com.br} 100