00001
00002
00003
00004 #ifndef _CPU_POWER_H
00005 #define _CPU_POWER_H
00006
00007 #include <sst/core/eventFunctor.h>
00008 #include <sst/core/component.h>
00009 #include <sst/core/link.h>
00010 #include <sst/core/timeConverter.h>
00011 #include "../power/power.h"
00012
00013 using namespace SST;
00014
00015 #if DBG_CPU_POWER
00016 #define _CPU_POWER_DBG( fmt, args...)\
00017 printf( "%d:Cpu_power::%s():%d: "fmt, _debug_rank, __FUNCTION__,__LINE__, ## args )
00018 #else
00019 #define _CPU_POWER_DBG( fmt, args...)
00020 #endif
00021
00022 class Cpu_power : public Component {
00023 typedef enum { WAIT, SEND } state_t;
00024 typedef enum { WHO_NIC, WHO_MEM } who_t;
00025 public:
00026 Cpu_power( ComponentId_t id, Params_t& params ) :
00027 Component( id ),
00028 params( params ),
00029 state(SEND),
00030 who(WHO_MEM),
00031 frequency( "2.2GHz" )
00032 {
00033 _CPU_POWER_DBG( "new id=%lu\n", id );
00034
00035 registerExit();
00036
00037 Params_t::iterator it = params.begin();
00038 while( it != params.end() ) {
00039 _CPU_POWER_DBG("key=%s value=%s\n",
00040 it->first.c_str(),it->second.c_str());
00041 if ( ! it->first.compare("clock") ) {
00042 frequency = it->second;
00043 }
00044 ++it;
00045 }
00046
00047 mem = LinkAdd( "MEM" );
00048 handler = new EventHandler< Cpu_power, bool, Cycle_t >
00049 ( this, &Cpu_power::clock );
00050 TimeConverter* tc = registerClock( frequency, handler );
00051 printf("CPU_POWER period: %ld\n",tc->getFactor());
00052 _CPU_POWER_DBG("Done registering clock\n");
00053
00054
00055 }
00056 int Setup() {
00057
00058 power = new Power(Id());
00059 power->setTech(Id(), params, CACHE_IL1);
00060
00061 power->setTech(Id(), params, CACHE_DL1);
00062
00063 power->setTech(Id(), params, CACHE_ITLB);
00064 power->setTech(Id(), params, CACHE_DTLB);
00065 power->setTech(Id(), params, RF);
00066 power->setTech(Id(), params, IB);
00067
00068
00069 power->setTech(Id(), params, PIPELINE);
00070 power->setTech(Id(), params, BYPASS);
00071
00072 power->setTech(Id(), params, EXEU_ALU);
00073 power->setTech(Id(), params, EXEU_FPU);
00074
00075 power->setTech(Id(), params, LSQ);
00076 power->setTech(Id(), params, BPRED);
00077 power->setTech(Id(), params, SCHEDULER_U);
00078 power->setTech(Id(), params, RENAME_U);
00079
00080
00081 power->setTech(Id(), params, BTB);
00082 power->setTech(Id(), params, LOAD_Q);
00083 power->setTech(Id(), params, CACHE_L1DIR);
00084 power->setTech(Id(), params, CACHE_L2DIR);
00085 power->setTech(Id(), params, CACHE_L2);
00086 power->setTech(Id(), params, CACHE_L3);
00087 power->setTech(Id(), params, MEM_CTRL);
00088 power->setTech(Id(), params, ROUTER);
00089
00090
00091 return 0;
00092 }
00093 int Finish() {
00094 pstats = readPowerStats(this);
00095 using namespace io_interval; std::cout <<"ID " << Id() <<": current total power = " << pstats.currentPower << " W" << std::endl;
00096 using namespace io_interval; std::cout <<"ID " << Id() <<": leakage power = " << pstats.leakagePower << " W" << std::endl;
00097 using namespace io_interval; std::cout <<"ID " << Id() <<": runtime power = " << pstats.runtimeDynamicPower << " W" << std::endl;
00098 using namespace io_interval; std::cout <<"ID " << Id() <<": TDP = " << pstats.TDP << " W" << std::endl;
00099 using namespace io_interval; std::cout <<"ID " << Id() <<": total energy = " << pstats.totalEnergy << " J" << std::endl;
00100 using namespace io_interval; std::cout <<"ID " << Id() <<": peak power = " << pstats.peak << " W" << std::endl;
00101 using namespace io_interval; std::cout <<"ID " << Id() <<": current cycle = " << pstats.currentCycle << std::endl;
00102 _CPU_POWER_DBG("\n");
00103 unregisterExit();
00104 return 0;
00105 }
00106
00107
00108 private:
00109
00110 Cpu_power( const Cpu_power& c );
00111
00112 bool clock( Cycle_t );
00113 ClockHandler_t* handler;
00114 bool handler1( Time_t time, Event *e );
00115
00116 Params_t params;
00117 Link* mem;
00118 state_t state;
00119 who_t who;
00120 std::string frequency;
00121
00122 Pdissipation_t pdata, pstats;
00123 Power *power;
00124 usagecounts_t mycounts;
00125
00126
00127 #if WANT_CHECKPOINT_SUPPORT2
00128 BOOST_SERIALIZE {
00129 printf("cpu_power::serialize()\n");
00130 _AR_DBG( Cpu_power, "start\n" );
00131 printf(" doing void cast\n");
00132 BOOST_VOID_CAST_REGISTER( Cpu_power*, Component* );
00133 printf(" base serializing: component\n");
00134 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Component );
00135 printf(" serializing: mem\n");
00136 ar & BOOST_SERIALIZATION_NVP( mem );
00137 printf(" serializing: handler\n");
00138 ar & BOOST_SERIALIZATION_NVP( handler );
00139 _AR_DBG( Cpu_power, "done\n" );
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 #endif
00170 };
00171
00172 #endif