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