OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_verilator/] [simulator.cpp] - Blame information for rev 32

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 alirezamon
#include <stdlib.h>
2
#include <stdio.h>
3
#include <unistd.h>
4
#include <string.h>
5
 
6
 
7
 
8
 
9
#include <ctype.h>
10
#include <stdint.h>
11
 
12
#include <inttypes.h>
13
 
14
 
15
#include <verilated.h>          // Defines common routines
16
#include "Vrouter.h"               // From Verilating "router.v"
17
#include "Vnoc.h"
18
#include "Vtraffic.h"
19
 
20
 
21
 
22
 
23
#include "parameter.h"
24
//#include "traffic_tabel.h"
25
 
26
 
27
#define  NC             (NX*NY)
28
#define  RATIO_INIT             2
29
 
30
unsigned char FIXED_SRC_DST_PAIR;
31
 
32
unsigned char  Xw=0,Yw=0;
33
 
34
 
35
 
36
 
37
//Vrouter *router;
38
Vrouter                 *router[NC];                     // Instantiation of module
39
Vnoc                    *noc;
40
Vtraffic                *traffic[NC];
41
 
42
unsigned long int main_time = 0;     // Current simulation time
43
unsigned int saved_time = 0;
44
 
45
 
46
unsigned int total_pck_num=0;
47
unsigned int sum_clk_h2h,sum_clk_h2t;
48
 
49
double           sum_clk_per_hop;
50
const int  CC=(C==0)? 1 : C;
51
 
52
unsigned int total_pck_num_per_class[CC]={0};
53
unsigned int sum_clk_h2h_per_class[CC]={0};
54
unsigned int sum_clk_h2t_per_class[CC]={0};
55
double           sum_clk_per_hop_per_class[CC]={0};
56
unsigned int clk_counter;
57
unsigned int count_en;
58
unsigned int total_router;
59
 
60
 
61
 
62
 
63
 
64
 
65
char all_done=0;
66
 
67
unsigned int flit_counter =0;
68
 
69
char ratio=RATIO_INIT;
70
double first_avg_latency_flit,current_avg_latency_flit;
71
 
72
double sc_time_stamp ();
73
int pow2( int );
74
 
75
 
76
 
77
int reset,clk;
78
 
79
#if (STND_DEV_EN)
80
        #include <math.h>
81
        double       sum_clk_pow2=0;
82
        double       sum_clk_pow2_per_class[C]={0};
83
        double standard_dev( double , unsigned int, double);
84
#endif
85
 
86
void update_noc_statistic (
87
        unsigned int,
88
        unsigned int,
89
    unsigned int,
90
    unsigned int
91
);
92
 
93
 
94
void pck_dst_gen (
95
    unsigned int,
96
        unsigned int,
97
        unsigned int,
98
        unsigned int*,
99
        unsigned int*
100
);
101
 
102
unsigned char pck_class_in_gen(
103
         unsigned int
104
 
105
);
106
 
107
 
108
 
109
 
110
void print_statistic (char *);
111
void print_parameter();
112
 
113
 
114
void reset_all_register();
115
 
116
 
117
 
118
char * TRAFFIC;
119
 
120
int PACKET_SIZE;
121
int MAX_PCK_NUM;
122
int MAX_SIM_CLKs;
123
int inject_ratios[100];
124
int C0_p=100, C1_p=0, C2_p=0, C3_p=0;
125
 
126
 
127
int  HOTSPOT_PERCENTAGE;
128
int  HOTSPOT_NUM;
129
int  HOTSPOT_CORE_1, HOTSPOT_CORE_2, HOTSPOT_CORE_3, HOTSPOT_CORE_4,HOTSPOT_CORE_5;
130
 
