gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
base_set_assoc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2003-2005,2014 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Erik Hallnor
41  */
42 
48 #ifndef __MEM_CACHE_TAGS_BASESETASSOC_HH__
49 #define __MEM_CACHE_TAGS_BASESETASSOC_HH__
50 
51 #include <cassert>
52 #include <cstring>
53 #include <list>
54 
55 #include "mem/cache/base.hh"
56 #include "mem/cache/blk.hh"
57 #include "mem/cache/tags/base.hh"
59 #include "mem/packet.hh"
60 #include "params/BaseSetAssoc.hh"
61 
76 class BaseSetAssoc : public BaseTags
77 {
78  public:
80  typedef CacheBlk BlkType;
83 
84 
85  protected:
87  const unsigned assoc;
89  unsigned allocAssoc;
91  const unsigned numSets;
93  const bool sequentialAccess;
94 
97 
101  uint8_t *dataBlks;
102 
104  int setShift;
106  int tagShift;
108  unsigned setMask;
109 
110 public:
111 
113  typedef BaseSetAssocParams Params;
114 
118  BaseSetAssoc(const Params *p);
119 
123  virtual ~BaseSetAssoc();
124 
131  CacheBlk *findBlockBySetAndWay(int set, int way) const override;
132 
137  void invalidate(CacheBlk *blk) override
138  {
139  assert(blk);
140  assert(blk->isValid());
141  tagsInUse--;
142  assert(blk->srcMasterId < cache->system->maxMasters());
143  occupancies[blk->srcMasterId]--;
146  blk->tickInserted = curTick();
147  }
148 
159  CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override
160  {
161  Addr tag = extractTag(addr);
162  int set = extractSet(addr);
163  BlkType *blk = sets[set].findBlk(tag, is_secure);
164 
165  // Access all tags in parallel, hence one in each way. The data side
166  // either accesses all blocks in parallel, or one block sequentially on
167  // a hit. Sequential access with a miss doesn't access data.
169  if (sequentialAccess) {
170  if (blk != nullptr) {
171  dataAccesses += 1;
172  }
173  } else {
175  }
176 
177  if (blk != nullptr) {
178  // If a cache hit
179  lat = accessLatency;
180  // Check if the block to be accessed is available. If not,
181  // apply the accessLatency on top of block->whenReady.
182  if (blk->whenReady > curTick() &&
183  cache->ticksToCycles(blk->whenReady - curTick()) >
184  accessLatency) {
185  lat = cache->ticksToCycles(blk->whenReady - curTick()) +
187  }
188  blk->refCount += 1;
189  } else {
190  // If a cache miss
191  lat = lookupLatency;
192  }
193 
194  return blk;
195  }
196 
205  CacheBlk* findBlock(Addr addr, bool is_secure) const override;
206 
215  {
216  BlkType *blk = nullptr;
217  int set = extractSet(addr);
218 
219  // prefer to evict an invalid block
220  for (int i = 0; i < allocAssoc; ++i) {
221  blk = sets[set].blks[i];
222  if (!blk->isValid())
223  break;
224  }
225 
226  return blk;
227  }
228 
234  void insertBlock(PacketPtr pkt, CacheBlk *blk) override
235  {
236  Addr addr = pkt->getAddr();
237  MasterID master_id = pkt->req->masterId();
238  uint32_t task_id = pkt->req->taskId();
239 
240  if (!blk->isTouched) {
241  tagsInUse++;
242  blk->isTouched = true;
243  if (!warmedUp && tagsInUse.value() >= warmupBound) {
244  warmedUp = true;
245  warmupCycle = curTick();
246  }
247  }
248 
249  // If we're replacing a block that was previously valid update
250  // stats for it. This can't be done in findBlock() because a
251  // found block might not actually be replaced there if the
252  // coherence protocol says it can't be.
253  if (blk->isValid()) {
254  replacements[0]++;
255  totalRefs += blk->refCount;
256  ++sampledRefs;
257  blk->refCount = 0;
258 
259  // deal with evicted block
260  assert(blk->srcMasterId < cache->system->maxMasters());
261  occupancies[blk->srcMasterId]--;
262 
263  blk->invalidate();
264  }
265 
266  blk->isTouched = true;
267 
268  // Set tag for new block. Caller is responsible for setting status.
269  blk->tag = extractTag(addr);
270 
271  // deal with what we are bringing in
272  assert(master_id < cache->system->maxMasters());
273  occupancies[master_id]++;
274  blk->srcMasterId = master_id;
275  blk->task_id = task_id;
276  blk->tickInserted = curTick();
277 
278  // We only need to write into one tag and one data block.
279  tagAccesses += 1;
280  dataAccesses += 1;
281  }
282 
287  virtual void setWayAllocationMax(int ways) override
288  {
289  fatal_if(ways < 1, "Allocation limit must be greater than zero");
290  allocAssoc = ways;
291  }
292 
297  virtual int getWayAllocationMax() const override
298  {
299  return allocAssoc;
300  }
301 
307  Addr extractTag(Addr addr) const override
308  {
309  return (addr >> tagShift);
310  }
311 
317  int extractSet(Addr addr) const override
318  {
319  return ((addr >> setShift) & setMask);
320  }
321 
328  Addr regenerateBlkAddr(Addr tag, unsigned set) const override
329  {
330  return ((tag << tagShift) | ((Addr)set << setShift));
331  }
332 
336  void cleanupRefs() override;
337 
341  std::string print() const override;
342 
346  void computeStats() override;
347 
360  void forEachBlk(CacheBlkVisitor &visitor) override {
361  for (unsigned i = 0; i < numSets * assoc; ++i) {
362  if (!visitor(blks[i]))
363  return;
364  }
365  }
366 };
367 
368 #endif // __MEM_CACHE_TAGS_BASESETASSOC_HH__
const bool sequentialAccess
Whether tags and data are accessed sequentially.
Counter value() const
Return the current value of this stat as its base type.
Definition: statistics.hh:677
unsigned allocAssoc
The allocatable associativity of the cache (alloc mask).
Declares a basic cache interface BaseCache.
Stats::Scalar sampledRefs
The number of reference counts sampled.
Definition: base.hh:115
const Cycles lookupLatency
The tag lookup latency of the cache.
Definition: base.hh:75
void insertBlock(PacketPtr pkt, CacheBlk *blk) override
Insert the new block into the cache.
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
bool warmedUp
Marked true when the cache is warmed up.
Definition: base.hh:91
Tick whenReady
Which curTick() will this block be accessable.
Definition: blk.hh:103
Bitfield< 7 > i
Definition: miscregs.hh:1378
Addr tag
Data block tag value.
Definition: blk.hh:86
CacheBlk * findBlockBySetAndWay(int set, int way) const override
Find the cache block given set and way.
Cycles ticksToCycles(Tick t) const
Stats::Average tagsInUse
Per cycle average of the number of tags that hold valid data.
Definition: base.hh:105
Stats::Scalar totalRefs
The total number of references to a block before it is replaced.
Definition: base.hh:108
ip6_addr_t addr
Definition: inet.hh:335
System * system
System we are currently operating in.
Definition: base.hh:329
BlkType * blks
The cache blocks.
An associative set of cache blocks.
Definition: cacheset.hh:57
Blktype * findBlk(Addr tag, bool is_secure, int &way_id) const
Find a block matching the tag in this set.
Definition: cacheset.hh:92
unsigned refCount
Number of references to this block since it was brought in.
Definition: blk.hh:115
Stats::Vector replacements
Number of replacements of valid blocks per thread.
Definition: base.hh:103
CacheBlk * accessBlock(Addr addr, bool is_secure, Cycles &lat) override
Access block and update replacement data.
Blktype ** blks
Cache blocks in this set, maintained in LRU order 0 = MRU.
Definition: cacheset.hh:64
Tick tickInserted
Definition: blk.hh:120
Declaration of a common base class for cache tagstore objects.
system
Definition: isa.cc:226
BaseTagsParams Params
Definition: base.hh:151
void forEachBlk(CacheBlkVisitor &visitor) override
Visit each block in the tag store and apply a visitor to the block.
Tick curTick()
The current simulated tick.
Definition: core.hh:47
A Basic Cache block.
Definition: blk.hh:79
BaseSetAssoc(const Params *p)
Construct and initialize this tag store.
int tagShift
The amount to shift the address to get the tag.
CacheBlk * findVictim(Addr addr) override
Find an invalid block to evict for the address provided.
A BaseSetAssoc cache tag store.
std::string print() const override
Print all tags used.
void computeStats() override
Called prior to dumping stats to compute task occupancy.
Declaration of an associative set.
Stats::Scalar tagAccesses
Number of tags consulted over all accesses.
Definition: base.hh:142
const RequestPtr req
A pointer to the original request.
Definition: packet.hh:304
const Cycles accessLatency
The total access latency of the cache.
Definition: base.hh:81
SetType * sets
The cache sets.
Stats::Scalar warmupCycle
The cycle that the warmup percentage was hit.
Definition: base.hh:124
Definitions of a simple cache block class.
void invalidate()
Invalidate the block and clear all state.
Definition: blk.hh:211
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
void invalidate(CacheBlk *blk) override
Invalidate the given block.
uint16_t MasterID
Definition: request.hh:85
CacheSet< CacheBlk > SetType
Typedef the set type used in this tag store.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
uint8_t * dataBlks
The data blocks, 1 per cache block.
const unsigned numSets
The number of sets in the cache.
MasterID maxMasters()
Get the number of masters registered in the system.
Definition: system.hh:344
Stats::Scalar dataAccesses
Number of data blocks consulted over all accesses.
Definition: base.hh:144
bool isTouched
whether this block has been touched
Definition: blk.hh:112
int setShift
The amount to shift the address to get the set.
MasterID masterId() const
Accesssor for the requestor id.
Definition: request.hh:624
BaseCache * cache
Pointer to the parent cache.
Definition: base.hh:83
BaseSetAssocParams Params
Convenience typedef.
Declaration of the Packet class.
CacheBlk BlkType
Typedef the block type used in this tag store.
Addr extractTag(Addr addr) const override
Generate the tag from the given address.
int extractSet(Addr addr) const override
Calculate the set index from the address.
void cleanupRefs() override
Called at end of simulation to complete average block reference stats.
virtual void setWayAllocationMax(int ways) override
Limit the allocation for the cache ways.
const unsigned assoc
The associativity of the cache.
int srcMasterId
holds the source requestor ID for this block.
Definition: blk.hh:118
uint32_t task_id
Task Id associated with this block.
Definition: blk.hh:83
int warmupBound
The number of tags that need to be touched to meet the warmup percentage.
Definition: base.hh:89
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
bool isValid() const
Checks that a block is valid.
Definition: blk.hh:203
virtual int getWayAllocationMax() const override
Get the way allocation mask limit.
CacheBlk * findBlock(Addr addr, bool is_secure) const override
Finds the given address in the cache, do not update replacement data.
virtual ~BaseSetAssoc()
Destructor.
Bitfield< 0 > p
A common base class of Cache tagstore objects.
Definition: base.hh:65
Base class for cache block visitor, operating on the cache block base class (later subclassed for the...
Definition: blk.hh:397
Stats::AverageVector occupancies
Average occupancy of each requestor using the cache.
Definition: base.hh:127
uint32_t taskId() const
Definition: request.hh:630
unsigned setMask
Mask out all bits that aren't part of the set index.
Invalid master id for assertion checking only.
Definition: request.hh:208
Addr getAddr() const
Definition: packet.hh:639
Addr regenerateBlkAddr(Addr tag, unsigned set) const override
Regenerate the block address from the tag.

Generated on Fri Jun 9 2017 13:03:48 for gem5 by doxygen 1.8.6