00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _BIT_BUCKET_H
00019 #define _BIT_BUCKET_H
00020
00021 #include <sst/core/event.h>
00022 #include <sst/core/component.h>
00023 #include <sst/core/link.h>
00024
00025
00026 using namespace SST;
00027
00028 #define DBG_BIT_BUCKET 1
00029 #if DBG_BIT_BUCKET
00030 #define _BIT_BUCKET_DBG(lvl, fmt, args...)\
00031 if (bit_bucket_debug >= lvl) { \
00032 printf("%d:Bit_bucket::%s():%d: " fmt, _debug_rank, __FUNCTION__, __LINE__, ## args); \
00033 }
00034 #else
00035 #define _BIT_BUCKET_DBG(lvl, fmt, args...)
00036 #endif
00037
00038
00039
00040
00041
00042 typedef enum {BIT_BUCKET_WRITE_START= 200, BIT_BUCKET_WRITE_DONE, BIT_BUCKET_READ_START,
00043 BIT_BUCKET_READ_DONE} bit_bucket_op_t;
00044
00045
00046 class Bit_bucket : public Component {
00047 public:
00048 Bit_bucket(ComponentId_t id, Params_t& params) :
00049 Component(id),
00050 params(params)
00051 {
00052 Params_t::iterator it= params.begin();
00053 bit_bucket_debug= 0;
00054 read_pipe= 0;
00055 write_pipe= 0;
00056 write_bw= 0;
00057 read_bw= 0;
00058 bytes_written= 0;
00059 bytes_read= 0;
00060 total_read_delay= 0;
00061 total_write_delay= 0;
00062 total_reads= 0;
00063 total_writes= 0;
00064
00065
00066 while (it != params.end()) {
00067 if (!it->first.compare("debug")) {
00068 sscanf(it->second.c_str(), "%d", &bit_bucket_debug);
00069
00070 } else if (!it->first.compare("write_bw")) {
00071 sscanf(it->second.c_str(), "%lud", (uint64_t *)&write_bw);
00072
00073 } else if (!it->first.compare("read_bw")) {
00074 sscanf(it->second.c_str(), "%lud", (uint64_t *)&read_bw);
00075 }
00076
00077 ++it;
00078 }
00079
00080
00081 if ((write_bw == 0) || (read_bw == 0)) {
00082 _BIT_BUCKET_DBG(0, "You need to supply a write_bw and read_bw in the configuration!\n");
00083 _ABORT(Bit_bucket, "Check the input XML file!\n");
00084 }
00085
00086
00087
00088 TimeConverter *tc= registerTimeBase("1ns", true);
00089
00090
00091 net= configureLink("STORAGE", new Event::Handler<Bit_bucket>
00092 (this, &Bit_bucket::handle_events));
00093 if (net == NULL) {
00094 _BIT_BUCKET_DBG(0, "Expected a link named \"STORAGE\" which is missing!\n");
00095 _ABORT(Bit_bucket, "Check the input XML file!\n");
00096 }
00097
00098
00099 self_link= configureSelfLink("Me", new Event::Handler<Bit_bucket>
00100 (this, &Bit_bucket::handle_events));
00101 if (self_link == NULL) {
00102 _ABORT(Ghost_pattern, "That was no good!\n");
00103 }
00104
00105 net->setDefaultTimeBase(tc);
00106 self_link->setDefaultTimeBase(tc);
00107 }
00108
00109
00110
00111 private:
00112
00113 Bit_bucket(const Bit_bucket &c);
00114 void handle_events(Event *);
00115
00116 Params_t params;
00117 Link *net;
00118 Link *self_link;
00119 int bit_bucket_debug;
00120 SimTime_t read_pipe;
00121 SimTime_t write_pipe;
00122 uint64_t write_bw;
00123 uint64_t read_bw;
00124 uint64_t bytes_written;
00125 uint64_t bytes_read;
00126 uint64_t total_read_delay;
00127 uint64_t total_write_delay;
00128 uint64_t total_reads;
00129 uint64_t total_writes;
00130
00131
00132 friend class boost::serialization::access;
00133 template<class Archive>
00134 void serialize(Archive & ar, const unsigned int version )
00135 {
00136 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Component);
00137 ar & BOOST_SERIALIZATION_NVP(params);
00138 }
00139
00140 template<class Archive>
00141 friend void save_construct_data(Archive & ar,
00142 const Bit_bucket * t,
00143 const unsigned int file_version)
00144 {
00145 _AR_DBG(Bit_bucket,"\n");
00146 ComponentId_t id = t->getId();
00147 Params_t params = t->params;
00148 ar << BOOST_SERIALIZATION_NVP(id);
00149 ar << BOOST_SERIALIZATION_NVP(params);
00150 }
00151
00152 template<class Archive>
00153 friend void load_construct_data(Archive & ar,
00154 Bit_bucket * t,
00155 const unsigned int file_version)
00156 {
00157 _AR_DBG(Bit_bucket,"\n");
00158 ComponentId_t id;
00159 Params_t params;
00160 ar >> BOOST_SERIALIZATION_NVP(id);
00161 ar >> BOOST_SERIALIZATION_NVP(params);
00162 ::new(t)Bit_bucket(id, params);
00163 }
00164 };
00165
00166 #endif // _BIT_BUCKET_H_