131
void  usage(){
132
        printf(" ./simulator -t [Traffic Pattern]  -s  [PACKET_SIZE]  -n  [MAX_PCK_NUM]  c      [MAX_SIM_CLKs]   -i [INJECTION_RATIO] -p [class traffic ratios %]  -h[HOTSPOT info] \n");
133
        printf("      Traffic Pattern: \"HOTSPOT\" \"RANDOM\" \"TORNADO\" \"BIT_REVERSE\"  \"BIT_COMPLEMENT\"  \"TRANSPOSE1\"   \"TRANSPOSE2\"\n");
134
        printf("      PACKET_SIZE: packet size in flit\n ");
135
        printf("      MAX_PCK_NUM: total number of sent packets. Simulation will stop when total of sent packet by all nodes reach this number\n");
136
        printf("      MAX_SIM_CLKs: simulation clock limit. Simulation will stop when simulation clock number reach this value \n");
137
        printf("      INJECTION_RATIO: packet injection ratios");
138
        printf("      class traffic ratios %: The percentage of traffic injected for each class. represented in string whit each clas ratio is seprated by coma. \"n0,n1,n2..\" \n");
139
        printf("      HOTSPOT info: represented in a string with following format:  \"HOTSPOT_PERCENTAGE,HOTSOPT_NUM,HOTSPOT_CORE_1,HOTSPOT_CORE_2,HOTSPOT_CORE_3,HOTSPOT_CORE_4,HOTSPOT_CORE_5\" \n");
140
}
141
 
142
 
143
int parse_string ( char * str, int * array)
144
{
145
    int i=0;
146
    char *pt;
147
    pt = strtok (str,",");
148
    while (pt != NULL) {
149
        int a = atoi(pt);
150
        array[i]=a;
151
        i++;
152
        pt = strtok (NULL, ",");
153
    }
154
   return i;
155
}
156
 
157
void processArgs (int argc, char **argv )
158
{
159
   char c;
160
   int p;
161
   int array[10];
162
 
163
   /* don't want getopt to moan - I can do that just fine thanks! */
164
   opterr = 0;
165
   if (argc < 2)  usage();
166
   while ((c = getopt (argc, argv, "t:s:n:c:i:p:h:")) != -1)
167
      {
168
         switch (c)
169
            {
170
 
171
            case 't':
172
                        TRAFFIC=optarg;
173
                        break;
174
                case 's':
175
                        PACKET_SIZE=atoi(optarg);
176
                        break;
177
                case 'n':
178
                         MAX_PCK_NUM=atoi(optarg);
179
                         break;
180
                case 'c':
181
                         MAX_SIM_CLKs=atoi(optarg);
182
                         break;
183
                case 'i':
184
                         ratio=atoi(optarg);
185
                         break;
186
                case 'p':
187
                        p= parse_string (optarg, array);
188
                    C0_p=array[0];
189
                    C1_p=array[1];
190
                    C2_p=array[2];
191
                    C3_p=array[3];
192
                        break;
193
                case 'h':
194
                         p= parse_string (optarg, array);
195
                         HOTSPOT_PERCENTAGE=array[0];
196
                         HOTSPOT_NUM=array[1];
197
                         HOTSPOT_CORE_1=array[2];
198
                         HOTSPOT_CORE_2=array[3];
199
                         HOTSPOT_CORE_3=array[4];
200
                         HOTSPOT_CORE_4=array[5];
201
                         HOTSPOT_CORE_5=array[6];
202
 
203
                         break;
204
 
205
 
206
 
207
            case '?':
208
               if (isprint (optopt))
209
                  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
210
               else
211
                  fprintf (stderr,
212
                           "Unknown option character `\\x%x'.\n",
213
                           optopt);
214
            default:
215
               usage();
216
               exit(1);
217
            }
218
      }
219
}
220
 
221
 
