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_IO_INC (cluster_io_id * (0x80000000ULL / (X_SIZE * Y_SIZE) * 2)) |
---|
298 | #define MEMC_MAX_SIZE (0x40000000 / (X_SIZE * Y_SIZE)) |
---|
299 | |
---|
300 | #define BROM_BASE 0x00BFC00000 |
---|
301 | #define BROM_SIZE 0x0000100000 // 1 Mbytes |
---|
302 | |
---|
303 | #define MEMC_BASE 0x0000000000 |
---|
304 | #define MEMC_SIZE min(0x04000000, MEMC_MAX_SIZE) |
---|
305 | |
---|
306 | #define XICU_BASE MEMC_MAX_SIZE + (XICU_TGTID << 19) |
---|
307 | #define XICU_SIZE 0x0000001000 // 4 Kbytes |
---|
308 | |
---|
309 | #define MDMA_BASE MEMC_MAX_SIZE + (MDMA_TGTID << 19) |
---|
310 | #define MDMA_SIZE (0x0000001000 * NB_DMA_CHANNELS) // 4 Kbytes per channel |
---|
311 | |
---|
312 | #define BDEV_BASE MEMC_MAX_SIZE + (BDEV_TGTID << 19) + (CLUSTER_IO_INC) |
---|
313 | #define BDEV_SIZE 0x0000001000 // 4 Kbytes |
---|
314 | |
---|
315 | #define MTTY_BASE MEMC_MAX_SIZE + (MTTY_TGTID << 19) + (CLUSTER_IO_INC) |
---|
316 | #define MTTY_SIZE 0x0000001000 // 4 Kbytes |
---|
317 | |
---|
318 | #define FBUF_BASE MEMC_MAX_SIZE + (FBUF_TGTID << 19) + (CLUSTER_IO_INC) |
---|
319 | #define FBUF_SIZE (FBUF_X_SIZE * FBUF_Y_SIZE * 2) // Should be 0x80000 |
---|
320 | |
---|
321 | #define MNIC_BASE MEMC_MAX_SIZE + (MNIC_TGTID << 19) + (CLUSTER_IO_INC) |
---|
322 | #define MNIC_SIZE 0x0000080000 |
---|
323 | |
---|
324 | #define CDMA_BASE MEMC_MAX_SIZE + (CDMA_TGTID << 19) + (CLUSTER_IO_INC) |
---|
325 | #define CDMA_SIZE (0x0000004000 * NB_CMA_CHANNELS) |
---|
326 | |
---|
327 | #define SIMH_BASE MEMC_MAX_SIZE + (SIMH_TGTID << 19) + (CLUSTER_IO_INC) |
---|
328 | #define SIMH_SIZE 0x0000001000 |
---|
329 | #endif |
---|
330 | |
---|
331 | bool stop_called = false; |
---|
332 | |
---|
333 | ///////////////////////////////// |
---|
334 | int _main(int argc, char *argv[]) |
---|
335 | { |
---|
336 | using namespace sc_core; |
---|
337 | using namespace soclib::caba; |
---|
338 | using namespace soclib::common; |
---|
339 | |
---|
340 | #ifdef USE_GIET |
---|
341 | char soft_name[256] = soft_pathname; // pathname to binary code |
---|
342 | #endif |
---|
343 | const int64_t max_cycles = 5000000; // Maximum number of cycles simulated in one sc_start call |
---|
344 | int64_t ncycles = 0x7FFFFFFFFFFFFFFF; // simulated cycles |
---|
345 | char disk_name[256] = BDEV_IMAGE_NAME; // pathname to the disk image |
---|
346 | char nic_rx_name[256] = NIC_RX_NAME; // pathname to the rx packets file |
---|
347 | char nic_tx_name[256] = NIC_TX_NAME; // pathname to the tx packets file |
---|
348 | ssize_t threads_nr = 1; // simulator's threads number |
---|
349 | bool debug_ok = false; // trace activated |
---|
350 | size_t debug_period = 1; // trace period |
---|
351 | size_t debug_memc_id = 0; // index of memc to be traced |
---|
352 | size_t debug_proc_id = 0; // index of proc to be traced |
---|
353 | int64_t debug_from = 0; // trace start cycle |
---|
354 | int64_t frozen_cycles = MAX_FROZEN_CYCLES; // monitoring frozen processor |
---|
355 | size_t cluster_io_id; // index of cluster containing IOs |
---|
356 | int64_t reset_counters = -1; |
---|
357 | int64_t dump_counters = -1; |
---|
358 | bool do_reset_counters = false; |
---|
359 | bool do_dump_counters = false; |
---|
360 | struct timeval t1, t2; |
---|
361 | uint64_t ms1, ms2; |
---|
362 | |
---|
363 | ////////////// command line arguments ////////////////////// |
---|
364 | if (argc > 1) |
---|
365 | { |
---|
366 | for (int n = 1; n < argc; n = n + 2) |
---|
367 | { |
---|
368 | if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc)) |
---|
369 | { |
---|
370 | ncycles = (int64_t) strtol(argv[n + 1], NULL, 0); |
---|
371 | } |
---|
372 | else if ((strcmp(argv[n], "-SOFT") == 0) && (n + 1 < argc)) |
---|
373 | { |
---|
374 | #ifdef USE_ALMOS |
---|
375 | assert( 0 && "Can't define almos soft name" ); |
---|
376 | #endif |
---|
377 | #ifdef USE_GIET |
---|
378 | strcpy(soft_name, argv[n + 1]); |
---|
379 | #endif |
---|
380 | } |
---|
381 | else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc)) |
---|
382 | { |
---|
383 | strcpy(disk_name, argv[n + 1]); |
---|
384 | } |
---|
385 | else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc)) |
---|
386 | { |
---|
387 | debug_ok = true; |
---|
388 | debug_from = (int64_t) strtol(argv[n + 1], NULL, 0); |
---|
389 | } |
---|
390 | else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc)) |
---|
391 | { |
---|
392 | debug_memc_id = (size_t) strtol(argv[n + 1], NULL, 0); |
---|
393 | #ifdef USE_ALMOS |
---|
394 | assert((debug_memc_id < (X_SIZE * Y_SIZE)) && |
---|
395 | "debug_memc_id larger than X_SIZE * Y_SIZE" ); |
---|
396 | #else |
---|
397 | size_t x = debug_memc_id >> Y_WIDTH; |
---|
398 | size_t y = debug_memc_id & ((1<<Y_WIDTH)-1); |
---|
399 | |
---|
400 | assert( (x <= X_SIZE) and (y <= Y_SIZE) && |
---|
401 | "MEMCID parameter refers a not valid memory cache"); |
---|
402 | #endif |
---|
403 | } |
---|
404 | else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc)) |
---|
405 | { |
---|
406 | debug_proc_id = (size_t) strtol(argv[n + 1], NULL, 0); |
---|
407 | #ifdef USE_ALMOS |
---|
408 | assert((debug_proc_id < (X_SIZE * Y_SIZE * NB_PROCS_MAX)) && |
---|
409 | "debug_proc_id larger than X_SIZE * Y_SIZE * NB_PROCS"); |
---|
410 | #else |
---|
411 | size_t cluster_xy = debug_proc_id / NB_PROCS_MAX ; |
---|
412 | size_t x = cluster_xy >> Y_WIDTH; |
---|
413 | size_t y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
414 | |
---|
415 | assert( (x <= X_SIZE) and (y <= Y_SIZE) && |
---|
416 | "PROCID parameter refers a not valid processor"); |
---|
417 | #endif |
---|
418 | } |
---|
419 | else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc)) |
---|
420 | { |
---|
421 | threads_nr = (ssize_t) strtol(argv[n + 1], NULL, 0); |
---|
422 | threads_nr = (threads_nr < 1) ? 1 : threads_nr; |
---|
423 | } |
---|
424 | else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc)) |
---|
425 | { |
---|
426 | frozen_cycles = (int64_t) strtol(argv[n + 1], NULL, 0); |
---|
427 | } |
---|
428 | else if ((strcmp(argv[n], "-PERIOD") == 0) && (n + 1 < argc)) |
---|
429 | { |
---|
430 | debug_period = (size_t) strtol(argv[n + 1], NULL, 0); |
---|
431 | } |
---|
432 | else if ((strcmp(argv[n], "--reset-counters") == 0) && (n + 1 < argc)) |
---|
433 | { |
---|
434 | reset_counters = (int64_t) strtol(argv[n + 1], NULL, 0); |
---|
435 | do_reset_counters = true; |
---|
436 | } |
---|
437 | else if ((strcmp(argv[n], "--dump-counters") == 0) && (n + 1 < argc)) |
---|
438 | { |
---|
439 | dump_counters = (int64_t) strtol(argv[n + 1], NULL, 0); |
---|
440 | do_dump_counters = true; |
---|
441 | } |
---|
442 | else |
---|
443 | { |
---|
444 | std::cout << " Arguments are (key,value) couples." << std::endl; |
---|
445 | std::cout << " The order is not important." << std::endl; |
---|
446 | std::cout << " Accepted arguments are :" << std::endl << std::endl; |
---|
447 | std::cout << " -SOFT pathname_for_embedded_soft" << std::endl; |
---|
448 | std::cout << " -DISK pathname_for_disk_image" << std::endl; |
---|
449 | std::cout << " -NCYCLES number_of_simulated_cycles" << std::endl; |
---|
450 | std::cout << " -DEBUG debug_start_cycle" << std::endl; |
---|
451 | std::cout << " -THREADS simulator's threads number" << std::endl; |
---|
452 | std::cout << " -FROZEN max_number_of_lines" << std::endl; |
---|
453 | std::cout << " -PERIOD number_of_cycles between trace" << std::endl; |
---|
454 | std::cout << " -MEMCID index_memc_to_be_traced" << std::endl; |
---|
455 | std::cout << " -PROCID index_proc_to_be_traced" << std::endl; |
---|
456 | exit(0); |
---|
457 | } |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | // checking hardware parameters |
---|
462 | assert( ( (X_SIZE == 1) or (X_SIZE == 2) or (X_SIZE == 4) or |
---|
463 | (X_SIZE == 8) or (X_SIZE == 16) ) and |
---|
464 | "The X_SIZE parameter must be 1, 2, 4, 8 or 16" ); |
---|
465 | |
---|
466 | assert( ( (Y_SIZE == 1) or (Y_SIZE == 2) or (Y_SIZE == 4) or |
---|
467 | (Y_SIZE == 8) or (Y_SIZE == 16) ) and |
---|
468 | "The Y_SIZE parameter must be 1, 2, 4, 8 or 16" ); |
---|
469 | |
---|
470 | assert( ( (NB_PROCS_MAX == 1) or (NB_PROCS_MAX == 2) or |
---|
471 | (NB_PROCS_MAX == 4) or (NB_PROCS_MAX == 8) ) and |
---|
472 | "The NB_PROCS_MAX parameter must be 1, 2, 4 or 8" ); |
---|
473 | |
---|
474 | assert( (NB_DMA_CHANNELS < 9) and |
---|
475 | "The NB_DMA_CHANNELS parameter must be smaller than 9" ); |
---|
476 | |
---|
477 | assert( (NB_TTY_CHANNELS < 15) and |
---|
478 | "The NB_TTY_CHANNELS parameter must be smaller than 15" ); |
---|
479 | |
---|
480 | assert( (NB_NIC_CHANNELS < 9) and |
---|
481 | "The NB_NIC_CHANNELS parameter must be smaller than 9" ); |
---|
482 | |
---|
483 | #ifdef USE_GIET |
---|
484 | assert( (vci_address_width == 40) and |
---|
485 | "VCI address width with the GIET must be 40 bits" ); |
---|
486 | #endif |
---|
487 | |
---|
488 | #ifdef USE_ALMOS |
---|
489 | assert( (vci_address_width == 32) and |
---|
490 | "VCI address width with ALMOS must be 32 bits" ); |
---|
491 | #endif |
---|
492 | |
---|
493 | |
---|
494 | std::cout << std::endl; |
---|
495 | std::cout << " - X_SIZE = " << X_SIZE << std::endl; |
---|
496 | std::cout << " - Y_SIZE = " << Y_SIZE << std::endl; |
---|
497 | std::cout << " - NB_PROCS_MAX = " << NB_PROCS_MAX << std::endl; |
---|
498 | std::cout << " - NB_DMA_CHANNELS = " << NB_DMA_CHANNELS << std::endl; |
---|
499 | std::cout << " - NB_TTY_CHANNELS = " << NB_TTY_CHANNELS << std::endl; |
---|
500 | std::cout << " - NB_NIC_CHANNELS = " << NB_NIC_CHANNELS << std::endl; |
---|
501 | std::cout << " - MEMC_WAYS = " << MEMC_WAYS << std::endl; |
---|
502 | std::cout << " - MEMC_SETS = " << MEMC_SETS << std::endl; |
---|
503 | std::cout << " - RAM_LATENCY = " << XRAM_LATENCY << std::endl; |
---|
504 | std::cout << " - MAX_FROZEN = " << frozen_cycles << std::endl; |
---|
505 | |
---|
506 | std::cout << std::endl; |
---|
507 | // Internal and External VCI parameters definition |
---|
508 | typedef soclib::caba::VciParams<vci_cell_width_int, |
---|
509 | vci_plen_width, |
---|
510 | vci_address_width, |
---|
511 | vci_rerror_width, |
---|
512 | vci_clen_width, |
---|
513 | vci_rflag_width, |
---|
514 | vci_srcid_width, |
---|
515 | vci_pktid_width, |
---|
516 | vci_trdid_width, |
---|
517 | vci_wrplen_width> vci_param_int; |
---|
518 | |
---|
519 | typedef soclib::caba::VciParams<vci_cell_width_ext, |
---|
520 | vci_plen_width, |
---|
521 | vci_address_width, |
---|
522 | vci_rerror_width, |
---|
523 | vci_clen_width, |
---|
524 | vci_rflag_width, |
---|
525 | vci_srcid_width, |
---|
526 | vci_pktid_width, |
---|
527 | vci_trdid_width, |
---|
528 | vci_wrplen_width> vci_param_ext; |
---|
529 | |
---|
530 | #if USE_OPENMP |
---|
531 | omp_set_dynamic(false); |
---|
532 | omp_set_num_threads(threads_nr); |
---|
533 | std::cerr << "Built with openmp version " << _OPENMP << std::endl; |
---|
534 | #endif |
---|
535 | |
---|
536 | // Define parameters depending on mesh size |
---|
537 | size_t x_width; |
---|
538 | size_t y_width; |
---|
539 | |
---|
540 | #ifdef USE_ALMOS |
---|
541 | if (X_SIZE == 1) x_width = 0; |
---|
542 | else if (X_SIZE == 2) x_width = 1; |
---|
543 | else if (X_SIZE <= 4) x_width = 2; |
---|
544 | else if (X_SIZE <= 8) x_width = 3; |
---|
545 | else x_width = 4; |
---|
546 | |
---|
547 | if (Y_SIZE == 1) y_width = 0; |
---|
548 | else if (Y_SIZE == 2) y_width = 1; |
---|
549 | else if (Y_SIZE <= 4) y_width = 2; |
---|
550 | else if (Y_SIZE <= 8) y_width = 3; |
---|
551 | else y_width = 4; |
---|
552 | |
---|
553 | #else |
---|
554 | size_t x_width = X_WIDTH; |
---|
555 | size_t y_width = Y_WIDTH; |
---|
556 | |
---|
557 | assert( (X_WIDTH <= 4) and (Y_WIDTH <= 4) and |
---|
558 | "Up to 256 clusters"); |
---|
559 | |
---|
560 | assert( (X_SIZE <= (1 << X_WIDTH)) and (Y_SIZE <= (1 << Y_WIDTH)) and |
---|
561 | "The X_WIDTH and Y_WIDTH parameter are insufficient"); |
---|
562 | |
---|
563 | #endif |
---|
564 | |
---|
565 | // index of cluster containing IOs |
---|
566 | cluster_io_id = 0x00bfc00000ULL >> (vci_address_width - x_width - y_width); |
---|
567 | |
---|
568 | |
---|
569 | ///////////////////// |
---|
570 | // Mapping Tables |
---|
571 | ///////////////////// |
---|
572 | |
---|
573 | // internal network |
---|
574 | MappingTable maptabd(vci_address_width, |
---|
575 | IntTab(x_width + y_width, 16 - x_width - y_width), |
---|
576 | IntTab(x_width + y_width, vci_srcid_width - x_width - y_width), |
---|
577 | 0x00FF800000); |
---|
578 | |
---|
579 | for (size_t x = 0; x < X_SIZE; x++) |
---|
580 | { |
---|
581 | for (size_t y = 0; y < Y_SIZE; y++) |
---|
582 | { |
---|
583 | sc_uint<vci_address_width> offset; |
---|
584 | offset = (sc_uint<vci_address_width>)cluster(x,y) |
---|
585 | << (vci_address_width-x_width-y_width); |
---|
586 | |
---|
587 | std::ostringstream si; |
---|
588 | si << "seg_xicu_" << x << "_" << y; |
---|
589 | maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE, |
---|
590 | IntTab(cluster(x,y),XICU_TGTID), false)); |
---|
591 | |
---|
592 | std::ostringstream sd; |
---|
593 | sd << "seg_mdma_" << x << "_" << y; |
---|
594 | maptabd.add(Segment(sd.str(), MDMA_BASE + offset, MDMA_SIZE, |
---|
595 | IntTab(cluster(x,y),MDMA_TGTID), false)); |
---|
596 | |
---|
597 | std::ostringstream sh; |
---|
598 | sh << "seg_memc_" << x << "_" << y; |
---|
599 | maptabd.add(Segment(sh.str(), MEMC_BASE + offset, MEMC_SIZE, |
---|
600 | IntTab(cluster(x,y),MEMC_TGTID), true)); |
---|
601 | |
---|
602 | if ( cluster(x,y) == cluster_io_id ) |
---|
603 | { |
---|
604 | maptabd.add(Segment("seg_mtty", MTTY_BASE, MTTY_SIZE, |
---|
605 | IntTab(cluster(x,y),MTTY_TGTID), false)); |
---|
606 | maptabd.add(Segment("seg_fbuf", FBUF_BASE, FBUF_SIZE, |
---|
607 | IntTab(cluster(x,y),FBUF_TGTID), false)); |
---|
608 | maptabd.add(Segment("seg_bdev", BDEV_BASE, BDEV_SIZE, |
---|
609 | IntTab(cluster(x,y),BDEV_TGTID), false)); |
---|
610 | maptabd.add(Segment("seg_brom", BROM_BASE, BROM_SIZE, |
---|
611 | IntTab(cluster(x,y),BROM_TGTID), true)); |
---|
612 | maptabd.add(Segment("seg_mnic", MNIC_BASE, MNIC_SIZE, |
---|
613 | IntTab(cluster(x,y),MNIC_TGTID), false)); |
---|
614 | maptabd.add(Segment("seg_cdma", CDMA_BASE, CDMA_SIZE, |
---|
615 | IntTab(cluster(x,y),CDMA_TGTID), false)); |
---|
616 | maptabd.add(Segment("seg_simh", SIMH_BASE, SIMH_SIZE, |
---|
617 | IntTab(cluster(x,y),SIMH_TGTID), false)); |
---|
618 | } |
---|
619 | } |
---|
620 | } |
---|
621 | std::cout << maptabd << std::endl; |
---|
622 | |
---|
623 | // external network |
---|
624 | MappingTable maptabx(vci_address_width, |
---|
625 | IntTab(x_width+y_width), |
---|
626 | IntTab(x_width+y_width), |
---|
627 | 0xFFFF000000ULL); |
---|
628 | |
---|
629 | for (size_t x = 0; x < X_SIZE; x++) |
---|
630 | { |
---|
631 | for (size_t y = 0; y < Y_SIZE ; y++) |
---|
632 | { |
---|
633 | |
---|
634 | sc_uint<vci_address_width> offset; |
---|
635 | offset = (sc_uint<vci_address_width>)cluster(x,y) |
---|
636 | << (vci_address_width-x_width-y_width); |
---|
637 | |
---|
638 | std::ostringstream sh; |
---|
639 | sh << "x_seg_memc_" << x << "_" << y; |
---|
640 | |
---|
641 | maptabx.add(Segment(sh.str(), MEMC_BASE + offset, |
---|
642 | MEMC_SIZE, IntTab(cluster(x,y)), false)); |
---|
643 | } |
---|
644 | } |
---|
645 | std::cout << maptabx << std::endl; |
---|
646 | |
---|
647 | //////////////////// |
---|
648 | // Signals |
---|
649 | /////////////////// |
---|
650 | |
---|
651 | sc_clock signal_clk("clk"); |
---|
652 | sc_signal<bool> signal_resetn("resetn"); |
---|
653 | |
---|
654 | // Horizontal inter-clusters DSPIN signals |
---|
655 | DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_inc = |
---|
656 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", X_SIZE-1, Y_SIZE, 3); |
---|
657 | DspinSignals<dspin_cmd_width>*** signal_dspin_h_cmd_dec = |
---|
658 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", X_SIZE-1, Y_SIZE, 3); |
---|
659 | DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_inc = |
---|
660 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", X_SIZE-1, Y_SIZE, 2); |
---|
661 | DspinSignals<dspin_rsp_width>*** signal_dspin_h_rsp_dec = |
---|
662 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", X_SIZE-1, Y_SIZE, 2); |
---|
663 | |
---|
664 | // Vertical inter-clusters DSPIN signals |
---|
665 | DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_inc = |
---|
666 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", X_SIZE, Y_SIZE-1, 3); |
---|
667 | DspinSignals<dspin_cmd_width>*** signal_dspin_v_cmd_dec = |
---|
668 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", X_SIZE, Y_SIZE-1, 3); |
---|
669 | DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_inc = |
---|
670 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", X_SIZE, Y_SIZE-1, 2); |
---|
671 | DspinSignals<dspin_rsp_width>*** signal_dspin_v_rsp_dec = |
---|
672 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", X_SIZE, Y_SIZE-1, 2); |
---|
673 | |
---|
674 | // Mesh boundaries DSPIN signals |
---|
675 | DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_in = |
---|
676 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_in" , X_SIZE, Y_SIZE, 4, 3); |
---|
677 | DspinSignals<dspin_cmd_width>**** signal_dspin_false_cmd_out = |
---|
678 | alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_false_cmd_out", X_SIZE, Y_SIZE, 4, 3); |
---|
679 | DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_in = |
---|
680 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_in" , X_SIZE, Y_SIZE, 4, 2); |
---|
681 | DspinSignals<dspin_rsp_width>**** signal_dspin_false_rsp_out = |
---|
682 | alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_false_rsp_out", X_SIZE, Y_SIZE, 4, 2); |
---|
683 | |
---|
684 | |
---|
685 | //////////////////////////// |
---|
686 | // Loader |
---|
687 | //////////////////////////// |
---|
688 | |
---|
689 | soclib::common::Loader loader(soft_name); |
---|
690 | |
---|
691 | typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss; |
---|
692 | proc_iss::set_loader(loader); |
---|
693 | |
---|
694 | //////////////////////////// |
---|
695 | // Clusters construction |
---|
696 | //////////////////////////// |
---|
697 | |
---|
698 | TsarXbarCluster<dspin_cmd_width, |
---|
699 | dspin_rsp_width, |
---|
700 | vci_param_int, |
---|
701 | vci_param_ext>* clusters[X_SIZE][Y_SIZE]; |
---|
702 | |
---|
703 | #if USE_OPENMP |
---|
704 | #pragma omp parallel |
---|
705 | { |
---|
706 | #pragma omp for |
---|
707 | #endif |
---|
708 | for (size_t i = 0; i < (X_SIZE * Y_SIZE); i++) |
---|
709 | { |
---|
710 | size_t x = i / Y_SIZE; |
---|
711 | size_t y = i % Y_SIZE; |
---|
712 | |
---|
713 | #if USE_OPENMP |
---|
714 | #pragma omp critical |
---|
715 | { |
---|
716 | #endif |
---|
717 | std::cout << std::endl; |
---|
718 | std::cout << "Cluster_" << x << "_" << y << std::endl; |
---|
719 | std::cout << std::endl; |
---|
720 | |
---|
721 | std::ostringstream sc; |
---|
722 | sc << "cluster_" << x << "_" << y; |
---|
723 | clusters[x][y] = new TsarXbarCluster<dspin_cmd_width, |
---|
724 | dspin_rsp_width, |
---|
725 | vci_param_int, |
---|
726 | vci_param_ext> |
---|
727 | ( |
---|
728 | sc.str().c_str(), |
---|
729 | NB_PROCS_MAX, |
---|
730 | NB_TTY_CHANNELS, |
---|
731 | NB_DMA_CHANNELS, |
---|
732 | x, |
---|
733 | y, |
---|
734 | cluster(x,y), |
---|
735 | maptabd, |
---|
736 | maptabx, |
---|
737 | x_width, |
---|
738 | y_width, |
---|
739 | vci_srcid_width - x_width - y_width, // l_id width, |
---|
740 | MEMC_TGTID, |
---|
741 | XICU_TGTID, |
---|
742 | MDMA_TGTID, |
---|
743 | FBUF_TGTID, |
---|
744 | MTTY_TGTID, |
---|
745 | BROM_TGTID, |
---|
746 | MNIC_TGTID, |
---|
747 | CDMA_TGTID, |
---|
748 | BDEV_TGTID, |
---|
749 | SIMH_TGTID, |
---|
750 | MEMC_WAYS, |
---|
751 | MEMC_SETS, |
---|
752 | L1_IWAYS, |
---|
753 | L1_ISETS, |
---|
754 | L1_DWAYS, |
---|
755 | L1_DSETS, |
---|
756 | XRAM_LATENCY, |
---|
757 | (cluster(x,y) == cluster_io_id), |
---|
758 | FBUF_X_SIZE, |
---|
759 | FBUF_Y_SIZE, |
---|
760 | disk_name, |
---|
761 | BDEV_SECTOR_SIZE, |
---|
762 | NB_NIC_CHANNELS, |
---|
763 | nic_rx_name, |
---|
764 | nic_tx_name, |
---|
765 | NIC_TIMEOUT, |
---|
766 | NB_CMA_CHANNELS, |
---|
767 | loader, |
---|
768 | frozen_cycles, |
---|
769 | debug_from, |
---|
770 | debug_ok and (cluster(x,y) == debug_memc_id), |
---|
771 | debug_ok and (cluster(x,y) == debug_proc_id) |
---|
772 | ); |
---|
773 | |
---|
774 | #if USE_OPENMP |
---|
775 | } // end critical |
---|
776 | #endif |
---|
777 | } // end for |
---|
778 | #if USE_OPENMP |
---|
779 | } |
---|
780 | #endif |
---|
781 | |
---|
782 | /////////////////////////////////////////////////////////////// |
---|
783 | // Net-list |
---|
784 | /////////////////////////////////////////////////////////////// |
---|
785 | |
---|
786 | // Clock & RESET |
---|
787 | for (size_t x = 0; x < (X_SIZE); x++){ |
---|
788 | for (size_t y = 0; y < Y_SIZE; y++){ |
---|
789 | clusters[x][y]->p_clk (signal_clk); |
---|
790 | clusters[x][y]->p_resetn (signal_resetn); |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | // Inter Clusters horizontal connections |
---|
795 | if (X_SIZE > 1){ |
---|
796 | for (size_t x = 0; x < (X_SIZE-1); x++){ |
---|
797 | for (size_t y = 0; y < Y_SIZE; y++){ |
---|
798 | for (size_t k = 0; k < 3; k++){ |
---|
799 | clusters[x][y]->p_cmd_out[EAST][k] (signal_dspin_h_cmd_inc[x][y][k]); |
---|
800 | clusters[x+1][y]->p_cmd_in[WEST][k] (signal_dspin_h_cmd_inc[x][y][k]); |
---|
801 | clusters[x][y]->p_cmd_in[EAST][k] (signal_dspin_h_cmd_dec[x][y][k]); |
---|
802 | clusters[x+1][y]->p_cmd_out[WEST][k] (signal_dspin_h_cmd_dec[x][y][k]); |
---|
803 | } |
---|
804 | |
---|
805 | for (size_t k = 0; k < 2; k++){ |
---|
806 | clusters[x][y]->p_rsp_out[EAST][k] (signal_dspin_h_rsp_inc[x][y][k]); |
---|
807 | clusters[x+1][y]->p_rsp_in[WEST][k] (signal_dspin_h_rsp_inc[x][y][k]); |
---|
808 | clusters[x][y]->p_rsp_in[EAST][k] (signal_dspin_h_rsp_dec[x][y][k]); |
---|
809 | clusters[x+1][y]->p_rsp_out[WEST][k] (signal_dspin_h_rsp_dec[x][y][k]); |
---|
810 | } |
---|
811 | } |
---|
812 | } |
---|
813 | } |
---|
814 | std::cout << std::endl << "Horizontal connections established" << std::endl; |
---|
815 | |
---|
816 | // Inter Clusters vertical connections |
---|
817 | if (Y_SIZE > 1) { |
---|
818 | for (size_t y = 0; y < (Y_SIZE-1); y++){ |
---|
819 | for (size_t x = 0; x < X_SIZE; x++){ |
---|
820 | for (size_t k = 0; k < 3; k++){ |
---|
821 | clusters[x][y]->p_cmd_out[NORTH][k] (signal_dspin_v_cmd_inc[x][y][k]); |
---|
822 | clusters[x][y+1]->p_cmd_in[SOUTH][k] (signal_dspin_v_cmd_inc[x][y][k]); |
---|
823 | clusters[x][y]->p_cmd_in[NORTH][k] (signal_dspin_v_cmd_dec[x][y][k]); |
---|
824 | clusters[x][y+1]->p_cmd_out[SOUTH][k] (signal_dspin_v_cmd_dec[x][y][k]); |
---|
825 | } |
---|
826 | |
---|
827 | for (size_t k = 0; k < 2; k++){ |
---|
828 | clusters[x][y]->p_rsp_out[NORTH][k] (signal_dspin_v_rsp_inc[x][y][k]); |
---|
829 | clusters[x][y+1]->p_rsp_in[SOUTH][k] (signal_dspin_v_rsp_inc[x][y][k]); |
---|
830 | clusters[x][y]->p_rsp_in[NORTH][k] (signal_dspin_v_rsp_dec[x][y][k]); |
---|
831 | clusters[x][y+1]->p_rsp_out[SOUTH][k] (signal_dspin_v_rsp_dec[x][y][k]); |
---|
832 | } |
---|
833 | } |
---|
834 | } |
---|
835 | } |
---|
836 | std::cout << "Vertical connections established" << std::endl; |
---|
837 | |
---|
838 | // East & West boundary cluster connections |
---|
839 | for (size_t y = 0; y < Y_SIZE; y++) |
---|
840 | { |
---|
841 | for (size_t k = 0; k < 3; k++) |
---|
842 | { |
---|
843 | clusters[0][y]->p_cmd_in[WEST][k] (signal_dspin_false_cmd_in[0][y][WEST][k]); |
---|
844 | clusters[0][y]->p_cmd_out[WEST][k] (signal_dspin_false_cmd_out[0][y][WEST][k]); |
---|
845 | clusters[X_SIZE-1][y]->p_cmd_in[EAST][k] (signal_dspin_false_cmd_in[X_SIZE-1][y][EAST][k]); |
---|
846 | clusters[X_SIZE-1][y]->p_cmd_out[EAST][k] (signal_dspin_false_cmd_out[X_SIZE-1][y][EAST][k]); |
---|
847 | } |
---|
848 | |
---|
849 | for (size_t k = 0; k < 2; k++) |
---|
850 | { |
---|
851 | clusters[0][y]->p_rsp_in[WEST][k] (signal_dspin_false_rsp_in[0][y][WEST][k]); |
---|
852 | clusters[0][y]->p_rsp_out[WEST][k] (signal_dspin_false_rsp_out[0][y][WEST][k]); |
---|
853 | clusters[X_SIZE-1][y]->p_rsp_in[EAST][k] (signal_dspin_false_rsp_in[X_SIZE-1][y][EAST][k]); |
---|
854 | clusters[X_SIZE-1][y]->p_rsp_out[EAST][k] (signal_dspin_false_rsp_out[X_SIZE-1][y][EAST][k]); |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | // North & South boundary clusters connections |
---|
859 | for (size_t x = 0; x < X_SIZE; x++) |
---|
860 | { |
---|
861 | for (size_t k = 0; k < 3; k++) |
---|
862 | { |
---|
863 | clusters[x][0]->p_cmd_in[SOUTH][k] (signal_dspin_false_cmd_in[x][0][SOUTH][k]); |
---|
864 | clusters[x][0]->p_cmd_out[SOUTH][k] (signal_dspin_false_cmd_out[x][0][SOUTH][k]); |
---|
865 | clusters[x][Y_SIZE-1]->p_cmd_in[NORTH][k] (signal_dspin_false_cmd_in[x][Y_SIZE-1][NORTH][k]); |
---|
866 | clusters[x][Y_SIZE-1]->p_cmd_out[NORTH][k] (signal_dspin_false_cmd_out[x][Y_SIZE-1][NORTH][k]); |
---|
867 | } |
---|
868 | |
---|
869 | for (size_t k = 0; k < 2; k++) |
---|
870 | { |
---|
871 | clusters[x][0]->p_rsp_in[SOUTH][k] (signal_dspin_false_rsp_in[x][0][SOUTH][k]); |
---|
872 | clusters[x][0]->p_rsp_out[SOUTH][k] (signal_dspin_false_rsp_out[x][0][SOUTH][k]); |
---|
873 | clusters[x][Y_SIZE-1]->p_rsp_in[NORTH][k] (signal_dspin_false_rsp_in[x][Y_SIZE-1][NORTH][k]); |
---|
874 | clusters[x][Y_SIZE-1]->p_rsp_out[NORTH][k] (signal_dspin_false_rsp_out[x][Y_SIZE-1][NORTH][k]); |
---|
875 | } |
---|
876 | } |
---|
877 | std::cout << "North, South, West, East connections established" << std::endl; |
---|
878 | std::cout << std::endl; |
---|
879 | |
---|
880 | |
---|
881 | //////////////////////////////////////////////////////// |
---|
882 | // Simulation |
---|
883 | /////////////////////////////////////////////////////// |
---|
884 | |
---|
885 | sc_start(sc_core::sc_time(0, SC_NS)); |
---|
886 | signal_resetn = false; |
---|
887 | |
---|
888 | // network boundaries signals |
---|
889 | for (size_t x = 0; x < X_SIZE ; x++){ |
---|
890 | for (size_t y = 0; y < Y_SIZE ; y++){ |
---|
891 | for (size_t a = 0; a < 4; a++){ |
---|
892 | for (size_t k = 0; k < 3; k++){ |
---|
893 | signal_dspin_false_cmd_in [x][y][a][k].write = false; |
---|
894 | signal_dspin_false_cmd_in [x][y][a][k].read = true; |
---|
895 | signal_dspin_false_cmd_out[x][y][a][k].write = false; |
---|
896 | signal_dspin_false_cmd_out[x][y][a][k].read = true; |
---|
897 | } |
---|
898 | |
---|
899 | for (size_t k = 0; k < 2; k++){ |
---|
900 | signal_dspin_false_rsp_in [x][y][a][k].write = false; |
---|
901 | signal_dspin_false_rsp_in [x][y][a][k].read = true; |
---|
902 | signal_dspin_false_rsp_out[x][y][a][k].write = false; |
---|
903 | signal_dspin_false_rsp_out[x][y][a][k].read = true; |
---|
904 | } |
---|
905 | } |
---|
906 | } |
---|
907 | } |
---|
908 | |
---|
909 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
910 | signal_resetn = true; |
---|
911 | |
---|
912 | if (debug_ok) { |
---|
913 | #if USE_OPENMP |
---|
914 | assert(false && "OPEN MP should not be used with debug because of its traces"); |
---|
915 | #endif |
---|
916 | |
---|
917 | if (gettimeofday(&t1, NULL) != 0) { |
---|
918 | perror("gettimeofday"); |
---|
919 | return EXIT_FAILURE; |
---|
920 | } |
---|
921 | |
---|
922 | for (int64_t n = 1; n < ncycles && !stop_called; n++) |
---|
923 | { |
---|
924 | // Monitor a specific address for L1 & L2 caches |
---|
925 | //clusters[0][0]->proc[0]->cache_monitor(0x800002c000ULL); |
---|
926 | //clusters[1][0]->memc->copies_monitor(0x800002C000ULL); |
---|
927 | |
---|
928 | if ((n % max_cycles) == 0) |
---|
929 | { |
---|
930 | |
---|
931 | if (gettimeofday(&t2, NULL) != 0) |
---|
932 | { |
---|
933 | perror("gettimeofday"); |
---|
934 | return EXIT_FAILURE; |
---|
935 | } |
---|
936 | |
---|
937 | ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000; |
---|
938 | ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000; |
---|
939 | std::cerr << "platform clock frequency " << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl; |
---|
940 | |
---|
941 | if (gettimeofday(&t1, NULL) != 0) |
---|
942 | { |
---|
943 | perror("gettimeofday"); |
---|
944 | return EXIT_FAILURE; |
---|
945 | } |
---|
946 | } |
---|
947 | |
---|
948 | |
---|
949 | if (n == reset_counters) { |
---|
950 | for (size_t x = 0; x < (X_SIZE); x++) { |
---|
951 | for (size_t y = 0; y < Y_SIZE; y++) { |
---|
952 | clusters[x][y]->memc->reset_counters(); |
---|
953 | } |
---|
954 | } |
---|
955 | } |
---|
956 | |
---|
957 | if (n == dump_counters) { |
---|
958 | for (size_t x = 0; x < (X_SIZE); x++) { |
---|
959 | for (size_t y = 0; y < Y_SIZE; y++) { |
---|
960 | clusters[x][y]->memc->print_stats(true, false); |
---|
961 | } |
---|
962 | } |
---|
963 | } |
---|
964 | |
---|
965 | if (debug_ok and (n > debug_from) and (n % debug_period == 0)) |
---|
966 | { |
---|
967 | std::cout << "****************** cycle " << std::dec << n ; |
---|
968 | std::cout << " ************************************************" << std::endl; |
---|
969 | |
---|
970 | // trace proc[debug_proc_id] |
---|
971 | size_t l = debug_proc_id % NB_PROCS_MAX ; |
---|
972 | size_t y = (debug_proc_id / NB_PROCS_MAX) % Y_SIZE ; |
---|
973 | size_t x = debug_proc_id / (Y_SIZE * NB_PROCS_MAX) ; |
---|
974 | |
---|
975 | std::ostringstream proc_signame; |
---|
976 | proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ; |
---|
977 | std::ostringstream p2m_signame; |
---|
978 | p2m_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " P2M" ; |
---|
979 | std::ostringstream m2p_signame; |
---|
980 | m2p_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " M2P" ; |
---|
981 | std::ostringstream p_cmd_signame; |
---|
982 | p_cmd_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " CMD" ; |
---|
983 | std::ostringstream p_rsp_signame; |
---|
984 | p_rsp_signame << "[SIG]PROC_" << x << "_" << y << "_" << l << " RSP" ; |
---|
985 | |
---|
986 | //clusters[x][y]->wi_proc[l]->print_trace(); |
---|
987 | //clusters[x][y]->signal_vci_ini_proc[l].print_trace(proc_signame.str()); |
---|
988 | //clusters[x][y]->signal_dspin_p2m_proc[l].print_trace(p2m_signame.str()); |
---|
989 | //clusters[x][y]->signal_dspin_m2p_proc[l].print_trace(m2p_signame.str()); |
---|
990 | //clusters[x][y]->signal_dspin_cmd_proc_i[l].print_trace(p_cmd_signame.str()); |
---|
991 | //clusters[x][y]->signal_dspin_rsp_proc_i[l].print_trace(p_rsp_signame.str()); |
---|
992 | |
---|
993 | //clusters[x][y]->xbar_rsp_d->print_trace(); |
---|
994 | //clusters[x][y]->xbar_cmd_d->print_trace(); |
---|
995 | //clusters[x][y]->signal_dspin_cmd_l2g_d.print_trace("[SIG]L2G CMD"); |
---|
996 | //clusters[x][y]->signal_dspin_cmd_g2l_d.print_trace("[SIG]G2L CMD"); |
---|
997 | //clusters[x][y]->signal_dspin_rsp_l2g_d.print_trace("[SIG]L2G RSP"); |
---|
998 | //clusters[x][y]->signal_dspin_rsp_g2l_d.print_trace("[SIG]G2L RSP"); |
---|
999 | |
---|
1000 | // trace memc[debug_memc_id] |
---|
1001 | x = debug_memc_id / Y_SIZE; |
---|
1002 | y = debug_memc_id % Y_SIZE; |
---|
1003 | |
---|
1004 | std::ostringstream smemc; |
---|
1005 | smemc << "[SIG]MEMC_" << x << "_" << y; |
---|
1006 | std::ostringstream sxram; |
---|
1007 | sxram << "[SIG]XRAM_" << x << "_" << y; |
---|
1008 | std::ostringstream sm2p; |
---|
1009 | sm2p << "[SIG]MEMC_" << x << "_" << y << " M2P" ; |
---|
1010 | std::ostringstream sp2m; |
---|
1011 | sp2m << "[SIG]MEMC_" << x << "_" << y << " P2M" ; |
---|
1012 | std::ostringstream m_cmd_signame; |
---|
1013 | m_cmd_signame << "[SIG]MEMC_" << x << "_" << y << " CMD" ; |
---|
1014 | std::ostringstream m_rsp_signame; |
---|
1015 | m_rsp_signame << "[SIG]MEMC_" << x << "_" << y << " RSP" ; |
---|
1016 | |
---|
1017 | //clusters[x][y]->memc->print_trace(); |
---|
1018 | //clusters[x][y]->wt_memc->print_trace(); |
---|
1019 | //clusters[x][y]->signal_vci_tgt_memc.print_trace(smemc.str()); |
---|
1020 | //clusters[x][y]->signal_vci_xram.print_trace(sxram.str()); |
---|
1021 | //clusters[x][y]->signal_dspin_p2m_memc.print_trace(sp2m.str()); |
---|
1022 | //clusters[x][y]->signal_dspin_m2p_memc.print_trace(sm2p.str()); |
---|
1023 | //clusters[x][y]->signal_dspin_cmd_memc_t.print_trace(m_cmd_signame.str()); |
---|
1024 | //clusters[x][y]->signal_dspin_rsp_memc_t.print_trace(m_rsp_signame.str()); |
---|
1025 | |
---|
1026 | // trace replicated peripherals |
---|
1027 | //clusters[1][1]->mdma->print_trace(); |
---|
1028 | //clusters[1][1]->signal_vci_tgt_mdma.print_trace("[SIG]MDMA_TGT_1_1"); |
---|
1029 | //clusters[1][1]->signal_vci_ini_mdma.print_trace("[SIG]MDMA_INI_1_1"); |
---|
1030 | |
---|
1031 | |
---|
1032 | // trace external peripherals |
---|
1033 | //size_t io_x = cluster_io_id / Y_SIZE; |
---|
1034 | //size_t io_y = cluster_io_id % Y_SIZE; |
---|
1035 | |
---|
1036 | //clusters[io_x][io_y]->brom->print_trace(); |
---|
1037 | //clusters[io_x][io_y]->wt_brom->print_trace(); |
---|
1038 | //clusters[io_x][io_y]->signal_vci_tgt_brom.print_trace("[SIG]BROM"); |
---|
1039 | //clusters[io_x][io_y]->signal_dspin_cmd_brom_t.print_trace("[SIG]BROM CMD"); |
---|
1040 | //clusters[io_x][io_y]->signal_dspin_rsp_brom_t.print_trace("[SIG]BROM RSP"); |
---|
1041 | |
---|
1042 | //clusters[io_x][io_y]->bdev->print_trace(); |
---|
1043 | //clusters[io_x][io_y]->signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT"); |
---|
1044 | //clusters[io_x][io_y]->signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI"); |
---|
1045 | } |
---|
1046 | |
---|
1047 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
1048 | } |
---|
1049 | } |
---|
1050 | else { |
---|
1051 | int64_t n = 0; |
---|
1052 | while (!stop_called) { |
---|
1053 | if (gettimeofday(&t1, NULL) != 0) { |
---|
1054 | perror("gettimeofday"); |
---|
1055 | return EXIT_FAILURE; |
---|
1056 | } |
---|
1057 | int64_t nb_cycles = max_cycles; |
---|
1058 | if (do_reset_counters) { |
---|
1059 | nb_cycles = min(nb_cycles, reset_counters - n); |
---|
1060 | } |
---|
1061 | if (do_dump_counters) { |
---|
1062 | nb_cycles = min(nb_cycles, dump_counters - n); |
---|
1063 | } |
---|
1064 | |
---|
1065 | sc_start(sc_core::sc_time(nb_cycles, SC_NS)); |
---|
1066 | n += nb_cycles; |
---|
1067 | |
---|
1068 | if (do_reset_counters && n == reset_counters) { |
---|
1069 | // Reseting counters |
---|
1070 | for (size_t x = 0; x < (X_SIZE); x++) { |
---|
1071 | for (size_t y = 0; y < Y_SIZE; y++) { |
---|
1072 | clusters[x][y]->memc->reset_counters(); |
---|
1073 | } |
---|
1074 | } |
---|
1075 | do_reset_counters = false; |
---|
1076 | } |
---|
1077 | |
---|
1078 | if (do_dump_counters && n == dump_counters) { |
---|
1079 | // Dumping counters |
---|
1080 | for (size_t x = 0; x < (X_SIZE); x++) { |
---|
1081 | for (size_t y = 0; y < Y_SIZE; y++) { |
---|
1082 | clusters[x][y]->memc->print_stats(true, false); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | do_dump_counters = false; |
---|
1086 | } |
---|
1087 | |
---|
1088 | |
---|
1089 | if (gettimeofday(&t2, NULL) != 0) { |
---|
1090 | perror("gettimeofday"); |
---|
1091 | return EXIT_FAILURE; |
---|
1092 | } |
---|
1093 | ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000; |
---|
1094 | ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000; |
---|
1095 | std::cerr << "cycle " << n << " platform clock frequency " << (double) nb_cycles / (double) (ms2 - ms1) << "Khz" << std::endl; |
---|
1096 | } |
---|
1097 | } |
---|
1098 | |
---|
1099 | |
---|
1100 | // Free memory |
---|
1101 | for (size_t i = 0; i < (X_SIZE * Y_SIZE); i++) |
---|
1102 | { |
---|
1103 | size_t x = i / Y_SIZE; |
---|
1104 | size_t y = i % Y_SIZE; |
---|
1105 | delete clusters[x][y]; |
---|
1106 | } |
---|
1107 | |
---|
1108 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_inc, X_SIZE - 1, Y_SIZE, 3); |
---|
1109 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_h_cmd_dec, X_SIZE - 1, Y_SIZE, 3); |
---|
1110 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_inc, X_SIZE - 1, Y_SIZE, 2); |
---|
1111 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_h_rsp_dec, X_SIZE - 1, Y_SIZE, 2); |
---|
1112 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_inc, X_SIZE, Y_SIZE - 1, 3); |
---|
1113 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_v_cmd_dec, X_SIZE, Y_SIZE - 1, 3); |
---|
1114 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_inc, X_SIZE, Y_SIZE - 1, 2); |
---|
1115 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_v_rsp_dec, X_SIZE, Y_SIZE - 1, 2); |
---|
1116 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_in, X_SIZE, Y_SIZE, 4, 3); |
---|
1117 | dealloc_elems<DspinSignals<dspin_cmd_width> >(signal_dspin_false_cmd_out, X_SIZE, Y_SIZE, 4, 3); |
---|
1118 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_in, X_SIZE, Y_SIZE, 4, 2); |
---|
1119 | dealloc_elems<DspinSignals<dspin_rsp_width> >(signal_dspin_false_rsp_out, X_SIZE, Y_SIZE, 4, 2); |
---|
1120 | |
---|
1121 | return EXIT_SUCCESS; |
---|
1122 | } |
---|
1123 | |
---|
1124 | |
---|
1125 | void handler(int dummy = 0) { |
---|
1126 | stop_called = true; |
---|
1127 | sc_stop(); |
---|
1128 | } |
---|
1129 | |
---|
1130 | void voidhandler(int dummy = 0) {} |
---|
1131 | |
---|
1132 | int sc_main (int argc, char *argv[]) |
---|
1133 | { |
---|
1134 | signal(SIGINT, handler); |
---|
1135 | signal(SIGPIPE, voidhandler); |
---|
1136 | |
---|
1137 | try { |
---|
1138 | return _main(argc, argv); |
---|
1139 | } catch (std::exception &e) { |
---|
1140 | std::cout << e.what() << std::endl; |
---|
1141 | } catch (...) { |
---|
1142 | std::cout << "Unknown exception occured" << std::endl; |
---|
1143 | throw; |
---|
1144 | } |
---|
1145 | return 1; |
---|
1146 | } |
---|
1147 | |
---|
1148 | |
---|
1149 | // Local Variables: |
---|
1150 | // tab-width: 3 |
---|
1151 | // c-basic-offset: 3 |
---|
1152 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
1153 | // indent-tabs-mode: nil |
---|
1154 | // End: |
---|
1155 | |
---|
1156 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 |
---|