00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef SST_CORE_INTROSPECTED_COMPONENT_H
00013 #define SST_CORE_INTROSPECTED_COMPONENT_H
00014 #include <sst/core/sst_types.h>
00015 #include <sst/core/serialization.h>
00016
00017 #include <cmath>
00018
00019 #include <iostream>
00020 #include <list>
00021 #include <map>
00022
00023 #if defined(__x86_64__) && defined(__APPLE__) && !defined(__USE_ISOC99)
00024
00025
00026 #define __USE_ISOC99 1
00027 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
00028 #pragma GCC diagnostic push
00029 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
00030 #endif
00031 #include <boost/numeric/interval.hpp>
00032 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
00033 #pragma GCC diagnostic pop
00034 #endif
00035 #undef __USE_ISOC99
00036 #else
00037
00038 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
00039 #pragma GCC diagnostic push
00040 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
00041 #endif
00042 #include <boost/numeric/interval.hpp>
00043 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
00044 #pragma GCC diagnostic pop
00045 #endif
00046
00047 #endif
00048 #include <boost/io/ios_state.hpp>
00049 #include <boost/any.hpp>
00050
00051 #include <sst/core/component.h>
00052
00053 #include <sst/core/timeConverter.h>
00054
00055 namespace io_interval {
00056 template<class T, class Policies, class CharType, class CharTraits>
00057 std::basic_ostream<CharType, CharTraits>
00058 &operator<<(std::basic_ostream<CharType, CharTraits> &stream,
00059 const boost::numeric::interval<T, Policies> &value)
00060 {
00061 if (empty(value)) {
00062 return stream << "nothing";
00063 } else if (singleton(value)) {
00064 boost::io::ios_precision_saver state(stream, std::numeric_limits<T>::digits10);
00065 return stream << lower(value);
00066 } else if (zero_in(value)) {
00067 return stream << "0~";
00068 } else {
00069 std::streamsize p = stream.precision();
00070 p = (p > 15) ? 15 : p - 1;
00071 double eps = 1.0; for(; p > 0; --p) { eps /= 10; }
00072 T eps2 = static_cast<T>(eps / 2) * norm(value);
00073 boost::numeric::interval<T, Policies> r = widen(value, eps2);
00074
00075 return stream << median(r) << " ± " << width(r)/2;
00076 }
00077 }
00078 }
00079
00080 using boost::any_cast;
00081
00082 namespace SST {
00083
00084 class Introspector;
00085
00086 typedef boost::numeric::interval<double> I;
00087
00088 typedef struct {
00089 I il1, il2, dl1, dl2, itlb, dtlb;
00090 I clock, bpred, rf, io, logic;
00091 I alu, fpu, mult, ib, issueQ, decoder, bypass, exeu;
00092 I pipeline, lsq, rat, rob, btb, L2, mc;
00093 I router, loadQ, renameU, schedulerU, L3, L1dir, L2dir;
00094 } itemized_t;
00095
00096 typedef struct
00097 {
00098
00099
00100 I TDP;
00101 I runtimeDynamicPower;
00102 I leakagePower;
00103 I peak;
00104 I currentPower;
00105 I averagePower;
00106 I totalEnergy;
00107 itemized_t itemizedRuntimeDynamicPower;
00108 itemized_t itemizedLeakagePower;
00109 itemized_t itemizedCurrentPower;
00110 itemized_t itemizedTDP;
00111 itemized_t itemizedPeak;
00112 itemized_t itemizedTotalPower;
00113 Time_t currentSimTime;
00114 }Pdissipation_t;
00115
00116
00117 typedef std::map<ComponentId_t, Pdissipation_t> PowerDatabase;
00118
00119
00120
00121
00122
00123 class IntrospectedComponent : public Component {
00124 public:
00125
00126
00127
00128
00129
00130 IntrospectedComponent( ComponentId_t id );
00131 virtual ~IntrospectedComponent() {}
00132
00133
00134 std::list<Introspector*> MyIntroList;
00135
00136
00137
00138
00139
00140 static PowerDatabase PDB;
00141
00142
00143 void regPowerStats(Pdissipation_t pusage);
00144
00145
00146
00147 std::pair<bool, Pdissipation_t> readPowerStats(Component* c);
00148
00149
00150
00151
00152
00153 class MonitorBase {
00154 public:
00155
00156 virtual boost::any operator()() = 0;
00157 virtual ~MonitorBase() {}
00158 };
00159
00160
00161 template <typename classT, typename returnT, typename argT = void>
00162 class MonitorFunction : public MonitorBase{
00163 private:
00164 typedef returnT (classT::*PtrMember)(argT);
00165 classT* object;
00166 const PtrMember member;
00167 argT data;
00168
00169 public:
00170 MonitorFunction( classT* const object, PtrMember member, argT data ) :
00171 object(object),
00172 member(member),
00173 data(data)
00174 {}
00175
00176
00177
00178
00179 boost::any operator()() {
00180 return static_cast<boost::any>( (const_cast<classT*>(object)->*member)(data) );
00181 }
00182 };
00183
00184 template <typename classT, typename returnT>
00185 class MonitorFunction<classT, returnT, void> : public MonitorBase{
00186 private:
00187 typedef returnT (classT::*PtrMember)();
00188 const PtrMember member;
00189 classT* object;
00190
00191 public:
00192 MonitorFunction( classT* const object, PtrMember member ) :
00193 member(member),
00194 object(object)
00195 {}
00196
00197
00198
00199
00200 boost::any operator()() {
00201 return static_cast<boost::any>( (const_cast<classT*>(object)->*member)() );
00202 }
00203 };
00204
00205 template <typename ptrT, typename idxT = void>
00206 class MonitorPointer : public MonitorBase{
00207 private:
00208 ptrT *data;
00209 idxT index;
00210
00211 public:
00212 MonitorPointer( ptrT* const data, idxT index ) :
00213 data(data),
00214 index(index)
00215 {}
00216
00217 boost::any operator()() {
00218 return static_cast<boost::any>( *data[index] );
00219 }
00220 };
00221
00222 template <typename ptrT>
00223 class MonitorPointer<ptrT, void> : public MonitorBase{
00224 private:
00225 ptrT* data;
00226
00227 public:
00228 MonitorPointer( ptrT* const data ) :
00229 data(data)
00230 {}
00231 boost::any operator()() {
00232
00233 return static_cast<boost::any>( *data );
00234 }
00235 };
00236
00237
00238
00239
00240 void registerIntrospector(std::string name);
00241
00242
00243
00244
00245
00246 void registerMonitor(std::string dataName, IntrospectedComponent::MonitorBase* handler);
00247
00248
00249 std::pair<bool, IntrospectedComponent::MonitorBase*> getMonitor(std::string dataname);
00250
00251 void triggerUpdate();
00252
00253
00254
00255
00256
00257 SimTime_t getFreq() {return defaultTimeBase->getFactor();}
00258
00259
00260
00261
00262
00263
00264 bool isTimeToPush(Cycle_t current, const char *name);
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 typedef std::map<std::string, IntrospectedComponent::MonitorBase*> MonitorMap_t;
00281
00282 protected:
00283
00284
00285
00286 MonitorMap_t monitorMap;
00287
00288
00289 protected:
00290 IntrospectedComponent();
00291
00292 private:
00293 friend class boost::serialization::access;
00294 template<class Archive>
00295 void serialize(Archive& ar, const unsigned int version);
00296 };
00297
00298 }
00299
00300 BOOST_CLASS_EXPORT_KEY(SST::IntrospectedComponent)
00301
00302 #endif // SST_CORE_INTROSPECTED_COMPONENT_H