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 42

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 41 alirezamon
#include <limits.h>
6 32 alirezamon
#include <ctype.h>
7
#include <stdint.h>
8
#include <inttypes.h>
9
 
10
 
11
#include <verilated.h>          // Defines common routines
12
#include "Vrouter.h"               // From Verilating "router.v"
13
#include "Vnoc.h"
14
#include "Vtraffic.h"
15 38 alirezamon
#include "parameter.h"
16 32 alirezamon
 
17
 
18
 
19 41 alirezamon
#ifndef  NC 
20 32 alirezamon
#define  NC             (NX*NY)
21 38 alirezamon
#endif
22 41 alirezamon
 
23 32 alirezamon
#define  RATIO_INIT             2
24
 
25 38 alirezamon
#define SYNTHETIC 0
26
#define CUSTOM 1 
27
#define DISABLE -1
28 32 alirezamon
 
29 41 alirezamon
#define MY_VL_SETBIT_W(data,bit) (data[VL_BITWORD_I(bit)] |= (VL_UL(1) << VL_BITBIT_I(bit)))
30
 
31 38 alirezamon
#include "traffic_task_graph.h"
32 32 alirezamon
 
33 42 alirezamon
#define STND_DEV_EN 1
34 32 alirezamon
 
35
 
36
//Vrouter *router;
37
Vrouter                 *router[NC];                     // Instantiation of module
38
Vnoc                    *noc;
39
Vtraffic                *traffic[NC];
40
 
41 38 alirezamon
 
42
char * TRAFFIC;
43
unsigned char FIXED_SRC_DST_PAIR;
44
unsigned char  Xw=0,Yw=0;
45 32 alirezamon
unsigned long int main_time = 0;     // Current simulation time
46
unsigned int saved_time = 0;
47
unsigned int total_pck_num=0;
48
unsigned int sum_clk_h2h,sum_clk_h2t;
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 38 alirezamon
 
57
unsigned int rsvd_core_total_pck_num[NC]= {0};
58
unsigned int rsvd_core_worst_delay[NC] =  {0};
59
unsigned int sent_core_total_pck_num[NC]= {0};
60
unsigned int sent_core_worst_delay[NC] =  {0};
61
unsigned int random_var[NC] = {100};
62
 
63 32 alirezamon
unsigned int clk_counter;
64
unsigned int count_en;
65
unsigned int total_router;
66
 
67 38 alirezamon
int reset,clk;
68 32 alirezamon
 
69
char all_done=0;
70
 
71
unsigned int flit_counter =0;
72
 
73 38 alirezamon
int ratio=RATIO_INIT;
74 32 alirezamon
double first_avg_latency_flit,current_avg_latency_flit;
75
 
76
double sc_time_stamp ();
77
int pow2( int );
78
 
79
 
80
 
81
 
82 38 alirezamon
 
83 32 alirezamon
#if (STND_DEV_EN)
84 42 alirezamon
        //#include <math.h>
85
        double sqroot (double s){
86
                int i;
87
                double root = s/3;
88
                if (s<=0) return 0;
89
                for(i=0;i<32;i++) root = (root +s/root)/2;
90
                return root;
91
        }
92
 
93 32 alirezamon
        double       sum_clk_pow2=0;
94 42 alirezamon
        double       sum_clk_pow2_per_class[C];
95 32 alirezamon
        double standard_dev( double , unsigned int, double);
96
#endif
97
 
98
void update_noc_statistic (
99 38 alirezamon
        int
100 32 alirezamon
);
101
 
102
 
103
void pck_dst_gen (
104
    unsigned int,
105
        unsigned int,
106
        unsigned int,
107
        unsigned int*,
108
        unsigned int*
109
);
110
 
111
unsigned char pck_class_in_gen(
112
         unsigned int
113
 
114
);
115
 
116
 
117
 
118
 
119
void print_statistic (char *);
120
void print_parameter();
121 38 alirezamon
void reset_all_register();
122
unsigned int rnd_between (unsigned int, unsigned int );
123 32 alirezamon
 
124
 
125
 
126
 
127
 
128 38 alirezamon
 
129
 
130
int TRAFFIC_TYPE=SYNTHETIC;
131
int PACKET_SIZE=5;
132
int MIN_PACKET_SIZE=5;
133
int MAX_PACKET_SIZE=5;
134 32 alirezamon
int MAX_PCK_NUM;
135
int MAX_SIM_CLKs;
136 38 alirezamon
 
137 32 alirezamon
int C0_p=100, C1_p=0, C2_p=0, C3_p=0;
138
 
139
 
140
int  HOTSPOT_NUM;
141 38 alirezamon
typedef struct HOTSPOT_NODE {
142
        int  ip_num;
143
        char send_enable;
144
        int  percentage; // x10 
145
} hotspot_st;
146 32 alirezamon
 
147 38 alirezamon
hotspot_st * hotspots;
148
 
149
 
150
 
151
 
152
 
153 32 alirezamon
void  usage(){
154 38 alirezamon
        printf(" ./simulator -f [Traffic Pattern file]\n\nor\n");
155
 
156
 
157
        printf(" ./simulator -t [Traffic Pattern]  -s  [MIN_PCK_SIZE] -m [MAX_PCK_SIZE] -n  [MAX_PCK_NUM]  c    [MAX SIM CLKs]   -i [INJECTION RATIO] -p [class traffic ratios (%%)]  -h[HOTSPOT info] \n");
158 32 alirezamon
        printf("      Traffic Pattern: \"HOTSPOT\" \"RANDOM\" \"TORNADO\" \"BIT_REVERSE\"  \"BIT_COMPLEMENT\"  \"TRANSPOSE1\"   \"TRANSPOSE2\"\n");
159 38 alirezamon
        printf("      MIN_PCK_SIZE: Minimum packet size in flit. The injected packet size is randomly selected between minimum and maximum packet size\n ");
160
        printf("      MAX_PCK_SIZE: Maximum packet size in flit. The injected packet size is randomly selected between minimum and maximum packet size\n ");
161
 
162 32 alirezamon
        printf("      MAX_PCK_NUM: total number of sent packets. Simulation will stop when total of sent packet by all nodes reach this number\n");
163
        printf("      MAX_SIM_CLKs: simulation clock limit. Simulation will stop when simulation clock number reach this value \n");
164 38 alirezamon
        printf("      INJECTION_RATIO: packet injection ratio");
165
        printf("      class traffic ratios %%: The percentage of traffic injected for each class. represented in string whit each class ratio is separated by comma. \"n0,n1,n2..\" \n");
166
        printf("      hotspot traffic info: represented in a string with following format:  \"HOTSPOT PERCENTAGE,HOTSPOT NUM,HOTSPOT CORE 1,HOTSPOT CORE 2,HOTSPOT CORE 3,HOTSPOT CORE 4,HOTSPOT CORE 5, ENABLE HOTSPOT CORES SEND \"   \n");
167 32 alirezamon
}
168
 
