1 | ///////////////////////////////////////////////////////////////////////// |
---|
2 | // File: top.cpp |
---|
3 | // Author: Alain Greiner |
---|
4 | // Copyright: UPMC/LIP6 |
---|
5 | // Date : august 2012 |
---|
6 | // This program is released under the GNU public license |
---|
7 | ///////////////////////////////////////////////////////////////////////// |
---|
8 | // This file define a generic TSAR architecture with virtual memory. |
---|
9 | // The physical address space is 32 bits. |
---|
10 | // The number of clusters cannot be larger than 256. |
---|
11 | // The number of processors per cluster cannot be larger than 8. |
---|
12 | // |
---|
13 | // - It uses vci_local_crossbar as local interconnect |
---|
14 | // - It uses virtual_dspin as global interconnect |
---|
15 | // - It uses the vci_cc_vcache_wrapper |
---|
16 | // - It uses the vci_mem_cache |
---|
17 | // - It contains one vci_xicu and one vci_multi_dma per cluster. |
---|
18 | // |
---|
19 | // All clusters are identical, but the cluster containing address |
---|
20 | // 0xBFC00000 (called io_cluster), that contains 5 extra components: |
---|
21 | // - the boot rom (BROM) |
---|
22 | // - the disk controller (BDEV) |
---|
23 | // - the multi-channel network controller (MNIC) |
---|
24 | // - the multi-channel tty controller (MTTY) |
---|
25 | // - the frame buffer controller (FBUF) |
---|
26 | // |
---|
27 | // It is build with one single component implementing a cluster: |
---|
28 | // The TsarClusterMmu component is defined in files |
---|
29 | // tsar_cluster_mmu.* (with * = cpp, h, sd) |
---|
30 | // |
---|
31 | // The IRQs are connected to XICUs as follow: |
---|
32 | // - The IRQ_IN[0] to IRQ_IN[7] ports are not used in all clusters. |
---|
33 | // - The DMA IRQs are connected to IRQ_IN[8] to IRQ_IN[15] in all clusters. |
---|
34 | // - The TTY IRQs are connected to IRQ_IN[16] to IRQ_IN[30] in I/O cluster. |
---|
35 | // - The BDEV IRQ is connected to IRQ_IN[31] in I/O cluster. |
---|
36 | // |
---|
37 | // The main hardware parameters must be defined in the hard_config.h file : |
---|
38 | // - CLUSTER_X : number of clusters in a row (power of 2) |
---|
39 | // - CLUSTER_Y : number of clusters in a column (power of 2) |
---|
40 | // - CLUSTER_SIZE : size of the segment allocated to a cluster |
---|
41 | // - NB_PROCS_MAX : number of processors per cluster (power of 2) |
---|
42 | // - NB_DMAS_MAX : number of DMA channels per cluster (< 9) |
---|
43 | // - NB_TTYS : number of TTY channels in I/O cluster (< 16) |
---|
44 | // - NB_NICS : number of NIC channels in I/O cluster (< 9) |
---|
45 | // |
---|
46 | // Some secondary hardware parameters must be defined in this top.cpp file: |
---|
47 | // - XRAM_LATENCY : external ram latency |
---|
48 | // - MEMC_WAYS : L2 cache number of ways |
---|
49 | // - MEMC_SETS : L2 cache number of sets |
---|
50 | // - L1_IWAYS |
---|
51 | // - L1_ISETS |
---|
52 | // - L1_DWAYS |
---|
53 | // - L1_DSETS |
---|
54 | // - FBUF_X_SIZE : width of frame buffer (pixels) |
---|
55 | // - FBUF_Y_SIZE : heigth of frame buffer (lines) |
---|
56 | // - BDEV_SECTOR_SIZE : block size for block drvice |
---|
57 | // - BDEV_IMAGE_NAME : file pathname for block device |
---|
58 | // - NIC_RX_NAME : file pathname for NIC received packets |
---|
59 | // - NIC_TX_NAME : file pathname for NIC transmited packets |
---|
60 | // - NIC_TIMEOUT : max number of cycles before closing a container |
---|
61 | // |
---|
62 | // General policy for 32 bits physical address decoding: |
---|
63 | // All segments base addresses are multiple of 64 Kbytes |
---|
64 | // Therefore the 16 address MSB bits completely define the target: |
---|
65 | // The (x_width + y_width) MSB bits (left aligned) define |
---|
66 | // the cluster index, and the 8 LSB bits define the local index: |
---|
67 | // | X_ID | Y_ID |---| LADR | OFFSET | |
---|
68 | // |x_width|y_width|---| 8 | 16 | |
---|
69 | ///////////////////////////////////////////////////////////////////////// |
---|
70 | |
---|
71 | #include <systemc> |
---|
72 | #include <sys/time.h> |
---|
73 | #include <iostream> |
---|
74 | #include <sstream> |
---|
75 | #include <cstdlib> |
---|
76 | #include <cstdarg> |
---|
77 | #include <stdint.h> |
---|
78 | |
---|
79 | #include "gdbserver.h" |
---|
80 | #include "mapping_table.h" |
---|
81 | #include "tsar_cluster_mmu.h" |
---|
82 | #include "alloc_elems.h" |
---|
83 | |
---|
84 | /////////////////////////////////////////////////// |
---|
85 | // OS |
---|
86 | /////////////////////////////////////////////////// |
---|
87 | #define USE_ALMOS 0 |
---|
88 | |
---|
89 | #define almos_bootloader_pathname "bootloader.bin" |
---|
90 | #define almos_kernel_pathname "kernel-soclib.bin@0xbfc10000:D" |
---|
91 | #define almos_archinfo_pathname "arch-info.bin@0xBFC08000:D" |
---|
92 | |
---|
93 | /////////////////////////////////////////////////// |
---|
94 | // Parallelisation |
---|
95 | /////////////////////////////////////////////////// |
---|
96 | #define USE_OPENMP 0 |
---|
97 | |
---|
98 | #if USE_OPENMP |
---|
99 | #include <omp.h> |
---|
100 | #endif |
---|
101 | |
---|
102 | // cluster index (computed from x,y coordinates) |
---|
103 | #define cluster(x,y) (y + CLUSTER_Y*x) |
---|
104 | |
---|
105 | // flit widths for the DSPIN network |
---|
106 | #define cmd_width 40 |
---|
107 | #define rsp_width 33 |
---|
108 | |
---|
109 | // VCI format |
---|
110 | #define cell_width 4 |
---|
111 | #define address_width 32 |
---|
112 | #define plen_width 8 |
---|
113 | #define error_width 2 |
---|
114 | #define clen_width 1 |
---|
115 | #define rflag_width 1 |
---|
116 | #define srcid_width 14 |
---|
117 | #define pktid_width 4 |
---|
118 | #define trdid_width 4 |
---|
119 | #define wrplen_width 1 |
---|
120 | |
---|
121 | //////////////////////////////////////////////////////////// |
---|
122 | // Main Hardware Parameters values |
---|
123 | //////////////////////i///////////////////////////////////// |
---|
124 | |
---|
125 | // Create a symbolic link to your local giet_vm copy |
---|
126 | // This directory must contain: |
---|
127 | // - hard_config.h |
---|
128 | // - soft.elf |
---|
129 | // - display/images.raw |
---|
130 | // - nic/rx_data.txt |
---|
131 | // - nic/tx_data.txt |
---|
132 | |
---|
133 | #include "giet_vm/hard_config.h" |
---|
134 | |
---|
135 | //////////////////////////////////////////////////////////// |
---|
136 | // Secondary Hardware Parameters values |
---|
137 | //////////////////////i///////////////////////////////////// |
---|
138 | |
---|
139 | #define XRAM_LATENCY 0 |
---|
140 | |
---|
141 | #define MEMC_WAYS 16 |
---|
142 | #define MEMC_SETS 256 |
---|
143 | |
---|
144 | #define L1_IWAYS 4 |
---|
145 | #define L1_ISETS 64 |
---|
146 | |
---|
147 | #define L1_DWAYS 4 |
---|
148 | #define L1_DSETS 64 |
---|
149 | |
---|
150 | #define FBUF_X_SIZE 128 |
---|
151 | #define FBUF_Y_SIZE 128 |
---|
152 | |
---|
153 | #define BDEV_SECTOR_SIZE 512 |
---|
154 | #define BDEV_IMAGE_NAME "giet_vm/display/images.raw" |
---|
155 | |
---|
156 | #define NIC_RX_NAME "giet_vm/nic/rx_data.txt" |
---|
157 | #define NIC_TX_NAME "giet_vm/nic/tx_data.txt" |
---|
158 | #define NIC_TIMEOUT 10000 |
---|
159 | |
---|
160 | //////////////////////////////////////////////////////////// |
---|
161 | // Software to be loaded in ROM & RAM |
---|
162 | //////////////////////i///////////////////////////////////// |
---|
163 | |
---|
164 | #define BOOT_SOFT_NAME "giet_vm/soft.elf" |
---|
165 | |
---|
166 | //////////////////////////////////////////////////////////// |
---|
167 | // DEBUG Parameters default values |
---|
168 | //////////////////////i///////////////////////////////////// |
---|
169 | |
---|
170 | #define MAX_FROZEN_CYCLES 10000 |
---|
171 | |
---|
172 | #define TRACE_MEMC_ID 0 |
---|
173 | #define TRACE_PROC_ID 1000000 |
---|
174 | |
---|
175 | ///////////////////////////////////////////////////////// |
---|
176 | // Physical segments definition |
---|
177 | ///////////////////////////////////////////////////////// |
---|
178 | // There is 3 segments replicated in all clusters |
---|
179 | // and 5 specific segments in the "IO" cluster |
---|
180 | // (containing address 0xBF000000) |
---|
181 | ///////////////////////////////////////////////////////// |
---|
182 | |
---|
183 | // specific segments in "IO" cluster : absolute physical address |
---|
184 | |
---|
185 | #define BROM_BASE 0xBFC00000 |
---|
186 | #define BROM_SIZE 0x00100000 // 1 Mbytes |
---|
187 | |
---|
188 | #define FBUF_BASE 0xBFD00000 |
---|
189 | #define FBUF_SIZE 0x00200000 // 2 Mbytes |
---|
190 | |
---|
191 | #define BDEV_BASE 0xBFF10000 |
---|
192 | #define BDEV_SIZE 0x00001000 // 4 Kbytes |
---|
193 | |
---|
194 | #define MTTY_BASE 0xBFF20000 |
---|
195 | #define MTTY_SIZE 0x00001000 // 4 Kbytes |
---|
196 | |
---|
197 | #define MNIC_BASE 0xBFF80000 |
---|
198 | #define MNIC_SIZE 0x00002000 * (NB_NICS + 1) // 8 Kbytes per channel + 8 Kbytes |
---|
199 | |
---|
200 | // replicated segments : address is incremented by a cluster offset |
---|
201 | // offset = cluster(x,y) << (address_width-x_width-y_width); |
---|
202 | |
---|
203 | #define MEMC_BASE 0x00000000 |
---|
204 | #define MEMC_SIZE 0x00C00000 // 12 Mbytes |
---|
205 | |
---|
206 | #define XICU_BASE 0x00F00000 |
---|
207 | #define XICU_SIZE 0x00001000 // 4 Kbytes |
---|
208 | |
---|
209 | #define CDMA_BASE 0x00F30000 |
---|
210 | #define CDMA_SIZE 0x00001000 * NB_DMAS_MAX // 4 Kbytes per channel |
---|
211 | |
---|
212 | //////////////////////////////////////////////////////////////////// |
---|
213 | // TGTID definition in direct space |
---|
214 | // For all components: global TGTID = global SRCID = cluster_index |
---|
215 | //////////////////////////////////////////////////////////////////// |
---|
216 | |
---|
217 | #define MEMC_TGTID 0 |
---|
218 | #define XICU_TGTID 1 |
---|
219 | #define CDMA_TGTID 2 |
---|
220 | #define MTTY_TGTID 3 |
---|
221 | #define FBUF_TGTID 4 |
---|
222 | #define BROM_TGTID 5 |
---|
223 | #define BDEV_TGTID 6 |
---|
224 | #define MNIC_TGTID 7 |
---|
225 | |
---|
226 | ///////////////////////////////// |
---|
227 | int _main(int argc, char *argv[]) |
---|
228 | { |
---|
229 | using namespace sc_core; |
---|
230 | using namespace soclib::caba; |
---|
231 | using namespace soclib::common; |
---|
232 | |
---|
233 | |
---|
234 | char soft_name[256] = BOOT_SOFT_NAME; // pathname to binary code |
---|
235 | size_t ncycles = 1000000000; // simulated cycles |
---|
236 | char disk_name[256] = BDEV_IMAGE_NAME; // pathname to the disk image |
---|
237 | char nic_rx_name[256] = NIC_RX_NAME; // pathname to the rx packets file |
---|
238 | char nic_tx_name[256] = NIC_TX_NAME; // pathname to the tx packets file |
---|
239 | ssize_t threads_nr = 1; // simulator's threads number |
---|
240 | bool debug_ok = false; // trace activated |
---|
241 | size_t debug_period = 1; // trace period |
---|
242 | size_t debug_memc_id = TRACE_MEMC_ID; // index of memc to be traced (cluster_id) |
---|
243 | size_t debug_proc_id = TRACE_PROC_ID; // index of proc to be traced |
---|
244 | uint32_t debug_from = 0; // trace start cycle |
---|
245 | uint32_t frozen_cycles = MAX_FROZEN_CYCLES; // monitoring frozen processor |
---|
246 | |
---|
247 | ////////////// command line arguments ////////////////////// |
---|
248 | if (argc > 1) |
---|
249 | { |
---|
250 | for (int n = 1; n < argc; n = n + 2) |
---|
251 | { |
---|
252 | if ((strcmp(argv[n],"-NCYCLES") == 0) && (n+1<argc)) |
---|
253 | { |
---|
254 | ncycles = atoi(argv[n+1]); |
---|
255 | } |
---|
256 | else if ((strcmp(argv[n],"-SOFT") == 0) && (n+1<argc) ) |
---|
257 | { |
---|
258 | strcpy(soft_name, argv[n+1]); |
---|
259 | } |
---|
260 | else if ((strcmp(argv[n],"-DISK") == 0) && (n+1<argc) ) |
---|
261 | { |
---|
262 | strcpy(disk_name, argv[n+1]); |
---|
263 | } |
---|
264 | else if ((strcmp(argv[n],"-DEBUG") == 0) && (n+1<argc) ) |
---|
265 | { |
---|
266 | debug_ok = true; |
---|
267 | debug_from = atoi(argv[n+1]); |
---|
268 | } |
---|
269 | else if ((strcmp(argv[n],"-MEMCID") == 0) && (n+1<argc) ) |
---|
270 | { |
---|
271 | debug_memc_id = atoi(argv[n+1]); |
---|
272 | assert( (debug_memc_id < (CLUSTER_X*CLUSTER_Y) ) && |
---|
273 | "debug_memc_id larger than XMAX * YMAX" ); |
---|
274 | } |
---|
275 | else if ((strcmp(argv[n],"-PROCID") == 0) && (n+1<argc) ) |
---|
276 | { |
---|
277 | debug_proc_id = atoi(argv[n+1]); |
---|
278 | assert( (debug_proc_id < (CLUSTER_X * CLUSTER_Y * NB_PROCS_MAX) ) && |
---|
279 | "debug_proc_id larger than XMAX * YMAX * NB_PROCS" ); |
---|
280 | } |
---|
281 | else if ((strcmp(argv[n], "-THREADS") == 0) && ((n+1) < argc)) |
---|
282 | { |
---|
283 | threads_nr = atoi(argv[n+1]); |
---|
284 | threads_nr = (threads_nr < 1) ? 1 : threads_nr; |
---|
285 | } |
---|
286 | else if ((strcmp(argv[n], "-FROZEN") == 0) && (n+1 < argc)) |
---|
287 | { |
---|
288 | frozen_cycles = atoi(argv[n+1]); |
---|
289 | } |
---|
290 | else if ((strcmp(argv[n], "-PERIOD") == 0) && (n+1 < argc)) |
---|
291 | { |
---|
292 | debug_period = atoi(argv[n+1]); |
---|
293 | } |
---|
294 | else |
---|
295 | { |
---|
296 | std::cout << " Arguments on the command line are (key,value) couples." << std::endl; |
---|
297 | std::cout << " The order is not important." << std::endl; |
---|
298 | std::cout << " Accepted arguments are :" << std::endl << std::endl; |
---|
299 | std::cout << " -SOFT pathname_for_embedded_soft" << std::endl; |
---|
300 | std::cout << " -DISK pathname_for_disk_image" << std::endl; |
---|
301 | std::cout << " -NCYCLES number_of_simulated_cycles" << std::endl; |
---|
302 | std::cout << " -DEBUG debug_start_cycle" << std::endl; |
---|
303 | std::cout << " -THREADS simulator's threads number" << std::endl; |
---|
304 | std::cout << " -FROZEN max_number_of_lines" << std::endl; |
---|
305 | std::cout << " -PERIOD number_of_cycles between trace" << std::endl; |
---|
306 | std::cout << " -MEMCID index_memc_to_be_traced" << std::endl; |
---|
307 | std::cout << " -PROCID index_proc_to_be_traced" << std::endl; |
---|
308 | exit(0); |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | // checking hardware parameters |
---|
314 | assert( ( (CLUSTER_X == 1) or (CLUSTER_X == 2) or (CLUSTER_X == 4) or |
---|
315 | (CLUSTER_X == 8) or (CLUSTER_X == 16) ) and |
---|
316 | "The CLUSTER_X parameter must be 1, 2, 4, 8 or 16" ); |
---|
317 | |
---|
318 | assert( ( (CLUSTER_Y == 1) or (CLUSTER_Y == 2) or (CLUSTER_Y == 4) or |
---|
319 | (CLUSTER_Y == 8) or (CLUSTER_Y == 16) ) and |
---|
320 | "The CLUSTER_Y parameter must be 1, 2, 4, 8 or 16" ); |
---|
321 | |
---|
322 | assert( ( (NB_PROCS_MAX == 1) or (NB_PROCS_MAX == 2) or |
---|
323 | (NB_PROCS_MAX == 4) or (NB_PROCS_MAX == 8) ) and |
---|
324 | "The NB_PROCS_MAX parameter must be 1, 2, 4 or 8" ); |
---|
325 | |
---|
326 | assert( (NB_DMAS_MAX < 9) and |
---|
327 | "The NB_DMAS_MAX parameter must be smaller than 9" ); |
---|
328 | |
---|
329 | assert( (NB_TTYS < 15) and |
---|
330 | "The NB_TTYS parameter must be smaller than 15" ); |
---|
331 | |
---|
332 | assert( (NB_NICS < 9) and |
---|
333 | "The NB_NICS parameter must be smaller than 9" ); |
---|
334 | |
---|
335 | std::cout << std::endl; |
---|
336 | std::cout << " - CLUSTER_X = " << CLUSTER_X << std::endl; |
---|
337 | std::cout << " - CLUSTER_Y = " << CLUSTER_Y << std::endl; |
---|
338 | std::cout << " - NB_PROCS_MAX = " << NB_PROCS_MAX << std::endl; |
---|
339 | std::cout << " - NB_DMAS_MAX = " << NB_DMAS_MAX << std::endl; |
---|
340 | std::cout << " - NB_TTYS = " << NB_TTYS << std::endl; |
---|
341 | std::cout << " - NB_NICS = " << NB_NICS << std::endl; |
---|
342 | std::cout << " - MEMC_WAYS = " << MEMC_WAYS << std::endl; |
---|
343 | std::cout << " - MEMC_SETS = " << MEMC_SETS << std::endl; |
---|
344 | std::cout << " - RAM_LATENCY = " << XRAM_LATENCY << std::endl; |
---|
345 | std::cout << " - MAX_FROZEN = " << frozen_cycles << std::endl; |
---|
346 | |
---|
347 | std::cout << std::endl; |
---|
348 | |
---|
349 | #if USE_OPENMP |
---|
350 | omp_set_dynamic(false); |
---|
351 | omp_set_num_threads(threads_nr); |
---|
352 | std::cerr << "Built with openmp version " << _OPENMP << std::endl; |
---|
353 | #endif |
---|
354 | |
---|
355 | // Define VCI parameters |
---|
356 | typedef soclib::caba::VciParams<cell_width, |
---|
357 | plen_width, |
---|
358 | address_width, |
---|
359 | error_width, |
---|
360 | clen_width, |
---|
361 | rflag_width, |
---|
362 | srcid_width, |
---|
363 | pktid_width, |
---|
364 | trdid_width, |
---|
365 | wrplen_width> vci_param; |
---|
366 | |
---|
367 | // Define parameters depending on mesh size |
---|
368 | size_t cluster_io_id; |
---|
369 | size_t x_width; |
---|
370 | size_t y_width; |
---|
371 | |
---|
372 | if (CLUSTER_X == 1) x_width = 0; |
---|
373 | else if (CLUSTER_X == 2) x_width = 1; |
---|
374 | else if (CLUSTER_X <= 4) x_width = 2; |
---|
375 | else if (CLUSTER_X <= 8) x_width = 3; |
---|
376 | else x_width = 4; |
---|
377 | |
---|
378 | if (CLUSTER_Y == 1) y_width = 0; |
---|
379 | else if (CLUSTER_Y == 2) y_width = 1; |
---|
380 | else if (CLUSTER_Y <= 4) y_width = 2; |
---|
381 | else if (CLUSTER_Y <= 8) y_width = 3; |
---|
382 | else y_width = 4; |
---|
383 | |
---|
384 | cluster_io_id = 0xBF >> (8 - x_width - y_width); |
---|
385 | |
---|
386 | ///////////////////// |
---|
387 | // Mapping Tables |
---|
388 | ///////////////////// |
---|
389 | |
---|
390 | // direct network |
---|
391 | MappingTable maptabd(address_width, |
---|
392 | IntTab(x_width + y_width, 16 - x_width - y_width), |
---|
393 | IntTab(x_width + y_width, srcid_width - x_width - y_width), |
---|
394 | 0x00FF0000); |
---|
395 | |
---|
396 | for (size_t x = 0; x < CLUSTER_X; x++) |
---|
397 | { |
---|
398 | for (size_t y = 0; y < CLUSTER_Y; y++) |
---|
399 | { |
---|
400 | sc_uint<address_width> offset = cluster(x,y) << (address_width-x_width-y_width); |
---|
401 | |
---|
402 | std::ostringstream sh; |
---|
403 | sh << "d_seg_memc_" << x << "_" << y; |
---|
404 | maptabd.add(Segment(sh.str(), MEMC_BASE+offset, MEMC_SIZE, IntTab(cluster(x,y),MEMC_TGTID), true)); |
---|
405 | |
---|
406 | std::ostringstream si; |
---|
407 | si << "d_seg_xicu_" << x << "_" << y; |
---|
408 | maptabd.add(Segment(si.str(), XICU_BASE+offset, XICU_SIZE, IntTab(cluster(x,y),XICU_TGTID), false)); |
---|
409 | |
---|
410 | std::ostringstream sd; |
---|
411 | sd << "d_seg_mdma_" << x << "_" << y; |
---|
412 | maptabd.add(Segment(sd.str(), CDMA_BASE+offset, CDMA_SIZE, IntTab(cluster(x,y),CDMA_TGTID), false)); |
---|
413 | |
---|
414 | if ( cluster(x,y) == cluster_io_id ) |
---|
415 | { |
---|
416 | maptabd.add(Segment("d_seg_mtty", MTTY_BASE, MTTY_SIZE, IntTab(cluster(x,y),MTTY_TGTID), false)); |
---|
417 | maptabd.add(Segment("d_seg_fbuf", FBUF_BASE, FBUF_SIZE, IntTab(cluster(x,y),FBUF_TGTID), false)); |
---|
418 | maptabd.add(Segment("d_seg_bdev", BDEV_BASE, BDEV_SIZE, IntTab(cluster(x,y),BDEV_TGTID), false)); |
---|
419 | maptabd.add(Segment("d_seg_mnic", MNIC_BASE, MNIC_SIZE, IntTab(cluster(x,y),MNIC_TGTID), false)); |
---|
420 | maptabd.add(Segment("d_seg_brom", BROM_BASE, BROM_SIZE, IntTab(cluster(x,y),BROM_TGTID), true)); |
---|
421 | } |
---|
422 | } |
---|
423 | } |
---|
424 | std::cout << maptabd << std::endl; |
---|
425 | |
---|
426 | // coherence network |
---|
427 | // - tgtid_c_proc = srcid_c_proc = local procid |
---|
428 | // - tgtid_c_memc = srcid_c_memc = NB_PROCS_MAX |
---|
429 | MappingTable maptabc(address_width, |
---|
430 | IntTab(x_width + y_width, srcid_width - x_width - y_width), |
---|
431 | IntTab(x_width + y_width, srcid_width - x_width - y_width), |
---|
432 | 0x00FF0000); |
---|
433 | |
---|
434 | for (size_t x = 0; x < CLUSTER_X; x++) |
---|
435 | { |
---|
436 | for (size_t y = 0; y < CLUSTER_Y; y++) |
---|
437 | { |
---|
438 | sc_uint<address_width> offset = cluster(x,y) << (address_width-x_width-y_width); |
---|
439 | |
---|
440 | // cleanup requests must be routed to the memory cache |
---|
441 | std::ostringstream sh; |
---|
442 | sh << "c_seg_memc_" << x << "_" << y; |
---|
443 | maptabc.add(Segment(sh.str(), (NB_PROCS_MAX << (address_width - srcid_width)) + offset, |
---|
444 | 0x10, IntTab(cluster(x,y), NB_PROCS_MAX), false)); |
---|
445 | |
---|
446 | // update & invalidate requests must be routed to the proper processor |
---|
447 | for ( size_t p = 0 ; p < NB_PROCS_MAX ; p++) |
---|
448 | { |
---|
449 | std::ostringstream sp; |
---|
450 | sp << "c_seg_proc_" << x << "_" << y << "_" << p; |
---|
451 | maptabc.add( Segment( sp.str() , (p << (address_width - srcid_width)) + offset , |
---|
452 | 0x10 , IntTab(cluster(x,y), p) , false)); |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | std::cout << maptabc << std::endl; |
---|
457 | |
---|
458 | // external network |
---|
459 | MappingTable maptabx(address_width, IntTab(1), IntTab(x_width+y_width), 0xF0000000); |
---|
460 | |
---|
461 | for (size_t x = 0; x < CLUSTER_X; x++) |
---|
462 | { |
---|
463 | for (size_t y = 0; y < CLUSTER_Y ; y++) |
---|
464 | { |
---|
465 | sc_uint<address_width> offset = cluster(x,y) << (address_width-x_width-y_width); |
---|
466 | std::ostringstream sh; |
---|
467 | sh << "x_seg_memc_" << x << "_" << y; |
---|
468 | maptabx.add(Segment(sh.str(), MEMC_BASE+offset, |
---|
469 | MEMC_SIZE, IntTab(cluster(x,y)), false)); |
---|
470 | } |
---|
471 | } |
---|
472 | std::cout << maptabx << std::endl; |
---|
473 | |
---|
474 | //////////////////// |
---|
475 | // Signals |
---|
476 | /////////////////// |
---|
477 | |
---|
478 | sc_clock signal_clk("clk"); |
---|
479 | sc_signal<bool> signal_resetn("resetn"); |
---|
480 | |
---|
481 | // Horizontal inter-clusters DSPIN signals |
---|
482 | DspinSignals<cmd_width>*** signal_dspin_h_cmd_inc = |
---|
483 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_h_cmd_inc", CLUSTER_X-1, CLUSTER_Y, 2); |
---|
484 | DspinSignals<cmd_width>*** signal_dspin_h_cmd_dec = |
---|
485 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_h_cmd_dec", CLUSTER_X-1, CLUSTER_Y, 2); |
---|
486 | DspinSignals<rsp_width>*** signal_dspin_h_rsp_inc = |
---|
487 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_h_rsp_inc", CLUSTER_X-1, CLUSTER_Y, 2); |
---|
488 | DspinSignals<rsp_width>*** signal_dspin_h_rsp_dec = |
---|
489 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_h_rsp_dec", CLUSTER_X-1, CLUSTER_Y, 2); |
---|
490 | |
---|
491 | // Vertical inter-clusters DSPIN signals |
---|
492 | DspinSignals<cmd_width>*** signal_dspin_v_cmd_inc = |
---|
493 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_v_cmd_inc", CLUSTER_X, CLUSTER_Y-1, 2); |
---|
494 | DspinSignals<cmd_width>*** signal_dspin_v_cmd_dec = |
---|
495 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_v_cmd_dec", CLUSTER_X, CLUSTER_Y-1, 2); |
---|
496 | DspinSignals<rsp_width>*** signal_dspin_v_rsp_inc = |
---|
497 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_v_rsp_inc", CLUSTER_X, CLUSTER_Y-1, 2); |
---|
498 | DspinSignals<rsp_width>*** signal_dspin_v_rsp_dec = |
---|
499 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_v_rsp_dec", CLUSTER_X, CLUSTER_Y-1, 2); |
---|
500 | |
---|
501 | // Mesh boundaries DSPIN signals |
---|
502 | DspinSignals<cmd_width>**** signal_dspin_false_cmd_in = |
---|
503 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_false_cmd_in", CLUSTER_X, CLUSTER_Y, 2, 4); |
---|
504 | DspinSignals<cmd_width>**** signal_dspin_false_cmd_out = |
---|
505 | alloc_elems<DspinSignals<cmd_width> >("signal_dspin_false_cmd_out", CLUSTER_X, CLUSTER_Y, 2, 4); |
---|
506 | DspinSignals<rsp_width>**** signal_dspin_false_rsp_in = |
---|
507 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_false_rsp_in", CLUSTER_X, CLUSTER_Y, 2, 4); |
---|
508 | DspinSignals<rsp_width>**** signal_dspin_false_rsp_out = |
---|
509 | alloc_elems<DspinSignals<rsp_width> >("signal_dspin_false_rsp_out", CLUSTER_X, CLUSTER_Y, 2, 4); |
---|
510 | |
---|
511 | |
---|
512 | //////////////////////////// |
---|
513 | // Loader |
---|
514 | //////////////////////////// |
---|
515 | |
---|
516 | #if USE_ALMOS |
---|
517 | soclib::common::Loader loader(almos_bootloader_pathname, |
---|
518 | almos_archinfo_pathname, |
---|
519 | almos_kernel_pathname); |
---|
520 | #else |
---|
521 | soclib::common::Loader loader(soft_name); |
---|
522 | #endif |
---|
523 | |
---|
524 | typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss; |
---|
525 | proc_iss::set_loader(loader); |
---|
526 | |
---|
527 | //////////////////////////// |
---|
528 | // Clusters construction |
---|
529 | //////////////////////////// |
---|
530 | |
---|
531 | TsarClusterMmu<vci_param, proc_iss, cmd_width, rsp_width>* clusters[CLUSTER_X][CLUSTER_Y]; |
---|
532 | |
---|
533 | #if USE_OPENMP |
---|
534 | #pragma omp parallel |
---|
535 | { |
---|
536 | #pragma omp for |
---|
537 | #endif |
---|
538 | for(size_t i = 0; i < (CLUSTER_X * CLUSTER_Y); i++) |
---|
539 | { |
---|
540 | size_t x = i / CLUSTER_Y; |
---|
541 | size_t y = i % CLUSTER_Y; |
---|
542 | |
---|
543 | #if USE_OPENMP |
---|
544 | #pragma omp critical |
---|
545 | { |
---|
546 | #endif |
---|
547 | std::ostringstream sc; |
---|
548 | sc << "cluster_" << x << "_" << y; |
---|
549 | clusters[x][y] = new TsarClusterMmu<vci_param, proc_iss, cmd_width, rsp_width> |
---|
550 | ( |
---|
551 | sc.str().c_str(), |
---|
552 | NB_PROCS_MAX, |
---|
553 | NB_TTYS, |
---|
554 | NB_DMAS_MAX, |
---|
555 | x, |
---|
556 | y, |
---|
557 | cluster(x,y), |
---|
558 | maptabd, |
---|
559 | maptabc, |
---|
560 | maptabx, |
---|
561 | x_width, |
---|
562 | y_width, |
---|
563 | MEMC_TGTID, |
---|
564 | XICU_TGTID, |
---|
565 | CDMA_TGTID, |
---|
566 | FBUF_TGTID, |
---|
567 | MTTY_TGTID, |
---|
568 | BROM_TGTID, |
---|
569 | MNIC_TGTID, |
---|
570 | BDEV_TGTID, |
---|
571 | MEMC_WAYS, |
---|
572 | MEMC_SETS, |
---|
573 | L1_IWAYS, |
---|
574 | L1_ISETS, |
---|
575 | L1_DWAYS, |
---|
576 | L1_DSETS, |
---|
577 | XRAM_LATENCY, |
---|
578 | (cluster(x,y) == cluster_io_id), |
---|
579 | FBUF_X_SIZE, |
---|
580 | FBUF_Y_SIZE, |
---|
581 | disk_name, |
---|
582 | BDEV_SECTOR_SIZE, |
---|
583 | NB_NICS, |
---|
584 | nic_rx_name, |
---|
585 | nic_tx_name, |
---|
586 | NIC_TIMEOUT, |
---|
587 | loader, |
---|
588 | frozen_cycles, |
---|
589 | debug_from, |
---|
590 | debug_ok and (cluster(x,y) == debug_memc_id), |
---|
591 | debug_ok and (cluster(x,y) == debug_proc_id) |
---|
592 | ); |
---|
593 | |
---|
594 | std::cout << "cluster_" << x << "_" << y << " constructed" << std::endl; |
---|
595 | #if USE_OPENMP |
---|
596 | } // end critical |
---|
597 | #endif |
---|
598 | } // end for |
---|
599 | #if USE_OPENMP |
---|
600 | } |
---|
601 | #endif |
---|
602 | |
---|
603 | /////////////////////////////////////////////////////////////// |
---|
604 | // Net-list |
---|
605 | /////////////////////////////////////////////////////////////// |
---|
606 | |
---|
607 | // Clock & RESET |
---|
608 | for (size_t x = 0; x < (CLUSTER_X); x++){ |
---|
609 | for (size_t y = 0; y < CLUSTER_Y; y++){ |
---|
610 | clusters[x][y]->p_clk (signal_clk); |
---|
611 | clusters[x][y]->p_resetn (signal_resetn); |
---|
612 | } |
---|
613 | } |
---|
614 | |
---|
615 | // Inter Clusters horizontal connections |
---|
616 | if (CLUSTER_X > 1){ |
---|
617 | for (size_t x = 0; x < (CLUSTER_X-1); x++){ |
---|
618 | for (size_t y = 0; y < CLUSTER_Y; y++){ |
---|
619 | for (size_t k = 0; k < 2; k++){ |
---|
620 | clusters[x][y]->p_cmd_out[k][EAST] (signal_dspin_h_cmd_inc[x][y][k]); |
---|
621 | clusters[x+1][y]->p_cmd_in[k][WEST] (signal_dspin_h_cmd_inc[x][y][k]); |
---|
622 | clusters[x][y]->p_cmd_in[k][EAST] (signal_dspin_h_cmd_dec[x][y][k]); |
---|
623 | clusters[x+1][y]->p_cmd_out[k][WEST] (signal_dspin_h_cmd_dec[x][y][k]); |
---|
624 | clusters[x][y]->p_rsp_out[k][EAST] (signal_dspin_h_rsp_inc[x][y][k]); |
---|
625 | clusters[x+1][y]->p_rsp_in[k][WEST] (signal_dspin_h_rsp_inc[x][y][k]); |
---|
626 | clusters[x][y]->p_rsp_in[k][EAST] (signal_dspin_h_rsp_dec[x][y][k]); |
---|
627 | clusters[x+1][y]->p_rsp_out[k][WEST] (signal_dspin_h_rsp_dec[x][y][k]); |
---|
628 | } |
---|
629 | } |
---|
630 | } |
---|
631 | } |
---|
632 | std::cout << std::endl << "Horizontal connections established" << std::endl; |
---|
633 | |
---|
634 | // Inter Clusters vertical connections |
---|
635 | if (CLUSTER_Y > 1) { |
---|
636 | for (size_t y = 0; y < (CLUSTER_Y-1); y++){ |
---|
637 | for (size_t x = 0; x < CLUSTER_X; x++){ |
---|
638 | for (size_t k = 0; k < 2; k++){ |
---|
639 | clusters[x][y]->p_cmd_out[k][NORTH] (signal_dspin_v_cmd_inc[x][y][k]); |
---|
640 | clusters[x][y+1]->p_cmd_in[k][SOUTH] (signal_dspin_v_cmd_inc[x][y][k]); |
---|
641 | clusters[x][y]->p_cmd_in[k][NORTH] (signal_dspin_v_cmd_dec[x][y][k]); |
---|
642 | clusters[x][y+1]->p_cmd_out[k][SOUTH] (signal_dspin_v_cmd_dec[x][y][k]); |
---|
643 | clusters[x][y]->p_rsp_out[k][NORTH] (signal_dspin_v_rsp_inc[x][y][k]); |
---|
644 | clusters[x][y+1]->p_rsp_in[k][SOUTH] (signal_dspin_v_rsp_inc[x][y][k]); |
---|
645 | clusters[x][y]->p_rsp_in[k][NORTH] (signal_dspin_v_rsp_dec[x][y][k]); |
---|
646 | clusters[x][y+1]->p_rsp_out[k][SOUTH] (signal_dspin_v_rsp_dec[x][y][k]); |
---|
647 | } |
---|
648 | } |
---|
649 | } |
---|
650 | } |
---|
651 | std::cout << "Vertical connections established" << std::endl; |
---|
652 | |
---|
653 | // East & West boundary cluster connections |
---|
654 | for (size_t y = 0; y < CLUSTER_Y; y++) |
---|
655 | { |
---|
656 | for (size_t k = 0; k < 2; k++) |
---|
657 | { |
---|
658 | clusters[0][y]->p_cmd_in[k][WEST] (signal_dspin_false_cmd_in[0][y][k][WEST]); |
---|
659 | clusters[0][y]->p_cmd_out[k][WEST] (signal_dspin_false_cmd_out[0][y][k][WEST]); |
---|
660 | clusters[0][y]->p_rsp_in[k][WEST] (signal_dspin_false_rsp_in[0][y][k][WEST]); |
---|
661 | clusters[0][y]->p_rsp_out[k][WEST] (signal_dspin_false_rsp_out[0][y][k][WEST]); |
---|
662 | |
---|
663 | clusters[CLUSTER_X-1][y]->p_cmd_in[k][EAST] (signal_dspin_false_cmd_in[CLUSTER_X-1][y][k][EAST]); |
---|
664 | clusters[CLUSTER_X-1][y]->p_cmd_out[k][EAST] (signal_dspin_false_cmd_out[CLUSTER_X-1][y][k][EAST]); |
---|
665 | clusters[CLUSTER_X-1][y]->p_rsp_in[k][EAST] (signal_dspin_false_rsp_in[CLUSTER_X-1][y][k][EAST]); |
---|
666 | clusters[CLUSTER_X-1][y]->p_rsp_out[k][EAST] (signal_dspin_false_rsp_out[CLUSTER_X-1][y][k][EAST]); |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | // North & South boundary clusters connections |
---|
671 | for (size_t x = 0; x < CLUSTER_X; x++) |
---|
672 | { |
---|
673 | for (size_t k = 0; k < 2; k++) |
---|
674 | { |
---|
675 | clusters[x][0]->p_cmd_in[k][SOUTH] (signal_dspin_false_cmd_in[x][0][k][SOUTH]); |
---|
676 | clusters[x][0]->p_cmd_out[k][SOUTH] (signal_dspin_false_cmd_out[x][0][k][SOUTH]); |
---|
677 | clusters[x][0]->p_rsp_in[k][SOUTH] (signal_dspin_false_rsp_in[x][0][k][SOUTH]); |
---|
678 | clusters[x][0]->p_rsp_out[k][SOUTH] (signal_dspin_false_rsp_out[x][0][k][SOUTH]); |
---|
679 | |
---|
680 | clusters[x][CLUSTER_Y-1]->p_cmd_in[k][NORTH] (signal_dspin_false_cmd_in[x][CLUSTER_Y-1][k][NORTH]); |
---|
681 | clusters[x][CLUSTER_Y-1]->p_cmd_out[k][NORTH] (signal_dspin_false_cmd_out[x][CLUSTER_Y-1][k][NORTH]); |
---|
682 | clusters[x][CLUSTER_Y-1]->p_rsp_in[k][NORTH] (signal_dspin_false_rsp_in[x][CLUSTER_Y-1][k][NORTH]); |
---|
683 | clusters[x][CLUSTER_Y-1]->p_rsp_out[k][NORTH] (signal_dspin_false_rsp_out[x][CLUSTER_Y-1][k][NORTH]); |
---|
684 | } |
---|
685 | } |
---|
686 | |
---|
687 | |
---|
688 | //////////////////////////////////////////////////////// |
---|
689 | // Simulation |
---|
690 | /////////////////////////////////////////////////////// |
---|
691 | |
---|
692 | sc_start(sc_core::sc_time(0, SC_NS)); |
---|
693 | signal_resetn = false; |
---|
694 | |
---|
695 | // network boundaries signals |
---|
696 | for (size_t x = 0; x < CLUSTER_X ; x++){ |
---|
697 | for (size_t y = 0; y < CLUSTER_Y ; y++){ |
---|
698 | for (size_t k = 0; k < 2; k++){ |
---|
699 | for (size_t a = 0; a < 4; a++){ |
---|
700 | signal_dspin_false_cmd_in[x][y][k][a].write = false; |
---|
701 | signal_dspin_false_cmd_in[x][y][k][a].read = true; |
---|
702 | signal_dspin_false_cmd_out[x][y][k][a].write = false; |
---|
703 | signal_dspin_false_cmd_out[x][y][k][a].read = true; |
---|
704 | |
---|
705 | signal_dspin_false_rsp_in[x][y][k][a].write = false; |
---|
706 | signal_dspin_false_rsp_in[x][y][k][a].read = true; |
---|
707 | signal_dspin_false_rsp_out[x][y][k][a].write = false; |
---|
708 | signal_dspin_false_rsp_out[x][y][k][a].read = true; |
---|
709 | } |
---|
710 | } |
---|
711 | } |
---|
712 | } |
---|
713 | |
---|
714 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
715 | signal_resetn = true; |
---|
716 | |
---|
717 | for (size_t n = 1; n < ncycles; n++) |
---|
718 | { |
---|
719 | |
---|
720 | if (debug_ok and (n > debug_from) and (n % debug_period == 0)) |
---|
721 | { |
---|
722 | std::cout << "****************** cycle " << std::dec << n ; |
---|
723 | std::cout << " ************************************************" << std::endl; |
---|
724 | |
---|
725 | //clusters[0][0]->memc->print_trace(); |
---|
726 | // trace proc[debug_proc_id] |
---|
727 | /* |
---|
728 | if ( debug_proc_id < (CLUSTER_X * CLUSTER_Y * NB_PROCS_MAX) ) |
---|
729 | { |
---|
730 | size_t proc_x = debug_proc_id / CLUSTER_Y; |
---|
731 | size_t proc_y = debug_proc_id % CLUSTER_Y; |
---|
732 | |
---|
733 | clusters[proc_x][proc_y]->proc[0]->print_trace(); |
---|
734 | |
---|
735 | clusters[proc_x][proc_y]->signal_vci_ini_d_proc[0].print_trace("proc_ini_d"); |
---|
736 | clusters[proc_x][proc_y]->signal_vci_ini_c_proc[0].print_trace("proc_ini_c"); |
---|
737 | clusters[proc_x][proc_y]->signal_vci_tgt_c_proc[0].print_trace("proc_tgt_c"); |
---|
738 | } |
---|
739 | |
---|
740 | // trace memc[debug_memc_id] |
---|
741 | if ( debug_memc_id < (CLUSTER_X * CLUSTER_Y) ) |
---|
742 | { |
---|
743 | size_t memc_x = debug_memc_id / CLUSTER_Y; |
---|
744 | size_t memc_y = debug_memc_id % CLUSTER_Y; |
---|
745 | |
---|
746 | clusters[memc_x][memc_y]->memc->print_trace(); |
---|
747 | |
---|
748 | clusters[memc_x][memc_y]->signal_vci_tgt_d_memc.print_trace("memc_tgt_d"); |
---|
749 | clusters[memc_x][memc_y]->signal_vci_ini_c_memc.print_trace("memc_ini_c"); |
---|
750 | clusters[memc_x][memc_y]->signal_vci_tgt_c_memc.print_trace("memc_tgt_c"); |
---|
751 | } |
---|
752 | |
---|
753 | // clusters[0][0]->signal_vci_tgt_d_xicu.print_trace("xicu_0_0"); |
---|
754 | // clusters[0][1]->signal_vci_tgt_d_xicu.print_trace("xicu_0_1"); |
---|
755 | // clusters[1][0]->signal_vci_tgt_d_xicu.print_trace("xicu_1_0"); |
---|
756 | // clusters[1][1]->signal_vci_tgt_d_xicu.print_trace("xicu_1_1"); |
---|
757 | |
---|
758 | // if ( clusters[1][1]->signal_irq_mdma[0].read() ) |
---|
759 | // std::cout << std::endl << " IRQ_DMA_1_1 activated" << std::endl; |
---|
760 | // if ( clusters[1][1]->signal_proc_it[0].read() ) |
---|
761 | // std::cout << " IRQ_PROC_1_1 activated" << std::endl << std::endl; |
---|
762 | |
---|
763 | // trace ioc component |
---|
764 | // size_t io_x = cluster_io_id / CLUSTER_Y; |
---|
765 | // size_t io_y = cluster_io_id % CLUSTER_Y; |
---|
766 | // clusters[io_x][io_y]->bdev->print_trace(); |
---|
767 | // clusters[io_x][io_y]->signal_vci_tgt_d_bdev.print_trace("bdev_1_0_tgt_d "); |
---|
768 | // clusters[io_x][io_y]->signal_vci_ini_d_bdev.print_trace("bdev_1_0_ini_d "); |
---|
769 | |
---|
770 | // clusters[1][1]->mdma->print_trace(); |
---|
771 | // clusters[1][1]->signal_vci_tgt_d_mdma.print_trace("mdma_1_1_tgt_d "); |
---|
772 | // clusters[1][1]->signal_vci_ini_d_mdma.print_trace("mdma_1_1_ini_d "); |
---|
773 | */ |
---|
774 | } |
---|
775 | |
---|
776 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
777 | } |
---|
778 | return EXIT_SUCCESS; |
---|
779 | } |
---|
780 | |
---|
781 | int sc_main (int argc, char *argv[]) |
---|
782 | { |
---|
783 | try { |
---|
784 | return _main(argc, argv); |
---|
785 | } catch (std::exception &e) { |
---|
786 | std::cout << e.what() << std::endl; |
---|
787 | } catch (...) { |
---|
788 | std::cout << "Unknown exception occured" << std::endl; |
---|
789 | throw; |
---|
790 | } |
---|
791 | return 1; |
---|
792 | } |
---|
793 | |
---|
794 | // Local Variables: |
---|
795 | // tab-width: 3 |
---|
796 | // c-basic-offset: 3 |
---|
797 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
798 | // indent-tabs-mode: nil |
---|
799 | // End: |
---|
800 | |
---|
801 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 |
---|