00001 #ifndef _CPU_H
00002 #define _CPU_H
00003
00004 #include <sst/eventFunctor.h>
00005 #include <sst/component.h>
00006 #include <sst/link.h>
00007 #include <OffCpuIF.h>
00008 #include <McNiagara.h>
00009
00010 using namespace SST;
00011
00012 #define DBG_CPU 1
00013
00014 #if DBG_CPU
00015 #define _CPU_DBG( fmt, args...)\
00016 printf( "%d:Cpu::%s():%d: "fmt, _debug_rank, __FUNCTION__,__LINE__, ## args )
00017 #else
00018 #define _CPU_DBG( fmt, args...)
00019 #endif
00020
00021 class Cpu : public Component, OffCpuIF {
00022 typedef enum { WAIT, SEND } state_t;
00023 typedef enum { WHO_NIC, WHO_MEM } who_t;
00024 public:
00025 virtual void memoryAccess(OffCpuIF::access_mode mode,
00026 unsigned long long address,
00027 unsigned long data_size);
00028 virtual void NICAccess(OffCpuIF::access_mode mode, unsigned long data_size);
00029 Cpu( ComponentId_t id, Simulation* sim, Params_t& params ) :
00030 Component( id, sim ),
00031 params( params ),
00032 state(SEND),
00033 who(WHO_MEM),
00034 frequency( "2.2GHz" )
00035 {
00036 _CPU_DBG( "new id=%lu\n", id );
00037 inputfile = "./notavail_insthist.dat";
00038 iprobfile = "./notavail_instprob.dat";
00039 perffile = "./notavail_perfcnt.dat";
00040 outputfile = "./mc_output";
00041 registerExit();
00042
00043 Params_t::iterator it = params.begin();
00044 while( it != params.end() ) {
00045 _CPU_DBG("key=%s value=%s\n",
00046 it->first.c_str(),it->second.c_str());
00047 if ( ! it->first.compare("clock") ) {
00048
00049 frequency = it->second;
00050 } else if ( ! it->first.compare("mccpu_ihistfile") ) {
00051 inputfile = (it->second.c_str());
00052 } else if ( ! it->first.compare("mccpu_outputfile") ) {
00053 outputfile = (it->second.c_str());
00054 } else if ( ! it->first.compare("mccpu_iprobfile") ) {
00055 iprobfile = (it->second.c_str());
00056 } else if ( ! it->first.compare("mccpu_perffile") ) {
00057 perffile = (it->second.c_str());
00058 }
00059 ++it;
00060 }
00061
00062
00063
00064
00065 handler = new EventHandler< Cpu, bool, Cycle_t >
00066 ( this, &Cpu::clock );
00067 _CPU_DBG("-->frequency=%s\n",frequency.c_str());
00068
00069 memHandler = new EventHandler< Cpu, bool, Event*>
00070 (this, &Cpu::memEvent);
00071 memLink = LinkAdd( "memory", memHandler);
00072
00073
00074 TimeConverter* tc = registerClock( frequency, handler );
00075
00076
00077 mcCpu = new McNiagara();
00078 cyclesAtLastClock = 0;
00079 printf("CPU period: %ld\n",tc->getFactor());
00080 _CPU_DBG("Done registering clock\n");
00081 }
00082 int Setup() {
00083 _CPU_DBG(" (%s) (%s) (%s) (%s)\n", inputfile, iprobfile,
00084 perffile, outputfile);
00085 mcCpu->init(inputfile, this, iprobfile, perffile, 0, 0);
00086 return 0;
00087 }
00088 int Finish() {
00089 char filename[128];
00090 _CPU_DBG("\n");
00091 sprintf(filename, "%s.%d", outputfile, Id());
00092 mcCpu->fini(filename);
00093 return 0;
00094 }
00095
00096 private:
00097
00098 Cpu( const Cpu& c );
00099
00100
00101 bool clock( Cycle_t );
00102 ClockHandler_t* handler;
00103 bool handler1( Time_t time, Event *e );
00104 Event::Handler_t* memHandler;
00105 bool memEvent( Event* );
00106 McNiagara *mcCpu;
00107 unsigned long cyclesAtLastClock;
00108
00109 Params_t params;
00110 Link* memLink;
00111 state_t state;
00112 who_t who;
00113 std::string frequency;
00114 const char *inputfile;
00115 const char *iprobfile;
00116 const char *perffile;
00117 const char *outputfile;
00118 };
00119
00120 #endif