169
 
170
int parse_string ( char * str, int * array)
171
{
172
    int i=0;
173
    char *pt;
174
    pt = strtok (str,",");
175
    while (pt != NULL) {
176
        int a = atoi(pt);
177
        array[i]=a;
178
        i++;
179
        pt = strtok (NULL, ",");
180
    }
181
   return i;
182
}
183
 
184 38 alirezamon
void update_hotspot(char * str){
185
         int i;
186
         int array[1000];
187
         int p;
188
         int acuum=0;
189
         hotspot_st * new_node;
190
         p= parse_string (str, array);
191
         if (p<4){
192
                        printf("Error in hotspot traffic parameters \n");
193
                        exit(1);
194
         }
195
         HOTSPOT_NUM=array[0];
196
         if (p<1+HOTSPOT_NUM*3){
197
                        printf("Error in hotspot traffic parameters \n");
198
                        exit(1);
199
         }
200
         new_node =  (hotspot_st *) malloc( HOTSPOT_NUM * sizeof(hotspot_st));
201
         if( new_node == NULL){
202
        printf("Error: cannot allocate memory for hotspot traffic\n");
203
            exit(1);
204
         }
205
         for (i=1;i<3*HOTSPOT_NUM; i+=3){
206
                new_node[i/3]. ip_num = array[i];
207
            new_node[i/3]. send_enable=array[i+1];
208
            new_node[i/3]. percentage =  acuum + array[i+2];
209
            acuum= new_node[i/3]. percentage;
210
 
211
         }
212
         if(acuum> 1000){
213
                        printf("Warning: The hotspot traffic summation %f exceed than 100 percent.  \n", (float) acuum /10);
214
 
215
         }
216
 
217
         hotspots=new_node;
218
}
219
 
220
 
221
 
222
 
223
 
224
 
225
 
226 32 alirezamon
void processArgs (int argc, char **argv )
227
{
228
   char c;
229
   int p;
230
   int array[10];
231 38 alirezamon
   float f;
232 32 alirezamon
 
233
   /* don't want getopt to moan - I can do that just fine thanks! */
234
   opterr = 0;
235
   if (argc < 2)  usage();
236 38 alirezamon
   while ((c = getopt (argc, argv, "t:s:m:n:c:i:p:h:f:")) != -1)
237 32 alirezamon
      {
238
         switch (c)
239
            {
240 38 alirezamon
                case 'f':
241
                        TRAFFIC_TYPE=CUSTOM;
242
                        TRAFFIC=(char *) "CUSTOM from file";
243
                        load_traffic_file(optarg,task_graph_data,task_graph_abstract);
244
                        MAX_PCK_NUM=task_graph_total_pck_num;
245
                        break;
246 32 alirezamon
            case 't':
247
                        TRAFFIC=optarg;
248 38 alirezamon
                        total_active_routers=-1;
249 32 alirezamon
                        break;
250
                case 's':
251 38 alirezamon
                        MIN_PACKET_SIZE=atoi(optarg);
252 32 alirezamon
                        break;
253 38 alirezamon
                case 'm':
254
                        MAX_PACKET_SIZE=atoi(optarg);
255
                        break;
256 32 alirezamon
                case 'n':
257
                         MAX_PCK_NUM=atoi(optarg);
258
                         break;
259
                case 'c':
260
                         MAX_SIM_CLKs=atoi(optarg);
261
                         break;
262 38 alirezamon
                case 'i':
263
                         f=atof(optarg);
264
                         f*=(MAX_RATIO/100);
265
                         ratio= (int) f;
266 32 alirezamon
                         break;
267
                case 'p':
268
                        p= parse_string (optarg, array);
269
                    C0_p=array[0];
270
                    C1_p=array[1];
271
                    C2_p=array[2];
272
                    C3_p=array[3];
273
                        break;
274 38 alirezamon
 
275 32 alirezamon
                case 'h':
276 38 alirezamon
 
277
                        update_hotspot(optarg);
278
 
279 32 alirezamon
 
280
                         break;
281
 
282
 
283
 
284
            case '?':
285
               if (isprint (optopt))
286
                  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
287
               else
288
                  fprintf (stderr,
289
                           "Unknown option character `\\x%x'.\n",
290
                           optopt);
291
            default:
292
               usage();
293
               exit(1);
294
            }
295
      }
296 38 alirezamon
   PACKET_SIZE=(MIN_PACKET_SIZE+MAX_PACKET_SIZE)/2;// average packet size
297 32 alirezamon
}
298
 
299
 