222
int main(int argc, char** argv) {
223
        char change_injection_ratio=0,inject_done;
224
        int i,j,x,y;//,report_delay_counter=0;
225
        char file_name[100];
226
        char deafult_out[] = {"result"};
227
        char * out_file_name;
228
        unsigned int dest_x, dest_y;
229
        int flit_out_all_size = sizeof(router[0]->flit_out_all)/sizeof(router[0]->flit_out_all[0]);
230
        while((0x1<<Xw) < NX)Xw++; //log2
231
        while((0x1<<Yw) < NY)Yw++;
232
 
233
 
234
        processArgs ( argc,  argv );
235
 
236
 
237
        FIXED_SRC_DST_PAIR = strcmp (TRAFFIC,"RANDOM") &  strcmp(TRAFFIC,"HOTSPOT") & strcmp(TRAFFIC,"random") & strcmp(TRAFFIC,"hot spot");
238
 
239
 
240
 
241
 
242
 
243
 
244
        Verilated::commandArgs(argc, argv);   // Remember args
245
 
246
        for(i=0;i<NC;i++)        router[i]       = new Vrouter;             // Create instance
247
        noc                                                             = new Vnoc;
248
        for(i=0;i<NC;i++)        traffic[i]  = new Vtraffic;
249
 
250
 
251
        /********************
252
        *       initialize input
253
        *********************/
254
 
255
        reset=1;
256
        reset_all_register();
257
        noc->start_i=0;
258
 
259
        for(x=0;x<NX;x++)for(y=0;y<NY;y++){
260
                                        i=(y*NX)+x;
261
                                        router[i]->current_x            = x;
262
                                        router[i]->current_y            = y;
263
                                        traffic[i]->current_x           = x;
264
                                        traffic[i]->current_y           = y;
265
                                        traffic[i]->start=0;
266
                                        traffic[i]->pck_size_in=PACKET_SIZE;
267
                                        traffic[i]->ratio=ratio;
268
                                        traffic[i]->pck_class_in=  pck_class_in_gen( i);
269
                                        pck_dst_gen ( x,y,i, &dest_x, &dest_y);
270
                                        traffic[i]->dest_x= dest_x;
271
                                        traffic[i]->dest_y=dest_y;
272
 
273
        }
274
 
275
 
276
 
277
 
278
        main_time=0;
279
        print_parameter();
280
        printf("\n\n\n Flit injection ratio per router is =%d \n",ratio);
281
        //printf("\n\n\n delay= %u clk",router->delay);
282
        while (!Verilated::gotFinish()) {
283
 
284
                if (main_time-saved_time >= 10 ) {
285
                        reset = 0;
286
                }
287
 
288
                if(main_time == saved_time+21){ count_en=1; noc->start_i=1;}//for(i=0;i<NC;i++) traffic[i]->start=1;}
289
                if(main_time == saved_time+26) noc->start_i=0;// for(i=0;i<NC;i++) traffic[i]->start=0;
290
 
291
 
292
 
293
 
294
                if ((main_time % 4) == 0) {
295
                        clk = 1;       // Toggle clock
296
                        if(count_en) clk_counter++;
297
                        inject_done= ((total_pck_num >= MAX_PCK_NUM) || (clk_counter>= MAX_SIM_CLKs));
298
                        //if(inject_done) printf("clk_counter=========%d\n",clk_counter);
299
                        for(x=0;x<NX;x++)for(y=0;y<NY;y++)
300
                        {
301
                                i=(y*NX)+x;
302
                                // a packet has been received
303
                                if(traffic[i]->update & ~reset){
304
                                        update_noc_statistic (
305
                                                traffic[i]->time_stamp_h2h,
306
                                                traffic[i]->time_stamp_h2t,
307
                                                traffic[i]->distance,
308
                                                traffic[i]->pck_class_out
309
                                        ) ;
310
                                }
311
                                // the header flit has been sent out
312
                                if(traffic[i]->hdr_flit_sent ){
313
                                        traffic[i]->pck_class_in=  pck_class_in_gen( i);
314
                                        if(!FIXED_SRC_DST_PAIR){
315
                                                pck_dst_gen ( x,y,i, &dest_x, &dest_y);
316
                                                traffic[i]->dest_x= dest_x;
317
                                                traffic[i]->dest_y=dest_y;
318
                                        }
319
                                }
320
 
321
                                if(traffic[i]->flit_out_wr==1) flit_counter++;
322
 
323
                        }//for
324
                        if(inject_done) {
325
                                for(x=0;x<NX;x++)for(y=0;y<NY;y++) if(traffic[(y*NX)+x]->pck_number>0) total_router        =       total_router +1;
326
 
327
                                printf(" simulation clock cycles:%d\n",clk_counter);
328
                                printf(" total received flits:%d\n",flit_counter);
329
                                print_statistic(out_file_name);
330
                                change_injection_ratio = 1;
331
                                for(i=0;i<NC;i++) {
332
                                        router[i]->final();
333
                                        traffic[i]->final();
334
                                }
335
                                noc->final();
336
 
337
 
338
                                return 0;
339
                        }
340
 
341
 
342
 
343
                }//if
344
                else
345
                {
346
 
347
                        clk = 0;
348
                        noc->ni_flit_in_wr =0;
349
 
350
                        for(x=0;x<NX;x++)for(y=0;y<NY;y++){
351
                                i=(y*NX)+x;
352
 
353
 
354
                                router[i]->flit_in_we_all       = noc->router_flit_out_we_all[i];
355
                                router[i]->credit_in_all        = noc->router_credit_out_all[i];
356
                                router[i]->congestion_in_all    = noc->router_congestion_out_all[i];
357
                                for(j=0;j<flit_out_all_size;j++)router[i]->flit_in_all[j]        = noc->router_flit_out_all[i][j];
358
 
359
 
360
                                noc->router_flit_in_we_all[i]   =       router[i]->flit_out_we_all ;
361
                                noc->router_credit_in_all[i]    =       router[i]->credit_out_all;
362
                                noc->router_congestion_in_all[i]=       router[i]->congestion_out_all;
363
                                for(j=0;j<flit_out_all_size;j++) noc->router_flit_in_all[i][j]   = router[i]->flit_out_all[j] ;
364
 
365
                                traffic[i]->flit_in  = noc->ni_flit_out [i];
366
                                traffic[i]->credit_in= noc->ni_credit_out[i];
367
 
368
 
369
                                noc->ni_credit_in[i] = traffic[i]->credit_out;
370
                                noc->ni_flit_in [i]  = traffic[i]->flit_out;
371
 
372
                                if(traffic[i]->flit_out_wr) noc->ni_flit_in_wr = noc->ni_flit_in_wr | ((vluint64_t)1<<i);
373
 
374
                                traffic[i]->flit_in_wr= ((noc->ni_flit_out_wr >> i) & 0x01);
375
 
376
 
377
                        }//for
378
 
379
 
380
                }//else
381
                //if(main_time > 20 && main_time < 30 ) traffic->start=1; else traffic->start=0;
382
                //if(main_time == saved_time+25) router[0]->flit_in_we_all=0;
383
                //if((main_time % 250)==0) printf("router->all_done =%u\n",router->all_done);
384
 
385
 
386
                noc-> clk = clk;
387
                noc-> reset = reset;
388
 
389
 
390
                for(i=0;i<NC;i++)        {
391
                        traffic[i]->start=  ((noc->start_o >>i)&  0x01);
392
                        traffic[i]->reset= reset;
393
                        traffic[i]->clk = clk;
394
                        router[i]->reset= reset;
395
                        router[i]->clk= clk ;
396
 
397
                }
398
 
399
 
400
                noc->eval();
401
 
402
 
403
                for(i=0;i<NC;i++) {
404
                                router[i]->eval();
405
                                traffic[i]->eval();
406
 
407
                }
408
 
409
 
410
 
411
 
412
                //router[0]->eval();            // Evaluate model
413
                //printf("clk=%x\n",router->clk );
414
 
415
                main_time++;
416
                //getchar();   
417
 
418
 
419
        }
420
        for(i=0;i<NC;i++) {
421
                router[i]->final();
422
                traffic[i]->final();
423
        }               // Done simulating
424
        noc->final();
425
 
426
}
427
 
