src/Samples/SamplePrefetcher.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 // This is a sample class to demonstrate how to implement 
00034 // a prefetcher module.
00035 // You can activate this class by defining USE_SAMPLE_PREFETCHER
00036 // in this file.
00037 //
00038 
00039 #ifndef SAMPLES_SAMPLE_PREFETCHER_H
00040 #define SAMPLES_SAMPLE_PREFETCHER_H
00041 
00042 // USE_SAMPLE_PREFETCHER is referred in this file, 'User/UserResourceMap.h'
00043 // and  'User/UserInit.h'.
00044 //#define USE_SAMPLE_PREFETCHER 1
00045 
00046 
00047 #include "Sim/Foundation/Resource/ResourceNode.h"
00048 #include "Sim/Memory/Prefetcher/PrefetcherBase.h"
00049 
00050 // All Onikiri classes are placed in a 'Onikiri' namespace.
00051 namespace Onikiri
00052 {
00053     class Core;
00054 
00055     // PrefetcherBase inherits PhysicalResourceNode so
00056     // SamplePrefetcher does not need to inherit PhysicalResourceNode.
00057     class SamplePrefetcher : public PrefetcherBase
00058     {
00059     public:
00060 
00061         SamplePrefetcher()
00062         {
00063         }
00064         virtual ~SamplePrefetcher()
00065         {
00066         }
00067 
00068         //
00069         // --- PrefetcherBase
00070         // Initialize and Finalize must be implemented.
00071         //
00072         virtual void Initialize( InitPhase phase )
00073         {
00074             // Initialize of a base class must be called.
00075             PrefetcherBase::Initialize( phase );
00076 
00077             if( phase == INIT_PRE_CONNECTION ){
00078 
00079                 // After constructing and before object connection.
00080                 // LoadParam() must be called in this phase or later.
00081                 LoadParam();
00082 
00083             }
00084             else if ( phase == INIT_POST_CONNECTION ){
00085             }
00086         }
00087 
00088         virtual void Finalize()
00089         {
00090             ReleaseParam();
00091 
00092             // Finalize of a base class must be called.
00093             PrefetcherBase::Finalize();
00094         }
00095 
00096         virtual void OnCacheAccess( Cache* cache, const CacheAccess& access, bool hit )
00097         {
00098             // If the cache access is miss, prefetch a next line.
00099             if( !hit ){
00100                 CacheAccess prefetch = access;
00101 
00102                 // If you need an original address, it can be obtained from 'op'.
00103                 // 'access' may be masked by a line offset.
00104                 //CacheAccess access( op->GetMemAccess(), op, CacheAccess::OT_READ );
00105                 
00106                 prefetch.type = CacheAccess::OT_PREFETCH;
00107                 prefetch.address.address += PrefetcherBase::m_lineSize;
00108                 
00109                 // Prefetch target is set to PrefetcherBase from XML.
00110                 Prefetch( prefetch );
00111             }
00112         }
00113 
00114         // Parameter & resource map.
00115         // These contents in this map are bound to XML in SampleDefaultParam.h.
00116         BEGIN_PARAM_MAP("")
00117             BEGIN_PARAM_PATH( GetParamPath() )
00118             END_PARAM_PATH()
00119             BEGIN_PARAM_PATH( GetResultPath() )
00120             END_PARAM_PATH()
00121             
00122             // Chain to a map of a base class.
00123             CHAIN_BASE_PARAM_MAP( PrefetcherBase )
00124         END_PARAM_MAP()
00125 
00126         BEGIN_RESOURCE_MAP()
00127             // Chain to a map of a base class.
00128             CHAIN_BASE_RESOURCE_MAP( PrefetcherBase )
00129         END_RESOURCE_MAP()
00130 
00131     };
00132 
00133     //
00134     // Default parameters and connections for SamplePrefetcher.
00135     // This XML overwrite XML in DefaultParam.xml.
00136     //
00137 
00138 #ifdef USE_SAMPLE_PREFETCHER
00139 
00140     static char g_samplePrefetcherParam[] = "       \n\
00141                                                     \n\
00142     <?xml version='1.0' encoding='UTF-8'?>          \n\
00143     <Session>                                       \n\
00144                                                     \n\
00145       <Simulator>                                   \n\
00146         <Configurations>                            \n\
00147           <DefaultConfiguration>                    \n\
00148                                                     \n\
00149             <Structure>                             \n\
00150               <Copy>                                \n\
00151                                                     \n\
00152                 <SamplePrefetcher                   \n\
00153                   Count = 'CoreCount'               \n\
00154                   Name  = 'samplePrefetcher'        \n\
00155                 >                                   \n\
00156                     <Connection                     \n\
00157                         Name = 'cacheL2'            \n\
00158                         To = 'target'               \n\
00159                     />                              \n\
00160                 </SamplePrefetcher>                 \n\
00161                                                     \n\
00162                 <Cache Name = 'cacheL1D' />         \n\
00163                 <Cache Name = 'cacheL1I' />         \n\
00164                 <Cache Name = 'cacheL2' >           \n\
00165                     <Connection                     \n\
00166                         Name = 'samplePrefetcher'   \n\
00167                         To = 'prefetcher'           \n\
00168                     />                              \n\
00169                 </Cache>                            \n\
00170                                                     \n\
00171                                                     \n\
00172               </Copy>                               \n\
00173             </Structure>                            \n\
00174                                                     \n\
00175             <Parameter>                             \n\
00176                                                     \n\
00177               <SamplePrefetcher                     \n\
00178                 EnablePrefetch = '1'                \n\
00179                 OffsetBitSize = '6'                 \n\
00180                 Name  = 'samplePrefetcher'          \n\
00181               >                                     \n\
00182               </SamplePrefetcher>                   \n\
00183                                                     \n\
00184             </Parameter>                            \n\
00185           </DefaultConfiguration>                   \n\
00186         </Configurations>                           \n\
00187       </Simulator>                                  \n\
00188                                                     \n\
00189     </Session>                                      \n\
00190                                                     \n\
00191                                                     \n\
00192     ";
00193 
00194 #endif  // #ifdef USE_SAMPLE_PREFETCHER
00195 
00196 
00197 }
00198 
00199 
00200 #endif

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