300
int main(int argc, char** argv) {
301
        char change_injection_ratio=0,inject_done;
302
        int i,j,x,y;//,report_delay_counter=0;
303
        char file_name[100];
304
        char deafult_out[] = {"result"};
305
        char * out_file_name;
306
        unsigned int dest_x, dest_y;
307
        int flit_out_all_size = sizeof(router[0]->flit_out_all)/sizeof(router[0]->flit_out_all[0]);
308
        while((0x1<<Xw) < NX)Xw++; //log2
309
        while((0x1<<Yw) < NY)Yw++;
310
 
311
 
312
        Verilated::commandArgs(argc, argv);   // Remember args
313
 
314
        for(i=0;i<NC;i++)        router[i]       = new Vrouter;             // Create instance
315
        noc                                                             = new Vnoc;
316
        for(i=0;i<NC;i++)        traffic[i]  = new Vtraffic;
317 38 alirezamon
 
318
        processArgs ( argc,  argv );
319
 
320
 
321
        FIXED_SRC_DST_PAIR = strcmp (TRAFFIC,"RANDOM") &  strcmp(TRAFFIC,"HOTSPOT") & strcmp(TRAFFIC,"random") & strcmp(TRAFFIC,"hot spot") & strcmp(TRAFFIC,"CUSTOM from file");
322
 
323 32 alirezamon
 
324
        /********************
325
        *       initialize input
326
        *********************/
327
 
328
        reset=1;
329
        reset_all_register();
330
        noc->start_i=0;
331 38 alirezamon
 
332 32 alirezamon
 
333
        for(x=0;x<NX;x++)for(y=0;y<NY;y++){
334 38 alirezamon
 
335 32 alirezamon
                                        i=(y*NX)+x;
336 38 alirezamon
                                        random_var[i] = 100;
337 32 alirezamon
                                        router[i]->current_x            = x;
338
                                        router[i]->current_y            = y;
339
                                        traffic[i]->current_x           = x;
340
                                        traffic[i]->current_y           = y;
341
                                        traffic[i]->start=0;
342
                                        traffic[i]->pck_class_in=  pck_class_in_gen( i);
343
                                        pck_dst_gen ( x,y,i, &dest_x, &dest_y);
344
                                        traffic[i]->dest_x= dest_x;
345
                                        traffic[i]->dest_y=dest_y;
346 38 alirezamon
                                        traffic[i]->stop=0;
347
                                        if(TRAFFIC_TYPE==SYNTHETIC){
348
                                                traffic[i]->pck_size_in=PACKET_SIZE;
349
                                                traffic[i]->avg_pck_size_in=PACKET_SIZE;
350
                                                traffic[i]->ratio=ratio;
351
                                                traffic[i]->init_weight=1;
352
                                        }
353 32 alirezamon
 
354 38 alirezamon
 
355 32 alirezamon
        }
356 38 alirezamon
        //traffic[35]->init_weight=10;
357 32 alirezamon
 
358 38 alirezamon
 
359 32 alirezamon
 
360
        main_time=0;
361
        print_parameter();
362 38 alirezamon
        if(strcmp(TRAFFIC,"CUSTOM from file")) printf("\n\n\n Flit injection ratio per router is =%f \n",(float)ratio*100/MAX_RATIO);
363 32 alirezamon
        //printf("\n\n\n delay= %u clk",router->delay);
364
        while (!Verilated::gotFinish()) {
365
 
366
                if (main_time-saved_time >= 10 ) {
367
                        reset = 0;
368
                }
369
 
370
                if(main_time == saved_time+21){ count_en=1; noc->start_i=1;}//for(i=0;i<NC;i++) traffic[i]->start=1;}
371
                if(main_time == saved_time+26) noc->start_i=0;// for(i=0;i<NC;i++) traffic[i]->start=0;
372 38 alirezamon
 
373
                        if ((main_time % 4) == 0) {
374 32 alirezamon
                        clk = 1;       // Toggle clock
375
                        if(count_en) clk_counter++;
376 38 alirezamon
                        inject_done= ((total_pck_num >= MAX_PCK_NUM) || (clk_counter>= MAX_SIM_CLKs) || total_active_routers == 0);
377 32 alirezamon
                        //if(inject_done) printf("clk_counter=========%d\n",clk_counter);
378 38 alirezamon
                        for(y=0;y<NY;y++)for(x=0;x<NX;x++)
379 32 alirezamon
                        {
380
                                i=(y*NX)+x;
381
                                // a packet has been received
382
                                if(traffic[i]->update & ~reset){
383 38 alirezamon
                                        update_noc_statistic (i) ;
384
 
385 32 alirezamon
                                }
386
                                // the header flit has been sent out
387
                                if(traffic[i]->hdr_flit_sent ){
388
                                        traffic[i]->pck_class_in=  pck_class_in_gen( i);
389 38 alirezamon
                                        sent_core_total_pck_num[i]++;
390 32 alirezamon
                                        if(!FIXED_SRC_DST_PAIR){
391
                                                pck_dst_gen ( x,y,i, &dest_x, &dest_y);
392
                                                traffic[i]->dest_x= dest_x;
393
                                                traffic[i]->dest_y=dest_y;
394
                                        }
395
                                }
396
 
397
                                if(traffic[i]->flit_out_wr==1) flit_counter++;
398
 
399
                        }//for
400
                        if(inject_done) {
401
                                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;
402
 
403
                                printf(" simulation clock cycles:%d\n",clk_counter);
404
                                printf(" total received flits:%d\n",flit_counter);
405
                                print_statistic(out_file_name);
406
                                change_injection_ratio = 1;
407
                                for(i=0;i<NC;i++) {
408
                                        router[i]->final();
409
                                        traffic[i]->final();
410
                                }
411 38 alirezamon
                                noc->final();
412 32 alirezamon
                                return 0;
413
                        }
414
 
415
 
416
 
417
                }//if
418
                else
419
                {
420
 
421
                        clk = 0;
422 41 alirezamon
#if (NC<=64)                            
423 32 alirezamon
                        noc->ni_flit_in_wr =0;
424 41 alirezamon
#else
425
                        for(j=0;j<(sizeof(noc->ni_flit_in_wr)/sizeof(noc->ni_flit_in_wr[0])); j++) noc->ni_flit_in_wr[j]=0;
426
#endif                  
427 32 alirezamon
                        for(x=0;x<NX;x++)for(y=0;y<NY;y++){
428
                                i=(y*NX)+x;
429
 
430
 
431
                                router[i]->flit_in_we_all       = noc->router_flit_out_we_all[i];
432
                                router[i]->credit_in_all        = noc->router_credit_out_all[i];
433
                                router[i]->congestion_in_all    = noc->router_congestion_out_all[i];
434 38 alirezamon
                                //router[i]->iport_weight_in_all        = noc->router_iport_weight_out_all[i];
435
 
436 32 alirezamon
                                for(j=0;j<flit_out_all_size;j++)router[i]->flit_in_all[j]        = noc->router_flit_out_all[i][j];
437
 
438
 
439
                                noc->router_flit_in_we_all[i]   =       router[i]->flit_out_we_all ;
440
                                noc->router_credit_in_all[i]    =       router[i]->credit_out_all;
441
                                noc->router_congestion_in_all[i]=       router[i]->congestion_out_all;
442 38 alirezamon
                                //noc->router_iport_weight_in_all[i]=   router[i]->iport_weight_out_all;
443
 
444 32 alirezamon
                                for(j=0;j<flit_out_all_size;j++) noc->router_flit_in_all[i][j]   = router[i]->flit_out_all[j] ;
445 41 alirezamon
#if (Fpay<=32)
446 32 alirezamon
                                traffic[i]->flit_in  = noc->ni_flit_out [i];
447 41 alirezamon
#else   
448
        for(j=0;j<(sizeof(traffic[i]->flit_out)/sizeof(traffic[i]->flit_out[0])); j++) traffic[i]->flit_in[j]  = noc->ni_flit_out [i][j];
449
#endif                                  
450 32 alirezamon
                                traffic[i]->credit_in= noc->ni_credit_out[i];
451
 
452
 
453
                                noc->ni_credit_in[i] = traffic[i]->credit_out;
454 41 alirezamon
#if (Fpay<=32)                          
455 32 alirezamon
                                noc->ni_flit_in [i]  = traffic[i]->flit_out;
456 41 alirezamon
#else   
457
        for(j=0;j<(sizeof(traffic[i]->flit_out)/sizeof(traffic[i]->flit_out[0])); j++) noc->ni_flit_in [i][j]  = traffic[i]->flit_out[j];
458
#endif
459 32 alirezamon
 
460 41 alirezamon
#if (NC<=64)                    
461 32 alirezamon
                                if(traffic[i]->flit_out_wr) noc->ni_flit_in_wr = noc->ni_flit_in_wr | ((vluint64_t)1<<i);
462
                                traffic[i]->flit_in_wr= ((noc->ni_flit_out_wr >> i) & 0x01);
463 41 alirezamon
#else
464
                                if(traffic[i]->flit_out_wr) MY_VL_SETBIT_W(noc->ni_flit_in_wr ,i);
465
                                traffic[i]->flit_in_wr=   (VL_BITISSET_W(noc->ni_flit_out_wr,i)>0);
466
#endif
467
 
468 32 alirezamon
 
469
 
470
                        }//for
471
 
472
 
473
                }//else
474
                //if(main_time > 20 && main_time < 30 ) traffic->start=1; else traffic->start=0;
475
                //if(main_time == saved_time+25) router[0]->flit_in_we_all=0;
476
                //if((main_time % 250)==0) printf("router->all_done =%u\n",router->all_done);
477
 
478
 
479
                noc-> clk = clk;
480
                noc-> reset = reset;
481
 
482
 
483
                for(i=0;i<NC;i++)        {
484 41 alirezamon
#if (NC<=64)                    
485 32 alirezamon
                        traffic[i]->start=  ((noc->start_o >>i)&  0x01);
486 41 alirezamon
#else
487
                        traffic[i]->start=   (VL_BITISSET_W(noc->start_o, i)>0);
488
#endif                  
489 32 alirezamon
                        traffic[i]->reset= reset;
490
                        traffic[i]->clk = clk;
491
                        router[i]->reset= reset;
492
                        router[i]->clk= clk ;
493
 
494
                }
495
 
496
 
497
                noc->eval();
498
 
499
 
500
                for(i=0;i<NC;i++) {
501
                                router[i]->eval();
502
                                traffic[i]->eval();
503
 
504
                }
505
 
506
 
507
 
508
 
509
                //router[0]->eval();            // Evaluate model
510
                //printf("clk=%x\n",router->clk );
511
 
512
                main_time++;
513
                //getchar();   
514
 
515
 
516
        }
517
        for(i=0;i<NC;i++) {
518
                router[i]->final();
519
                traffic[i]->final();
520
        }               // Done simulating
521
        noc->final();
522
 
523
}
524
 