428
 
429
 
430
 
431
 
432
 
433
 
434
 
435
double sc_time_stamp () {       // Called by $time in Verilog
436
        return main_time;
437
}
438
 
439
int pow2( int num){
440
        int pw;
441
        pw= (0x1 << num);
442
        return pw;
443
}
444
 
445
 
446
 
447
/**********************************
448
 *
449
 *      update_noc_statistic
450
 *
451
 *
452
 *********************************/
453
 
454
 
455
 
456
void update_noc_statistic (
457
                unsigned int    clk_num_h2h,
458
                unsigned int    clk_num_h2t,
459
        unsigned int    distance,
460
        unsigned int    class_num
461
)
462
{
463
 
464
 
465
                        total_pck_num+=1;
466
                        //if((total_pck_num & 0Xffff )==0 ) printf("total_pck_num=%d\n",total_pck_num);
467
                        sum_clk_h2h+=clk_num_h2h;
468
                        sum_clk_h2t+=clk_num_h2t;
469
#if (STND_DEV_EN)
470
                        sum_clk_pow2+=(double)clk_num_h2h * (double) clk_num_h2h;
471
                        sum_clk_pow2_per_class[class_num]+=(double)clk_num_h2h * (double) clk_num_h2h;
472
#endif
473
 
474
                        sum_clk_per_hop+= ((double)clk_num_h2h/(double)distance);
475
                        total_pck_num_per_class[class_num]+=1;
476
                        sum_clk_h2h_per_class[class_num]+=clk_num_h2h ;
477
                        sum_clk_h2t_per_class[class_num]+=clk_num_h2t ;
478
                        sum_clk_per_hop_per_class[class_num]+= ((double)clk_num_h2h/(double)distance);
479
 
480
 
481
 
482
 
483
        }
