00001
00002 #ifndef MEMORYMODEL_H
00003 #define MEMORYMODEL_H
00004
00005 #include <McSimDefs.h>
00006 #include <CycleTracker.h>
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 class MemoryModel
00024 {
00025
00026 enum MemOpType {MEMLOAD, MEMSTORE};
00027
00028
00029 class Cost {
00030 public:
00031 static const unsigned int LoadAfterLoad = 1;
00032 static const unsigned int LoadFromSTB = 2;
00033 static const unsigned int AverageStoreLatency = 25;
00034 static const unsigned int StoreAfterStore = 2;
00035 };
00036
00037 class Config {
00038 public:
00039 static const unsigned int StoreBufferSize = 8;
00040 };
00041
00042
00043 struct MemoryOp
00044 {
00045 InstructionNumber insnNum;
00046 Address address;
00047 unsigned int numBytes;
00048 CycleCount issueCycle;
00049 CycleCount satisfiedCycle;
00050 MemOpType op;
00051 struct MemoryOp *next;
00052 };
00053
00054 public:
00055 MemoryModel();
00056 ~MemoryModel();
00057 void initLatencies(unsigned int latTLB, unsigned int latL1, unsigned int latL2,
00058 unsigned int latMem);
00059 void initProbabilities(double pSTBHit, double pL1Hit, double pL2Hit,
00060 double pTLBMiss, double pICHit, double pIL2Hit,
00061 double pITLBMiss);
00062 void getDataLoadStats(unsigned long long *numLoads,
00063 unsigned long long *numSTBHits,
00064 unsigned long long *numL1Hits,
00065 unsigned long long *numL2Hits,
00066 unsigned long long *numMemoryHits,
00067 unsigned long long *numTLBMisses);
00068 void getInstLoadStats(unsigned long long *numILoads,
00069 unsigned long long *numICHits,
00070 unsigned long long *numIL2Hits,
00071 unsigned long long *numIMemoryHits,
00072 unsigned long long *numITLBMisses);
00073 void getStoreStats(unsigned long long *numStores );
00074 CycleCount serveLoad(CycleCount currentCycle, Address address,
00075 unsigned int numBytes, CycleTracker::CycleReason *reason);
00076 CycleCount serveILoad(CycleCount currentCycle, Address address,
00077 unsigned int numBytes, CycleTracker::CycleReason *reason);
00078 CycleCount serveStore(CycleCount currentCycle, Address address,
00079 unsigned int numBytes, CycleTracker::CycleReason *reason);
00080 private:
00081 int addToMemoryQ(CycleCount whenSatisfied, MemOpType type);
00082 unsigned int numberInMemoryQ(MemOpType memOp);
00083 double purgeMemoryQ(CycleCount upToCycle);
00084
00085 MemoryOp *memQHead, *memQTail, *lastLoad, *lastStore;
00086 unsigned int numLoadsInQ, numStoresInQ;
00087 unsigned int latencyL1, latencyL2, latencyMem, latencyTLB;
00088 double pSTBHit, pL1Hit, pL2Hit, pTLBMiss, pICHit, pIL2Hit, pITLBMiss;
00089 unsigned long long numL1Hits, numL2Hits, numMemoryHits, numTLBMisses;
00090 unsigned long long numICHits, numIL2Hits, numIMemoryHits, numITLBMisses;
00091 unsigned long long numSTBHits, numStores, numLoads, numILoads;
00092 };
00093
00094 #endif