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 38

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

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

powered by: WebSVN 2.1.0

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