484
 
485
/*************************
486
 *
487
 *              update
488
 *
489
 *
490
 ************************/
491
 
492
 
493
 
494
 
495
 
496
 
497
 
498
 
499
 
500
 
501
 
502
void print_statistic (char * out_file_name){
503
        double avg_latency_per_hop,  avg_latency_flit, avg_latency_pck, avg_throughput,min_avg_latency_per_class;
504
        int i;
505
#if (STND_DEV_EN)
506
        double  std_dev;
507
#endif
508
                                        char file_name[100];
509
                                        avg_throughput= ((double)(total_pck_num*PACKET_SIZE*100)/total_router )/clk_counter;
510
                                        printf(" Total active routers: %d \n",total_router);
511
                                        printf(" Avg throughput is: %f (flits/clk/node %%)\n",    avg_throughput);
512
                        avg_latency_flit   = (double)sum_clk_h2h/total_pck_num;
513
                        avg_latency_pck    = (double)sum_clk_h2t/total_pck_num;
514
                        if(ratio==RATIO_INIT) first_avg_latency_flit=avg_latency_flit;
515
#if (STND_DEV_EN)
516
                        std_dev= standard_dev( sum_clk_pow2,total_pck_num, avg_latency_flit);
517
                       // sprintf(file_name,"%s_std.txt",out_file_name);
518
                        //update_file( file_name,avg_throughput,std_dev);
519
 
520
#endif
521
                        avg_latency_per_hop    = (double)sum_clk_per_hop/total_pck_num;
522
                        printf   ("\nall : \n");
523
                      //  sprintf(file_name,"%s_all.txt",out_file_name);
524
                        //update_file(file_name ,ratio,avg_latency );
525
if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0){
526
                        printf(" Total number of packet = %d \n average latency per hop = %f \n average latency = %f\n",total_pck_num,avg_latency_per_hop,avg_latency_pck);
527
                      // update_file(file_name ,avg_throughput,avg_latency_pck);
528
 
529
}else{
530
                         printf(" Total number of packet = %d \n average latency per hop = %f \n average latency = %f\n",total_pck_num,avg_latency_per_hop,avg_latency_flit);
531
                     //   update_file(file_name ,avg_throughput,avg_latency_flit);
532
 
533
}
534
                        //fwrite(fp,"%d,%f,%f,%f,",total_pck_num,avg_latency_per_hop,avg_latency,max_latency_per_hop);
535
                        min_avg_latency_per_class=1000000;
