[854] | 1 | /* -*- c++ -*- |
---|
| 2 | * |
---|
| 3 | * File : dspin_router.cpp |
---|
| 4 | * Copyright (c) UPMC, Lip6 |
---|
| 5 | * Authors : Alain Greiner, Abbas Sheibanyrad, Ivan Miro, Zhen Zhang |
---|
| 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 | */ |
---|
| 28 | |
---|
| 29 | /////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // Implementation Note : |
---|
| 31 | // The xfirst_route(), broadcast_route() and is_broadcast() functions |
---|
| 32 | // defined below are used to decode the DSPIN first flit format: |
---|
| 33 | // - In case of a non-broadcast packet : |
---|
| 34 | // | X | Y |---------------------------------------|BC | |
---|
| 35 | // | x_width | y_width | flit_width - (x_width + y_width + 2) | 0 | |
---|
| 36 | // |
---|
| 37 | // - In case of a broacast |
---|
[997] | 38 | // | XMIN | XMAX | YMIN | YMAX |----------------|SP|BC | |
---|
| 39 | // | 5 | 5 | 5 | 5 | flit_width - 21| 1| 1 | |
---|
[854] | 40 | /////////////////////////////////////////////////////////////////////////// |
---|
| 41 | |
---|
| 42 | #include "../include/dspin_router.h" |
---|
[886] | 43 | #include "dspin_router_config.h" |
---|
[854] | 44 | |
---|
| 45 | namespace soclib { namespace caba { |
---|
| 46 | |
---|
| 47 | using namespace soclib::common; |
---|
| 48 | using namespace soclib::caba; |
---|
| 49 | |
---|
| 50 | #define tmpl(x) template<int flit_width> x DspinRouter<flit_width> |
---|
| 51 | |
---|
| 52 | //////////////////////////////////////////////// |
---|
| 53 | // constructor |
---|
| 54 | //////////////////////////////////////////////// |
---|
| 55 | tmpl(/**/)::DspinRouter( sc_module_name name, |
---|
| 56 | const size_t x, |
---|
| 57 | const size_t y, |
---|
| 58 | const size_t x_width, |
---|
| 59 | const size_t y_width, |
---|
| 60 | const size_t in_fifo_depth, |
---|
| 61 | const size_t out_fifo_depth, |
---|
[994] | 62 | const bool broadcast_supported, |
---|
| 63 | const bool configuration_supported) |
---|
[854] | 64 | : soclib::caba::BaseModule(name), |
---|
| 65 | |
---|
| 66 | p_clk( "p_clk" ), |
---|
| 67 | p_resetn( "p_resetn" ), |
---|
| 68 | p_in( alloc_elems<DspinInput<flit_width> >("p_in", 5) ), |
---|
| 69 | p_out( alloc_elems<DspinOutput<flit_width> >("p_out", 5) ), |
---|
[994] | 70 | p_recovery_cfg(NULL), |
---|
[854] | 71 | |
---|
| 72 | r_alloc_out( alloc_elems<sc_signal<bool> >("r_alloc_out", 5)), |
---|
| 73 | r_index_out( soclib::common::alloc_elems<sc_signal<size_t> >("r_index_out", 5)), |
---|
| 74 | r_fsm_in( alloc_elems<sc_signal<int> >("r_fsm_in", 5)), |
---|
| 75 | r_index_in( alloc_elems<sc_signal<size_t> >("r_index_in", 5)), |
---|
| 76 | |
---|
| 77 | m_local_x( x ), |
---|
| 78 | m_local_y( y ), |
---|
| 79 | m_x_width( x_width ), |
---|
| 80 | m_x_shift( flit_width - x_width ), |
---|
| 81 | m_x_mask( (0x1 << x_width) - 1 ), |
---|
| 82 | m_y_width( y_width ), |
---|
| 83 | m_y_shift( flit_width - x_width - y_width ), |
---|
| 84 | m_y_mask( (0x1 << y_width) - 1 ), |
---|
| 85 | m_broadcast_supported( broadcast_supported ), |
---|
| 86 | m_disable_mask( 0 ) |
---|
| 87 | { |
---|
| 88 | std::cout << " - Building DspinRouter : " << name << std::endl; |
---|
| 89 | |
---|
| 90 | SC_METHOD (transition); |
---|
| 91 | dont_initialize(); |
---|
| 92 | sensitive << p_clk.pos(); |
---|
| 93 | |
---|
| 94 | SC_METHOD (genMoore); |
---|
| 95 | dont_initialize(); |
---|
| 96 | sensitive << p_clk.neg(); |
---|
| 97 | |
---|
| 98 | r_fifo_in = (GenericFifo<internal_flit_t>*) |
---|
| 99 | malloc(sizeof(GenericFifo<internal_flit_t>) * 5); |
---|
| 100 | |
---|
| 101 | r_fifo_out = (GenericFifo<internal_flit_t>*) |
---|
| 102 | malloc(sizeof(GenericFifo<internal_flit_t>) * 5); |
---|
| 103 | |
---|
| 104 | r_buf_in = (internal_flit_t*) |
---|
| 105 | malloc(sizeof(internal_flit_t) * 5); |
---|
| 106 | |
---|
| 107 | for( size_t i = 0 ; i < 5 ; i++ ) |
---|
| 108 | { |
---|
| 109 | std::ostringstream stri; |
---|
| 110 | stri << "r_in_fifo_" << i; |
---|
| 111 | new(&r_fifo_in[i]) |
---|
| 112 | GenericFifo<internal_flit_t >(stri.str(), in_fifo_depth); |
---|
| 113 | |
---|
| 114 | std::ostringstream stro; |
---|
| 115 | stro << "r_out_fifo_" << i; |
---|
| 116 | new(&r_fifo_out[i]) |
---|
| 117 | GenericFifo<internal_flit_t >(stro.str(), out_fifo_depth); |
---|
| 118 | } |
---|
[877] | 119 | |
---|
[994] | 120 | if (configuration_supported) { |
---|
| 121 | p_recovery_cfg = new sc_core::sc_in<uint32_t> ("p_recovery_cfg"); |
---|
| 122 | } |
---|
[854] | 123 | } // end constructor |
---|
| 124 | |
---|
| 125 | /////////////////////////////////////////////////// |
---|
[877] | 126 | tmpl(/**/)::~DspinRouter() |
---|
| 127 | { |
---|
[994] | 128 | if ( is_reconfigurable() ) delete p_recovery_cfg; |
---|
[877] | 129 | } |
---|
| 130 | |
---|
| 131 | /////////////////////////////////////////////////// |
---|
[994] | 132 | tmpl(int)::blackhole_position() |
---|
[854] | 133 | { |
---|
[994] | 134 | if ( is_reconfigurable() ) { |
---|
| 135 | return p_recovery_cfg->read() & 0xF; |
---|
| 136 | } |
---|
| 137 | return BH_NONE; |
---|
[854] | 138 | } |
---|
| 139 | |
---|
[873] | 140 | /////////////////////////////////////////////////// |
---|
[994] | 141 | tmpl(void)::bind_recovery_port(sc_signal<uint32_t> &s) |
---|
[931] | 142 | { |
---|
[994] | 143 | if (!is_reconfigurable()) { |
---|
| 144 | std::cerr << "Error in " << name() |
---|
| 145 | << ": router configuration not supported." << std::endl |
---|
| 146 | << "Enable it during router instantiation." << std::endl; |
---|
| 147 | exit(1); |
---|
[931] | 148 | } |
---|
| 149 | (*p_recovery_cfg)(s); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /////////////////////////////////////////////////// |
---|
[994] | 153 | tmpl(int)::xfirst_route( size_t xdest, size_t ydest ) |
---|
| 154 | { |
---|
| 155 | return (xdest < m_local_x ? REQ_WEST : |
---|
| 156 | (xdest > m_local_x ? REQ_EAST : |
---|
| 157 | (ydest < m_local_y ? REQ_SOUTH : |
---|
| 158 | (ydest > m_local_y ? REQ_NORTH : REQ_LOCAL)))); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /////////////////////////////////////////////////// |
---|
[947] | 162 | tmpl(bool)::is_destination_blackhole( size_t xdest, size_t ydest, int bhpos ) |
---|
[931] | 163 | { |
---|
| 164 | size_t xhole, yhole; |
---|
[994] | 165 | switch (bhpos) { |
---|
| 166 | case BH_N: |
---|
| 167 | xhole = m_local_x; |
---|
| 168 | yhole = m_local_y - 1; |
---|
| 169 | break; |
---|
| 170 | case BH_NW: |
---|
| 171 | xhole = m_local_x + 1; |
---|
| 172 | yhole = m_local_y - 1; |
---|
| 173 | break; |
---|
| 174 | case BH_W: |
---|
| 175 | xhole = m_local_x + 1; |
---|
| 176 | yhole = m_local_y; |
---|
| 177 | break; |
---|
| 178 | case BH_SW: |
---|
| 179 | xhole = m_local_x + 1; |
---|
| 180 | yhole = m_local_y + 1; |
---|
| 181 | break; |
---|
| 182 | case BH_S: |
---|
| 183 | xhole = m_local_x; |
---|
| 184 | yhole = m_local_y + 1; |
---|
| 185 | break; |
---|
| 186 | case BH_SE: |
---|
| 187 | xhole = m_local_x - 1; |
---|
| 188 | yhole = m_local_y + 1; |
---|
| 189 | break; |
---|
| 190 | case BH_E: |
---|
| 191 | xhole = m_local_x - 1; |
---|
| 192 | yhole = m_local_y; |
---|
| 193 | break; |
---|
| 194 | case BH_NE: |
---|
| 195 | xhole = m_local_x - 1; |
---|
| 196 | yhole = m_local_y - 1; |
---|
| 197 | break; |
---|
| 198 | default: |
---|
| 199 | return false; |
---|
[931] | 200 | } |
---|
| 201 | |
---|
| 202 | return ((xdest == xhole) && (ydest == yhole)); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /////////////////////////////////////////////////// |
---|
[873] | 206 | tmpl(int)::recovery_route( size_t xdest, size_t ydest ) |
---|
| 207 | { |
---|
[947] | 208 | int bhpos = blackhole_position(); |
---|
[931] | 209 | |
---|
[873] | 210 | if ( xdest > m_local_x ) { |
---|
| 211 | if ( (bhpos == BH_NE) || (bhpos == BH_E) || (bhpos == BH_SE) || |
---|
| 212 | (bhpos == BH_S) ) { |
---|
| 213 | return REQ_EAST; |
---|
| 214 | } |
---|
| 215 | else if ( bhpos == BH_N ) { |
---|
| 216 | if ( (m_local_y == 1) || (m_local_x == 0) || (ydest >= m_local_y) || |
---|
| 217 | (xdest > (m_local_x + 1)) ) { |
---|
| 218 | return REQ_EAST; |
---|
| 219 | } |
---|
| 220 | else { |
---|
| 221 | return REQ_WEST; |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | else if ( bhpos == BH_NW ) { |
---|
| 225 | if ( (m_local_y == 1) || (ydest >= m_local_y) || |
---|
| 226 | (xdest > (m_local_x + 2)) ) { |
---|
| 227 | return REQ_EAST; |
---|
| 228 | } |
---|
| 229 | else { |
---|
| 230 | return REQ_SOUTH; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | else if ( bhpos == BH_W ) { |
---|
| 234 | if ( (m_local_y == 0) || (ydest > m_local_y)) { |
---|
| 235 | return REQ_NORTH; |
---|
| 236 | } |
---|
| 237 | else { |
---|
| 238 | return REQ_SOUTH; |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | else if ( bhpos == BH_SW ) { |
---|
| 242 | if ( (ydest <= m_local_y) || (xdest > (m_local_x + 1)) ) { |
---|
| 243 | return REQ_EAST; |
---|
| 244 | } |
---|
| 245 | else { |
---|
| 246 | return REQ_NORTH; |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | std::cout << "error: unexpected condition in function " |
---|
| 250 | << __FILE__ << ":" << __func__ << " +" << __LINE__ |
---|
| 251 | << std::endl; |
---|
| 252 | exit(1); |
---|
| 253 | } // end if (xdest > m_local_x) |
---|
| 254 | else if ( xdest < m_local_x ) { |
---|
| 255 | if ( (bhpos == BH_N) || (bhpos == BH_NW) || (bhpos == BH_W) || |
---|
| 256 | (bhpos == BH_SW) || (bhpos == BH_S) ) { |
---|
| 257 | return REQ_WEST; |
---|
| 258 | } |
---|
| 259 | else if ( bhpos == BH_NE ) { |
---|
| 260 | if ( (xdest < (m_local_x - 1)) || (ydest >= m_local_y) ) { |
---|
| 261 | return REQ_WEST; |
---|
| 262 | } |
---|
| 263 | else { |
---|
| 264 | return REQ_SOUTH; |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | else if ( bhpos == BH_SE ) { |
---|
| 268 | if ( (m_local_x == 1) && (ydest > (m_local_y + 1)) ) { |
---|
| 269 | return REQ_NORTH; |
---|
| 270 | } |
---|
| 271 | else { |
---|
| 272 | return REQ_WEST; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | else if ( bhpos == BH_E ) { |
---|
| 276 | if ( (m_local_y == 0) || |
---|
| 277 | ((m_local_x == 1) && (ydest > m_local_y)) ) { |
---|
| 278 | return REQ_NORTH; |
---|
| 279 | } |
---|
| 280 | else { |
---|
| 281 | return REQ_SOUTH; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | std::cout << "error: unexpected condition in function " |
---|
| 285 | << __FILE__ << ":" << __func__ << " +" << __LINE__ |
---|
| 286 | << std::endl; |
---|
| 287 | exit(1); |
---|
| 288 | } // end if (xdest < m_local_x) |
---|
| 289 | else if ( ydest > m_local_y ) { |
---|
| 290 | if ( bhpos != BH_S ) { |
---|
| 291 | return REQ_NORTH; |
---|
| 292 | } |
---|
| 293 | else if ( m_local_x != 0 ) { |
---|
| 294 | return REQ_WEST; |
---|
| 295 | } |
---|
| 296 | else { |
---|
| 297 | return REQ_EAST; |
---|
| 298 | } |
---|
| 299 | } // end if (ydest > m_local_y) |
---|
| 300 | else if ( ydest < m_local_y ) { |
---|
| 301 | if ( bhpos != BH_N ) { |
---|
| 302 | return REQ_SOUTH; |
---|
| 303 | } |
---|
| 304 | else if ( m_local_x != 0) { |
---|
| 305 | return REQ_WEST; |
---|
| 306 | } |
---|
| 307 | else { |
---|
| 308 | return REQ_EAST; |
---|
| 309 | } |
---|
| 310 | } // end if (ydest < m_local_y) |
---|
| 311 | return REQ_LOCAL; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /////////////////////////////////////////////////// |
---|
| 315 | tmpl(int)::route( sc_uint<flit_width> data ) |
---|
| 316 | { |
---|
| 317 | size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask; |
---|
| 318 | size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask; |
---|
[994] | 319 | if ( blackhole_position() != BH_NONE ) |
---|
[877] | 320 | { |
---|
[994] | 321 | // reroute the request if its destination is the blackhole (this |
---|
| 322 | // is to implement the segment recovery mechanism) |
---|
| 323 | if ( is_destination_blackhole(xdest, ydest, blackhole_position()) ) |
---|
[877] | 324 | { |
---|
[994] | 325 | int dir = migration_route(); |
---|
[947] | 326 | |
---|
| 327 | #if SOCLIB_MODULE_DEBUG |
---|
[994] | 328 | std::cout << "<" << name() << "> migration: " |
---|
| 329 | << "route request to DIR = " << dir << std::endl; |
---|
[947] | 330 | #endif |
---|
[994] | 331 | return dir; |
---|
| 332 | } |
---|
[947] | 333 | |
---|
[994] | 334 | if (is_network_recovery_enable()) |
---|
| 335 | { |
---|
| 336 | int dir = recovery_route(xdest, ydest); |
---|
[947] | 337 | |
---|
| 338 | #if SOCLIB_MODULE_DEBUG |
---|
[994] | 339 | std::cout << "<" << name() << "> network recovery: " |
---|
| 340 | << "route request to DIR = " << dir << std::endl; |
---|
[947] | 341 | #endif |
---|
[994] | 342 | return dir; |
---|
[877] | 343 | } |
---|
[873] | 344 | } |
---|
[877] | 345 | return xfirst_route(xdest, ydest); |
---|
[873] | 346 | } |
---|
| 347 | |
---|
[994] | 348 | /////////////////////////////////////////////////// |
---|
[854] | 349 | tmpl(int)::broadcast_route(int step, int source, sc_uint<flit_width> data) |
---|
| 350 | { |
---|
[994] | 351 | const size_t lx = m_local_x; |
---|
| 352 | const size_t ly = m_local_y; |
---|
| 353 | const size_t xmin = (data >> (flit_width - 5 )) & 0x1F; |
---|
| 354 | const size_t xmax = (data >> (flit_width - 10)) & 0x1F; |
---|
| 355 | const size_t ymin = (data >> (flit_width - 15)) & 0x1F; |
---|
| 356 | const size_t ymax = (data >> (flit_width - 20)) & 0x1F; |
---|
| 357 | const int bh = blackhole_position(); |
---|
[997] | 358 | |
---|
[994] | 359 | int sel = REQ_NOP; |
---|
[997] | 360 | bool special = ((data & 0x2) != 0); |
---|
[854] | 361 | |
---|
| 362 | switch(source) { |
---|
| 363 | case REQ_LOCAL : |
---|
[994] | 364 | if ( step == 1 ) sel = REQ_NORTH; |
---|
| 365 | else if ( step == 2 ) sel = REQ_SOUTH; |
---|
| 366 | else if ( step == 3 ) { |
---|
| 367 | if ( (bh == BH_N) && (lx != 0) && (ly != 1) ) { |
---|
| 368 | sel = REQ_NOP; |
---|
| 369 | break; |
---|
| 370 | } |
---|
| 371 | sel = REQ_EAST; |
---|
| 372 | } |
---|
| 373 | else if ( step == 4 ) { |
---|
| 374 | if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) { |
---|
| 375 | sel = REQ_NOP; |
---|
| 376 | break; |
---|
| 377 | } |
---|
| 378 | sel = REQ_WEST; |
---|
| 379 | } |
---|
[854] | 380 | break; |
---|
| 381 | case REQ_NORTH : |
---|
[994] | 382 | if ( step == 1 ) sel = REQ_SOUTH; |
---|
| 383 | else if ( step == 2 ) sel = REQ_LOCAL; |
---|
| 384 | else if ( step == 3 ) { |
---|
| 385 | if ( bh == BH_SW ) { |
---|
| 386 | sel = REQ_EAST; |
---|
| 387 | break; |
---|
| 388 | } |
---|
| 389 | sel = REQ_NOP; |
---|
| 390 | } |
---|
| 391 | else if ( step == 4 ) { |
---|
[997] | 392 | if ( (bh == BH_SE) && (!special || (lx == 1))) { |
---|
[994] | 393 | sel = REQ_WEST; |
---|
| 394 | break; |
---|
| 395 | } |
---|
| 396 | sel = REQ_NOP; |
---|
| 397 | } |
---|
[854] | 398 | break; |
---|
| 399 | case REQ_SOUTH : |
---|
[994] | 400 | if ( step == 1 ) sel = REQ_NORTH; |
---|
| 401 | else if ( step == 2 ) sel = REQ_LOCAL; |
---|
| 402 | else if ( step == 3 ) { |
---|
| 403 | if ( bh == BH_NW ) { |
---|
| 404 | sel = REQ_EAST; |
---|
| 405 | break; |
---|
| 406 | } |
---|
| 407 | if ( (bh == BH_NE) && ((lx == 1) || (ly == 1)) ) { |
---|
| 408 | sel = REQ_WEST; |
---|
| 409 | break; |
---|
| 410 | } |
---|
| 411 | sel = REQ_NOP; |
---|
| 412 | } |
---|
| 413 | else if ( step == 4 ) sel = REQ_NOP; |
---|
[854] | 414 | break; |
---|
| 415 | case REQ_EAST : |
---|
[994] | 416 | if ( step == 1 ) { |
---|
| 417 | if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) { |
---|
| 418 | sel = REQ_NOP; |
---|
| 419 | break; |
---|
| 420 | } |
---|
| 421 | sel = REQ_WEST; |
---|
| 422 | } |
---|
| 423 | else if ( step == 2 ) sel = REQ_NORTH; |
---|
| 424 | else if ( step == 3 ) sel = REQ_SOUTH; |
---|
| 425 | else if ( step == 4 ) sel = REQ_LOCAL; |
---|
[854] | 426 | break; |
---|
| 427 | case REQ_WEST : |
---|
[994] | 428 | if ( step == 1 ) { |
---|
| 429 | if ( (bh == BH_N) && (ly != 1) ) { |
---|
| 430 | sel = REQ_NOP; |
---|
| 431 | break; |
---|
| 432 | } |
---|
[997] | 433 | if ( (bh == BH_S) && special ) { |
---|
[994] | 434 | sel = REQ_NOP; |
---|
| 435 | break; |
---|
| 436 | } |
---|
| 437 | sel = REQ_EAST; |
---|
| 438 | } |
---|
| 439 | else if ( step == 2 ) sel = REQ_NORTH; |
---|
| 440 | else if ( step == 3 ) sel = REQ_SOUTH; |
---|
| 441 | else if ( step == 4 ) sel = REQ_LOCAL; |
---|
[854] | 442 | break; |
---|
| 443 | } |
---|
| 444 | |
---|
[994] | 445 | if ( (sel == REQ_NORTH) && !(ly < ymax) ) sel = REQ_NOP; |
---|
| 446 | else if ( (sel == REQ_SOUTH) && !(ly > ymin) ) sel = REQ_NOP; |
---|
| 447 | else if ( (sel == REQ_EAST ) && !(lx < xmax) ) sel = REQ_NOP; |
---|
| 448 | else if ( (sel == REQ_WEST ) && !(lx > xmin) ) sel = REQ_NOP; |
---|
| 449 | |
---|
| 450 | #if 0 |
---|
| 451 | /* This code can be used if we want to inhibit requests to the |
---|
| 452 | * blackhole. However, it is not strictly necessary because the |
---|
| 453 | * blackhole will consume the request and will do nothing with it */ |
---|
| 454 | |
---|
| 455 | if ( (sel == REQ_NORTH) && (bh == BH_S) ) sel = REQ_NOP; |
---|
| 456 | else if ( (sel == REQ_SOUTH) && (bh == BH_N) ) sel = REQ_NOP; |
---|
| 457 | else if ( (sel == REQ_EAST ) && (bh == BH_W) ) sel = REQ_NOP; |
---|
| 458 | else if ( (sel == REQ_WEST ) && (bh == BH_E) ) sel = REQ_NOP; |
---|
| 459 | #endif |
---|
| 460 | |
---|
[854] | 461 | return sel; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | ///////////////////////////////////////////////////////// |
---|
[994] | 465 | tmpl(bool)::is_broadcast(sc_uint<flit_width> data) |
---|
[854] | 466 | { |
---|
| 467 | return ( (data & 0x1) != 0); |
---|
| 468 | } |
---|
| 469 | |
---|
[994] | 470 | ///////////////////////////////////////////////////////// |
---|
| 471 | tmpl(sc_uint<flit_width>)::compute_broadcast_header(int source) |
---|
| 472 | { |
---|
| 473 | const int bh = blackhole_position(); |
---|
| 474 | sc_uint<flit_width> header = r_fifo_in[source].read().data; |
---|
[997] | 475 | sc_uint<flit_width> special = 0x2; |
---|
[994] | 476 | switch (source) { |
---|
[997] | 477 | case REQ_NORTH: |
---|
| 478 | if ( (bh == BH_NW) || (bh == BH_NE) ) { |
---|
| 479 | header |= special; |
---|
[994] | 480 | } |
---|
| 481 | break; |
---|
| 482 | |
---|
[997] | 483 | /* Make sure that broadcast transactions do not enter the DSPIN |
---|
| 484 | * network with the special bit set. This can arrive if an initiator |
---|
| 485 | * or a local interconnect uses the broadcast header reserved bits |
---|
| 486 | * internally and don't reset them */ |
---|
| 487 | case REQ_LOCAL: |
---|
| 488 | header &= ~special; |
---|
[994] | 489 | break; |
---|
| 490 | } |
---|
| 491 | return header; |
---|
| 492 | } |
---|
| 493 | |
---|
[854] | 494 | ///////////////////////// |
---|
| 495 | tmpl(void)::print_trace() |
---|
| 496 | { |
---|
| 497 | const char* port_name[] = |
---|
| 498 | { |
---|
| 499 | "N", |
---|
| 500 | "S", |
---|
| 501 | "E", |
---|
| 502 | "W", |
---|
| 503 | "L" |
---|
| 504 | }; |
---|
| 505 | |
---|
| 506 | const char* infsm_str[] = |
---|
| 507 | { |
---|
| 508 | "IDLE", |
---|
| 509 | "REQ", |
---|
| 510 | "ALLOC", |
---|
| 511 | "REQ_FIRST", |
---|
| 512 | "ALLOC_FIRST", |
---|
| 513 | "REQ_SECOND", |
---|
| 514 | "ALLOC_SECOND", |
---|
| 515 | "REQ_THIRD", |
---|
| 516 | "ALLOC_THIRD", |
---|
| 517 | "REQ_FOURTH", |
---|
| 518 | "ALLOC_FOURTH" |
---|
| 519 | }; |
---|
| 520 | |
---|
[994] | 521 | const char* bh_str[] = |
---|
| 522 | { |
---|
| 523 | "BH_NONE", |
---|
| 524 | "BH_N", |
---|
| 525 | "BH_NE", |
---|
| 526 | "BH_E", |
---|
| 527 | "BH_SE", |
---|
| 528 | "BH_S", |
---|
| 529 | "BH_SW", |
---|
| 530 | "BH_W", |
---|
| 531 | "BH_NW" |
---|
| 532 | }; |
---|
| 533 | |
---|
[854] | 534 | std::cout << "DSPIN_ROUTER " << name(); |
---|
[994] | 535 | std::cout << " / bh = " << bh_str[blackhole_position()]; |
---|
[854] | 536 | |
---|
| 537 | for( size_t i = 0 ; i < 5 ; i++) // loop on input ports |
---|
| 538 | { |
---|
| 539 | std::cout << " / infsm[" << port_name[i] << "] " |
---|
| 540 | << infsm_str[r_fsm_in[i].read()]; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | for ( size_t out=0 ; out<5 ; out++) // loop on output ports |
---|
| 544 | { |
---|
| 545 | if ( r_alloc_out[out].read() ) |
---|
| 546 | { |
---|
| 547 | int in = r_index_out[out]; |
---|
| 548 | std::cout << " / " << port_name[in] << " -> " << port_name[out] ; |
---|
| 549 | } |
---|
| 550 | } |
---|
| 551 | std::cout << std::endl; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | //////////////////////// |
---|
| 555 | tmpl(void)::transition() |
---|
| 556 | { |
---|
| 557 | // Long wires connecting input and output ports |
---|
| 558 | size_t req_in[5]; // input ports -> output ports |
---|
| 559 | size_t get_out[5]; // output ports -> input ports |
---|
| 560 | bool put_in[5]; // input ports -> output ports |
---|
| 561 | internal_flit_t data_in[5]; // input ports -> output ports |
---|
| 562 | |
---|
| 563 | // control signals for the input fifos |
---|
| 564 | bool fifo_in_write[5]; |
---|
| 565 | bool fifo_in_read[5]; |
---|
| 566 | internal_flit_t fifo_in_wdata[5]; |
---|
| 567 | |
---|
| 568 | // control signals for the output fifos |
---|
| 569 | bool fifo_out_write[5]; |
---|
| 570 | bool fifo_out_read[5]; |
---|
| 571 | internal_flit_t fifo_out_wdata[5]; |
---|
| 572 | |
---|
| 573 | // Reset |
---|
| 574 | if ( p_resetn == false ) |
---|
| 575 | { |
---|
| 576 | for(size_t i = 0 ; i < 5 ; i++) |
---|
| 577 | { |
---|
| 578 | r_alloc_out[i] = false; |
---|
| 579 | r_index_out[i] = 0; |
---|
| 580 | r_index_in[i] = 0; |
---|
| 581 | r_fsm_in[i] = INFSM_IDLE; |
---|
| 582 | r_fifo_in[i].init(); |
---|
| 583 | r_fifo_out[i].init(); |
---|
| 584 | } |
---|
| 585 | return; |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | // fifos signals default values |
---|
| 589 | for(size_t i = 0 ; i < 5 ; i++) |
---|
| 590 | { |
---|
| 591 | fifo_in_read[i] = false; |
---|
| 592 | |
---|
| 593 | // do not write into the FIFO of disabled interfaces |
---|
| 594 | fifo_in_write[i] = p_in[i].write.read() && |
---|
[1006] | 595 | (((m_disable_mask >> i) & 1) == 0); |
---|
[854] | 596 | |
---|
| 597 | fifo_in_wdata[i].data = p_in[i].data.read(); |
---|
| 598 | fifo_in_wdata[i].eop = p_in[i].eop.read(); |
---|
| 599 | |
---|
[1006] | 600 | fifo_out_read[i] = p_out[i].read.read() || |
---|
| 601 | (((m_disable_mask >> i) & 1) == 1); |
---|
[854] | 602 | fifo_out_write[i] = false; |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | // loop on the output ports: |
---|
| 606 | // compute get_out[j] depending on the output port state |
---|
| 607 | // and combining fifo_out[j].wok and r_alloc_out[j] |
---|
| 608 | for ( size_t j = 0 ; j < 5 ; j++ ) |
---|
| 609 | { |
---|
| 610 | if( r_alloc_out[j].read() and (r_fifo_out[j].wok()) ) |
---|
| 611 | { |
---|
| 612 | get_out[j] = r_index_out[j].read(); |
---|
| 613 | } |
---|
| 614 | else |
---|
| 615 | { |
---|
| 616 | get_out[j] = 0xFFFFFFFF; |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | // loop on the input ports : |
---|
| 621 | // The port state is defined by r_fsm_in[i], r_index_in[i] & r_buf_in[i] |
---|
| 622 | // The req_in[i] computation implements the X-FIRST algorithm. |
---|
| 623 | // data_in[i], put_in[i] and req_in[i] depend on the input port state. |
---|
| 624 | // The fifo_in_read[i] is computed further... |
---|
| 625 | |
---|
| 626 | for ( size_t i = 0 ; i < 5 ; i++ ) |
---|
| 627 | { |
---|
| 628 | switch ( r_fsm_in[i].read() ) |
---|
| 629 | { |
---|
| 630 | case INFSM_IDLE: // no output port allocated |
---|
| 631 | { |
---|
| 632 | put_in[i] = false; |
---|
| 633 | |
---|
| 634 | if ( r_fifo_in[i].rok() ) // packet available in input fifo |
---|
| 635 | { |
---|
| 636 | if ( is_broadcast( r_fifo_in[i].read().data ) and |
---|
| 637 | m_broadcast_supported ) // broadcast |
---|
| 638 | { |
---|
[994] | 639 | if ( r_fifo_in[i].read().eop ) |
---|
| 640 | { |
---|
| 641 | std::cout << "ERROR in DSPIN_ROUTER " << name() |
---|
| 642 | << " : broadcast packet must be 2 flits" << std::endl; |
---|
| 643 | exit(1); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | internal_flit_t header; |
---|
| 647 | header.eop = false; |
---|
| 648 | header.data = compute_broadcast_header(i); |
---|
| 649 | |
---|
[854] | 650 | fifo_in_read[i] = true; |
---|
[994] | 651 | req_in[i] = broadcast_route(1, i, header.data); |
---|
| 652 | r_buf_in[i] = header; |
---|
[854] | 653 | r_index_in[i] = req_in[i]; |
---|
| 654 | if( req_in[i] == REQ_NOP ) r_fsm_in[i] = INFSM_REQ_SECOND; |
---|
| 655 | else r_fsm_in[i] = INFSM_REQ_FIRST; |
---|
| 656 | } |
---|
| 657 | else // unicast |
---|
| 658 | { |
---|
[873] | 659 | req_in[i] = route(r_fifo_in[i].read().data); |
---|
[854] | 660 | r_index_in[i] = req_in[i]; |
---|
| 661 | r_fsm_in[i] = INFSM_REQ; |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | req_in[i] = REQ_NOP; |
---|
| 667 | } |
---|
| 668 | break; |
---|
| 669 | } |
---|
| 670 | case INFSM_REQ: // not a broadcast / waiting output port allocation |
---|
| 671 | { |
---|
| 672 | data_in[i] = r_fifo_in[i].read(); |
---|
| 673 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 674 | req_in[i] = r_index_in[i]; |
---|
| 675 | fifo_in_read[i] = (get_out[r_index_in[i].read()] == i); |
---|
| 676 | if ( get_out[r_index_in[i].read()] == i ) // first flit transfered |
---|
| 677 | { |
---|
| 678 | if ( r_fifo_in[i].read().eop ) r_fsm_in[i] = INFSM_IDLE; |
---|
| 679 | else r_fsm_in[i] = INFSM_ALLOC; |
---|
| 680 | } |
---|
| 681 | break; |
---|
| 682 | } |
---|
| 683 | case INFSM_ALLOC: // not a broadcast / output port allocated |
---|
| 684 | { |
---|
| 685 | data_in[i] = r_fifo_in[i].read(); |
---|
| 686 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 687 | req_in[i] = REQ_NOP; // no request |
---|
| 688 | fifo_in_read[i] = (get_out[r_index_in[i].read()] == i); |
---|
| 689 | if ( r_fifo_in[i].read().eop and |
---|
| 690 | r_fifo_in[i].rok() and |
---|
| 691 | (get_out[r_index_in[i].read()] == i) ) // last flit transfered |
---|
| 692 | { |
---|
| 693 | r_fsm_in[i] = INFSM_IDLE; |
---|
| 694 | } |
---|
| 695 | break; |
---|
| 696 | } |
---|
| 697 | case INFSM_REQ_FIRST: // broacast / waiting first output port allocation |
---|
| 698 | { |
---|
| 699 | data_in[i] = r_buf_in[i]; |
---|
| 700 | put_in[i] = true; |
---|
| 701 | req_in[i] = broadcast_route(1, i, r_buf_in[i].data); |
---|
| 702 | r_index_in[i] = req_in[i]; |
---|
| 703 | if ( req_in[i] == REQ_NOP ) // no transfer for this step |
---|
| 704 | { |
---|
| 705 | r_fsm_in[i] = INFSM_REQ_SECOND; |
---|
| 706 | } |
---|
| 707 | else |
---|
| 708 | { |
---|
| 709 | if( get_out[req_in[i]] == i ) // header flit transfered |
---|
| 710 | { |
---|
| 711 | r_fsm_in[i] = INFSM_ALLOC_FIRST; |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | break; |
---|
| 715 | } |
---|
| 716 | case INFSM_ALLOC_FIRST: // broadcast / first output port allocated |
---|
| 717 | { |
---|
| 718 | data_in[i] = r_fifo_in[i].read(); |
---|
| 719 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 720 | req_in[i] = REQ_NOP; |
---|
| 721 | if( (get_out[r_index_in[i].read()] == i) |
---|
| 722 | and r_fifo_in[i].rok() ) // data flit transfered |
---|
| 723 | { |
---|
| 724 | if ( not r_fifo_in[i].read().eop ) |
---|
| 725 | { |
---|
| 726 | std::cout << "ERROR in DSPIN_ROUTER " << name() |
---|
| 727 | << " : broadcast packet must be 2 flits" << std::endl; |
---|
| 728 | } |
---|
| 729 | r_fsm_in[i] = INFSM_REQ_SECOND; |
---|
| 730 | } |
---|
| 731 | break; |
---|
| 732 | } |
---|
| 733 | case INFSM_REQ_SECOND: // broacast / waiting second output port allocation |
---|
| 734 | { |
---|
| 735 | data_in[i] = r_buf_in[i]; |
---|
| 736 | put_in[i] = true; |
---|
| 737 | req_in[i] = broadcast_route(2, i, r_buf_in[i].data); |
---|
| 738 | r_index_in[i] = req_in[i]; |
---|
| 739 | if ( req_in[i] == REQ_NOP ) // no transfer for this step |
---|
| 740 | { |
---|
| 741 | r_fsm_in[i] = INFSM_REQ_THIRD; |
---|
| 742 | } |
---|
| 743 | else |
---|
| 744 | { |
---|
| 745 | if( get_out[req_in[i]] == i ) // header flit transfered |
---|
| 746 | { |
---|
| 747 | r_fsm_in[i] = INFSM_ALLOC_SECOND; |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | break; |
---|
| 751 | } |
---|
| 752 | case INFSM_ALLOC_SECOND: // broadcast / second output port allocated |
---|
| 753 | { |
---|
| 754 | data_in[i] = r_fifo_in[i].read(); |
---|
| 755 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 756 | req_in[i] = REQ_NOP; |
---|
| 757 | if( (get_out[r_index_in[i].read()] == i ) |
---|
| 758 | and r_fifo_in[i].rok() ) // data flit transfered |
---|
| 759 | { |
---|
| 760 | if ( not r_fifo_in[i].read().eop ) |
---|
| 761 | { |
---|
| 762 | std::cout << "ERROR in DSPIN_ROUTER " << name() |
---|
| 763 | << " : broadcast packet must be 2 flits" << std::endl; |
---|
| 764 | } |
---|
| 765 | r_fsm_in[i] = INFSM_REQ_THIRD; |
---|
| 766 | } |
---|
| 767 | break; |
---|
| 768 | } |
---|
| 769 | case INFSM_REQ_THIRD: // broacast / waiting third output port allocation |
---|
| 770 | { |
---|
| 771 | data_in[i] = r_buf_in[i]; |
---|
| 772 | put_in[i] = true; |
---|
| 773 | req_in[i] = broadcast_route(3, i, r_buf_in[i].data); |
---|
| 774 | r_index_in[i] = req_in[i]; |
---|
| 775 | if ( req_in[i] == REQ_NOP ) // no transfer for this step |
---|
| 776 | { |
---|
| 777 | r_fsm_in[i] = INFSM_REQ_FOURTH; |
---|
| 778 | } |
---|
| 779 | else |
---|
| 780 | { |
---|
| 781 | if( get_out[req_in[i]] == i ) // header flit transfered |
---|
| 782 | { |
---|
| 783 | r_fsm_in[i] = INFSM_ALLOC_THIRD; |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | break; |
---|
| 787 | } |
---|
| 788 | case INFSM_ALLOC_THIRD: // broadcast / third output port allocated |
---|
| 789 | { |
---|
| 790 | data_in[i] = r_fifo_in[i].read(); |
---|
| 791 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 792 | req_in[i] = REQ_NOP; |
---|
| 793 | if( (get_out[r_index_in[i].read()] == i ) |
---|
| 794 | and r_fifo_in[i].rok() ) // data flit transfered |
---|
| 795 | { |
---|
| 796 | if ( not r_fifo_in[i].read().eop ) |
---|
| 797 | { |
---|
| 798 | std::cout << "ERROR in DSPIN_ROUTER " << name() |
---|
| 799 | << " : broadcast packet must be 2 flits" << std::endl; |
---|
| 800 | } |
---|
| 801 | r_fsm_in[i] = INFSM_REQ_FOURTH; |
---|
| 802 | } |
---|
| 803 | break; |
---|
| 804 | } |
---|
| 805 | case INFSM_REQ_FOURTH: // broacast / waiting fourth output port allocation |
---|
| 806 | { |
---|
| 807 | data_in[i] = r_buf_in[i]; |
---|
| 808 | put_in[i] = true; |
---|
| 809 | req_in[i] = broadcast_route(4, i, r_buf_in[i].data); |
---|
| 810 | r_index_in[i] = req_in[i]; |
---|
| 811 | if ( req_in[i] == REQ_NOP ) // no transfer for this step |
---|
| 812 | { |
---|
| 813 | fifo_in_read[i] = true; |
---|
| 814 | r_fsm_in[i] = INFSM_IDLE; |
---|
| 815 | } |
---|
| 816 | else |
---|
| 817 | { |
---|
| 818 | if( get_out[req_in[i]] == i ) // header flit transfered |
---|
| 819 | { |
---|
| 820 | r_fsm_in[i] = INFSM_ALLOC_FOURTH; |
---|
| 821 | } |
---|
| 822 | } |
---|
| 823 | break; |
---|
| 824 | } |
---|
| 825 | case INFSM_ALLOC_FOURTH: // broadcast / fourth output port allocated |
---|
| 826 | { |
---|
| 827 | data_in[i] = r_fifo_in[i].read(); |
---|
| 828 | put_in[i] = r_fifo_in[i].rok(); |
---|
| 829 | req_in[i] = REQ_NOP; |
---|
| 830 | if( (get_out[r_index_in[i].read()] == i ) |
---|
| 831 | and r_fifo_in[i].rok() ) // data flit transfered |
---|
| 832 | { |
---|
| 833 | if ( not r_fifo_in[i].read().eop ) |
---|
| 834 | { |
---|
| 835 | std::cout << "ERROR in DSPIN_ROUTER " << name() |
---|
| 836 | << " : broadcast packet must be 2 flits" << std::endl; |
---|
| 837 | } |
---|
| 838 | fifo_in_read[i] = true; |
---|
| 839 | r_fsm_in[i] = INFSM_IDLE; |
---|
| 840 | } |
---|
| 841 | break; |
---|
| 842 | } |
---|
| 843 | } // end switch |
---|
| 844 | } // end for input ports |
---|
| 845 | |
---|
| 846 | // loop on the output ports : |
---|
| 847 | // The r_alloc_out[j] and r_index_out[j] computation |
---|
| 848 | // implements the round-robin allocation policy. |
---|
| 849 | // These two registers implement a 10 states FSM. |
---|
| 850 | for( size_t j = 0 ; j < 5 ; j++ ) |
---|
| 851 | { |
---|
| 852 | if( not r_alloc_out[j].read() ) // not allocated: possible new allocation |
---|
| 853 | { |
---|
| 854 | for( size_t k = r_index_out[j].read() + 1 ; |
---|
| 855 | k < (r_index_out[j] + 6) ; k++) |
---|
| 856 | { |
---|
| 857 | size_t i = k % 5; |
---|
| 858 | |
---|
| 859 | if( req_in[i] == j ) |
---|
| 860 | { |
---|
| 861 | r_alloc_out[j] = true; |
---|
| 862 | r_index_out[j] = i; |
---|
| 863 | break; |
---|
| 864 | } |
---|
| 865 | } // end loop on input ports |
---|
| 866 | } |
---|
| 867 | else // allocated: possible desallocation |
---|
| 868 | { |
---|
| 869 | if ( data_in[r_index_out[j]].eop and |
---|
| 870 | r_fifo_out[j].wok() and |
---|
| 871 | put_in[r_index_out[j]] ) |
---|
| 872 | { |
---|
| 873 | r_alloc_out[j] = false; |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | } // end loop on output ports |
---|
| 877 | |
---|
| 878 | // loop on the output ports : |
---|
| 879 | // The fifo_out_write[j] and fifo_out_wdata[j] computation |
---|
| 880 | // implements the output port mux. |
---|
| 881 | for( size_t j = 0 ; j < 5 ; j++ ) |
---|
| 882 | { |
---|
| 883 | if( r_alloc_out[j] ) // output port allocated |
---|
| 884 | { |
---|
[1006] | 885 | fifo_out_write[j] = put_in[r_index_out[j]]; |
---|
[854] | 886 | fifo_out_wdata[j] = data_in[r_index_out[j]]; |
---|
| 887 | } |
---|
| 888 | } // end loop on the output ports |
---|
| 889 | |
---|
| 890 | // FIFOS update |
---|
| 891 | for(size_t i = 0 ; i < 5 ; i++) |
---|
| 892 | { |
---|
| 893 | r_fifo_in[i].update(fifo_in_read[i], |
---|
| 894 | fifo_in_write[i], |
---|
| 895 | fifo_in_wdata[i]); |
---|
| 896 | r_fifo_out[i].update(fifo_out_read[i], |
---|
| 897 | fifo_out_write[i], |
---|
| 898 | fifo_out_wdata[i]); |
---|
| 899 | } |
---|
| 900 | } // end transition |
---|
| 901 | |
---|
| 902 | //////////////////////////////// |
---|
| 903 | // genMoore |
---|
| 904 | //////////////////////////////// |
---|
| 905 | tmpl(void)::genMoore() |
---|
| 906 | { |
---|
| 907 | for(size_t i = 0 ; i < 5 ; i++) |
---|
| 908 | { |
---|
| 909 | // input ports : READ signals |
---|
[1006] | 910 | p_in[i].read = r_fifo_in[i].wok() || |
---|
| 911 | (((m_disable_mask >> i) & 1) == 1); |
---|
[854] | 912 | |
---|
| 913 | // output ports : DATA & WRITE signals |
---|
| 914 | p_out[i].data = r_fifo_out[i].read().data; |
---|
| 915 | p_out[i].eop = r_fifo_out[i].read().eop; |
---|
[1006] | 916 | p_out[i].write = r_fifo_out[i].rok() && |
---|
| 917 | (((m_disable_mask >> i) & 1) == 0); |
---|
[854] | 918 | } |
---|
| 919 | } // end genMoore |
---|
| 920 | |
---|
| 921 | }} // end namespace |
---|
| 922 | |
---|
| 923 | // Local Variables: |
---|
| 924 | // tab-width: 4 |
---|
| 925 | // c-basic-offset: 4 |
---|
| 926 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 927 | // indent-tabs-mode: nil |
---|
| 928 | // End: |
---|
| 929 | |
---|
| 930 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|