2006-06-28 17:02:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2005 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Erik Hallnor
|
|
|
|
* Dave Greene
|
|
|
|
* Steve Reinhardt
|
2007-05-19 07:35:04 +02:00
|
|
|
* Ron Dreslinski
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Describes a cache based on template policies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CACHE_HH__
|
|
|
|
#define __CACHE_HH__
|
|
|
|
|
|
|
|
#include "base/misc.hh" // fatal, panic, and warn
|
|
|
|
|
|
|
|
#include "mem/cache/base_cache.hh"
|
2006-12-19 05:47:12 +01:00
|
|
|
#include "mem/cache/cache_blk.hh"
|
2007-06-18 02:27:53 +02:00
|
|
|
#include "mem/cache/miss/mshr.hh"
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-05-19 07:35:04 +02:00
|
|
|
#include "sim/eventq.hh"
|
|
|
|
|
2006-06-29 22:07:19 +02:00
|
|
|
//Forward decleration
|
2006-12-19 06:53:06 +01:00
|
|
|
class BasePrefetcher;
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A template-policy based cache. The behavior of the cache can be altered by
|
|
|
|
* supplying different template policies. TagStore handles all tag and data
|
2007-06-28 05:54:13 +02:00
|
|
|
* storage @sa TagStore.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-28 05:54:13 +02:00
|
|
|
template <class TagStore>
|
2006-06-28 17:02:14 +02:00
|
|
|
class Cache : public BaseCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Define the type of cache block to use. */
|
|
|
|
typedef typename TagStore::BlkType BlkType;
|
2006-12-19 05:47:12 +01:00
|
|
|
/** A typedef for a list of BlkType pointers. */
|
|
|
|
typedef typename TagStore::BlkList BlkList;
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
bool prefetchAccess;
|
2006-12-14 07:04:36 +01:00
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
protected:
|
|
|
|
|
2006-12-14 07:04:36 +01:00
|
|
|
class CpuSidePort : public CachePort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CpuSidePort(const std::string &_name,
|
2007-06-28 05:54:13 +02:00
|
|
|
Cache<TagStore> *_cache);
|
2006-12-14 07:04:36 +01:00
|
|
|
|
|
|
|
// BaseCache::CachePort just has a BaseCache *; this function
|
|
|
|
// lets us get back the type info we lost when we stored the
|
|
|
|
// cache pointer there.
|
2007-06-28 05:54:13 +02:00
|
|
|
Cache<TagStore> *myCache() {
|
|
|
|
return static_cast<Cache<TagStore> *>(cache);
|
2006-12-14 07:04:36 +01:00
|
|
|
}
|
|
|
|
|
2007-05-22 16:30:55 +02:00
|
|
|
virtual void getDeviceAddressRanges(AddrRangeList &resp,
|
|
|
|
bool &snoop);
|
|
|
|
|
2006-12-14 07:04:36 +01:00
|
|
|
virtual bool recvTiming(PacketPtr pkt);
|
|
|
|
|
|
|
|
virtual Tick recvAtomic(PacketPtr pkt);
|
|
|
|
|
|
|
|
virtual void recvFunctional(PacketPtr pkt);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MemSidePort : public CachePort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MemSidePort(const std::string &_name,
|
2007-06-28 05:54:13 +02:00
|
|
|
Cache<TagStore> *_cache);
|
2006-12-14 07:04:36 +01:00
|
|
|
|
|
|
|
// BaseCache::CachePort just has a BaseCache *; this function
|
|
|
|
// lets us get back the type info we lost when we stored the
|
|
|
|
// cache pointer there.
|
2007-06-28 05:54:13 +02:00
|
|
|
Cache<TagStore> *myCache() {
|
|
|
|
return static_cast<Cache<TagStore> *>(cache);
|
2006-12-14 07:04:36 +01:00
|
|
|
}
|
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
void sendPacket();
|
|
|
|
|
|
|
|
void processSendEvent();
|
2007-05-19 07:35:04 +02:00
|
|
|
|
2007-05-22 16:30:55 +02:00
|
|
|
virtual void getDeviceAddressRanges(AddrRangeList &resp,
|
|
|
|
bool &snoop);
|
|
|
|
|
2006-12-14 07:04:36 +01:00
|
|
|
virtual bool recvTiming(PacketPtr pkt);
|
|
|
|
|
2007-05-19 07:35:04 +02:00
|
|
|
virtual void recvRetry();
|
|
|
|
|
2006-12-14 07:04:36 +01:00
|
|
|
virtual Tick recvAtomic(PacketPtr pkt);
|
|
|
|
|
|
|
|
virtual void recvFunctional(PacketPtr pkt);
|
2007-05-19 07:35:04 +02:00
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
typedef EventWrapper<MemSidePort, &MemSidePort::processSendEvent>
|
|
|
|
SendEvent;
|
2006-12-14 07:04:36 +01:00
|
|
|
};
|
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
/** Tag and data Storage */
|
|
|
|
TagStore *tags;
|
2007-06-18 02:27:53 +02:00
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
/** Prefetcher */
|
2006-12-19 06:53:06 +01:00
|
|
|
BasePrefetcher *prefetcher;
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-06-27 08:30:30 +02:00
|
|
|
/** Temporary cache block for occasional transitory use */
|
|
|
|
BlkType *tempBlock;
|
|
|
|
|
2006-12-19 05:47:12 +01:00
|
|
|
/**
|
|
|
|
* Can this cache should allocate a block on a line-sized write miss.
|
|
|
|
*/
|
|
|
|
const bool doFastWrites;
|
|
|
|
|
|
|
|
const bool prefetchMiss;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a replacement for the given request.
|
|
|
|
* @param blk A pointer to the block, usually NULL
|
|
|
|
* @param pkt The memory request to satisfy.
|
|
|
|
* @param new_state The new state of the block.
|
|
|
|
* @param writebacks A list to store any generated writebacks.
|
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
BlkType* doReplacement(BlkType *blk, PacketPtr pkt,
|
2006-12-19 05:47:12 +01:00
|
|
|
CacheBlk::State new_state, PacketList &writebacks);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does all the processing necessary to perform the provided request.
|
|
|
|
* @param pkt The memory request to perform.
|
|
|
|
* @param lat The latency of the access.
|
|
|
|
* @param writebacks List for any writebacks that need to be performed.
|
|
|
|
* @param update True if the replacement data should be updated.
|
|
|
|
* @return Pointer to the cache block touched by the request. NULL if it
|
|
|
|
* was a miss.
|
|
|
|
*/
|
2007-06-21 20:59:17 +02:00
|
|
|
bool access(PacketPtr pkt, BlkType *&blk, int &lat);
|
2007-03-28 00:05:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*Handle doing the Compare and Swap function for SPARC.
|
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void cmpAndSwap(BlkType *blk, PacketPtr pkt);
|
2006-12-19 05:47:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates a cache block and handles all outstanding requests for the
|
|
|
|
* satisfied fill request. This version takes two memory requests. One
|
|
|
|
* contains the fill data, the other is an optional target to satisfy.
|
|
|
|
* Used for Cache::probe.
|
|
|
|
* @param pkt The memory request with the fill data.
|
2007-06-18 02:27:53 +02:00
|
|
|
* @param blk The cache block if it already exists.
|
2006-12-19 05:47:12 +01:00
|
|
|
* @param writebacks List for any writebacks that need to be performed.
|
|
|
|
* @return Pointer to the new cache block.
|
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
BlkType *handleFill(PacketPtr pkt, BlkType *blk,
|
|
|
|
PacketList &writebacks);
|
2006-12-19 05:47:12 +01:00
|
|
|
|
2007-06-25 02:32:31 +02:00
|
|
|
void satisfyCpuSideRequest(PacketPtr pkt, BlkType *blk);
|
2007-06-21 20:59:17 +02:00
|
|
|
bool satisfyMSHR(MSHR *mshr, PacketPtr pkt, BlkType *blk);
|
2007-06-18 02:27:53 +02:00
|
|
|
|
2007-06-27 07:23:10 +02:00
|
|
|
void doTimingSupplyResponse(PacketPtr req_pkt, uint8_t *blk_data,
|
|
|
|
bool already_copied);
|
2006-12-19 05:47:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the blk to the new state.
|
|
|
|
* @param blk The cache block being snooped.
|
|
|
|
* @param new_state The new coherence state for the block.
|
|
|
|
*/
|
2007-06-27 07:23:10 +02:00
|
|
|
void handleSnoop(PacketPtr ptk, BlkType *blk,
|
|
|
|
bool is_timing, bool is_deferred);
|
2006-12-19 05:47:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a writeback request for the given block.
|
|
|
|
* @param blk The block to writeback.
|
|
|
|
* @return The writeback request for the block.
|
|
|
|
*/
|
|
|
|
PacketPtr writebackBlk(BlkType *blk);
|
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
class Params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TagStore *tags;
|
|
|
|
BaseCache::Params baseParams;
|
2006-12-19 06:53:06 +01:00
|
|
|
BasePrefetcher*prefetcher;
|
2006-06-28 17:02:14 +02:00
|
|
|
bool prefetchAccess;
|
2006-12-19 05:47:12 +01:00
|
|
|
const bool doFastWrites;
|
|
|
|
const bool prefetchMiss;
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-06-28 05:54:13 +02:00
|
|
|
Params(TagStore *_tags,
|
2006-10-18 17:16:22 +02:00
|
|
|
BaseCache::Params params,
|
2006-12-19 06:53:06 +01:00
|
|
|
BasePrefetcher *_prefetcher,
|
2006-12-19 05:47:12 +01:00
|
|
|
bool prefetch_access, int hit_latency,
|
|
|
|
bool do_fast_writes,
|
|
|
|
bool prefetch_miss)
|
2007-06-28 05:54:13 +02:00
|
|
|
: tags(_tags),
|
2006-10-18 17:16:22 +02:00
|
|
|
baseParams(params),
|
2006-06-29 22:07:19 +02:00
|
|
|
prefetcher(_prefetcher), prefetchAccess(prefetch_access),
|
2006-12-19 05:47:12 +01:00
|
|
|
doFastWrites(do_fast_writes),
|
2007-06-18 02:27:53 +02:00
|
|
|
prefetchMiss(prefetch_miss)
|
2006-06-28 17:02:14 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Instantiates a basic cache object. */
|
2006-06-28 23:28:33 +02:00
|
|
|
Cache(const std::string &_name, Params ¶ms);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2006-12-14 07:04:36 +01:00
|
|
|
virtual Port *getPort(const std::string &if_name, int idx = -1);
|
2007-03-09 00:57:15 +01:00
|
|
|
virtual void deletePortRefs(Port *p);
|
2006-06-29 22:07:19 +02:00
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
void regStats();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs the access specified by the request.
|
2006-08-15 01:25:07 +02:00
|
|
|
* @param pkt The request to perform.
|
2006-06-28 17:02:14 +02:00
|
|
|
* @return The result of the access.
|
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
bool timingAccess(PacketPtr pkt);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
2007-06-18 02:27:53 +02:00
|
|
|
* Performs the access specified by the request.
|
|
|
|
* @param pkt The request to perform.
|
|
|
|
* @return The result of the access.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
Tick atomicAccess(PacketPtr pkt);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
2007-06-18 02:27:53 +02:00
|
|
|
* Performs the access specified by the request.
|
|
|
|
* @param pkt The request to perform.
|
|
|
|
* @return The result of the access.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void functionalAccess(PacketPtr pkt, CachePort *otherSidePort);
|
2006-10-13 21:47:05 +02:00
|
|
|
|
2006-06-28 17:02:14 +02:00
|
|
|
/**
|
|
|
|
* Handles a response (cache line fill/write ack) from the bus.
|
2006-08-15 01:25:07 +02:00
|
|
|
* @param pkt The request being responded to.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void handleResponse(PacketPtr pkt);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Snoops bus transactions to maintain coherence.
|
2006-08-15 01:25:07 +02:00
|
|
|
* @param pkt The current bus transaction.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void snoopTiming(PacketPtr pkt);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
/**
|
|
|
|
* Snoop for the provided request in the cache and return the estimated
|
|
|
|
* time of completion.
|
|
|
|
* @param pkt The memory request to snoop
|
|
|
|
* @return The estimated completion time.
|
|
|
|
*/
|
|
|
|
Tick snoopAtomic(PacketPtr pkt);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
2006-08-15 01:25:07 +02:00
|
|
|
* Squash all requests associated with specified thread.
|
2006-06-28 17:02:14 +02:00
|
|
|
* intended for use by I-cache.
|
2006-08-15 01:25:07 +02:00
|
|
|
* @param threadNum The thread to squash.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void squash(int threadNum);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
2007-06-18 02:27:53 +02:00
|
|
|
* Selects a outstanding request to service.
|
|
|
|
* @return The request to service, NULL if none found.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-21 20:59:17 +02:00
|
|
|
PacketPtr getBusPacket(PacketPtr cpu_pkt, BlkType *blk,
|
|
|
|
bool needsExclusive);
|
2007-06-18 02:27:53 +02:00
|
|
|
MSHR *getNextMSHR();
|
2007-06-21 20:59:17 +02:00
|
|
|
PacketPtr getTimingPacket();
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
/**
|
2007-06-18 02:27:53 +02:00
|
|
|
* Marks a request as in service (sent on the bus). This can have side
|
|
|
|
* effect since storage for no response commands is deallocated once they
|
|
|
|
* are successfully sent.
|
|
|
|
* @param pkt The request that was sent on the bus.
|
2006-06-28 17:02:14 +02:00
|
|
|
*/
|
2007-06-18 02:27:53 +02:00
|
|
|
void markInService(MSHR *mshr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform the given writeback request.
|
|
|
|
* @param pkt The writeback request.
|
|
|
|
*/
|
|
|
|
void doWriteback(PacketPtr pkt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether there are any outstanding misses.
|
|
|
|
*/
|
|
|
|
bool outstandingMisses() const
|
|
|
|
{
|
|
|
|
return mshrQueue.allocated != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheBlk *findBlock(Addr addr) {
|
|
|
|
return tags->findBlock(addr);
|
|
|
|
}
|
2006-12-19 06:53:06 +01:00
|
|
|
|
|
|
|
bool inCache(Addr addr) {
|
|
|
|
return (tags->findBlock(addr) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inMissQueue(Addr addr) {
|
2007-06-18 02:27:53 +02:00
|
|
|
return (mshrQueue.findMatch(addr) != 0);
|
2006-12-19 06:53:06 +01:00
|
|
|
}
|
2006-06-28 17:02:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __CACHE_HH__
|