536
                        for(i=0;i<C;i++){
537
                                avg_throughput           = (total_pck_num_per_class[i]>0)? ((double)(total_pck_num_per_class[i]*PACKET_SIZE*100)/total_router )/clk_counter:0;
538
                                                avg_latency_flit         = (total_pck_num_per_class[i]>0)? (double)sum_clk_h2h_per_class[i]/total_pck_num_per_class[i]:0;
539
                                                avg_latency_pck          = (total_pck_num_per_class[i]>0)? (double)sum_clk_h2t_per_class[i]/total_pck_num_per_class[i]:0;
540
                                                avg_latency_per_hop  = (total_pck_num_per_class[i]>0)? (double)sum_clk_per_hop_per_class[i]/total_pck_num_per_class[i]:0;
541
if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0){
542
                                                 printf  ("\nclass : %d  \n",i);
543
                            printf      (" Total number of packet  = %d \n avg_throughput = %f \n average latency per hop = %f \n average latency = %f\n",total_pck_num_per_class[i],avg_throughput,avg_latency_per_hop,avg_latency_pck);
544
                            //sprintf(file_name,"%s_c%u.txt",out_file_name,i);
545
                           // update_file( file_name,avg_throughput,avg_latency_pck );
546
}else{
547
 
548
printf   ("\nclass : %d  \n",i);
549
                            printf      (" Total number of packet  = %d \n avg_throughput = %f \n average latency per hop = %f \n average latency = %f\n",total_pck_num_per_class[i],avg_throughput,avg_latency_per_hop,avg_latency_flit);
550
                           // sprintf(file_name,"%s_c%u.txt",out_file_name,i);
551
                           // update_file( file_name,avg_throughput,avg_latency_flit );
552
 
553
 
554
 
555
 
556
}
557
                            if(min_avg_latency_per_class > avg_latency_flit) min_avg_latency_per_class=avg_latency_flit;
558
 
559
#if (STND_DEV_EN)
560
                            std_dev= (total_pck_num_per_class[i]>0)?  standard_dev( sum_clk_pow2_per_class[i],total_pck_num_per_class[i], avg_latency_flit):0;
561
                           // sprintf(file_name,"%s_std%u.txt",out_file_name,i);
562
                           // update_file( file_name,avg_throughput,std_dev);
563
 
564
#endif
565
 
566
 
567
                         }//for
568
                        current_avg_latency_flit=min_avg_latency_per_class;
569
 
570
 
571
 
572
 
573
}
574
 
575
void print_parameter (){
576
 
577
                printf ("Router parameters: \n");
578
                printf ("\tTopology: %s\n",TOPOLOGY);
579
                printf ("\tRouting algorithm: %s\n",ROUTE_NAME);
580
                printf ("\tVC_per port: %d\n", V);
581
                printf ("\tBuffer_width: %d\n", B);
582
            printf ("\tRouter num in row: %d \n",NX);
583
            printf ("\tRouter num in column: %d \n",NY);
584
            printf ("\tNumber of Class: %d\n", C);
585
            printf ("\tFlit data width: %d \n", Fpay);
586
            printf ("\tVC reallocation mechanism: %s \n",  VC_REALLOCATION_TYPE);
587
            printf ("\tVC/sw combination mechanism: %s \n", COMBINATION_TYPE);
588
            printf ("\troute-subfunction: %s \n", ROUTE_SUBFUNC );
589
            printf ("\tAVC_ATOMIC_EN:%d \n", AVC_ATOMIC_EN);
590
            printf ("\tCongestion Index:%d \n",CONGESTION_INDEX);
591
            printf ("\tADD_PIPREG_AFTER_CROSSBAR:%d\n",ADD_PIPREG_AFTER_CROSSBAR);
592
 
593
 
594
 
595
#if(DEBUG_EN)
596
            printf ("\tDebuging is enabled\n");
597
#else
598
            printf ("\tDebuging is disabled\n");
599
#endif
600
 
601
        printf ("Simulation parameters\n");
602
        if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0)printf ("\tOutput is the average latency on sending the packet head until receiving tail\n");
