• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/introspectedComponent.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef SST_INTROSPECTED_COMPONENT_H
00014 #define SST_INTROSPECTED_COMPONENT_H
00015 
00016 #include <cmath>
00017 #include <iostream>
00018 #include <list>
00019 #include <deque>
00020 #include <map>
00021 
00022 #if defined(__x86_64__) && defined(__APPLE__) && !defined(__USE_ISOC99)
00023 // Boost interval sometimes doesn't detect the correct method for
00024 // manipulating FP rounting on MacOS
00025 #define __USE_ISOC99 1
00026 #include <boost/numeric/interval.hpp>
00027 #undef __USE_ISOC99
00028 #else
00029 #include <boost/numeric/interval.hpp>
00030 #endif
00031 #include <boost/io/ios_state.hpp>
00032 
00033 #include <sst/core/component.h>
00034 #include <sst/core/sst_types.h>
00035 //#include <sst/core/linkMap.h>
00036 #include <sst/core/timeConverter.h>
00037 
00038 namespace io_interval {  // from boost interval io example (io_wide)
00039 template<class T, class Policies, class CharType, class CharTraits>
00040 std::basic_ostream<CharType, CharTraits> 
00041 &operator<<(std::basic_ostream<CharType, CharTraits> &stream,
00042             const boost::numeric::interval<T, Policies> &value)
00043 {
00044     if (empty(value)) {
00045         return stream << "nothing";
00046     } else if (singleton(value)) {
00047         boost::io::ios_precision_saver state(stream, std::numeric_limits<T>::digits10);
00048         return stream << lower(value);
00049     } else if (zero_in(value)) {
00050         return stream << "0~";
00051     } else {
00052         std::streamsize p = stream.precision();
00053         p = (p > 15) ? 15 : p - 1;
00054         double eps = 1.0; for(; p > 0; --p) { eps /= 10; }
00055         T eps2 = static_cast<T>(eps / 2) * norm(value);
00056         boost::numeric::interval<T, Policies> r = widen(value, eps2);
00057         //return stream << '[' << lower(r) << ',' << upper(r) << ']';
00058         return stream << median(r) << " ± " << width(r)/2;
00059     }
00060 }
00061 }
00062 
00063 namespace SST {
00064 
00065 class Introspector;
00066 
00067 typedef boost::numeric::interval<double> I;
00068 
00069 typedef struct {
00070     I il1, il2, dl1, dl2, itlb, dtlb;
00071     I clock, bpred, rf, io, logic;
00072     I alu, fpu, mult, ib, issueQ, decoder, bypass, exeu;
00073     I pipeline, lsq, rat, rob, btb, L2, mc;
00074     I router, loadQ, renameU, schedulerU, L3, L1dir, L2dir;
00075 } itemized_t;
00076 
00077 typedef struct 
00078 {
00079     //I internalPower;
00080     //I switchingPower;
00081     I TDP; //thermal dynamic power
00082     I runtimeDynamicPower;
00083     I leakagePower; //=threshold leakage + gate leakage
00084     I peak;
00085     I currentPower; //=leakage + rumtimeDynamic
00086     I averagePower;
00087     I totalEnergy;
00088     itemized_t itemizedRuntimeDynamicPower;
00089     itemized_t itemizedLeakagePower;
00090     itemized_t itemizedCurrentPower;
00091     itemized_t itemizedTDP;
00092     itemized_t itemizedPeak;
00093     itemized_t itemizedTotalPower; //total energy
00094     Time_t currentSimTime;
00095 }Pdissipation_t;
00096 
00097 
00098 typedef std::map<ComponentId_t, Pdissipation_t> PowerDatabase;
00099 
00100 /**
00101  * Main component object for the simulation. 
00102  *  All models inherit from this. 
00103  */
00104 class IntrospectedComponent : public Component {
00105 public:
00106     typedef  std::map<std::string,std::string> Params_t;
00107     
00108     typedef std::map<std::string, int> Monitors;
00109 
00110 
00111     /** List of common statistics that components want to be monitored.
00112         When editting the list, make sure to edit the vector, stats_name, 
00113         in introspectedComponent::getDataID() as well. */
00114     enum stats {/*McPAT counters*/
00115         core_temperature,branch_read, branch_write, RAS_read, RAS_write,
00116         il1_read, il1_readmiss, IB_read, IB_write, BTB_read, BTB_write,
00117         int_win_read, int_win_write, fp_win_read, fp_win_write, ROB_read, ROB_write,
00118         iFRAT_read, iFRAT_write, iFRAT_search, fFRAT_read, fFRAT_write, fFRAT_search, iRRAT_write, fRRAT_write,
00119         ifreeL_read, ifreeL_write, ffreeL_read, ffreeL_write, idcl_read, fdcl_read,
00120         dl1_read, dl1_readmiss, dl1_write, dl1_writemiss, LSQ_read, LSQ_write,
00121         itlb_read, itlb_readmiss, dtlb_read, dtlb_readmiss,
00122         int_regfile_reads, int_regfile_writes, float_regfile_reads, float_regfile_writes, RFWIN_read, RFWIN_write,
00123         bypass_access, router_access,
00124         L2_read, L2_readmiss, L2_write, L2_writemiss, L3_read, L3_readmiss, L3_write, L3_writemiss,
00125         L1Dir_read, L1Dir_readmiss, L1Dir_write, L1Dir_writemiss, L2Dir_read, L2Dir_readmiss, L2Dir_write, L2Dir_writemiss,
00126         memctrl_read, memctrl_write,
00127         /*sim-panalyzer counters*/
00128         alu_access, fpu_access, mult_access, io_access,
00129         /*zesto counters */
00130         cache_load_lookups, cache_load_misses, cache_store_lookups, cache_store_misses, writeback_lookups, 
00131         writeback_misses, prefetch_lookups, prefetch_misses, 
00132         prefetch_insertions, prefetch_useful_insertions, MSHR_occupancy /* Miss Status Handling Registers total occupancy */,
00133         MSHR_full_cycles /* number of cycles when full */, WBB_insertions /* total writebacks */, WBB_victim_insertions /* total non-dirty insertions */,
00134         WBB_combines /* number eliminated due to write combining */, WBB_occupancy /* total occupancy */, WBB_full_cycles /* number of cycles when full */,
00135         WBB_hits, WBB_victim_hits, core_lookups, core_misses, MSHR_combos,
00136         /*IntSim*/
00137         ib_access, issueQ_access, decoder_access, pipeline_access, lsq_access,
00138         rat_access, rob_access, btb_access, l2_access, mc_access,
00139         loadQ_access, rename_access, scheduler_access, l3_access, l1dir_access, l2dir_access,
00140         /*DRAMSim*/
00141         dram_backgroundEnergy, dram_burstEnergy, dram_actpreEnergy, dram_refreshEnergy,
00142         /*router/NoC*/
00143         router_delay, local_message,
00144         /*power data*/
00145         current_power, leakage_power, runtime_power, total_power, peak_power     }; 
00146 
00147     /** Constructor. Generally only called by the factory class. 
00148         @param id Unique component ID
00149         @param sim Pointer to the global simulation object */
00150     IntrospectedComponent( ComponentId_t id );
00151     virtual ~IntrospectedComponent() {} 
00152 
00153     /** List of id of introspectors that monitor this component. */
00154     std::list<Introspector*> MyIntroList;
00155 
00156     // Power
00157     /** Central power/energy database that stores power dissipation data 
00158         (including current power, total energy, peak power, etc) of the components 
00159         on the same rank.*/
00160     static PowerDatabase PDB;
00161     /** Register/update power dissipation data in the central power database 
00162         @param pusage Structure that contains power dissipation data of a component */
00163     void regPowerStats(Pdissipation_t pusage);      
00164     /** Read power dissipation data of this component from database 
00165         @param c Pointer to the component that one whats to query power
00166         from the central power database */
00167     std::pair<bool, Pdissipation_t> readPowerStats(Component* c);
00168 
00169 
00170     //Introspector
00171     /** Get the period set by defaultTimeBase, which is usually set by Component::registerClock().
00172         This can be used by clever components to ensure they only compute statistics data when needed.
00173         Returns the time between two handler function calls. (For introspectors, this means time
00174         between introspections.) */
00175     SimTime_t getFreq() {return defaultTimeBase->getFactor();}
00176     /** Add the statistical integer data to the map of monitors 
00177         for this component. The map, monitorINT, stores both the name and the ID of the integer data.
00178         @param paramName Description of the integer data*/
00179     void registerMonitorInt(std::string dataName);
00180     /** Arbitrary statistical integer data monitoring. Returns a pair<> which indicates
00181         if the component has a monitor associated with the string
00182         indicated by "dataName", and (if so) the ID of the integer data.
00183         @param dataName Description of the integer data*/
00184     std::pair<bool, int> ifMonitorIntData(std::string dataName);
00185     /** Add the statistical double data to the map of monitors 
00186         for this component. The map, monitorDOUBLE, stores both the name and the ID of the double data.
00187         @param dataName Description of the double data*/        
00188     void registerMonitorDouble(std::string dataName);
00189     /** Arbitrary statistical double data monitoring. Returns a pair<> which indicates
00190         if the component has a monitor associated with the string
00191         indicated by "dataName", and (if so) the ID of the double data.
00192         @param dataName Description of the double data*/
00193     std::pair<bool, int> ifMonitorDoubleData(std::string dataName);
00194     /** Add the "id" of a introspector to an internal list, MyIntroList.
00195         Indicates the introspector monitors the component.
00196         @param id ID of the introspector that monitors the component*/
00197     void addToIntroList(Introspector *introspector);
00198     /** Check if current is the time for the component to push/report data (e.g. power)
00199         by querying its introspector.
00200         @param current Current cycle from component's view
00201         @param type Component type of the introspector that component queries about push frequency*/ 
00202     bool isTimeToPush(Cycle_t current, const char *type);
00203     /** Return the value of the integer data indicated by "dataID" and "index" (if the data structure is a table).
00204         Each component type needs to implement its own getIntData. The function is usually called by introspector pull
00205         mechanism.
00206         @param dataID ID of the integer data
00207         @param index of the table (if the data structure is a table); default is set to 0 */ 
00208     virtual uint64_t getIntData(int dataID, int index=0){ return 0;}
00209     /** Return the value of the double data indicated by "dataID" and "index" (if the data structure is a table).
00210         Each component type needs to implement its own getDoubleData. The function is usually called by introspector pull
00211         mechanism.
00212         @param dataID ID of the integer data
00213         @param index of the table (if the data structure is a table); default is set to 0 */ 
00214     virtual double getDoubleData(int dataID, int index=0){ return 0;}
00215     /** Returns the ID of the data associated with the string indicated by "dataName".
00216         This function is usually called in introspectedComponent::registerMonitorInt() or Component::registerMonitorDouble().
00217         @param dataName Description of the integer data*/
00218     int getDataID(std::string dataName);
00219 
00220 protected:
00221     /** Database of integer monitors (arbitrary integer data that a
00222         compopent wishes to be monitored) available through
00223         introspectedComponent::getMonitorIntData() */   
00224     Monitors monitorINT;
00225     /** Database of double monitors (arbitrary double data that a
00226         compopent wishes to be monitored) available through
00227         introspectedComponent::getMonitorDoubleData() */        
00228     Monitors monitorDOUBLE;
00229         
00230 private:
00231     IntrospectedComponent(); // For serialization only
00232     
00233     friend class boost::serialization::access;
00234     template<class Archive>
00235     void serialize(Archive& ar, const unsigned int version);
00236 }; 
00237 
00238 }
00239 
00240 BOOST_CLASS_EXPORT_KEY(SST::IntrospectedComponent)
00241 
00242 #endif

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1