525
 
526
 
527
 
528 38 alirezamon
/*************
529
 * sc_time_stamp
530
 *
531
 * **********/
532 32 alirezamon
 
533
 
534
 
535
double sc_time_stamp () {       // Called by $time in Verilog
536
        return main_time;
537
}
538
 
539
int pow2( int num){
540
        int pw;
541
        pw= (0x1 << num);
542
        return pw;
543
}
544
 
545
 
546
 
547
/**********************************
548
 *
549
 *      update_noc_statistic
550
 *
551
 *
552
 *********************************/
553
 
554
 
555
 
556
void update_noc_statistic (
557 38 alirezamon
 
558
                int                     core_num
559 32 alirezamon
)
560
{
561
 
562 38 alirezamon
        unsigned int    clk_num_h2h =traffic[core_num]->time_stamp_h2h;
563
        unsigned int    clk_num_h2t =traffic[core_num]->time_stamp_h2t;
564
    unsigned int    distance=traffic[core_num]->distance;
565
    unsigned int        class_num=traffic[core_num]->pck_class_out;
566
    unsigned int    src_x=traffic[core_num]->src_x;
567
    unsigned int    src_y=traffic[core_num]->src_y;
568 32 alirezamon
 
569 38 alirezamon
    unsigned int    src = (src_y*NX)+src_x;
570
 
571
 
572
 
573
 
574
        total_pck_num+=1;
575
 
576
        if((total_pck_num & 0Xffff )==0 ) printf(" packet sent total=%d\n",total_pck_num);
577
 
578
 
579
        sum_clk_h2h+=clk_num_h2h;
580
        sum_clk_h2t+=clk_num_h2t;
581 32 alirezamon
#if (STND_DEV_EN)
582 38 alirezamon
        sum_clk_pow2+=(double)clk_num_h2h * (double) clk_num_h2h;
583
        sum_clk_pow2_per_class[class_num]+=(double)clk_num_h2h * (double) clk_num_h2h;
584 32 alirezamon
#endif
585
 
586 38 alirezamon
        sum_clk_per_hop+= ((double)clk_num_h2h/(double)distance);
587
        total_pck_num_per_class[class_num]+=1;
588
        sum_clk_h2h_per_class[class_num]+=clk_num_h2h ;
589
        sum_clk_h2t_per_class[class_num]+=clk_num_h2t ;
590
        sum_clk_per_hop_per_class[class_num]+= ((double)clk_num_h2h/(double)distance);
591 32 alirezamon
 
592 38 alirezamon
        rsvd_core_total_pck_num[core_num]=rsvd_core_total_pck_num[core_num]+1;
593 32 alirezamon
 
594 38 alirezamon
        if (rsvd_core_worst_delay[core_num] < clk_num_h2t) rsvd_core_worst_delay[core_num] = (strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0)?  clk_num_h2t :  clk_num_h2h;
595
    if (sent_core_worst_delay[src] < clk_num_h2t) sent_core_worst_delay[src] = (strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0)?  clk_num_h2t :  clk_num_h2h;
596 32 alirezamon
 
597
 
598 38 alirezamon
}
599 32 alirezamon
 
600
/*************************
601
 *
602
 *              update
603
 *
604
 *
605
 ************************/
