00001
00002
00003 #ifndef _CPU_ROUTER_POWER_H
00004 #define _CPU_ROUTER_POWER_H
00005
00006
00007 #include <sst/core/introspectedComponent.h>
00008 #include <sst/core/link.h>
00009 #include <sst/core/timeConverter.h>
00010 #include "../power/power.h"
00011
00012 using namespace SST;
00013
00014 #if DBG_CPU_ROUTER_POWER
00015 #define _CPU_ROUTER_POWER_DBG( fmt, args...)\
00016 printf( "%d:Cpu_router_power::%s():%d: "fmt, _debug_rank, __FUNCTION__,__LINE__, ## args )
00017 #else
00018 #define _CPU_ROUTER_POWER_DBG( fmt, args...)
00019 #endif
00020
00021 class Cpu_router_power : public IntrospectedComponent {
00022 typedef enum { WAIT, SEND } state_t;
00023 typedef enum { WHO_NIC, WHO_MEM } who_t;
00024 public:
00025 Cpu_router_power( ComponentId_t id, Params_t& params ) :
00026 IntrospectedComponent( id ),
00027 params( params ),
00028 state(SEND),
00029 who(WHO_MEM),
00030 frequency( "2.2GHz" ) {
00031 _CPU_ROUTER_POWER_DBG( "new id=%lu\n", id );
00032 registerExit();
00033
00034 Params_t::iterator it = params.begin();
00035 while( it != params.end() ) {
00036 _CPU_ROUTER_POWER_DBG("key=%s value=%s\n", it->first.c_str(),it->second.c_str());
00037 if ( ! it->first.compare("clock") ) {
00038 frequency = it->second;
00039 }
00040 ++it;
00041 }
00042
00043 mem = configureLink( "MEM" );
00044 TimeConverter* tc = registerClock( frequency, new Clock::Handler<Cpu_router_power>(this,&Cpu_router_power::clock) );
00045
00046 mem->setDefaultTimeBase(tc);
00047 printf("CPU_ROUTER_POWER period: %ld\n",tc->getFactor());
00048 _CPU_ROUTER_POWER_DBG("Done registering clock\n");
00049 }
00050
00051 int Setup() {
00052
00053 power = new Power(getId());
00054 power->setChip(params);
00055 power->setTech(getId(), params, ROUTER, ORION);
00056 return 0;
00057 }
00058
00059 int Finish() {
00060 std::pair<bool, Pdissipation_t> res = readPowerStats(this);
00061 if(res.first) {
00062 using namespace io_interval; std::cout <<"ID " << getId() <<": link leakage power = " << res.second.leakagePower << " W" << std::endl;
00063 using namespace io_interval; std::cout <<"ID " << getId() <<": link dynamic power = " << res.second.runtimeDynamicPower << " W" << std::endl;
00064 using namespace io_interval; std::cout <<"ID " << getId() <<": Total power = " << res.second.currentPower << " W" << std::endl;
00065
00066
00067
00068 }
00069 _CPU_ROUTER_POWER_DBG("\n");
00070
00071 return 0;
00072 }
00073
00074
00075 private:
00076 Cpu_router_power( const Cpu_router_power& c );
00077 Cpu_router_power() : IntrospectedComponent(-1) {}
00078
00079 bool clock( Cycle_t );
00080
00081 Params_t params;
00082 Link* mem;
00083 state_t state;
00084 who_t who;
00085 std::string frequency;
00086
00087 Pdissipation_t pdata, pstats;
00088 Power *power;
00089 usagecounts_t mycounts;
00090
00091 friend class boost::serialization::access;
00092 template<class Archive>
00093 void serialize(Archive & ar, const unsigned int version ) {
00094 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Component);
00095 ar & BOOST_SERIALIZATION_NVP(params);
00096 ar & BOOST_SERIALIZATION_NVP(mem);
00097 ar & BOOST_SERIALIZATION_NVP(state);
00098 ar & BOOST_SERIALIZATION_NVP(who);
00099 ar & BOOST_SERIALIZATION_NVP(frequency);
00100 }
00101 };
00102
00103 #endif