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