606
 
607
 
608
 
609
 
610
 
611
void print_statistic (char * out_file_name){
612
        double avg_latency_per_hop,  avg_latency_flit, avg_latency_pck, avg_throughput,min_avg_latency_per_class;
613
        int i;
614
#if (STND_DEV_EN)
615
        double  std_dev;
616
#endif
617
                                        char file_name[100];
618 38 alirezamon
                                        avg_throughput= ((double)(flit_counter*100)/total_router )/clk_counter;
619 32 alirezamon
                                        printf(" Total active routers: %d \n",total_router);
620
                                        printf(" Avg throughput is: %f (flits/clk/node %%)\n",    avg_throughput);
621
                        avg_latency_flit   = (double)sum_clk_h2h/total_pck_num;
622
                        avg_latency_pck    = (double)sum_clk_h2t/total_pck_num;
623
                        if(ratio==RATIO_INIT) first_avg_latency_flit=avg_latency_flit;
624
#if (STND_DEV_EN)
625
                        std_dev= standard_dev( sum_clk_pow2,total_pck_num, avg_latency_flit);
626 42 alirezamon
                        printf(" standard_dev = %f\n",std_dev);
627
 
628 32 alirezamon
                       // sprintf(file_name,"%s_std.txt",out_file_name);
629
                        //update_file( file_name,avg_throughput,std_dev);
630
 
631
#endif
632
                        avg_latency_per_hop    = (double)sum_clk_per_hop/total_pck_num;
633
                        printf   ("\nall : \n");
634
                      //  sprintf(file_name,"%s_all.txt",out_file_name);
635
                        //update_file(file_name ,ratio,avg_latency );
636
if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0){
637
                        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);
638
                      // update_file(file_name ,avg_throughput,avg_latency_pck);
639
 
640
}else{
641
                         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);
642
                     //   update_file(file_name ,avg_throughput,avg_latency_flit);
643
 
644
}
645
                        //fwrite(fp,"%d,%f,%f,%f,",total_pck_num,avg_latency_per_hop,avg_latency,max_latency_per_hop);
646
                        min_avg_latency_per_class=1000000;
647
                        for(i=0;i<C;i++){
648
                                avg_throughput           = (total_pck_num_per_class[i]>0)? ((double)(total_pck_num_per_class[i]*PACKET_SIZE*100)/total_router )/clk_counter:0;
649
                                                avg_latency_flit         = (total_pck_num_per_class[i]>0)? (double)sum_clk_h2h_per_class[i]/total_pck_num_per_class[i]:0;
650
                                                avg_latency_pck          = (total_pck_num_per_class[i]>0)? (double)sum_clk_h2t_per_class[i]/total_pck_num_per_class[i]:0;
651
                                                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;
652
if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0){
653
                                                 printf  ("\nclass : %d  \n",i);
654
                            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);
655
                            //sprintf(file_name,"%s_c%u.txt",out_file_name,i);
656
                           // update_file( file_name,avg_throughput,avg_latency_pck );
657
}else{
658
 
659
printf   ("\nclass : %d  \n",i);
660
                            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);
661
                           // sprintf(file_name,"%s_c%u.txt",out_file_name,i);
662
                           // update_file( file_name,avg_throughput,avg_latency_flit );
663
 
664
 
665
}
666
                            if(min_avg_latency_per_class > avg_latency_flit) min_avg_latency_per_class=avg_latency_flit;
667
 
668
#if (STND_DEV_EN)
669
                            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;
670
                           // sprintf(file_name,"%s_std%u.txt",out_file_name,i);
671
                           // update_file( file_name,avg_throughput,std_dev);
672
 
673
#endif
674
 
675
 
676
                         }//for
677
                        current_avg_latency_flit=min_avg_latency_per_class;
678
 
679 38 alirezamon
        for (i=0;i<NC;i++) {
680
                printf   ("\n\nCore %d\n",i);
681
                        printf   ("\n\ttotal number of received packets: %u\n",rsvd_core_total_pck_num[i]);
682
                        printf   ("\n\tworst-case-delay of received pckets (clks): %u\n",rsvd_core_worst_delay[i] );
683
                        printf   ("\n\ttotal number of sent packets: %u\n",traffic[i]->pck_number);
684
                        printf   ("\n\tworst-case-delay of sent pckets (clks): %u\n",sent_core_worst_delay[i] );
685
        }
686 32 alirezamon
 
687
 
688
 
689
}
690
 
691
void print_parameter (){
692
 
693
                printf ("Router parameters: \n");
694
                printf ("\tTopology: %s\n",TOPOLOGY);
695
                printf ("\tRouting algorithm: %s\n",ROUTE_NAME);
696
                printf ("\tVC_per port: %d\n", V);
697
                printf ("\tBuffer_width: %d\n", B);
698
            printf ("\tRouter num in row: %d \n",NX);
699
            printf ("\tRouter num in column: %d \n",NY);
700
            printf ("\tNumber of Class: %d\n", C);
701
            printf ("\tFlit data width: %d \n", Fpay);
702
            printf ("\tVC reallocation mechanism: %s \n",  VC_REALLOCATION_TYPE);
703
            printf ("\tVC/sw combination mechanism: %s \n", COMBINATION_TYPE);
704
            printf ("\troute-subfunction: %s \n", ROUTE_SUBFUNC );
705
            printf ("\tAVC_ATOMIC_EN:%d \n", AVC_ATOMIC_EN);
706
            printf ("\tCongestion Index:%d \n",CONGESTION_INDEX);
707
            printf ("\tADD_PIPREG_AFTER_CROSSBAR:%d\n",ADD_PIPREG_AFTER_CROSSBAR);
708 38 alirezamon
            printf ("\tSSA_EN enabled:%s \n",SSA_EN);
709
            printf ("\tSwitch allocator arbitration type:%s \n",SWA_ARBITER_TYPE);
710 32 alirezamon
 
711
 
712 38 alirezamon
        printf ("\nSimulation parameters\n");
713 32 alirezamon
#if(DEBUG_EN)
714 38 alirezamon
    printf ("\tDebuging is enabled\n");
715 32 alirezamon
#else
716 38 alirezamon
    printf ("\tDebuging is disabled\n");
717 32 alirezamon
#endif
718 38 alirezamon
        if(strcmp (AVG_LATENCY_METRIC,"HEAD_2_TAIL")==0)printf ("\tOutput is the average latency on sending the packet header until receiving tail\n");
719
        else printf ("\tOutput is the average latency on sending the packet header until receiving header flit at destination node\n");
720 32 alirezamon
        printf ("\tTraffic pattern:%s\n",TRAFFIC);
721
        if(C>0) printf ("\ttraffic percentage of class 0 is : %d\n", C0_p);
722
        if(C>1) printf ("\ttraffic percentage of class 1 is : %d\n", C1_p);
723
        if(C>2) printf ("\ttraffic percentage of class 2 is : %d\n", C2_p);
724
        if(C>3) printf ("\ttraffic percentage of class 3 is : %d\n", C3_p);
725 38 alirezamon
        if(strcmp (TRAFFIC,"HOTSPOT")==0){
726
                //printf ("\tHot spot percentage: %u\n", HOTSPOT_PERCENTAGE);
727 32 alirezamon
            printf ("\tNumber of hot spot cores: %d\n", HOTSPOT_NUM);
728
 
729
        }
730
            //printf ("\tTotal packets sent by one router: %u\n", TOTAL_PKT_PER_ROUTER);
731 38 alirezamon
                printf ("\tSimulation timeout =%d\n", MAX_SIM_CLKs);
732
                printf ("\tSimulation ends on total packet num of =%d\n", MAX_PCK_NUM);
733
            printf ("\tPacket size (min,max,average) in flits: (%u,%u,%u)\n",MIN_PACKET_SIZE,MAX_PACKET_SIZE,PACKET_SIZE);
734
            printf ("\tPacket injector FIFO width in flit:%u \n",TIMSTMP_FIFO_NUM);
735 32 alirezamon
}
736
 
