sector_blk.cc revision 13224
113224Sodanrc@yahoo.com.br/** 213224Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 313224Sodanrc@yahoo.com.br * All rights reserved. 413224Sodanrc@yahoo.com.br * 513224Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 613224Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 713224Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 813224Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 913224Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1013224Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1113224Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1213224Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1313224Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1413224Sodanrc@yahoo.com.br * this software without specific prior written permission. 1513224Sodanrc@yahoo.com.br * 1613224Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713224Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813224Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913224Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013224Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113224Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213224Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313224Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413224Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513224Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613224Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713224Sodanrc@yahoo.com.br * 2813224Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2913224Sodanrc@yahoo.com.br */ 3013224Sodanrc@yahoo.com.br 3113224Sodanrc@yahoo.com.br/** @file 3213224Sodanrc@yahoo.com.br * Implementation of a simple sector block class. Each sector consists of a 3313224Sodanrc@yahoo.com.br * sequence of cache blocks that may or may not be present in the cache. 3413224Sodanrc@yahoo.com.br */ 3513224Sodanrc@yahoo.com.br 3613224Sodanrc@yahoo.com.br#include "mem/cache/tags/sector_blk.hh" 3713224Sodanrc@yahoo.com.br 3813224Sodanrc@yahoo.com.br#include <cassert> 3913224Sodanrc@yahoo.com.br 4013224Sodanrc@yahoo.com.br#include "base/cprintf.hh" 4113224Sodanrc@yahoo.com.br#include "base/logging.hh" 4213224Sodanrc@yahoo.com.br 4313224Sodanrc@yahoo.com.brvoid 4413224Sodanrc@yahoo.com.brSectorSubBlk::setSectorBlock(SectorBlk* sector_blk) 4513224Sodanrc@yahoo.com.br{ 4613224Sodanrc@yahoo.com.br assert(sector_blk != nullptr); 4713224Sodanrc@yahoo.com.br _sectorBlk = sector_blk; 4813224Sodanrc@yahoo.com.br} 4913224Sodanrc@yahoo.com.br 5013224Sodanrc@yahoo.com.brconst SectorBlk* 5113224Sodanrc@yahoo.com.brSectorSubBlk::getSectorBlock() const 5213224Sodanrc@yahoo.com.br{ 5313224Sodanrc@yahoo.com.br return _sectorBlk; 5413224Sodanrc@yahoo.com.br} 5513224Sodanrc@yahoo.com.br 5613224Sodanrc@yahoo.com.brvoid 5713224Sodanrc@yahoo.com.brSectorSubBlk::setSectorOffset(const int sector_offset) 5813224Sodanrc@yahoo.com.br{ 5913224Sodanrc@yahoo.com.br _sectorOffset = sector_offset; 6013224Sodanrc@yahoo.com.br} 6113224Sodanrc@yahoo.com.br 6213224Sodanrc@yahoo.com.brint 6313224Sodanrc@yahoo.com.brSectorSubBlk::getSectorOffset() const 6413224Sodanrc@yahoo.com.br{ 6513224Sodanrc@yahoo.com.br return _sectorOffset; 6613224Sodanrc@yahoo.com.br} 6713224Sodanrc@yahoo.com.br 6813224Sodanrc@yahoo.com.brAddr 6913224Sodanrc@yahoo.com.brSectorSubBlk::getTag() const 7013224Sodanrc@yahoo.com.br{ 7113224Sodanrc@yahoo.com.br return _sectorBlk->getTag(); 7213224Sodanrc@yahoo.com.br} 7313224Sodanrc@yahoo.com.br 7413224Sodanrc@yahoo.com.brvoid 7513224Sodanrc@yahoo.com.brSectorSubBlk::insert(const Addr tag, const bool is_secure, 7613224Sodanrc@yahoo.com.br const int src_master_ID, const uint32_t task_ID) 7713224Sodanrc@yahoo.com.br{ 7813224Sodanrc@yahoo.com.br // Make sure it is not overwriting another sector 7913224Sodanrc@yahoo.com.br panic_if((_sectorBlk && _sectorBlk->isValid()) && 8013224Sodanrc@yahoo.com.br ((_sectorBlk->getTag() != tag) || 8113224Sodanrc@yahoo.com.br (_sectorBlk->isSecure() != is_secure)), 8213224Sodanrc@yahoo.com.br "Overwriting valid sector!"); 8313224Sodanrc@yahoo.com.br 8413224Sodanrc@yahoo.com.br CacheBlk::insert(tag, is_secure, src_master_ID, task_ID); 8513224Sodanrc@yahoo.com.br 8613224Sodanrc@yahoo.com.br // Set sector tag 8713224Sodanrc@yahoo.com.br _sectorBlk->setTag(tag); 8813224Sodanrc@yahoo.com.br} 8913224Sodanrc@yahoo.com.br 9013224Sodanrc@yahoo.com.brstd::string 9113224Sodanrc@yahoo.com.brSectorSubBlk::print() const 9213224Sodanrc@yahoo.com.br{ 9313224Sodanrc@yahoo.com.br return csprintf("%s sector offset: %#x", CacheBlk::print(), 9413224Sodanrc@yahoo.com.br getSectorOffset()); 9513224Sodanrc@yahoo.com.br} 9613224Sodanrc@yahoo.com.br 9713224Sodanrc@yahoo.com.brbool 9813224Sodanrc@yahoo.com.brSectorBlk::isValid() const 9913224Sodanrc@yahoo.com.br{ 10013224Sodanrc@yahoo.com.br // If any of the blocks in the sector is valid, so is the sector 10113224Sodanrc@yahoo.com.br for (const auto& blk : blks) { 10213224Sodanrc@yahoo.com.br if (blk->isValid()) { 10313224Sodanrc@yahoo.com.br return true; 10413224Sodanrc@yahoo.com.br } 10513224Sodanrc@yahoo.com.br } 10613224Sodanrc@yahoo.com.br return false; 10713224Sodanrc@yahoo.com.br} 10813224Sodanrc@yahoo.com.br 10913224Sodanrc@yahoo.com.brbool 11013224Sodanrc@yahoo.com.brSectorBlk::isSecure() const 11113224Sodanrc@yahoo.com.br{ 11213224Sodanrc@yahoo.com.br // If any of the valid blocks in the sector is secure, so is the sector 11313224Sodanrc@yahoo.com.br for (const auto& blk : blks) { 11413224Sodanrc@yahoo.com.br if (blk->isValid()) { 11513224Sodanrc@yahoo.com.br return blk->isSecure(); 11613224Sodanrc@yahoo.com.br } 11713224Sodanrc@yahoo.com.br } 11813224Sodanrc@yahoo.com.br return false; 11913224Sodanrc@yahoo.com.br} 12013224Sodanrc@yahoo.com.br 12113224Sodanrc@yahoo.com.brvoid 12213224Sodanrc@yahoo.com.brSectorBlk::setTag(const Addr tag) 12313224Sodanrc@yahoo.com.br{ 12413224Sodanrc@yahoo.com.br _tag = tag; 12513224Sodanrc@yahoo.com.br} 12613224Sodanrc@yahoo.com.br 12713224Sodanrc@yahoo.com.brAddr 12813224Sodanrc@yahoo.com.brSectorBlk::getTag() const 12913224Sodanrc@yahoo.com.br{ 13013224Sodanrc@yahoo.com.br return _tag; 13113224Sodanrc@yahoo.com.br} 132