base.hh revision 9448
12810SN/A/*
28856Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38856Sandreas.hansson@arm.com * All rights reserved.
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98856Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138856Sandreas.hansson@arm.com *
142810SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
152810SN/A * All rights reserved.
162810SN/A *
172810SN/A * Redistribution and use in source and binary forms, with or without
182810SN/A * modification, are permitted provided that the following conditions are
192810SN/A * met: redistributions of source code must retain the above copyright
202810SN/A * notice, this list of conditions and the following disclaimer;
212810SN/A * redistributions in binary form must reproduce the above copyright
222810SN/A * notice, this list of conditions and the following disclaimer in the
232810SN/A * documentation and/or other materials provided with the distribution;
242810SN/A * neither the name of the copyright holders nor the names of its
252810SN/A * contributors may be used to endorse or promote products derived from
262810SN/A * this software without specific prior written permission.
272810SN/A *
282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392810SN/A *
402810SN/A * Authors: Erik Hallnor
414458SN/A *          Steve Reinhardt
424458SN/A *          Ron Dreslinski
432810SN/A */
442810SN/A
452810SN/A/**
462810SN/A * @file
472810SN/A * Declares a basic cache interface BaseCache.
482810SN/A */
492810SN/A
502810SN/A#ifndef __BASE_CACHE_HH__
512810SN/A#define __BASE_CACHE_HH__
522810SN/A
537676Snate@binkert.org#include <algorithm>
547676Snate@binkert.org#include <list>
557676Snate@binkert.org#include <string>
562810SN/A#include <vector>
572810SN/A
582825SN/A#include "base/misc.hh"
592810SN/A#include "base/statistics.hh"
602810SN/A#include "base/trace.hh"
616215Snate@binkert.org#include "base/types.hh"
628232Snate@binkert.org#include "debug/Cache.hh"
638232Snate@binkert.org#include "debug/CachePort.hh"
645338Sstever@gmail.com#include "mem/cache/mshr_queue.hh"
652810SN/A#include "mem/mem_object.hh"
662810SN/A#include "mem/packet.hh"
678914Sandreas.hansson@arm.com#include "mem/qport.hh"
688229Snate@binkert.org#include "mem/request.hh"
695034SN/A#include "params/BaseCache.hh"
702811SN/A#include "sim/eventq.hh"
718786Sgblack@eecs.umich.edu#include "sim/full_system.hh"
724626SN/A#include "sim/sim_exit.hh"
738833Sdam.sunwoo@arm.com#include "sim/system.hh"
742810SN/A
753194SN/Aclass MSHR;
762810SN/A/**
772810SN/A * A basic cache interface. Implements some common functions for speed.
782810SN/A */
792810SN/Aclass BaseCache : public MemObject
802810SN/A{
814628SN/A    /**
824628SN/A     * Indexes to enumerate the MSHR queues.
834628SN/A     */
844628SN/A    enum MSHRQueueIndex {
854628SN/A        MSHRQueue_MSHRs,
864628SN/A        MSHRQueue_WriteBuffer
874628SN/A    };
884628SN/A
898737Skoansin.tan@gmail.com  public:
904628SN/A    /**
914628SN/A     * Reasons for caches to be blocked.
924628SN/A     */
934628SN/A    enum BlockedCause {
944628SN/A        Blocked_NoMSHRs = MSHRQueue_MSHRs,
954628SN/A        Blocked_NoWBBuffers = MSHRQueue_WriteBuffer,
964628SN/A        Blocked_NoTargets,
974628SN/A        NUM_BLOCKED_CAUSES
984628SN/A    };
994628SN/A
1004628SN/A    /**
1014628SN/A     * Reasons for cache to request a bus.
1024628SN/A     */
1034628SN/A    enum RequestCause {
1044628SN/A        Request_MSHR = MSHRQueue_MSHRs,
1054628SN/A        Request_WB = MSHRQueue_WriteBuffer,
1064628SN/A        Request_PF,
1074628SN/A        NUM_REQUEST_CAUSES
1084628SN/A    };
1094628SN/A
1108737Skoansin.tan@gmail.com  protected:
1114628SN/A
1128856Sandreas.hansson@arm.com    /**
1138856Sandreas.hansson@arm.com     * A cache master port is used for the memory-side port of the
1148856Sandreas.hansson@arm.com     * cache, and in addition to the basic timing port that only sends
1158856Sandreas.hansson@arm.com     * response packets through a transmit list, it also offers the
1168856Sandreas.hansson@arm.com     * ability to schedule and send request packets (requests &
1178856Sandreas.hansson@arm.com     * writebacks). The send event is scheduled through requestBus,
1188856Sandreas.hansson@arm.com     * and the sendDeferredPacket of the timing port is modified to
1198856Sandreas.hansson@arm.com     * consider both the transmit list and the requests from the MSHR.
1208856Sandreas.hansson@arm.com     */
1218922Swilliam.wang@arm.com    class CacheMasterPort : public QueuedMasterPort
1222810SN/A    {
1238856Sandreas.hansson@arm.com
1242844SN/A      public:
1258856Sandreas.hansson@arm.com
1268856Sandreas.hansson@arm.com        /**
1278856Sandreas.hansson@arm.com         * Schedule a send of a request packet (from the MSHR). Note
1288856Sandreas.hansson@arm.com         * that we could already have a retry or a transmit list of
1298856Sandreas.hansson@arm.com         * responses outstanding.
1308856Sandreas.hansson@arm.com         */
1318856Sandreas.hansson@arm.com        void requestBus(RequestCause cause, Tick time)
1328856Sandreas.hansson@arm.com        {
1338856Sandreas.hansson@arm.com            DPRINTF(CachePort, "Asserting bus request for cause %d\n", cause);
1348914Sandreas.hansson@arm.com            queue.schedSendEvent(time);
1358856Sandreas.hansson@arm.com        }
1368856Sandreas.hansson@arm.com
1373738SN/A      protected:
1384458SN/A
1398856Sandreas.hansson@arm.com        CacheMasterPort(const std::string &_name, BaseCache *_cache,
1408975Sandreas.hansson@arm.com                        MasterPacketQueue &_queue) :
1418922Swilliam.wang@arm.com            QueuedMasterPort(_name, _cache, _queue)
1428914Sandreas.hansson@arm.com        { }
1432810SN/A
1448856Sandreas.hansson@arm.com        /**
1458856Sandreas.hansson@arm.com         * Memory-side port always snoops.
1468856Sandreas.hansson@arm.com         *
1478914Sandreas.hansson@arm.com         * @return always true
1488856Sandreas.hansson@arm.com         */
1498922Swilliam.wang@arm.com        virtual bool isSnooping() const { return true; }
1508856Sandreas.hansson@arm.com    };
1513013SN/A
1528856Sandreas.hansson@arm.com    /**
1538856Sandreas.hansson@arm.com     * A cache slave port is used for the CPU-side port of the cache,
1548856Sandreas.hansson@arm.com     * and it is basically a simple timing port that uses a transmit
1558856Sandreas.hansson@arm.com     * list for responses to the CPU (or connected master). In
1568856Sandreas.hansson@arm.com     * addition, it has the functionality to block the port for
1578856Sandreas.hansson@arm.com     * incoming requests. If blocked, the port will issue a retry once
1588856Sandreas.hansson@arm.com     * unblocked.
1598856Sandreas.hansson@arm.com     */
1608922Swilliam.wang@arm.com    class CacheSlavePort : public QueuedSlavePort
1618856Sandreas.hansson@arm.com    {
1625314SN/A
1632811SN/A      public:
1648856Sandreas.hansson@arm.com
1658856Sandreas.hansson@arm.com        /** Do not accept any new requests. */
1662810SN/A        void setBlocked();
1672810SN/A
1688856Sandreas.hansson@arm.com        /** Return to normal operation and accept new requests. */
1692810SN/A        void clearBlocked();
1702810SN/A
1718856Sandreas.hansson@arm.com      protected:
1728856Sandreas.hansson@arm.com
1738856Sandreas.hansson@arm.com        CacheSlavePort(const std::string &_name, BaseCache *_cache,
1748856Sandreas.hansson@arm.com                       const std::string &_label);
1753606SN/A
1768914Sandreas.hansson@arm.com        /** A normal packet queue used to store responses. */
1778975Sandreas.hansson@arm.com        SlavePacketQueue queue;
1788914Sandreas.hansson@arm.com
1792810SN/A        bool blocked;
1802810SN/A
1812897SN/A        bool mustSendRetry;
1822897SN/A
1838856Sandreas.hansson@arm.com      private:
1844458SN/A
1859087Sandreas.hansson@arm.com        EventWrapper<SlavePort, &SlavePort::sendRetry> sendRetryEvent;
1868856Sandreas.hansson@arm.com
1872811SN/A    };
1882810SN/A
1898856Sandreas.hansson@arm.com    CacheSlavePort *cpuSidePort;
1908856Sandreas.hansson@arm.com    CacheMasterPort *memSidePort;
1913338SN/A
1924626SN/A  protected:
1934626SN/A
1944626SN/A    /** Miss status registers */
1954626SN/A    MSHRQueue mshrQueue;
1964626SN/A
1974626SN/A    /** Write/writeback buffer */
1984626SN/A    MSHRQueue writeBuffer;
1994626SN/A
2004628SN/A    MSHR *allocateBufferInternal(MSHRQueue *mq, Addr addr, int size,
2014628SN/A                                 PacketPtr pkt, Tick time, bool requestBus)
2024628SN/A    {
2034666SN/A        MSHR *mshr = mq->allocate(addr, size, pkt, time, order++);
2044628SN/A
2054628SN/A        if (mq->isFull()) {
2064628SN/A            setBlocked((BlockedCause)mq->index);
2074628SN/A        }
2084628SN/A
2094628SN/A        if (requestBus) {
2104628SN/A            requestMemSideBus((RequestCause)mq->index, time);
2114628SN/A        }
2124628SN/A
2134628SN/A        return mshr;
2144628SN/A    }
2154628SN/A
2167667Ssteve.reinhardt@amd.com    void markInServiceInternal(MSHR *mshr, PacketPtr pkt)
2174628SN/A    {
2184628SN/A        MSHRQueue *mq = mshr->queue;
2194628SN/A        bool wasFull = mq->isFull();
2207667Ssteve.reinhardt@amd.com        mq->markInService(mshr, pkt);
2214628SN/A        if (wasFull && !mq->isFull()) {
2224628SN/A            clearBlocked((BlockedCause)mq->index);
2234628SN/A        }
2244628SN/A    }
2254628SN/A
2269347SAndreas.Sandberg@arm.com    /**
2279347SAndreas.Sandberg@arm.com     * Write back dirty blocks in the cache using functional accesses.
2289347SAndreas.Sandberg@arm.com     */
2299347SAndreas.Sandberg@arm.com    virtual void memWriteback() = 0;
2309347SAndreas.Sandberg@arm.com    /**
2319347SAndreas.Sandberg@arm.com     * Invalidates all blocks in the cache.
2329347SAndreas.Sandberg@arm.com     *
2339347SAndreas.Sandberg@arm.com     * @warn Dirty cache lines will not be written back to
2349347SAndreas.Sandberg@arm.com     * memory. Make sure to call functionalWriteback() first if you
2359347SAndreas.Sandberg@arm.com     * want the to write them to memory.
2369347SAndreas.Sandberg@arm.com     */
2379347SAndreas.Sandberg@arm.com    virtual void memInvalidate() = 0;
2389347SAndreas.Sandberg@arm.com    /**
2399347SAndreas.Sandberg@arm.com     * Determine if there are any dirty blocks in the cache.
2409347SAndreas.Sandberg@arm.com     *
2419347SAndreas.Sandberg@arm.com     * \return true if at least one block is dirty, false otherwise.
2429347SAndreas.Sandberg@arm.com     */
2439347SAndreas.Sandberg@arm.com    virtual bool isDirty() const = 0;
2449347SAndreas.Sandberg@arm.com
2454626SN/A    /** Block size of this cache */
2466227Snate@binkert.org    const unsigned blkSize;
2474626SN/A
2484630SN/A    /**
2494630SN/A     * The latency of a hit in this device.
2504630SN/A     */
2519288Sandreas.hansson@arm.com    const Cycles hitLatency;
2529263Smrinmoy.ghosh@arm.com
2539263Smrinmoy.ghosh@arm.com    /**
2549263Smrinmoy.ghosh@arm.com     * The latency of sending reponse to its upper level cache/core on a
2559263Smrinmoy.ghosh@arm.com     * linefill. In most contemporary processors, the return path on a cache
2569263Smrinmoy.ghosh@arm.com     * miss is much quicker that the hit latency. The responseLatency parameter
2579263Smrinmoy.ghosh@arm.com     * tries to capture this latency.
2589263Smrinmoy.ghosh@arm.com     */
2599288Sandreas.hansson@arm.com    const Cycles responseLatency;
2604630SN/A
2614626SN/A    /** The number of targets for each MSHR. */
2624626SN/A    const int numTarget;
2634626SN/A
2646122SSteve.Reinhardt@amd.com    /** Do we forward snoops from mem side port through to cpu side port? */
2656122SSteve.Reinhardt@amd.com    bool forwardSnoops;
2664626SN/A
2678134SAli.Saidi@ARM.com    /** Is this cache a toplevel cache (e.g. L1, I/O cache). If so we should
2688134SAli.Saidi@ARM.com     * never try to forward ownership and similar optimizations to the cpu
2698134SAli.Saidi@ARM.com     * side */
2708134SAli.Saidi@ARM.com    bool isTopLevel;
2718134SAli.Saidi@ARM.com
2722810SN/A    /**
2732810SN/A     * Bit vector of the blocking reasons for the access path.
2742810SN/A     * @sa #BlockedCause
2752810SN/A     */
2762810SN/A    uint8_t blocked;
2772810SN/A
2786122SSteve.Reinhardt@amd.com    /** Increasing order number assigned to each incoming request. */
2796122SSteve.Reinhardt@amd.com    uint64_t order;
2806122SSteve.Reinhardt@amd.com
2812810SN/A    /** Stores time the cache blocked for statistics. */
2829288Sandreas.hansson@arm.com    Cycles blockedCycle;
2832810SN/A
2844626SN/A    /** Pointer to the MSHR that has no targets. */
2854626SN/A    MSHR *noTargetMSHR;
2862810SN/A
2872810SN/A    /** The number of misses to trigger an exit event. */
2882810SN/A    Counter missCount;
2892810SN/A
2903503SN/A    /** The drain event. */
2919342SAndreas.Sandberg@arm.com    DrainManager *drainManager;
2923503SN/A
2936122SSteve.Reinhardt@amd.com    /**
2946122SSteve.Reinhardt@amd.com     * The address range to which the cache responds on the CPU side.
2956122SSteve.Reinhardt@amd.com     * Normally this is all possible memory addresses. */
2968883SAli.Saidi@ARM.com    AddrRangeList addrRanges;
2976122SSteve.Reinhardt@amd.com
2988833Sdam.sunwoo@arm.com  public:
2998833Sdam.sunwoo@arm.com    /** System we are currently operating in. */
3008833Sdam.sunwoo@arm.com    System *system;
3016978SLisa.Hsu@amd.com
3022810SN/A    // Statistics
3032810SN/A    /**
3042810SN/A     * @addtogroup CacheStatistics
3052810SN/A     * @{
3062810SN/A     */
3072810SN/A
3082810SN/A    /** Number of hits per thread for each type of command. @sa Packet::Command */
3095999Snate@binkert.org    Stats::Vector hits[MemCmd::NUM_MEM_CMDS];
3102810SN/A    /** Number of hits for demand accesses. */
3112810SN/A    Stats::Formula demandHits;
3122810SN/A    /** Number of hit for all accesses. */
3132810SN/A    Stats::Formula overallHits;
3142810SN/A
3152810SN/A    /** Number of misses per thread for each type of command. @sa Packet::Command */
3165999Snate@binkert.org    Stats::Vector misses[MemCmd::NUM_MEM_CMDS];
3172810SN/A    /** Number of misses for demand accesses. */
3182810SN/A    Stats::Formula demandMisses;
3192810SN/A    /** Number of misses for all accesses. */
3202810SN/A    Stats::Formula overallMisses;
3212810SN/A
3222810SN/A    /**
3232810SN/A     * Total number of cycles per thread/command spent waiting for a miss.
3242810SN/A     * Used to calculate the average miss latency.
3252810SN/A     */
3265999Snate@binkert.org    Stats::Vector missLatency[MemCmd::NUM_MEM_CMDS];
3272810SN/A    /** Total number of cycles spent waiting for demand misses. */
3282810SN/A    Stats::Formula demandMissLatency;
3292810SN/A    /** Total number of cycles spent waiting for all misses. */
3302810SN/A    Stats::Formula overallMissLatency;
3312810SN/A
3322810SN/A    /** The number of accesses per command and thread. */
3334022SN/A    Stats::Formula accesses[MemCmd::NUM_MEM_CMDS];
3342810SN/A    /** The number of demand accesses. */
3352810SN/A    Stats::Formula demandAccesses;
3362810SN/A    /** The number of overall accesses. */
3372810SN/A    Stats::Formula overallAccesses;
3382810SN/A
3392810SN/A    /** The miss rate per command and thread. */
3404022SN/A    Stats::Formula missRate[MemCmd::NUM_MEM_CMDS];
3412810SN/A    /** The miss rate of all demand accesses. */
3422810SN/A    Stats::Formula demandMissRate;
3432810SN/A    /** The miss rate for all accesses. */
3442810SN/A    Stats::Formula overallMissRate;
3452810SN/A
3462810SN/A    /** The average miss latency per command and thread. */
3474022SN/A    Stats::Formula avgMissLatency[MemCmd::NUM_MEM_CMDS];
3482810SN/A    /** The average miss latency for demand misses. */
3492810SN/A    Stats::Formula demandAvgMissLatency;
3502810SN/A    /** The average miss latency for all misses. */
3512810SN/A    Stats::Formula overallAvgMissLatency;
3522810SN/A
3532810SN/A    /** The total number of cycles blocked for each blocked cause. */
3545999Snate@binkert.org    Stats::Vector blocked_cycles;
3552810SN/A    /** The number of times this cache blocked for each blocked cause. */
3565999Snate@binkert.org    Stats::Vector blocked_causes;
3572810SN/A
3582810SN/A    /** The average number of cycles blocked for each blocked cause. */
3592810SN/A    Stats::Formula avg_blocked;
3602810SN/A
3612810SN/A    /** The number of fast writes (WH64) performed. */
3625999Snate@binkert.org    Stats::Scalar fastWrites;
3632810SN/A
3642810SN/A    /** The number of cache copies performed. */
3655999Snate@binkert.org    Stats::Scalar cacheCopies;
3662810SN/A
3674626SN/A    /** Number of blocks written back per thread. */
3685999Snate@binkert.org    Stats::Vector writebacks;
3694626SN/A
3704626SN/A    /** Number of misses that hit in the MSHRs per command and thread. */
3715999Snate@binkert.org    Stats::Vector mshr_hits[MemCmd::NUM_MEM_CMDS];
3724626SN/A    /** Demand misses that hit in the MSHRs. */
3734626SN/A    Stats::Formula demandMshrHits;
3744626SN/A    /** Total number of misses that hit in the MSHRs. */
3754626SN/A    Stats::Formula overallMshrHits;
3764626SN/A
3774626SN/A    /** Number of misses that miss in the MSHRs, per command and thread. */
3785999Snate@binkert.org    Stats::Vector mshr_misses[MemCmd::NUM_MEM_CMDS];
3794626SN/A    /** Demand misses that miss in the MSHRs. */
3804626SN/A    Stats::Formula demandMshrMisses;
3814626SN/A    /** Total number of misses that miss in the MSHRs. */
3824626SN/A    Stats::Formula overallMshrMisses;
3834626SN/A
3844626SN/A    /** Number of misses that miss in the MSHRs, per command and thread. */
3855999Snate@binkert.org    Stats::Vector mshr_uncacheable[MemCmd::NUM_MEM_CMDS];
3864626SN/A    /** Total number of misses that miss in the MSHRs. */
3874626SN/A    Stats::Formula overallMshrUncacheable;
3884626SN/A
3894626SN/A    /** Total cycle latency of each MSHR miss, per command and thread. */
3905999Snate@binkert.org    Stats::Vector mshr_miss_latency[MemCmd::NUM_MEM_CMDS];
3914626SN/A    /** Total cycle latency of demand MSHR misses. */
3924626SN/A    Stats::Formula demandMshrMissLatency;
3934626SN/A    /** Total cycle latency of overall MSHR misses. */
3944626SN/A    Stats::Formula overallMshrMissLatency;
3954626SN/A
3964626SN/A    /** Total cycle latency of each MSHR miss, per command and thread. */
3975999Snate@binkert.org    Stats::Vector mshr_uncacheable_lat[MemCmd::NUM_MEM_CMDS];
3984626SN/A    /** Total cycle latency of overall MSHR misses. */
3994626SN/A    Stats::Formula overallMshrUncacheableLatency;
4004626SN/A
4017461Snate@binkert.org#if 0
4024626SN/A    /** The total number of MSHR accesses per command and thread. */
4034626SN/A    Stats::Formula mshrAccesses[MemCmd::NUM_MEM_CMDS];
4044626SN/A    /** The total number of demand MSHR accesses. */
4054626SN/A    Stats::Formula demandMshrAccesses;
4064626SN/A    /** The total number of MSHR accesses. */
4074626SN/A    Stats::Formula overallMshrAccesses;
4087461Snate@binkert.org#endif
4094626SN/A
4104626SN/A    /** The miss rate in the MSHRs pre command and thread. */
4114626SN/A    Stats::Formula mshrMissRate[MemCmd::NUM_MEM_CMDS];
4124626SN/A    /** The demand miss rate in the MSHRs. */
4134626SN/A    Stats::Formula demandMshrMissRate;
4144626SN/A    /** The overall miss rate in the MSHRs. */
4154626SN/A    Stats::Formula overallMshrMissRate;
4164626SN/A
4174626SN/A    /** The average latency of an MSHR miss, per command and thread. */
4184626SN/A    Stats::Formula avgMshrMissLatency[MemCmd::NUM_MEM_CMDS];
4194626SN/A    /** The average latency of a demand MSHR miss. */
4204626SN/A    Stats::Formula demandAvgMshrMissLatency;
4214626SN/A    /** The average overall latency of an MSHR miss. */
4224626SN/A    Stats::Formula overallAvgMshrMissLatency;
4234626SN/A
4244626SN/A    /** The average latency of an MSHR miss, per command and thread. */
4254626SN/A    Stats::Formula avgMshrUncacheableLatency[MemCmd::NUM_MEM_CMDS];
4264626SN/A    /** The average overall latency of an MSHR miss. */
4274626SN/A    Stats::Formula overallAvgMshrUncacheableLatency;
4284626SN/A
4294626SN/A    /** The number of times a thread hit its MSHR cap. */
4305999Snate@binkert.org    Stats::Vector mshr_cap_events;
4314626SN/A    /** The number of times software prefetches caused the MSHR to block. */
4325999Snate@binkert.org    Stats::Vector soft_prefetch_mshr_full;
4334626SN/A
4345999Snate@binkert.org    Stats::Scalar mshr_no_allocate_misses;
4354626SN/A
4362810SN/A    /**
4372810SN/A     * @}
4382810SN/A     */
4392810SN/A
4402810SN/A    /**
4412810SN/A     * Register stats for this object.
4422810SN/A     */
4432810SN/A    virtual void regStats();
4442810SN/A
4452810SN/A  public:
4465034SN/A    typedef BaseCacheParams Params;
4475034SN/A    BaseCache(const Params *p);
4485034SN/A    ~BaseCache() {}
4493606SN/A
4502858SN/A    virtual void init();
4512858SN/A
4529294Sandreas.hansson@arm.com    virtual BaseMasterPort &getMasterPort(const std::string &if_name,
4539294Sandreas.hansson@arm.com                                          PortID idx = InvalidPortID);
4549294Sandreas.hansson@arm.com    virtual BaseSlavePort &getSlavePort(const std::string &if_name,
4559294Sandreas.hansson@arm.com                                        PortID idx = InvalidPortID);
4568922Swilliam.wang@arm.com
4572810SN/A    /**
4582810SN/A     * Query block size of a cache.
4592810SN/A     * @return  The block size
4602810SN/A     */
4616227Snate@binkert.org    unsigned
4626227Snate@binkert.org    getBlockSize() const
4632810SN/A    {
4642810SN/A        return blkSize;
4652810SN/A    }
4662810SN/A
4674626SN/A
4686666Ssteve.reinhardt@amd.com    Addr blockAlign(Addr addr) const { return (addr & ~(Addr(blkSize - 1))); }
4694626SN/A
4704626SN/A
4718883SAli.Saidi@ARM.com    const AddrRangeList &getAddrRanges() const { return addrRanges; }
4726122SSteve.Reinhardt@amd.com
4734628SN/A    MSHR *allocateMissBuffer(PacketPtr pkt, Tick time, bool requestBus)
4744628SN/A    {
4754902SN/A        assert(!pkt->req->isUncacheable());
4764628SN/A        return allocateBufferInternal(&mshrQueue,
4774628SN/A                                      blockAlign(pkt->getAddr()), blkSize,
4784628SN/A                                      pkt, time, requestBus);
4794628SN/A    }
4804628SN/A
4814902SN/A    MSHR *allocateWriteBuffer(PacketPtr pkt, Tick time, bool requestBus)
4824628SN/A    {
4834902SN/A        assert(pkt->isWrite() && !pkt->isRead());
4844902SN/A        return allocateBufferInternal(&writeBuffer,
4854902SN/A                                      pkt->getAddr(), pkt->getSize(),
4864628SN/A                                      pkt, time, requestBus);
4874628SN/A    }
4884628SN/A
4894902SN/A    MSHR *allocateUncachedReadBuffer(PacketPtr pkt, Tick time, bool requestBus)
4904902SN/A    {
4914902SN/A        assert(pkt->req->isUncacheable());
4924902SN/A        assert(pkt->isRead());
4934902SN/A        return allocateBufferInternal(&mshrQueue,
4944902SN/A                                      pkt->getAddr(), pkt->getSize(),
4954902SN/A                                      pkt, time, requestBus);
4964902SN/A    }
4974628SN/A
4982810SN/A    /**
4992810SN/A     * Returns true if the cache is blocked for accesses.
5002810SN/A     */
5012810SN/A    bool isBlocked()
5022810SN/A    {
5032810SN/A        return blocked != 0;
5042810SN/A    }
5052810SN/A
5062810SN/A    /**
5072810SN/A     * Marks the access path of the cache as blocked for the given cause. This
5082810SN/A     * also sets the blocked flag in the slave interface.
5092810SN/A     * @param cause The reason for the cache blocking.
5102810SN/A     */
5112810SN/A    void setBlocked(BlockedCause cause)
5122810SN/A    {
5132810SN/A        uint8_t flag = 1 << cause;
5142810SN/A        if (blocked == 0) {
5152810SN/A            blocked_causes[cause]++;
5169288Sandreas.hansson@arm.com            blockedCycle = curCycle();
5174630SN/A            cpuSidePort->setBlocked();
5182810SN/A        }
5194630SN/A        blocked |= flag;
5204630SN/A        DPRINTF(Cache,"Blocking for cause %d, mask=%d\n", cause, blocked);
5212810SN/A    }
5222810SN/A
5232810SN/A    /**
5242810SN/A     * Marks the cache as unblocked for the given cause. This also clears the
5252810SN/A     * blocked flags in the appropriate interfaces.
5262810SN/A     * @param cause The newly unblocked cause.
5272810SN/A     * @warning Calling this function can cause a blocked request on the bus to
5282810SN/A     * access the cache. The cache must be in a state to handle that request.
5292810SN/A     */
5302810SN/A    void clearBlocked(BlockedCause cause)
5312810SN/A    {
5322810SN/A        uint8_t flag = 1 << cause;
5334630SN/A        blocked &= ~flag;
5344630SN/A        DPRINTF(Cache,"Unblocking for cause %d, mask=%d\n", cause, blocked);
5354630SN/A        if (blocked == 0) {
5369288Sandreas.hansson@arm.com            blocked_cycles[cause] += curCycle() - blockedCycle;
5374630SN/A            cpuSidePort->clearBlocked();
5382810SN/A        }
5392810SN/A    }
5402810SN/A
5412810SN/A    /**
5422810SN/A     * Request the master bus for the given cause and time.
5432810SN/A     * @param cause The reason for the request.
5442810SN/A     * @param time The time to make the request.
5452810SN/A     */
5464458SN/A    void requestMemSideBus(RequestCause cause, Tick time)
5472810SN/A    {
5484458SN/A        memSidePort->requestBus(cause, time);
5492810SN/A    }
5502810SN/A
5512810SN/A    /**
5522810SN/A     * Clear the master bus request for the given cause.
5532810SN/A     * @param cause The request reason to clear.
5542810SN/A     */
5554458SN/A    void deassertMemSideBusRequest(RequestCause cause)
5562810SN/A    {
5575875Ssteve.reinhardt@amd.com        // Obsolete... we no longer signal bus requests explicitly so
5585875Ssteve.reinhardt@amd.com        // we can't deassert them.  Leaving this in as a no-op since
5595875Ssteve.reinhardt@amd.com        // the prefetcher calls it to indicate that it no longer wants
5605875Ssteve.reinhardt@amd.com        // to request a prefetch, and someday that might be
5615875Ssteve.reinhardt@amd.com        // interesting again.
5622811SN/A    }
5633503SN/A
5649342SAndreas.Sandberg@arm.com    virtual unsigned int drain(DrainManager *dm);
5653503SN/A
5664626SN/A    virtual bool inCache(Addr addr) = 0;
5674626SN/A
5684626SN/A    virtual bool inMissQueue(Addr addr) = 0;
5694626SN/A
5708833Sdam.sunwoo@arm.com    void incMissCount(PacketPtr pkt)
5713503SN/A    {
5728833Sdam.sunwoo@arm.com        assert(pkt->req->masterId() < system->maxMasters());
5738833Sdam.sunwoo@arm.com        misses[pkt->cmdToIndex()][pkt->req->masterId()]++;
5744626SN/A
5754626SN/A        if (missCount) {
5764626SN/A            --missCount;
5774626SN/A            if (missCount == 0)
5784626SN/A                exitSimLoop("A cache reached the maximum miss count");
5793503SN/A        }
5803503SN/A    }
5818833Sdam.sunwoo@arm.com    void incHitCount(PacketPtr pkt)
5826978SLisa.Hsu@amd.com    {
5838833Sdam.sunwoo@arm.com        assert(pkt->req->masterId() < system->maxMasters());
5848833Sdam.sunwoo@arm.com        hits[pkt->cmdToIndex()][pkt->req->masterId()]++;
5856978SLisa.Hsu@amd.com
5866978SLisa.Hsu@amd.com    }
5873503SN/A
5882810SN/A};
5892810SN/A
5902810SN/A#endif //__BASE_CACHE_HH__
591