[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 | { |
---|
[124] | 109 | for(int i = 0; i < tab_size ; i++){ |
---|
| 110 | delete r_req_id[i]; |
---|
| 111 | } |
---|
| 112 | delete r_req_id; |
---|
[77] | 113 | } |
---|
| 114 | |
---|
[81] | 115 | /////////////////////////////////// |
---|
[115] | 116 | tmpl(uint32_t)::destAdress() |
---|
[81] | 117 | /////////////////////////////////// |
---|
| 118 | { |
---|
[115] | 119 | return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ; |
---|
[81] | 120 | } |
---|
| 121 | |
---|
[98] | 122 | |
---|
| 123 | /////////////////////////////////// |
---|
[115] | 124 | tmpl(uint32_t)::destAdress(uint32_t *rand_seed) |
---|
[98] | 125 | /////////////////////////////////// |
---|
[115] | 126 | { |
---|
| 127 | return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ; |
---|
| 128 | } |
---|
[98] | 129 | |
---|
[106] | 130 | |
---|
[77] | 131 | ////////////////////////////////// |
---|
[106] | 132 | tmpl(void)::print_trace() |
---|
| 133 | ////////////////////////////////// |
---|
| 134 | { |
---|
[123] | 135 | const char* state_cmd_str[] = { "IDLE", |
---|
| 136 | "SINGLE_SEND", |
---|
| 137 | "BC_SEND"}; |
---|
[106] | 138 | |
---|
[123] | 139 | const char* state_bc_rsp_str[] = {"IDLE", |
---|
| 140 | "WAIT_RSP"}; |
---|
| 141 | |
---|
[106] | 142 | std::cout << "Vci_Synthetic_Initiator " << name() |
---|
[115] | 143 | << " : " << std::dec << m_cpt_cycles << " cycles " |
---|
[123] | 144 | << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] |
---|
| 145 | << " : state_rsp_fsm = " << state_bc_rsp_str[r_bc_rsp_fsm] |
---|
[115] | 146 | << " Adresse to send : " << std::hex << m_address_to_send |
---|
[123] | 147 | << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() |
---|
[124] | 148 | << " Number of packets sent : " << std::dec << m_npackets << " " << m_id_to_send << std::endl; |
---|
[123] | 149 | for(int i = 0; i < (1<<vci_param::T) ; i++){ |
---|
[125] | 150 | std::cout << "ID : " << i << " " << (uint64_t)(r_req_id[i][0].read()) << " " << (uint64_t)(r_req_id[i][1].read()) << std::endl; |
---|
[123] | 151 | } |
---|
[106] | 152 | } |
---|
| 153 | |
---|
| 154 | ////////////////////////////////// |
---|
| 155 | tmpl(void)::printStats() |
---|
| 156 | ////////////////////////////////// |
---|
| 157 | { |
---|
[122] | 158 | std::cout << name() << " : "<< std::dec << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
| 159 | std::cout << ((double)m_latency1/(double)m_npackets) << " | " << ((double)m_latency2/(double)m_npackets) << std::endl; |
---|
| 160 | if(m_bc_period) |
---|
| 161 | std::cout << ((double)m_latency_bc/(double)m_nb_bc) << std::endl; |
---|
[106] | 162 | } |
---|
| 163 | |
---|
| 164 | ////////////////////////////////// |
---|
[77] | 165 | tmpl(void)::transition() |
---|
[106] | 166 | ////////////////////////////////// |
---|
[77] | 167 | { |
---|
| 168 | // RESET |
---|
| 169 | if ( ! p_resetn.read() ) { |
---|
[98] | 170 | // Initializing seed for random numbers generation |
---|
[122] | 171 | #ifndef DETERMINISTIC |
---|
[98] | 172 | srand(time(NULL)); |
---|
[115] | 173 | #endif |
---|
[77] | 174 | |
---|
[98] | 175 | // Initializing FSMs |
---|
[123] | 176 | r_cmd_fsm = VCI_IDLE; |
---|
[77] | 177 | |
---|
[123] | 178 | r_bc_rsp_fsm = BC_RSP_IDLE; |
---|
| 179 | |
---|
[98] | 180 | // Initializing FIFOs |
---|
[78] | 181 | m_date_fifo.init(); |
---|
[77] | 182 | |
---|
[122] | 183 | // Initializing the stats |
---|
| 184 | m_latency1 = 0 ; |
---|
| 185 | m_latency2 = 0 ; |
---|
[77] | 186 | // Activity counters |
---|
| 187 | m_cpt_cycles = 0; |
---|
[81] | 188 | m_npackets = 0; |
---|
[122] | 189 | |
---|
| 190 | m_start_latency_bc = 0; |
---|
| 191 | m_latency_bc = 0; |
---|
| 192 | m_nb_bc = 0; |
---|
[123] | 193 | m_id_to_send = -1; |
---|
[77] | 194 | |
---|
[106] | 195 | r_broadcast_req = false; |
---|
| 196 | |
---|
[123] | 197 | r_broadcast_rsp = false; |
---|
| 198 | |
---|
| 199 | r_bc_nrsp = 0; |
---|
| 200 | |
---|
| 201 | for(int i = 0; i < tab_size; i++){ |
---|
| 202 | r_req_id[i][0] = 0; |
---|
| 203 | r_req_id[i][1] = 0; |
---|
[125] | 204 | std::cout << "bla bla" << std::endl; |
---|
[123] | 205 | } |
---|
| 206 | |
---|
[77] | 207 | return; |
---|
| 208 | } |
---|
| 209 | |
---|
[81] | 210 | bool date_fifo_put = false; |
---|
| 211 | bool date_fifo_get = false; |
---|
[77] | 212 | |
---|
[106] | 213 | |
---|
| 214 | |
---|
[123] | 215 | // FSM controling effective requests send |
---|
| 216 | switch ( r_cmd_fsm.read() ) { |
---|
[77] | 217 | ////////////////// |
---|
[78] | 218 | case VCI_IDLE: |
---|
[77] | 219 | { |
---|
[98] | 220 | if (m_date_fifo.rok()){ |
---|
[123] | 221 | if (r_broadcast_req.read() && !r_broadcast_rsp.read()){ |
---|
[111] | 222 | m_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ; |
---|
[123] | 223 | r_cmd_fsm = VCI_BC_SEND ; |
---|
[98] | 224 | } else { |
---|
[124] | 225 | m_id_to_send = -1; |
---|
[123] | 226 | for(int i = 0; i < tab_size; i++){ |
---|
[124] | 227 | if(r_req_id[i][0].read() == 0){ |
---|
[123] | 228 | m_id_to_send = i; |
---|
[125] | 229 | //r_req_id[i][0] = m_date_fifo.read(); |
---|
| 230 | //r_req_id[i][1] = m_cpt_cycles; |
---|
[123] | 231 | break; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | if(m_id_to_send == -1){ |
---|
| 235 | r_cmd_fsm = VCI_IDLE ; |
---|
| 236 | break; |
---|
| 237 | } else { |
---|
| 238 | r_cmd_fsm = VCI_SINGLE_SEND ; |
---|
| 239 | } |
---|
[122] | 240 | #ifdef DETERMINISTIC |
---|
[115] | 241 | 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)); |
---|
| 242 | #else |
---|
[111] | 243 | 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] | 244 | #endif |
---|
[98] | 245 | m_count = 0; |
---|
| 246 | } |
---|
| 247 | } |
---|
[77] | 248 | break; |
---|
| 249 | } |
---|
| 250 | ////////////////// |
---|
[78] | 251 | case VCI_SINGLE_SEND: |
---|
[77] | 252 | { |
---|
[98] | 253 | if (p_vci.cmdack.read()){ |
---|
| 254 | if (m_count == m_length-1) { |
---|
[124] | 255 | //r_req_id[m_id_to_send][0] = (uint64_t)(m_date_fifo.read()); |
---|
[125] | 256 | r_req_id[m_id_to_send][0] = m_date_fifo.read(); |
---|
| 257 | r_req_id[m_id_to_send][1] = m_cpt_cycles; |
---|
[124] | 258 | //std::cout << name () << " FIFO " << m_date_fifo.read() << std::endl; |
---|
[123] | 259 | date_fifo_get = true; |
---|
[125] | 260 | m_npackets++; |
---|
[123] | 261 | r_cmd_fsm = VCI_IDLE ; |
---|
[98] | 262 | } else { |
---|
[123] | 263 | r_cmd_fsm = VCI_SINGLE_SEND ; |
---|
[106] | 264 | m_count++; |
---|
[98] | 265 | } |
---|
| 266 | } |
---|
[77] | 267 | break; |
---|
| 268 | } |
---|
[123] | 269 | /////////////////// |
---|
| 270 | case VCI_BC_SEND: |
---|
[77] | 271 | { |
---|
[98] | 272 | if (p_vci.rspval.read()) { |
---|
[123] | 273 | r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ; |
---|
| 274 | m_start_latency_bc = m_cpt_cycles; |
---|
[124] | 275 | r_broadcast_rsp = true; |
---|
[98] | 276 | date_fifo_get = true; |
---|
[123] | 277 | r_bc_rsp_fsm = VCI_IDLE; |
---|
| 278 | break; |
---|
[81] | 279 | } |
---|
[77] | 280 | } |
---|
[123] | 281 | } // end switch vci_fsm |
---|
| 282 | |
---|
| 283 | switch(r_bc_rsp_fsm.read()){ |
---|
| 284 | /////////////////// |
---|
| 285 | case BC_RSP_IDLE: |
---|
[77] | 286 | { |
---|
[123] | 287 | if (p_vci.rspval.read() && r_broadcast_rsp.read()) { |
---|
| 288 | r_bc_rsp_fsm = BC_RSP_WAIT_RSP; |
---|
[111] | 289 | break; |
---|
| 290 | } |
---|
[77] | 291 | } |
---|
[123] | 292 | //////////////////// |
---|
| 293 | case BC_RSP_WAIT_RSP: |
---|
[77] | 294 | { |
---|
[123] | 295 | if (p_vci.rspval.read() && (p_vci.rpktid.read() == 1)){ |
---|
| 296 | if (r_bc_nrsp == 1) { |
---|
[98] | 297 | r_broadcast_req = false; |
---|
[123] | 298 | r_broadcast_rsp = false; |
---|
[106] | 299 | m_address_to_send = 0; |
---|
[122] | 300 | m_latency_bc = m_latency_bc + (m_cpt_cycles - m_start_latency_bc); |
---|
| 301 | m_nb_bc++; |
---|
[123] | 302 | r_bc_rsp_fsm = BC_RSP_IDLE ; |
---|
[98] | 303 | } else { |
---|
[123] | 304 | r_bc_nrsp = r_bc_nrsp.read() - 1;; |
---|
| 305 | r_bc_rsp_fsm = BC_RSP_WAIT_RSP ; |
---|
[98] | 306 | } |
---|
| 307 | } |
---|
[77] | 308 | break; |
---|
[123] | 309 | } |
---|
| 310 | } |
---|
[77] | 311 | |
---|
[123] | 312 | if(p_vci.rspval.read()){ |
---|
| 313 | if((int)(p_vci.pktid.read()) == 0){ |
---|
[124] | 314 | m_latency1 = m_latency1 + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][0].read()); |
---|
| 315 | m_latency2 = m_latency2 + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][1].read()); |
---|
[125] | 316 | //m_npackets++; |
---|
[124] | 317 | r_req_id[(int)(p_vci.rtrdid.read())][0] = 0; |
---|
| 318 | r_req_id[(int)(p_vci.rtrdid.read())][1] = 0; |
---|
| 319 | //std::cout << name() << " bla bla " << p_vci.rtrdid.read() << std::endl; |
---|
[123] | 320 | } |
---|
| 321 | } |
---|
[77] | 322 | |
---|
[106] | 323 | /////////////////// Filling fifo |
---|
[122] | 324 | if( ( (uint64_t)(m_rho*m_cpt_cycles) > (uint64_t)(m_length*m_npackets*1000)) ){ |
---|
[81] | 325 | if (m_date_fifo.wok()){ |
---|
| 326 | date_fifo_put = true ; |
---|
| 327 | } |
---|
[106] | 328 | if (m_bc_period){ |
---|
| 329 | if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){ |
---|
| 330 | r_broadcast_req = true; |
---|
| 331 | } |
---|
[81] | 332 | } |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | if (date_fifo_put){ |
---|
| 336 | if (date_fifo_get){ |
---|
| 337 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
[77] | 338 | } else { |
---|
[81] | 339 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
[77] | 340 | } |
---|
| 341 | } else { |
---|
[81] | 342 | if (date_fifo_get){ |
---|
| 343 | m_date_fifo.simple_get(); |
---|
[77] | 344 | } |
---|
| 345 | } |
---|
[98] | 346 | |
---|
[77] | 347 | m_cpt_cycles++; |
---|
| 348 | |
---|
[81] | 349 | return; |
---|
| 350 | |
---|
[77] | 351 | } // end transition() |
---|
| 352 | |
---|
| 353 | ///////////////////////////// |
---|
| 354 | tmpl(void)::genMoore() |
---|
| 355 | ///////////////////////////// |
---|
| 356 | { |
---|
| 357 | //////////////////////////////////////////////////////////// |
---|
[98] | 358 | // Command signals on the p_vci port |
---|
[77] | 359 | //////////////////////////////////////////////////////////// |
---|
[98] | 360 | p_vci.cmd = vci_param::CMD_WRITE; |
---|
[81] | 361 | p_vci.be = 0xF; |
---|
[123] | 362 | p_vci.srcid = m_srcid; |
---|
[81] | 363 | p_vci.pktid = 0; |
---|
| 364 | p_vci.cons = false; |
---|
| 365 | p_vci.wrap = false; |
---|
| 366 | p_vci.contig = true; |
---|
| 367 | p_vci.clen = 0; |
---|
| 368 | p_vci.cfixed = false; |
---|
[123] | 369 | p_vci.rspack = true; |
---|
[77] | 370 | |
---|
| 371 | |
---|
[123] | 372 | switch ( r_cmd_fsm.read() ) { |
---|
[77] | 373 | |
---|
[78] | 374 | ////////////////// |
---|
| 375 | case VCI_IDLE: |
---|
| 376 | { |
---|
[81] | 377 | p_vci.cmdval = false; |
---|
| 378 | p_vci.address = 0; |
---|
| 379 | p_vci.plen = 0; |
---|
| 380 | p_vci.wdata = 0; |
---|
| 381 | p_vci.trdid = 0; |
---|
| 382 | p_vci.eop = false; |
---|
[78] | 383 | break; |
---|
| 384 | } |
---|
| 385 | ////////////////// |
---|
| 386 | case VCI_SINGLE_SEND: |
---|
| 387 | { |
---|
[98] | 388 | p_vci.cmdval = true; |
---|
[106] | 389 | p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); |
---|
[98] | 390 | p_vci.plen = m_length*4; |
---|
| 391 | p_vci.wdata = 0; |
---|
[123] | 392 | p_vci.trdid = m_id_to_send; |
---|
[98] | 393 | if (m_count == m_length - 1 ) { |
---|
| 394 | p_vci.eop = true; |
---|
| 395 | } else { |
---|
| 396 | p_vci.eop = false; |
---|
| 397 | } |
---|
[78] | 398 | break; |
---|
| 399 | } |
---|
| 400 | /////////////////// |
---|
| 401 | case VCI_BC_SEND: |
---|
| 402 | { |
---|
[98] | 403 | p_vci.cmdval = true; |
---|
[106] | 404 | p_vci.address = (addr_t) m_address_to_send; |
---|
[98] | 405 | p_vci.plen = 4; |
---|
| 406 | p_vci.wdata = 0; |
---|
[123] | 407 | p_vci.pktid = 1; |
---|
[98] | 408 | p_vci.trdid = 0; |
---|
| 409 | p_vci.eop = true; |
---|
[78] | 410 | break; |
---|
| 411 | } |
---|
[123] | 412 | } // end switch vci_cmd_fsm |
---|
[77] | 413 | |
---|
| 414 | } // end genMoore() |
---|
| 415 | |
---|
| 416 | }} // end name space |
---|