737
 
738 38 alirezamon
 
739
 
740
 
741 32 alirezamon
/************************
742
 *
743
 *      reset system
744
 *
745
 *
746
 * *******************/
747
 
748
void reset_all_register (void){
749
        int i;
750
 
751
 
752
 
753
         total_router=0;
754
         total_pck_num=0;
755
         sum_clk_h2h=0;
756
         sum_clk_h2t=0;
757
#if (STND_DEV_EN)
758
         sum_clk_pow2=0;
759
#endif
760
 
761
         sum_clk_per_hop=0;
762
         count_en=0;
763
         clk_counter=0;
764
 
765
         for(i=0;i<C;i++)
766
         {
767
                 total_pck_num_per_class[i]=0;
768
             sum_clk_h2h_per_class[i]=0;
769
             sum_clk_h2t_per_class[i]=0;
770
                 sum_clk_per_hop_per_class[i]=0;
771
#if (STND_DEV_EN)
772
                 sum_clk_pow2_per_class[i]=0;
773
#endif
774
 
775
         }  //for
776
         flit_counter=0;
777
}
778
 
779
 
780
 
781
 
782
/***********************
783
 *
784
 *      standard_dev
785
 *
786
 * ******************/
787
 
788
#if (STND_DEV_EN)
789 42 alirezamon
/************************
790
 * std_dev = sqrt[(B-A^2/N)/N]  = sqrt [(B/N)- (A/N)^2] = sqrt [B/N - mean^2]
791
 * A = sum of the values
792
 * B = sum of the squarded values
793
 * *************/
794 32 alirezamon
 
795
double standard_dev( double sum_pow2, unsigned int  total_num, double average){
796
        double std_dev;
797 42 alirezamon
 
798
        /*
799
        double  A, B, N;
800
        N= total_num;
801
        A= average * N;
802
        B= sum_pow2;
803 32 alirezamon
 
804 42 alirezamon
        A=(A*A)/N;
805
        std_dev = (B-A)/N;
806 32 alirezamon
        std_dev = sqrt(std_dev);
807 42 alirezamon
*/
808 32 alirezamon
 
809 42 alirezamon
        std_dev = sum_pow2/(double)total_num; //B/N
810
        std_dev -= (average*average);// (B/N) - mean^2
811
        std_dev = sqroot(std_dev);// sqrt [B/N - mean^2]
812
 
813 32 alirezamon
        return std_dev;
814
 
815
}
816
 
817
#endif
818
 
819
 
820
 
821
/**********************
822
 *
823
 *      pck_class_in_gen
824
 *
825
 * *****************/
826
 
827
unsigned char  pck_class_in_gen(
828
         unsigned int  core_num
829
 
830
) {
831
 
832
        unsigned char pck_class_in;
833
        unsigned char  rnd=rand()%100;
834
 
835
        pck_class_in=     ( rnd <    C0_p               )?  0:
836
                                  ( rnd <   (C0_p+C1_p) )?      1:
837
                                  ( rnd <   (C0_p+C1_p+C2_p))?2:3;
838
 
839
 
840
 
841
    return pck_class_in;
842
}
843
 
844 38 alirezamon
 
845 32 alirezamon
/**********************************
846
 
847
        pck_dst_gen
848
 
849
*********************************/
850
 
851 38 alirezamon
 
852
 
853
 
854
void pck_dst_gen_2D (
855 32 alirezamon
    unsigned int current_x,
856
        unsigned int current_y,
857
        unsigned int core_num,
858
        unsigned int *dest_x,
859
        unsigned int *dest_y
860
){
861
 
862
 
863 38 alirezamon
        unsigned int rnd=0,nc=NX*NY;
864 32 alirezamon
        unsigned int rnd100=0;
865 38 alirezamon
        unsigned int max_percent=100/HOTSPOT_NUM;
866 32 alirezamon
        int i;
867
 
868 38 alirezamon
        traffic[core_num]->pck_size_in=rnd_between(MIN_PACKET_SIZE,MAX_PACKET_SIZE);
869 32 alirezamon
 
870
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
871
 
872
                do{
873 38 alirezamon
                        rnd=rand()%nc;
874 32 alirezamon
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
875
 
876
       (*dest_y) = (rnd / NX );
877
           (*dest_x) = (rnd % NX );
878
 
879
 
880
        }
881 38 alirezamon
 
882 32 alirezamon
        else if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
883
 
884 38 alirezamon
                unsigned int rnd1000=0;
885
                int i;
886
 
887
 
888 32 alirezamon
                do{
889 38 alirezamon
                        rnd=rand()%nc;
890 32 alirezamon
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
891
 
892 38 alirezamon
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
893
 
894
                for (i=0;i<HOTSPOT_NUM; i++){
895
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
896
                                rnd = core_num; // turn off the core
897
                                (*dest_y) = (rnd / NX );
898
                                (*dest_x) = (rnd % NX );
899
                                return;
900
                        }
901
                }
902
 
903
                for (i=0;i<HOTSPOT_NUM; i++){
904
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
905
                                rnd = hotspots[i].ip_num;
906
                                (*dest_y) = (rnd / NX );
907
                                (*dest_x) = (rnd % NX );
908
                                return;
909
                        }
910
 
911
                }