603
        else printf ("\tOutput is the average latency on sending the packet head until receiving the head\n");
604
        printf ("\tTraffic pattern:%s\n",TRAFFIC);
605
        if(C>0) printf ("\ttraffic percentage of class 0 is : %d\n", C0_p);
606
        if(C>1) printf ("\ttraffic percentage of class 1 is : %d\n", C1_p);
607
        if(C>2) printf ("\ttraffic percentage of class 2 is : %d\n", C2_p);
608
        if(C>3) printf ("\ttraffic percentage of class 3 is : %d\n", C3_p);
609
        if((strcmp (TRAFFIC,"HOTSPOT")==0)|| (strcmp (TRAFFIC,"hot spot")==0)){
610
                printf ("\tHot spot percentage: %u\n", HOTSPOT_PERCENTAGE);
611
            printf ("\tNumber of hot spot cores: %d\n", HOTSPOT_NUM);
612
 
613
        }
614
            //printf ("\tTotal packets sent by one router: %u\n", TOTAL_PKT_PER_ROUTER);
615
                printf ("\t Simulation timeout =%d\n", MAX_SIM_CLKs);
616
                printf ("\t Simulation ends on total packet num of =%d\n", MAX_PCK_NUM);
617
            printf ("\tPacket size: %u flits\n",PACKET_SIZE);
618
            printf ("\t SSA_EN enabled:%s \n",SSA_EN);
619
}
620
 
621
 
622
/************************
623
 *
624
 *      reset system
625
 *
626
 *
627
 * *******************/
628
 
629
void reset_all_register (void){
630
        int i;
631
 
632
 
633
 
634
         total_router=0;
635
         total_pck_num=0;
636
         sum_clk_h2h=0;
637
         sum_clk_h2t=0;
638
#if (STND_DEV_EN)
639
         sum_clk_pow2=0;
640
#endif
641
 
642
         sum_clk_per_hop=0;
643
         count_en=0;
644
         clk_counter=0;
645
 
646
         for(i=0;i<C;i++)
647
         {
648
                 total_pck_num_per_class[i]=0;
649
             sum_clk_h2h_per_class[i]=0;
650
             sum_clk_h2t_per_class[i]=0;
651
                 sum_clk_per_hop_per_class[i]=0;
652
#if (STND_DEV_EN)
653
                 sum_clk_pow2_per_class[i]=0;
654
#endif
655
 
656
         }  //for
657
         flit_counter=0;
658
}
659
 
660
 
661
 
662
 
663
/***********************
664
 *
665
 *      standard_dev
666
 *
667
 * ******************/
668
 
669
#if (STND_DEV_EN)
670
 
671
 
672
double standard_dev( double sum_pow2, unsigned int  total_num, double average){
673
        double std_dev;
674
 
675
        std_dev = sum_pow2/(double)total_num;
676
        std_dev -= (average*average);
677
        std_dev = sqrt(std_dev);
678
 
679
        return std_dev;
680
 
681
}
682
 
683
#endif
684
 
685
 
686
 
687
/**********************
688
 *
689
 *      pck_class_in_gen
690
 *
691
 * *****************/
692
 
693
unsigned char  pck_class_in_gen(
694
         unsigned int  core_num
695
 
696
) {
697
 
698
        unsigned char pck_class_in;
699
        unsigned char  rnd=rand()%100;
700
 
701
        pck_class_in=     ( rnd <    C0_p               )?  0:
702
                                  ( rnd <   (C0_p+C1_p) )?      1:
703
                                  ( rnd <   (C0_p+C1_p+C2_p))?2:3;
704
 
705
 
706
 
707
    return pck_class_in;
708
}
709
 
710
/**********************************
711
 
712
        pck_dst_gen
713
 
714
*********************************/
715
 
