[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 | |
---|
[115] | 34 | //#define DETERMINISM |
---|
[77] | 35 | |
---|
| 36 | namespace soclib { namespace caba { |
---|
| 37 | |
---|
| 38 | |
---|
[78] | 39 | #define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param> |
---|
[77] | 40 | |
---|
[78] | 41 | //using soclib::common::uint32_log2; |
---|
| 42 | |
---|
[77] | 43 | //////////////////////////////// |
---|
| 44 | // Constructor |
---|
| 45 | //////////////////////////////// |
---|
| 46 | |
---|
[78] | 47 | tmpl(/**/)::VciSyntheticInitiator( |
---|
[77] | 48 | sc_module_name name, |
---|
[102] | 49 | const soclib::common::MappingTable &mt, |
---|
| 50 | const soclib::common::IntTab &vci_index, |
---|
| 51 | const uint32_t length, // Packet length (flit numbers) |
---|
[106] | 52 | const uint32_t rho, // Packets ratio on the network |
---|
| 53 | // const float rho, // Packets ratio on the network |
---|
[102] | 54 | const uint32_t depth, // Fifo depth |
---|
| 55 | const uint32_t xmesh, |
---|
| 56 | const uint32_t ymesh, |
---|
| 57 | const uint32_t bc_period, // Broadcast period, if no broadcast => 0 |
---|
| 58 | const uint32_t xmin, |
---|
| 59 | const uint32_t xmax, |
---|
| 60 | const uint32_t ymin, |
---|
| 61 | const uint32_t ymax |
---|
[78] | 62 | ) |
---|
[77] | 63 | |
---|
| 64 | : soclib::caba::BaseModule(name), |
---|
| 65 | |
---|
| 66 | p_clk("clk"), |
---|
| 67 | p_resetn("resetn"), |
---|
| 68 | p_vci("vci_ini"), |
---|
| 69 | |
---|
[98] | 70 | m_srcid( mt.indexForId(vci_index) ), |
---|
[77] | 71 | // FIFOs |
---|
[81] | 72 | m_length(length), |
---|
| 73 | m_rho(rho), |
---|
| 74 | m_depth(depth), |
---|
| 75 | m_xmesh(xmesh), |
---|
| 76 | m_ymesh(ymesh), |
---|
| 77 | m_bc_period(bc_period), |
---|
| 78 | m_xmin(xmin), |
---|
| 79 | m_xmax(xmax), |
---|
| 80 | m_ymin(ymin), |
---|
| 81 | m_ymax(ymax), |
---|
[78] | 82 | m_date_fifo("m_date_fifo", depth), |
---|
[115] | 83 | m_local_seed(m_srcid), |
---|
[102] | 84 | r_vci_fsm("r_vci_fsm") |
---|
[77] | 85 | { |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | SC_METHOD(transition); |
---|
| 89 | dont_initialize(); |
---|
| 90 | sensitive << p_clk.pos(); |
---|
| 91 | |
---|
| 92 | SC_METHOD(genMoore); |
---|
| 93 | dont_initialize(); |
---|
| 94 | sensitive << p_clk.neg(); |
---|
| 95 | |
---|
| 96 | } // end constructor |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | ///////////////////////////////// |
---|
[78] | 100 | tmpl(/**/)::~VciSyntheticInitiator() |
---|
[77] | 101 | ///////////////////////////////// |
---|
| 102 | { |
---|
| 103 | } |
---|
| 104 | |
---|
[81] | 105 | /////////////////////////////////// |
---|
[115] | 106 | tmpl(uint32_t)::destAdress() |
---|
[81] | 107 | /////////////////////////////////// |
---|
| 108 | { |
---|
[115] | 109 | return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ; |
---|
[81] | 110 | } |
---|
| 111 | |
---|
[98] | 112 | |
---|
| 113 | /////////////////////////////////// |
---|
[115] | 114 | tmpl(uint32_t)::destAdress(uint32_t *rand_seed) |
---|
[98] | 115 | /////////////////////////////////// |
---|
[115] | 116 | { |
---|
| 117 | return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ; |
---|
| 118 | } |
---|
[98] | 119 | |
---|
[106] | 120 | |
---|
[77] | 121 | ////////////////////////////////// |
---|
[106] | 122 | tmpl(void)::print_trace() |
---|
| 123 | ////////////////////////////////// |
---|
| 124 | { |
---|
| 125 | const char* state_str[] = { "IDLE", |
---|
| 126 | "SINGLE_SEND", |
---|
| 127 | "SINGLE_RECEIVE", |
---|
| 128 | "BC_SEND", |
---|
| 129 | "BC_RECEIVE" }; |
---|
| 130 | |
---|
| 131 | std::cout << "Vci_Synthetic_Initiator " << name() |
---|
[115] | 132 | << " : " << std::dec << m_cpt_cycles << " cycles " |
---|
[106] | 133 | << " : state = " << state_str[r_vci_fsm] |
---|
[115] | 134 | << " Adresse to send : " << std::hex << m_address_to_send |
---|
| 135 | << " Number of broadcast to receive : " << std::dec << m_bc_nrsp << std::endl; |
---|
[106] | 136 | } |
---|
| 137 | |
---|
| 138 | ////////////////////////////////// |
---|
| 139 | tmpl(void)::printStats() |
---|
| 140 | ////////////////////////////////// |
---|
| 141 | { |
---|
| 142 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | ////////////////////////////////// |
---|
[77] | 146 | tmpl(void)::transition() |
---|
[106] | 147 | ////////////////////////////////// |
---|
[77] | 148 | { |
---|
| 149 | // RESET |
---|
| 150 | if ( ! p_resetn.read() ) { |
---|
[98] | 151 | // Initializing seed for random numbers generation |
---|
[115] | 152 | #ifndef DETERMINISM |
---|
[98] | 153 | srand(time(NULL)); |
---|
[115] | 154 | #endif |
---|
[77] | 155 | |
---|
[98] | 156 | // Initializing FSMs |
---|
| 157 | r_vci_fsm = VCI_IDLE; |
---|
[77] | 158 | |
---|
[98] | 159 | // Initializing FIFOs |
---|
[78] | 160 | m_date_fifo.init(); |
---|
[77] | 161 | |
---|
| 162 | // Activity counters |
---|
| 163 | m_cpt_cycles = 0; |
---|
[81] | 164 | m_npackets = 0; |
---|
[77] | 165 | |
---|
[106] | 166 | r_broadcast_req = false; |
---|
| 167 | |
---|
[77] | 168 | return; |
---|
| 169 | } |
---|
| 170 | |
---|
[81] | 171 | bool date_fifo_put = false; |
---|
| 172 | bool date_fifo_get = false; |
---|
[77] | 173 | |
---|
[106] | 174 | // if (m_cpt_cycles == 0) { |
---|
| 175 | // m_rhos = 0.0 ; |
---|
| 176 | // } else { |
---|
| 177 | // m_rhos = static_cast<float>(m_npackets * m_length) / static_cast<float>(m_cpt_cycles) ; |
---|
| 178 | // } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | |
---|
[78] | 182 | switch ( r_vci_fsm.read() ) { |
---|
[77] | 183 | |
---|
[106] | 184 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
| 185 | //printStats(); |
---|
[77] | 186 | ////////////////// |
---|
[78] | 187 | case VCI_IDLE: |
---|
[77] | 188 | { |
---|
[98] | 189 | if (m_date_fifo.rok()){ |
---|
| 190 | if (r_broadcast_req.read()){ |
---|
[111] | 191 | m_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ; |
---|
[98] | 192 | r_vci_fsm = VCI_BC_SEND ; |
---|
| 193 | } else { |
---|
| 194 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
[115] | 195 | #ifdef DETERMINISM |
---|
| 196 | m_address_to_send = destAdress(&m_local_seed) << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh)); |
---|
| 197 | #else |
---|
[111] | 198 | m_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh)); |
---|
[115] | 199 | #endif |
---|
[98] | 200 | m_count = 0; |
---|
| 201 | } |
---|
| 202 | } |
---|
[77] | 203 | break; |
---|
| 204 | } |
---|
| 205 | ////////////////// |
---|
[78] | 206 | case VCI_SINGLE_SEND: |
---|
[77] | 207 | { |
---|
[98] | 208 | if (p_vci.cmdack.read()){ |
---|
| 209 | if (m_count == m_length-1) { |
---|
| 210 | m_start_latency1 = m_date_fifo.read(); |
---|
| 211 | m_start_latency2 = m_cpt_cycles; |
---|
| 212 | r_vci_fsm = VCI_SINGLE_RECEIVE ; |
---|
| 213 | } else { |
---|
| 214 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
[106] | 215 | m_count++; |
---|
[98] | 216 | } |
---|
| 217 | } |
---|
[77] | 218 | break; |
---|
| 219 | } |
---|
| 220 | ////////////////////// |
---|
[78] | 221 | case VCI_SINGLE_RECEIVE: |
---|
[77] | 222 | { |
---|
[98] | 223 | if (p_vci.rspval.read()) { |
---|
| 224 | m_start_latency1 = m_date_fifo.read(); |
---|
| 225 | m_start_latency2 = m_cpt_cycles; |
---|
| 226 | m_npackets++; |
---|
| 227 | date_fifo_get = true; |
---|
[106] | 228 | m_address_to_send = 0; |
---|
[81] | 229 | r_vci_fsm = VCI_IDLE ; |
---|
| 230 | } |
---|
[77] | 231 | break; |
---|
| 232 | } |
---|
| 233 | /////////////////// |
---|
[78] | 234 | case VCI_BC_SEND: |
---|
[77] | 235 | { |
---|
[111] | 236 | if (p_vci.cmdack.read()) { |
---|
| 237 | m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ; |
---|
| 238 | r_vci_fsm = VCI_BC_RECEIVE; |
---|
| 239 | break; |
---|
| 240 | } |
---|
[77] | 241 | } |
---|
| 242 | //////////////////// |
---|
[78] | 243 | case VCI_BC_RECEIVE: |
---|
[77] | 244 | { |
---|
[98] | 245 | if (p_vci.rspval.read()){ |
---|
[111] | 246 | if (m_bc_nrsp == 1) { |
---|
[98] | 247 | r_broadcast_req = false; |
---|
[106] | 248 | m_address_to_send = 0; |
---|
[98] | 249 | r_vci_fsm = VCI_IDLE ; |
---|
| 250 | } else { |
---|
| 251 | m_bc_nrsp--; |
---|
| 252 | r_vci_fsm = VCI_BC_RECEIVE ; |
---|
| 253 | } |
---|
| 254 | } |
---|
[77] | 255 | break; |
---|
| 256 | } |
---|
[78] | 257 | } // end switch vci_fsm |
---|
[77] | 258 | |
---|
| 259 | |
---|
[106] | 260 | /////////////////// Filling fifo |
---|
| 261 | if( ( (uint64_t)(m_rho*m_cpt_cycles) >= (uint64_t)(m_length*m_npackets*1000)) ){ |
---|
[81] | 262 | if (m_date_fifo.wok()){ |
---|
| 263 | date_fifo_put = true ; |
---|
| 264 | } |
---|
[106] | 265 | if (m_bc_period){ |
---|
| 266 | if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){ |
---|
| 267 | r_broadcast_req = true; |
---|
| 268 | } |
---|
[81] | 269 | } |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | if (date_fifo_put){ |
---|
| 273 | if (date_fifo_get){ |
---|
| 274 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
[77] | 275 | } else { |
---|
[81] | 276 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
[77] | 277 | } |
---|
| 278 | } else { |
---|
[81] | 279 | if (date_fifo_get){ |
---|
| 280 | m_date_fifo.simple_get(); |
---|
[77] | 281 | } |
---|
| 282 | } |
---|
[98] | 283 | |
---|
[77] | 284 | m_cpt_cycles++; |
---|
| 285 | |
---|
[81] | 286 | return; |
---|
| 287 | |
---|
[77] | 288 | } // end transition() |
---|
| 289 | |
---|
| 290 | ///////////////////////////// |
---|
| 291 | tmpl(void)::genMoore() |
---|
| 292 | ///////////////////////////// |
---|
| 293 | { |
---|
| 294 | //////////////////////////////////////////////////////////// |
---|
[98] | 295 | // Command signals on the p_vci port |
---|
[77] | 296 | //////////////////////////////////////////////////////////// |
---|
[98] | 297 | p_vci.cmd = vci_param::CMD_WRITE; |
---|
[81] | 298 | p_vci.be = 0xF; |
---|
| 299 | p_vci.pktid = 0; |
---|
[98] | 300 | p_vci.srcid = m_srcid; |
---|
[81] | 301 | p_vci.cons = false; |
---|
| 302 | p_vci.wrap = false; |
---|
| 303 | p_vci.contig = true; |
---|
| 304 | p_vci.clen = 0; |
---|
| 305 | p_vci.cfixed = false; |
---|
[77] | 306 | |
---|
| 307 | |
---|
[78] | 308 | switch ( r_vci_fsm.read() ) { |
---|
[77] | 309 | |
---|
[78] | 310 | ////////////////// |
---|
| 311 | case VCI_IDLE: |
---|
| 312 | { |
---|
[81] | 313 | p_vci.cmdval = false; |
---|
| 314 | p_vci.address = 0; |
---|
| 315 | p_vci.plen = 0; |
---|
| 316 | p_vci.wdata = 0; |
---|
| 317 | p_vci.trdid = 0; |
---|
| 318 | p_vci.eop = false; |
---|
[98] | 319 | p_vci.rspack = false; |
---|
[78] | 320 | break; |
---|
| 321 | } |
---|
| 322 | ////////////////// |
---|
| 323 | case VCI_SINGLE_SEND: |
---|
| 324 | { |
---|
[98] | 325 | p_vci.cmdval = true; |
---|
[106] | 326 | p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); |
---|
[98] | 327 | p_vci.plen = m_length*4; |
---|
| 328 | p_vci.wdata = 0; |
---|
| 329 | p_vci.trdid = 0; |
---|
| 330 | if (m_count == m_length - 1 ) { |
---|
| 331 | p_vci.eop = true; |
---|
| 332 | } else { |
---|
| 333 | p_vci.eop = false; |
---|
| 334 | } |
---|
| 335 | p_vci.rspack = false; |
---|
[78] | 336 | break; |
---|
| 337 | } |
---|
| 338 | ////////////////////// |
---|
| 339 | case VCI_SINGLE_RECEIVE: |
---|
| 340 | { |
---|
[98] | 341 | p_vci.cmdval = false; |
---|
| 342 | p_vci.address = 0; |
---|
| 343 | p_vci.plen = 0; |
---|
| 344 | p_vci.wdata = 0; |
---|
| 345 | p_vci.trdid = 0; |
---|
| 346 | p_vci.eop = false; |
---|
| 347 | p_vci.rspack = true; |
---|
| 348 | break; |
---|
[78] | 349 | } |
---|
| 350 | /////////////////// |
---|
| 351 | case VCI_BC_SEND: |
---|
| 352 | { |
---|
[98] | 353 | p_vci.cmdval = true; |
---|
[106] | 354 | p_vci.address = (addr_t) m_address_to_send; |
---|
[98] | 355 | p_vci.plen = 4; |
---|
| 356 | p_vci.wdata = 0; |
---|
| 357 | p_vci.trdid = 0; |
---|
| 358 | p_vci.eop = true; |
---|
| 359 | p_vci.rspack = false; |
---|
[78] | 360 | break; |
---|
| 361 | } |
---|
| 362 | //////////////////// |
---|
| 363 | case VCI_BC_RECEIVE: |
---|
| 364 | { |
---|
[98] | 365 | p_vci.cmdval = false; |
---|
| 366 | p_vci.address = 0; |
---|
| 367 | p_vci.plen = 0; |
---|
| 368 | p_vci.wdata = 0; |
---|
| 369 | p_vci.trdid = 0; |
---|
| 370 | p_vci.eop = false; |
---|
| 371 | p_vci.rspack = true; |
---|
[78] | 372 | break; |
---|
| 373 | } |
---|
| 374 | } // end switch vci_fsm |
---|
[77] | 375 | |
---|
| 376 | } // end genMoore() |
---|
| 377 | |
---|
| 378 | }} // end name space |
---|