912
                (*dest_y) = (rnd / NX );
913
                (*dest_x) = (rnd % NX );
914
                return;
915 32 alirezamon
 
916
 
917
        } else if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
918
 
919
                 (*dest_x) = NX-current_y-1;
920
                 (*dest_y) = NY-current_x-1;
921
 
922
 
923
 
924
        } else if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
925
                (*dest_x)   = current_y;
926
                (*dest_y)   = current_x;
927
 
928
 
929 38 alirezamon
 
930 32 alirezamon
        } else if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
931
                unsigned int joint_addr= (current_x<<Xw)+current_y;
932
                unsigned int reverse_addr=0;
933
                unsigned int pos=0;
934
                for(i=0; i<(Xw+Yw); i++){//reverse the address
935
                         pos= (((Xw+Yw)-1)-i);
936
                         reverse_addr|= ((joint_addr >> pos) & 0x01) << i;
937
                   // reverse_addr[i]  = joint_addr [((Xw+Yw)-1)-i];
938
                }
939
                (*dest_x)   = reverse_addr>>Yw;
940
                (*dest_y)   = reverse_addr&(0xFF>> (8-Yw));
941
 
942
 
943
 
944
 
945
         } else if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
946
 
947
                 (*dest_x)    = (~current_x) &(0xFF>> (8-Xw));
948
                 (*dest_y)    = (~current_y) &(0xFF>> (8-Yw));
949
 
950
 
951 38 alirezamon
          }  else if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
952 32 alirezamon
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
953
                 (*dest_x)    = ((current_x + ((NX/2)-1))%NX);
954
                 (*dest_y)    = ((current_y + ((NY/2)-1))%NY);
955
 
956
 
957
     }  else if( strcmp(TRAFFIC ,"CUSTOM") == 0){
958
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
959
                if(current_x ==0 && current_y == 0 ){
960
                 (*dest_x)    =  NX-1;
961
                 (*dest_y)    =  NY-1;
962 38 alirezamon
                }else{// make it invalid
963 32 alirezamon
                 (*dest_x)    =  current_x;
964
                 (*dest_y)    =  current_y;
965
 
966
                }
967
 
968
     }
969
 
970 38 alirezamon
         else {
971
                 printf ("traffic %s is an unsupported traffic pattern\n",TRAFFIC);
972
                 (*dest_x)    =  current_x;
973
                 (*dest_y)    =  current_y;
974 32 alirezamon
 
975 38 alirezamon
         }
976
 
977 32 alirezamon
}
978
 
979
 
980
 
981
 
982 38 alirezamon
void pck_dst_gen_1D (
983
    unsigned int current_x,
984
        unsigned int core_num,
985
        unsigned int *dest_x
986 32 alirezamon
 
987 38 alirezamon
){
988 32 alirezamon
 
989
 
990 38 alirezamon
        unsigned int rnd=0,nc=NX;
991
        unsigned int rnd100=0;
992
        unsigned int max_percent=100/HOTSPOT_NUM;
993
        int i;
994
 
995
        traffic[core_num]->pck_size_in=rnd_between(MIN_PACKET_SIZE,MAX_PACKET_SIZE);
996 32 alirezamon
 
997 38 alirezamon
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
998 32 alirezamon
 
999 38 alirezamon
                do{
1000
                        rnd=rand()%nc;
1001
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
1002 32 alirezamon
 
1003 38 alirezamon
           (*dest_x) = (rnd % NX );
1004
                return;
1005 32 alirezamon
 
1006 38 alirezamon
        }
1007
 
1008
        if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
1009 32 alirezamon
 
1010 38 alirezamon
                unsigned int rnd1000=0;
1011
                int i;
1012 32 alirezamon
 
1013 38 alirezamon
 
1014
                do{
1015
                        rnd=rand()%nc;
1016
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
1017 32 alirezamon
 
1018 38 alirezamon
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
1019
 
1020
                for (i=0;i<HOTSPOT_NUM; i++){
1021
                        //printf("%u==0 && %u == %u\n", hotspots[i].send_enable , core_num , hotspots[i].ip_num);
1022
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
1023
                                rnd = core_num; // turn off the core
1024
                                (*dest_x) = (rnd % NX );
1025
                                return;
1026
                        }
1027
                }
1028
 
1029
                for (i=0;i<HOTSPOT_NUM; i++){
1030
                        //printf("%u<%u && %u |= %u\n", rnd1000 , hotspots[i].percentage , core_num ,hotspots[i].ip_num);
1031
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
1032
                                rnd = hotspots[i].ip_num;
1033
                                (*dest_x) = (rnd % NX );
1034
                                return;
1035
                        }
1036
 
1037
                }
1038
        (*dest_x) = (rnd % NX );
1039
                return;
1040 32 alirezamon
 
1041 38 alirezamon
        }
1042
 
1043
 
1044
        if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
1045
 
1046
                 //(*dest_x) = (current_x<4)? NX-current_x-1: current_x;
1047
                  (*dest_x) =  NX-current_x-1;
1048
                // (*dest_y) = NY-current_x-1;
1049
                return;
1050 32 alirezamon
 
1051 38 alirezamon
 
1052
        }
1053
        if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
1054
                 (*dest_x) = NX-current_x-1;
1055
        //      (*dest_x)   = current_y;
1056
        //      (*dest_y)   = current_x;
1057
                return;
1058
 
1059
        }
1060
 
1061
        if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
1062
 
1063
                unsigned int reverse_addr=0;
1064
                unsigned int pos=0;
1065
                for(i=0; i<(Xw); i++){//reverse the address
1066
                         pos= (((Xw)-1)-i);
1067
                         reverse_addr|= ((current_x >> pos) & 0x01) << i;
1068
                   // reverse_addr[i]  = joint_addr [((Xw+Yw)-1)-i];
1069
                }
1070
                (*dest_x)   = reverse_addr;
1071
                return;
1072
 
1073
         }
1074
 
1075
         if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
1076
 
