00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef SIM_MEMORY_PREFETCHER_STRIDE_PREFETCHER_H
00037 #define SIM_MEMORY_PREFETCHER_STRIDE_PREFETCHER_H
00038
00039 #include "Sim/Memory/Prefetcher/PrefetcherBase.h"
00040 #include "Sim/Memory/Cache/CacheExtraStateTable.h"
00041
00042 namespace Onikiri
00043 {
00044
00045 class StridePrefetcher : public PrefetcherBase
00046 {
00047 int m_distance;
00048 int m_degree;
00049 int m_streamTableSize;
00050
00051
00052 s64 m_numPrefetchingStream;
00053 double m_numAvgPrefetchStreamLength;
00054
00055 enum StreamStatus
00056 {
00057 SS_INVALID,
00058 SS_ALLOCATED,
00059 SS_PREFETCHING
00060 };
00061
00062
00063 static const int CONFIDENCE_INIT = 0;
00064 static const int CONFIDENCE_MIN = 0;
00065 static const int CONFIDENCE_MAX = 7;
00066 static const int CONFIDENCE_INC = 1;
00067 static const int CONFIDENCE_DEC = 4;
00068 static const int CONFIDENCE_PREDICTION_THREASHOLD = 7;
00069
00070
00071 struct Stream
00072 {
00073 StreamStatus status;
00074
00075 Addr pc;
00076
00077 Addr orig;
00078 Addr addr;
00079 s64 stride;
00080
00081 int count;
00082 int streamLength;
00083 shttl::counter<> confidence;
00084
00085 Stream()
00086 {
00087 Reset();
00088 confidence.set(
00089 CONFIDENCE_INIT,
00090 CONFIDENCE_MIN,
00091 CONFIDENCE_MAX,
00092 CONFIDENCE_INC,
00093 CONFIDENCE_DEC,
00094 CONFIDENCE_PREDICTION_THREASHOLD
00095 );
00096 }
00097
00098 void Reset()
00099 {
00100 status = SS_INVALID;
00101 stride = 0;
00102
00103 count = 0;
00104 streamLength = 0;
00105 confidence.reset();
00106 }
00107
00108 String ToString() const;
00109 };
00110
00111 typedef
00112 shttl::table< Stream >
00113 StreamTable;
00114
00115 StreamTable m_streamTable;
00116
00117
00118 void Prefetch( OpIterator op, Stream* stream );
00119
00120 public:
00121
00122 StridePrefetcher();
00123 ~StridePrefetcher();
00124
00125
00126 virtual void OnCacheAccess( Cache* cache, const CacheAccess& access, bool hit );
00127
00128
00129 virtual void Initialize(InitPhase phase);
00130
00131 BEGIN_PARAM_MAP("")
00132 BEGIN_PARAM_PATH( GetParamPath() )
00133 PARAM_ENTRY( "@Distance", m_distance );
00134 PARAM_ENTRY( "@Degree", m_degree );
00135 PARAM_ENTRY( "@StreamTableSize", m_streamTableSize );
00136 END_PARAM_PATH()
00137 BEGIN_PARAM_PATH( GetResultPath() )
00138 PARAM_ENTRY( "@NumPrefetchingStream", m_numPrefetchingStream );
00139 PARAM_ENTRY( "@NumAvgPrefetchStreamLength", m_numAvgPrefetchStreamLength );
00140 END_PARAM_PATH()
00141 CHAIN_BASE_PARAM_MAP( PrefetcherBase )
00142 END_PARAM_MAP()
00143
00144 BEGIN_RESOURCE_MAP()
00145 CHAIN_BASE_RESOURCE_MAP( PrefetcherBase )
00146 END_RESOURCE_MAP()
00147 };
00148
00149
00150 };
00151
00152 #endif // SIM_MEMORY_PREFETCHER_STRIDE_PREFETCHER_H
00153