| 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 physical address space is 40 bits. | 
|---|
| 10 | // | 
|---|
| 11 | // The number of clusters cannot be larger than 256. | 
|---|
| 12 | // The number of processors per cluster cannot be larger than 8. | 
|---|
| 13 | //  | 
|---|
| 14 | // - It uses four dspin_local_crossbar per cluster as local interconnect  | 
|---|
| 15 | // - It uses two virtual_dspin routers per cluster as global interconnect | 
|---|
| 16 | // - It uses the vci_cc_vcache_wrapper  | 
|---|
| 17 | // - It uses the vci_mem_cache | 
|---|
| 18 | // - It contains one vci_xicu per cluster. | 
|---|
| 19 | // - It contains one vci_multi_dma per cluster. | 
|---|
| 20 | // - It contains one vci_simple_ram per cluster to model the L3 cache. | 
|---|
| 21 | // | 
|---|
| 22 | // The communication between the MemCache and the Xram is 64 bits. | 
|---|
| 23 | // | 
|---|
| 24 | // All clusters are identical, but the cluster 0 (called io_cluster),  | 
|---|
| 25 | // contains 6 extra components: | 
|---|
| 26 | // - the boot rom (BROM) | 
|---|
| 27 | // - the disk controller (BDEV) | 
|---|
| 28 | // - the multi-channel network controller (MNIC) | 
|---|
| 29 | // - the multi-channel chained buffer dma controller (CDMA) | 
|---|
| 30 | // - the multi-channel tty controller (MTTY) | 
|---|
| 31 | // - the frame buffer controller (FBUF) | 
|---|
| 32 | // | 
|---|
| 33 | // It is build with one single component implementing a cluster, | 
|---|
| 34 | // defined in files tsar_xbar_cluster.* (with * = cpp, h, sd) | 
|---|
| 35 | // | 
|---|
| 36 | // The IRQs are connected to XICUs as follow: | 
|---|
| 37 | // - The IRQ_IN[0] to IRQ_IN[7] ports are not used in all clusters. | 
|---|
| 38 | // - The DMA IRQs are connected to IRQ_IN[8] to IRQ_IN[15] in all clusters. | 
|---|
| 39 | // - The TTY IRQs are connected to IRQ_IN[16] to IRQ_IN[30] in I/O cluster. | 
|---|
| 40 | // - The BDEV IRQ is connected to IRQ_IN[31] in I/O cluster. | 
|---|
| 41 | //  | 
|---|
| 42 | // Some hardware parameters are used when compiling the OS, and are used  | 
|---|
| 43 | // by this top.cpp file. They must be defined in the hard_config.h file : | 
|---|
| 44 | // - CLUSTER_X        : number of clusters in a row (power of 2) | 
|---|
| 45 | // - CLUSTER_Y        : number of clusters in a column (power of 2) | 
|---|
| 46 | // - CLUSTER_SIZE     : size of the segment allocated to a cluster | 
|---|
| 47 | // - NB_PROCS_MAX     : number of processors per cluster (power of 2) | 
|---|
| 48 | // - NB_DMA_CHANNELS  : number of DMA channels per cluster (< 9) | 
|---|
| 49 | // - NB_TTY_CHANNELS  : number of TTY channels in I/O cluster (< 16) | 
|---|
| 50 | // - NB_NIC_CHANNELS  : number of NIC channels in I/O cluster (< 9) | 
|---|
| 51 | //  | 
|---|
| 52 | // Some other hardware parameters are not used when compiling the OS, | 
|---|
| 53 | // and can be directly defined in this top.cpp file: | 
|---|
| 54 | // - XRAM_LATENCY     : external ram latency  | 
|---|
| 55 | // - MEMC_WAYS        : L2 cache number of ways | 
|---|
| 56 | // - MEMC_SETS        : L2 cache number of sets | 
|---|
| 57 | // - L1_IWAYS      | 
|---|
| 58 | // - L1_ISETS     | 
|---|
| 59 | // - L1_DWAYS    | 
|---|
| 60 | // - L1_DSETS   | 
|---|
| 61 | // - FBUF_X_SIZE      : width of frame buffer (pixels) | 
|---|
| 62 | // - FBUF_Y_SIZE      : heigth of frame buffer (lines) | 
|---|
| 63 | // - BDEV_SECTOR_SIZE : block size for block drvice | 
|---|
| 64 | // - BDEV_IMAGE_NAME  : file pathname for block device  | 
|---|
| 65 | // - NIC_RX_NAME      : file pathname for NIC received packets | 
|---|
| 66 | // - NIC_TX_NAME      : file pathname for NIC transmited packets | 
|---|
| 67 | // - NIC_TIMEOUT      : max number of cycles before closing a container | 
|---|
| 68 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 69 | // General policy for 40 bits physical address decoding: | 
|---|
| 70 | // All physical segments base addresses are multiple of 1 Mbytes | 
|---|
| 71 | // (=> the 24 LSB bits = 0, and the 16 MSB bits define the target)  | 
|---|
| 72 | // The (x_width + y_width) MSB bits (left aligned) define | 
|---|
| 73 | // the cluster index, and the LADR bits define the local index: | 
|---|
| 74 | //      | X_ID  | Y_ID  |---| LADR |     OFFSET          | | 
|---|
| 75 | //      |x_width|y_width|---|  8   |       24            | | 
|---|
| 76 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 77 | // General policy for 14 bits SRCID decoding: | 
|---|
| 78 | // Each component is identified by (x_id, y_id, l_id) tuple. | 
|---|
| 79 | //      | X_ID  | Y_ID  |---| L_ID | | 
|---|
| 80 | //      |x_width|y_width|---|  6   | | 
|---|
| 81 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 82 |  | 
|---|
| 83 | #include <systemc> | 
|---|
| 84 | #include <sys/time.h> | 
|---|
| 85 | #include <iostream> | 
|---|
| 86 | #include <sstream> | 
|---|
| 87 | #include <cstdlib> | 
|---|
| 88 | #include <cstdarg> | 
|---|
| 89 | #include <stdint.h> | 
|---|
| 90 |  | 
|---|
| 91 | #include "gdbserver.h" | 
|---|
| 92 | #include "mapping_table.h" | 
|---|
| 93 | #include "alloc_elems.h" | 
|---|
| 94 | #include "tsar_xbar_cluster.h" | 
|---|
| 95 |  | 
|---|
| 96 | #define USE_ALMOS 1 | 
|---|
| 97 | //#define USE_GIET  | 
|---|
| 98 |  | 
|---|
| 99 | #ifdef USE_ALMOS | 
|---|
| 100 | #ifdef USE_GIET | 
|---|
| 101 | #error "Can't use Two different OS" | 
|---|
| 102 | #endif | 
|---|
| 103 | #endif | 
|---|
| 104 |  | 
|---|
| 105 | #ifndef USE_ALMOS | 
|---|
| 106 | #ifndef USE_GIET | 
|---|
| 107 | #error "You need to specify one OS" | 
|---|
| 108 | #endif | 
|---|
| 109 | #endif | 
|---|
| 110 |  | 
|---|
| 111 | #ifdef USE_ALMOS | 
|---|
| 112 |    #define PREFIX_OS "almos/" | 
|---|
| 113 |    #include "almos/hard_config.h" | 
|---|
| 114 | #endif | 
|---|
| 115 | #ifdef USE_GIET | 
|---|
| 116 |    #define PREFIX_OS "giet_vm/" | 
|---|
| 117 | #endif | 
|---|
| 118 |  | 
|---|
| 119 | /////////////////////////////////////////////////// | 
|---|
| 120 | //               Parallelisation | 
|---|
| 121 | /////////////////////////////////////////////////// | 
|---|
| 122 |  | 
|---|
| 123 | #define USE_OPENMP 0 | 
|---|
| 124 |  | 
|---|
| 125 | #if USE_OPENMP | 
|---|
| 126 | #include <omp.h> | 
|---|
| 127 | #endif | 
|---|
| 128 |  | 
|---|
| 129 | //  cluster index (computed from x,y coordinates) | 
|---|
| 130 | #ifdef USE_ALMOS | 
|---|
| 131 |    #define cluster(x,y)   (y + x * Y_SIZE) | 
|---|
| 132 | #else | 
|---|
| 133 |    #define cluster(x,y)   (y + (x << Y_WIDTH)) | 
|---|
| 134 | #endif | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 | #define min(x, y) (x < y ? x : y) | 
|---|
| 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 | #ifdef USE_ALMOS | 
|---|
| 154 | #define vci_address_width     32 | 
|---|
| 155 | #endif | 
|---|
| 156 | #ifdef USE_GIET | 
|---|
| 157 | #define vci_address_width     40 | 
|---|
| 158 | #endif | 
|---|
| 159 | #define vci_plen_width        8 | 
|---|
| 160 | #define vci_rerror_width      1 | 
|---|
| 161 | #define vci_clen_width        1 | 
|---|
| 162 | #define vci_rflag_width       1 | 
|---|
| 163 | #define vci_srcid_width       14 | 
|---|
| 164 | #define vci_pktid_width       4 | 
|---|
| 165 | #define vci_trdid_width       4 | 
|---|
| 166 | #define vci_wrplen_width      1 | 
|---|
| 167 |  | 
|---|
| 168 | //////////////////////////////////////////////////////////// | 
|---|
| 169 | //    Secondary Hardware Parameters          | 
|---|
| 170 | //////////////////////i///////////////////////////////////// | 
|---|
| 171 |  | 
|---|
| 172 |  | 
|---|
| 173 | #define XRAM_LATENCY          0 | 
|---|
| 174 |  | 
|---|
| 175 | #define MEMC_WAYS             16 | 
|---|
| 176 | #define MEMC_SETS             256 | 
|---|
| 177 |  | 
|---|
| 178 | #define L1_IWAYS              4 | 
|---|
| 179 | #define L1_ISETS              64 | 
|---|
| 180 |  | 
|---|
| 181 | #define L1_DWAYS              4 | 
|---|
| 182 | #define L1_DSETS              64 | 
|---|
| 183 |  | 
|---|
| 184 | #ifdef USE_ALMOS | 
|---|
| 185 | #define FBUF_X_SIZE           1024 | 
|---|
| 186 | #define FBUF_Y_SIZE           1024 | 
|---|
| 187 | #endif | 
|---|
| 188 | #ifdef USE_GIET | 
|---|
| 189 | #define FBUF_X_SIZE           128 | 
|---|
| 190 | #define FBUF_Y_SIZE           128 | 
|---|
| 191 | #endif | 
|---|
| 192 |  | 
|---|
| 193 | #ifdef USE_GIET | 
|---|
| 194 | #define BDEV_SECTOR_SIZE      512 | 
|---|
| 195 | #define BDEV_IMAGE_NAME       PREFIX_OS"display/images.raw" | 
|---|
| 196 | #endif | 
|---|
| 197 | #ifdef USE_ALMOS | 
|---|
| 198 | #define BDEV_SECTOR_SIZE      4096 | 
|---|
| 199 | #define BDEV_IMAGE_NAME       PREFIX_OS"hdd-img.bin" | 
|---|
| 200 | #endif | 
|---|
| 201 |  | 
|---|
| 202 | #define NIC_RX_NAME           PREFIX_OS"nic/rx_packets.txt" | 
|---|
| 203 | #define NIC_TX_NAME           PREFIX_OS"nic/tx_packets.txt" | 
|---|
| 204 | #define NIC_TIMEOUT           10000 | 
|---|
| 205 |  | 
|---|
| 206 | #define NORTH                 0 | 
|---|
| 207 | #define SOUTH                 1 | 
|---|
| 208 | #define EAST                  2 | 
|---|
| 209 | #define WEST                  3 | 
|---|
| 210 |  | 
|---|
| 211 | //////////////////////////////////////////////////////////// | 
|---|
| 212 | //    Software to be loaded in ROM & RAM          | 
|---|
| 213 | //////////////////////i///////////////////////////////////// | 
|---|
| 214 |  | 
|---|
| 215 | #ifdef USE_ALMOS | 
|---|
| 216 | #define soft_name       PREFIX_OS"bootloader-tsar-mipsel.bin",\ | 
|---|
| 217 |                         PREFIX_OS"kernel-soclib.bin@0xbfc10000:D",\ | 
|---|
| 218 |                         PREFIX_OS"arch-info.bib@0xBFC08000:D" | 
|---|
| 219 | #endif | 
|---|
| 220 | #ifdef USE_GIET | 
|---|
| 221 | #define soft_pathname   PREFIX_OS"soft.elf" | 
|---|
| 222 | #endif | 
|---|
| 223 |  | 
|---|
| 224 | //////////////////////////////////////////////////////////// | 
|---|
| 225 | //     DEBUG Parameters default values          | 
|---|
| 226 | //////////////////////i///////////////////////////////////// | 
|---|
| 227 |  | 
|---|
| 228 | #define MAX_FROZEN_CYCLES     100000000 | 
|---|
| 229 |  | 
|---|
| 230 |  | 
|---|
| 231 | //////////////////////////////////////////////////////////////////// | 
|---|
| 232 | //     TGTID definition in direct space | 
|---|
| 233 | // For all components:  global TGTID = global SRCID = cluster_index | 
|---|
| 234 | //////////////////////////////////////////////////////////////////// | 
|---|
| 235 |  | 
|---|
| 236 | #define MEMC_TGTID      0 | 
|---|
| 237 | #define XICU_TGTID      1 | 
|---|
| 238 | #define MDMA_TGTID      2 | 
|---|
| 239 | #define MTTY_TGTID      3 | 
|---|
| 240 | #define BDEV_TGTID      4 | 
|---|
| 241 | #define MNIC_TGTID      5 | 
|---|
| 242 | #define BROM_TGTID      6 | 
|---|
| 243 | #define CDMA_TGTID      7 | 
|---|
| 244 | #define SIMH_TGTID      8 | 
|---|
| 245 | #define FBUF_TGTID      9 | 
|---|
| 246 |  | 
|---|
| 247 |  | 
|---|
| 248 | ///////////////////////////////////////////////////////// | 
|---|
| 249 | //    Physical segments definition | 
|---|
| 250 | ///////////////////////////////////////////////////////// | 
|---|
| 251 | // There is 3 segments replicated in all clusters | 
|---|
| 252 | // and 5 specific segments in the "IO" cluster  | 
|---|
| 253 | // (containing address 0xBF000000) | 
|---|
| 254 | ///////////////////////////////////////////////////////// | 
|---|
| 255 |  | 
|---|
| 256 | #ifdef USE_GIET | 
|---|
| 257 |    // specific segments in "IO" cluster : absolute physical address | 
|---|
| 258 |    #define BROM_BASE    0x00BFC00000 | 
|---|
| 259 |    #define BROM_SIZE    0x0000100000   // 1 Mbytes | 
|---|
| 260 |  | 
|---|
| 261 |    #define FBUF_BASE    0x00B2000000 | 
|---|
| 262 |    #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2) | 
|---|
| 263 |  | 
|---|
| 264 |    #define BDEV_BASE    0x00B3000000 | 
|---|
| 265 |    #define BDEV_SIZE    0x0000001000   // 4 Kbytes | 
|---|
| 266 |  | 
|---|
| 267 |    #define MTTY_BASE    0x00B4000000 | 
|---|
| 268 |    #define MTTY_SIZE    0x0000001000   // 4 Kbytes | 
|---|
| 269 |  | 
|---|
| 270 |    #define MNIC_BASE    0x00B5000000 | 
|---|
| 271 |    #define MNIC_SIZE    0x0000080000   // 512 Kbytes (for 8 channels) | 
|---|
| 272 |  | 
|---|
| 273 |    #define CDMA_BASE    0x00B6000000 | 
|---|
| 274 |    #define CDMA_SIZE    0x0000004000 * NB_CMA_CHANNELS | 
|---|
| 275 |  | 
|---|
| 276 |    // replicated segments : address is incremented by a cluster offset | 
|---|
| 277 |    //     offset  = cluster(x,y) << (address_width-x_width-y_width); | 
|---|
| 278 |  | 
|---|
| 279 |    #define MEMC_BASE    0x0000000000 | 
|---|
| 280 |    #define MEMC_SIZE    0x0010000000   // 256 Mbytes per cluster | 
|---|
| 281 |  | 
|---|
| 282 |    #define XICU_BASE    0x00B0000000 | 
|---|
| 283 |    #define XICU_SIZE    0x0000001000   // 4 Kbytes | 
|---|
| 284 |  | 
|---|
| 285 |    #define MDMA_BASE    0x00B1000000 | 
|---|
| 286 |    #define MDMA_SIZE    0x0000001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel | 
|---|
| 287 |  | 
|---|
| 288 |    #define SIMH_BASE    0x00B7000000 | 
|---|
| 289 |    #define SIMH_SIZE    0x0000001000 | 
|---|
| 290 | #endif | 
|---|
| 291 |  | 
|---|
| 292 | #ifdef USE_ALMOS | 
|---|
| 293 |    // 2^19 is the offset for the local id (8 bits for global ID : | 
|---|
| 294 |    // 1 bit for Memcache or Peripheral, 4 for local peripheral id) | 
|---|
| 295 |    // (Almos supports 32 bits physical addresses) | 
|---|
| 296 |  | 
|---|
| 297 |    #define CLUSTER_INC (0x80000000ULL / (X_SIZE * Y_SIZE) * 2) | 
|---|
| 298 |  | 
|---|
| 299 |    #define CLUSTER_IO_INC (cluster_io_id * CLUSTER_INC) | 
|---|
| 300 |    #define MEMC_MAX_SIZE (0x40000000 / (X_SIZE * Y_SIZE)) // 0x40000000 : valeur totale souhaitée (ici : 1Go) | 
|---|
| 301 |  | 
|---|
| 302 |    #define BROM_BASE    0x00BFC00000 | 
|---|
| 303 |    #define BROM_SIZE    0x0000100000 // 1 Mbytes | 
|---|
| 304 |  | 
|---|
| 305 |    #define MEMC_BASE    0x0000000000 | 
|---|
| 306 |    #define MEMC_SIZE    min(0x04000000, MEMC_MAX_SIZE) | 
|---|
| 307 |  | 
|---|
| 308 |    #define XICU_BASE    (CLUSTER_INC >> 1) + (XICU_TGTID << 19) | 
|---|
| 309 |    #define XICU_SIZE    0x0000001000 // 4 Kbytes | 
|---|
| 310 |     | 
|---|
| 311 |    #define MDMA_BASE    (CLUSTER_INC >> 1) + (MDMA_TGTID << 19) | 
|---|
| 312 |    #define MDMA_SIZE    (0x0000001000 * NB_DMA_CHANNELS) // 4 Kbytes per channel   | 
|---|
| 313 |  | 
|---|
| 314 |    #define BDEV_BASE    (CLUSTER_INC >> 1) + (BDEV_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 315 |    #define BDEV_SIZE    0x0000001000 // 4 Kbytes | 
|---|
| 316 |  | 
|---|
| 317 |    #define MTTY_BASE    (CLUSTER_INC >> 1) + (MTTY_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 318 |    #define MTTY_SIZE    0x0000001000 // 4 Kbytes | 
|---|
| 319 |  | 
|---|
| 320 |    #define FBUF_BASE    (CLUSTER_INC >> 1) + (FBUF_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 321 |    #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2) // Should be 0x80000 | 
|---|
| 322 |  | 
|---|
| 323 |    #define MNIC_BASE    (CLUSTER_INC >> 1) + (MNIC_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 324 |    #define MNIC_SIZE    0x0000080000 | 
|---|
| 325 |  | 
|---|
| 326 |    #define CDMA_BASE    (CLUSTER_INC >> 1) + (CDMA_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 327 |    #define CDMA_SIZE    (0x0000004000 * NB_CMA_CHANNELS) | 
|---|
| 328 |  | 
|---|
| 329 |    #define SIMH_BASE    (CLUSTER_INC >> 1) + (SIMH_TGTID << 19) + (CLUSTER_IO_INC) | 
|---|
| 330 |    #define SIMH_SIZE    0x0000001000 | 
|---|
| 331 | #endif | 
|---|
| 332 |  | 
|---|
| 333 | bool stop_called = false; | 
|---|
| 334 |  | 
|---|
| 335 | ///////////////////////////////// | 
|---|
| 336 | int _main(int argc, char *argv[]) | 
|---|
| 337 | { | 
|---|
| 338 |    using namespace sc_core; | 
|---|
| 339 |    using namespace soclib::caba; | 
|---|
| 340 |    using namespace soclib::common; | 
|---|
| 341 |  | 
|---|
| 342 | #ifdef USE_GIET | 
|---|
| 343 |    char     soft_name[256]    = soft_pathname;      // pathname to binary code | 
|---|
| 344 | #endif | 
|---|
| 345 |    const int64_t max_cycles   = 5000000;             // Maximum number of cycles simulated in one sc_start call | 
|---|
| 346 |    int64_t ncycles            = 0x7FFFFFFFFFFFFFFF;  // simulated cycles | 
|---|
| 347 |    char     disk_name[256]    = BDEV_IMAGE_NAME;    // pathname to the disk image | 
|---|
| 348 |    char     nic_rx_name[256]  = NIC_RX_NAME;        // pathname to the rx packets file | 
|---|
| 349 |    char     nic_tx_name[256]  = NIC_TX_NAME;        // pathname to the tx packets file | 
|---|
| 350 |    ssize_t  threads_nr        = 1;                  // simulator's threads number | 
|---|
| 351 |    bool     debug_ok          = false;              // trace activated | 
|---|
| 352 |    size_t   debug_period      = 1;                  // trace period | 
|---|
| 353 |    size_t   debug_memc_id     = 0;                  // index of memc to be traced  | 
|---|
| 354 |    size_t   debug_proc_id     = 0;                  // index of proc to be traced | 
|---|
| 355 |    int64_t  debug_from        = 0;                  // trace start cycle | 
|---|
| 356 |    int64_t  frozen_cycles     = MAX_FROZEN_CYCLES;  // monitoring frozen processor | 
|---|
| 357 |    size_t   cluster_io_id;                         // index of cluster containing IOs | 
|---|
| 358 |    int64_t  reset_counters    = -1; | 
|---|
| 359 |    int64_t  dump_counters     = -1; | 
|---|
| 360 |    bool     do_reset_counters = false; | 
|---|
| 361 |    bool     do_dump_counters  = false; | 
|---|
| 362 |    struct   timeval t1, t2; | 
|---|
| 363 |    uint64_t ms1, ms2; | 
|---|
| 364 |  | 
|---|
| 365 |    ////////////// command line arguments ////////////////////// | 
|---|
| 366 |    if (argc > 1) | 
|---|
| 367 |    { | 
|---|
| 368 |       for (int n = 1; n < argc; n = n + 2) | 
|---|
| 369 |       { | 
|---|
| 370 |          if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc)) | 
|---|
| 371 |          { | 
|---|
| 372 |             ncycles = (int64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 373 |          } | 
|---|
| 374 |          else if ((strcmp(argv[n], "-SOFT") == 0) && (n + 1 < argc)) | 
|---|
| 375 |          { | 
|---|
| 376 | #ifdef USE_ALMOS | 
|---|
| 377 |             assert( 0 && "Can't define almos soft name" ); | 
|---|
| 378 | #endif | 
|---|
| 379 | #ifdef USE_GIET | 
|---|
| 380 |             strcpy(soft_name, argv[n + 1]); | 
|---|
| 381 | #endif | 
|---|
| 382 |          } | 
|---|
| 383 |          else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc)) | 
|---|
| 384 |          { | 
|---|
| 385 |             strcpy(disk_name, argv[n + 1]); | 
|---|
| 386 |          } | 
|---|
| 387 |          else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc)) | 
|---|
| 388 |          { | 
|---|
| 389 |             debug_ok = true; | 
|---|
| 390 |             debug_from = (int64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 391 |          } | 
|---|
| 392 |          else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc)) | 
|---|
| 393 |          { | 
|---|
| 394 |             debug_memc_id = (size_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 395 | #ifdef USE_ALMOS | 
|---|
| 396 |             assert((debug_memc_id < (X_SIZE * Y_SIZE)) && | 
|---|
| 397 |                    "debug_memc_id larger than X_SIZE * Y_SIZE" ); | 
|---|
| 398 | #else | 
|---|
| 399 |             size_t x = debug_memc_id >> Y_WIDTH; | 
|---|
| 400 |             size_t y = debug_memc_id & ((1<<Y_WIDTH)-1); | 
|---|
| 401 |  | 
|---|
| 402 |             assert( (x <= X_SIZE) and (y <= Y_SIZE) && | 
|---|
| 403 |                   "MEMCID parameter refers a not valid memory cache"); | 
|---|
| 404 | #endif | 
|---|
| 405 |          } | 
|---|
| 406 |          else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc)) | 
|---|
| 407 |          { | 
|---|
| 408 |             debug_proc_id = (size_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 409 | #ifdef USE_ALMOS | 
|---|
| 410 |             assert((debug_proc_id < (X_SIZE * Y_SIZE * NB_PROCS_MAX)) &&  | 
|---|
| 411 |                    "debug_proc_id larger than X_SIZE * Y_SIZE * NB_PROCS"); | 
|---|
| 412 | #else | 
|---|
| 413 |             size_t cluster_xy = debug_proc_id / NB_PROCS_MAX ; | 
|---|
| 414 |             size_t x          = cluster_xy >> Y_WIDTH; | 
|---|
| 415 |             size_t y          = cluster_xy & ((1<<Y_WIDTH)-1); | 
|---|
| 416 |  | 
|---|
| 417 |             assert( (x <= X_SIZE) and (y <= Y_SIZE) && | 
|---|
| 418 |                   "PROCID parameter refers a not valid processor"); | 
|---|
| 419 | #endif | 
|---|
| 420 |          } | 
|---|
| 421 |          else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc)) | 
|---|
| 422 |          { | 
|---|
| 423 |             threads_nr = (ssize_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 424 |             threads_nr = (threads_nr < 1) ? 1 : threads_nr; | 
|---|
| 425 |          } | 
|---|
| 426 |          else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc)) | 
|---|
| 427 |          { | 
|---|
| 428 |             frozen_cycles = (int64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 429 |          } | 
|---|
| 430 |          else if ((strcmp(argv[n], "-PERIOD") == 0) && (n + 1 < argc)) | 
|---|
| 431 |          { | 
|---|
| 432 |             debug_period = (size_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 433 |          } | 
|---|
| 434 |          else if ((strcmp(argv[n], "--reset-counters") == 0) && (n + 1 < argc)) | 
|---|
| 435 |          { | 
|---|
| 436 |             reset_counters = (int64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 437 |             do_reset_counters = true; | 
|---|
| 438 |          } | 
|---|
| 439 |          else if ((strcmp(argv[n], "--dump-counters") == 0) && (n + 1 < argc)) | 
|---|
| 440 |          { | 
|---|
| 441 |             dump_counters = (int64_t) strtol(argv[n + 1], NULL, 0); | 
|---|
| 442 |             do_dump_counters = true; | 
|---|
| 443 |          } | 
|---|
| 444 |          else | 
|---|
| 445 |          { | 
|---|
| 446 |             std::cout << "   Arguments are (key,value) couples." << std::endl; | 
|---|
| 447 |             std::cout << "   The order is not important." << std::endl; | 
|---|
| 448 |             std::cout << "   Accepted arguments are :" << std::endl << std::endl; | 
|---|
| 449 |             std::cout << "     -SOFT pathname_for_embedded_soft" << std::endl; | 
|---|
| 450 |             std::cout << "     -DISK pathname_for_disk_image" << std::endl; | 
|---|
| 451 |             std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl; | 
|---|
| 452 |             std::cout << "     -DEBUG debug_start_cycle" << std::endl; | 
|---|
| 453 |             std::cout << "     -THREADS simulator's threads number" << std::endl; | 
|---|
| 454 |             std::cout << "     -FROZEN max_number_of_lines" << std::endl; | 
|---|
| 455 |             std::cout << "     -PERIOD number_of_cycles between trace" << std::endl; | 
|---|
| 456 |             std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl; | 
|---|
| 457 |             std::cout << "     -PROCID index_proc_to_be_traced" << std::endl; | 
|---|
| 458 |             exit(0); | 
|---|
| 459 |          } | 
|---|
| 460 |       } | 
|---|
| 461 |    } | 
|---|
| 462 |  | 
|---|
| 463 |     // checking hardware parameters | 
|---|
| 464 |     assert( ( (X_SIZE == 1) or (X_SIZE == 2) or (X_SIZE == 4) or | 
|---|
| 465 |               (X_SIZE == 8) or (X_SIZE == 16) ) and | 
|---|
| 466 |               "The X_SIZE parameter must be 1, 2, 4, 8 or 16" ); | 
|---|
| 467 |  | 
|---|
| 468 |     assert( ( (Y_SIZE == 1) or (Y_SIZE == 2) or (Y_SIZE == 4) or | 
|---|
| 469 |               (Y_SIZE == 8) or (Y_SIZE == 16) ) and | 
|---|
| 470 |               "The Y_SIZE parameter must be 1, 2, 4, 8 or 16" ); | 
|---|
| 471 |  | 
|---|
| 472 |     assert( ( (NB_PROCS_MAX == 1) or (NB_PROCS_MAX == 2) or | 
|---|
| 473 |               (NB_PROCS_MAX == 4) or (NB_PROCS_MAX == 8) ) and | 
|---|
| 474 |              "The NB_PROCS_MAX parameter must be 1, 2, 4 or 8" ); | 
|---|
| 475 |  | 
|---|
| 476 |     assert( (NB_DMA_CHANNELS < 9) and | 
|---|
| 477 |             "The NB_DMA_CHANNELS parameter must be smaller than 9" ); | 
|---|
| 478 |  | 
|---|
| 479 |     assert( (NB_TTY_CHANNELS < 15) and | 
|---|
| 480 |             "The NB_TTY_CHANNELS parameter must be smaller than 15" ); | 
|---|
| 481 |  | 
|---|
| 482 |     assert( (NB_NIC_CHANNELS < 9) and | 
|---|
| 483 |             "The NB_NIC_CHANNELS parameter must be smaller than 9" ); | 
|---|
| 484 |  | 
|---|
| 485 | #ifdef USE_GIET | 
|---|
| 486 |     assert( (vci_address_width == 40) and | 
|---|
| 487 |             "VCI address width with the GIET must be 40 bits" ); | 
|---|
| 488 | #endif | 
|---|
| 489 |  | 
|---|
| 490 | #ifdef USE_ALMOS | 
|---|
| 491 |     assert( (vci_address_width == 32) and | 
|---|
| 492 |             "VCI address width with ALMOS must be 32 bits" ); | 
|---|
| 493 | #endif | 
|---|
| 494 |  | 
|---|
| 495 |  | 
|---|
| 496 |     std::cout << std::endl; | 
|---|
| 497 |     std::cout << " - X_SIZE             = " << X_SIZE << std::endl; | 
|---|
| 498 |     std::cout << " - Y_SIZE             = " << Y_SIZE << std::endl; | 
|---|
| 499 |     std::cout << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl; | 
|---|
| 500 |     std::cout << " - NB_DMA_CHANNELS  = " << NB_DMA_CHANNELS <<  std::endl; | 
|---|
| 501 |     std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl; | 
|---|
| 502 |     std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl; | 
|---|
| 503 |     std::cout << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl; | 
|---|
| 504 |     std::cout << " - MEMC_SETS        = " << MEMC_SETS << std::endl; | 
|---|
| 505 |     std::cout << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl; | 
|---|
| 506 |     std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl; | 
|---|
| 507 |  | 
|---|
| 508 |     std::cout << std::endl; | 
|---|
| 509 |     // Internal and External VCI parameters definition | 
|---|
| 510 |     typedef soclib::caba::VciParams<vci_cell_width_int, | 
|---|
| 511 |                                     vci_plen_width, | 
|---|
| 512 |                                     vci_address_width, | 
|---|
| 513 |                                     vci_rerror_width, | 
|---|
| 514 |                                     vci_clen_width, | 
|---|
| 515 |                                     vci_rflag_width, | 
|---|
| 516 |                                     vci_srcid_width, | 
|---|
| 517 |                                     vci_pktid_width, | 
|---|
| 518 |                                     vci_trdid_width, | 
|---|
| 519 |                                     vci_wrplen_width> vci_param_int; | 
|---|
| 520 |  | 
|---|
| 521 |     typedef soclib::caba::VciParams<vci_cell_width_ext, | 
|---|
| 522 |                                     vci_plen_width, | 
|---|
| 523 |                                     vci_address_width, | 
|---|
| 524 |                                     vci_rerror_width, | 
|---|
| 525 |                                     vci_clen_width, | 
|---|
| 526 |                                     vci_rflag_width, | 
|---|
| 527 |                                     vci_srcid_width, | 
|---|
| 528 |                                     vci_pktid_width, | 
|---|
| 529 |                                     vci_trdid_width, | 
|---|
| 530 |                                     vci_wrplen_width> vci_param_ext; | 
|---|
| 531 |  | 
|---|
| 532 | #if USE_OPENMP | 
|---|
| 533 |    omp_set_dynamic(false); | 
|---|
| 534 |    omp_set_num_threads(threads_nr); | 
|---|
| 535 |    std::cerr << "Built with openmp version " << _OPENMP << std::endl; | 
|---|
| 536 | #endif | 
|---|
| 537 |  | 
|---|
| 538 |    // Define parameters depending on mesh size | 
|---|
| 539 |    size_t   x_width; | 
|---|
| 540 |    size_t   y_width; | 
|---|
| 541 |  | 
|---|
| 542 | #ifdef USE_ALMOS | 
|---|
| 543 |    if      (X_SIZE == 1) x_width = 0; | 
|---|
| 544 |    else if (X_SIZE == 2) x_width = 1; | 
|---|
| 545 |    else if (X_SIZE <= 4) x_width = 2; | 
|---|
| 546 |    else if (X_SIZE <= 8) x_width = 3; | 
|---|
| 547 |    else                x_width = 4; | 
|---|
| 548 |  | 
|---|
| 549 |    if      (Y_SIZE == 1) y_width = 0; | 
|---|
| 550 |    else if (Y_SIZE == 2) y_width = 1; | 
|---|
| 551 |    else if (Y_SIZE <= 4) y_width = 2; | 
|---|
| 552 |    else if (Y_SIZE <= 8) y_width = 3; | 
|---|
| 553 |    else                y_width = 4; | 
|---|
| 554 |  | 
|---|
| 555 | #else | 
|---|
| 556 |    size_t x_width = X_WIDTH; | 
|---|
| 557 |    size_t y_width = Y_WIDTH; | 
|---|
| 558 |  | 
|---|
| 559 |    assert( (X_WIDTH <= 4) and (Y_WIDTH <= 4) and | 
|---|
| 560 |            "Up to 256 clusters"); | 
|---|
| 561 |  | 
|---|
| 562 |    assert( (X_SIZE <= (1 << X_WIDTH)) and (Y_SIZE <= (1 << Y_WIDTH)) and | 
|---|
| 563 |            "The X_WIDTH and Y_WIDTH parameter are insufficient"); | 
|---|
| 564 |  | 
|---|
| 565 | #endif | 
|---|
| 566 |  | 
|---|
| 567 |    // index of cluster containing IOs | 
|---|
| 568 |    cluster_io_id = 0x00bfc00000ULL >> (vci_address_width - x_width - y_width); | 
|---|
| 569 |  | 
|---|
| 570 |  | 
|---|
| 571 |    ///////////////////// | 
|---|
| 572 |    //  Mapping Tables | 
|---|
| 573 |    ///////////////////// | 
|---|
| 574 |  | 
|---|
| 575 |    // internal network | 
|---|
| 576 |    MappingTable maptabd(vci_address_width,  | 
|---|
| 577 |                         IntTab(x_width + y_width, 16 - x_width - y_width),  | 
|---|
| 578 |                         IntTab(x_width + y_width, vci_srcid_width - x_width - y_width),  | 
|---|
| 579 |                         0x00FF800000); | 
|---|
| 580 |  | 
|---|
| 581 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 582 |    { | 
|---|
| 583 |       for (size_t y = 0; y < Y_SIZE; y++) | 
|---|
| 584 |       { | 
|---|
| 585 |          sc_uint<vci_address_width> offset; | 
|---|
| 586 |          offset = (sc_uint<vci_address_width>)cluster(x,y)  | 
|---|
| 587 |                    << (vci_address_width-x_width-y_width); | 
|---|
| 588 |  | 
|---|
| 589 |          std::ostringstream    si; | 
|---|
| 590 |          si << "seg_xicu_" << x << "_" << y; | 
|---|
| 591 |          maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE,  | 
|---|
| 592 |                   IntTab(cluster(x,y),XICU_TGTID), false)); | 
|---|
| 593 |  | 
|---|
| 594 |          std::ostringstream    sd; | 
|---|
| 595 |          sd << "seg_mdma_" << x << "_" << y; | 
|---|
| 596 |          maptabd.add(Segment(sd.str(), MDMA_BASE + offset, MDMA_SIZE,  | 
|---|
| 597 |                   IntTab(cluster(x,y),MDMA_TGTID), false)); | 
|---|
| 598 |  | 
|---|
| 599 |          std::ostringstream    sh; | 
|---|
| 600 |          sh << "seg_memc_" << x << "_" << y; | 
|---|
| 601 |          maptabd.add(Segment(sh.str(), MEMC_BASE + offset, MEMC_SIZE,  | 
|---|
| 602 |                   IntTab(cluster(x,y),MEMC_TGTID), true)); | 
|---|
| 603 |  | 
|---|
| 604 |          if ( cluster(x,y) == cluster_io_id ) | 
|---|
| 605 |          { | 
|---|
| 606 |             maptabd.add(Segment("seg_mtty", MTTY_BASE, MTTY_SIZE,  | 
|---|
| 607 |                         IntTab(cluster(x,y),MTTY_TGTID), false)); | 
|---|
| 608 |             maptabd.add(Segment("seg_fbuf", FBUF_BASE, FBUF_SIZE,  | 
|---|
| 609 |                         IntTab(cluster(x,y),FBUF_TGTID), false)); | 
|---|
| 610 |             maptabd.add(Segment("seg_bdev", BDEV_BASE, BDEV_SIZE,  | 
|---|
| 611 |                         IntTab(cluster(x,y),BDEV_TGTID), false)); | 
|---|
| 612 |             maptabd.add(Segment("seg_brom", BROM_BASE, BROM_SIZE,  | 
|---|
| 613 |                         IntTab(cluster(x,y),BROM_TGTID), true)); | 
|---|
| 614 |             maptabd.add(Segment("seg_mnic", MNIC_BASE, MNIC_SIZE,  | 
|---|
| 615 |                         IntTab(cluster(x,y),MNIC_TGTID), false)); | 
|---|
| 616 |             maptabd.add(Segment("seg_cdma", CDMA_BASE, CDMA_SIZE,  | 
|---|
| 617 |                         IntTab(cluster(x,y),CDMA_TGTID), false)); | 
|---|
| 618 |             maptabd.add(Segment("seg_simh", SIMH_BASE, SIMH_SIZE,  | 
|---|
| 619 |                         IntTab(cluster(x,y),SIMH_TGTID), false)); | 
|---|
| 620 |          } | 
|---|
| 621 |       } | 
|---|
| 622 |    } | 
|---|
| 623 |    std::cout << maptabd << std::endl; | 
|---|
| 624 |  | 
|---|
| 625 |    // external network | 
|---|
| 626 |    MappingTable maptabx(vci_address_width,  | 
|---|
| 627 |                         IntTab(x_width+y_width),  | 
|---|
| 628 |                         IntTab(x_width+y_width),  | 
|---|
| 629 |                         0xFFFF000000ULL); | 
|---|
| 630 |  | 
|---|
| 631 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 632 |    { | 
|---|
| 633 |       for (size_t y = 0; y < Y_SIZE ; y++) | 
|---|
| 634 |       { | 
|---|
| 635 |  | 
|---|
| 636 |          sc_uint<vci_address_width> offset; | 
|---|
| 637 |          offset = (sc_uint<vci_address_width>)cluster(x,y)  | 
|---|
| 638 |                    << (vci_address_width-x_width-y_width); | 
|---|
| 639 |  | 
|---|
| 640 |          std::ostringstream sh; | 
|---|
| 641 |          sh << "x_seg_memc_" << x << "_" << y; | 
|---|
| 642 |  | 
|---|
| 643 |          maptabx.add(Segment(sh.str(), MEMC_BASE + offset,  | 
|---|
| 644 |                      MEMC_SIZE, IntTab(cluster(x,y)), false)); | 
|---|
| 645 |       } | 
|---|
| 646 |    } | 
|---|
| 647 |    std::cout << maptabx << std::endl; | 
|---|
| 648 |  | 
|---|
| 649 |    //////////////////// | 
|---|
| 650 |    // Signals | 
|---|
| 651 |    /////////////////// | 
|---|
| 652 |  | 
|---|
| 653 |    sc_clock           signal_clk("clk"); | 
|---|
| 654 |    sc_signal<bool>    signal_resetn("resetn"); | 
|---|
| 655 |  | 
|---|
| 656 |    // Horizontal inter-clusters DSPIN signals | 
|---|
| 657 |    DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_inc = | 
|---|
| 658 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", X_SIZE-1, Y_SIZE, 3); | 
|---|
| 659 |    DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_dec = | 
|---|
| 660 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", X_SIZE-1, Y_SIZE, 3); | 
|---|
| 661 |    DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_inc = | 
|---|
| 662 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", X_SIZE-1, Y_SIZE, 2); | 
|---|
| 663 |    DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_dec = | 
|---|
| 664 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", X_SIZE-1, Y_SIZE, 2); | 
|---|
| 665 |  | 
|---|
| 666 |    // Vertical inter-clusters DSPIN signals | 
|---|
| 667 |    DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_inc = | 
|---|
| 668 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", X_SIZE, Y_SIZE-1, 3); | 
|---|
| 669 |    DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_dec = | 
|---|
| 670 |       alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", X_SIZE, Y_SIZE-1, 3); | 
|---|
| 671 |    DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_inc = | 
|---|
| 672 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", X_SIZE, Y_SIZE-1, 2); | 
|---|
| 673 |    DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_dec = | 
|---|
| 674 |       alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", X_SIZE, Y_SIZE-1, 2); | 
|---|
| 675 |  | 
|---|
| 676 |    // Mesh boundaries DSPIN signals | 
|---|
| 677 |    DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_in = | 
|---|
| 678 |          alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_in" , X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 679 |    DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_out = | 
|---|
| 680 |          alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_out", X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 681 |    DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_in = | 
|---|
| 682 |          alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_in" , X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 683 |    DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_out = | 
|---|
| 684 |          alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_out", X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 685 |  | 
|---|
| 686 |    //////////////////////////// | 
|---|
| 687 |    //      Loader     | 
|---|
| 688 |    //////////////////////////// | 
|---|
| 689 |  | 
|---|
| 690 |    soclib::common::Loader loader(soft_name); | 
|---|
| 691 |  | 
|---|
| 692 |    typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss; | 
|---|
| 693 |    proc_iss::set_loader(loader); | 
|---|
| 694 |  | 
|---|
| 695 |    //////////////////////////// | 
|---|
| 696 |    // Clusters construction | 
|---|
| 697 |    //////////////////////////// | 
|---|
| 698 |  | 
|---|
| 699 |    TsarXbarCluster<dspin_cmd_width, | 
|---|
| 700 |                    dspin_rsp_width, | 
|---|
| 701 |                    vci_param_int, | 
|---|
| 702 |                    vci_param_ext>*          clusters[X_SIZE][Y_SIZE]; | 
|---|
| 703 |  | 
|---|
| 704 | #if USE_OPENMP | 
|---|
| 705 | #pragma omp parallel | 
|---|
| 706 |     { | 
|---|
| 707 | #pragma omp for | 
|---|
| 708 | #endif | 
|---|
| 709 |         for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++) | 
|---|
| 710 |         { | 
|---|
| 711 |             size_t x = i / Y_SIZE; | 
|---|
| 712 |             size_t y = i % Y_SIZE; | 
|---|
| 713 |  | 
|---|
| 714 | #if USE_OPENMP | 
|---|
| 715 | #pragma omp critical | 
|---|
| 716 |             { | 
|---|
| 717 | #endif | 
|---|
| 718 |             std::cout << std::endl; | 
|---|
| 719 |             std::cout << "Cluster_" << x << "_" << y << std::endl; | 
|---|
| 720 |             std::cout << std::endl; | 
|---|
| 721 |  | 
|---|
| 722 |             std::ostringstream sc; | 
|---|
| 723 |             sc << "cluster_" << x << "_" << y; | 
|---|
| 724 |             clusters[x][y] = new TsarXbarCluster<dspin_cmd_width, | 
|---|
| 725 |                                                  dspin_rsp_width, | 
|---|
| 726 |                                                  vci_param_int, | 
|---|
| 727 |                                                  vci_param_ext> | 
|---|
| 728 |             ( | 
|---|
| 729 |                 sc.str().c_str(), | 
|---|
| 730 |                 NB_PROCS_MAX, | 
|---|
| 731 |                 NB_TTY_CHANNELS, | 
|---|
| 732 |                 NB_DMA_CHANNELS, | 
|---|
| 733 |                 x, | 
|---|
| 734 |                 y, | 
|---|
| 735 |                 cluster(x,y), | 
|---|
| 736 |                 maptabd, | 
|---|
| 737 |                 maptabx, | 
|---|
| 738 |                 x_width, | 
|---|
| 739 |                 y_width, | 
|---|
| 740 |                 vci_srcid_width - x_width - y_width,   // l_id width, | 
|---|
| 741 |                 MEMC_TGTID, | 
|---|
| 742 |                 XICU_TGTID, | 
|---|
| 743 |                 MDMA_TGTID, | 
|---|
| 744 |                 FBUF_TGTID, | 
|---|
| 745 |                 MTTY_TGTID, | 
|---|
| 746 |                 BROM_TGTID, | 
|---|
| 747 |                 MNIC_TGTID, | 
|---|
| 748 |                 CDMA_TGTID, | 
|---|
| 749 |                 BDEV_TGTID, | 
|---|
| 750 |                 SIMH_TGTID, | 
|---|
| 751 |                 MEMC_WAYS, | 
|---|
| 752 |                 MEMC_SETS, | 
|---|
| 753 |                 L1_IWAYS, | 
|---|
| 754 |                 L1_ISETS, | 
|---|
| 755 |                 L1_DWAYS, | 
|---|
| 756 |                 L1_DSETS, | 
|---|
| 757 |                 IRQ_PER_PROCESSOR, | 
|---|
| 758 |                 XRAM_LATENCY, | 
|---|
| 759 |                 (cluster(x,y) == cluster_io_id), | 
|---|
| 760 |                 FBUF_X_SIZE, | 
|---|
| 761 |                 FBUF_Y_SIZE, | 
|---|
| 762 |                 disk_name, | 
|---|
| 763 |                 BDEV_SECTOR_SIZE, | 
|---|
| 764 |                 NB_NIC_CHANNELS, | 
|---|
| 765 |                 nic_rx_name, | 
|---|
| 766 |                 nic_tx_name, | 
|---|
| 767 |                 NIC_TIMEOUT, | 
|---|
| 768 |                 NB_CMA_CHANNELS, | 
|---|
| 769 |                 loader, | 
|---|
| 770 |                 frozen_cycles, | 
|---|
| 771 |                 debug_from, | 
|---|
| 772 |                 debug_ok and (cluster(x,y) == debug_memc_id), | 
|---|
| 773 |                 debug_ok and (cluster(x,y) == debug_proc_id) | 
|---|
| 774 |             ); | 
|---|
| 775 |  | 
|---|
| 776 | #if USE_OPENMP | 
|---|
| 777 |             } // end critical | 
|---|
| 778 | #endif | 
|---|
| 779 |         } // end for | 
|---|
| 780 | #if USE_OPENMP | 
|---|
| 781 |     } | 
|---|
| 782 | #endif | 
|---|
| 783 |  | 
|---|
| 784 |    /////////////////////////////////////////////////////////////// | 
|---|
| 785 |    //     Net-list  | 
|---|
| 786 |    /////////////////////////////////////////////////////////////// | 
|---|
| 787 |  | 
|---|
| 788 |    // Clock & RESET | 
|---|
| 789 |    for (size_t x = 0; x < (X_SIZE); x++){ | 
|---|
| 790 |       for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 791 |          clusters[x][y]->p_clk                         (signal_clk); | 
|---|
| 792 |          clusters[x][y]->p_resetn                      (signal_resetn); | 
|---|
| 793 |       } | 
|---|
| 794 |    } | 
|---|
| 795 |  | 
|---|
| 796 |    // Inter Clusters horizontal connections | 
|---|
| 797 |    if (X_SIZE > 1){ | 
|---|
| 798 |       for (size_t x = 0; x < (X_SIZE-1); x++){ | 
|---|
| 799 |          for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 800 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 801 |                clusters[x][y]->p_cmd_out[EAST][k]      (signal_dspin_h_cmd_inc[x][y][k]); | 
|---|
| 802 |                clusters[x+1][y]->p_cmd_in[WEST][k]     (signal_dspin_h_cmd_inc[x][y][k]); | 
|---|
| 803 |                clusters[x][y]->p_cmd_in[EAST][k]       (signal_dspin_h_cmd_dec[x][y][k]); | 
|---|
| 804 |                clusters[x+1][y]->p_cmd_out[WEST][k]    (signal_dspin_h_cmd_dec[x][y][k]); | 
|---|
| 805 |             } | 
|---|
| 806 |  | 
|---|
| 807 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 808 |                clusters[x][y]->p_rsp_out[EAST][k]      (signal_dspin_h_rsp_inc[x][y][k]); | 
|---|
| 809 |                clusters[x+1][y]->p_rsp_in[WEST][k]     (signal_dspin_h_rsp_inc[x][y][k]); | 
|---|
| 810 |                clusters[x][y]->p_rsp_in[EAST][k]       (signal_dspin_h_rsp_dec[x][y][k]); | 
|---|
| 811 |                clusters[x+1][y]->p_rsp_out[WEST][k]    (signal_dspin_h_rsp_dec[x][y][k]); | 
|---|
| 812 |             } | 
|---|
| 813 |          } | 
|---|
| 814 |       } | 
|---|
| 815 |    } | 
|---|
| 816 |    std::cout << std::endl << "Horizontal connections established" << std::endl; | 
|---|
| 817 |  | 
|---|
| 818 |    // Inter Clusters vertical connections | 
|---|
| 819 |    if (Y_SIZE > 1) { | 
|---|
| 820 |       for (size_t y = 0; y < (Y_SIZE-1); y++){ | 
|---|
| 821 |          for (size_t x = 0; x < X_SIZE; x++){ | 
|---|
| 822 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 823 |                clusters[x][y]->p_cmd_out[NORTH][k]     (signal_dspin_v_cmd_inc[x][y][k]); | 
|---|
| 824 |                clusters[x][y+1]->p_cmd_in[SOUTH][k]    (signal_dspin_v_cmd_inc[x][y][k]); | 
|---|
| 825 |                clusters[x][y]->p_cmd_in[NORTH][k]      (signal_dspin_v_cmd_dec[x][y][k]); | 
|---|
| 826 |                clusters[x][y+1]->p_cmd_out[SOUTH][k]   (signal_dspin_v_cmd_dec[x][y][k]); | 
|---|
| 827 |             } | 
|---|
| 828 |  | 
|---|
| 829 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 830 |                clusters[x][y]->p_rsp_out[NORTH][k]     (signal_dspin_v_rsp_inc[x][y][k]); | 
|---|
| 831 |                clusters[x][y+1]->p_rsp_in[SOUTH][k]    (signal_dspin_v_rsp_inc[x][y][k]); | 
|---|
| 832 |                clusters[x][y]->p_rsp_in[NORTH][k]      (signal_dspin_v_rsp_dec[x][y][k]); | 
|---|
| 833 |                clusters[x][y+1]->p_rsp_out[SOUTH][k]   (signal_dspin_v_rsp_dec[x][y][k]); | 
|---|
| 834 |             } | 
|---|
| 835 |          } | 
|---|
| 836 |       } | 
|---|
| 837 |    } | 
|---|
| 838 |    std::cout << "Vertical connections established" << std::endl; | 
|---|
| 839 |  | 
|---|
| 840 |    // East & West boundary cluster connections | 
|---|
| 841 |    for (size_t y = 0; y < Y_SIZE; y++) | 
|---|
| 842 |    { | 
|---|
| 843 |       for (size_t k = 0; k < 3; k++) | 
|---|
| 844 |       { | 
|---|
| 845 |          clusters[0][y]->p_cmd_in[WEST][k]        (signal_dspin_false_cmd_in [0][y][WEST][k]); | 
|---|
| 846 |          clusters[0][y]->p_cmd_out[WEST][k]       (signal_dspin_false_cmd_out[0][y][WEST][k]); | 
|---|
| 847 |          clusters[X_SIZE-1][y]->p_cmd_in[EAST][k] (signal_dspin_false_cmd_in [X_SIZE-1][y][EAST][k]); | 
|---|
| 848 |          clusters[X_SIZE-1][y]->p_cmd_out[EAST][k](signal_dspin_false_cmd_out[X_SIZE-1][y][EAST][k]); | 
|---|
| 849 |       } | 
|---|
| 850 |  | 
|---|
| 851 |       for (size_t k = 0; k < 2; k++) | 
|---|
| 852 |       { | 
|---|
| 853 |          clusters[0][y]->p_rsp_in[WEST][k]        (signal_dspin_false_rsp_in [0][y][WEST][k]); | 
|---|
| 854 |          clusters[0][y]->p_rsp_out[WEST][k]       (signal_dspin_false_rsp_out[0][y][WEST][k]); | 
|---|
| 855 |          clusters[X_SIZE-1][y]->p_rsp_in[EAST][k] (signal_dspin_false_rsp_in [X_SIZE-1][y][EAST][k]); | 
|---|
| 856 |          clusters[X_SIZE-1][y]->p_rsp_out[EAST][k](signal_dspin_false_rsp_out[X_SIZE-1][y][EAST][k]); | 
|---|
| 857 |       } | 
|---|
| 858 |    } | 
|---|
| 859 |  | 
|---|
| 860 |    // North & South boundary clusters connections | 
|---|
| 861 |    for (size_t x = 0; x < X_SIZE; x++) | 
|---|
| 862 |    { | 
|---|
| 863 |       for (size_t k = 0; k < 3; k++) | 
|---|
| 864 |       { | 
|---|
| 865 |          clusters[x][0]->p_cmd_in[SOUTH][k]        (signal_dspin_false_cmd_in [x][0][SOUTH][k]); | 
|---|
| 866 |          clusters[x][0]->p_cmd_out[SOUTH][k]       (signal_dspin_false_cmd_out[x][0][SOUTH][k]); | 
|---|
| 867 |          clusters[x][Y_SIZE-1]->p_cmd_in[NORTH][k] (signal_dspin_false_cmd_in [x][Y_SIZE-1][NORTH][k]); | 
|---|
| 868 |          clusters[x][Y_SIZE-1]->p_cmd_out[NORTH][k](signal_dspin_false_cmd_out[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 869 |       } | 
|---|
| 870 |  | 
|---|
| 871 |       for (size_t k = 0; k < 2; k++) | 
|---|
| 872 |       { | 
|---|
| 873 |          clusters[x][0]->p_rsp_in[SOUTH][k]        (signal_dspin_false_rsp_in [x][0][SOUTH][k]); | 
|---|
| 874 |          clusters[x][0]->p_rsp_out[SOUTH][k]       (signal_dspin_false_rsp_out[x][0][SOUTH][k]); | 
|---|
| 875 |          clusters[x][Y_SIZE-1]->p_rsp_in[NORTH][k] (signal_dspin_false_rsp_in [x][Y_SIZE-1][NORTH][k]); | 
|---|
| 876 |          clusters[x][Y_SIZE-1]->p_rsp_out[NORTH][k](signal_dspin_false_rsp_out[x][Y_SIZE-1][NORTH][k]); | 
|---|
| 877 |       } | 
|---|
| 878 |    } | 
|---|
| 879 |    std::cout << "North, South, West, East connections established" << std::endl; | 
|---|
| 880 |    std::cout << std::endl; | 
|---|
| 881 |  | 
|---|
| 882 |  | 
|---|
| 883 |    //////////////////////////////////////////////////////// | 
|---|
| 884 |    //   Simulation | 
|---|
| 885 |    /////////////////////////////////////////////////////// | 
|---|
| 886 |  | 
|---|
| 887 |    sc_start(sc_core::sc_time(0, SC_NS)); | 
|---|
| 888 |    signal_resetn = false; | 
|---|
| 889 |  | 
|---|
| 890 |    // network boundaries signals | 
|---|
| 891 |    for (size_t x = 0; x < X_SIZE ; x++){ | 
|---|
| 892 |       for (size_t y = 0; y < Y_SIZE ; y++){ | 
|---|
| 893 |          for (size_t a = 0; a < 4; a++){ | 
|---|
| 894 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 895 |                signal_dspin_false_cmd_in [x][y][a][k].write = false; | 
|---|
| 896 |                signal_dspin_false_cmd_in [x][y][a][k].read  = true; | 
|---|
| 897 |                signal_dspin_false_cmd_out[x][y][a][k].write = false; | 
|---|
| 898 |                signal_dspin_false_cmd_out[x][y][a][k].read  = true; | 
|---|
| 899 |             } | 
|---|
| 900 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 901 |                signal_dspin_false_rsp_in [x][y][a][k].write = false; | 
|---|
| 902 |                signal_dspin_false_rsp_in [x][y][a][k].read  = true; | 
|---|
| 903 |                signal_dspin_false_rsp_out[x][y][a][k].write = false; | 
|---|
| 904 |                signal_dspin_false_rsp_out[x][y][a][k].read  = true; | 
|---|
| 905 |             } | 
|---|
| 906 |          } | 
|---|
| 907 |       } | 
|---|
| 908 |    } | 
|---|
| 909 |  | 
|---|
| 910 |    sc_start(sc_core::sc_time(1, SC_NS)); | 
|---|
| 911 |    signal_resetn = true; | 
|---|
| 912 |  | 
|---|
| 913 | #define SC_TRACE | 
|---|
| 914 | #ifdef SC_TRACE | 
|---|
| 915 |    sc_trace_file * tf = sc_create_vcd_trace_file("my_trace_file"); | 
|---|
| 916 |  | 
|---|
| 917 |    if (X_SIZE > 1){ | 
|---|
| 918 |       for (size_t x = 0; x < (X_SIZE-1); x++){ | 
|---|
| 919 |          for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 920 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 921 |                signal_dspin_h_cmd_inc[x][y][k].trace(tf, "dspin_h_cmd_inc"); | 
|---|
| 922 |                signal_dspin_h_cmd_dec[x][y][k].trace(tf, "dspin_h_cmd_dec"); | 
|---|
| 923 |             } | 
|---|
| 924 |  | 
|---|
| 925 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 926 |                signal_dspin_h_rsp_inc[x][y][k].trace(tf, "dspin_h_rsp_inc"); | 
|---|
| 927 |                signal_dspin_h_rsp_dec[x][y][k].trace(tf, "dspin_h_rsp_dec"); | 
|---|
| 928 |             } | 
|---|
| 929 |          } | 
|---|
| 930 |       } | 
|---|
| 931 |    } | 
|---|
| 932 |  | 
|---|
| 933 |    if (Y_SIZE > 1) { | 
|---|
| 934 |       for (size_t y = 0; y < (Y_SIZE-1); y++){ | 
|---|
| 935 |          for (size_t x = 0; x < X_SIZE; x++){ | 
|---|
| 936 |             for (size_t k = 0; k < 3; k++){ | 
|---|
| 937 |                signal_dspin_v_cmd_inc[x][y][k].trace(tf, "dspin_v_cmd_inc"); | 
|---|
| 938 |                signal_dspin_v_cmd_dec[x][y][k].trace(tf, "dspin_v_cmd_dec"); | 
|---|
| 939 |             } | 
|---|
| 940 |  | 
|---|
| 941 |             for (size_t k = 0; k < 2; k++){ | 
|---|
| 942 |                signal_dspin_v_rsp_inc[x][y][k].trace(tf, "dspin_v_rsp_inc"); | 
|---|
| 943 |                signal_dspin_v_rsp_dec[x][y][k].trace(tf, "dspin_v_rsp_dec"); | 
|---|
| 944 |             } | 
|---|
| 945 |          } | 
|---|
| 946 |       } | 
|---|
| 947 |    } | 
|---|
| 948 |  | 
|---|
| 949 |    for (size_t x = 0; x < (X_SIZE); x++){ | 
|---|
| 950 |       for (size_t y = 0; y < Y_SIZE; y++){ | 
|---|
| 951 |          std::ostringstream signame; | 
|---|
| 952 |          signame << "cluster" << x << "_" << y; | 
|---|
| 953 |          clusters[x][y]->trace(tf, signame.str()); | 
|---|
| 954 |       } | 
|---|
| 955 |    } | 
|---|
| 956 | #endif | 
|---|
| 957 |  | 
|---|
| 958 |    if (debug_ok) { | 
|---|
| 959 |       #if USE_OPENMP | 
|---|
| 960 |          assert(false && "OPEN MP should not be used with debug because of its traces"); | 
|---|
| 961 |       #endif | 
|---|
| 962 |  | 
|---|
| 963 |       if (gettimeofday(&t1, NULL) != 0) { | 
|---|
| 964 |          perror("gettimeofday"); | 
|---|
| 965 |          return EXIT_FAILURE; | 
|---|
| 966 |       } | 
|---|
| 967 |  | 
|---|
| 968 |       for (int64_t n = 1; n < ncycles && !stop_called; n++) | 
|---|
| 969 |       { | 
|---|
| 970 |          // Monitor a specific address for L1 & L2 caches | 
|---|
| 971 |          //clusters[0][0]->proc[0]->cache_monitor(0x800002c000ULL); | 
|---|
| 972 |          //clusters[1][0]->memc->copies_monitor(0x800002C000ULL); | 
|---|
| 973 |  | 
|---|
| 974 |          if ((n % max_cycles) == 0) | 
|---|
| 975 |          { | 
|---|
| 976 |  | 
|---|
| 977 |             if (gettimeofday(&t2, NULL) != 0) | 
|---|
| 978 |             { | 
|---|
| 979 |                perror("gettimeofday"); | 
|---|
| 980 |                return EXIT_FAILURE; | 
|---|
| 981 |             } | 
|---|
| 982 |  | 
|---|
| 983 |             ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000; | 
|---|
| 984 |             ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000; | 
|---|
| 985 |             std::cerr << "platform clock frequency " << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl; | 
|---|
| 986 |  | 
|---|
| 987 |             if (gettimeofday(&t1, NULL) != 0) | 
|---|
| 988 |             { | 
|---|
| 989 |                perror("gettimeofday"); | 
|---|
| 990 |                return EXIT_FAILURE; | 
|---|
| 991 |             } | 
|---|
| 992 |          } | 
|---|
| 993 |  | 
|---|
| 994 |  | 
|---|
| 995 |          if (n == reset_counters) { | 
|---|
| 996 |             for (size_t x = 0; x < (X_SIZE); x++) { | 
|---|
| 997 |                for (size_t y = 0; y < Y_SIZE; y++) { | 
|---|
| 998 |                   clusters[x][y]->memc->reset_counters(); | 
|---|
| 999 |                } | 
|---|
| 1000 |             } | 
|---|
| 1001 |          } | 
|---|
| 1002 |  | 
|---|
| 1003 |          if (n == dump_counters) { | 
|---|
| 1004 |             for (size_t x = 0; x < (X_SIZE); x++) { | 
|---|
| 1005 |                for (size_t y = 0; y < Y_SIZE; y++) { | 
|---|
| 1006 |                   clusters[x][y]->memc->print_stats(true, false); | 
|---|
| 1007 |                } | 
|---|
| 1008 |             } | 
|---|
| 1009 |          } | 
|---|
| 1010 |  | 
|---|
| 1011 |          if ((n > debug_from) and (n % debug_period == 0)) | 
|---|
| 1012 |          { | 
|---|
| 1013 |             std::cout << "****************** cycle " << std::dec << n ; | 
|---|
| 1014 |             std::cout << " ************************************************" << std::endl; | 
|---|
| 1015 |  | 
|---|
| 1016 |             // trace proc[debug_proc_id] | 
|---|
| 1017 |             size_t l = debug_proc_id % NB_PROCS_MAX ; | 
|---|
| 1018 |             size_t y = (debug_proc_id / NB_PROCS_MAX) % Y_SIZE ; | 
|---|
| 1019 |             size_t x = debug_proc_id / (Y_SIZE * NB_PROCS_MAX) ; | 
|---|
| 1020 |  | 
|---|
| 1021 |             std::ostringstream proc_signame; | 
|---|
| 1022 |             proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ; | 
|---|
| 1023 |             std::ostringstream p2m_signame; | 
|---|
| 1024 |             p2m_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " P2M" ; | 
|---|
| 1025 |             std::ostringstream m2p_signame; | 
|---|
| 1026 |             m2p_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " M2P" ; | 
|---|
| 1027 |  | 
|---|
| 1028 |             //clusters[x][y]->signal_vci_ini_proc[l].print_trace(proc_signame.str()); | 
|---|
| 1029 |             //clusters[x][y]->signal_dspin_p2m_proc[l].print_trace(p2m_signame.str()); | 
|---|
| 1030 |             //clusters[x][y]->signal_dspin_m2p_proc[l].print_trace(m2p_signame.str()); | 
|---|
| 1031 |  | 
|---|
| 1032 |             //clusters[x][y]->signal_dspin_cmd_l2g_d.print_trace("[SIG]L2G CMD"); | 
|---|
| 1033 |             //clusters[x][y]->signal_dspin_cmd_g2l_d.print_trace("[SIG]G2L CMD"); | 
|---|
| 1034 |             //clusters[x][y]->signal_dspin_rsp_l2g_d.print_trace("[SIG]L2G RSP"); | 
|---|
| 1035 |             //clusters[x][y]->signal_dspin_rsp_g2l_d.print_trace("[SIG]G2L RSP"); | 
|---|
| 1036 |  | 
|---|
| 1037 |             // trace memc[debug_memc_id] | 
|---|
| 1038 |             x = debug_memc_id / Y_SIZE; | 
|---|
| 1039 |             y = debug_memc_id % Y_SIZE; | 
|---|
| 1040 |  | 
|---|
| 1041 |             std::ostringstream smemc; | 
|---|
| 1042 |             smemc << "[SIG]MEMC_" << x << "_" << y; | 
|---|
| 1043 |             std::ostringstream sxram; | 
|---|
| 1044 |             sxram << "[SIG]XRAM_" << x << "_" << y; | 
|---|
| 1045 |             std::ostringstream sm2p; | 
|---|
| 1046 |             sm2p << "[SIG]MEMC_" << x << "_" << y << " M2P" ; | 
|---|
| 1047 |             std::ostringstream sp2m; | 
|---|
| 1048 |             sp2m << "[SIG]MEMC_" << x << "_" << y << " P2M" ; | 
|---|
| 1049 |  | 
|---|
| 1050 |             //clusters[x][y]->memc->print_trace(); | 
|---|
| 1051 |             //clusters[x][y]->signal_vci_tgt_memc.print_trace(smemc.str()); | 
|---|
| 1052 |             //clusters[x][y]->signal_vci_xram.print_trace(sxram.str()); | 
|---|
| 1053 |             //clusters[x][y]->signal_dspin_p2m_memc.print_trace(sp2m.str()); | 
|---|
| 1054 |             //clusters[x][y]->signal_dspin_m2p_memc.print_trace(sm2p.str()); | 
|---|
| 1055 |  | 
|---|
| 1056 |             // trace replicated peripherals | 
|---|
| 1057 |             //clusters[1][1]->mdma->print_trace(); | 
|---|
| 1058 |             //clusters[1][1]->signal_vci_tgt_mdma.print_trace("[SIG]MDMA_TGT_1_1"); | 
|---|
| 1059 |             //clusters[1][1]->signal_vci_ini_mdma.print_trace("[SIG]MDMA_INI_1_1"); | 
|---|
| 1060 |  | 
|---|
| 1061 |  | 
|---|
| 1062 |             // trace external peripherals | 
|---|
| 1063 |             //size_t io_x   = cluster_io_id / Y_SIZE; | 
|---|
| 1064 |             //size_t io_y   = cluster_io_id % Y_SIZE; | 
|---|
| 1065 |  | 
|---|
| 1066 |             //clusters[io_x][io_y]->brom->print_trace(); | 
|---|
| 1067 |             //clusters[io_x][io_y]->signal_vci_tgt_brom.print_trace("[SIG]BROM"); | 
|---|
| 1068 |  | 
|---|
| 1069 |             //clusters[io_x][io_y]->bdev->print_trace(); | 
|---|
| 1070 |             //clusters[io_x][io_y]->signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT"); | 
|---|
| 1071 |             //clusters[io_x][io_y]->signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI"); | 
|---|
| 1072 |          } | 
|---|
| 1073 |  | 
|---|
| 1074 |          sc_start(sc_core::sc_time(1, SC_NS)); | 
|---|
| 1075 |       } | 
|---|
| 1076 |    } | 
|---|
| 1077 |    else { | 
|---|
| 1078 |       int64_t n = 0; | 
|---|
| 1079 |       while (!stop_called && n != ncycles) { | 
|---|
| 1080 |          if (gettimeofday(&t1, NULL) != 0) { | 
|---|
| 1081 |             perror("gettimeofday"); | 
|---|
| 1082 |             return EXIT_FAILURE; | 
|---|
| 1083 |          } | 
|---|
| 1084 |          int64_t nb_cycles = min(max_cycles, ncycles - n); | 
|---|
| 1085 |          if (do_reset_counters) { | 
|---|
| 1086 |             nb_cycles = min(nb_cycles, reset_counters - n); | 
|---|
| 1087 |          } | 
|---|
| 1088 |          if (do_dump_counters) { | 
|---|
| 1089 |             nb_cycles = min(nb_cycles, dump_counters - n); | 
|---|
| 1090 |          } | 
|---|
| 1091 |  | 
|---|
| 1092 |          sc_start(sc_core::sc_time(nb_cycles, SC_NS)); | 
|---|
| 1093 |          n += nb_cycles; | 
|---|
| 1094 |  | 
|---|
| 1095 |          if (do_reset_counters && n == reset_counters) { | 
|---|
| 1096 |             // Reseting counters | 
|---|
| 1097 |             for (size_t x = 0; x < (X_SIZE); x++) { | 
|---|
| 1098 |                for (size_t y = 0; y < Y_SIZE; y++) { | 
|---|
| 1099 |                   clusters[x][y]->memc->reset_counters(); | 
|---|
| 1100 |                } | 
|---|
| 1101 |             } | 
|---|
| 1102 |             do_reset_counters = false; | 
|---|
| 1103 |          } | 
|---|
| 1104 |  | 
|---|
| 1105 |          if (do_dump_counters && n == dump_counters) { | 
|---|
| 1106 |             // Dumping counters | 
|---|
| 1107 |             for (size_t x = 0; x < (X_SIZE); x++) { | 
|---|
| 1108 |                for (size_t y = 0; y < Y_SIZE; y++) { | 
|---|
| 1109 |                   clusters[x][y]->memc->print_stats(true, false); | 
|---|
| 1110 |                } | 
|---|
| 1111 |             } | 
|---|
| 1112 |             do_dump_counters = false; | 
|---|
| 1113 |          } | 
|---|
| 1114 |  | 
|---|
| 1115 |  | 
|---|
| 1116 |          if (gettimeofday(&t2, NULL) != 0) { | 
|---|
| 1117 |             perror("gettimeofday"); | 
|---|
| 1118 |             return EXIT_FAILURE; | 
|---|
| 1119 |          } | 
|---|
| 1120 |          ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000; | 
|---|
| 1121 |          ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000; | 
|---|
| 1122 |          std::cerr << std::dec << "cycle " << n << " platform clock frequency " << (double) nb_cycles / (double) (ms2 - ms1) << "Khz" << std::endl; | 
|---|
| 1123 |       } | 
|---|
| 1124 |    } | 
|---|
| 1125 |  | 
|---|
| 1126 |     | 
|---|
| 1127 |    // Free memory | 
|---|
| 1128 |    for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++) | 
|---|
| 1129 |    { | 
|---|
| 1130 |       size_t x = i / Y_SIZE; | 
|---|
| 1131 |       size_t y = i % Y_SIZE; | 
|---|
| 1132 |       delete clusters[x][y]; | 
|---|
| 1133 |    } | 
|---|
| 1134 |  | 
|---|
| 1135 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_inc, X_SIZE - 1, Y_SIZE, 3); | 
|---|
| 1136 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_dec, X_SIZE - 1, Y_SIZE, 3); | 
|---|
| 1137 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_inc, X_SIZE - 1, Y_SIZE, 2); | 
|---|
| 1138 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_dec, X_SIZE - 1, Y_SIZE, 2); | 
|---|
| 1139 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_inc, X_SIZE, Y_SIZE - 1, 3); | 
|---|
| 1140 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_dec, X_SIZE, Y_SIZE - 1, 3); | 
|---|
| 1141 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_inc, X_SIZE, Y_SIZE - 1, 2); | 
|---|
| 1142 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_dec, X_SIZE, Y_SIZE - 1, 2); | 
|---|
| 1143 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_in, X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 1144 |    dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_out, X_SIZE, Y_SIZE, 4, 3); | 
|---|
| 1145 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_in, X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 1146 |    dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_out, X_SIZE, Y_SIZE, 4, 2); | 
|---|
| 1147 |  | 
|---|
| 1148 |    return EXIT_SUCCESS; | 
|---|
| 1149 | } | 
|---|
| 1150 |  | 
|---|
| 1151 |  | 
|---|
| 1152 | void handler(int dummy = 0) { | 
|---|
| 1153 |    stop_called = true; | 
|---|
| 1154 |    sc_stop(); | 
|---|
| 1155 | } | 
|---|
| 1156 |  | 
|---|
| 1157 | void voidhandler(int dummy = 0) {} | 
|---|
| 1158 |  | 
|---|
| 1159 | int sc_main (int argc, char *argv[]) | 
|---|
| 1160 | { | 
|---|
| 1161 |    signal(SIGINT, handler); | 
|---|
| 1162 |    signal(SIGPIPE, voidhandler); | 
|---|
| 1163 |  | 
|---|
| 1164 |    try { | 
|---|
| 1165 |       return _main(argc, argv); | 
|---|
| 1166 |    } catch (std::exception &e) { | 
|---|
| 1167 |       std::cout << e.what() << std::endl; | 
|---|
| 1168 |    } catch (...) { | 
|---|
| 1169 |       std::cout << "Unknown exception occured" << std::endl; | 
|---|
| 1170 |       throw; | 
|---|
| 1171 |    } | 
|---|
| 1172 |    return 1; | 
|---|
| 1173 | } | 
|---|
| 1174 |  | 
|---|
| 1175 |  | 
|---|
| 1176 | // Local Variables: | 
|---|
| 1177 | // tab-width: 3 | 
|---|
| 1178 | // c-basic-offset: 3 | 
|---|
| 1179 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
| 1180 | // indent-tabs-mode: nil | 
|---|
| 1181 | // End: | 
|---|
| 1182 |  | 
|---|
| 1183 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 | 
|---|