1077
                 (*dest_x)    = (~current_x) &(0xFF>> (8-Xw));
1078
                 return;
1079
                 //(*dest_y)    = (~current_y) &(0xFF>> (8-Yw));
1080
 
1081
 
1082
         }
1083
 
1084
         if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
1085
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
1086
                 (*dest_x)    = ((current_x + ((NX/2)-1))%NX);
1087
                // (*dest_y)    = ((current_y + ((NY/2)-1))%NY);
1088
                return;
1089
 
1090
     }
1091
 
1092
     if( strcmp(TRAFFIC ,"CUSTOM") == 0){
1093
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
1094
                if(current_x ==0  ){
1095
                 (*dest_x)    =  NX-1;
1096
                // (*dest_y)    =  NY-1;
1097
                }else{// make it invalid
1098
                 (*dest_x)    =  current_x;
1099
                 //(*dest_y)    =  current_y;
1100
 
1101
                }
1102
                return;
1103
     }
1104
 
1105
 
1106
                 printf ("traffic %s is an unsupported traffic pattern\n",TRAFFIC);
1107
                 (*dest_x)    =  current_x;
1108
 
1109
 
1110
}
1111
 
1112
unsigned int rnd_between (unsigned int a, unsigned int b){
1113
        unsigned int rnd,diff,min;
1114
        if(a==b) return a;
1115
        diff= (a<b) ?  b-a+1 : a-b+1;
1116
        min= (a<b) ?  a : b;
1117
        rnd = (rand() % diff) +  min;
1118
        return rnd;
1119
}
1120
 
1121
void update_injct_var(unsigned int src,  unsigned int injct_var){
1122
        //printf("before%u=%u\n",src,random_var[src]);
1123
        random_var[src]= rnd_between(100-injct_var, 100+injct_var);
1124
        //printf("after=%u\n",random_var[src]);
1125
}
1126
 
1127
unsigned int pck_dst_gen_task_graph ( unsigned int src){
1128
         task_t  task;
1129
        float f,v;
1130
 
1131
 
1132
 
1133
 
1134
        int index = task_graph_abstract[src].active_index;
1135
 
1136
        if(index == DISABLE){
1137
                traffic[src]->ratio=0;
1138
                traffic[src]->stop=1;
1139
                 return src; //disable sending
1140
        }
1141
 
1142
        if(     read(task_graph_data[src],index,&task)==0){
1143
                traffic[src]->ratio=0;
1144
                traffic[src]->stop=1;
1145
                 return src; //disable sending
1146
 
1147
        }
1148
 
1149
        if(sent_core_total_pck_num[src] & 0xFF){//sent 255 packets
1150
                        //printf("uu=%u\n",task.jnjct_var);
1151
                        update_injct_var(src, task.jnjct_var);
1152
 
1153
                }
1154
 
1155
        task_graph_total_pck_num++;
1156
        task.pck_sent = task.pck_sent +1;
1157
        task.burst_sent= task.burst_sent+1;
1158
        task.byte_sent = task.byte_sent + (task.avg_pck_size * (Fpay/8) );
1159
 
1160
        traffic[src]->pck_class_in=  pck_class_in_gen(src);
1161
        traffic[src]->avg_pck_size_in=task.avg_pck_size;
1162
        traffic[src]->pck_size_in=rnd_between(task.min_pck_size,task.max_pck_size);
1163
 
1164
        f=  task.injection_rate;
1165
        v= random_var[src];
1166
        f*= (v /100);
1167
        if(f>100) f= 100;
1168
        f=  f * MAX_RATIO / 100;
1169
 
1170
        traffic[src]->ratio=(unsigned int)f;
1171
        traffic[src]->init_weight=task.initial_weight;
1172
 
1173
 
1174
 
1175
 
1176
        if (task.burst_sent >= task.burst_size){
1177
                task.burst_sent=0;
1178
                task_graph_abstract[src].active_index=task_graph_abstract[src].active_index+1;
1179
                if(task_graph_abstract[src].active_index>=task_graph_abstract[src].total_index) task_graph_abstract[src].active_index=0;
1180
 
1181
        }
1182
 
1183
 
1184
        update_by_index(task_graph_data[src],index,task);
1185
 
1186
        if (task.byte_sent  >= task.bytes){ // This task is done remove it from the queue
1187
                                remove_by_index(&task_graph_data[src],index);
1188
                                task_graph_abstract[src].total_index = task_graph_abstract[src].total_index-1;
1189
                                if(task_graph_abstract[src].total_index==0){ //all tasks are done turned off the core
1190
                                        task_graph_abstract[src].active_index=-1;
1191
                                        traffic[src]->ratio=0;
1192
                                        traffic[src]->stop=1;
1193
                                        if(total_active_routers!=0) total_active_routers--;
1194
                                        return src;
1195
                                }
1196
                                if(task_graph_abstract[src].active_index>=task_graph_abstract[src].total_index) task_graph_abstract[src].active_index=0;
1197
        }
1198
 
1199
        return task.dst;
1200
 
1201
 
1202
 
1203
 
1204
}
1205
 
1206
 
1207
 
1208
 
1209
void pck_dst_gen (
1210
    unsigned int current_x,
1211
        unsigned int current_y,
1212
        unsigned int core_num,
1213
        unsigned int *dest_x,
1214
        unsigned int *dest_y
1215
){
1216
 
1217
        if(TRAFFIC_TYPE==CUSTOM){
1218
                int dest =      pck_dst_gen_task_graph ( core_num);
1219
                 (*dest_y) = (dest / NX );
1220
                 (*dest_x) = (dest % NX );
1221
                // printf ("%d->%d (%d,%d)\n",core_num,dest,(*dest_y),(*dest_x) );      
1222
                return;
1223
 
1224
        }
1225
 
1226
 
1227
        if((strcmp (TOPOLOGY,"MESH")==0)||(strcmp (TOPOLOGY,"TORUS")==0)){
1228
                pck_dst_gen_2D (
1229
                    current_x,
1230
                        current_y,
1231
                        core_num,
1232
                        dest_x,
1233
                        dest_y
1234
                );
1235
                return;
1236
        }
1237
 
1238
        dest_y=0;
1239
        pck_dst_gen_1D (
1240
                        current_x,
1241
                        core_num,
1242
                        dest_x);
1243
 
1244
}
1245
 
1246
 
1247
 
1248
 

powered by: WebSVN 2.1.0

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