diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/BaseCache.py --- a/src/mem/cache/BaseCache.py Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/BaseCache.py Thu Jan 26 12:26:34 2012 +0000 @@ -29,8 +29,8 @@ from m5.params import * from m5.proxy import Self from MemObject import MemObject +from Prefetcher import BasePrefetcher -class Prefetch(Enum): vals = ['none', 'tagged', 'stride', 'ghb'] class BaseCache(MemObject): type = 'BaseCache' @@ -58,22 +58,7 @@ write_buffers = Param.Int(8, "number of write buffers") prefetch_on_access = Param.Bool(False, "notify the hardware prefetcher on every access (not just misses)") - prefetcher_size = Param.Int(100, - "Number of entries in the hardware prefetch queue") - prefetch_past_page = Param.Bool(False, - "Allow prefetches to cross virtual page boundaries") - prefetch_serial_squash = Param.Bool(False, - "Squash prefetches with a later time on a subsequent miss") - prefetch_degree = Param.Int(1, - "Degree of the prefetch depth") - prefetch_latency = Param.Latency(10 * Self.latency, - "Latency of the prefetcher") - prefetch_policy = Param.Prefetch('none', - "Type of prefetcher to use") - prefetch_use_cpu_id = Param.Bool(True, - "Use the CPU ID to separate calculations of prefetches") - prefetch_data_accesses_only = Param.Bool(False, - "Only prefetch on data not on instruction accesses") + prefetcher = Param.BasePrefetcher(NULL,"Prefetcher attached to cache") cpu_side = Port("Port on side closer to CPU") mem_side = Port("Port on side closer to MEM") addr_range = Param.AddrRange(AllMemory, "The address range for the CPU-side port") diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/builder.cc --- a/src/mem/cache/builder.cc Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/builder.cc Thu Jan 26 12:26:34 2012 +0000 @@ -37,7 +37,6 @@ #include #include "config/the_isa.hh" -#include "enums/Prefetch.hh" #include "mem/cache/base.hh" #include "mem/cache/cache.hh" #include "mem/config/cache.hh" @@ -57,30 +56,13 @@ #include "mem/cache/tags/iic.hh" #endif -//Prefetcher Headers -#include "mem/cache/prefetch/ghb.hh" -#include "mem/cache/prefetch/stride.hh" -#include "mem/cache/prefetch/tagged.hh" using namespace std; #define BUILD_CACHE(TAGS, tags) \ do { \ - BasePrefetcher *pf; \ - if (prefetch_policy == Enums::tagged) { \ - pf = new TaggedPrefetcher(this); \ - } \ - else if (prefetch_policy == Enums::stride) { \ - pf = new StridePrefetcher(this); \ - } \ - else if (prefetch_policy == Enums::ghb) { \ - pf = new GHBPrefetcher(this); \ - } \ - else { \ - pf = NULL; \ - } \ Cache *retval = \ - new Cache(this, tags, pf); \ + new Cache(this, tags); \ return retval; \ } while (0) diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/cache.hh --- a/src/mem/cache/cache.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/cache.hh Thu Jan 26 12:26:34 2012 +0000 @@ -211,7 +211,7 @@ public: /** Instantiates a basic cache object. */ - Cache(const Params *p, TagStore *tags, BasePrefetcher *prefetcher); + Cache(const Params *p, TagStore *tags); virtual Port *getPort(const std::string &if_name, int idx = -1); diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/cache_impl.hh --- a/src/mem/cache/cache_impl.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/cache_impl.hh Thu Jan 26 12:26:34 2012 +0000 @@ -63,10 +63,10 @@ #include "sim/sim_exit.hh" template -Cache::Cache(const Params *p, TagStore *tags, BasePrefetcher *pf) +Cache::Cache(const Params *p, TagStore *tags) : BaseCache(p), tags(tags), - prefetcher(pf), + prefetcher(p->prefetcher), doFastWrites(true), prefetchOnAccess(p->prefetch_on_access) { @@ -91,8 +91,6 @@ { BaseCache::regStats(); tags->regStats(name()); - if (prefetcher) - prefetcher->regStats(name()); } template diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/Prefetcher.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mem/cache/prefetch/Prefetcher.py Thu Jan 26 12:26:34 2012 +0000 @@ -0,0 +1,35 @@ +from m5.SimObject import SimObject +from m5.params import * +class BasePrefetcher(SimObject): + type = 'BasePrefetcher' + abstract = True + prefetcher_size = Param.Int(100, + "Number of entries in the hardware prefetch queue") + prefetch_past_page = Param.Bool(False, + "Allow prefetches to cross virtual page boundaries") + prefetch_serial_squash = Param.Bool(False, + "Squash prefetches with a later time on a subsequent miss") + prefetch_degree = Param.Int(1, + "Degree of the prefetch depth") + prefetch_latency = Param.Int(10 , + "Latency of the prefetcher") + prefetch_use_cpu_id = Param.Bool(True, + "Use the CPU ID to separate calculations of prefetches") + prefetch_data_accesses_only = Param.Bool(False, + "Only prefetch on data not on instruction accesses") + +class GHBPrefetcher(BasePrefetcher): + type = 'GHBPrefetcher' + cxx_class = 'GHBPrefetcher' + +class StridePrefetcher(BasePrefetcher): + type = 'StridePrefetcher' + cxx_class = 'StridePrefetcher' + +class TaggedPrefetcher(BasePrefetcher): + type = 'TaggedPrefetcher' + cxx_class = 'TaggedPrefetcher' + + + + diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/SConscript --- a/src/mem/cache/prefetch/SConscript Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/SConscript Thu Jan 26 12:26:34 2012 +0000 @@ -32,6 +32,7 @@ if env['TARGET_ISA'] == 'no': Return() +SimObject('Prefetcher.py') Source('base.cc') Source('ghb.cc') diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/base.hh --- a/src/mem/cache/prefetch/base.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/base.hh Thu Jan 26 12:26:34 2012 +0000 @@ -41,10 +41,11 @@ #include "base/statistics.hh" #include "mem/packet.hh" #include "params/BaseCache.hh" +#include "sim/sim_object.hh" class BaseCache; -class BasePrefetcher +class BasePrefetcher : public SimObject { protected: @@ -62,6 +63,9 @@ /** The block size of the parent cache. */ int blkSize; + int latency; + int degree; + bool useContextId; /** Do we prefetch across page boundaries. */ bool pageStop; @@ -71,8 +75,6 @@ /** Do we prefetch on only data reads, or on inst reads as well. */ bool onlyData; - std::string _name; - public: Stats::Scalar pfIdentified; @@ -85,16 +87,14 @@ Stats::Scalar pfSpanPage; Stats::Scalar pfSquashed; - void regStats(const std::string &name); + void regStats(); public: - - BasePrefetcher(const BaseCacheParams *p); + typedef BasePrefetcherParams Params; + BasePrefetcher(const Params *p); virtual ~BasePrefetcher() {} - const std::string name() const { return _name; } - void setCache(BaseCache *_cache); /** @@ -130,7 +130,12 @@ * Utility function: are addresses a and b on the same VM page? */ bool samePage(Addr a, Addr b); + public: + const Params* + params() const + { + return dynamic_cast(_params); + } + }; - - #endif //__MEM_CACHE_PREFETCH_BASE_PREFETCHER_HH__ diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/base.cc --- a/src/mem/cache/prefetch/base.cc Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/base.cc Thu Jan 26 12:26:34 2012 +0000 @@ -43,8 +43,8 @@ #include "mem/cache/base.hh" #include "mem/request.hh" -BasePrefetcher::BasePrefetcher(const BaseCacheParams *p) - : size(p->prefetcher_size), pageStop(!p->prefetch_past_page), +BasePrefetcher::BasePrefetcher(const Params *p) + : SimObject(p), size(p->prefetcher_size), pageStop(!p->prefetch_past_page), serialSquash(p->prefetch_serial_squash), onlyData(p->prefetch_data_accesses_only) { @@ -55,54 +55,53 @@ { cache = _cache; blkSize = cache->getBlockSize(); - _name = cache->name() + "-pf"; } void -BasePrefetcher::regStats(const std::string &name) +BasePrefetcher::regStats() { pfIdentified - .name(name + ".prefetcher.num_hwpf_identified") + .name(name() + ".prefetcher.num_hwpf_identified") .desc("number of hwpf identified") ; pfMSHRHit - .name(name + ".prefetcher.num_hwpf_already_in_mshr") + .name(name() + ".prefetcher.num_hwpf_already_in_mshr") .desc("number of hwpf that were already in mshr") ; pfCacheHit - .name(name + ".prefetcher.num_hwpf_already_in_cache") + .name(name() + ".prefetcher.num_hwpf_already_in_cache") .desc("number of hwpf that were already in the cache") ; pfBufferHit - .name(name + ".prefetcher.num_hwpf_already_in_prefetcher") + .name(name() + ".prefetcher.num_hwpf_already_in_prefetcher") .desc("number of hwpf that were already in the prefetch queue") ; pfRemovedFull - .name(name + ".prefetcher.num_hwpf_evicted") + .name(name() + ".prefetcher.num_hwpf_evicted") .desc("number of hwpf removed due to no buffer left") ; pfRemovedMSHR - .name(name + ".prefetcher.num_hwpf_removed_MSHR_hit") + .name(name() + ".prefetcher.num_hwpf_removed_MSHR_hit") .desc("number of hwpf removed because MSHR allocated") ; pfIssued - .name(name + ".prefetcher.num_hwpf_issued") + .name(name() + ".prefetcher.num_hwpf_issued") .desc("number of hwpf issued") ; pfSpanPage - .name(name + ".prefetcher.num_hwpf_span_page") + .name(name() + ".prefetcher.num_hwpf_span_page") .desc("number of hwpf spanning a virtual page") ; pfSquashed - .name(name + ".prefetcher.num_hwpf_squashed_from_miss") + .name(name() + ".prefetcher.num_hwpf_squashed_from_miss") .desc("number of hwpf that got squashed due to a miss " "aborting calculation time") ; @@ -276,3 +275,5 @@ { return roundDown(a, TheISA::VMPageSize) == roundDown(b, TheISA::VMPageSize); } + + diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/ghb.hh --- a/src/mem/cache/prefetch/ghb.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/ghb.hh Thu Jan 26 12:26:34 2012 +0000 @@ -37,6 +37,7 @@ #define __MEM_CACHE_PREFETCH_GHB_PREFETCHER_HH__ #include "mem/cache/prefetch/base.hh" +#include "params/GHBPrefetcher.hh" class GHBPrefetcher : public BasePrefetcher { @@ -52,10 +53,8 @@ bool useContextId; public: - - GHBPrefetcher(const BaseCacheParams *p) - : BasePrefetcher(p), latency(p->prefetch_latency), - degree(p->prefetch_degree), useContextId(p->prefetch_use_cpu_id) + GHBPrefetcher(const Params *p) + : BasePrefetcher(p) { } diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/ghb.cc --- a/src/mem/cache/prefetch/ghb.cc Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/ghb.cc Thu Jan 26 12:26:34 2012 +0000 @@ -71,3 +71,10 @@ } } } + + +GHBPrefetcher* +GHBPrefetcherParams::create() +{ + return new GHBPrefetcher(this); +} diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/stride.hh --- a/src/mem/cache/prefetch/stride.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/stride.hh Thu Jan 26 12:26:34 2012 +0000 @@ -39,6 +39,7 @@ #include #include "mem/cache/prefetch/base.hh" +#include "params/StridePrefetcher.hh" class StridePrefetcher : public BasePrefetcher { @@ -63,15 +64,11 @@ Addr *lastMissAddr[Max_Contexts]; std::list table[Max_Contexts]; - Tick latency; - int degree; - bool useContextId; public: - StridePrefetcher(const BaseCacheParams *p) - : BasePrefetcher(p), latency(p->prefetch_latency), - degree(p->prefetch_degree), useContextId(p->prefetch_use_cpu_id) + StridePrefetcher(const Params *p) + : BasePrefetcher(p) { } diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/stride.cc --- a/src/mem/cache/prefetch/stride.cc Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/stride.cc Thu Jan 26 12:26:34 2012 +0000 @@ -132,3 +132,10 @@ tab.push_back(new_entry); } } + + +StridePrefetcher* +StridePrefetcherParams::create() +{ + return new StridePrefetcher(this); +} diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/tagged.hh --- a/src/mem/cache/prefetch/tagged.hh Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/tagged.hh Thu Jan 26 12:26:34 2012 +0000 @@ -37,6 +37,8 @@ #define __MEM_CACHE_PREFETCH_TAGGED_PREFETCHER_HH__ #include "mem/cache/prefetch/base.hh" +#include "params/TaggedPrefetcher.hh" + class TaggedPrefetcher : public BasePrefetcher { @@ -47,7 +49,7 @@ public: - TaggedPrefetcher(const BaseCacheParams *p); + TaggedPrefetcher(const Params *p); ~TaggedPrefetcher() {} diff -r 2751ee885a48 -r 7ee3900d49bf src/mem/cache/prefetch/tagged.cc --- a/src/mem/cache/prefetch/tagged.cc Thu Jan 26 12:26:33 2012 +0000 +++ b/src/mem/cache/prefetch/tagged.cc Thu Jan 26 12:26:34 2012 +0000 @@ -35,7 +35,7 @@ #include "mem/cache/prefetch/tagged.hh" -TaggedPrefetcher::TaggedPrefetcher(const BaseCacheParams *p) +TaggedPrefetcher::TaggedPrefetcher(const Params *p) : BasePrefetcher(p), latency(p->prefetch_latency), degree(p->prefetch_degree) { @@ -62,3 +62,8 @@ } +TaggedPrefetcher* +TaggedPrefetcherParams::create() +{ + return new TaggedPrefetcher(this); +}