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

sst/elements/cpu/cpu.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 _CPU_H
00014 #define _CPU_H
00015 
00016 #include <sst/core/component.h>
00017 #include <sst/core/link.h>
00018 #include <sst/core/timeConverter.h>
00019 
00020 using namespace SST;
00021 
00022 #if DBG_CPU
00023 #define _CPU_DBG( fmt, args...)\
00024          printf( "%d:Cpu::%s():%d: "fmt, _debug_rank, __FUNCTION__,__LINE__, ## args )
00025 #else
00026 #define _CPU_DBG( fmt, args...)
00027 #endif
00028 
00029 class Cpu : public Component {
00030         typedef enum { WAIT, SEND } state_t;
00031         typedef enum { WHO_NIC, WHO_MEM } who_t;
00032 
00033 public:
00034     Cpu( ComponentId_t id, Params_t& params ) :
00035         Component( id ),
00036         params( params ),
00037         state(SEND),
00038         who(WHO_MEM), 
00039         frequency( "2.2GHz" )
00040     {
00041         _CPU_DBG( "new id=%lu\n", id );
00042 
00043         registerExit();
00044 
00045         Params_t::iterator it = params.begin(); 
00046         while( it != params.end() ) { 
00047             _CPU_DBG("key=%s value=%s\n",
00048                      it->first.c_str(),it->second.c_str());
00049             if ( ! it->first.compare("clock") ) {
00050                 /*                     sscanf( it->second.c_str(), "%f", &frequency ); */
00051                 frequency = it->second;
00052             }    
00053             ++it;
00054         } 
00055             
00056         mem = configureLink( "MEM" );
00057         _CPU_DBG("-->frequency=%s\n",frequency.c_str());
00058 
00059 //         handler = new SST::EventHandler< Cpu, bool, Cycle_t >
00060 //             ( this, &Cpu::clock );
00061 
00062 //         TimeConverter* tc = registerClock( frequency, handler );
00063         TimeConverter* tc = registerClock( frequency, new Clock::Handler<Cpu>(this,&Cpu::clock) );
00064 
00065         mem->setDefaultTimeBase(tc);
00066         printf("CPU period: %ld\n",(long int) tc->getFactor());
00067         _CPU_DBG("Done registering clock\n");
00068             
00069     }
00070 
00071     int Setup() {
00072         _CPU_DBG("\n");
00073         return 0;
00074     }
00075 
00076     int Finish() {
00077         _CPU_DBG("\n");
00078         return 0;
00079     }
00080 
00081 private:
00082     Cpu( const Cpu& c );
00083     Cpu() :  Component(-1) {} // for serialization only
00084 
00085     bool clock( Cycle_t );
00086 //     bool handler1( Time_t time, Event *e );
00087 
00088     Params_t    params;
00089     Link*       mem;
00090     state_t     state;
00091     who_t       who;
00092     std::string frequency;
00093 
00094     friend class boost::serialization::access;
00095     template<class Archive>
00096     void serialize(Archive & ar, const unsigned int version )
00097     {
00098         ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Component);
00099         ar & BOOST_SERIALIZATION_NVP(params);
00100         ar & BOOST_SERIALIZATION_NVP(mem);
00101         ar & BOOST_SERIALIZATION_NVP(state);
00102         ar & BOOST_SERIALIZATION_NVP(who);
00103         ar & BOOST_SERIALIZATION_NVP(frequency);
00104     }
00105 };
00106 
00107 #endif

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