base.hh revision 11722
110008Snilay@cs.wisc.edu/*
210008Snilay@cs.wisc.edu * Copyright (c) 2012-2014 ARM Limited
310008Snilay@cs.wisc.edu * All rights reserved.
410008Snilay@cs.wisc.edu *
510008Snilay@cs.wisc.edu * The license below extends only to copyright in the software and shall
610008Snilay@cs.wisc.edu * not be construed as granting a license to any other intellectual
710008Snilay@cs.wisc.edu * property including but not limited to intellectual property relating
810008Snilay@cs.wisc.edu * to a hardware implementation of the functionality of the software
910008Snilay@cs.wisc.edu * licensed hereunder.  You may use the software subject to the license
1010008Snilay@cs.wisc.edu * terms below provided that you ensure that this notice is replicated
1110008Snilay@cs.wisc.edu * unmodified and in its entirety in all distributions of the software,
1210008Snilay@cs.wisc.edu * modified or unmodified, in source code or in binary form.
1310008Snilay@cs.wisc.edu *
1410008Snilay@cs.wisc.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
1510008Snilay@cs.wisc.edu * All rights reserved.
1610008Snilay@cs.wisc.edu *
1710008Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without
1810008Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are
1910008Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright
2010008Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer;
2110008Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright
2210008Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the
2310008Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution;
2410008Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its
2510008Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from
2610008Snilay@cs.wisc.edu * this software without specific prior written permission.
2710008Snilay@cs.wisc.edu *
2810008Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2910008Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3010008Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3110008Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3210008Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3310008Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3410008Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3510008Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3610008Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3710529Smorr@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3810008Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3910008Snilay@cs.wisc.edu *
4011019Sjthestness@gmail.com * Authors: Erik Hallnor
4110008Snilay@cs.wisc.edu *          Ron Dreslinski
4211019Sjthestness@gmail.com */
4311019Sjthestness@gmail.com
4411019Sjthestness@gmail.com/**
4510008Snilay@cs.wisc.edu * @file
4610008Snilay@cs.wisc.edu * Declaration of a common base class for cache tagstore objects.
4710008Snilay@cs.wisc.edu */
4810008Snilay@cs.wisc.edu
4910008Snilay@cs.wisc.edu#ifndef __BASE_TAGS_HH__
5010008Snilay@cs.wisc.edu#define __BASE_TAGS_HH__
5110008Snilay@cs.wisc.edu
5210519Snilay@cs.wisc.edu#include <string>
5310008Snilay@cs.wisc.edu
5410008Snilay@cs.wisc.edu#include "base/callback.hh"
5510008Snilay@cs.wisc.edu#include "base/statistics.hh"
5610008Snilay@cs.wisc.edu#include "mem/cache/blk.hh"
5710008Snilay@cs.wisc.edu#include "params/BaseTags.hh"
5810008Snilay@cs.wisc.edu#include "sim/clocked_object.hh"
5910008Snilay@cs.wisc.edu
6010008Snilay@cs.wisc.educlass BaseCache;
6110008Snilay@cs.wisc.edu
6210008Snilay@cs.wisc.edu/**
6310008Snilay@cs.wisc.edu * A common base class of Cache tagstore objects.
6410008Snilay@cs.wisc.edu */
6510008Snilay@cs.wisc.educlass BaseTags : public ClockedObject
6610008Snilay@cs.wisc.edu{
6710008Snilay@cs.wisc.edu  protected:
6810008Snilay@cs.wisc.edu    /** The block size of the cache. */
6910008Snilay@cs.wisc.edu    const unsigned blkSize;
7010008Snilay@cs.wisc.edu    /** The size of the cache. */
7110008Snilay@cs.wisc.edu    const unsigned size;
7210008Snilay@cs.wisc.edu    /** The tag lookup latency of the cache. */
7310008Snilay@cs.wisc.edu    const Cycles lookupLatency;
7410008Snilay@cs.wisc.edu    /**
7510008Snilay@cs.wisc.edu     * The total access latency of the cache. This latency
7610008Snilay@cs.wisc.edu     * is different depending on the cache access mode
7710008Snilay@cs.wisc.edu     * (parallel or sequential)
7810008Snilay@cs.wisc.edu     */
7910008Snilay@cs.wisc.edu    const Cycles accessLatency;
8010008Snilay@cs.wisc.edu    /** Pointer to the parent cache. */
8110008Snilay@cs.wisc.edu    BaseCache *cache;
8210008Snilay@cs.wisc.edu
8310008Snilay@cs.wisc.edu    /**
8410008Snilay@cs.wisc.edu     * The number of tags that need to be touched to meet the warmup
8510008Snilay@cs.wisc.edu     * percentage.
8610008Snilay@cs.wisc.edu     */
8710008Snilay@cs.wisc.edu    int warmupBound;
8810008Snilay@cs.wisc.edu    /** Marked true when the cache is warmed up. */
8910008Snilay@cs.wisc.edu    bool warmedUp;
9010970Sdavid.hashe@amd.com
9110970Sdavid.hashe@amd.com    /** the number of blocks in the cache */
9210008Snilay@cs.wisc.edu    unsigned numBlocks;
9310008Snilay@cs.wisc.edu
9410970Sdavid.hashe@amd.com    // Statistics
9510970Sdavid.hashe@amd.com    /**
9610008Snilay@cs.wisc.edu     * @addtogroup CacheStatistics
9710008Snilay@cs.wisc.edu     * @{
9810008Snilay@cs.wisc.edu     */
9910529Smorr@cs.wisc.edu
10010300Scastilloe@unican.es    /** Number of replacements of valid blocks per thread. */
10110008Snilay@cs.wisc.edu    Stats::Vector replacements;
10210008Snilay@cs.wisc.edu    /** Per cycle average of the number of tags that hold valid data. */
10310988Snilay@cs.wisc.edu    Stats::Average tagsInUse;
10410988Snilay@cs.wisc.edu
10510300Scastilloe@unican.es    /** The total number of references to a block before it is replaced. */
10610008Snilay@cs.wisc.edu    Stats::Scalar totalRefs;
10710008Snilay@cs.wisc.edu
10810008Snilay@cs.wisc.edu    /**
10910008Snilay@cs.wisc.edu     * The number of reference counts sampled. This is different from
11010008Snilay@cs.wisc.edu     * replacements because we sample all the valid blocks when the simulator
11110008Snilay@cs.wisc.edu     * exits.
11210008Snilay@cs.wisc.edu     */
11310008Snilay@cs.wisc.edu    Stats::Scalar sampledRefs;
11410008Snilay@cs.wisc.edu
11510008Snilay@cs.wisc.edu    /**
11610008Snilay@cs.wisc.edu     * Average number of references to a block before is was replaced.
11710008Snilay@cs.wisc.edu     * @todo This should change to an average stat once we have them.
11810008Snilay@cs.wisc.edu     */
11910008Snilay@cs.wisc.edu    Stats::Formula avgRefs;
12010008Snilay@cs.wisc.edu
12110008Snilay@cs.wisc.edu    /** The cycle that the warmup percentage was hit. */
12210008Snilay@cs.wisc.edu    Stats::Scalar warmupCycle;
12310008Snilay@cs.wisc.edu
12410008Snilay@cs.wisc.edu    /** Average occupancy of each requestor using the cache */
12510008Snilay@cs.wisc.edu    Stats::AverageVector occupancies;
12610008Snilay@cs.wisc.edu
12710008Snilay@cs.wisc.edu    /** Average occ % of each requestor using the cache */
12810311Snilay@cs.wisc.edu    Stats::Formula avgOccs;
12910311Snilay@cs.wisc.edu
13011022Sjthestness@gmail.com    /** Occupancy of each context/cpu using the cache */
13111022Sjthestness@gmail.com    Stats::Vector occupanciesTaskId;
13211022Sjthestness@gmail.com
13311022Sjthestness@gmail.com    /** Occupancy of each context/cpu using the cache */
13411022Sjthestness@gmail.com    Stats::Vector2d ageTaskId;
13510311Snilay@cs.wisc.edu
13610311Snilay@cs.wisc.edu    /** Occ % of each context/cpu using the cache */
13711022Sjthestness@gmail.com    Stats::Formula percentOccsTaskId;
13811022Sjthestness@gmail.com
13911022Sjthestness@gmail.com    /** Number of tags consulted over all accesses. */
14011022Sjthestness@gmail.com    Stats::Scalar tagAccesses;
14111022Sjthestness@gmail.com    /** Number of data blocks consulted over all accesses. */
14211022Sjthestness@gmail.com    Stats::Scalar dataAccesses;
14310311Snilay@cs.wisc.edu
14411022Sjthestness@gmail.com    /**
14511022Sjthestness@gmail.com     * @}
14611022Sjthestness@gmail.com     */
14711022Sjthestness@gmail.com
14810311Snilay@cs.wisc.edu  public:
14910008Snilay@cs.wisc.edu    typedef BaseTagsParams Params;
15010008Snilay@cs.wisc.edu    BaseTags(const Params *p);
15110008Snilay@cs.wisc.edu
15210008Snilay@cs.wisc.edu    /**
15310008Snilay@cs.wisc.edu     * Destructor.
15410008Snilay@cs.wisc.edu     */
15510008Snilay@cs.wisc.edu    virtual ~BaseTags() {}
15610008Snilay@cs.wisc.edu
15710008Snilay@cs.wisc.edu    /**
15810008Snilay@cs.wisc.edu     * Set the parent cache back pointer.
15910008Snilay@cs.wisc.edu     * @param _cache Pointer to parent cache.
16010008Snilay@cs.wisc.edu     */
16110008Snilay@cs.wisc.edu    void setCache(BaseCache *_cache);
16210008Snilay@cs.wisc.edu
16310008Snilay@cs.wisc.edu    /**
16410008Snilay@cs.wisc.edu     * Register local statistics.
16510311Snilay@cs.wisc.edu     */
16611022Sjthestness@gmail.com    void regStats();
16711022Sjthestness@gmail.com
16811022Sjthestness@gmail.com    /**
16911022Sjthestness@gmail.com     * Average in the reference count for valid blocks when the simulation
17011022Sjthestness@gmail.com     * exits.
17111022Sjthestness@gmail.com     */
17210311Snilay@cs.wisc.edu    virtual void cleanupRefs() {}
17311022Sjthestness@gmail.com
17411022Sjthestness@gmail.com    /**
17511022Sjthestness@gmail.com     * Computes stats just prior to dump event
17611022Sjthestness@gmail.com     */
17711022Sjthestness@gmail.com    virtual void computeStats() {}
17811022Sjthestness@gmail.com
17910311Snilay@cs.wisc.edu    /**
18010008Snilay@cs.wisc.edu     * Print all tags used
18110008Snilay@cs.wisc.edu     */
18210008Snilay@cs.wisc.edu    virtual std::string print() const = 0;
18310008Snilay@cs.wisc.edu
18410008Snilay@cs.wisc.edu    /**
18510008Snilay@cs.wisc.edu     * Find a block using the memory address
18610008Snilay@cs.wisc.edu     */
18710008Snilay@cs.wisc.edu    virtual CacheBlk * findBlock(Addr addr, bool is_secure) const = 0;
18810008Snilay@cs.wisc.edu
18910008Snilay@cs.wisc.edu    /**
19010008Snilay@cs.wisc.edu     * Calculate the block offset of an address.
19110008Snilay@cs.wisc.edu     * @param addr the address to get the offset of.
19210008Snilay@cs.wisc.edu     * @return the block offset.
19310008Snilay@cs.wisc.edu     */
19410008Snilay@cs.wisc.edu    int extractBlkOffset(Addr addr) const
19510008Snilay@cs.wisc.edu    {
19610008Snilay@cs.wisc.edu        return (addr & (Addr)(blkSize-1));
19710008Snilay@cs.wisc.edu    }
19810008Snilay@cs.wisc.edu
19910524Snilay@cs.wisc.edu    /**
20010524Snilay@cs.wisc.edu     * Find the cache block given set and way
20110008Snilay@cs.wisc.edu     * @param set The set of the block.
20210008Snilay@cs.wisc.edu     * @param way The way of the block.
20310008Snilay@cs.wisc.edu     * @return The cache block.
20410008Snilay@cs.wisc.edu     */
20510008Snilay@cs.wisc.edu    virtual CacheBlk *findBlockBySetAndWay(int set, int way) const = 0;
20610008Snilay@cs.wisc.edu
20710311Snilay@cs.wisc.edu    /**
20811022Sjthestness@gmail.com     * Limit the allocation for the cache ways.
20911022Sjthestness@gmail.com     * @param ways The maximum number of ways available for replacement.
21011022Sjthestness@gmail.com     */
21111022Sjthestness@gmail.com    virtual void setWayAllocationMax(int ways)
21211022Sjthestness@gmail.com    {
21311022Sjthestness@gmail.com        panic("This tag class does not implement way allocation limit!\n");
21411022Sjthestness@gmail.com    }
21510311Snilay@cs.wisc.edu
21610008Snilay@cs.wisc.edu    /**
21710008Snilay@cs.wisc.edu     * Get the way allocation mask limit.
21810008Snilay@cs.wisc.edu     * @return The maximum number of ways available for replacement.
21910008Snilay@cs.wisc.edu     */
22010008Snilay@cs.wisc.edu    virtual int getWayAllocationMax() const
22110008Snilay@cs.wisc.edu    {
22210008Snilay@cs.wisc.edu        panic("This tag class does not implement way allocation limit!\n");
22310008Snilay@cs.wisc.edu        return -1;
22410008Snilay@cs.wisc.edu    }
22510008Snilay@cs.wisc.edu
22610008Snilay@cs.wisc.edu    virtual unsigned getNumSets() const = 0;
22710008Snilay@cs.wisc.edu
22810008Snilay@cs.wisc.edu    virtual unsigned getNumWays() const = 0;
22910008Snilay@cs.wisc.edu
23010008Snilay@cs.wisc.edu    virtual void invalidate(CacheBlk *blk) = 0;
23110008Snilay@cs.wisc.edu
23210652Smalek.musleh@gmail.com    virtual CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat,
23311022Sjthestness@gmail.com                                  int context_src) = 0;
23411022Sjthestness@gmail.com
23511022Sjthestness@gmail.com    virtual Addr extractTag(Addr addr) const = 0;
23611022Sjthestness@gmail.com
23711022Sjthestness@gmail.com    virtual void insertBlock(PacketPtr pkt, CacheBlk *blk) = 0;
23810652Smalek.musleh@gmail.com
23910008Snilay@cs.wisc.edu    virtual Addr regenerateBlkAddr(Addr tag, unsigned set) const = 0;
24010008Snilay@cs.wisc.edu
24110008Snilay@cs.wisc.edu    virtual CacheBlk* findVictim(Addr addr) = 0;
24210008Snilay@cs.wisc.edu
24310008Snilay@cs.wisc.edu    virtual int extractSet(Addr addr) const = 0;
24410008Snilay@cs.wisc.edu
24510519Snilay@cs.wisc.edu    virtual void forEachBlk(CacheBlkVisitor &visitor) = 0;
24610519Snilay@cs.wisc.edu};
24710519Snilay@cs.wisc.edu
24810519Snilay@cs.wisc.educlass BaseTagsCallback : public Callback
24910519Snilay@cs.wisc.edu{
25010519Snilay@cs.wisc.edu    BaseTags *tags;
25110519Snilay@cs.wisc.edu  public:
25210519Snilay@cs.wisc.edu    BaseTagsCallback(BaseTags *t) : tags(t) {}
25310519Snilay@cs.wisc.edu    virtual void process() { tags->cleanupRefs(); };
25410519Snilay@cs.wisc.edu};
25511022Sjthestness@gmail.com
25611022Sjthestness@gmail.comclass BaseTagsDumpCallback : public Callback
25711022Sjthestness@gmail.com{
25811022Sjthestness@gmail.com    BaseTags *tags;
25911022Sjthestness@gmail.com  public:
26010519Snilay@cs.wisc.edu    BaseTagsDumpCallback(BaseTags *t) : tags(t) {}
26110519Snilay@cs.wisc.edu    virtual void process() { tags->computeStats(); };
26210519Snilay@cs.wisc.edu};
26310008Snilay@cs.wisc.edu
26410008Snilay@cs.wisc.edu#endif //__BASE_TAGS_HH__
265