#include"mem/cache/prefetch/queued.hh" #include"params/StreamPrefetcher.hh" // Direction of stream for each stream entry in the stream table
#include"base/types.hh"
namespace gem5 {
namespace prefetch {
enumStreamDirection{ ASCENDING = 1, // For example - A, A+1, A+2 DESCENDING = -1, // For example - A, A-1, A-2 INVALID = 0 }; // Status of a stream entry in the stream table. enumStreamStatus{ INV = 0, TRAINING = 1, // Stream training is not over yet. Once trained will move to MONITOR status MONITOR = 2// Monitor and Request: Stream entry ready for issuing prefetch requests };
classStream : public Queued { protected: staticconstuint32_t MaxContexts = 64; // Creates per-core stream tables for upto 64 processor cores uint32_t tableSize; // Number of entries in a stream table constbool useMasterId; // Use the master-id to train the streams uint32_t degree; // Determines the number of prefetch reuquests to be issued at a time uint32_t distance; // Determines the prefetch distance
/* StreamTableEntry Stores the basic attributes of a stream table entry. */ classStreamTableEntry {
public: int LRU_index; Addr allocAddr; // Address that initiated the stream training Addr startAddr; // First address of a stream Addr endAddr; // Last address of a stream StreamDirection trainedDirection; // Direction of trained stream (Ascending or Descending) StreamStatus status; // Status of the stream entry StreamDirection trendDirection[2]; // Stores the last two stream directions of an entry
}; voidresetEntry(StreamTableEntry *this_entry);
/* Creating a StreamTable for each core with Tablesize as the number of stream entries */ StreamTableEntry **StreamTable[MaxContexts];
public: Stream(const StreamPrefetcherParams &p); ~Stream(); /* Function called by cache controller to initiate the stream training process */ // void calculatePrefetch(const PacketPtr &pkt, std::vector<AddrPriority> &addresses); voidcalculatePrefetch(const PrefetchInfo &pfi, std::vector<AddrPriority> &addresses); };
} // namespace prefetch } // namespace gem5
#endif// __MEM_CACHE_PREFETCH_STREAM_HH__
二、修改Prefetcher.py
文件路径:./src/mem/cache/prefetch/Prefetcher.py
新增代码块
1 2 3 4 5 6 7 8 9 10
classStreamPrefetcher(QueuedPrefetcher): type = 'StreamPrefetcher' cxx_class = 'gem5::prefetch::Stream' cxx_header = "mem/cache/prefetch/stream.hh" table_sets = Param.Int(16, "Number of sets in PC lookup table") table_assoc = Param.Int(4, "Associativity of PC lookup table") tableSize = Param.Int(8, "Number of sets in PC lookup table") distance = Param.Int(5, "Associativity of PC lookup table") use_master_id = Param.Bool(True, "Use master id based history") degree = Param.Int(4, "Number of prefetches to generate")