716
void pck_dst_gen (
717
    unsigned int current_x,
718
        unsigned int current_y,
719
        unsigned int core_num,
720
        unsigned int *dest_x,
721
        unsigned int *dest_y
722
){
723
 
724
 
725
        unsigned int rnd=0;
726
        unsigned int rnd100=0;
727
        int i;
728
 
729
 
730
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
731
 
732
                do{
733
                        rnd=rand()%NC;
734
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
735
 
736
       (*dest_y) = (rnd / NX );
737
           (*dest_x) = (rnd % NX );
738
 
739
 
740
        }
741
        else if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
742
 
743
                do{
744
                                rnd=rand()%NC;
745
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
746
 
747
                rnd100=rand()%100;
748
 
749
                if              (rnd100 < HOTSPOT_PERCENTAGE    && core_num !=HOTSPOT_CORE_1 )  rnd = HOTSPOT_CORE_1;
750
                else if((HOTSPOT_NUM > 1)       && (rnd100 >= 20 )      && (rnd100 < (20+HOTSPOT_PERCENTAGE)) && core_num!=HOTSPOT_CORE_2 )  rnd = HOTSPOT_CORE_2;
751
                else if((HOTSPOT_NUM > 2)       && (rnd100 >= 40)       && (rnd100 < (40+HOTSPOT_PERCENTAGE)) && core_num!=HOTSPOT_CORE_3 )  rnd = HOTSPOT_CORE_3;
752
                else if((HOTSPOT_NUM > 3)       && (rnd100 >= 60)       && (rnd100 < (60+HOTSPOT_PERCENTAGE)) && core_num!=HOTSPOT_CORE_4 )  rnd = HOTSPOT_CORE_4;
753
                else if((HOTSPOT_NUM > 4)       && (rnd100 >= 80)       && (rnd100 < (80+HOTSPOT_PERCENTAGE)) && core_num!=HOTSPOT_CORE_5 )  rnd = HOTSPOT_CORE_5;
754
 
755
 
756
 
757
                 (*dest_y) = (rnd / NX );
758
                 (*dest_x) = (rnd % NX );
759
 
760
 
761
        } else if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
762
 
763
                 (*dest_x) = NX-current_y-1;
764
                 (*dest_y) = NY-current_x-1;
765
 
766
 
767
 
768
        } else if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
769
                (*dest_x)   = current_y;
770
                (*dest_y)   = current_x;
771
 
772
 
773
        } else if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
774
                unsigned int joint_addr= (current_x<<Xw)+current_y;
775
                unsigned int reverse_addr=0;
776
                unsigned int pos=0;
777
                for(i=0; i<(Xw+Yw); i++){//reverse the address
778
                         pos= (((Xw+Yw)-1)-i);
779
                         reverse_addr|= ((joint_addr >> pos) & 0x01) << i;
780
                   // reverse_addr[i]  = joint_addr [((Xw+Yw)-1)-i];
781
                }
782
                (*dest_x)   = reverse_addr>>Yw;
783
                (*dest_y)   = reverse_addr&(0xFF>> (8-Yw));
784
 
785
 
786
 
787
 
788
         } else if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
789
 
790
                 (*dest_x)    = (~current_x) &(0xFF>> (8-Xw));
791
                 (*dest_y)    = (~current_y) &(0xFF>> (8-Yw));
792
 
793
 
794
     }  else if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
795
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
796
                 (*dest_x)    = ((current_x + ((NX/2)-1))%NX);
797
                 (*dest_y)    = ((current_y + ((NY/2)-1))%NY);
798
 
799
 
800
     }  else if( strcmp(TRAFFIC ,"CUSTOM") == 0){
801
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
802
                if(current_x ==0 && current_y == 0 ){
803
                 (*dest_x)    =  NX-1;
804
                 (*dest_y)    =  NY-1;
805
                }else{// make it unvalid
806
                 (*dest_x)    =  current_x;
807
                 (*dest_y)    =  current_y;
808
 
809
                }
810
 
811
     }
812
 
813
         else printf ("traffic %s is an unsupported traffic pattern\n",TRAFFIC);
814
 
815
}
816
 
817
 
818
 
819
 
820
 
821
 
822
 
823
 
824
 
825
 
826
 
827
 
828
 
829
 
830
 
831
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.