fa_lru.hh revision 13418
12810Srdreslin@umich.edu/*
212665Snikos.nikoleris@arm.com * Copyright (c) 2012-2013,2016,2018 ARM Limited
39347SAndreas.Sandberg@arm.com * All rights reserved.
49347SAndreas.Sandberg@arm.com *
59347SAndreas.Sandberg@arm.com * The license below extends only to copyright in the software and shall
69347SAndreas.Sandberg@arm.com * not be construed as granting a license to any other intellectual
79347SAndreas.Sandberg@arm.com * property including but not limited to intellectual property relating
89347SAndreas.Sandberg@arm.com * to a hardware implementation of the functionality of the software
99347SAndreas.Sandberg@arm.com * licensed hereunder.  You may use the software subject to the license
109347SAndreas.Sandberg@arm.com * terms below provided that you ensure that this notice is replicated
119347SAndreas.Sandberg@arm.com * unmodified and in its entirety in all distributions of the software,
129347SAndreas.Sandberg@arm.com * modified or unmodified, in source code or in binary form.
139347SAndreas.Sandberg@arm.com *
142810Srdreslin@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
152810Srdreslin@umich.edu * All rights reserved.
162810Srdreslin@umich.edu *
172810Srdreslin@umich.edu * Redistribution and use in source and binary forms, with or without
182810Srdreslin@umich.edu * modification, are permitted provided that the following conditions are
192810Srdreslin@umich.edu * met: redistributions of source code must retain the above copyright
202810Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer;
212810Srdreslin@umich.edu * redistributions in binary form must reproduce the above copyright
222810Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer in the
232810Srdreslin@umich.edu * documentation and/or other materials provided with the distribution;
242810Srdreslin@umich.edu * neither the name of the copyright holders nor the names of its
252810Srdreslin@umich.edu * contributors may be used to endorse or promote products derived from
262810Srdreslin@umich.edu * this software without specific prior written permission.
272810Srdreslin@umich.edu *
282810Srdreslin@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292810Srdreslin@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302810Srdreslin@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312810Srdreslin@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322810Srdreslin@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332810Srdreslin@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342810Srdreslin@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352810Srdreslin@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362810Srdreslin@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372810Srdreslin@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382810Srdreslin@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392810Srdreslin@umich.edu *
402810Srdreslin@umich.edu * Authors: Erik Hallnor
4112665Snikos.nikoleris@arm.com *          Nikos Nikoleris
422810Srdreslin@umich.edu */
432810Srdreslin@umich.edu
442810Srdreslin@umich.edu/**
452810Srdreslin@umich.edu * @file
462810Srdreslin@umich.edu * Declaration of a fully associative LRU tag store.
472810Srdreslin@umich.edu */
482810Srdreslin@umich.edu
496216Snate@binkert.org#ifndef __MEM_CACHE_TAGS_FA_LRU_HH__
506216Snate@binkert.org#define __MEM_CACHE_TAGS_FA_LRU_HH__
512810Srdreslin@umich.edu
5212727Snikos.nikoleris@arm.com#include <cstdint>
5312728Snikos.nikoleris@arm.com#include <functional>
5412727Snikos.nikoleris@arm.com#include <string>
5511168Sandreas.hansson@arm.com#include <unordered_map>
5613163Sodanrc@yahoo.com.br#include <vector>
572810Srdreslin@umich.edu
5812727Snikos.nikoleris@arm.com#include "base/bitfield.hh"
5912665Snikos.nikoleris@arm.com#include "base/intmath.hh"
6012727Snikos.nikoleris@arm.com#include "base/logging.hh"
6112727Snikos.nikoleris@arm.com#include "base/statistics.hh"
6212727Snikos.nikoleris@arm.com#include "base/types.hh"
6313223Sodanrc@yahoo.com.br#include "mem/cache/cache_blk.hh"
648229Snate@binkert.org#include "mem/cache/tags/base.hh"
659796Sprakash.ramrakhyani@arm.com#include "params/FALRU.hh"
662810Srdreslin@umich.edu
6712665Snikos.nikoleris@arm.com// Uncomment to enable sanity checks for the FALRU cache and the
6812665Snikos.nikoleris@arm.com// TrackedCaches class
6912665Snikos.nikoleris@arm.com//#define FALRU_DEBUG
7012665Snikos.nikoleris@arm.com
7113216Sodanrc@yahoo.com.brclass BaseCache;
7212773Sodanrc@yahoo.com.brclass ReplaceableEntry;
7312773Sodanrc@yahoo.com.br
7412665Snikos.nikoleris@arm.com// A bitmask of the caches we are keeping track of. Currently the
7512665Snikos.nikoleris@arm.com// lowest bit is the smallest cache we are tracking, as it is
7612665Snikos.nikoleris@arm.com// specified by the corresponding parameter. The rest of the bits are
7712665Snikos.nikoleris@arm.com// for exponentially growing cache sizes.
7812665Snikos.nikoleris@arm.comtypedef uint32_t CachesMask;
7912665Snikos.nikoleris@arm.com
802810Srdreslin@umich.edu/**
812810Srdreslin@umich.edu * A fully associative cache block.
822810Srdreslin@umich.edu */
832810Srdreslin@umich.educlass FALRUBlk : public CacheBlk
842810Srdreslin@umich.edu{
8512636Sodanrc@yahoo.com.br  public:
8613162Sodanrc@yahoo.com.br    FALRUBlk() : CacheBlk(), prev(nullptr), next(nullptr), inCachesMask(0) {}
8713162Sodanrc@yahoo.com.br
882810Srdreslin@umich.edu    /** The previous block in LRU order. */
892810Srdreslin@umich.edu    FALRUBlk *prev;
902810Srdreslin@umich.edu    /** The next block in LRU order. */
912810Srdreslin@umich.edu    FALRUBlk *next;
922810Srdreslin@umich.edu
9312665Snikos.nikoleris@arm.com    /** A bit mask of the caches that fit this block. */
9412665Snikos.nikoleris@arm.com    CachesMask inCachesMask;
9513222Sodanrc@yahoo.com.br
9613222Sodanrc@yahoo.com.br    /**
9713222Sodanrc@yahoo.com.br     * Pretty-print inCachesMask and other CacheBlk information.
9813222Sodanrc@yahoo.com.br     *
9913222Sodanrc@yahoo.com.br     * @return string with basic state information
10013222Sodanrc@yahoo.com.br     */
10113222Sodanrc@yahoo.com.br    std::string print() const override;
1022810Srdreslin@umich.edu};
1032810Srdreslin@umich.edu
1042810Srdreslin@umich.edu/**
1052810Srdreslin@umich.edu * A fully associative LRU cache. Keeps statistics for accesses to a number of
1062810Srdreslin@umich.edu * cache sizes at once.
1072810Srdreslin@umich.edu */
1082810Srdreslin@umich.educlass FALRU : public BaseTags
1092810Srdreslin@umich.edu{
1102810Srdreslin@umich.edu  public:
1112810Srdreslin@umich.edu    /** Typedef the block type used in this class. */
1122810Srdreslin@umich.edu    typedef FALRUBlk BlkType;
1136227Snate@binkert.org
1142810Srdreslin@umich.edu  protected:
1152810Srdreslin@umich.edu    /** The cache blocks. */
1162810Srdreslin@umich.edu    FALRUBlk *blks;
1172810Srdreslin@umich.edu
1182810Srdreslin@umich.edu    /** The MRU block. */
1192810Srdreslin@umich.edu    FALRUBlk *head;
1202810Srdreslin@umich.edu    /** The LRU block. */
1212810Srdreslin@umich.edu    FALRUBlk *tail;
1222810Srdreslin@umich.edu
1232810Srdreslin@umich.edu    /** Hash table type mapping addresses to cache block pointers. */
12412775Snikos.nikoleris@arm.com    struct PairHash
12512775Snikos.nikoleris@arm.com    {
12612775Snikos.nikoleris@arm.com        template <class T1, class T2>
12712775Snikos.nikoleris@arm.com        std::size_t operator()(const std::pair<T1, T2> &p) const
12812775Snikos.nikoleris@arm.com        {
12912775Snikos.nikoleris@arm.com            return std::hash<T1>()(p.first) ^ std::hash<T2>()(p.second);
13012775Snikos.nikoleris@arm.com        }
13112775Snikos.nikoleris@arm.com    };
13212775Snikos.nikoleris@arm.com    typedef std::pair<Addr, bool> TagHashKey;
13312775Snikos.nikoleris@arm.com    typedef std::unordered_map<TagHashKey, FALRUBlk *, PairHash> TagHash;
1342810Srdreslin@umich.edu
1352810Srdreslin@umich.edu    /** The address hash table. */
13612775Snikos.nikoleris@arm.com    TagHash tagHash;
1372810Srdreslin@umich.edu
1382810Srdreslin@umich.edu    /**
1392810Srdreslin@umich.edu     * Move a cache block to the MRU position.
14012648Sodanrc@yahoo.com.br     *
1412810Srdreslin@umich.edu     * @param blk The block to promote.
1422810Srdreslin@umich.edu     */
1432810Srdreslin@umich.edu    void moveToHead(FALRUBlk *blk);
1442810Srdreslin@umich.edu
1452810Srdreslin@umich.edu    /**
14612648Sodanrc@yahoo.com.br     * Move a cache block to the LRU position.
14712648Sodanrc@yahoo.com.br     *
14812648Sodanrc@yahoo.com.br     * @param blk The block to demote.
14912648Sodanrc@yahoo.com.br     */
15012648Sodanrc@yahoo.com.br    void moveToTail(FALRUBlk *blk);
15112648Sodanrc@yahoo.com.br
15212636Sodanrc@yahoo.com.br  public:
1539796Sprakash.ramrakhyani@arm.com    typedef FALRUParams Params;
1549796Sprakash.ramrakhyani@arm.com
1552810Srdreslin@umich.edu    /**
1562810Srdreslin@umich.edu     * Construct and initialize this cache tagstore.
1572810Srdreslin@umich.edu     */
1589796Sprakash.ramrakhyani@arm.com    FALRU(const Params *p);
1599086Sandreas.hansson@arm.com    ~FALRU();
1602810Srdreslin@umich.edu
1612810Srdreslin@umich.edu    /**
16213216Sodanrc@yahoo.com.br     * Initialize blocks and set the parent cache back pointer.
16313216Sodanrc@yahoo.com.br     *
16413216Sodanrc@yahoo.com.br     * @param _cache Pointer to parent cache.
16513216Sodanrc@yahoo.com.br     */
16613378Sgabeblack@google.com    void tagsInit(BaseCache *_cache) override;
16713216Sodanrc@yahoo.com.br
16813216Sodanrc@yahoo.com.br    /**
1692810Srdreslin@umich.edu     * Register the stats for this object.
1702810Srdreslin@umich.edu     */
17111169Sandreas.hansson@arm.com    void regStats() override;
1722810Srdreslin@umich.edu
1732810Srdreslin@umich.edu    /**
1743862Sstever@eecs.umich.edu     * Invalidate a cache block.
1753862Sstever@eecs.umich.edu     * @param blk The block to invalidate.
1762810Srdreslin@umich.edu     */
17711169Sandreas.hansson@arm.com    void invalidate(CacheBlk *blk) override;
1782810Srdreslin@umich.edu
1792810Srdreslin@umich.edu    /**
18011483Snikos.nikoleris@arm.com     * Access block and update replacement data.  May not succeed, in which
18111484Snikos.nikoleris@arm.com     * case nullptr pointer is returned.  This has all the implications of a
18211484Snikos.nikoleris@arm.com     * cache access and should only be used as such.
18313418Sodanrc@yahoo.com.br     * Returns tag lookup latency and the inCachesMask flags as a side effect.
18413418Sodanrc@yahoo.com.br     *
1852810Srdreslin@umich.edu     * @param addr The address to look for.
18610028SGiacomo.Gabrielli@arm.com     * @param is_secure True if the target memory space is secure.
18713418Sodanrc@yahoo.com.br     * @param lat The latency of the tag lookup.
18812665Snikos.nikoleris@arm.com     * @param in_cache_mask Mask indicating the caches in which the blk fits.
1892810Srdreslin@umich.edu     * @return Pointer to the cache block.
1902810Srdreslin@umich.edu     */
19110815Sdavid.guillen@arm.com    CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat,
19212665Snikos.nikoleris@arm.com                          CachesMask *in_cache_mask);
19310815Sdavid.guillen@arm.com
19410815Sdavid.guillen@arm.com    /**
19510815Sdavid.guillen@arm.com     * Just a wrapper of above function to conform with the base interface.
19610815Sdavid.guillen@arm.com     */
19711870Snikos.nikoleris@arm.com    CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
1982810Srdreslin@umich.edu
1992810Srdreslin@umich.edu    /**
2002810Srdreslin@umich.edu     * Find the block in the cache, do not update the replacement data.
2012810Srdreslin@umich.edu     * @param addr The address to look for.
20210028SGiacomo.Gabrielli@arm.com     * @param is_secure True if the target memory space is secure.
2032810Srdreslin@umich.edu     * @param asid The address space ID.
2042810Srdreslin@umich.edu     * @return Pointer to the cache block.
2052810Srdreslin@umich.edu     */
20611169Sandreas.hansson@arm.com    CacheBlk* findBlock(Addr addr, bool is_secure) const override;
2072810Srdreslin@umich.edu
2082810Srdreslin@umich.edu    /**
20912743Sodanrc@yahoo.com.br     * Find a block given set and way.
21012743Sodanrc@yahoo.com.br     *
21112743Sodanrc@yahoo.com.br     * @param set The set of the block.
21212743Sodanrc@yahoo.com.br     * @param way The way of the block.
21312743Sodanrc@yahoo.com.br     * @return The block.
21412743Sodanrc@yahoo.com.br     */
21512743Sodanrc@yahoo.com.br    ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override;
21612743Sodanrc@yahoo.com.br
21712743Sodanrc@yahoo.com.br    /**
21812744Sodanrc@yahoo.com.br     * Find replacement victim based on address. The list of evicted blocks
21912744Sodanrc@yahoo.com.br     * only contains the victim.
22012600Sodanrc@yahoo.com.br     *
22112600Sodanrc@yahoo.com.br     * @param addr Address to find a victim for.
22212746Sodanrc@yahoo.com.br     * @param is_secure True if the target memory space is secure.
22312744Sodanrc@yahoo.com.br     * @param evict_blks Cache blocks to be evicted.
22412600Sodanrc@yahoo.com.br     * @return Cache block to be replaced.
2252810Srdreslin@umich.edu     */
22612746Sodanrc@yahoo.com.br    CacheBlk* findVictim(Addr addr, const bool is_secure,
22712746Sodanrc@yahoo.com.br                         std::vector<CacheBlk*>& evict_blks) const override;
2285717Shsul@eecs.umich.edu
22912636Sodanrc@yahoo.com.br    /**
23012636Sodanrc@yahoo.com.br     * Insert the new block into the cache and update replacement data.
23112636Sodanrc@yahoo.com.br     *
23213215Sodanrc@yahoo.com.br     * @param addr Address of the block.
23313215Sodanrc@yahoo.com.br     * @param is_secure Whether the block is in secure space or not.
23413215Sodanrc@yahoo.com.br     * @param src_master_ID The source requestor ID.
23513215Sodanrc@yahoo.com.br     * @param task_ID The new task ID.
23612636Sodanrc@yahoo.com.br     * @param blk The block to update.
23712636Sodanrc@yahoo.com.br     */
23813215Sodanrc@yahoo.com.br    void insertBlock(const Addr addr, const bool is_secure,
23913215Sodanrc@yahoo.com.br                     const int src_master_ID, const uint32_t task_ID,
24013215Sodanrc@yahoo.com.br                     CacheBlk *blk) override;
2412810Srdreslin@umich.edu
2422810Srdreslin@umich.edu    /**
2432810Srdreslin@umich.edu     * Generate the tag from the addres. For fully associative this is just the
2442810Srdreslin@umich.edu     * block address.
2452810Srdreslin@umich.edu     * @param addr The address to get the tag from.
2462810Srdreslin@umich.edu     * @return The tag.
2472810Srdreslin@umich.edu     */
24811169Sandreas.hansson@arm.com    Addr extractTag(Addr addr) const override
2492810Srdreslin@umich.edu    {
2502810Srdreslin@umich.edu        return blkAlign(addr);
2512810Srdreslin@umich.edu    }
2522810Srdreslin@umich.edu
2532810Srdreslin@umich.edu    /**
25412574Sodanrc@yahoo.com.br     * Regenerate the block address from the tag.
25512574Sodanrc@yahoo.com.br     *
25612574Sodanrc@yahoo.com.br     * @param block The block.
2572810Srdreslin@umich.edu     * @return the block address.
2582810Srdreslin@umich.edu     */
25912574Sodanrc@yahoo.com.br    Addr regenerateBlkAddr(const CacheBlk* blk) const override
2602810Srdreslin@umich.edu    {
26112574Sodanrc@yahoo.com.br        return blk->tag;
2622810Srdreslin@umich.edu    }
2637612SGene.Wu@arm.com
26412728Snikos.nikoleris@arm.com    void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
26512728Snikos.nikoleris@arm.com        for (int i = 0; i < numBlocks; i++) {
26612728Snikos.nikoleris@arm.com            visitor(blks[i]);
26712728Snikos.nikoleris@arm.com        }
26812728Snikos.nikoleris@arm.com    }
2699663Suri.wiener@arm.com
27012728Snikos.nikoleris@arm.com    bool anyBlk(std::function<bool(CacheBlk &)> visitor) override {
2719347SAndreas.Sandberg@arm.com        for (int i = 0; i < numBlocks; i++) {
27212728Snikos.nikoleris@arm.com            if (visitor(blks[i])) {
27312728Snikos.nikoleris@arm.com                return true;
27412728Snikos.nikoleris@arm.com            }
2759347SAndreas.Sandberg@arm.com        }
27612728Snikos.nikoleris@arm.com        return false;
2779347SAndreas.Sandberg@arm.com    }
27812665Snikos.nikoleris@arm.com
27912665Snikos.nikoleris@arm.com  private:
28012665Snikos.nikoleris@arm.com    /**
28112665Snikos.nikoleris@arm.com     * Mechanism that allows us to simultaneously collect miss
28212665Snikos.nikoleris@arm.com     * statistics for multiple caches. Currently, we keep track of
28312665Snikos.nikoleris@arm.com     * caches from a set minimum size of interest up to the actual
28412665Snikos.nikoleris@arm.com     * cache size.
28512665Snikos.nikoleris@arm.com     */
28612665Snikos.nikoleris@arm.com    class CacheTracking
28712665Snikos.nikoleris@arm.com    {
28812665Snikos.nikoleris@arm.com      public:
28912665Snikos.nikoleris@arm.com        CacheTracking(unsigned min_size, unsigned max_size,
29012665Snikos.nikoleris@arm.com                      unsigned block_size)
29112665Snikos.nikoleris@arm.com            : blkSize(block_size),
29212665Snikos.nikoleris@arm.com              minTrackedSize(min_size),
29312665Snikos.nikoleris@arm.com              numTrackedCaches(max_size > min_size ?
29412665Snikos.nikoleris@arm.com                               floorLog2(max_size) - floorLog2(min_size) : 0),
29512665Snikos.nikoleris@arm.com              inAllCachesMask(mask(numTrackedCaches)),
29613163Sodanrc@yahoo.com.br              boundaries(numTrackedCaches)
29712665Snikos.nikoleris@arm.com        {
29812665Snikos.nikoleris@arm.com            fatal_if(numTrackedCaches > sizeof(CachesMask) * 8,
29912665Snikos.nikoleris@arm.com                     "Not enough bits (%s) in type CachesMask type to keep "
30012665Snikos.nikoleris@arm.com                     "track of %d caches\n", sizeof(CachesMask),
30112665Snikos.nikoleris@arm.com                     numTrackedCaches);
30212665Snikos.nikoleris@arm.com        }
30312665Snikos.nikoleris@arm.com
30412665Snikos.nikoleris@arm.com        /**
30512665Snikos.nikoleris@arm.com         * Initialiaze cache blocks and the tracking mechanism
30612665Snikos.nikoleris@arm.com         *
30712665Snikos.nikoleris@arm.com         * All blocks in the cache need to be initialized once.
30812665Snikos.nikoleris@arm.com         *
30912665Snikos.nikoleris@arm.com         * @param blk the MRU block
31012665Snikos.nikoleris@arm.com         * @param blk the LRU block
31112665Snikos.nikoleris@arm.com         */
31212665Snikos.nikoleris@arm.com        void init(FALRUBlk *head, FALRUBlk *tail);
31312665Snikos.nikoleris@arm.com
31412665Snikos.nikoleris@arm.com        /**
31512665Snikos.nikoleris@arm.com         * Update boundaries as a block will be moved to the MRU.
31612665Snikos.nikoleris@arm.com         *
31712665Snikos.nikoleris@arm.com         * For all caches that didn't fit the block before moving it,
31812665Snikos.nikoleris@arm.com         * we move their boundaries one block closer to the MRU. We
31912665Snikos.nikoleris@arm.com         * also update InCacheMasks as neccessary.
32012665Snikos.nikoleris@arm.com         *
32112665Snikos.nikoleris@arm.com         * @param blk the block that will be moved to the head
32212665Snikos.nikoleris@arm.com         */
32312665Snikos.nikoleris@arm.com        void moveBlockToHead(FALRUBlk *blk);
32412665Snikos.nikoleris@arm.com
32512665Snikos.nikoleris@arm.com        /**
32612665Snikos.nikoleris@arm.com         * Update boundaries as a block will be moved to the LRU.
32712665Snikos.nikoleris@arm.com         *
32812665Snikos.nikoleris@arm.com         * For all caches that fitted the block before moving it, we
32912665Snikos.nikoleris@arm.com         * move their boundaries one block closer to the LRU. We
33012665Snikos.nikoleris@arm.com         * also update InCacheMasks as neccessary.
33112665Snikos.nikoleris@arm.com         *
33212665Snikos.nikoleris@arm.com         * @param blk the block that will be moved to the head
33312665Snikos.nikoleris@arm.com         */
33412665Snikos.nikoleris@arm.com        void moveBlockToTail(FALRUBlk *blk);
33512665Snikos.nikoleris@arm.com
33612665Snikos.nikoleris@arm.com        /**
33712665Snikos.nikoleris@arm.com         * Notify of a block access.
33812665Snikos.nikoleris@arm.com         *
33912665Snikos.nikoleris@arm.com         * This should be called every time a block is accessed and it
34012665Snikos.nikoleris@arm.com         * updates statistics. If the input block is nullptr then we
34112665Snikos.nikoleris@arm.com         * treat the access as a miss. The block's InCacheMask
34212665Snikos.nikoleris@arm.com         * determines the caches in which the block fits.
34312665Snikos.nikoleris@arm.com         *
34412665Snikos.nikoleris@arm.com         * @param blk the block to record the access for
34512665Snikos.nikoleris@arm.com         */
34612665Snikos.nikoleris@arm.com        void recordAccess(FALRUBlk *blk);
34712665Snikos.nikoleris@arm.com
34812665Snikos.nikoleris@arm.com        /**
34912665Snikos.nikoleris@arm.com         * Check that the tracking mechanism is in consistent state.
35012665Snikos.nikoleris@arm.com         *
35112665Snikos.nikoleris@arm.com         * Iterate from the head (MRU) to the tail (LRU) of the list
35212665Snikos.nikoleris@arm.com         * of blocks and assert the inCachesMask and the boundaries
35312665Snikos.nikoleris@arm.com         * are in consistent state.
35412665Snikos.nikoleris@arm.com         *
35512665Snikos.nikoleris@arm.com         * @param head the MRU block of the actual cache
35612665Snikos.nikoleris@arm.com         * @param head the LRU block of the actual cache
35712665Snikos.nikoleris@arm.com         */
35813164Sodanrc@yahoo.com.br        void check(const FALRUBlk *head, const FALRUBlk *tail) const;
35912665Snikos.nikoleris@arm.com
36012665Snikos.nikoleris@arm.com        /**
36112665Snikos.nikoleris@arm.com         * Register the stats for this object.
36212665Snikos.nikoleris@arm.com         */
36312665Snikos.nikoleris@arm.com        void regStats(std::string name);
36412665Snikos.nikoleris@arm.com
36512665Snikos.nikoleris@arm.com      private:
36612665Snikos.nikoleris@arm.com        /** The size of the cache block */
36712665Snikos.nikoleris@arm.com        const unsigned blkSize;
36812665Snikos.nikoleris@arm.com        /** The smallest cache we are tracking */
36912665Snikos.nikoleris@arm.com        const unsigned minTrackedSize;
37012665Snikos.nikoleris@arm.com        /** The number of different size caches being tracked. */
37112665Snikos.nikoleris@arm.com        const int numTrackedCaches;
37212665Snikos.nikoleris@arm.com        /** A mask for all cache being tracked. */
37312665Snikos.nikoleris@arm.com        const CachesMask inAllCachesMask;
37412665Snikos.nikoleris@arm.com        /** Array of pointers to blocks at the cache boundaries. */
37513163Sodanrc@yahoo.com.br        std::vector<FALRUBlk*> boundaries;
37612665Snikos.nikoleris@arm.com
37712665Snikos.nikoleris@arm.com      protected:
37812665Snikos.nikoleris@arm.com        /**
37912665Snikos.nikoleris@arm.com         * @defgroup FALRUStats Fully Associative LRU specific statistics
38012665Snikos.nikoleris@arm.com         * The FA lru stack lets us track multiple cache sizes at once. These
38112665Snikos.nikoleris@arm.com         * statistics track the hits and misses for different cache sizes.
38212665Snikos.nikoleris@arm.com         * @{
38312665Snikos.nikoleris@arm.com         */
38412665Snikos.nikoleris@arm.com
38512665Snikos.nikoleris@arm.com        /** Hits in each cache */
38612665Snikos.nikoleris@arm.com        Stats::Vector hits;
38712665Snikos.nikoleris@arm.com        /** Misses in each cache */
38812665Snikos.nikoleris@arm.com        Stats::Vector misses;
38912665Snikos.nikoleris@arm.com        /** Total number of accesses */
39012665Snikos.nikoleris@arm.com        Stats::Scalar accesses;
39112665Snikos.nikoleris@arm.com
39212665Snikos.nikoleris@arm.com        /**
39312665Snikos.nikoleris@arm.com         * @}
39412665Snikos.nikoleris@arm.com         */
39512665Snikos.nikoleris@arm.com    };
39612665Snikos.nikoleris@arm.com    CacheTracking cacheTracking;
3972810Srdreslin@umich.edu};
3982810Srdreslin@umich.edu
3996216Snate@binkert.org#endif // __MEM_CACHE_TAGS_FA_LRU_HH__
400