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 41

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

powered by: WebSVN 2.1.0

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