source: trunk/platforms/almos-tsar-mipsel/top.cpp @ 609

Last change on this file since 609 was 609, checked in by almaless, 10 years ago

Introduce a TSAR reference platform for ALMOS

File size: 37.2 KB
Line 
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 "tsar_xbar_cluster.h"
94#include "alloc_elems.h"
95
96///////////////////////////////////////////////////
97//               Parallelisation
98///////////////////////////////////////////////////
99#if USE_OPENMP
100#include <omp.h>
101#endif
102
103//  cluster index (computed from x,y coordinates)
104#define cluster(x,y)   (y + ymax * x)
105
106#define min(x, y) (x < y ? x : y)
107
108///////////////////////////////////////////////////////////
109//          DSPIN parameters           
110///////////////////////////////////////////////////////////
111#define dspin_cmd_width      39
112#define dspin_rsp_width      32
113
114///////////////////////////////////////////////////////////
115//          VCI parameters           
116///////////////////////////////////////////////////////////
117#define vci_cell_width_int    4
118#define vci_cell_width_ext    8
119#define vci_address_width     32
120#define vci_plen_width        8
121#define vci_rerror_width      1
122#define vci_clen_width        1
123#define vci_rflag_width       1
124#define vci_srcid_width       14
125#define vci_pktid_width       4
126#define vci_trdid_width       4
127#define vci_wrplen_width      1
128
129////////////////////////////////////////////////////////////
130//    Main Hardware Parameters values         
131////////////////////////////////////////////////////////////
132#define CLUSTER_X             1
133#define CLUSTER_Y             1
134#define NB_CLUSTERS           1
135#define NB_PROCS_MAX          4
136#define NB_DMA_CHANNELS       1
137#define NB_TTY_CHANNELS       4
138#define NB_IOC_CHANNELS       1
139#define NB_NIC_CHANNELS       1
140#define NB_CMA_CHANNELS       0
141#define USE_XICU              1
142#define IOMMU_ACTIVE          0
143
144////////////////////////////////////////////////////////////
145//    Secondary Hardware Parameters         
146////////////////////////////////////////////////////////////
147#define XRAM_LATENCY          0
148
149#define MEMC_WAYS             16
150#define MEMC_SETS             256
151
152#define L1_IWAYS              4
153#define L1_ISETS              64
154#define L1_DWAYS              4
155#define L1_DSETS              64
156
157#define FBUF_X_SIZE           512
158#define FBUF_Y_SIZE           512
159
160#define BDEV_SECTOR_SIZE      4096
161#define BDEV_IMAGE_NAME       "hdd-img.bin"
162
163#define NIC_RX_NAME           "rx_packets.txt"
164#define NIC_TX_NAME           "tx_packets.txt"
165#define NIC_TIMEOUT           10000
166
167#define NORTH                 0
168#define SOUTH                 1
169#define EAST                  2
170#define WEST                  3
171
172////////////////////////////////////////////////////////////
173//    Software to be loaded in ROM/RAM         
174////////////////////////////////////////////////////////////
175#define soft_name       "bootloader.bin",\
176                        "kernel-soclib.bin@0xbfc10000:D",\
177                        "arch-info.bin@0xBFC08000:D"
178
179////////////////////////////////////////////////////////////
180//     DEBUG Parameters default values         
181////////////////////////////////////////////////////////////
182#define MAX_FROZEN_CYCLES     100000000
183
184////////////////////////////////////////////////////////////////////
185//     TGTID definition in direct space
186// For all components:  global TGTID = global SRCID = cluster_index
187////////////////////////////////////////////////////////////////////
188#define MEMC_TGTID      0
189#define XICU_TGTID      1
190#define MDMA_TGTID      2
191#define MTTY_TGTID      3
192#define FBUF_TGTID      4
193#define BDEV_TGTID      5
194#define MNIC_TGTID      6
195#define BROM_TGTID      7
196#define CDMA_TGTID      8
197#define SIMH_TGTID      9
198
199/////////////////////////////////////////////////////////
200//    Physical segments definition
201/////////////////////////////////////////////////////////
202// There is 3 segments replicated in all clusters
203// and 5 specific segments in the "IO" cluster
204// (containing address 0xBF000000)
205/////////////////////////////////////////////////////////
206// Physical Address Decoding: 8 GID + 8 LID + 16 offset.
207/////////////////////////////////////////////////////////
208#define RAM_BASE        0x00000000     
209#define RAM_SIZE        0x00C00000
210
211#define BROM_BASE       0xBFC00000     
212#define BROM_SIZE       0x00100000
213
214#define FBUF_BASE       0xBFD00000     
215#define FBUF_SIZE       0x00200000
216
217#define XICU_BASE       0x00F00000     
218#define XICU_SIZE       0x00002000
219
220#define BDEV_BASE       0xBFF10000
221#define BDEV_SIZE       0x00000100
222
223#define MTTY_BASE       0xBFF20000     
224#define MTTY_SIZE       0x00000100
225
226#define MDMA_BASE       0x00F30000
227#define MDMA_SIZE       0x00001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel
228
229#define MEMC_BASE       0x00F40000     
230#define MEMC_SIZE       0x00001000
231
232#define SIMH_BASE       0xBFF50000
233#define SIMH_SIZE       0x00001000
234
235#define CDMA_BASE       0xBFF60000     
236#define CDMA_SIZE       0x00000100
237
238#define MNIC_BASE       0xB0F80000
239#define MNIC_SIZE       0x00080000   // 512 Kbytes (for 8 channels)
240
241bool stop_called = false;
242
243/////////////////////////////////
244int _main(int argc, char *argv[])
245{
246   using namespace sc_core;
247   using namespace soclib::caba;
248   using namespace soclib::common;
249
250   uint64_t ncycles          = 0xFFFFFFFFFFFFFFFF; // simulated cycles
251   char     disk_name[256]   = BDEV_IMAGE_NAME;    // pathname to the disk image
252   char     nic_rx_name[256] = NIC_RX_NAME;        // pathname to the rx packets file
253   char     nic_tx_name[256] = NIC_TX_NAME;        // pathname to the tx packets file
254   ssize_t  threads_nr       = 1;                  // simulator's threads number
255   bool     debug_ok         = false;              // trace activated
256   size_t   debug_period     = 1;                  // trace period
257   size_t   debug_memc_id    = 0;                  // index of memc to be traced
258   size_t   debug_proc_id    = 0;                  // index of proc to be traced
259   uint32_t debug_from       = 0;                  // trace start cycle
260   uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;  // monitoring frozen processor
261   size_t   xmax             = CLUSTER_X;          // number of clusters in a row
262   size_t   ymax             = CLUSTER_Y;          // number of clusters in a column
263   size_t   nprocs           = NB_PROCS_MAX;               // number of processors per cluster
264   size_t   xfb              = FBUF_X_SIZE;           // frameBuffer column number
265   size_t   yfb              = FBUF_Y_SIZE;        // frameBuffer lines number
266   size_t   fb_mode          = 420;
267   size_t   memc_size        = RAM_SIZE;
268   size_t   blk_size         = BDEV_SECTOR_SIZE;
269   size_t   l1_i_ways        = L1_IWAYS;
270   size_t   l1_d_ways        = L1_DWAYS;
271   size_t   l1_i_sets        = L1_ISETS;
272   size_t   l1_d_sets        = L1_DSETS;
273   size_t   memc_sets        = MEMC_SETS;
274   size_t   memc_ways        = MEMC_WAYS;
275   size_t   xram_latency     = XRAM_LATENCY;
276   size_t   cluster_io_id;                         // index of cluster containing IOs
277   struct   timeval t1,t2;
278   uint64_t ms1,ms2;
279
280   ////////////// command line arguments //////////////////////
281   if (argc > 1)
282   {
283      for (int n = 1; n < argc; n = n + 2)
284      {
285         if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc))
286         {
287            ncycles = atoi(argv[n + 1]);
288         }
289         else if( (strcmp(argv[n],"-NPROCS") == 0) && (n+1<argc) )
290         {
291            nprocs = atoi(argv[n+1]);
292            assert( ((nprocs == 1) || (nprocs == 2) || (nprocs == 4)) &&
293                    "NPROCS must be equal to 1, 2, or 4");
294         }
295         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc))
296         {
297            threads_nr = atoi(argv[n + 1]);
298            threads_nr = (threads_nr < 1) ? 1 : threads_nr;
299         }
300         else if( (strcmp(argv[n],"-XMAX") == 0) && (n+1<argc) )
301         {
302            xmax = atoi(argv[n+1]);
303            assert( ((xmax == 1) || (xmax == 2) || (xmax == 4) || (xmax == 8) || (xmax == 16)) 
304                         && "The XMAX parameter must be 2, 4, 8, or 16" );
305         }
306         else if( (strcmp(argv[n],"-YMAX") == 0) && (n+1<argc) )
307         {
308            ymax = atoi(argv[n+1]);
309            assert( ((ymax == 1) || (ymax == 2) || (ymax == 4) || (ymax == 8) || (ymax == 16)) 
310                         && "The YMAX parameter must be 2, 4, 8, or 16" );
311         }
312         else if((strcmp(argv[n], "-MEMSZ") == 0) && (n+1 < argc))
313         {
314            memc_size = atoi(argv[n+1]);
315         }
316         else if((strcmp(argv[n], "-MCWAYS") == 0) && (n+1 < argc))
317         {
318            memc_ways = atoi(argv[n+1]);
319         }
320         else if((strcmp(argv[n], "-MCSETS") == 0) && (n+1 < argc))
321         {
322            memc_sets = atoi(argv[n+1]);
323         }
324         else if((strcmp(argv[n], "-L1_IWAYS") == 0) && (n+1 < argc))
325         {
326            l1_i_ways = atoi(argv[n+1]);
327         }
328         else if((strcmp(argv[n], "-L1_ISETS") == 0) && (n+1 < argc))
329              {
330            l1_i_sets = atoi(argv[n+1]);
331         }
332         else if((strcmp(argv[n], "-L1_DWAYS") == 0) && (n+1 < argc))
333              {
334            l1_d_ways = atoi(argv[n+1]);
335         }
336         else if((strcmp(argv[n], "-L1_DSETS") == 0) && (n+1 < argc))
337              {
338            l1_d_sets = atoi(argv[n+1]);
339         }
340         else if((strcmp(argv[n], "-XLATENCY") == 0) && (n+1 < argc))
341              {
342            xram_latency = atoi(argv[n+1]);
343         }
344         else if( (strcmp(argv[n],"-XFB") == 0) && (n+1<argc) )
345         {
346            xfb = atoi(argv[n+1]);
347         }
348         else if( (strcmp(argv[n],"-YFB") == 0) && (n+1<argc) )
349         {
350            yfb = atoi(argv[n+1]);
351         }
352         else if( (strcmp(argv[n], "-FBMODE") == 0) && (n+1 < argc))
353         {
354            fb_mode = atoi(argv[n+1]);
355         }
356         else if ((strcmp(argv[n], "-SOFT") == 0) && (n + 1 < argc))
357         {
358            std::cerr << "Warning: -SOFT is useless when using Almos, ignored" << std::endl;
359         }
360         else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc))
361         {
362            strcpy(disk_name, argv[n + 1]);
363         }
364         else if( (strcmp(argv[n],"-BLKSZ") == 0) && (n+1<argc) )
365         {
366            blk_size = atoi(argv[n+1]);
367            assert(((blk_size % 512) == 0) && "BDEV: Block size must be multiple of 512 bytes");
368         }
369         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc))
370         {
371            debug_ok = true;
372            debug_from = atoi(argv[n + 1]);
373         }
374         else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc))
375         {
376            debug_memc_id = atoi(argv[n + 1]);
377            assert((debug_memc_id < (xmax * ymax)) && 
378                   "debug_memc_id larger than xmax * ymax" );
379         }
380         else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc))
381         {
382            debug_proc_id = atoi(argv[n + 1]);
383            assert((debug_proc_id < (xmax * ymax * nprocs)) && 
384                   "debug_proc_id larger than XMAX * ymax * NB_PROCS");
385         }
386         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc))
387         {
388            frozen_cycles = atoi(argv[n + 1]);
389         }
390         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n + 1 < argc))
391         {
392            debug_period = atoi(argv[n + 1]);
393         }
394         else
395         {
396            std::cout << "   Arguments are (key,value) couples." << std::endl;
397            std::cout << "   The order is not important." << std::endl;
398            std::cout << "   Accepted arguments are :" << std::endl << std::endl;
399            std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl;
400            std::cout << "     -NPROCS number_of_processors_per_cluster" << std::endl;
401            std::cout << "     -THREADS simulator's openmp threads number" << std::endl;
402            std::cout << "     -XMAX number_of_clusters_in_a_row" << std::endl;
403            std::cout << "     -YMAX number_of_clusters_in_a_column" << std::endl;
404            std::cout << "     -MCWAYS memory_cache_number_of_ways" << std::endl;
405            std::cout << "     -MCSETS memory_cache_number_of_sets" << std::endl;
406            std::cout << "     -L1_IWAYS L1_instruction_cache_number_of_ways" << std::endl;
407            std::cout << "     -L1_ISETS L1_instruction_cache_number_of_sets" << std::endl;
408            std::cout << "     -L1_DWAYS L1_data_cache_number_of_ways" << std::endl;
409            std::cout << "     -XLATENCY external_ram_latency_value" << std::endl;
410            std::cout << "     -XFB fram_buffer_number_of_pixels" << std::endl;
411            std::cout << "     -YFB fram_buffer_number_of_lines" << std::endl;
412            std::cout << "     -FBMODE fram buffer subsampling integer value "
413               "(YUV:420,YUV:422,RGB:0,RGB:16,RGB:32,RGBPAL:256)" << std::endl;
414            std::cout << "     -MEMSZ per-cluster memory size ( <= 12 MB when using Almos)" << std::endl;
415            std::cout << "     -L1_DSETS L1_data_cache_number_of_sets" << std::endl;
416            std::cout << "     -SOFT pathname_for_embedded_soft (GIET only)" << std::endl;
417            std::cout << "     -DISK pathname_for_disk_image" << std::endl;
418            std::cout << "     -BLKSZ sector size in bytes ( must be multiple of 512 bytes )" << std::endl;
419            std::cout << "     -DEBUG debug_start_cycle" << std::endl;
420            std::cout << "     -FROZEN max_number_of_lines" << std::endl;
421            std::cout << "     -PERIOD number_of_cycles between trace" << std::endl;
422            std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl;
423            std::cout << "     -PROCID index_proc_to_be_traced" << std::endl;
424            exit(0);
425         }
426      }
427   }
428
429    // checking hardware parameters
430    assert( ( (xmax == 1) or (xmax == 2) or (xmax == 4) or
431              (xmax == 8) or (xmax == 16) ) and
432              "The XMAX parameter must be 1, 2, 4, 8 or 16" );
433
434    assert( ( (ymax == 1) or (ymax == 2) or (ymax == 4) or
435              (ymax == 8) or (ymax == 16) ) and
436              "The YMAX parameter must be 1, 2, 4, 8 or 16" );
437
438    assert( ( (nprocs == 1) or (nprocs == 2) or
439              (nprocs == 4) or (nprocs == 8) ) and
440             "The nprocs parameter must be 1, 2, 4 or 8" );
441
442    assert( (NB_DMA_CHANNELS < 9) and
443            "The NB_DMA_CHANNELS parameter must be smaller than 9" );
444
445    assert( (NB_TTY_CHANNELS < 15) and
446            "The NB_TTY_CHANNELS parameter must be smaller than 15" );
447
448    assert( (NB_NIC_CHANNELS < 9) and
449            "The NB_NIC_CHANNELS parameter must be smaller than 9" );
450
451    assert( (vci_address_width == 32) and
452            "VCI address width with ALMOS must be 32 bits" );
453
454    std::cout << std::endl;
455    std::cout << " - XMAX             = " << xmax << std::endl;
456    std::cout << " - YMAX             = " << ymax << std::endl;
457    std::cout << " - NPROCS           = " << nprocs <<  std::endl;
458    std::cout << " - NB_DMA_CHANNELS  = " << NB_DMA_CHANNELS <<  std::endl;
459    std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl;
460    std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl;
461    std::cout << " - MEMC_WAYS        = " << memc_ways << std::endl;
462    std::cout << " - MEMC_SETS        = " << memc_sets << std::endl;
463    std::cout << " - RAM_SIZE         = " << memc_size << std::endl;
464    std::cout << " - RAM_LATENCY      = " << xram_latency << std::endl;
465    std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl;
466    std::cout << "[PROCS] " << nprocs * xmax * ymax << std::endl;
467
468    std::cout << std::endl;
469    // Internal and External VCI parameters definition
470    typedef soclib::caba::VciParams<vci_cell_width_int,
471                                    vci_plen_width,
472                                    vci_address_width,
473                                    vci_rerror_width,
474                                    vci_clen_width,
475                                    vci_rflag_width,
476                                    vci_srcid_width,
477                                    vci_pktid_width,
478                                    vci_trdid_width,
479                                    vci_wrplen_width> vci_param_int;
480
481    typedef soclib::caba::VciParams<vci_cell_width_ext,
482                                    vci_plen_width,
483                                    vci_address_width,
484                                    vci_rerror_width,
485                                    vci_clen_width,
486                                    vci_rflag_width,
487                                    vci_srcid_width,
488                                    vci_pktid_width,
489                                    vci_trdid_width,
490                                    vci_wrplen_width> vci_param_ext;
491
492#if USE_OPENMP
493   omp_set_dynamic(false);
494   omp_set_num_threads(threads_nr);
495   std::cerr << "Built with openmp version " << _OPENMP << std::endl;
496#endif
497
498   // Define parameters depending on mesh size
499   size_t   x_width;
500   size_t   y_width;
501
502   if      (xmax == 1) x_width = 0;
503   else if (xmax == 2) x_width = 1;
504   else if (xmax <= 4) x_width = 2;
505   else if (xmax <= 8) x_width = 3;
506   else                x_width = 4;
507
508   if      (ymax == 1) y_width = 0;
509   else if (ymax == 2) y_width = 1;
510   else if (ymax <= 4) y_width = 2;
511   else if (ymax <= 8) y_width = 3;
512   else                y_width = 4;
513
514   cluster_io_id = 0xbfc00000 >> (vci_address_width - x_width - y_width); // index of cluster containing IOs
515
516   /////////////////////
517   //  Mapping Tables
518   /////////////////////
519
520   // internal network
521   MappingTable maptabd(vci_address_width, 
522                        IntTab(x_width + y_width, 16 - x_width - y_width), 
523                        IntTab(x_width + y_width, vci_srcid_width - x_width - y_width), 
524                        0x00FFFF0000);
525
526   for (size_t x = 0; x < xmax; x++)
527   {
528      for (size_t y = 0; y < ymax; y++)
529      {
530         sc_uint<vci_address_width> offset;
531         offset = (sc_uint<vci_address_width>)cluster(x,y) 
532                   << (vci_address_width-x_width-y_width);
533
534         std::ostringstream    si;
535         si << "seg_xicu_" << x << "_" << y;
536         maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE, 
537                  IntTab(cluster(x,y),XICU_TGTID), false));
538
539         std::ostringstream    sd;
540         sd << "seg_mdma_" << x << "_" << y;
541         maptabd.add(Segment(sd.str(), MDMA_BASE + offset, MDMA_SIZE, 
542                  IntTab(cluster(x,y),MDMA_TGTID), false));
543
544         std::ostringstream    sh;
545         sh << "seg_ram_" << x << "_" << y;
546         maptabd.add(Segment(sh.str(), RAM_BASE + offset, memc_size, 
547                  IntTab(cluster(x,y),MEMC_TGTID), true));
548
549         std::ostringstream    sconf;
550         sconf << "seg_memc_config_" << x << "_" << y;
551         maptabd.add(Segment(sconf.str(), MEMC_BASE + offset, MEMC_SIZE, 
552                             IntTab(cluster(x,y),MEMC_TGTID), true, true));
553
554         if ( cluster(x,y) == cluster_io_id )
555         {
556            maptabd.add(Segment("seg_mtty", MTTY_BASE, MTTY_SIZE, 
557                        IntTab(cluster(x,y),MTTY_TGTID), false));
558            maptabd.add(Segment("seg_fbuf", FBUF_BASE, FBUF_SIZE, 
559                        IntTab(cluster(x,y),FBUF_TGTID), false));
560            maptabd.add(Segment("seg_bdev", BDEV_BASE, BDEV_SIZE, 
561                        IntTab(cluster(x,y),BDEV_TGTID), false));
562            maptabd.add(Segment("seg_brom", BROM_BASE, BROM_SIZE, 
563                        IntTab(cluster(x,y),BROM_TGTID), true));
564            maptabd.add(Segment("seg_mnic", MNIC_BASE, MNIC_SIZE, 
565                        IntTab(cluster(x,y),MNIC_TGTID), false));
566            maptabd.add(Segment("seg_cdma", CDMA_BASE, CDMA_SIZE, 
567                        IntTab(cluster(x,y),CDMA_TGTID), false));
568            maptabd.add(Segment("seg_simh", SIMH_BASE, SIMH_SIZE, 
569                        IntTab(cluster(x,y),SIMH_TGTID), false));
570         }
571      }
572   }
573   std::cout << maptabd << std::endl;
574
575   // external network
576   MappingTable maptabx(vci_address_width, 
577                        IntTab(x_width+y_width), 
578                        IntTab(x_width+y_width), 
579                        0x00FFFF0000ULL);
580
581   for (size_t x = 0; x < xmax; x++)
582   {
583      for (size_t y = 0; y < ymax ; y++)
584      { 
585
586         sc_uint<vci_address_width> offset;
587         offset = (sc_uint<vci_address_width>)cluster(x,y) 
588                   << (vci_address_width-x_width-y_width);
589
590         std::ostringstream sh;
591         sh << "x_seg_memc_" << x << "_" << y;
592
593         maptabx.add(Segment(sh.str(), RAM_BASE + offset, 
594                     memc_size, IntTab(cluster(x,y)), false));
595      }
596   }
597   std::cout << maptabx << std::endl;
598
599   ////////////////////
600   // Signals
601   ///////////////////
602
603   std::cout << "Clock  .. ";
604   sc_clock           signal_clk("clk");
605   std::cout << ". [OK]" << std::endl;
606   sc_signal<bool>    signal_resetn("resetn");
607
608   // Horizontal inter-clusters DSPIN signals
609   DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_inc =
610      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", xmax-1, ymax, 3);
611
612   DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_dec =
613      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", xmax-1, ymax, 3);
614
615   DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_inc =
616      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", xmax-1, ymax, 2);
617   DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_dec =
618      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", xmax-1, ymax, 2);
619
620   // Vertical inter-clusters DSPIN signals
621   DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_inc =
622      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", xmax, ymax-1, 3);
623   DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_dec =
624      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", xmax, ymax-1, 3);
625   DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_inc =
626      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", xmax, ymax-1, 2);
627   DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_dec =
628      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", xmax, ymax-1, 2);
629
630   // Mesh boundaries DSPIN signals
631   DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_in =
632      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_in" , xmax, ymax, 4, 3);
633   DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_out =
634      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_out", xmax, ymax, 4, 3);
635   DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_in =
636      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_in" , xmax, ymax, 4, 2);
637   DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_out =
638      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_out", xmax, ymax, 4, 2);
639
640   ////////////////////////////
641   //      Loader   
642   ////////////////////////////
643
644   soclib::common::Loader loader(soft_name);
645
646   typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
647   proc_iss::set_loader(loader);
648
649   ////////////////////////////
650   // Clusters construction
651   ////////////////////////////
652
653   TsarXbarCluster<dspin_cmd_width,
654                   dspin_rsp_width,
655                   vci_param_int,
656                   vci_param_ext>*          clusters[xmax][ymax];
657
658#if USE_OPENMP
659#pragma omp parallel
660    {
661#pragma omp for
662#endif
663        for (size_t i = 0; i  < (xmax * ymax); i++)
664        {
665            size_t x = i / ymax;
666            size_t y = i % ymax;
667
668#if USE_OPENMP
669#pragma omp critical
670            {
671#endif
672            std::cout << std::endl;
673            std::cout << "Cluster_" << x << "_" << y << std::endl;
674            std::cout << std::endl;
675
676            std::ostringstream sc;
677            sc << "cluster_" << x << "_" << y;
678            clusters[x][y] = new TsarXbarCluster<dspin_cmd_width,
679                                                 dspin_rsp_width,
680                                                 vci_param_int,
681                                                 vci_param_ext>
682            (
683                sc.str().c_str(),
684                nprocs,
685                NB_TTY_CHANNELS, 
686                NB_DMA_CHANNELS, 
687                x,
688                y,
689                cluster(x,y),
690                maptabd,
691                maptabx,
692                x_width,
693                y_width,
694                vci_srcid_width - x_width - y_width,   // l_id width,
695                MEMC_TGTID,
696                XICU_TGTID,
697                MDMA_TGTID,
698                FBUF_TGTID,
699                MTTY_TGTID,
700                BROM_TGTID,
701                MNIC_TGTID,
702                CDMA_TGTID,
703                BDEV_TGTID,
704                SIMH_TGTID,
705                memc_ways,
706                memc_sets,
707                l1_i_ways,
708                l1_i_sets,
709                l1_d_ways,
710                l1_d_sets,
711                xram_latency,
712                (cluster(x,y) == cluster_io_id),
713                xfb,
714                yfb,
715                disk_name,
716                blk_size,
717                NB_NIC_CHANNELS,
718                nic_rx_name,
719                nic_tx_name,
720                NIC_TIMEOUT,
721                NB_CMA_CHANNELS,
722                loader,
723                frozen_cycles,
724                debug_from   ,
725                debug_ok and (cluster(x,y) == debug_memc_id),
726                debug_ok and (cluster(x,y) == debug_proc_id) 
727            );
728
729#if USE_OPENMP
730            } // end critical
731#endif
732        } // end for
733#if USE_OPENMP
734    }
735#endif
736
737   ///////////////////////////////////////////////////////////////
738   //     Net-list
739   ///////////////////////////////////////////////////////////////
740
741   // Clock & RESET
742   for (size_t x = 0; x < (xmax); x++){
743      for (size_t y = 0; y < ymax; y++){
744         clusters[x][y]->p_clk                         (signal_clk);
745         clusters[x][y]->p_resetn                      (signal_resetn);
746      }
747   }
748
749   // Inter Clusters horizontal connections
750   if (xmax > 1){
751      for (size_t x = 0; x < (xmax-1); x++){
752         for (size_t y = 0; y < ymax; y++){
753            for (size_t k = 0; k < 3; k++){
754               clusters[x][y]->p_cmd_out[EAST][k]      (signal_dspin_h_cmd_inc[x][y][k]);
755               clusters[x+1][y]->p_cmd_in[WEST][k]     (signal_dspin_h_cmd_inc[x][y][k]);
756               clusters[x][y]->p_cmd_in[EAST][k]       (signal_dspin_h_cmd_dec[x][y][k]);
757               clusters[x+1][y]->p_cmd_out[WEST][k]    (signal_dspin_h_cmd_dec[x][y][k]);
758            }
759
760            for (size_t k = 0; k < 2; k++){
761               clusters[x][y]->p_rsp_out[EAST][k]      (signal_dspin_h_rsp_inc[x][y][k]);
762               clusters[x+1][y]->p_rsp_in[WEST][k]     (signal_dspin_h_rsp_inc[x][y][k]);
763               clusters[x][y]->p_rsp_in[EAST][k]       (signal_dspin_h_rsp_dec[x][y][k]);
764               clusters[x+1][y]->p_rsp_out[WEST][k]    (signal_dspin_h_rsp_dec[x][y][k]);
765            }
766         }
767      }
768   }
769   std::cout << std::endl << "Horizontal connections established" << std::endl;   
770
771   // Inter Clusters vertical connections
772   if (ymax > 1) {
773      for (size_t y = 0; y < (ymax-1); y++){
774         for (size_t x = 0; x < xmax; x++){
775            for (size_t k = 0; k < 3; k++){
776               clusters[x][y]->p_cmd_out[NORTH][k]     (signal_dspin_v_cmd_inc[x][y][k]);
777               clusters[x][y+1]->p_cmd_in[SOUTH][k]    (signal_dspin_v_cmd_inc[x][y][k]);
778               clusters[x][y]->p_cmd_in[NORTH][k]      (signal_dspin_v_cmd_dec[x][y][k]);
779               clusters[x][y+1]->p_cmd_out[SOUTH][k]   (signal_dspin_v_cmd_dec[x][y][k]);
780            }
781
782            for (size_t k = 0; k < 2; k++){
783               clusters[x][y]->p_rsp_out[NORTH][k]     (signal_dspin_v_rsp_inc[x][y][k]);
784               clusters[x][y+1]->p_rsp_in[SOUTH][k]    (signal_dspin_v_rsp_inc[x][y][k]);
785               clusters[x][y]->p_rsp_in[NORTH][k]      (signal_dspin_v_rsp_dec[x][y][k]);
786               clusters[x][y+1]->p_rsp_out[SOUTH][k]   (signal_dspin_v_rsp_dec[x][y][k]);
787            }
788         }
789      }
790   }
791   std::cout << "Vertical connections established" << std::endl;
792
793   // East & West boundary cluster connections
794   for (size_t y = 0; y < ymax; y++)
795   {
796      for (size_t k = 0; k < 3; k++)
797      {
798         clusters[0][y]->p_cmd_in[WEST][k]        (signal_dspin_false_cmd_in[0][y][WEST][k]);
799         clusters[0][y]->p_cmd_out[WEST][k]       (signal_dspin_false_cmd_out[0][y][WEST][k]);
800         clusters[xmax-1][y]->p_cmd_in[EAST][k]   (signal_dspin_false_cmd_in[xmax-1][y][EAST][k]);
801         clusters[xmax-1][y]->p_cmd_out[EAST][k]  (signal_dspin_false_cmd_out[xmax-1][y][EAST][k]);
802      }
803
804      for (size_t k = 0; k < 2; k++)
805      {
806         clusters[0][y]->p_rsp_in[WEST][k]        (signal_dspin_false_rsp_in[0][y][WEST][k]);
807         clusters[0][y]->p_rsp_out[WEST][k]       (signal_dspin_false_rsp_out[0][y][WEST][k]);
808         clusters[xmax-1][y]->p_rsp_in[EAST][k]   (signal_dspin_false_rsp_in[xmax-1][y][EAST][k]);
809         clusters[xmax-1][y]->p_rsp_out[EAST][k]  (signal_dspin_false_rsp_out[xmax-1][y][EAST][k]);
810      }
811   }
812
813   // North & South boundary clusters connections
814   for (size_t x = 0; x < xmax; x++)
815   {
816      for (size_t k = 0; k < 3; k++)
817      {
818         clusters[x][0]->p_cmd_in[SOUTH][k]       (signal_dspin_false_cmd_in[x][0][SOUTH][k]);
819         clusters[x][0]->p_cmd_out[SOUTH][k]      (signal_dspin_false_cmd_out[x][0][SOUTH][k]);
820         clusters[x][ymax-1]->p_cmd_in[NORTH][k]  (signal_dspin_false_cmd_in[x][ymax-1][NORTH][k]);
821         clusters[x][ymax-1]->p_cmd_out[NORTH][k] (signal_dspin_false_cmd_out[x][ymax-1][NORTH][k]);
822      }
823
824      for (size_t k = 0; k < 2; k++)
825      {
826         clusters[x][0]->p_rsp_in[SOUTH][k]       (signal_dspin_false_rsp_in[x][0][SOUTH][k]);
827         clusters[x][0]->p_rsp_out[SOUTH][k]      (signal_dspin_false_rsp_out[x][0][SOUTH][k]);
828         clusters[x][ymax-1]->p_rsp_in[NORTH][k]  (signal_dspin_false_rsp_in[x][ymax-1][NORTH][k]);
829         clusters[x][ymax-1]->p_rsp_out[NORTH][k] (signal_dspin_false_rsp_out[x][ymax-1][NORTH][k]);
830      }
831   }
832   std::cout << "North, South, West, East connections established" << std::endl;
833   std::cout << std::endl;
834
835
836   ////////////////////////////////////////////////////////
837   //   Simulation
838   ///////////////////////////////////////////////////////
839
840   sc_start(sc_core::sc_time(0, SC_NS));
841   signal_resetn = false;
842
843   // network boundaries signals
844   for (size_t x = 0; x < xmax ; x++){
845      for (size_t y = 0; y < ymax ; y++){
846         for (size_t a = 0; a < 4; a++){
847            for (size_t k = 0; k < 3; k++){
848               signal_dspin_false_cmd_in [x][y][a][k].write = false;
849               signal_dspin_false_cmd_in [x][y][a][k].read  = true;
850               signal_dspin_false_cmd_out[x][y][a][k].write = false;
851               signal_dspin_false_cmd_out[x][y][a][k].read  = true;
852            }
853
854            for (size_t k = 0; k < 2; k++){
855               signal_dspin_false_rsp_in [x][y][a][k].write = false;
856               signal_dspin_false_rsp_in [x][y][a][k].read  = true;
857               signal_dspin_false_rsp_out[x][y][a][k].write = false;
858               signal_dspin_false_rsp_out[x][y][a][k].read  = true;
859            }
860         }
861      }
862   }
863
864#define STATS_CYCLES 10000000
865
866   sc_start(sc_core::sc_time(1, SC_NS));
867   signal_resetn = true;
868
869   uint64_t n = 0;
870   
871   while (!stop_called) {
872        if (gettimeofday(&t1, NULL) != 0) {
873                perror("gettimeofday");
874                return EXIT_FAILURE;
875        }
876        sc_start(STATS_CYCLES);
877        n += STATS_CYCLES;
878        if (gettimeofday(&t2, NULL) != 0) {
879                perror("gettimeofday");
880                return EXIT_FAILURE;
881        }
882        ms1 = (uint64_t)t1.tv_sec * 1000ULL + (uint64_t)t1.tv_usec / 1000;
883        ms2 = (uint64_t)t2.tv_sec * 1000ULL + (uint64_t)t2.tv_usec / 1000;
884        std::cerr << "cycle " << n
885                << " platform clock frequency " 
886                << (double)STATS_CYCLES / (double)(ms2 - ms1) 
887                << "Khz" << std::endl;
888   }
889   
890   // Free memory
891   for (size_t i = 0; i  < (xmax * ymax); i++)
892   {
893      size_t x = i / ymax;
894      size_t y = i % ymax;
895      delete clusters[x][y];
896   }
897
898   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_inc, xmax - 1, ymax, 3);
899   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_dec, xmax - 1, ymax, 3);
900   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_inc, xmax - 1, ymax, 2);
901   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_dec, xmax - 1, ymax, 2);
902   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_inc, xmax, ymax - 1, 3);
903   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_dec, xmax, ymax - 1, 3);
904   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_inc, xmax, ymax - 1, 2);
905   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_dec, xmax, ymax - 1, 2);
906   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_in, xmax, ymax, 4, 3);
907   dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_out, xmax, ymax, 4, 3);
908   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_in, xmax, ymax, 4, 2);
909   dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_out, xmax, ymax, 4, 2);
910
911   return EXIT_SUCCESS;
912}
913
914
915void handler(int dummy = 0) {
916   stop_called = true;
917   sc_stop();
918}
919
920void voidhandler(int dummy = 0) {}
921
922int sc_main (int argc, char *argv[])
923{
924   signal(SIGINT, handler);
925   signal(SIGPIPE, voidhandler);
926
927   try {
928      return _main(argc, argv);
929   } catch (std::exception &e) {
930      std::cout << e.what() << std::endl;
931   } catch (...) {
932      std::cout << "Unknown exception occured" << std::endl;
933      throw;
934   }
935   return 1;
936}
937
938
939// Local Variables:
940// tab-width: 3
941// c-basic-offset: 3
942// c-file-offsets:((innamespace . 0)(inline-open . 0))
943// indent-tabs-mode: nil
944// End:
945
946// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
Note: See TracBrowser for help on using the repository browser.