base.hh revision 8856
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"
678229Snate@binkert.org#include "mem/request.hh"
684626SN/A#include "mem/tport.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     */
1218856Sandreas.hansson@arm.com    class CacheMasterPort : public SimpleTimingPort
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);
1348856Sandreas.hansson@arm.com            schedSendEvent(time);
1358856Sandreas.hansson@arm.com        }
1368856Sandreas.hansson@arm.com
1378856Sandreas.hansson@arm.com        void respond(PacketPtr pkt, Tick time) {
1388856Sandreas.hansson@arm.com            schedSendTiming(pkt, time);
1398856Sandreas.hansson@arm.com        }
1402810SN/A
1413738SN/A      protected:
1424458SN/A
1438856Sandreas.hansson@arm.com        CacheMasterPort(const std::string &_name, BaseCache *_cache,
1448856Sandreas.hansson@arm.com                        const std::string &_label);
1452810SN/A
1468856Sandreas.hansson@arm.com        /**
1478856Sandreas.hansson@arm.com         * Memory-side port always snoops.
1488856Sandreas.hansson@arm.com         *
1498856Sandreas.hansson@arm.com         * return always true
1508856Sandreas.hansson@arm.com         */
1518856Sandreas.hansson@arm.com        virtual bool isSnooping() { return true; }
1528856Sandreas.hansson@arm.com    };
1533013SN/A
1548856Sandreas.hansson@arm.com    /**
1558856Sandreas.hansson@arm.com     * A cache slave port is used for the CPU-side port of the cache,
1568856Sandreas.hansson@arm.com     * and it is basically a simple timing port that uses a transmit
1578856Sandreas.hansson@arm.com     * list for responses to the CPU (or connected master). In
1588856Sandreas.hansson@arm.com     * addition, it has the functionality to block the port for
1598856Sandreas.hansson@arm.com     * incoming requests. If blocked, the port will issue a retry once
1608856Sandreas.hansson@arm.com     * unblocked.
1618856Sandreas.hansson@arm.com     */
1628856Sandreas.hansson@arm.com    class CacheSlavePort : public SimpleTimingPort
1638856Sandreas.hansson@arm.com    {
1645314SN/A
1652811SN/A      public:
1668856Sandreas.hansson@arm.com
1678856Sandreas.hansson@arm.com        /** Do not accept any new requests. */
1682810SN/A        void setBlocked();
1692810SN/A
1708856Sandreas.hansson@arm.com        /** Return to normal operation and accept new requests. */
1712810SN/A        void clearBlocked();
1722810SN/A
1738856Sandreas.hansson@arm.com        void respond(PacketPtr pkt, Tick time) {
1748856Sandreas.hansson@arm.com            schedSendTiming(pkt, time);
1758856Sandreas.hansson@arm.com        }
1768856Sandreas.hansson@arm.com
1778856Sandreas.hansson@arm.com      protected:
1788856Sandreas.hansson@arm.com
1798856Sandreas.hansson@arm.com        CacheSlavePort(const std::string &_name, BaseCache *_cache,
1808856Sandreas.hansson@arm.com                       const std::string &_label);
1813606SN/A
1822810SN/A        bool blocked;
1832810SN/A
1842897SN/A        bool mustSendRetry;
1852897SN/A
1868856Sandreas.hansson@arm.com      private:
1874458SN/A
1888856Sandreas.hansson@arm.com        EventWrapper<Port, &Port::sendRetry> sendRetryEvent;
1898856Sandreas.hansson@arm.com
1902811SN/A    };
1912810SN/A
1928856Sandreas.hansson@arm.com    CacheSlavePort *cpuSidePort;
1938856Sandreas.hansson@arm.com    CacheMasterPort *memSidePort;
1943338SN/A
1954626SN/A  protected:
1964626SN/A
1974626SN/A    /** Miss status registers */
1984626SN/A    MSHRQueue mshrQueue;
1994626SN/A
2004626SN/A    /** Write/writeback buffer */
2014626SN/A    MSHRQueue writeBuffer;
2024626SN/A
2034628SN/A    MSHR *allocateBufferInternal(MSHRQueue *mq, Addr addr, int size,
2044628SN/A                                 PacketPtr pkt, Tick time, bool requestBus)
2054628SN/A    {
2064666SN/A        MSHR *mshr = mq->allocate(addr, size, pkt, time, order++);
2074628SN/A
2084628SN/A        if (mq->isFull()) {
2094628SN/A            setBlocked((BlockedCause)mq->index);
2104628SN/A        }
2114628SN/A
2124628SN/A        if (requestBus) {
2134628SN/A            requestMemSideBus((RequestCause)mq->index, time);
2144628SN/A        }
2154628SN/A
2164628SN/A        return mshr;
2174628SN/A    }
2184628SN/A
2197667Ssteve.reinhardt@amd.com    void markInServiceInternal(MSHR *mshr, PacketPtr pkt)
2204628SN/A    {
2214628SN/A        MSHRQueue *mq = mshr->queue;
2224628SN/A        bool wasFull = mq->isFull();
2237667Ssteve.reinhardt@amd.com        mq->markInService(mshr, pkt);
2244628SN/A        if (wasFull && !mq->isFull()) {
2254628SN/A            clearBlocked((BlockedCause)mq->index);
2264628SN/A        }
2274628SN/A    }
2284628SN/A
2294626SN/A    /** Block size of this cache */
2306227Snate@binkert.org    const unsigned blkSize;
2314626SN/A
2324630SN/A    /**
2334630SN/A     * The latency of a hit in this device.
2344630SN/A     */
2354630SN/A    int hitLatency;
2364630SN/A
2374626SN/A    /** The number of targets for each MSHR. */
2384626SN/A    const int numTarget;
2394626SN/A
2406122SSteve.Reinhardt@amd.com    /** Do we forward snoops from mem side port through to cpu side port? */
2416122SSteve.Reinhardt@amd.com    bool forwardSnoops;
2424626SN/A
2438134SAli.Saidi@ARM.com    /** Is this cache a toplevel cache (e.g. L1, I/O cache). If so we should
2448134SAli.Saidi@ARM.com     * never try to forward ownership and similar optimizations to the cpu
2458134SAli.Saidi@ARM.com     * side */
2468134SAli.Saidi@ARM.com    bool isTopLevel;
2478134SAli.Saidi@ARM.com
2482810SN/A    /**
2492810SN/A     * Bit vector of the blocking reasons for the access path.
2502810SN/A     * @sa #BlockedCause
2512810SN/A     */
2522810SN/A    uint8_t blocked;
2532810SN/A
2546122SSteve.Reinhardt@amd.com    /** Increasing order number assigned to each incoming request. */
2556122SSteve.Reinhardt@amd.com    uint64_t order;
2566122SSteve.Reinhardt@amd.com
2572810SN/A    /** Stores time the cache blocked for statistics. */
2582810SN/A    Tick blockedCycle;
2592810SN/A
2604626SN/A    /** Pointer to the MSHR that has no targets. */
2614626SN/A    MSHR *noTargetMSHR;
2622810SN/A
2632810SN/A    /** The number of misses to trigger an exit event. */
2642810SN/A    Counter missCount;
2652810SN/A
2663503SN/A    /** The drain event. */
2673503SN/A    Event *drainEvent;
2683503SN/A
2696122SSteve.Reinhardt@amd.com    /**
2706122SSteve.Reinhardt@amd.com     * The address range to which the cache responds on the CPU side.
2716122SSteve.Reinhardt@amd.com     * Normally this is all possible memory addresses. */
2726122SSteve.Reinhardt@amd.com    Range<Addr> addrRange;
2736122SSteve.Reinhardt@amd.com
2748833Sdam.sunwoo@arm.com  public:
2758833Sdam.sunwoo@arm.com    /** System we are currently operating in. */
2768833Sdam.sunwoo@arm.com    System *system;
2776978SLisa.Hsu@amd.com
2782810SN/A    // Statistics
2792810SN/A    /**
2802810SN/A     * @addtogroup CacheStatistics
2812810SN/A     * @{
2822810SN/A     */
2832810SN/A
2842810SN/A    /** Number of hits per thread for each type of command. @sa Packet::Command */
2855999Snate@binkert.org    Stats::Vector hits[MemCmd::NUM_MEM_CMDS];
2862810SN/A    /** Number of hits for demand accesses. */
2872810SN/A    Stats::Formula demandHits;
2882810SN/A    /** Number of hit for all accesses. */
2892810SN/A    Stats::Formula overallHits;
2902810SN/A
2912810SN/A    /** Number of misses per thread for each type of command. @sa Packet::Command */
2925999Snate@binkert.org    Stats::Vector misses[MemCmd::NUM_MEM_CMDS];
2932810SN/A    /** Number of misses for demand accesses. */
2942810SN/A    Stats::Formula demandMisses;
2952810SN/A    /** Number of misses for all accesses. */
2962810SN/A    Stats::Formula overallMisses;
2972810SN/A
2982810SN/A    /**
2992810SN/A     * Total number of cycles per thread/command spent waiting for a miss.
3002810SN/A     * Used to calculate the average miss latency.
3012810SN/A     */
3025999Snate@binkert.org    Stats::Vector missLatency[MemCmd::NUM_MEM_CMDS];
3032810SN/A    /** Total number of cycles spent waiting for demand misses. */
3042810SN/A    Stats::Formula demandMissLatency;
3052810SN/A    /** Total number of cycles spent waiting for all misses. */
3062810SN/A    Stats::Formula overallMissLatency;
3072810SN/A
3082810SN/A    /** The number of accesses per command and thread. */
3094022SN/A    Stats::Formula accesses[MemCmd::NUM_MEM_CMDS];
3102810SN/A    /** The number of demand accesses. */
3112810SN/A    Stats::Formula demandAccesses;
3122810SN/A    /** The number of overall accesses. */
3132810SN/A    Stats::Formula overallAccesses;
3142810SN/A
3152810SN/A    /** The miss rate per command and thread. */
3164022SN/A    Stats::Formula missRate[MemCmd::NUM_MEM_CMDS];
3172810SN/A    /** The miss rate of all demand accesses. */
3182810SN/A    Stats::Formula demandMissRate;
3192810SN/A    /** The miss rate for all accesses. */
3202810SN/A    Stats::Formula overallMissRate;
3212810SN/A
3222810SN/A    /** The average miss latency per command and thread. */
3234022SN/A    Stats::Formula avgMissLatency[MemCmd::NUM_MEM_CMDS];
3242810SN/A    /** The average miss latency for demand misses. */
3252810SN/A    Stats::Formula demandAvgMissLatency;
3262810SN/A    /** The average miss latency for all misses. */
3272810SN/A    Stats::Formula overallAvgMissLatency;
3282810SN/A
3292810SN/A    /** The total number of cycles blocked for each blocked cause. */
3305999Snate@binkert.org    Stats::Vector blocked_cycles;
3312810SN/A    /** The number of times this cache blocked for each blocked cause. */
3325999Snate@binkert.org    Stats::Vector blocked_causes;
3332810SN/A
3342810SN/A    /** The average number of cycles blocked for each blocked cause. */
3352810SN/A    Stats::Formula avg_blocked;
3362810SN/A
3372810SN/A    /** The number of fast writes (WH64) performed. */
3385999Snate@binkert.org    Stats::Scalar fastWrites;
3392810SN/A
3402810SN/A    /** The number of cache copies performed. */
3415999Snate@binkert.org    Stats::Scalar cacheCopies;
3422810SN/A
3434626SN/A    /** Number of blocks written back per thread. */
3445999Snate@binkert.org    Stats::Vector writebacks;
3454626SN/A
3464626SN/A    /** Number of misses that hit in the MSHRs per command and thread. */
3475999Snate@binkert.org    Stats::Vector mshr_hits[MemCmd::NUM_MEM_CMDS];
3484626SN/A    /** Demand misses that hit in the MSHRs. */
3494626SN/A    Stats::Formula demandMshrHits;
3504626SN/A    /** Total number of misses that hit in the MSHRs. */
3514626SN/A    Stats::Formula overallMshrHits;
3524626SN/A
3534626SN/A    /** Number of misses that miss in the MSHRs, per command and thread. */
3545999Snate@binkert.org    Stats::Vector mshr_misses[MemCmd::NUM_MEM_CMDS];
3554626SN/A    /** Demand misses that miss in the MSHRs. */
3564626SN/A    Stats::Formula demandMshrMisses;
3574626SN/A    /** Total number of misses that miss in the MSHRs. */
3584626SN/A    Stats::Formula overallMshrMisses;
3594626SN/A
3604626SN/A    /** Number of misses that miss in the MSHRs, per command and thread. */
3615999Snate@binkert.org    Stats::Vector mshr_uncacheable[MemCmd::NUM_MEM_CMDS];
3624626SN/A    /** Total number of misses that miss in the MSHRs. */
3634626SN/A    Stats::Formula overallMshrUncacheable;
3644626SN/A
3654626SN/A    /** Total cycle latency of each MSHR miss, per command and thread. */
3665999Snate@binkert.org    Stats::Vector mshr_miss_latency[MemCmd::NUM_MEM_CMDS];
3674626SN/A    /** Total cycle latency of demand MSHR misses. */
3684626SN/A    Stats::Formula demandMshrMissLatency;
3694626SN/A    /** Total cycle latency of overall MSHR misses. */
3704626SN/A    Stats::Formula overallMshrMissLatency;
3714626SN/A
3724626SN/A    /** Total cycle latency of each MSHR miss, per command and thread. */
3735999Snate@binkert.org    Stats::Vector mshr_uncacheable_lat[MemCmd::NUM_MEM_CMDS];
3744626SN/A    /** Total cycle latency of overall MSHR misses. */
3754626SN/A    Stats::Formula overallMshrUncacheableLatency;
3764626SN/A
3777461Snate@binkert.org#if 0
3784626SN/A    /** The total number of MSHR accesses per command and thread. */
3794626SN/A    Stats::Formula mshrAccesses[MemCmd::NUM_MEM_CMDS];
3804626SN/A    /** The total number of demand MSHR accesses. */
3814626SN/A    Stats::Formula demandMshrAccesses;
3824626SN/A    /** The total number of MSHR accesses. */
3834626SN/A    Stats::Formula overallMshrAccesses;
3847461Snate@binkert.org#endif
3854626SN/A
3864626SN/A    /** The miss rate in the MSHRs pre command and thread. */
3874626SN/A    Stats::Formula mshrMissRate[MemCmd::NUM_MEM_CMDS];
3884626SN/A    /** The demand miss rate in the MSHRs. */
3894626SN/A    Stats::Formula demandMshrMissRate;
3904626SN/A    /** The overall miss rate in the MSHRs. */
3914626SN/A    Stats::Formula overallMshrMissRate;
3924626SN/A
3934626SN/A    /** The average latency of an MSHR miss, per command and thread. */
3944626SN/A    Stats::Formula avgMshrMissLatency[MemCmd::NUM_MEM_CMDS];
3954626SN/A    /** The average latency of a demand MSHR miss. */
3964626SN/A    Stats::Formula demandAvgMshrMissLatency;
3974626SN/A    /** The average overall latency of an MSHR miss. */
3984626SN/A    Stats::Formula overallAvgMshrMissLatency;
3994626SN/A
4004626SN/A    /** The average latency of an MSHR miss, per command and thread. */
4014626SN/A    Stats::Formula avgMshrUncacheableLatency[MemCmd::NUM_MEM_CMDS];
4024626SN/A    /** The average overall latency of an MSHR miss. */
4034626SN/A    Stats::Formula overallAvgMshrUncacheableLatency;
4044626SN/A
4054626SN/A    /** The number of times a thread hit its MSHR cap. */
4065999Snate@binkert.org    Stats::Vector mshr_cap_events;
4074626SN/A    /** The number of times software prefetches caused the MSHR to block. */
4085999Snate@binkert.org    Stats::Vector soft_prefetch_mshr_full;
4094626SN/A
4105999Snate@binkert.org    Stats::Scalar mshr_no_allocate_misses;
4114626SN/A
4122810SN/A    /**
4132810SN/A     * @}
4142810SN/A     */
4152810SN/A
4162810SN/A    /**
4172810SN/A     * Register stats for this object.
4182810SN/A     */
4192810SN/A    virtual void regStats();
4202810SN/A
4212810SN/A  public:
4225034SN/A    typedef BaseCacheParams Params;
4235034SN/A    BaseCache(const Params *p);
4245034SN/A    ~BaseCache() {}
4253606SN/A
4262858SN/A    virtual void init();
4272858SN/A
4282810SN/A    /**
4292810SN/A     * Query block size of a cache.
4302810SN/A     * @return  The block size
4312810SN/A     */
4326227Snate@binkert.org    unsigned
4336227Snate@binkert.org    getBlockSize() const
4342810SN/A    {
4352810SN/A        return blkSize;
4362810SN/A    }
4372810SN/A
4384626SN/A
4396666Ssteve.reinhardt@amd.com    Addr blockAlign(Addr addr) const { return (addr & ~(Addr(blkSize - 1))); }
4404626SN/A
4414626SN/A
4426122SSteve.Reinhardt@amd.com    const Range<Addr> &getAddrRange() const { return addrRange; }
4436122SSteve.Reinhardt@amd.com
4444628SN/A    MSHR *allocateMissBuffer(PacketPtr pkt, Tick time, bool requestBus)
4454628SN/A    {
4464902SN/A        assert(!pkt->req->isUncacheable());
4474628SN/A        return allocateBufferInternal(&mshrQueue,
4484628SN/A                                      blockAlign(pkt->getAddr()), blkSize,
4494628SN/A                                      pkt, time, requestBus);
4504628SN/A    }
4514628SN/A
4524902SN/A    MSHR *allocateWriteBuffer(PacketPtr pkt, Tick time, bool requestBus)
4534628SN/A    {
4544902SN/A        assert(pkt->isWrite() && !pkt->isRead());
4554902SN/A        return allocateBufferInternal(&writeBuffer,
4564902SN/A                                      pkt->getAddr(), pkt->getSize(),
4574628SN/A                                      pkt, time, requestBus);
4584628SN/A    }
4594628SN/A
4604902SN/A    MSHR *allocateUncachedReadBuffer(PacketPtr pkt, Tick time, bool requestBus)
4614902SN/A    {
4624902SN/A        assert(pkt->req->isUncacheable());
4634902SN/A        assert(pkt->isRead());
4644902SN/A        return allocateBufferInternal(&mshrQueue,
4654902SN/A                                      pkt->getAddr(), pkt->getSize(),
4664902SN/A                                      pkt, time, requestBus);
4674902SN/A    }
4684628SN/A
4692810SN/A    /**
4702810SN/A     * Returns true if the cache is blocked for accesses.
4712810SN/A     */
4722810SN/A    bool isBlocked()
4732810SN/A    {
4742810SN/A        return blocked != 0;
4752810SN/A    }
4762810SN/A
4772810SN/A    /**
4782810SN/A     * Marks the access path of the cache as blocked for the given cause. This
4792810SN/A     * also sets the blocked flag in the slave interface.
4802810SN/A     * @param cause The reason for the cache blocking.
4812810SN/A     */
4822810SN/A    void setBlocked(BlockedCause cause)
4832810SN/A    {
4842810SN/A        uint8_t flag = 1 << cause;
4852810SN/A        if (blocked == 0) {
4862810SN/A            blocked_causes[cause]++;
4877823Ssteve.reinhardt@amd.com            blockedCycle = curTick();
4884630SN/A            cpuSidePort->setBlocked();
4892810SN/A        }
4904630SN/A        blocked |= flag;
4914630SN/A        DPRINTF(Cache,"Blocking for cause %d, mask=%d\n", cause, blocked);
4922810SN/A    }
4932810SN/A
4942810SN/A    /**
4952810SN/A     * Marks the cache as unblocked for the given cause. This also clears the
4962810SN/A     * blocked flags in the appropriate interfaces.
4972810SN/A     * @param cause The newly unblocked cause.
4982810SN/A     * @warning Calling this function can cause a blocked request on the bus to
4992810SN/A     * access the cache. The cache must be in a state to handle that request.
5002810SN/A     */
5012810SN/A    void clearBlocked(BlockedCause cause)
5022810SN/A    {
5032810SN/A        uint8_t flag = 1 << cause;
5044630SN/A        blocked &= ~flag;
5054630SN/A        DPRINTF(Cache,"Unblocking for cause %d, mask=%d\n", cause, blocked);
5064630SN/A        if (blocked == 0) {
5077823Ssteve.reinhardt@amd.com            blocked_cycles[cause] += curTick() - blockedCycle;
5084630SN/A            cpuSidePort->clearBlocked();
5092810SN/A        }
5102810SN/A    }
5112810SN/A
5122810SN/A    /**
5132810SN/A     * Request the master bus for the given cause and time.
5142810SN/A     * @param cause The reason for the request.
5152810SN/A     * @param time The time to make the request.
5162810SN/A     */
5174458SN/A    void requestMemSideBus(RequestCause cause, Tick time)
5182810SN/A    {
5194458SN/A        memSidePort->requestBus(cause, time);
5202810SN/A    }
5212810SN/A
5222810SN/A    /**
5232810SN/A     * Clear the master bus request for the given cause.
5242810SN/A     * @param cause The request reason to clear.
5252810SN/A     */
5264458SN/A    void deassertMemSideBusRequest(RequestCause cause)
5272810SN/A    {
5285875Ssteve.reinhardt@amd.com        // Obsolete... we no longer signal bus requests explicitly so
5295875Ssteve.reinhardt@amd.com        // we can't deassert them.  Leaving this in as a no-op since
5305875Ssteve.reinhardt@amd.com        // the prefetcher calls it to indicate that it no longer wants
5315875Ssteve.reinhardt@amd.com        // to request a prefetch, and someday that might be
5325875Ssteve.reinhardt@amd.com        // interesting again.
5332811SN/A    }
5343503SN/A
5353503SN/A    virtual unsigned int drain(Event *de);
5363503SN/A
5374626SN/A    virtual bool inCache(Addr addr) = 0;
5384626SN/A
5394626SN/A    virtual bool inMissQueue(Addr addr) = 0;
5404626SN/A
5418833Sdam.sunwoo@arm.com    void incMissCount(PacketPtr pkt)
5423503SN/A    {
5438833Sdam.sunwoo@arm.com        assert(pkt->req->masterId() < system->maxMasters());
5448833Sdam.sunwoo@arm.com        misses[pkt->cmdToIndex()][pkt->req->masterId()]++;
5454626SN/A
5464626SN/A        if (missCount) {
5474626SN/A            --missCount;
5484626SN/A            if (missCount == 0)
5494626SN/A                exitSimLoop("A cache reached the maximum miss count");
5503503SN/A        }
5513503SN/A    }
5528833Sdam.sunwoo@arm.com    void incHitCount(PacketPtr pkt)
5536978SLisa.Hsu@amd.com    {
5548833Sdam.sunwoo@arm.com        assert(pkt->req->masterId() < system->maxMasters());
5558833Sdam.sunwoo@arm.com        hits[pkt->cmdToIndex()][pkt->req->masterId()]++;
5566978SLisa.Hsu@amd.com
5576978SLisa.Hsu@amd.com    }
5583503SN/A
5592810SN/A};
5602810SN/A
5612810SN/A#endif //__BASE_CACHE_HH__
562