gem5  v22.1.0.0
sector_blk.cc
Go to the documentation of this file.
1 
35 
36 #include <cassert>
37 
38 #include "base/cprintf.hh"
39 #include "base/logging.hh"
40 
41 namespace gem5
42 {
43 
44 void
46 {
47  assert(sector_blk != nullptr);
48  _sectorBlk = sector_blk;
49 }
50 
51 SectorBlk*
53 {
54  return _sectorBlk;
55 }
56 
57 void
58 SectorSubBlk::setSectorOffset(const int sector_offset)
59 {
60  _sectorOffset = sector_offset;
61 }
62 
63 int
65 {
66  return _sectorOffset;
67 }
68 
69 Addr
71 {
72  // If the sub-block is valid its tag must match its sector's
73  const Addr tag = _sectorBlk->getTag();
74  assert(!isValid() || (CacheBlk::getTag() == tag));
75  return tag;
76 }
77 
78 void
80 {
83 }
84 
85 void
86 SectorSubBlk::insert(const Addr tag, const bool is_secure)
87 {
88  // Make sure it is not overwriting another sector
90  !_sectorBlk->matchTag(tag, is_secure), "Overwriting valid sector!");
91 
92  // If the sector is not valid, insert the new tag. The sector block
93  // handles its own tag's invalidation, so do not attempt to insert MaxAddr.
94  if ((_sectorBlk && !_sectorBlk->isValid()) && (tag != MaxAddr)) {
95  _sectorBlk->insert(tag, is_secure);
96  }
97  CacheBlk::insert(tag, is_secure);
98 }
99 
100 void
102 {
105 }
106 
107 std::string
109 {
110  return csprintf("%s sector offset: %#x", CacheBlk::print(),
111  getSectorOffset());
112 }
113 
115  : TaggedEntry(), _validCounter(0)
116 {
117 }
118 
119 bool
121 {
122  // If any of the blocks in the sector is valid, so is the sector
123  return _validCounter > 0;
124 }
125 
126 uint8_t
128 {
129  return _validCounter;
130 }
131 
132 void
134 {
135  _validCounter++;
136 }
137 
138 void
140 {
141  // If all sub-blocks have been invalidated, the sector becomes invalid,
142  // so clear secure bit
143  if (--_validCounter == 0) {
144  invalidate();
145  }
146 }
147 
148 void
149 SectorBlk::setPosition(const uint32_t set, const uint32_t way)
150 {
152  for (auto& blk : blks) {
153  blk->setPosition(set, way);
154  }
155 }
156 
157 std::string
159 {
160  std::string sub_blk_print;
161  for (const auto& sub_blk : blks) {
162  if (sub_blk->isValid()) {
163  sub_blk_print += "\t[" + sub_blk->print() + "]\n";
164  }
165  }
166  return csprintf("%s valid sub-blks (%d):\n%s",
167  TaggedEntry::print(), getNumValid(), sub_blk_print);
168 }
169 
170 } // namespace gem5
std::string print() const override
Pretty-print tag, set and way, and interpret state bits to readable form including mapping to a MOESI...
Definition: cache_blk.hh:364
virtual void insert(const Addr tag, const bool is_secure)
Insert the block by assigning it a tag and marking it valid.
Definition: tagged_entry.hh:93
virtual void invalidate() override
Invalidate the block and clear all state.
Definition: cache_blk.hh:200
virtual void setPosition(const uint32_t set, const uint32_t way)
Set both the set and way.
A Basic Sector block.
Definition: sector_blk.hh:135
void invalidateSubBlk()
Decrease the number of valid sub-blocks.
Definition: sector_blk.cc:139
std::vector< SectorSubBlk * > blks
List of blocks associated to this sector.
Definition: sector_blk.hh:147
std::string print() const override
Print relevant information for this sector block and its sub-blocks.
Definition: sector_blk.cc:158
bool isValid() const override
Checks that a sector block is valid.
Definition: sector_blk.cc:120
uint8_t getNumValid() const
Get the number of sub-blocks that have been validated.
Definition: sector_blk.cc:127
void setPosition(const uint32_t set, const uint32_t way) override
Sets the position of the sub-entries, besides its own.
Definition: sector_blk.cc:149
uint8_t _validCounter
Counter of the number of valid sub-blocks.
Definition: sector_blk.hh:141
void validateSubBlk()
Increase the number of valid sub-blocks.
Definition: sector_blk.cc:133
int getSectorOffset() const
Get offset of this sub-block within the sector.
Definition: sector_blk.cc:64
SectorBlk * _sectorBlk
Sector block associated to this block.
Definition: sector_blk.hh:57
void setSectorBlock(SectorBlk *sector_blk)
Set sector block associated to this block.
Definition: sector_blk.cc:45
void setSectorOffset(const int sector_offset)
Set offset of this sub-block within the sector.
Definition: sector_blk.cc:58
Addr getTag() const override
Get tag associated to this block.
Definition: sector_blk.cc:70
void invalidate() override
Invalidate the block and inform sector block.
Definition: sector_blk.cc:101
void setValid() override
Set valid bit and inform sector block.
Definition: sector_blk.cc:79
std::string print() const override
Pretty-print sector offset and other CacheBlk information.
Definition: sector_blk.cc:108
int _sectorOffset
The offset of this sub-block in the sector.
Definition: sector_blk.hh:62
SectorBlk * getSectorBlock() const
Get sector block associated to this block.
Definition: sector_blk.cc:52
A tagged entry is an entry containing a tag.
Definition: tagged_entry.hh:47
virtual bool isValid() const
Checks if the entry is valid.
Definition: tagged_entry.hh:57
std::string print() const override
Prints relevant information about this entry.
virtual void invalidate()
Invalidate the block.
virtual bool matchTag(Addr tag, bool is_secure) const
Checks if the given tag information corresponds to this entry's.
Definition: tagged_entry.hh:81
virtual void insert(const Addr tag, const bool is_secure)
Insert the block by assigning it a tag and marking it valid.
Definition: tagged_entry.hh:93
virtual Addr getTag() const
Get tag associated to this block.
Definition: tagged_entry.hh:71
virtual void setValid()
Set valid bit.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
const Addr MaxAddr
Definition: types.hh:171
Copyright (c) 2018, 2020 Inria All rights reserved.

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1