src/Sim/Memory/Prefetcher/StreamPrefetcher.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 //
00033 // Stream prefetcher implementation.
00034 // This implementation is based on a model described in the below paper.
00035 // 
00036 // "Feedback Directed Prefetching: Improving the Performance 
00037 //  and Bandwidth-Efficiency of Hardware Prefetchers", 
00038 // Santhosh Srinathyz et al., HPCA 07
00039 //
00040 //
00041 
00042 #ifndef __STREAM_PREFETCHER_H__
00043 #define __STREAM_PREFETCHER_H__
00044 
00045 #include "Sim/Memory/Prefetcher/PrefetcherBase.h"
00046 #include "Sim/Memory/Cache/CacheExtraStateTable.h"
00047 
00048 namespace Onikiri
00049 {
00050 
00051     class StreamPrefetcher : public PrefetcherBase
00052     {
00053     protected:
00054 
00055         int m_distance;
00056         int m_degree;
00057         int m_streamTableSize;
00058         int m_trainingWindowSize;
00059         int m_trainingThreshold;
00060 
00061         u64 m_effectiveDistance;        // An effective distance is calculated 
00062                                         // by a 'distance' parameter and a line size.
00063         u64 m_effectiveTrainingWindow;  //
00064 
00065         // Statistics
00066         s64 m_numAllocatedStream;
00067         s64 m_numMonitioredStream;
00068         s64 m_numAscendingMonitioredStream;
00069         s64 m_numDesscendingMonitioredStream;
00070         double m_numAvgMonitoredStreamLength;
00071         s64 m_numTrainingAccess;
00072         s64 m_numAlocatingAccess;
00073 
00074         enum StreamStatus
00075         {
00076             SS_INVALID,
00077             SS_TRAINING,    // Including 'Allocated' state as 'trainingCount' == 0.
00078             SS_MONITOR
00079         };
00080 
00081         struct Stream
00082         {
00083             StreamStatus status;    // Stream status
00084 
00085             Addr orig;      // An first accessed address of a stream 
00086             Addr addr;      // A current 'start' address of a stream 
00087 
00088             int  count;     // Access count 
00089             bool ascending; // Stream direction
00090 
00091             Stream()
00092             {
00093                 Reset();
00094             }
00095 
00096             void Reset()
00097             {
00098                 status = SS_INVALID;
00099                 ascending = true;
00100                 count = 0;
00101             }
00102 
00103             String ToString() const;
00104         };
00105 
00106         typedef 
00107             shttl::table< Stream > 
00108             StreamTable;
00109 
00110         StreamTable m_streamTable;
00111 
00112         // Do prefetch an address specified by a stream and update a stream. 
00113         void Prefetch( const CacheAccess& kickerAccess, Stream* stream );
00114 
00115         // Returns whether 'addr' is in a window specified by the remaining arguments or not .
00116         // 'ascending' means a direction of a window. 
00117         bool IsInWindow( const Addr& addr, const Addr& start, u64 windowSize, bool ascending );
00118         bool IsInWindow( u64 addr, u64 start, u64 windowSize, bool ascending );
00119 
00120         // Check and update entries with SS_MONITOR status in the stream table.
00121         // Returns whether any entries are updated or not.
00122         bool UpdateMonitorStream( const CacheAccess& access );
00123 
00124         // Check and update entries with SS_TRAINING status in the stream table.
00125         bool UpdateTrainingStream( const CacheAccess& access );
00126 
00127         // Allocate a new entry in the stream table.
00128         void AllocateStream( const CacheAccess& access );
00129 
00130     public:
00131         
00132         StreamPrefetcher();
00133         ~StreamPrefetcher();
00134 
00135         // --- PrefetcherIF
00136         virtual void OnCacheAccess( Cache* cache, const CacheAccess& access, bool hit );
00137 
00138         // --- PhysicalResourceNode
00139         virtual void Initialize(InitPhase phase);
00140 
00141         BEGIN_PARAM_MAP("")
00142             BEGIN_PARAM_PATH( GetParamPath() )
00143                 PARAM_ENTRY( "@Distance",        m_distance );
00144                 PARAM_ENTRY( "@Degree",          m_degree );
00145                 PARAM_ENTRY( "@StreamTableSize", m_streamTableSize );
00146                 PARAM_ENTRY( "@TrainingWindowSize", m_trainingWindowSize );
00147                 PARAM_ENTRY( "@TrainingThreashold", m_trainingThreshold );
00148             END_PARAM_PATH()
00149             BEGIN_PARAM_PATH( GetResultPath() )
00150                 PARAM_ENTRY( "@NumAllocatedStream", m_numAllocatedStream );
00151                 PARAM_ENTRY( "@NumMonitioredStream", m_numMonitioredStream );
00152                 PARAM_ENTRY( "@NumAscendingMonitioredStream",   m_numAscendingMonitioredStream );
00153                 PARAM_ENTRY( "@NumDesscendingMonitioredStream", m_numDesscendingMonitioredStream );
00154                 PARAM_ENTRY( "@NumAvgMonitoredStreamLength",    m_numAvgMonitoredStreamLength );
00155                 PARAM_ENTRY( "@NumTrainingAccess",  m_numTrainingAccess );
00156                 PARAM_ENTRY( "@NumAlocatingAccess", m_numAlocatingAccess );
00157             END_PARAM_PATH()
00158             CHAIN_BASE_PARAM_MAP( PrefetcherBase )
00159         END_PARAM_MAP()
00160 
00161         BEGIN_RESOURCE_MAP()
00162             CHAIN_BASE_RESOURCE_MAP( PrefetcherBase )
00163         END_RESOURCE_MAP()
00164     };
00165 
00166 
00167 }; // namespace Onikiri
00168 
00169 #endif // __STREAM_PREFETCHER_H__
00170 

Onikiri2に対してTue Jun 18 14:34:24 2013に生成されました。  doxygen 1.4.7