sector_blk.hh revision 13225:8d1621fc586e
14123Sbinkertn@umich.edu/** 24123Sbinkertn@umich.edu * Copyright (c) 2018 Inria 34123Sbinkertn@umich.edu * All rights reserved. 44123Sbinkertn@umich.edu * 54123Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64123Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 74123Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 84123Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 94123Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 104123Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 114123Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 124123Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 134123Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 144123Sbinkertn@umich.edu * this software without specific prior written permission. 154123Sbinkertn@umich.edu * 164123Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174123Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184123Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194123Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204123Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214123Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224123Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234123Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244123Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254123Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264123Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274123Sbinkertn@umich.edu * 284123Sbinkertn@umich.edu * Authors: Daniel Carvalho 294123Sbinkertn@umich.edu */ 304123Sbinkertn@umich.edu 314123Sbinkertn@umich.edu/** @file 324167Sbinkertn@umich.edu * Definition of a simple sector block class. Each sector consists of a 334167Sbinkertn@umich.edu * sequence of cache blocks that may or may not be present in the cache. 344167Sbinkertn@umich.edu */ 354123Sbinkertn@umich.edu 364123Sbinkertn@umich.edu#ifndef __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 374167Sbinkertn@umich.edu#define __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 384123Sbinkertn@umich.edu 394167Sbinkertn@umich.edu#include <vector> 404167Sbinkertn@umich.edu 414167Sbinkertn@umich.edu#include "mem/cache/cache_blk.hh" 424167Sbinkertn@umich.edu#include "mem/cache/replacement_policies/replaceable_entry.hh" 434167Sbinkertn@umich.edu 444167Sbinkertn@umich.educlass SectorBlk; 454167Sbinkertn@umich.edu 464167Sbinkertn@umich.edu/** 474167Sbinkertn@umich.edu * A sector is composed of sub-blocks, and each sub-block has information 484167Sbinkertn@umich.edu * regarding its sector and a pointer to its sector tag. 494167Sbinkertn@umich.edu */ 504167Sbinkertn@umich.educlass SectorSubBlk : public CacheBlk 514167Sbinkertn@umich.edu{ 524167Sbinkertn@umich.edu private: 534167Sbinkertn@umich.edu /** 544167Sbinkertn@umich.edu * Sector block associated to this block. 554167Sbinkertn@umich.edu */ 564167Sbinkertn@umich.edu SectorBlk* _sectorBlk; 574167Sbinkertn@umich.edu 584167Sbinkertn@umich.edu /** 594167Sbinkertn@umich.edu * The offset of this sub-block in the sector. 604167Sbinkertn@umich.edu */ 614167Sbinkertn@umich.edu int _sectorOffset; 624167Sbinkertn@umich.edu 634167Sbinkertn@umich.edu public: 644167Sbinkertn@umich.edu SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {} 654167Sbinkertn@umich.edu SectorSubBlk(const SectorSubBlk&) = delete; 664167Sbinkertn@umich.edu SectorSubBlk& operator=(const SectorSubBlk&) = delete; 674167Sbinkertn@umich.edu ~SectorSubBlk() {}; 684167Sbinkertn@umich.edu 694167Sbinkertn@umich.edu /** 704167Sbinkertn@umich.edu * Set sector block associated to this block. 714167Sbinkertn@umich.edu * 724167Sbinkertn@umich.edu * @param sector_blk The sector block pointer. 734167Sbinkertn@umich.edu */ 744167Sbinkertn@umich.edu void setSectorBlock(SectorBlk* sector_blk); 754167Sbinkertn@umich.edu 764123Sbinkertn@umich.edu /** 774123Sbinkertn@umich.edu * Get sector block associated to this block. 784167Sbinkertn@umich.edu * 794167Sbinkertn@umich.edu * @return The sector block pointer. 804167Sbinkertn@umich.edu */ 814167Sbinkertn@umich.edu const SectorBlk* getSectorBlock() const; 824123Sbinkertn@umich.edu 834123Sbinkertn@umich.edu /** 844167Sbinkertn@umich.edu * Set offset of this sub-block within the sector. 854167Sbinkertn@umich.edu * 86 * @param sector_offset The block's offset. 87 */ 88 void setSectorOffset(const int sector_offset); 89 90 /** 91 * Get offset of this sub-block within the sector. 92 * 93 * @return sector_offset The block's offset. 94 */ 95 int getSectorOffset() const; 96 97 /** 98 * Get tag associated to this block. 99 * 100 * @return The tag value. 101 */ 102 Addr getTag() const; 103 104 /** 105 * Set member variables when a block insertion occurs. Resets reference 106 * count to 1 (the insertion counts as a reference), and touch block if 107 * it hadn't been touched previously. Sets the insertion tick to the 108 * current tick. Does not make block valid. 109 * 110 * @param tag Block address tag. 111 * @param is_secure Whether the block is in secure space or not. 112 * @param src_master_ID The source requestor ID. 113 * @param task_ID The new task ID. 114 */ 115 void insert(const Addr tag, const bool is_secure, const int src_master_ID, 116 const uint32_t task_ID) override; 117 118 /** 119 * Pretty-print sector offset and other CacheBlk information. 120 * 121 * @return string with basic state information 122 */ 123 std::string print() const override; 124}; 125 126/** 127 * A Basic Sector block. 128 * Contains the tag and a list of blocks associated to this sector. 129 */ 130class SectorBlk : public ReplaceableEntry 131{ 132 private: 133 /** 134 * Sector tag value. A sector's tag is the tag of all its sub-blocks. 135 */ 136 Addr _tag; 137 138 public: 139 SectorBlk() : ReplaceableEntry(), _tag(MaxAddr) {} 140 SectorBlk(const SectorBlk&) = delete; 141 SectorBlk& operator=(const SectorBlk&) = delete; 142 ~SectorBlk() {}; 143 144 /** List of blocks associated to this sector. */ 145 std::vector<SectorSubBlk*> blks; 146 147 /** 148 * Checks that a sector block is valid. 149 * 150 * @return True if any of the blocks in the sector is valid. 151 */ 152 bool isValid() const; 153 154 /** 155 * Checks that a sector block is secure. A single secure block suffices 156 * to imply that the whole sector is secure, as the insertion proccess 157 * asserts that different secure spaces can't coexist in the same sector. 158 * 159 * @return True if any of the blocks in the sector is secure. 160 */ 161 bool isSecure() const; 162 163 /** 164 * Set tag associated to this block. 165 * 166 * @param The tag value. 167 */ 168 void setTag(const Addr tag); 169 170 /** 171 * Get tag associated to this block. 172 * 173 * @return The tag value. 174 */ 175 Addr getTag() const; 176}; 177 178#endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__ 179