bip_rp.cc revision 12727
112634Sodanrc@yahoo.com.br/**
212634Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria
312634Sodanrc@yahoo.com.br * All rights reserved.
412634Sodanrc@yahoo.com.br *
512634Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without
612634Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are
712634Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright
812634Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer;
912634Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright
1012634Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the
1112634Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution;
1212634Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its
1312634Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from
1412634Sodanrc@yahoo.com.br * this software without specific prior written permission.
1512634Sodanrc@yahoo.com.br *
1612634Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712634Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812634Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912634Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012634Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112634Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212634Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312634Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412634Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512634Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612634Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712634Sodanrc@yahoo.com.br *
2812634Sodanrc@yahoo.com.br * Authors: Daniel Carvalho
2912634Sodanrc@yahoo.com.br */
3012634Sodanrc@yahoo.com.br
3112634Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/bip_rp.hh"
3212634Sodanrc@yahoo.com.br
3312684Sodanrc@yahoo.com.br#include <memory>
3412684Sodanrc@yahoo.com.br
3512634Sodanrc@yahoo.com.br#include "base/random.hh"
3612727Snikos.nikoleris@arm.com#include "params/BIPRP.hh"
3712634Sodanrc@yahoo.com.br
3812634Sodanrc@yahoo.com.brBIPRP::BIPRP(const Params *p)
3912634Sodanrc@yahoo.com.br    : LRURP(p), btp(p->btp)
4012634Sodanrc@yahoo.com.br{
4112634Sodanrc@yahoo.com.br}
4212634Sodanrc@yahoo.com.br
4312634Sodanrc@yahoo.com.brvoid
4412684Sodanrc@yahoo.com.brBIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
4512634Sodanrc@yahoo.com.br{
4612684Sodanrc@yahoo.com.br    std::shared_ptr<LRUReplData> casted_replacement_data =
4712684Sodanrc@yahoo.com.br        std::static_pointer_cast<LRUReplData>(replacement_data);
4812634Sodanrc@yahoo.com.br
4912684Sodanrc@yahoo.com.br    // Entries are inserted as MRU if lower than btp, LRU otherwise
5012634Sodanrc@yahoo.com.br    if (random_mt.random<unsigned>(1, 100) <= btp) {
5112684Sodanrc@yahoo.com.br        casted_replacement_data->lastTouchTick = curTick();
5212634Sodanrc@yahoo.com.br    } else {
5312634Sodanrc@yahoo.com.br        // Make their timestamps as old as possible, so that they become LRU
5412684Sodanrc@yahoo.com.br        casted_replacement_data->lastTouchTick = 1;
5512634Sodanrc@yahoo.com.br    }
5612634Sodanrc@yahoo.com.br}
5712634Sodanrc@yahoo.com.br
5812634Sodanrc@yahoo.com.brBIPRP*
5912634Sodanrc@yahoo.com.brBIPRPParams::create()
6012634Sodanrc@yahoo.com.br{
6112634Sodanrc@yahoo.com.br    return new BIPRP(this);
6212634Sodanrc@yahoo.com.br}
63