| 1 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 2 | // File: top.cpp  | 
|---|
| 3 | // Author: Alain Greiner  | 
|---|
| 4 | // Copyright: UPMC/LIP6 | 
|---|
| 5 | // Date : may 2013 | 
|---|
| 6 | // This program is released under the GNU public license | 
|---|
| 7 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 8 | // This file define a generic TSAR architecture. | 
|---|
| 9 | // The processor is a MIPS32 processor wrapped in a GDB server | 
|---|
| 10 | // (this is defined in the tsar_xbar_cluster). | 
|---|
| 11 | //  | 
|---|
| 12 | // The seg_reset_base and seg_kcode_base addresses are not constrained | 
|---|
| 13 | // to be 0xBFC00000 and 0x80000000. | 
|---|
| 14 | // | 
|---|
| 15 | // It does not use an external ROM, as the boot code is stored | 
|---|
| 16 | // in cluster (0,0) memory. | 
|---|
| 17 | // | 
|---|
| 18 | // The physical address space is 40 bits. | 
|---|
| 19 | // The 8 address MSB bits define the cluster index. | 
|---|
| 20 | // | 
|---|
| 21 | // The number of clusters cannot be larger than 256. | 
|---|
| 22 | // The number of processors per cluster cannot be larger than 4. | 
|---|
| 23 | //  | 
|---|
| 24 | // - It uses four dspin_local_crossbar per cluster as local interconnect  | 
|---|
| 25 | // - It uses two virtual_dspin routers per cluster as global interconnect | 
|---|
| 26 | // - It uses the vci_cc_vcache_wrapper  | 
|---|
| 27 | // - It uses the vci_mem_cache | 
|---|
| 28 | // - It contains one vci_xicu per cluster. | 
|---|
| 29 | // - It contains one vci_multi_dma per cluster. | 
|---|
| 30 | // - It contains one vci_simple_ram per cluster to model the L3 cache. | 
|---|
| 31 | // | 
|---|
| 32 | // The communication between the MemCache and the Xram is 64 bits. | 
|---|
| 33 | // | 
|---|
| 34 | // All clusters are identical, but the cluster 0 (called io_cluster),  | 
|---|
| 35 | // contains 6 extra components: | 
|---|
| 36 | // - the disk controller (BDEV) | 
|---|
| 37 | // - the multi-channel network controller (MNIC) | 
|---|
| 38 | // - the multi-channel chained buffer dma controller (CDMA) | 
|---|
| 39 | // - the multi-channel tty controller (MTTY) | 
|---|
| 40 | // - the frame buffer controller (FBUF) | 
|---|
| 41 | // | 
|---|
| 42 | // It is build with one single component implementing a cluster, | 
|---|
| 43 | // defined in files tsar_leti_cluster.* (with * = cpp, h, sd) | 
|---|
| 44 | // | 
|---|
| 45 | // The IRQs are connected to XICUs as follow: | 
|---|
| 46 | // - The BDEV IRQ is connected to IRQ_IN[0] in I/O cluster. | 
|---|
| 47 | // - The IRQ_IN[1] to IRQ_IN[7] ports are not used in all clusters. | 
|---|
| 48 | // - The DMA IRQs are connected to IRQ_IN[8:11] in all clusters. | 
|---|
| 49 | // - The MEMC IRQ is connected to IRQ_IN[12] in all clusters. | 
|---|
| 50 | // - The TTY IRQs are connected to IRQ_IN[16:31] in I/O cluster. | 
|---|
| 51 | //  | 
|---|
| 52 | // Some hardware parameters are used when compiling the OS, and are used  | 
|---|
| 53 | // by this top.cpp file. They must be defined in the hard_config.h file : | 
|---|
| 54 | // - X_WIDTH          : number of bits for x coordinate (must be 4) | 
|---|
| 55 | // - Y_WIDTH          : number of bits for y coordinate (must be 4) | 
|---|
| 56 | // - X_SIZE           : number of clusters in a row  | 
|---|
| 57 | // - Y_SIZE           : number of clusters in a column  | 
|---|
| 58 | // - NB_PROCS_MAX     : number of processors per cluster (power of 2) | 
|---|
| 59 | // - NB_DMA_CHANNELS  : number of DMA channels per cluster (< 9) | 
|---|
| 60 | // - NB_TTY_CHANNELS  : number of TTY channels in I/O cluster (< 17) | 
|---|
| 61 | // - NB_NIC_CHANNELS  : number of NIC channels in I/O cluster (< 9) | 
|---|
| 62 | //  | 
|---|
| 63 | // Some other hardware parameters are not used when compiling the OS, | 
|---|
| 64 | // and can be directly defined in this top.cpp file: | 
|---|
| 65 | // - XRAM_LATENCY     : external ram latency  | 
|---|
| 66 | // - MEMC_WAYS        : L2 cache number of ways | 
|---|
| 67 | // - MEMC_SETS        : L2 cache number of sets | 
|---|
| 68 | // - L1_IWAYS      | 
|---|
| 69 | // - L1_ISETS     | 
|---|
| 70 | // - L1_DWAYS    | 
|---|
| 71 | // - L1_DSETS   | 
|---|
| 72 | // - FBUF_X_SIZE      : width of frame buffer (pixels) | 
|---|
| 73 | // - FBUF_Y_SIZE      : heigth of frame buffer (lines) | 
|---|
| 74 | // - BDEV_SECTOR_SIZE : block size for block drvice | 
|---|
| 75 | // - BDEV_IMAGE_NAME  : file pathname for block device  | 
|---|
| 76 | // - NIC_RX_NAME      : file pathname for NIC received packets | 
|---|
| 77 | // - NIC_TX_NAME      : file pathname for NIC transmited packets | 
|---|
| 78 | // - NIC_TIMEOUT      : max number of cycles before closing a container | 
|---|
| 79 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 80 | // General policy for 40 bits physical address decoding: | 
|---|
| 81 | // All physical segments base addresses are multiple of 1 Mbytes | 
|---|
| 82 | // (=> the 24 LSB bits = 0, and the 16 MSB bits define the target)  | 
|---|
| 83 | // The (X_WIDTH + Y_WIDTH) MSB bits (left aligned) define | 
|---|
| 84 | // the cluster index, and the LADR bits define the local index: | 
|---|
| 85 | //      |X_ID|Y_ID|  LADR |     OFFSET          | | 
|---|
| 86 | //      |  4 |  4 |   8   |       24            | | 
|---|
| 87 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 88 | // General policy for 14 bits SRCID decoding: | 
|---|
| 89 | // Each component is identified by (x_id, y_id, l_id) tuple. | 
|---|
| 90 | //      |X_ID|Y_ID| L_ID | | 
|---|
| 91 | //      |  4 |  4 |  6   | | 
|---|
| 92 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 93 |  | 
|---|
| 94 | #include <systemc> | 
|---|
| 95 | #include <sys/time.h> | 
|---|
| 96 | #include <iostream> | 
|---|
| 97 | #include <sstream> | 
|---|
| 98 | #include <cstdlib> | 
|---|
| 99 | #include <cstdarg> | 
|---|
| 100 | #include <stdint.h> | 
|---|
| 101 |  | 
|---|
| 102 | #include "gdbserver.h" | 
|---|
| 103 | #include "mapping_table.h" | 
|---|
| 104 | #include "tsar_leti_cluster.h" | 
|---|
| 105 | #include "alloc_elems.h" | 
|---|
| 106 |  | 
|---|
| 107 | /////////////////////////////////////////////////// | 
|---|
| 108 | //      OS | 
|---|
| 109 | /////////////////////////////////////////////////// | 
|---|
| 110 |  | 
|---|
| 111 | #define USE_GIET_VM     0 | 
|---|
| 112 | #define USE_GIET_TSAR   1 | 
|---|
| 113 |  | 
|---|
| 114 | #if ( USE_GIET_VM and USE_GIET_TSAR ) | 
|---|
| 115 | #error "Can't use Two different OS" | 
|---|
| 116 | #endif | 
|---|
| 117 |  | 
|---|
| 118 | #if ( (not USE_GIET_VM) and (not USE_GIET_TSAR) ) | 
|---|
| 119 | #error "You need to specify one OS" | 
|---|
| 120 | #endif | 
|---|
| 121 |  | 
|---|
| 122 | /////////////////////////////////////////////////// | 
|---|
| 123 | //               Parallelisation | 
|---|
| 124 | /////////////////////////////////////////////////// | 
|---|
| 125 | #define USE_OPENMP 0 | 
|---|
| 126 |  | 
|---|
| 127 | #if USE_OPENMP | 
|---|
| 128 | #include <omp.h> | 
|---|
| 129 | #endif | 
|---|
| 130 |  | 
|---|
| 131 | /////////////////////////////////////////////////// | 
|---|
| 132 | //  cluster index (from x,y coordinates) | 
|---|
| 133 | /////////////////////////////////////////////////// | 
|---|
| 134 |  | 
|---|
| 135 | #define cluster(x,y)   (y + (x << Y_WIDTH)) | 
|---|
| 136 |  | 
|---|
| 137 | #define min(a, b) (a < b ? a : b) | 
|---|
| 138 |  | 
|---|
| 139 | /////////////////////////////////////////////////////////// | 
|---|
| 140 | //          DSPIN parameters            | 
|---|
| 141 | /////////////////////////////////////////////////////////// | 
|---|
| 142 |  | 
|---|
| 143 | #define dspin_cmd_width      39 | 
|---|
| 144 | #define dspin_rsp_width      32 | 
|---|
| 145 |  | 
|---|
| 146 | /////////////////////////////////////////////////////////// | 
|---|
| 147 | //          VCI parameters            | 
|---|
| 148 | /////////////////////////////////////////////////////////// | 
|---|
| 149 |  | 
|---|
| 150 | #define vci_cell_width_int    4 | 
|---|
| 151 | #define vci_cell_width_ext    8 | 
|---|
| 152 |  | 
|---|
| 153 | #if USE_ALMOS | 
|---|
| 154 | #define vci_address_width     32 | 
|---|
| 155 | #endif | 
|---|
| 156 |  | 
|---|
| 157 | #if (USE_GIET_VM or USE_GIET_TSAR) | 
|---|
| 158 | #define vci_address_width     40 | 
|---|
| 159 | #endif | 
|---|
| 160 |  | 
|---|
| 161 | #define vci_plen_width        8 | 
|---|
| 162 | #define vci_rerror_width      1 | 
|---|
| 163 | #define vci_clen_width        1 | 
|---|
| 164 | #define vci_rflag_width       1 | 
|---|
| 165 | #define vci_srcid_width       14 | 
|---|
| 166 | #define vci_pktid_width       4 | 
|---|
| 167 | #define vci_trdid_width       4 | 
|---|
| 168 | #define vci_wrplen_width      1 | 
|---|
| 169 |  | 
|---|
| 170 | //////////////////////////////////////////////////////////// | 
|---|
| 171 | //    Main Hardware Parameters values          | 
|---|
| 172 | //////////////////////i///////////////////////////////////// | 
|---|
| 173 |  | 
|---|
| 174 | #if USE_GIET_VM | 
|---|
| 175 | #include "giet_vm/hard_config.h" | 
|---|
| 176 | #endif | 
|---|
| 177 |  | 
|---|
| 178 | #if USE_GIET_TSAR | 
|---|
| 179 | #include "../../softs/soft_hello_giet/hard_config.h" | 
|---|
| 180 | #endif | 
|---|
| 181 |  | 
|---|
| 182 |  | 
|---|
| 183 | //////////////////////////////////////////////////////////// | 
|---|
| 184 | //    Secondary Hardware Parameters          | 
|---|
| 185 | //////////////////////i///////////////////////////////////// | 
|---|
| 186 |  | 
|---|
| 187 | #define RESET_ADDRESS         0x0 | 
|---|
| 188 |  | 
|---|
| 189 | #define XRAM_LATENCY          0 | 
|---|
| 190 |  | 
|---|
| 191 | #define MEMC_WAYS             16 | 
|---|
| 192 | #define MEMC_SETS             256 | 
|---|
| 193 |  | 
|---|
| 194 | #define L1_IWAYS              4 | 
|---|
| 195 | #define L1_ISETS              64 | 
|---|
| 196 |  | 
|---|
| 197 | #define L1_DWAYS              4 | 
|---|
| 198 | #define L1_DSETS              64 | 
|---|
| 199 |  | 
|---|
| 200 | #define FBUF_X_SIZE           128 | 
|---|
| 201 | #define FBUF_Y_SIZE           128 | 
|---|
| 202 |  | 
|---|
| 203 | #define BDEV_SECTOR_SIZE      512 | 
|---|
| 204 | #define BDEV_IMAGE_NAME       "../../softs/soft_hello_giet/fake" | 
|---|
| 205 |  | 
|---|
| 206 | #define NIC_TIMEOUT           10000 | 
|---|
| 207 | #define NIC_RX_NAME           "../../softs/soft_hello_giet/fake" | 
|---|
| 208 | #define NIC_TX_NAME           "../../softs/soft_hello_giet/fake" | 
|---|
| 209 |  | 
|---|
| 210 | #define NORTH                 0 | 
|---|
| 211 | #define SOUTH                 1 | 
|---|
| 212 | #define EAST                  2 | 
|---|
| 213 | #define WEST                  3 | 
|---|
| 214 |  | 
|---|
| 215 | //////////////////////////////////////////////////////////// | 
|---|
| 216 | //    Arguments for the SoCLib loader          | 
|---|
| 217 | //////////////////////i///////////////////////////////////// | 
|---|
| 218 |  | 
|---|
| 219 | #if USE_GIET_VM | 
|---|
| 220 | #define loader_args          "TBD" | 
|---|
| 221 | #endif | 
|---|
| 222 |  | 
|---|
| 223 | #if USE_GIET_TSAR | 
|---|
| 224 | #define loader_args          "../../softs/soft_hello_giet/bin.soft" | 
|---|
| 225 | #endif | 
|---|
| 226 |  | 
|---|
| 227 | //////////////////////////////////////////////////////////// | 
|---|
| 228 | //     DEBUG Parameters default values          | 
|---|
| 229 | //////////////////////i///////////////////////////////////// | 
|---|
| 230 |  | 
|---|
| 231 | #define MAX_FROZEN_CYCLES     1000000 | 
|---|
| 232 |  | 
|---|
| 233 | //////////////////////////////////////////////////////////////////// | 
|---|
| 234 | //     TGTID definition in direct space | 
|---|
| 235 | // For all components:  global TGTID = global SRCID = cluster_index | 
|---|
| 236 | //////////////////////////////////////////////////////////////////// | 
|---|
| 237 |  | 
|---|
| 238 | #define MEMC_TGTID      0 | 
|---|
| 239 | #define XICU_TGTID      1 | 
|---|
| 240 | #define MDMA_TGTID      2 | 
|---|
| 241 | #define MTTY_TGTID      3 | 
|---|
| 242 | #define FBUF_TGTID      4 | 
|---|
| 243 | #define BDEV_TGTID      5 | 
|---|
| 244 | #define MNIC_TGTID      6 | 
|---|
| 245 | #define CDMA_TGTID      7 | 
|---|
| 246 | #define SIMH_TGTID      8 | 
|---|
| 247 |  | 
|---|
| 248 | /////////////////////////////////////////////////////////////// | 
|---|
| 249 | //    Physical segments definition | 
|---|
| 250 | /////////////////////////////////////////////////////////////// | 
|---|
| 251 | // There is 4 segments replicated in all clusters, | 
|---|
| 252 | // and 5 specific segments in cluster 0 (IO cluster)  | 
|---|
| 253 | // The following values are for segments in cluster 0. | 
|---|
| 254 | // These 32 bits values must be concatenate with the cluster  | 
|---|
| 255 | // index (on 8 bits) to obtain the 40 bits address. | 
|---|
| 256 | /////////////////////////////////////////////////////////////// | 
|---|
| 257 |  | 
|---|
| 258 |    // non replicated segments / only in cluster(0,0) | 
|---|
| 259 |  | 
|---|
| 260 |    #define FBUF_BASE    0xF3000000 | 
|---|
| 261 |    #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2) | 
|---|
| 262 |  | 
|---|
| 263 |    #define BDEV_BASE    0xF4000000 | 
|---|
| 264 |    #define BDEV_SIZE    0x00001000   // 4 Kbytes | 
|---|
| 265 |  | 
|---|
| 266 |    #define MTTY_BASE    0xF2000000 | 
|---|
| 267 |    #define MTTY_SIZE    0x00001000   // 4 Kbytes | 
|---|
| 268 |  | 
|---|
| 269 |    #define MNIC_BASE    0xF5000000 | 
|---|
| 270 |    #define MNIC_SIZE    0x00800000   // 512 Kbytes (for 8 channels) | 
|---|
| 271 |  | 
|---|
| 272 |    #define CDMA_BASE    0xF6000000 | 
|---|
| 273 |    #define CDMA_SIZE    0x00004000 * NB_CMA_CHANNELS | 
|---|
| 274 |  | 
|---|
| 275 |    // replicated segments : address is extended to 40 bits by cluster_xy | 
|---|
| 276 |  | 
|---|
| 277 |    #define MEMC_BASE    0x00000000 | 
|---|
| 278 |    #define MEMC_SIZE    0x01000000   // 16 Mbytes per cluster | 
|---|
| 279 |  | 
|---|
| 280 |    #define XICU_BASE    0xF0000000 | 
|---|
| 281 |    #define XICU_SIZE    0x00001000   // 4 Kbytes | 
|---|
| 282 |  | 
|---|
| 283 |    #define MDMA_BASE    0xF1000000 | 
|---|
| 284 |    #define MDMA_SIZE    0x00001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel | 
|---|
| 285 |  | 
|---|
| 286 |    #define SIMH_BASE    0xFF000000 | 
|---|
| 287 |    #define SIMH_SIZE    0x00001000   // 4 Kbytes | 
|---|
| 288 |  | 
|---|
| 289 | bool stop_called = false; | 
|---|
| 290 |  | 
|---|
| 291 | ///////////////////////////////// | 
|---|
| 292 | int _main(int argc, char *argv[]) | 
|---|
| 293 | { | 
|---|
| 294 |    using namespace sc_core; | 
|---|
| 295 |    using namespace soclib::caba; | 
|---|
| 296 |    using namespace soclib::common; | 
|---|
| 297 |  | 
|---|
| 298 |    uint64_t ncycles          = 0xFFFFFFFFFFFFFFFF; // simulated cycles | 
|---|
| 299 |    char     disk_name[256]   = BDEV_IMAGE_NAME;    // pathname to the disk image | 
|---|
| 300 |    char     nic_rx_name[256] = NIC_RX_NAME;        // pathname to the rx packets file | 
|---|
| 301 |    char     nic_tx_name[256] = NIC_TX_NAME;        // pathname to the tx packets file | 
|---|
| 302 |    size_t   threads_nr       = 1;                  // simulator's threads number | 
|---|
| 303 |    bool     trace_ok         = false;              // trace activated | 
|---|
| 304 |    uint32_t trace_from       = 0;                  // trace start cycle | 
|---|
| 305 |    bool     trace_proc_ok    = false;              // detailed proc trace activated | 
|---|
| 306 |    size_t   trace_memc_ok    = false;              // detailed memc trace activated | 
|---|
| 307 |    size_t   trace_memc_id    = 0;                  // index of memc to be traced  | 
|---|
| 308 |    size_t   trace_proc_id    = 0;                  // index of proc to be traced | 
|---|
| 309 |    uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;  // monitoring frozen processor | 
|---|
| 310 |    struct   timeval t1,t2; | 
|---|
| 311 |    uint64_t ms1,ms2; | 
|---|
| 312 |  | 
|---|
| 313 |    ////////////// command line arguments ////////////////////// | 
|---|
| 314 |    if (argc > 1) | 
|---|
| 315 |    { | 
|---|
| 316 |       for (int n = 1; n < argc; n = n + 2) | 
|---|
| 317 |       { | 
|---|
| 318 |          if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc)) | 
|---|
| 319 |          { | 
|---|
| 320 |             ncycles = (uint64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 321 |          } | 
|---|
| 322 |          else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc)) | 
|---|
| 323 |          { | 
|---|
| 324 |             strcpy(disk_name, argv[n + 1]); | 
|---|
| 325 |          } | 
|---|
| 326 |          else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc)) | 
|---|
| 327 |          { | 
|---|
| 328 |             trace_ok = true; | 
|---|
| 329 |             trace_from = (uint32_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 330 |          } | 
|---|
| 331 |          else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc)) | 
|---|
| 332 |          { | 
|---|
| 333 |             trace_memc_ok = true; | 
|---|
| 334 |             trace_memc_id = (size_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 335 |             size_t x = trace_memc_id >> Y_WIDTH; | 
|---|
| 336 |             size_t y = trace_memc_id & ((1<<Y_WIDTH)-1); | 
|---|
| 337 |  | 
|---|
| 338 |             assert( (x <= X_SIZE) and (y <= Y_SIZE) && | 
|---|
| 339 |                   "MEMCID parameter refers a not valid memory cache"); | 
|---|
| 340 |          } | 
|---|
| 341 |          else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc)) | 
|---|
| 342 |          { | 
|---|
| 343 |             trace_proc_ok = true; | 
|---|
| 344 |             trace_proc_id = (size_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 345 |             size_t cluster_xy = trace_proc_id / NB_PROCS_MAX ; | 
|---|
| 346 |             size_t x          = cluster_xy >> Y_WIDTH; | 
|---|
| 347 |             size_t y          = cluster_xy & ((1<<Y_WIDTH)-1); | 
|---|
| 348 |  | 
|---|
| 349 |             assert( (x <= X_SIZE) and (y <= Y_SIZE) && | 
|---|
| 350 |                   "PROCID parameter refers a not valid processor"); | 
|---|
| 351 |          } | 
|---|
| 352 |          else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc)) | 
|---|
| 353 |          { | 
|---|
| 354 |             threads_nr = (ssize_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 355 |             threads_nr = (threads_nr < 1) ? 1 : threads_nr; | 
|---|
| 356 |          } | 
|---|
| 357 |          else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc)) | 
|---|
| 358 |          { | 
|---|
| 359 |             frozen_cycles = (uint32_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 360 |          } | 
|---|
| 361 |          else | 
|---|
| 362 |          { | 
|---|
| 363 |             std::cout << "   Arguments are (key,value) couples." << std::endl; | 
|---|
| 364 |             std::cout << "   The order is not important." << std::endl; | 
|---|
| 365 |             std::cout << "   Accepted arguments are :" << std::endl << std::endl; | 
|---|
| 366 |             std::cout << "     -DISK pathname_for_disk_image" << std::endl; | 
|---|
| 367 |             std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl; | 
|---|
| 368 |             std::cout << "     -DEBUG debug_start_cycle" << std::endl; | 
|---|
| 369 |             std::cout << "     -THREADS simulator's threads number" << std::endl; | 
|---|
| 370 |             std::cout << "     -FROZEN max_number_of_lines" << std::endl; | 
|---|
| 371 |             std::cout << "     -PERIOD number_of_cycles between trace" << std::endl; | 
|---|
| 372 |             std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl; | 
|---|
| 373 |             std::cout << "     -PROCID index_proc_to_be_traced" << std::endl; | 
|---|
| 374 |             exit(0); | 
|---|
| 375 |          } | 
|---|
| 376 |       } | 
|---|
| 377 |    } | 
|---|
| 378 |  | 
|---|
| 379 |     // checking hardware parameters | 
|---|
| 380 |     assert( (X_SIZE <= 16) and | 
|---|
| 381 |             "The X_SIZE parameter cannot be larger than 16" ); | 
|---|
| 382 |  | 
|---|
| 383 |     assert( (Y_SIZE <= 16) and | 
|---|
| 384 |             "The Y_SIZE parameter cannot be larger than 16" ); | 
|---|
| 385 |  | 
|---|
| 386 |     assert( (NB_PROCS_MAX <= 8) and | 
|---|
| 387 |             "The NB_PROCS_MAX parameter cannot be larger than 8" ); | 
|---|
| 388 |  | 
|---|
| 389 |     assert( (NB_DMA_CHANNELS < 9) and | 
|---|
| 390 |             "The NB_DMA_CHANNELS parameter cannot be larger than 8" ); | 
|---|
| 391 |  | 
|---|
| 392 |     assert( (NB_TTY_CHANNELS <= 16) and | 
|---|
| 393 |             "The NB_TTY_CHANNELS parameter cannot be larger than 16" ); | 
|---|
| 394 |  | 
|---|
| 395 |     assert( (NB_NIC_CHANNELS < 9) and | 
|---|
| 396 |             "The NB_NIC_CHANNELS parameter cannot be larger than 8" ); | 
|---|
| 397 |  | 
|---|
| 398 |     assert( (vci_address_width == 40) and | 
|---|
| 399 |             "VCI address width with the GIET must be 40 bits" ); | 
|---|
| 400 |  | 
|---|
| 401 |     assert( (X_WIDTH == 4) and (Y_WIDTH == 4) and | 
|---|
| 402 |             "ERROR: you must have X_WIDTH == Y_WIDTH == 4"); | 
|---|
| 403 |   | 
|---|
| 404 |     std::cout << std::endl; | 
|---|
| 405 |  | 
|---|
| 406 |     std::cout << " - X_SIZE           = " << X_SIZE << std::endl; | 
|---|
| 407 |     std::cout << " - Y_SIZE           = " << Y_SIZE << std::endl; | 
|---|
| 408 |     std::cout << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl; | 
|---|
| 409 |     std::cout << " - NB_DMA_CHANNELS  = " << NB_DMA_CHANNELS <<  std::endl; | 
|---|
| 410 |     std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl; | 
|---|
| 411 |     std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl; | 
|---|
| 412 |     std::cout << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl; | 
|---|
| 413 |     std::cout << " - MEMC_SETS        = " << MEMC_SETS << std::endl; | 
|---|
| 414 |     std::cout << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl; | 
|---|
| 415 |     std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl; | 
|---|
| 416 |     std::cout << " - MAX_CYCLES       = " << ncycles << std::endl; | 
|---|
| 417 |     std::cout << " - RESET_ADDRESS    = " << RESET_ADDRESS << std::endl; | 
|---|
| 418 |  | 
|---|
| 419 |     std::cout << std::endl; | 
|---|
| 420 |  | 
|---|
| 421 |     // Internal and External VCI parameters definition | 
|---|
| 422 |     typedef soclib::caba::VciParams<vci_cell_width_int, | 
|---|
| 423 |                                     vci_plen_width, | 
|---|
| 424 |                                     vci_address_width, | 
|---|
| 425 |                                     vci_rerror_width, | 
|---|
| 426 |                                     vci_clen_width, | 
|---|
| 427 |                                     vci_rflag_width, | 
|---|
| 428 |                                     vci_srcid_width, | 
|---|
| 429 |                                     vci_pktid_width, | 
|---|
| 430 |                                     vci_trdid_width, | 
|---|
| 431 |                                     vci_wrplen_width> vci_param_int; | 
|---|
| 432 |  | 
|---|
| 433 |     typedef soclib::caba::VciParams<vci_cell_width_ext, | 
|---|
| 434 |                                     vci_plen_width, | 
|---|
| 435 |                                     vci_address_width, | 
|---|
| 436 |                                     vci_rerror_width, | 
|---|
| 437 |                                     vci_clen_width, | 
|---|
| 438 |                                     vci_rflag_width, | 
|---|
| 439 |                                     vci_srcid_width, | 
|---|
| 440 |                                     vci_pktid_width, | 
|---|
| 441 |                                     vci_trdid_width, | 
|---|
| 442 |                                     vci_wrplen_width> vci_param_ext; | 
|---|
| 443 |  | 
|---|
| 444 | #if USE_OPENMP | 
|---|
| 445 |    omp_set_dynamic(false); | 
|---|
| 446 |    omp_set_num_threads(threads_nr); | 
|---|
| 447 |    std::cerr << "Built with openmp version " << _OPENMP << std::endl; | 
|---|
| 448 | #endif | 
|---|
| 449 |  | 
|---|
| 450 |  | 
|---|
| 451 |    ///////////////////// | 
|---|
| 452 |    //  Mapping Tables | 
|---|
| 453 |    ///////////////////// | 
|---|
| 454 |  | 
|---|
| 455 |    // internal network | 
|---|
| 456 |    MappingTable maptabd(vci_address_width,  | 
|---|
| 457 |                         IntTab(X_WIDTH + Y_WIDTH, 16 - X_WIDTH - Y_WIDTH),  | 
|---|
| 458 |                         IntTab(X_WIDTH + Y_WIDTH, vci_srcid_width - X_WIDTH - Y_WIDTH),  | 
|---|
| 459 |                         0xFF800000); | 
|---|
| 460 |  | 
|---|
| 461 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 462 |    { | 
|---|
| 463 |       for (size_t y = 0; y < Y_SIZE; y++) | 
|---|
| 464 |       { | 
|---|
| 465 |          sc_uint<vci_address_width> offset; | 
|---|
| 466 |          offset = (sc_uint<vci_address_width>)cluster(x,y)  | 
|---|
| 467 |                    << (vci_address_width-X_WIDTH-Y_WIDTH); | 
|---|
| 468 |  | 
|---|
| 469 |          std::ostringstream    si; | 
|---|
| 470 |          si << "seg_xicu_" << x << "_" << y; | 
|---|
| 471 |          maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE,  | 
|---|
| 472 |                   IntTab(cluster(x,y),XICU_TGTID), false)); | 
|---|
| 473 |  | 
|---|
| 474 |          std::ostringstream    sd; | 
|---|
| 475 |          sd << "seg_mdma_" << x << "_" << y; | 
|---|
| 476 |          maptabd.add(Segment(sd.str(), MDMA_BASE + offset, MDMA_SIZE,  | 
|---|
| 477 |                   IntTab(cluster(x,y),MDMA_TGTID), false)); | 
|---|
| 478 |  | 
|---|
| 479 |          std::ostringstream    sh; | 
|---|
| 480 |          sh << "seg_memc_" << x << "_" << y; | 
|---|
| 481 |          maptabd.add(Segment(sh.str(), MEMC_BASE + offset, MEMC_SIZE,  | 
|---|
| 482 |                   IntTab(cluster(x,y),MEMC_TGTID), true)); | 
|---|
| 483 |  | 
|---|
| 484 |          if ( cluster(x,y) == 0 ) | 
|---|
| 485 |          { | 
|---|
| 486 |             maptabd.add(Segment("seg_mtty", MTTY_BASE, MTTY_SIZE,  | 
|---|
| 487 |                         IntTab(cluster(x,y),MTTY_TGTID), false)); | 
|---|
| 488 |             maptabd.add(Segment("seg_fbuf", FBUF_BASE, FBUF_SIZE,  | 
|---|
| 489 |                         IntTab(cluster(x,y),FBUF_TGTID), false)); | 
|---|
| 490 |             maptabd.add(Segment("seg_bdev", BDEV_BASE, BDEV_SIZE,  | 
|---|
| 491 |                         IntTab(cluster(x,y),BDEV_TGTID), false)); | 
|---|
| 492 |             maptabd.add(Segment("seg_mnic", MNIC_BASE, MNIC_SIZE,  | 
|---|
| 493 |                         IntTab(cluster(x,y),MNIC_TGTID), false)); | 
|---|
| 494 |             maptabd.add(Segment("seg_cdma", CDMA_BASE, CDMA_SIZE,  | 
|---|
| 495 |                         IntTab(cluster(x,y),CDMA_TGTID), false)); | 
|---|
| 496 |             maptabd.add(Segment("seg_simh", SIMH_BASE, SIMH_SIZE,  | 
|---|
| 497 |                         IntTab(cluster(x,y),SIMH_TGTID), false)); | 
|---|
| 498 |          } | 
|---|
| 499 |       } | 
|---|
| 500 |    } | 
|---|
| 501 |    std::cout << maptabd << std::endl; | 
|---|
| 502 |  | 
|---|
| 503 |    // external network | 
|---|
| 504 |    MappingTable maptabx(vci_address_width,  | 
|---|
| 505 |                         IntTab(X_WIDTH+Y_WIDTH),  | 
|---|
| 506 |                         IntTab(X_WIDTH+Y_WIDTH),  | 
|---|
| 507 |                         0xFFFF000000ULL); | 
|---|
| 508 |  | 
|---|
| 509 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 510 |    { | 
|---|
| 511 |       for (size_t y = 0; y < Y_SIZE ; y++) | 
|---|
| 512 |       {  | 
|---|
| 513 |  | 
|---|
| 514 |          sc_uint<vci_address_width> offset; | 
|---|
| 515 |          offset = (sc_uint<vci_address_width>)cluster(x,y)  | 
|---|
| 516 |                    << (vci_address_width-X_WIDTH-Y_WIDTH); | 
|---|
| 517 |  | 
|---|
| 518 |          std::ostringstream sh; | 
|---|
| 519 |          sh << "x_seg_memc_" << x << "_" << y; | 
|---|
| 520 |  | 
|---|
| 521 |          maptabx.add(Segment(sh.str(), MEMC_BASE + offset,  | 
|---|
| 522 |                      MEMC_SIZE, IntTab(cluster(x,y)), false)); | 
|---|
| 523 |       } | 
|---|
| 524 |    } | 
|---|
| 525 |    std::cout << maptabx << std::endl; | 
|---|
| 526 |  | 
|---|
| 527 |    //////////////////// | 
|---|
| 528 |    // Signals | 
|---|
| 529 |    /////////////////// | 
|---|
| 530 |  | 
|---|
| 531 |    sc_clock           signal_clk("clk"); | 
|---|
| 532 |    sc_signal<bool>    signal_resetn("resetn"); | 
|---|
| 533 |  | 
|---|
| 534 |    // Horizontal inter-clusters DSPIN signals | 
|---|
| 535 |    DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_inc = | 
|---|
| 536 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", X_SIZE-1, Y_SIZE, 3); | 
|---|
| 537 |    DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_dec = | 
|---|
| 538 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", X_SIZE-1, Y_SIZE, 3); | 
|---|
| 539 |    DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_inc = | 
|---|
| 540 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", X_SIZE-1, Y_SIZE, 2); | 
|---|
| 541 |    DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_dec = | 
|---|
| 542 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", X_SIZE-1, Y_SIZE, 2); | 
|---|
| 543 |  | 
|---|
| 544 |    // Vertical inter-clusters DSPIN signals | 
|---|
| 545 |    DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_inc = | 
|---|
| 546 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", X_SIZE, Y_SIZE-1, 3); | 
|---|
| 547 |    DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_dec = | 
|---|
| 548 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", X_SIZE, Y_SIZE-1, 3); | 
|---|
| 549 |    DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_inc = | 
|---|
| 550 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", X_SIZE, Y_SIZE-1, 2); | 
|---|
| 551 |    DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_dec = | 
|---|
| 552 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", X_SIZE, Y_SIZE-1, 2); | 
|---|
| 553 |  | 
|---|
| 554 |    // Mesh boundaries DSPIN signals | 
|---|
| 555 |    DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_in = | 
|---|
| 556 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_in" , X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 557 |    DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_out = | 
|---|
| 558 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_out", X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 559 |    DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_in = | 
|---|
| 560 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_in" , X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 561 |    DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_out = | 
|---|
| 562 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_out", X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 563 |  | 
|---|
| 564 |  | 
|---|
| 565 |    //////////////////////////// | 
|---|
| 566 |    //      Loader     | 
|---|
| 567 |    //////////////////////////// | 
|---|
| 568 |  | 
|---|
| 569 |    soclib::common::Loader loader( loader_args ); | 
|---|
| 570 |  | 
|---|
| 571 |    typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss; | 
|---|
| 572 |    proc_iss::set_loader(loader); | 
|---|
| 573 |  | 
|---|
| 574 |    //////////////////////////// | 
|---|
| 575 |    // Clusters construction | 
|---|
| 576 |    //////////////////////////// | 
|---|
| 577 |  | 
|---|
| 578 |    TsarLetiCluster<dspin_cmd_width, | 
|---|
| 579 |                    dspin_rsp_width, | 
|---|
| 580 |                    vci_param_int, | 
|---|
| 581 |                    vci_param_ext>*          clusters[X_SIZE][Y_SIZE]; | 
|---|
| 582 |  | 
|---|
| 583 | #if USE_OPENMP | 
|---|
| 584 | #pragma omp parallel | 
|---|
| 585 |     { | 
|---|
| 586 | #pragma omp for | 
|---|
| 587 | #endif | 
|---|
| 588 |         for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++) | 
|---|
| 589 |         { | 
|---|
| 590 |             size_t x = i / Y_SIZE; | 
|---|
| 591 |             size_t y = i % Y_SIZE; | 
|---|
| 592 |  | 
|---|
| 593 | #if USE_OPENMP | 
|---|
| 594 | #pragma omp critical | 
|---|
| 595 |             { | 
|---|
| 596 | #endif | 
|---|
| 597 |             std::cout << std::endl; | 
|---|
| 598 |             std::cout << "Cluster_" << x << "_" << y  | 
|---|
| 599 |                       << " with cluster_xy = " << cluster(x,y) << std::endl; | 
|---|
| 600 |             std::cout << std::endl; | 
|---|
| 601 |  | 
|---|
| 602 |             std::ostringstream sc; | 
|---|
| 603 |             sc << "cluster_" << x << "_" << y; | 
|---|
| 604 |             clusters[x][y] = new TsarLetiCluster<dspin_cmd_width, | 
|---|
| 605 |                                                  dspin_rsp_width, | 
|---|
| 606 |                                                  vci_param_int, | 
|---|
| 607 |                                                  vci_param_ext> | 
|---|
| 608 |             ( | 
|---|
| 609 |                 sc.str().c_str(), | 
|---|
| 610 |                 NB_PROCS_MAX, | 
|---|
| 611 |                 NB_TTY_CHANNELS,   | 
|---|
| 612 |                 NB_DMA_CHANNELS,  | 
|---|
| 613 |                 x, | 
|---|
| 614 |                 y, | 
|---|
| 615 |                 cluster(x,y), | 
|---|
| 616 |                 maptabd, | 
|---|
| 617 |                 maptabx, | 
|---|
| 618 |                 RESET_ADDRESS, | 
|---|
| 619 |                 X_WIDTH, | 
|---|
| 620 |                 Y_WIDTH, | 
|---|
| 621 |                 vci_srcid_width - X_WIDTH - Y_WIDTH,   // l_id width, | 
|---|
| 622 |                 MEMC_TGTID, | 
|---|
| 623 |                 XICU_TGTID, | 
|---|
| 624 |                 MDMA_TGTID, | 
|---|
| 625 |                 FBUF_TGTID, | 
|---|
| 626 |                 MTTY_TGTID, | 
|---|
| 627 |                 MNIC_TGTID, | 
|---|
| 628 |                 CDMA_TGTID, | 
|---|
| 629 |                 BDEV_TGTID, | 
|---|
| 630 |                 SIMH_TGTID, | 
|---|
| 631 |                 MEMC_WAYS, | 
|---|
| 632 |                 MEMC_SETS, | 
|---|
| 633 |                 L1_IWAYS, | 
|---|
| 634 |                 L1_ISETS, | 
|---|
| 635 |                 L1_DWAYS, | 
|---|
| 636 |                 L1_DSETS, | 
|---|
| 637 |                 XRAM_LATENCY, | 
|---|
| 638 |                 (cluster(x,y) == 0), | 
|---|
| 639 |                 FBUF_X_SIZE, | 
|---|
| 640 |                 FBUF_Y_SIZE, | 
|---|
| 641 |                 disk_name, | 
|---|
| 642 |                 BDEV_SECTOR_SIZE, | 
|---|
| 643 |                 NB_NIC_CHANNELS, | 
|---|
| 644 |                 nic_rx_name, | 
|---|
| 645 |                 nic_tx_name, | 
|---|
| 646 |                 NIC_TIMEOUT, | 
|---|
| 647 |                 NB_CMA_CHANNELS, | 
|---|
| 648 |                 loader, | 
|---|
| 649 |                 frozen_cycles, | 
|---|
| 650 |                 trace_from, | 
|---|
| 651 |                 trace_proc_ok,  | 
|---|
| 652 |                 trace_proc_id, | 
|---|
| 653 |                 trace_memc_ok,  | 
|---|
| 654 |                 trace_memc_id | 
|---|
| 655 |             ); | 
|---|
| 656 |  | 
|---|
| 657 | #if USE_OPENMP | 
|---|
| 658 |             } // end critical | 
|---|
| 659 | #endif | 
|---|
| 660 |         } // end for | 
|---|
| 661 | #if USE_OPENMP | 
|---|
| 662 |     } | 
|---|
| 663 | #endif | 
|---|
| 664 |  | 
|---|
| 665 |    /////////////////////////////////////////////////////////////// | 
|---|
| 666 |    //     Net-list  | 
|---|
| 667 |    /////////////////////////////////////////////////////////////// | 
|---|
| 668 |  | 
|---|
| 669 |    // Clock & RESET | 
|---|
| 670 |    for (size_t x = 0; x < (X_SIZE); x++){ | 
|---|
| 671 |       for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 672 |          clusters[x][y]->p_clk                         (signal_clk); | 
|---|
| 673 |          clusters[x][y]->p_resetn                      (signal_resetn); | 
|---|
| 674 |       } | 
|---|
| 675 |    } | 
|---|
| 676 |  | 
|---|
| 677 |    // Inter Clusters horizontal connections | 
|---|
| 678 |    if (X_SIZE > 1){ | 
|---|
| 679 |       for (size_t x = 0; x < (X_SIZE-1); x++){ | 
|---|
| 680 |          for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 681 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 682 |                clusters[x][y]->p_cmd_out[EAST][k]      (signal_dspin_h_cmd_inc[x][y][k]); | 
|---|
| 683 |                clusters[x+1][y]->p_cmd_in[WEST][k]     (signal_dspin_h_cmd_inc[x][y][k]); | 
|---|
| 684 |                clusters[x][y]->p_cmd_in[EAST][k]       (signal_dspin_h_cmd_dec[x][y][k]); | 
|---|
| 685 |                clusters[x+1][y]->p_cmd_out[WEST][k]    (signal_dspin_h_cmd_dec[x][y][k]); | 
|---|
| 686 |             } | 
|---|
| 687 |  | 
|---|
| 688 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 689 |                clusters[x][y]->p_rsp_out[EAST][k]      (signal_dspin_h_rsp_inc[x][y][k]); | 
|---|
| 690 |                clusters[x+1][y]->p_rsp_in[WEST][k]     (signal_dspin_h_rsp_inc[x][y][k]); | 
|---|
| 691 |                clusters[x][y]->p_rsp_in[EAST][k]       (signal_dspin_h_rsp_dec[x][y][k]); | 
|---|
| 692 |                clusters[x+1][y]->p_rsp_out[WEST][k]    (signal_dspin_h_rsp_dec[x][y][k]); | 
|---|
| 693 |             } | 
|---|
| 694 |          } | 
|---|
| 695 |       } | 
|---|
| 696 |    } | 
|---|
| 697 |    std::cout << std::endl << "Horizontal connections established" << std::endl;    | 
|---|
| 698 |  | 
|---|
| 699 |    // Inter Clusters vertical connections | 
|---|
| 700 |    if (Y_SIZE > 1) { | 
|---|
| 701 |       for (size_t y = 0; y < (Y_SIZE-1); y++){ | 
|---|
| 702 |          for (size_t x = 0; x < X_SIZE; x++){ | 
|---|
| 703 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 704 |                clusters[x][y]->p_cmd_out[NORTH][k]     (signal_dspin_v_cmd_inc[x][y][k]); | 
|---|
| 705 |                clusters[x][y+1]->p_cmd_in[SOUTH][k]    (signal_dspin_v_cmd_inc[x][y][k]); | 
|---|
| 706 |                clusters[x][y]->p_cmd_in[NORTH][k]      (signal_dspin_v_cmd_dec[x][y][k]); | 
|---|
| 707 |                clusters[x][y+1]->p_cmd_out[SOUTH][k]   (signal_dspin_v_cmd_dec[x][y][k]); | 
|---|
| 708 |             } | 
|---|
| 709 |  | 
|---|
| 710 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 711 |                clusters[x][y]->p_rsp_out[NORTH][k]     (signal_dspin_v_rsp_inc[x][y][k]); | 
|---|
| 712 |                clusters[x][y+1]->p_rsp_in[SOUTH][k]    (signal_dspin_v_rsp_inc[x][y][k]); | 
|---|
| 713 |                clusters[x][y]->p_rsp_in[NORTH][k]      (signal_dspin_v_rsp_dec[x][y][k]); | 
|---|
| 714 |                clusters[x][y+1]->p_rsp_out[SOUTH][k]   (signal_dspin_v_rsp_dec[x][y][k]); | 
|---|
| 715 |             } | 
|---|
| 716 |          } | 
|---|
| 717 |       } | 
|---|
| 718 |    } | 
|---|
| 719 |    std::cout << "Vertical connections established" << std::endl; | 
|---|
| 720 |  | 
|---|
| 721 |    // East & West boundary cluster connections | 
|---|
| 722 |    for (size_t y = 0; y < Y_SIZE; y++) | 
|---|
| 723 |    { | 
|---|
| 724 |       for (size_t k = 0; k < 3; k++) | 
|---|
| 725 |       { | 
|---|
| 726 |          clusters[0][y]->p_cmd_in[WEST][k]        (signal_dspin_false_cmd_in[0][y][WEST][k]); | 
|---|
| 727 |          clusters[0][y]->p_cmd_out[WEST][k]       (signal_dspin_false_cmd_out[0][y][WEST][k]); | 
|---|
| 728 |          clusters[X_SIZE-1][y]->p_cmd_in[EAST][k]   (signal_dspin_false_cmd_in[X_SIZE-1][y][EAST][k]); | 
|---|
| 729 |          clusters[X_SIZE-1][y]->p_cmd_out[EAST][k]  (signal_dspin_false_cmd_out[X_SIZE-1][y][EAST][k]); | 
|---|
| 730 |       } | 
|---|
| 731 |  | 
|---|
| 732 |       for (size_t k = 0; k < 2; k++) | 
|---|
| 733 |       { | 
|---|
| 734 |          clusters[0][y]->p_rsp_in[WEST][k]        (signal_dspin_false_rsp_in[0][y][WEST][k]); | 
|---|
| 735 |          clusters[0][y]->p_rsp_out[WEST][k]       (signal_dspin_false_rsp_out[0][y][WEST][k]); | 
|---|
| 736 |          clusters[X_SIZE-1][y]->p_rsp_in[EAST][k]   (signal_dspin_false_rsp_in[X_SIZE-1][y][EAST][k]); | 
|---|
| 737 |          clusters[X_SIZE-1][y]->p_rsp_out[EAST][k]  (signal_dspin_false_rsp_out[X_SIZE-1][y][EAST][k]); | 
|---|
| 738 |       } | 
|---|
| 739 |    } | 
|---|
| 740 |  | 
|---|
| 741 |    // North & South boundary clusters connections | 
|---|
| 742 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 743 |    { | 
|---|
| 744 |       for (size_t k = 0; k < 3; k++) | 
|---|
| 745 |       { | 
|---|
| 746 |          clusters[x][0]->p_cmd_in[SOUTH][k]       (signal_dspin_false_cmd_in[x][0][SOUTH][k]); | 
|---|
| 747 |          clusters[x][0]->p_cmd_out[SOUTH][k]      (signal_dspin_false_cmd_out[x][0][SOUTH][k]); | 
|---|
| 748 |          clusters[x][Y_SIZE-1]->p_cmd_in[NORTH][k]  (signal_dspin_false_cmd_in[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 749 |          clusters[x][Y_SIZE-1]->p_cmd_out[NORTH][k] (signal_dspin_false_cmd_out[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 750 |       } | 
|---|
| 751 |  | 
|---|
| 752 |       for (size_t k = 0; k < 2; k++) | 
|---|
| 753 |       { | 
|---|
| 754 |          clusters[x][0]->p_rsp_in[SOUTH][k]       (signal_dspin_false_rsp_in[x][0][SOUTH][k]); | 
|---|
| 755 |          clusters[x][0]->p_rsp_out[SOUTH][k]      (signal_dspin_false_rsp_out[x][0][SOUTH][k]); | 
|---|
| 756 |          clusters[x][Y_SIZE-1]->p_rsp_in[NORTH][k]  (signal_dspin_false_rsp_in[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 757 |          clusters[x][Y_SIZE-1]->p_rsp_out[NORTH][k] (signal_dspin_false_rsp_out[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 758 |       } | 
|---|
| 759 |    } | 
|---|
| 760 |    std::cout << "North, South, West, East connections established" << std::endl; | 
|---|
| 761 |    std::cout << std::endl; | 
|---|
| 762 |  | 
|---|
| 763 |  | 
|---|
| 764 |    //////////////////////////////////////////////////////// | 
|---|
| 765 |    //   Simulation | 
|---|
| 766 |    /////////////////////////////////////////////////////// | 
|---|
| 767 |  | 
|---|
| 768 |    sc_start(sc_core::sc_time(0, SC_NS)); | 
|---|
| 769 |    signal_resetn = false; | 
|---|
| 770 |  | 
|---|
| 771 |    // network boundaries signals | 
|---|
| 772 |    for (size_t x = 0; x < X_SIZE ; x++){ | 
|---|
| 773 |       for (size_t y = 0; y < Y_SIZE ; y++){ | 
|---|
| 774 |          for (size_t a = 0; a < 4; a++){ | 
|---|
| 775 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 776 |                signal_dspin_false_cmd_in [x][y][a][k].write = false; | 
|---|
| 777 |                signal_dspin_false_cmd_in [x][y][a][k].read  = true; | 
|---|
| 778 |                signal_dspin_false_cmd_out[x][y][a][k].write = false; | 
|---|
| 779 |                signal_dspin_false_cmd_out[x][y][a][k].read  = true; | 
|---|
| 780 |             } | 
|---|
| 781 |  | 
|---|
| 782 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 783 |                signal_dspin_false_rsp_in [x][y][a][k].write = false; | 
|---|
| 784 |                signal_dspin_false_rsp_in [x][y][a][k].read  = true; | 
|---|
| 785 |                signal_dspin_false_rsp_out[x][y][a][k].write = false; | 
|---|
| 786 |                signal_dspin_false_rsp_out[x][y][a][k].read  = true; | 
|---|
| 787 |             } | 
|---|
| 788 |          } | 
|---|
| 789 |       } | 
|---|
| 790 |    } | 
|---|
| 791 |  | 
|---|
| 792 |    sc_start(sc_core::sc_time(1, SC_NS)); | 
|---|
| 793 |    signal_resetn = true; | 
|---|
| 794 |  | 
|---|
| 795 |    if (gettimeofday(&t1, NULL) != 0)  | 
|---|
| 796 |    { | 
|---|
| 797 |       perror("gettimeofday"); | 
|---|
| 798 |       return EXIT_FAILURE; | 
|---|
| 799 |    } | 
|---|
| 800 |  | 
|---|
| 801 |    for (uint64_t n = 1; n < ncycles && !stop_called; n++) | 
|---|
| 802 |    { | 
|---|
| 803 |       // Monitor a specific address for L1 & L2 caches | 
|---|
| 804 |       //clusters[0][0]->proc[0]->cache_monitor(0x800002c000ULL); | 
|---|
| 805 |       //clusters[1][0]->memc->copies_monitor(0x800002C000ULL); | 
|---|
| 806 |  | 
|---|
| 807 |       if( (n % 5000000) == 0) | 
|---|
| 808 |       { | 
|---|
| 809 |  | 
|---|
| 810 |          if (gettimeofday(&t2, NULL) != 0)  | 
|---|
| 811 |          { | 
|---|
| 812 |             perror("gettimeofday"); | 
|---|
| 813 |             return EXIT_FAILURE; | 
|---|
| 814 |          } | 
|---|
| 815 |  | 
|---|
| 816 |          ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000; | 
|---|
| 817 |          ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000; | 
|---|
| 818 |          std::cerr << "platform clock frequency "  | 
|---|
| 819 |                    << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl; | 
|---|
| 820 |  | 
|---|
| 821 |          if (gettimeofday(&t1, NULL) != 0)  | 
|---|
| 822 |          { | 
|---|
| 823 |             perror("gettimeofday"); | 
|---|
| 824 |             return EXIT_FAILURE; | 
|---|
| 825 |          } | 
|---|
| 826 |       } | 
|---|
| 827 |  | 
|---|
| 828 |       if ( trace_ok and (n > trace_from) ) | 
|---|
| 829 |       { | 
|---|
| 830 |          std::cout << "****************** cycle " << std::dec << n ; | 
|---|
| 831 |          std::cout << " ************************************************" << std::endl; | 
|---|
| 832 |  | 
|---|
| 833 |         // trace proc[trace_proc_id]  | 
|---|
| 834 |         size_t l = trace_proc_id % NB_PROCS_MAX ; | 
|---|
| 835 |         size_t x = (trace_proc_id / NB_PROCS_MAX) >> Y_WIDTH ; | 
|---|
| 836 |         size_t y = (trace_proc_id / NB_PROCS_MAX) & ((1<<Y_WIDTH) - 1); | 
|---|
| 837 |  | 
|---|
| 838 |         std::ostringstream proc_signame; | 
|---|
| 839 |         proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ; | 
|---|
| 840 |         std::ostringstream p2m_signame; | 
|---|
| 841 |         p2m_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " P2M" ; | 
|---|
| 842 |         std::ostringstream m2p_signame; | 
|---|
| 843 |         m2p_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " M2P" ; | 
|---|
| 844 |         std::ostringstream p_cmd_signame; | 
|---|
| 845 |         p_cmd_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " CMD" ; | 
|---|
| 846 |         std::ostringstream p_rsp_signame; | 
|---|
| 847 |         p_rsp_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " RSP" ; | 
|---|
| 848 |  | 
|---|
| 849 |         clusters[x][y]->proc[l]->print_trace(); | 
|---|
| 850 | //        clusters[x][y]->wi_proc[l]->print_trace(); | 
|---|
| 851 |         clusters[x][y]->signal_vci_ini_proc[l].print_trace(proc_signame.str()); | 
|---|
| 852 |         clusters[x][y]->signal_dspin_p2m_proc[l].print_trace(p2m_signame.str()); | 
|---|
| 853 |         clusters[x][y]->signal_dspin_m2p_proc[l].print_trace(m2p_signame.str()); | 
|---|
| 854 |         clusters[x][y]->signal_dspin_cmd_proc_i[l].print_trace(p_cmd_signame.str()); | 
|---|
| 855 |         clusters[x][y]->signal_dspin_rsp_proc_i[l].print_trace(p_rsp_signame.str()); | 
|---|
| 856 |  | 
|---|
| 857 | //        clusters[x][y]->xbar_rsp_d->print_trace(); | 
|---|
| 858 | //        clusters[x][y]->xbar_cmd_d->print_trace(); | 
|---|
| 859 | //        clusters[x][y]->signal_dspin_cmd_l2g_d.print_trace("[SIG]L2G CMD"); | 
|---|
| 860 | //        clusters[x][y]->signal_dspin_cmd_g2l_d.print_trace("[SIG]G2L CMD"); | 
|---|
| 861 | //        clusters[x][y]->signal_dspin_rsp_l2g_d.print_trace("[SIG]L2G RSP"); | 
|---|
| 862 | //        clusters[x][y]->signal_dspin_rsp_g2l_d.print_trace("[SIG]G2L RSP"); | 
|---|
| 863 |  | 
|---|
| 864 |         // trace memc[trace_memc_id]  | 
|---|
| 865 |         x = trace_memc_id >> Y_WIDTH; | 
|---|
| 866 |         y = trace_memc_id & ((1<<Y_WIDTH) - 1); | 
|---|
| 867 |  | 
|---|
| 868 |         std::ostringstream smemc; | 
|---|
| 869 |         smemc << "[SIG]MEMC_" << x << "_" << y; | 
|---|
| 870 |         std::ostringstream sxram; | 
|---|
| 871 |         sxram << "[SIG]XRAM_" << x << "_" << y; | 
|---|
| 872 |         std::ostringstream sm2p; | 
|---|
| 873 |         sm2p << "[SIG]MEMC_" << x << "_" << y << " M2P" ; | 
|---|
| 874 |         std::ostringstream sp2m; | 
|---|
| 875 |         sp2m << "[SIG]MEMC_" << x << "_" << y << " P2M" ; | 
|---|
| 876 |         std::ostringstream m_cmd_signame; | 
|---|
| 877 |         m_cmd_signame << "[SIG]MEMC_" << x << "_" << y <<  " CMD" ; | 
|---|
| 878 |         std::ostringstream m_rsp_signame; | 
|---|
| 879 |         m_rsp_signame << "[SIG]MEMC_" << x << "_" << y <<  " RSP" ; | 
|---|
| 880 |  | 
|---|
| 881 |         clusters[x][y]->memc->print_trace(); | 
|---|
| 882 | //        clusters[x][y]->wt_memc->print_trace(); | 
|---|
| 883 |         clusters[x][y]->signal_vci_tgt_memc.print_trace(smemc.str()); | 
|---|
| 884 |         clusters[x][y]->signal_vci_xram.print_trace(sxram.str()); | 
|---|
| 885 |         clusters[x][y]->signal_dspin_p2m_memc.print_trace(sp2m.str()); | 
|---|
| 886 |         clusters[x][y]->signal_dspin_m2p_memc.print_trace(sm2p.str()); | 
|---|
| 887 |         clusters[x][y]->signal_dspin_cmd_memc_t.print_trace(m_cmd_signame.str()); | 
|---|
| 888 |         clusters[x][y]->signal_dspin_rsp_memc_t.print_trace(m_rsp_signame.str()); | 
|---|
| 889 |          | 
|---|
| 890 |         // trace replicated peripherals | 
|---|
| 891 | //        clusters[1][1]->mdma->print_trace(); | 
|---|
| 892 | //        clusters[1][1]->signal_vci_tgt_mdma.print_trace("[SIG]MDMA_TGT_1_1"); | 
|---|
| 893 | //        clusters[1][1]->signal_vci_ini_mdma.print_trace("[SIG]MDMA_INI_1_1"); | 
|---|
| 894 |          | 
|---|
| 895 |  | 
|---|
| 896 |         // trace external peripherals | 
|---|
| 897 |          | 
|---|
| 898 | //        clusters[0][0]->bdev->print_trace(); | 
|---|
| 899 | //        clusters[0][0]->signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT"); | 
|---|
| 900 | //        clusters[0][0]->signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI"); | 
|---|
| 901 |  | 
|---|
| 902 | //        clusters[0][0]->mtty->print_trace(); | 
|---|
| 903 | //        clusters[0][0]->wt_mtty->print_trace(); | 
|---|
| 904 | //        clusters[0][0]->signal_vci_tgt_mtty.print_trace("[SIG]MTTY"); | 
|---|
| 905 |       } | 
|---|
| 906 |  | 
|---|
| 907 |       sc_start(sc_core::sc_time(1, SC_NS)); | 
|---|
| 908 |    } | 
|---|
| 909 |  | 
|---|
| 910 |     | 
|---|
| 911 |    // Free memory | 
|---|
| 912 |    for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++) | 
|---|
| 913 |    { | 
|---|
| 914 |       size_t x = i / Y_SIZE; | 
|---|
| 915 |       size_t y = i % Y_SIZE; | 
|---|
| 916 |       delete clusters[x][y]; | 
|---|
| 917 |    } | 
|---|
| 918 |  | 
|---|
| 919 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_inc, X_SIZE - 1, Y_SIZE, 3); | 
|---|
| 920 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_dec, X_SIZE - 1, Y_SIZE, 3); | 
|---|
| 921 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_inc, X_SIZE - 1, Y_SIZE, 2); | 
|---|
| 922 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_dec, X_SIZE - 1, Y_SIZE, 2); | 
|---|
| 923 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_inc, X_SIZE, Y_SIZE - 1, 3); | 
|---|
| 924 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_dec, X_SIZE, Y_SIZE - 1, 3); | 
|---|
| 925 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_inc, X_SIZE, Y_SIZE - 1, 2); | 
|---|
| 926 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_dec, X_SIZE, Y_SIZE - 1, 2); | 
|---|
| 927 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_in, X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 928 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_out, X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 929 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_in, X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 930 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_out, X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 931 |  | 
|---|
| 932 |    return EXIT_SUCCESS; | 
|---|
| 933 | } | 
|---|
| 934 |  | 
|---|
| 935 |  | 
|---|
| 936 | void handler(int dummy = 0) { | 
|---|
| 937 |    stop_called = true; | 
|---|
| 938 |    sc_stop(); | 
|---|
| 939 | } | 
|---|
| 940 |  | 
|---|
| 941 | void voidhandler(int dummy = 0) {} | 
|---|
| 942 |  | 
|---|
| 943 | int sc_main (int argc, char *argv[]) | 
|---|
| 944 | { | 
|---|
| 945 |    signal(SIGINT, handler); | 
|---|
| 946 |    signal(SIGPIPE, voidhandler); | 
|---|
| 947 |  | 
|---|
| 948 |    try { | 
|---|
| 949 |       return _main(argc, argv); | 
|---|
| 950 |    } catch (std::exception &e) { | 
|---|
| 951 |       std::cout << e.what() << std::endl; | 
|---|
| 952 |    } catch (...) { | 
|---|
| 953 |       std::cout << "Unknown exception occured" << std::endl; | 
|---|
| 954 |       throw; | 
|---|
| 955 |    } | 
|---|
| 956 |    return 1; | 
|---|
| 957 | } | 
|---|
| 958 |  | 
|---|
| 959 |  | 
|---|
| 960 | // Local Variables: | 
|---|
| 961 | // tab-width: 3 | 
|---|
| 962 | // c-basic-offset: 3 | 
|---|
| 963 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
| 964 | // indent-tabs-mode: nil | 
|---|
| 965 | // End: | 
|---|
| 966 |  | 
|---|
| 967 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 | 
|---|