[77] | 1 | /* -*- c++ -*- |
---|
| 2 | * File : vci_traffic_generator.cpp |
---|
| 3 | * Date : 26/08/2010 |
---|
| 4 | * Copyright : UPMC / LIP6 |
---|
| 5 | * Authors : Christophe Choichillon |
---|
| 6 | * |
---|
| 7 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
| 8 | * |
---|
| 9 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
| 10 | * |
---|
| 11 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU Lesser General Public License as published |
---|
| 13 | * by the Free Software Foundation; version 2.1 of the License. |
---|
| 14 | * |
---|
| 15 | * SoCLib is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * Lesser General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU Lesser General Public |
---|
| 21 | * License along with SoCLib; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
| 23 | * 02110-1301 USA |
---|
| 24 | * |
---|
| 25 | * SOCLIB_LGPL_HEADER_END |
---|
| 26 | * |
---|
| 27 | * Maintainers: christophe.choichillon@lip6.fr |
---|
| 28 | */ |
---|
| 29 | |
---|
[78] | 30 | #include "../include/vci_synthetic_initiator.h" |
---|
[106] | 31 | #include <iostream> |
---|
[77] | 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | namespace soclib { namespace caba { |
---|
| 36 | |
---|
| 37 | |
---|
[78] | 38 | #define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param> |
---|
[77] | 39 | |
---|
[78] | 40 | //using soclib::common::uint32_log2; |
---|
| 41 | |
---|
[77] | 42 | //////////////////////////////// |
---|
| 43 | // Constructor |
---|
| 44 | //////////////////////////////// |
---|
| 45 | |
---|
[78] | 46 | tmpl(/**/)::VciSyntheticInitiator( |
---|
[77] | 47 | sc_module_name name, |
---|
[102] | 48 | const soclib::common::MappingTable &mt, |
---|
| 49 | const soclib::common::IntTab &vci_index, |
---|
| 50 | const uint32_t length, // Packet length (flit numbers) |
---|
[106] | 51 | const uint32_t rho, // Packets ratio on the network |
---|
| 52 | // const float rho, // Packets ratio on the network |
---|
[102] | 53 | const uint32_t depth, // Fifo depth |
---|
| 54 | const uint32_t xmesh, |
---|
| 55 | const uint32_t ymesh, |
---|
| 56 | const uint32_t bc_period, // Broadcast period, if no broadcast => 0 |
---|
| 57 | const uint32_t xmin, |
---|
| 58 | const uint32_t xmax, |
---|
| 59 | const uint32_t ymin, |
---|
| 60 | const uint32_t ymax |
---|
[78] | 61 | ) |
---|
[77] | 62 | |
---|
| 63 | : soclib::caba::BaseModule(name), |
---|
| 64 | |
---|
| 65 | p_clk("clk"), |
---|
| 66 | p_resetn("resetn"), |
---|
| 67 | p_vci("vci_ini"), |
---|
| 68 | |
---|
[98] | 69 | m_srcid( mt.indexForId(vci_index) ), |
---|
[77] | 70 | // FIFOs |
---|
[81] | 71 | m_length(length), |
---|
| 72 | m_rho(rho), |
---|
| 73 | m_depth(depth), |
---|
| 74 | m_xmesh(xmesh), |
---|
| 75 | m_ymesh(ymesh), |
---|
| 76 | m_bc_period(bc_period), |
---|
| 77 | m_xmin(xmin), |
---|
| 78 | m_xmax(xmax), |
---|
| 79 | m_ymin(ymin), |
---|
| 80 | m_ymax(ymax), |
---|
[78] | 81 | m_date_fifo("m_date_fifo", depth), |
---|
[102] | 82 | r_vci_fsm("r_vci_fsm") |
---|
[77] | 83 | { |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | SC_METHOD(transition); |
---|
| 87 | dont_initialize(); |
---|
| 88 | sensitive << p_clk.pos(); |
---|
| 89 | |
---|
| 90 | SC_METHOD(genMoore); |
---|
| 91 | dont_initialize(); |
---|
| 92 | sensitive << p_clk.neg(); |
---|
| 93 | |
---|
| 94 | } // end constructor |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | ///////////////////////////////// |
---|
[78] | 98 | tmpl(/**/)::~VciSyntheticInitiator() |
---|
[77] | 99 | ///////////////////////////////// |
---|
| 100 | { |
---|
| 101 | } |
---|
| 102 | |
---|
[81] | 103 | /////////////////////////////////// |
---|
[98] | 104 | tmpl(size_t)::destAdress() |
---|
[81] | 105 | /////////////////////////////////// |
---|
| 106 | { |
---|
[106] | 107 | return (size_t) (rand() % (m_xmesh * m_ymesh)) ; |
---|
[81] | 108 | } |
---|
| 109 | |
---|
[98] | 110 | |
---|
| 111 | /////////////////////////////////// |
---|
| 112 | // tmpl(void)::destAdress(/*size_t X_local, size_t Y_local,*/ size_t &X_dest, size_t &Y_dest) |
---|
| 113 | /////////////////////////////////// |
---|
| 114 | // { |
---|
| 115 | // size_t x_dest_calc, y_dest_calc; |
---|
| 116 | // do{ |
---|
| 117 | // x_dest_calc = (rand()%m_xmesh); |
---|
| 118 | // y_dest_calc = (rand()%m_ymesh); |
---|
| 119 | // } while((x_dest_calc = m_x) && (y_dest_calc == m_y)); |
---|
| 120 | // } |
---|
| 121 | |
---|
[106] | 122 | |
---|
[77] | 123 | ////////////////////////////////// |
---|
[106] | 124 | tmpl(void)::print_trace() |
---|
| 125 | ////////////////////////////////// |
---|
| 126 | { |
---|
| 127 | const char* state_str[] = { "IDLE", |
---|
| 128 | "SINGLE_SEND", |
---|
| 129 | "SINGLE_RECEIVE", |
---|
| 130 | "BC_SEND", |
---|
| 131 | "BC_RECEIVE" }; |
---|
| 132 | |
---|
| 133 | std::cout << "Vci_Synthetic_Initiator " << name() |
---|
| 134 | << " : " << m_cpt_cycles << " cycles " |
---|
| 135 | << " : state = " << state_str[r_vci_fsm] |
---|
| 136 | << " Adresse to send : " << m_address_to_send << std::endl; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | ////////////////////////////////// |
---|
| 140 | tmpl(void)::printStats() |
---|
| 141 | ////////////////////////////////// |
---|
| 142 | { |
---|
| 143 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | ////////////////////////////////// |
---|
[77] | 147 | tmpl(void)::transition() |
---|
[106] | 148 | ////////////////////////////////// |
---|
[77] | 149 | { |
---|
| 150 | // RESET |
---|
| 151 | if ( ! p_resetn.read() ) { |
---|
[98] | 152 | // Initializing seed for random numbers generation |
---|
| 153 | srand(time(NULL)); |
---|
[77] | 154 | |
---|
[98] | 155 | // Initializing FSMs |
---|
| 156 | r_vci_fsm = VCI_IDLE; |
---|
[77] | 157 | |
---|
[98] | 158 | // Initializing FIFOs |
---|
[78] | 159 | m_date_fifo.init(); |
---|
[77] | 160 | |
---|
| 161 | // Activity counters |
---|
| 162 | m_cpt_cycles = 0; |
---|
[81] | 163 | m_npackets = 0; |
---|
[77] | 164 | |
---|
[106] | 165 | r_broadcast_req = false; |
---|
| 166 | |
---|
[77] | 167 | return; |
---|
| 168 | } |
---|
| 169 | |
---|
[81] | 170 | bool date_fifo_put = false; |
---|
| 171 | bool date_fifo_get = false; |
---|
[77] | 172 | |
---|
[106] | 173 | // if (m_cpt_cycles == 0) { |
---|
| 174 | // m_rhos = 0.0 ; |
---|
| 175 | // } else { |
---|
| 176 | // m_rhos = static_cast<float>(m_npackets * m_length) / static_cast<float>(m_cpt_cycles) ; |
---|
| 177 | // } |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
[78] | 181 | switch ( r_vci_fsm.read() ) { |
---|
[77] | 182 | |
---|
[106] | 183 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
| 184 | //printStats(); |
---|
[77] | 185 | ////////////////// |
---|
[78] | 186 | case VCI_IDLE: |
---|
[77] | 187 | { |
---|
[98] | 188 | if (m_date_fifo.rok()){ |
---|
| 189 | if (r_broadcast_req.read()){ |
---|
[106] | 190 | m_address_to_send = (((((((((m_xmin << 5) | m_xmax ) << 5 ) | m_ymin ) << 5 ) | m_ymax ) << 5 ) << vci_param::N-(4*5) ) | 0x3) | 0 ; |
---|
[98] | 191 | r_vci_fsm = VCI_BC_SEND ; |
---|
| 192 | } else { |
---|
| 193 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
[106] | 194 | m_address_to_send = destAdress() << 32-10; |
---|
[98] | 195 | m_count = 0; |
---|
| 196 | } |
---|
| 197 | } |
---|
[77] | 198 | break; |
---|
| 199 | } |
---|
| 200 | ////////////////// |
---|
[78] | 201 | case VCI_SINGLE_SEND: |
---|
[77] | 202 | { |
---|
[98] | 203 | if (p_vci.cmdack.read()){ |
---|
| 204 | if (m_count == m_length-1) { |
---|
| 205 | m_start_latency1 = m_date_fifo.read(); |
---|
| 206 | m_start_latency2 = m_cpt_cycles; |
---|
| 207 | r_vci_fsm = VCI_SINGLE_RECEIVE ; |
---|
| 208 | } else { |
---|
| 209 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
[106] | 210 | m_count++; |
---|
[98] | 211 | } |
---|
| 212 | } |
---|
[77] | 213 | break; |
---|
| 214 | } |
---|
| 215 | ////////////////////// |
---|
[78] | 216 | case VCI_SINGLE_RECEIVE: |
---|
[77] | 217 | { |
---|
[98] | 218 | if (p_vci.rspval.read()) { |
---|
| 219 | m_start_latency1 = m_date_fifo.read(); |
---|
| 220 | m_start_latency2 = m_cpt_cycles; |
---|
| 221 | m_npackets++; |
---|
| 222 | date_fifo_get = true; |
---|
[106] | 223 | m_address_to_send = 0; |
---|
[81] | 224 | r_vci_fsm = VCI_IDLE ; |
---|
| 225 | } |
---|
[77] | 226 | break; |
---|
| 227 | } |
---|
| 228 | /////////////////// |
---|
[78] | 229 | case VCI_BC_SEND: |
---|
[77] | 230 | { |
---|
[98] | 231 | m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin); |
---|
| 232 | r_vci_fsm = VCI_BC_SEND; |
---|
[77] | 233 | break; |
---|
| 234 | } |
---|
| 235 | //////////////////// |
---|
[78] | 236 | case VCI_BC_RECEIVE: |
---|
[77] | 237 | { |
---|
[98] | 238 | if (p_vci.rspval.read()){ |
---|
| 239 | if (m_bc_nrsp == 0) { |
---|
| 240 | r_broadcast_req = false; |
---|
[106] | 241 | m_address_to_send = 0; |
---|
[98] | 242 | r_vci_fsm = VCI_IDLE ; |
---|
| 243 | } else { |
---|
| 244 | m_bc_nrsp--; |
---|
| 245 | r_vci_fsm = VCI_BC_RECEIVE ; |
---|
| 246 | } |
---|
| 247 | } |
---|
[77] | 248 | break; |
---|
| 249 | } |
---|
[78] | 250 | } // end switch vci_fsm |
---|
[77] | 251 | |
---|
| 252 | |
---|
[106] | 253 | /////////////////// Filling fifo |
---|
| 254 | if( ( (uint64_t)(m_rho*m_cpt_cycles) >= (uint64_t)(m_length*m_npackets*1000)) ){ |
---|
[81] | 255 | if (m_date_fifo.wok()){ |
---|
| 256 | date_fifo_put = true ; |
---|
| 257 | } |
---|
[106] | 258 | if (m_bc_period){ |
---|
| 259 | if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){ |
---|
| 260 | r_broadcast_req = true; |
---|
| 261 | } |
---|
[81] | 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | if (date_fifo_put){ |
---|
| 266 | if (date_fifo_get){ |
---|
| 267 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
[77] | 268 | } else { |
---|
[81] | 269 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
[77] | 270 | } |
---|
| 271 | } else { |
---|
[81] | 272 | if (date_fifo_get){ |
---|
| 273 | m_date_fifo.simple_get(); |
---|
[77] | 274 | } |
---|
| 275 | } |
---|
[98] | 276 | |
---|
[77] | 277 | m_cpt_cycles++; |
---|
| 278 | |
---|
[81] | 279 | return; |
---|
| 280 | |
---|
[77] | 281 | } // end transition() |
---|
| 282 | |
---|
| 283 | ///////////////////////////// |
---|
| 284 | tmpl(void)::genMoore() |
---|
| 285 | ///////////////////////////// |
---|
| 286 | { |
---|
| 287 | //////////////////////////////////////////////////////////// |
---|
[98] | 288 | // Command signals on the p_vci port |
---|
[77] | 289 | //////////////////////////////////////////////////////////// |
---|
[98] | 290 | p_vci.cmd = vci_param::CMD_WRITE; |
---|
[81] | 291 | p_vci.be = 0xF; |
---|
| 292 | p_vci.pktid = 0; |
---|
[98] | 293 | p_vci.srcid = m_srcid; |
---|
[81] | 294 | p_vci.cons = false; |
---|
| 295 | p_vci.wrap = false; |
---|
| 296 | p_vci.contig = true; |
---|
| 297 | p_vci.clen = 0; |
---|
| 298 | p_vci.cfixed = false; |
---|
[77] | 299 | |
---|
| 300 | |
---|
[78] | 301 | switch ( r_vci_fsm.read() ) { |
---|
[77] | 302 | |
---|
[78] | 303 | ////////////////// |
---|
| 304 | case VCI_IDLE: |
---|
| 305 | { |
---|
[81] | 306 | p_vci.cmdval = false; |
---|
| 307 | p_vci.address = 0; |
---|
| 308 | p_vci.plen = 0; |
---|
| 309 | p_vci.wdata = 0; |
---|
| 310 | p_vci.trdid = 0; |
---|
| 311 | p_vci.eop = false; |
---|
[98] | 312 | p_vci.rspack = false; |
---|
[78] | 313 | break; |
---|
| 314 | } |
---|
| 315 | ////////////////// |
---|
| 316 | case VCI_SINGLE_SEND: |
---|
| 317 | { |
---|
[98] | 318 | p_vci.cmdval = true; |
---|
[106] | 319 | p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); |
---|
[98] | 320 | p_vci.plen = m_length*4; |
---|
| 321 | p_vci.wdata = 0; |
---|
| 322 | p_vci.trdid = 0; |
---|
| 323 | if (m_count == m_length - 1 ) { |
---|
| 324 | p_vci.eop = true; |
---|
| 325 | } else { |
---|
| 326 | p_vci.eop = false; |
---|
| 327 | } |
---|
| 328 | p_vci.rspack = false; |
---|
[78] | 329 | break; |
---|
| 330 | } |
---|
| 331 | ////////////////////// |
---|
| 332 | case VCI_SINGLE_RECEIVE: |
---|
| 333 | { |
---|
[98] | 334 | p_vci.cmdval = false; |
---|
| 335 | p_vci.address = 0; |
---|
| 336 | p_vci.plen = 0; |
---|
| 337 | p_vci.wdata = 0; |
---|
| 338 | p_vci.trdid = 0; |
---|
| 339 | p_vci.eop = false; |
---|
| 340 | p_vci.rspack = true; |
---|
| 341 | break; |
---|
[78] | 342 | } |
---|
| 343 | /////////////////// |
---|
| 344 | case VCI_BC_SEND: |
---|
| 345 | { |
---|
[98] | 346 | p_vci.cmdval = true; |
---|
[106] | 347 | p_vci.address = (addr_t) m_address_to_send; |
---|
[98] | 348 | p_vci.plen = 4; |
---|
| 349 | p_vci.wdata = 0; |
---|
| 350 | p_vci.trdid = 0; |
---|
| 351 | p_vci.eop = true; |
---|
| 352 | p_vci.rspack = false; |
---|
[78] | 353 | break; |
---|
| 354 | } |
---|
| 355 | //////////////////// |
---|
| 356 | case VCI_BC_RECEIVE: |
---|
| 357 | { |
---|
[98] | 358 | p_vci.cmdval = false; |
---|
| 359 | p_vci.address = 0; |
---|
| 360 | p_vci.plen = 0; |
---|
| 361 | p_vci.wdata = 0; |
---|
| 362 | p_vci.trdid = 0; |
---|
| 363 | p_vci.eop = false; |
---|
| 364 | p_vci.rspack = true; |
---|
[78] | 365 | break; |
---|
| 366 | } |
---|
| 367 | } // end switch vci_fsm |
---|
[77] | 368 | |
---|
| 369 | } // end genMoore() |
---|
| 370 | |
---|
| 371 | }} // end name space |
---|