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/] [perl_gui/] [lib/] [perl/] [emulator.pl] - Blame information for rev 32

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

Line No. Rev Author Line
1 25 alirezamon
#! /usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
use strict;
4
use warnings;
5
use Gtk2;
6
use Gtk2::Ex::Graph::GD;
7
use GD::Graph::Data;
8
use emulator;
9
use IO::CaptureOutput qw(capture qxx qxy);
10
use GD::Graph::colour qw/:colours/;
11
use Proc::Background;
12
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep  clock_gettime clock_getres clock_nanosleep clock stat );
13
 
14
use File::Basename;
15
use File::Path qw/make_path/;
16 28 alirezamon
use File::Copy;
17
use File::Find::Rule;
18 25 alirezamon
 
19
require "widget.pl";
20
require "emulate_ram_gen.pl";
21
require "mpsoc_gen.pl";
22
require "mpsoc_verilog_gen.pl";
23
require "readme_gen.pl";
24
 
25
use List::MoreUtils qw(uniq);
26
 
27
 
28 28 alirezamon
# hardware parameters taken from noc_emulator.v
29
use constant PCK_CNTw =>30;  # packet counter width in bits (results in maximum of 2^30 = 1  G packets)
30
use constant PCK_SIZw =>14;  # packet size width in bits (results in maximum packet size of 2^14 = 16 K flit)
31
use constant MAXXw    =>4;   # maximum nodes in x dimention is 2^MAXXw equal to 16 nodes in x dimention
32
use constant MAXYw    =>4;   # 16 nodes in y dimention : hence max emulator size is 16X16
33
use constant MAXCw    =>4;   # 16 message classes  
34
use constant RATIOw   =>7;   # log2(100)
35
use constant MAX_PATTERN => 124;
36
use constant RAM_SIZE => (MAX_PATTERN+4);
37 25 alirezamon
 
38 28 alirezamon
 
39
#use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
40
use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
41
use constant MAX_PCK_SIZ => (2**PCK_SIZw)-1;
42
use constant MAX_SIM_CLKs=> 100000000; # simulation end at if clock counter reach this number           
43 25 alirezamon
 
44 28 alirezamon
use constant EMULATION_RTLS => "/mpsoc/src_emulate/rtl/noc_emulator.v , /mpsoc/src_peripheral/jtag/jtag_wb/ , /mpsoc/src_peripheral/ram/generic_ram.v, /mpsoc/src_noc/";
45 25 alirezamon
 
46 28 alirezamon
 
47
 
48
 
49
 
50 25 alirezamon
sub gen_chart {
51
        my $emulate=shift;
52
        my($width,$hight)=max_win_size();
53
        my $graph_w=$width/2.5;
54
        my $graph_h=$hight/2.5;
55
        my $graph = Gtk2::Ex::Graph::GD->new($graph_w, $graph_h, 'linespoints');
56
        my @x;
57
        my @legend_keys;
58
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
59
        my $scale= $emulate->object_get_attribute("graph_scale",undef);
60
        my @results;
61
        $results[0]=[0];
62
        $results[1]= [0];
63
my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
64
 
65
my @ginfo = (
66
{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
67
{ label=>"Y Axix Title", param_name=>"Y_Title", type=>"Entry", default_val=>'Latency (clock)', content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
68
  { label=>"X Axix Title", param_name=>"X_Title", type=>"Entry", default_val=>'Load per router (flits/clock (%))', content=>undef, info=>undef, param_parent=>'graph_param',ref_delay=>undef },
69
  { label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>'graph_param', ref_delay=>undef},
70
 { label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
71
 { label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
72 32 alirezamon
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axix maximum value", param_parent=>'graph_param', ref_delay=> 5},
73 25 alirezamon
 { label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>'graph_param', ref_delay=> 5},
74
 
75
 
76
);
77
 
78 28 alirezamon
 
79
 
80
 
81
 
82 25 alirezamon
        if(defined  $sample_num){
83
                my @color;
84
                my $min_y=200;
85
                for (my $i=1;$i<=$sample_num; $i++) {
86
                        my $color_num=$emulate->object_get_attribute("sample$i","color");
87
                        my $l_name= $emulate->object_get_attribute("sample$i","line_name");
88
                        $legend_keys[$i-1]= (defined $l_name)? $l_name : "NoC$i";
89
                        $color_num=$i+1 if(!defined $color_num);
90
                        push(@color, "my_color$color_num");
91
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
92
                        if(defined $ref) {
93
                                push(@x, sort {$a<=>$b} keys $ref);
94
                        }
95
 
96
                }#for
97 32 alirezamon
        my  @x2;
98
        @x2 =  uniq(sort {$a<=>$b} @x) if (scalar @x);
99
 
100
        my  @x1; #remove x values larger than x_max
101
        my $x_max= $emulate->object_get_attribute( 'graph_param','X_MAX');
102
        foreach  my $p (@x2){
103
                if(defined $x_max) {push (@x1,$p) if($p<$x_max);}
104
                else {push (@x1,$p);}
105
        }
106
 
107 28 alirezamon
        #print "\@x1=@x1\n";
108 25 alirezamon
        if (scalar @x1){
109
                $results[0]=\@x1;
110 32 alirezamon
                my $i;
111
                for ($i=1;$i<=$sample_num; $i++) {
112 25 alirezamon
                        my $j=0;
113
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
114
                        if(defined $ref){
115 28 alirezamon
                                #print "$i\n";
116 25 alirezamon
                                my %line=%$ref;
117
                                foreach my $k (@x1){
118
                                        $results[$i][$j]=$line{$k};
119
                                        $min_y= $line{$k} if (defined $line{$k} && $line{$k}!=0 && $min_y > $line{$k});
120
                                        $j++;
121
                                }#$k
122 28 alirezamon
                        }#if
123
                        else {
124
                                $results[$i][$j]=undef;
125
 
126 32 alirezamon
                        }
127
 
128 25 alirezamon
                }#$i
129
 
130 32 alirezamon
 
131
 
132 25 alirezamon
        }#if
133
        my $max_y=$min_y*$scale;
134
 
135 32 alirezamon
        my $s=scalar @x1;
136 25 alirezamon
 
137 32 alirezamon
        # all results which is larger than ymax will be changed to ymax,
138
        for (my $i=1;$i<=$sample_num; $i++) {
139
                for (my $j=1;$j<=$s; $j++) {
140
                        $results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
141
                }
142
        }
143
 
144
 
145
 
146 25 alirezamon
 
147
        my $graphs_info;
148
        foreach my $d ( @ginfo){
149
                $graphs_info->{$d->{param_name}}=$emulate->object_get_attribute( 'graph_param',$d->{param_name});
150
                $graphs_info->{$d->{param_name}}= $d->{default_val} if(!defined $graphs_info->{$d->{param_name}});
151
        }
152
 
153 28 alirezamon
 
154 25 alirezamon
 
155
        $graph->set (
156
                x_label         => $graphs_info->{X_Title},
157
                y_label         => $graphs_info->{Y_Title},
158
                y_max_value     => $max_y,
159
                y_min_value     => $graphs_info->{Y_MIN},
160 32 alirezamon
                y_tick_number   => 8,
161
               #        x_min_value     => $graphs_info->{X_MIN}, # dosent work?
162 25 alirezamon
                title           => $graphs_info->{G_Title},
163
                bar_spacing     => 1,
164
                shadowclr       => 'dred',
165 32 alirezamon
 
166
                box_axis       => 0,
167
                skip_undef=> 1,
168
                transparent     => 1,
169 25 alirezamon
                                line_width              => $graphs_info->{LINEw},
170
                                cycle_clrs              => 'blue',
171
                                legend_placement => $graphs_info->{legend_placement},
172
                                dclrs=>\@color,
173
                );
174
     }#if
175
        $graph->set_legend(@legend_keys);
176
 
177
 
178 32 alirezamon
 
179
 
180
 
181
 
182
 
183 25 alirezamon
        my $data = GD::Graph::Data->new(\@results) or die GD::Graph::Data->error;
184 32 alirezamon
        $data->make_strict();
185
 
186 25 alirezamon
        my $image = my_get_image($emulate,$graph,$data);
187
 
188 32 alirezamon
 
189 25 alirezamon
 
190 32 alirezamon
      # print  Data::Dumper->Dump ([\@results],['ttt']); 
191 25 alirezamon
 
192
 
193
 
194
 
195
        my $table = Gtk2::Table->new (25, 10, FALSE);
196
 
197
 
198
                my $box = Gtk2::HBox->new (TRUE, 2);
199
                my $filename;
200
                $box->set_border_width (4);
201
                my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
202
                my $frame = Gtk2::Frame->new;
203
                $frame->set_shadow_type ('in');
204
                $frame->add ($image);
205
                $align->add ($frame);
206
 
207
 
208
                my $plus = def_image_button('icons/plus.png',undef,TRUE);
209
                my $minues = def_image_button('icons/minus.png',undef,TRUE);
210
                my $setting = def_image_button('icons/setting.png',undef,TRUE);
211
                my $save = def_image_button('icons/save.png',undef,TRUE);
212
 
213
                $minues -> signal_connect("clicked" => sub{
214
                        $emulate->object_add_attribute("graph_scale",undef,$scale+0.5);
215
                        set_gui_status($emulate,"ref",1);
216
                });
217
 
218
                $plus  -> signal_connect("clicked" => sub{
219
                        $emulate->object_add_attribute("graph_scale",undef,$scale-0.5) if( $scale>0.5);
220
                        set_gui_status($emulate,"ref",5);
221
                });
222
 
223
                $setting -> signal_connect("clicked" => sub{
224
                        get_graph_setting ($emulate,\@ginfo);
225
                });
226
 
227
                $save-> signal_connect("clicked" => sub{
228
                         my $G = $graph->{graph};
229
                         my @imags=$G->export_format();
230
                        save_graph_as ($emulate,\@imags);
231
                });
232
 
233
 
234
 
235
 
236
                $table->attach_defaults ($align , 0, 9, 0, 25);
237
                my $row=0;
238
                $table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
239
                $table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
240
                $table->attach ($setting, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
241
                $table->attach ($save, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
242
                while ($row<10){
243
 
244
                        my $tmp=gen_label_in_left('');
245
                        $table->attach_defaults ($tmp, 9, 10, $row,  $row+1);$row++;
246
                }
247
 
248
        return $table;
249
 
250
}
251
 
252
 
253
##############
254
#       save_graph_as
255
##############
256
 
257
sub save_graph_as {
258
        my ($emulate,$ref)=@_;
259
 
260
        my $file;
261
        my $title ='Save as';
262
 
263
 
264
 
265
        my @extensions=@$ref;
266
        my $open_in=undef;
267
        my $dialog = Gtk2::FileChooserDialog->new(
268
                'Save file', undef,
269
                'save',
270
                'gtk-cancel' => 'cancel',
271
                'gtk-ok'     => 'ok',
272
                );
273
        # if(defined $extension){
274
 
275
                foreach my $ext (@extensions){
276
                        my $filter = Gtk2::FileFilter->new();
277
                        $filter->set_name($ext);
278
                        $filter->add_pattern("*.$ext");
279
                        $dialog->add_filter ($filter);
280
                }
281
 
282
        # }
283
          if(defined  $open_in){
284
                $dialog->set_current_folder ($open_in);
285
                # print "$open_in\n";
286
 
287
        }
288
 
289
        if ( "ok" eq $dialog->run ) {
290
                        $file = $dialog->get_filename;
291
                        my $ext = $dialog->get_filter;
292
                        $ext=$ext->get_name;
293
                        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
294
                        $file = ($suffix eq ".$ext" )? $file : "$file.$ext";
295
 
296
                        $emulate->object_add_attribute("graph_save","name",$file);
297
                        $emulate->object_add_attribute("graph_save","extension",$ext);
298
                        $emulate->object_add_attribute("graph_save","save",1);
299
                        set_gui_status($emulate,"ref",1);
300
 
301
 
302
 
303
                         }
304
                        $dialog->destroy;
305
 
306
 
307
 
308
 
309
 
310
 
311
}
312
 
313
 
314
 
315
 
316
sub my_get_image {
317
        my ($emulate,$self, $data) = @_;
318
        $self->{graphdata} = $data;
319
        my $graph = $self->{graph};
320 32 alirezamon
        my $gd2=$graph->plot($data) or warn $graph->error;
321 25 alirezamon
        my $loader = Gtk2::Gdk::PixbufLoader->new;
322
 
323
 
324 32 alirezamon
        #cut the upper side of the image to remove the stright line created by chaanging large results to ymax
325
 
326 25 alirezamon
 
327 32 alirezamon
        my $gd1=  GD::Image->new($gd2->getBounds);
328
        my $white= $gd1->colorAllocate(255,255,254);
329
        my ($x,$h)=$gd2->getBounds;
330
        $gd1->transparent($white);
331
        $gd1->copy( $gd2, 0, 0, 0, ,$h*0.05, $x ,$h*.95 );
332 25 alirezamon
 
333
 
334
        $loader->write ($gd1->png);
335
        $loader->close;
336
 
337
        my $save=$emulate->object_get_attribute("graph_save","save");
338
        $save=0 if (!defined $save);
339
        if ($save ==1){
340
                my $file=$emulate->object_get_attribute("graph_save","name");
341
                my $ext=$emulate->object_get_attribute("graph_save","extension");
342
                $emulate->object_add_attribute("graph_save","save",0);
343
 
344 32 alirezamon
                #image
345 25 alirezamon
                open(my $out, '>', $file);
346
                if (tell $out )
347
                {
348 32 alirezamon
                        warn "Cannot open '$file' to write: $!";
349 25 alirezamon
                }else
350
                {
351
                        #my @extens=$graph->export_format();
352
                        binmode $out;
353
                        print $out $gd1->$ext;# if($ext eq 'png');
354
                        #print $out  $gd1->gif  if($ext eq 'gif');
355
                        close $out;
356
                }
357 32 alirezamon
                #text_file
358
                open(  $out, '>', "$file.txt");
359
                if (tell $out )
360
                {
361
                        warn "Cannot open $file.txt to write: $!";
362
                }
363
                else
364
                {
365
                        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
366
                        if (defined  $sample_num){
367
                                for (my $i=1;$i<=$sample_num; $i++) {
368
                                        my $l_name= $emulate->object_get_attribute("sample$i","line_name");
369
                                        my $ref=$emulate->object_get_attribute ("sample$i","result");
370
                                        my @x;
371
                                        if(defined $ref) {
372
 
373
                                                print $out "$l_name\n";
374
                                                foreach my $x (sort {$a<=>$b} keys $ref) {
375
                                                        my $y=$ref->{$x};
376
                                                        print $out "\t$x , $y\n";
377
                                                }
378
                                                print $out "\n\n";
379
                                        }
380
                                }#for
381 25 alirezamon
 
382 32 alirezamon
                        }
383
 
384
                        close $out;
385
                }
386
 
387 25 alirezamon
        }
388
 
389
 
390
 
391
        my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
392 32 alirezamon
 
393
 
394 25 alirezamon
        $self->{graphimage} = $image;
395
        my $hotspotlist;
396
        if ($self->{graphtype} eq 'bars' or
397
                $self->{graphtype} eq 'lines' or
398
                $self->{graphtype} eq 'linespoints') {
399
                foreach my $hotspot ($graph->get_hotspot) {
400
                        push @$hotspotlist, $hotspot if $hotspot;
401
                }
402
        }
403
        $self->{hotspotlist} = $hotspotlist;
404
        my $eventbox = $self->{eventbox};
405
        my @children = $eventbox->get_children;
406
        foreach my $child (@children) {
407
                $eventbox->remove($child);
408
        }
409
 
410
 
411
 
412
 
413
        $eventbox->add ($image);
414
 
415
        $eventbox->signal_connect ('button-press-event' =>
416
                sub {
417
                        my ($widget, $event) = @_;
418
                        return TRUE;
419
                        return FALSE unless $event->button == 3;
420
                        $self->{optionsmenu}->popup(
421
                                undef, # parent menu shell
422
                                undef, # parent menu item
423
                                undef, # menu pos func
424
                                undef, # data
425
                                $event->button,
426
                                $event->time
427
                        );
428
                }
429
        );
430
        $eventbox->show_all;
431
        return $eventbox;
432
}
433
 
434
 
435
############
436
#       get_graph_setting
437
###########
438
 
439
sub get_graph_setting {
440
        my ($emulate,$ref)=@_;
441
        my($width,$hight)=max_win_size();
442
        my $window=def_popwin_size($width/3,$hight/3,'Graph Setting');
443
        my $table = def_table(10, 2, FALSE);
444
        my $row=0;
445
 
446
 
447
my @data=@$ref;
448
foreach my $d (@data) {
449
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
450
}
451
 
452
 
453
 
454
 
455
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
456
        $scrolled_win->set_policy( "automatic", "automatic" );
457
        $scrolled_win->add_with_viewport($table);
458
        my $ok = def_image_button('icons/select.png',' OK ');
459
 
460
 
461
        my $mtable = def_table(10, 1, FALSE);
462
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
463
        $mtable->attach($ok,0,1,9,10,'shrink','shrink',2,2);
464
        $window->add ($mtable);
465
        $window->show_all();
466
 
467
        $ok-> signal_connect("clicked" => sub{
468
                $window->destroy;
469
                set_gui_status($emulate,"ref",1);
470
        });
471
 
472
 
473
 
474
}
475
 
476
 
477
 
478
 
479
 
480
 
481
 
482
 
483
 
484
 
485
 
486
 
487
 ################
488
 # get_color_window
489
 ###############
490
 
491
 sub get_color_window{
492
         my ($emulate,$atrebute1,$atrebute2)=@_;
493
         my $window=def_popwin_size(800,600,"Select line color");
494
         my ($r,$c)=(4,8);
495
         my $table= def_table(5,6,TRUE);
496
         for (my $col=0;$col<$c;$col++){
497
                  for (my $row=0;$row<$r;$row++){
498
                        my $color_num=$row*$c+$col;
499
                        my $color=def_colored_button("    ",$color_num);
500
                        $table->attach_defaults ($color, $col, $col+1, $row, $row+1);
501
                        $color->signal_connect("clicked"=> sub{
502
                                $emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);
503
                                #print "$emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);\n";
504
                                set_gui_status($emulate,"ref",1);
505
                                $window->destroy;
506
                        });
507
                 }
508
         }
509
 
510
         $window->add($table);
511
 
512
        $window->show_all();
513
 
514
}
515
 
516
 
517
 
518
 
519
sub check_inserted_ratios {
520
                my $str=shift;
521
                my @ratios;
522
 
523
            my @chunks=split(',',$str);
524
            foreach my $p (@chunks){
525
                        if($p !~ /^[0-9.:,]+$/){ message_dialog ("$p has invalid character(S)" ); return undef; }
526
                        my @range=split(':',$p);
527
                        my $size= scalar @range;
528
                        if($size==1){ # its a number
529
                                if ( $range[0] <= 0 || $range[0] >100  ) { message_dialog ("$range[0] is out of boundery (1:100)" ); return undef; }
530
                                push(@ratios,$range[0]);
531
                        }elsif($size ==3){# its a range
532
                                my($min,$max,$step)=@range;
533
                                if ( $min <= 0 || $min >100  ) { message_dialog ("$min in  $p is out of boundery (1:100)" ); return undef; }
534
                                if ( $max <= 0 || $max >100  ) { message_dialog ("$max in  $p is out of boundery (1:100)" ); return undef; }
535
                                for (my $i=$min; $i<=$max; $i=$i+$step){
536
                                                push(@ratios,$i);
537
                                }
538
 
539
                        }else{
540
                                 message_dialog ("$p has invalid format. The correct format for range is \$min:\$max:\$step" );
541
 
542
                        }
543
 
544
 
545
 
546
                }#foreach
547
                my @r=uniq(sort {$a<=>$b} @ratios);
548
                return \@r;
549
 
550
}
551
 
552
 
553
 
554
 
555
 
556
 
557
 
558
sub get_injection_ratios{
559
                my ($emulate,$atrebute1,$atrebute2)=@_;
560
                my $box = Gtk2::HBox->new( FALSE, 0 );
561
                my $init=$emulate->object_get_attribute($atrebute1,$atrebute2);
562
                my $entry=gen_entry($init);
563
                my $button=def_image_button("icons/right.png",'Check');
564
                $button->signal_connect("clicked" => sub {
565
                        my $text= $entry->get_text();
566
                        my $r=check_inserted_ratios($text);
567
                        if(defined      $r){
568
                                my $all=  join (',',@$r);
569
                                message_dialog ("$all" );
570
                        }
571
 
572
 
573
                });
574
                $entry->signal_connect ("changed" => sub {
575
                        my $text= $entry->get_text();
576
                        $emulate->object_add_attribute($atrebute1,$atrebute2,$text);
577
 
578
                });
579
                $box->pack_start( $entry, 1,1, 0);
580
                $box->pack_start( $button, 0, 1, 3);
581
                return  $box;
582
}
583
 
584
 
585
 
586
sub get_noc_configuration{
587 32 alirezamon
        my ($emulate,$mode,$n,$set_win) =@_;
588
 
589 28 alirezamon
        my $table=def_table(10,2,FALSE);
590
        my $row=0;
591 25 alirezamon
 
592
 
593 32 alirezamon
        my $traffics="tornado,transposed 1,transposed 2,bit reverse,bit complement,random"; #TODO hot spot for emulator
594
        my $dir = Cwd::getcwd();
595
        if($mode eq "simulate"){
596
                $traffics=$traffics.",hot spot";
597
                my $open_in       = abs_path("$ENV{PRONOC_WORK}/simulate");
598
                attach_widget_to_table ($table,$row,gen_label_in_left("Verilated file:"),gen_button_message ("Select the the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.","icons/help.png"), get_file_name_object ($emulate,"sample$n","sof_file",undef,$open_in)); $row++;
599 28 alirezamon
 
600 32 alirezamon
        }else{
601
 
602
                my $open_in       = abs_path("$ENV{PRONOC_WORK}/emulate/sof");
603
                attach_widget_to_table ($table,$row,gen_label_in_left("SoF file:"),gen_button_message ("Select the SRAM Object File (sof) for this NoC configration.","icons/help.png"), get_file_name_object ($emulate,"sample$n","sof_file",'sof',$open_in)); $row++;
604
        }
605 25 alirezamon
 
606 32 alirezamon
   my @emulateinfo = (
607 28 alirezamon
        { label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>"NoC$n", content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>"sample$n", ref_delay=> undef},
608
 
609
        { label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>"sample$n", ref_delay=>undef},
610
 
611
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>"sample$n", ref_delay=>undef},
612
 
613 32 alirezamon
        { label=>"Packet number limit per node:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>1000000, content=>"2,".MAX_PCK_NUM.",1", info=>"Each node stops sending packets when it reaches packet number limit  or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
614 28 alirezamon
 
615
{ label=>"Emulation clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>MAX_SIM_CLKs, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit  or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
616
 
617
 
618 32 alirezamon
);
619 28 alirezamon
 
620
 
621
 
622 32 alirezamon
        my @siminfo = (
623
        { label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>"NoC$n", content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>"sample$n", ref_delay=> undef, new_status=>undef},
624 28 alirezamon
 
625 32 alirezamon
        { label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>"sample$n", ref_delay=>1, new_status=>'ref_set_win'},
626
 
627
        { label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>"sample$n", ref_delay=>undef},
628
 
629
        { label=>"Total packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>200000, content=>"2,".MAX_PCK_NUM.",1", info=>"Simulation will stop when total numbr of sent packets by all nodes reaches packet number limit  or total simulation clock reach its limit", param_parent=>"sample$n", ref_delay=>undef, new_status=>undef},
630
 
631
        { label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit  or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef,  new_status=>undef},
632
        );
633
 
634
my @hotspot_info=(
635
        { label=>'Hot Spot num:', param_name=>'HOTSPOT_NUM', type=>'Spin-button', default_val=>1,
636
          content=>"1,5,1", info=>"Number of hot spot nodes in the network",
637
          param_parent=>"sample$n", ref_delay=> 1, new_status=>'ref_set_win'},
638
        { label=>'Hot Spot traffic percentage:', param_name=>'HOTSPOT_PERCENTAGE', type=>'Spin-button', default_val=>1,
639
          content=>"1,20,1", info=>"If it is set as n then each node sends n % of its traffic to each hotspot node",
640
          param_parent=>"sample$n", ref_delay=> undef, new_status=>undef},
641
 
642
        );
643
 
644
 
645
 
646
 
647
 
648
 
649
        my @info= ($mode eq "simulate")? @siminfo : @emulateinfo;
650
 
651
 
652
        foreach my $d ( @info) {
653
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
654
        }
655
        my $traffic=$emulate->object_get_attribute("sample$n","traffic");
656
 
657
        if ($traffic eq 'hot spot'){
658
                foreach my $d ( @hotspot_info) {
659
                        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
660
                }
661
                my $num=$emulate->object_get_attribute("sample$n","HOTSPOT_NUM");
662
                for (my $i=0;$i<$num;$i++){
663
                        my $m=$i+1;
664
                        $row=noc_param_widget ($emulate, "Hotspot $m tile num:", "HOTSPOT_CORE_$m", 0, 'Spin-button', "0,256,1",
665
                         "Defne the tile number which is  hotspt. All other nodes will send [Hot Spot traffic percentage] of their traffic to this node ", $table,$row,1,"sample$n" );
666
 
667
 
668
                }
669
 
670
        }
671
 
672
 
673
 
674 28 alirezamon
                my $l= "Define injection ratios. You can define individual ratios seprating by comma (\',\') or define a range of injection ratios with \$min:\$max:\$step format.
675
                        As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
676
                my $u=get_injection_ratios ($emulate,"sample$n","ratios");
677 25 alirezamon
 
678 28 alirezamon
attach_widget_to_table ($table,$row,gen_label_in_left("Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
679
 
680
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
681
        $scrolled_win->set_policy( "automatic", "automatic" );
682
        $scrolled_win->add_with_viewport($table);
683 25 alirezamon
 
684
        my $ok = def_image_button('icons/select.png','OK');
685 28 alirezamon
        my $mtable = def_table(10, 1, TRUE);
686
 
687
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
688
        $mtable-> attach ($ok , 0, 1,  9, 10,'expand','shrink',2,2);
689 25 alirezamon
 
690 32 alirezamon
        $set_win->add ($mtable);
691
        $set_win->show_all();
692 28 alirezamon
 
693 32 alirezamon
        $set_win ->signal_connect (destroy => sub{
694
 
695
                $emulate->object_add_attribute("active_setting",undef,undef);
696
        });
697 28 alirezamon
 
698
 
699
 
700
 
701
 
702
 
703
 
704 25 alirezamon
 
705
 
706 28 alirezamon
 
707
 
708 25 alirezamon
        $ok->signal_connect("clicked"=> sub{
709
                #check if sof file has been selected
710
                my $s=$emulate->object_get_attribute("sample$n","sof_file");
711
                #check if injection ratios are valid
712
                my $r=$emulate->object_get_attribute("sample$n","ratios");
713
                if(defined $s && defined $r) {
714 32 alirezamon
                                $set_win->destroy;
715
                                #$emulate->object_add_attribute("active_setting",undef,undef);
716 25 alirezamon
                                set_gui_status($emulate,"ref",1);
717
                } else {
718
 
719
                        if(!defined $s){
720 32 alirezamon
                                my $m=($mode eq 'simulate') ? "Please select NoC verilated file" : "Please select sof file!";
721
                                message_dialog($m);
722 25 alirezamon
                        } else {
723 32 alirezamon
                                 message_dialog("Please define valid injection ratio(s)!");
724 25 alirezamon
                        }
725
                }
726
        });
727 28 alirezamon
 
728 25 alirezamon
 
729 28 alirezamon
 
730
 
731 32 alirezamon
 
732 28 alirezamon
 
733
 
734
 
735 25 alirezamon
 
736
 
737
}
738
 
739
 
740
 
741
#####################
742
#               gen_widgets_column
743
###################      
744
 
745
sub gen_emulation_column {
746 32 alirezamon
        my ($emulate,$mode, $row_num,$info)=@_;
747 25 alirezamon
        my $table=def_table($row_num,10,FALSE);
748
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
749 32 alirezamon
        my($width,$hight)=max_win_size();
750
        my $set_win=def_popwin_size($width/2.5,$hight*.8,"NoC configuration setting");
751
 
752 25 alirezamon
        $scrolled_win->set_policy( "automatic", "automatic" );
753
        $scrolled_win->add_with_viewport($table);
754
        my $row=0;
755 32 alirezamon
 
756 25 alirezamon
        #title  
757 32 alirezamon
        my $title_l =($mode eq "simulate" ) ? "NoC Simulator" : "NoC Emulator";
758
        my $title=gen_label_in_center($title_l);
759
        my $box=def_vbox(FALSE, 1);
760
        $box->pack_start( $title, FALSE, FALSE, 3);
761
        my $separator = Gtk2::HSeparator->new;
762
        $box->pack_start( $separator, FALSE, FALSE, 3);
763
        $table->attach_defaults ($box , 0, 10,  $row, $row+1); $row++;
764 25 alirezamon
 
765
 
766 32 alirezamon
 
767
        my $lb=($mode ne "simulate" ) ?  gen_label_in_left("Number of emulations"): gen_label_in_left("Number of simulations");
768 25 alirezamon
        my $spin= gen_spin_object ($emulate,"emulate_num",undef,"1,100,1",1,'ref','1');
769 32 alirezamon
        $table->attach  ($lb, 0, 2, $row, $row+1,'expand','shrink',2,2);
770
        $table->attach  ($spin, 2, 4, $row, $row+1,'expand','shrink',2,2);
771 25 alirezamon
 
772
 
773 32 alirezamon
        #my $mod=gen_combobox_object ($emulate,'mode',undef, 'Emulation,Simulation','Emulation','ref','1');
774
 
775
 
776 25 alirezamon
 
777 32 alirezamon
 
778
        #$table->attach  ($lb, 4, 6, $row, $row+1,'expand','shrink',2,2);
779
        #$table->attach  ($mod, 6, 8, $row, $row+1,'expand','shrink',2,2);
780
$row++;
781
 
782
 
783
 
784
 
785
 
786
        $separator = Gtk2::HSeparator->new;
787
        $table->attach_defaults ($separator  , 0, 10,  $row, $row+1); $row++;
788
 
789 25 alirezamon
        my @positions=(0,1,2,3,6,7);
790
        my $col=0;
791
 
792 32 alirezamon
        my @title=(" Name", " Configuration Setting   ", "Line's color", "Clear Graph","  ");
793 25 alirezamon
        foreach my $t (@title){
794
 
795 32 alirezamon
                $table->attach (gen_label_in_left($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'fill','shrink',2,2);$col++;
796 25 alirezamon
        }
797
 
798
        my $traffics="Random,Transposed 1,Transposed 2,Tornado";
799
 
800
        $col=0;
801
        $row++;
802
        @positions=(0,1,2,3,4,5,6,7);
803
 
804
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
805
         if(!defined $sample_num){
806
                $sample_num=1;
807
                $emulate->object_add_attribute("emulate_num",undef,1);
808
         }
809
        my $i=0;
810 32 alirezamon
        my $active=$emulate->object_get_attribute("active_setting",undef);
811 25 alirezamon
        for ($i=1;$i<=$sample_num; $i++){
812
                $col=0;
813
                my $sample="sample$i";
814
                my $n=$i;
815
                my $set=def_image_button("icons/setting.png");
816
                my $name=$emulate->object_get_attribute($sample,"line_name");
817
                my $l;
818 32 alirezamon
                my $s=$emulate->object_get_attribute("sample$n","sof_file");
819
                #check if injection ratios are valid
820
                my $r=$emulate->object_get_attribute("sample$n","ratios");
821
                if(defined $s && defined $r && defined $name){
822
                         $l=gen_label_in_left(" $i- ".$name);
823 25 alirezamon
                } else {
824 32 alirezamon
                        $l=gen_label_in_left("Define NoC configuration");
825 25 alirezamon
                        $l->set_markup("<span  foreground= 'red' ><b>Define NoC configuration</b></span>");
826
                }
827 32 alirezamon
                #my $box=def_pack_hbox(FALSE,0,(gen_label_in_left("$i- "),$l,$set));
828
                $table->attach ($l, $positions[$col], $positions[$col+1], $row, $row+1,'fill','shrink',2,2);$col++;
829
                $table->attach ($set, $positions[$col], $positions[$col+1], $row, $row+1,'shrink','shrink',2,2);$col++;
830
 
831
 
832
                if(defined $active){#The setting windows ask for refershing so open it again
833
                        get_noc_configuration($emulate,$mode,$n,$set_win) if    ($active ==$n);
834
                }
835
 
836
 
837
 
838 25 alirezamon
                $set->signal_connect("clicked"=> sub{
839 32 alirezamon
                        $emulate->object_add_attribute("active_setting",undef,$n);
840
                        get_noc_configuration($emulate,$mode,$n,$set_win);
841 25 alirezamon
                });
842
 
843
 
844
 
845
                my $color_num=$emulate->object_get_attribute($sample,"color");
846
                if(!defined $color_num){
847
                        $color_num = $i+1;
848
                        $emulate->object_add_attribute($sample,"color",$color_num);
849
                }
850
                my $color=def_colored_button("    ",$color_num);
851
                $table->attach ($color, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
852
 
853
 
854
 
855
 
856
 
857
 
858
                $color->signal_connect("clicked"=> sub{
859
                        get_color_window($emulate,$sample,"color");
860
                });
861
 
862
                #clear line
863
                my $clear = def_image_button('icons/clear.png');
864
                $clear->signal_connect("clicked"=> sub{
865
                        $emulate->object_add_attribute ($sample,'result',undef);
866
                        set_gui_status($emulate,"ref",2);
867
                });
868
                $table->attach ($clear, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
869
                #run/pause
870
                my $run = def_image_button('icons/run.png','Run');
871
                $table->attach ($run, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
872
                $run->signal_connect("clicked"=> sub{
873
                        $emulate->object_add_attribute ($sample,"status","run");
874
                        #start the emulator if it is not running        
875
                        my $status= $emulate->object_get_attribute('status',undef);
876
                        if($status ne 'run'){
877
 
878 32 alirezamon
                                run_emulator($emulate,$info) if($mode eq 'emulate');
879
                                run_simulator($emulate,$info) if($mode eq 'simulate');
880 25 alirezamon
                                set_gui_status($emulate,"ref",2);
881
                        }
882
 
883
                });
884
 
885
                my $image = gen_noc_status_image($emulate,$i);
886
 
887
                $table->attach_defaults ($image, $positions[$col], $positions[$col+1], $row, $row+1);
888
 
889
 
890
                $row++;
891
 
892
        }
893
        while ( $row<15){
894
                $table->attach_defaults (gen_label_in_left(' '), 0, 1, $row, $row+1); $row++;
895
        }
896
 
897
 
898
 
899
 
900 32 alirezamon
        return ($scrolled_win,$set_win);
901 25 alirezamon
}
902
 
903
 
904
 
905
 
906
##########
907
#
908
##########
909
 
910
sub check_sample{
911
        my ($emulate,$i,$info)=@_;
912
        my $status=1;
913
        my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
914
        # ckeck if sample have sof file
915
        if(!defined $sof){
916
                add_info($info, "Error: SoF file has not set for NoC$i!\n");
917
                $emulate->object_add_attribute ("sample$i","status","failed");
918
                $status=0;
919
        } else {
920
                # ckeck if sof file has info file 
921
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
922
                my $sof_info="$path$name.inf";
923
                if(!(-f $sof_info)){
924
                        add_info($info, "Could not find $name.inf file in $path. An information file is required for each sof file containig the device name and  NoC configuration. Press F4 for more help.\n");
925
                        $emulate->object_add_attribute ("sample$i","status","failed");
926
                        $status=0;
927
                }else { #add info
928 28 alirezamon
                        my $pp= do $sof_info ;
929
 
930
                        my $p=$pp->{'noc_param'};
931
 
932
 
933
 
934
 
935
 
936 25 alirezamon
                        $status=0 if $@;
937
                        message_dialog("Error reading: $@") if $@;
938
                        if ($status==1){
939
                                $emulate->object_add_attribute ("sample$i","noc_info",$p) ;
940
                                        #print"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n";
941
 
942
                        }
943
 
944
 
945
 
946
                }
947
        }
948
 
949
 
950
        return $status;
951
 
952
 
953
}
954
 
955
 
956
 
957
 
958
##########
959
#  run external commands
960
##########
961
 
962
 
963
 
964
 
965
 
966
sub run_cmd_in_back_ground
967
{
968
  my $command = shift;
969
 
970
 
971
 
972
 
973
 
974
 
975
  ### Start running the Background Job:
976
    my $proc = Proc::Background->new($command);
977
    my $PID = $proc->pid;
978
    my $start_time = $proc->start_time;
979
    my $alive = $proc->alive;
980
 
981
  ### While $alive is NOT '0', then keep checking till it is...
982
  #  *When $alive is '0', it has finished executing.
983
  while($alive ne 0)
984
  {
985
    $alive = $proc->alive;
986
 
987
    # This while loop will cause Gtk2 to conti processing events, if
988
    # there are events pending... *which there are...
989
    while (Gtk2->events_pending) {
990
      Gtk2->main_iteration;
991
    }
992
    Gtk2::Gdk->flush;
993
 
994
    usleep(1000);
995
  }
996
 
997
  my $end_time = $proc->end_time;
998
 # print "*Command Completed at $end_time, with PID = $PID\n\n";
999
 
1000
  # Since the while loop has exited, the BG job has finished running:
1001
  # so close the pop-up window...
1002
 # $popup_window->hide;
1003
 
1004
  # Get the RETCODE from the Background Job using the 'wait' method
1005
  my $retcode = $proc->wait;
1006
  $retcode /= 256;
1007
 
1008
  print "\t*RETCODE == $retcode\n\n";
1009
  Gtk2::Gdk->flush;
1010
  ### Check if the RETCODE returned with an Error:
1011
  if ($retcode ne 0) {
1012
    print "Error: The Background Job ($command) returned with an Error...!\n";
1013
    return 1;
1014
  } else {
1015
    #print "Success: The Background Job Completed Successfully...!\n";
1016
    return 0;
1017
  }
1018
 
1019
}
1020
 
1021
 
1022
 
1023
 
1024
sub run_cmd_in_back_ground_get_stdout
1025
{
1026
        my $cmd=shift;
1027
        my $exit;
1028
        my ($stdout, $stderr);
1029
        capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
1030
        return ($stdout,$exit,$stderr);
1031
 
1032
}
1033
 
1034
 
1035
#############
1036
#  images
1037
##########
1038
sub get_status_gif{
1039
                my $emulate=shift;
1040
                my $status= $emulate->object_get_attribute('status',undef);
1041
                if($status eq 'ideal'){
1042
                        return show_gif ("icons/ProNoC.png");
1043
                } elsif ($status eq 'run') {
1044
                        my($width,$hight)=max_win_size();
1045
                        my $image=($width>=1600)? "icons/hamster_l.gif":
1046
                                  ($width>=1200)? "icons/hamster_m.gif": "icons/hamster_s.gif";
1047
 
1048
                        return show_gif ($image);
1049
                } elsif ($status eq 'programer_failed') {
1050
                        return show_gif ("icons/Error.png");
1051
                }
1052
 
1053
}
1054
 
1055
 
1056
 
1057
 
1058
sub gen_noc_status_image {
1059
        my ($emulate,$i)=@_;
1060
        my   $status= $emulate->object_get_attribute ("sample$i","status");
1061
         $status='' if(!defined  $status);
1062
        my $image;
1063
        my $vbox = Gtk2::HBox->new (TRUE,1);
1064
        $image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
1065
        $image = def_image("icons/button_ok.png") if($status eq "done");
1066
        $image = def_image("icons/cancel.png") if($status eq "failed");
1067
        #$image_file = "icons/load.gif" if($status eq "run");
1068
 
1069
        if (defined $image) {
1070
                my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
1071
        my $frame = Gtk2::Frame->new;
1072
                $frame->set_shadow_type ('in');
1073
                # Animation
1074
                $frame->add ($image);
1075
                $align->add ($frame);
1076
                $vbox->pack_start ($align, FALSE, FALSE, 0);
1077
        }
1078
        return $vbox;
1079
 
1080
}
1081
 
1082
 
1083
############
1084
#       run_emulator
1085
###########
1086
 
1087
sub run_emulator {
1088
        my ($emulate,$info)=@_;
1089
        #return if(!check_samples($emulate,$info));
1090
        $emulate->object_add_attribute('status',undef,'run');
1091
        set_gui_status($emulate,"ref",1);
1092
        show_info($info, "start emulation\n");
1093
 
1094
        #search for available usb blaster
1095
        my $cmd = "jtagconfig";
1096
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
1097
        my @matches= ($stdout =~ /USB-Blaster.*/g);
1098
        my $usb_blaster=$matches[0];
1099
        if (!defined $usb_blaster){
1100
                add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
1101
                $emulate->object_add_attribute('status',undef,'programer_failed');
1102
                set_gui_status($emulate,"ref",2);
1103 28 alirezamon
                #/***/
1104 25 alirezamon
                return;
1105
        }else{
1106
                add_info($info, "find $usb_blaster\n");
1107
        }
1108
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
1109
        for (my $i=1; $i<=$sample_num; $i++){
1110
                my $status=$emulate->object_get_attribute ("sample$i","status");
1111
                next if($status ne "run");
1112
                next if(!check_sample($emulate,$i,$info));
1113
                my $r= $emulate->object_get_attribute("sample$i","ratios");
1114
                my @ratios=@{check_inserted_ratios($r)};
1115
                #$emulate->object_add_attribute ("sample$i","status","run");                    
1116
                my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
1117
                add_info($info, "Programe FPGA device using $sof\n");
1118
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
1119
 
1120
 
1121
                my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
1122 28 alirezamon
 
1123 25 alirezamon
                #my $output = `$cmd 2>&1 1>/dev/null`;           # either with backticks
1124 28 alirezamon
 
1125
 
1126
 
1127
                #/***/
1128 25 alirezamon
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
1129
                if($exit){#programming FPGA board has failed
1130
                        $emulate->object_add_attribute('status',undef,'programer_failed');
1131
                        add_info($info, "$stdout\n");
1132
                        $emulate->object_add_attribute ("sample$i","status","failed");
1133
                        set_gui_status($emulate,"ref",2);
1134
                        next;
1135 28 alirezamon
                }
1136
                #print "$stdout\n";
1137
 
1138 25 alirezamon
                # read noc configuration 
1139
 
1140
 
1141 28 alirezamon
 
1142
 
1143 25 alirezamon
 
1144 28 alirezamon
                foreach  my $ratio_in (@ratios){
1145 25 alirezamon
 
1146 28 alirezamon
                        add_info($info, "Configure packet generators for  injection ratio of $ratio_in \% \n");
1147
                        next if(!programe_pck_gens($emulate,$i,$ratio_in,$info));
1148
 
1149
                        my $avg=read_pack_gen($emulate,$i,$info);
1150
                        next if (!defined $avg);
1151
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
1152
                        my %results;
1153
                        %results= %{$ref} if(defined $ref);
1154
                        #push(@results,$avg);
1155
                        $results{$ratio_in}=$avg;
1156
                        $emulate->object_add_attribute ("sample$i","result",\%results);
1157
                        set_gui_status($emulate,"ref",2);
1158 25 alirezamon
 
1159
                }
1160
                $emulate->object_add_attribute ("sample$i","status","done");
1161
 
1162
        }
1163
 
1164
        add_info($info, "End emulation!\n");
1165
        $emulate->object_add_attribute('status',undef,'ideal');
1166
        set_gui_status($emulate,"ref",1);
1167
}
1168
 
1169
 
1170
 
1171
 
1172
 
1173
 
1174
 
1175
 
1176
 
1177
 
1178
sub process_notebook_gen{
1179 32 alirezamon
                my ($emulate,$info,$mode)=@_;
1180 25 alirezamon
                my $notebook = Gtk2::Notebook->new;
1181
                $notebook->set_tab_pos ('left');
1182
                $notebook->set_scrollable(TRUE);
1183
                $notebook->can_focus(FALSE);
1184 32 alirezamon
 
1185 25 alirezamon
 
1186 32 alirezamon
                my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info);
1187
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run emulator  ")) if($mode eq "emulate");
1188
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run simulator ")) if($mode eq "simulate");
1189 25 alirezamon
 
1190
 
1191 32 alirezamon
                my $page2=get_noc_setting_gui ($emulate,$info,$mode);
1192
                my $pp=$notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic (" _Generate NoC \n Configuration"));
1193 25 alirezamon
 
1194
 
1195
 
1196 32 alirezamon
 
1197 25 alirezamon
                my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1198
                $scrolled_win->set_policy( "automatic", "automatic" );
1199
                $scrolled_win->add_with_viewport($notebook);
1200
                $scrolled_win->show_all;
1201
                my $page_num=$emulate->object_get_attribute ("process_notebook","currentpage");
1202
                $notebook->set_current_page ($page_num) if(defined $page_num);
1203
                $notebook->signal_connect( 'switch-page'=> sub{
1204
                        $emulate->object_add_attribute ("process_notebook","currentpage",$_[2]);        #save the new pagenumber
1205
 
1206
                });
1207
 
1208 32 alirezamon
                return ($scrolled_win,$set_win);
1209 25 alirezamon
 
1210
}
1211
 
1212
 
1213
sub get_noc_setting_gui {
1214 32 alirezamon
        my ($emulate,$info_text,$mode)=@_;
1215 28 alirezamon
        my $table=def_table(20,10,FALSE);#      my ($row,$col,$homogeneous)=@_;
1216
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1217
        $scrolled_win->set_policy( "automatic", "automatic" );
1218
        $scrolled_win->add_with_viewport($table);
1219
        my $row=noc_config ($emulate,$table);
1220 25 alirezamon
 
1221 28 alirezamon
        my($label,$param,$default,$content,$type,$info);
1222
        my @dirs = grep {-d} glob("../src_emulate/fpga/*");
1223
        my $fpgas;
1224
        foreach my $dir (@dirs) {
1225
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
1226
                $default=$name;
1227
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
1228
 
1229
        }
1230
 
1231 25 alirezamon
 
1232 32 alirezamon
my @fpgainfo;
1233 25 alirezamon
 
1234 32 alirezamon
        if($mode eq "emulate"){
1235 28 alirezamon
 
1236 32 alirezamon
        @fpgainfo = (
1237 28 alirezamon
        { label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
1238
        { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
1239
        { label=>"Project directory", param_name=>"SOF_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/emulate", content=>undef, info=>"Define the working directory for generating .sof file", param_parent=>'fpga_param',ref_delay=>undef },
1240
 
1241
);
1242 32 alirezamon
 
1243
}
1244
else {
1245
 
1246
@fpgainfo = (
1247
        #{ label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
1248
        { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
1249
        { label=>"Project directory", param_name=>"BIN_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/simulate", content=>undef, info=>"Define the working directory for generating simulation executable binarry file", param_parent=>'sim_param',ref_delay=>undef },
1250
 
1251
);
1252
}
1253
 
1254
 
1255
 
1256
 
1257
foreach my $d (@fpgainfo) {
1258 28 alirezamon
        $row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
1259
}
1260
 
1261 32 alirezamon
 
1262
 
1263
 
1264
 
1265 25 alirezamon
 
1266
 
1267
 
1268
 
1269
                my $generate = def_image_button('icons/gen.png','Generate');
1270
 
1271
 
1272
                $table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
1273
 
1274
                $generate->signal_connect ('clicked'=> sub{
1275 32 alirezamon
                        generate_sof_file($emulate,$info_text) if($mode eq "emulate");
1276
                        generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
1277 25 alirezamon
 
1278
                });
1279
 
1280
 
1281
            return $scrolled_win;
1282
 
1283
}
1284
 
1285
 
1286
 
1287
 
1288
 
1289
 
1290
 
1291
sub generate_sof_file {
1292
        my ($emulate,$info)=@_;
1293
                print "start compilation\n";
1294
                my $fpga_board=  $emulate->object_get_attribute ('fpga_param',"FPGA_BOARD");
1295
                #create work directory
1296
                my $dir_name=$emulate->object_get_attribute ('fpga_param',"SOF_DIR");
1297 28 alirezamon
                $dir_name="$dir_name/$fpga_board";
1298 25 alirezamon
                my $save_name=$emulate->object_get_attribute ('fpga_param',"SAVE_NAME");
1299
                $save_name=$fpga_board if (!defined $save_name);
1300
                $dir_name= "$dir_name/$save_name";
1301
 
1302
                show_info($info, "generate working directory: $dir_name\n");
1303
 
1304
 
1305
                #copy all noc source codes
1306 28 alirezamon
                my @files = split(/\s*,\s*/,EMULATION_RTLS);
1307 25 alirezamon
 
1308
                my $dir = Cwd::getcwd();
1309
                my $project_dir   = abs_path("$dir/../../");
1310
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $dir_name/src/" );
1311 32 alirezamon
 
1312
 
1313
 
1314 28 alirezamon
                copy_file_and_folders(\@files,$project_dir,"$dir_name/src/");
1315
 
1316
                foreach my $f(@files){
1317
                        my $n="$project_dir/$f";
1318
                        if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
1319
                                add_info ($info, " WARNING: file/folder  \"$f\" ($n)  dose not exists \n");
1320
 
1321
                         }
1322
 
1323
 
1324
                }
1325 25 alirezamon
 
1326
 
1327 28 alirezamon
 
1328 25 alirezamon
 
1329 28 alirezamon
 
1330 25 alirezamon
                #copy fpga board files
1331
 
1332
                ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -Rf \"$project_dir/mpsoc/src_emulate/fpga/$fpga_board\"/*    \"$dir_name/\"");
1333
                if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout); return;}
1334
 
1335 28 alirezamon
                #generate parameters for emulator_top.v file
1336
                my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
1337
                open(FILE,  ">$dir_name/src/noc_parameters.v") || die "Can not open: $!";
1338
                print FILE $localparam;
1339 25 alirezamon
                close(FILE) || die "Error closing file: $!";
1340 28 alirezamon
                open(FILE,  ">$dir_name/src/pass_parameters.v") || die "Can not open: $!";
1341
                print FILE $pass_param;
1342
                close(FILE) || die "Error closing file: $!";
1343 25 alirezamon
 
1344
 
1345
                #compile the code  
1346
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
1347
                add_info($info, "Start Quartus compilation\n $stdout\n");
1348 28 alirezamon
                my @compilation_command =("cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_map --64bit $fpga_board --read_settings_files=on ",
1349
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_fit --64bit $fpga_board --read_settings_files=on ",
1350
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_asm --64bit $fpga_board --read_settings_files=on ",
1351
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_sta --64bit $fpga_board ");
1352
 
1353
 
1354
 
1355
 
1356
 
1357
                foreach my $cmd (@compilation_command){
1358
                        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $cmd);
1359
                        if($exit != 0){
1360
                                print "Quartus compilation failed !\n";
1361
                                add_info($info, "Quartus compilation failed !\n$cmd\n $stdout\n");
1362
                                return;
1363
                        }
1364 25 alirezamon
 
1365 28 alirezamon
                }
1366
 
1367
 
1368
 
1369 25 alirezamon
                        #save sof file
1370
                        my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
1371 28 alirezamon
                        mkpath("$sofdir/$fpga_board/",1,01777);
1372
                        open(FILE,  ">$sofdir/$fpga_board/$save_name.inf") || die "Can not open: $!";
1373 25 alirezamon
                        print FILE perl_file_header("$save_name.inf");
1374 28 alirezamon
                        my %pp;
1375
                        $pp{'noc_param'}= $emulate->{'noc_param'};
1376
                        $pp{'fpga_param'}= $emulate->{'fpga_param'};
1377
                        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
1378 25 alirezamon
                        close(FILE) || die "Error closing file: $!";
1379 28 alirezamon
 
1380
 
1381
                        #find  $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof" 
1382
                        @files = File::Find::Rule->file()
1383
                            ->name( '*.sof' )
1384
                            ->in( "$dir_name" );
1385
                        copy($files[0],"$sofdir/$fpga_board/$save_name.sof") or do {
1386
                                my $err= "Error copy($files[0] , $sofdir/$fpga_board/$save_name.sof";
1387
                                print "$err\n";
1388
                                message_dialog($err);
1389
                                return;
1390
                        };
1391
                        message_dialog("sof file has been generated successfully");
1392 25 alirezamon
 
1393
 
1394
 
1395
}
1396
 
1397
##########
1398
#       save_emulation
1399
##########
1400
sub save_emulation {
1401
        my ($emulate)=@_;
1402
        # read emulation name
1403
        my $name=$emulate->object_get_attribute ("emulate_name",undef);
1404
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
1405
        if ($s == 0){
1406
                message_dialog("Please set emulation name!");
1407
                return 0;
1408
        }
1409
        # Write object file
1410
        open(FILE,  ">lib/emulate/$name.EML") || die "Can not open: $!";
1411
        print FILE perl_file_header("$name.EML");
1412
        print FILE Data::Dumper->Dump([\%$emulate],[$name]);
1413
        close(FILE) || die "Error closing file: $!";
1414
        message_dialog("Emulation saved as lib/emulate/$name.EML!");
1415
        return 1;
1416
}
1417
 
1418
#############
1419
#       load_emulation
1420
############
1421
 
1422
sub load_emulation {
1423
        my ($emulate,$info)=@_;
1424
        my $file;
1425
        my $dialog = Gtk2::FileChooserDialog->new(
1426
                'Select a File', undef,
1427
                'open',
1428
                'gtk-cancel' => 'cancel',
1429
                'gtk-ok'     => 'ok',
1430
                );
1431
 
1432
        my $filter = Gtk2::FileFilter->new();
1433
        $filter->set_name("EML");
1434
        $filter->add_pattern("*.EML");
1435
        $dialog->add_filter ($filter);
1436
        my $dir = Cwd::getcwd();
1437
        $dialog->set_current_folder ("$dir/lib/emulate");
1438
 
1439
 
1440
        if ( "ok" eq $dialog->run ) {
1441
                $file = $dialog->get_filename;
1442
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1443
                if($suffix eq '.EML'){
1444
                        my $pp= eval { do $file };
1445
                        if ($@ || !defined $pp){
1446
                                add_info($info,"**Error reading  $file file: $@\n");
1447
                                 $dialog->destroy;
1448
                                return;
1449
                        }
1450
 
1451
                        clone_obj($emulate,$pp);
1452
                        #message_dialog("done!");                               
1453
                }
1454
     }
1455
     $dialog->destroy;
1456
}
1457
 
1458
############
1459
#    main
1460
############
1461
sub emulator_main{
1462
 
1463
        add_color_to_gd();
1464
        my $emulate= emulator->emulator_new();
1465
        set_gui_status($emulate,"ideal",0);
1466
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
1467
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
1468
 
1469
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
1470
        my ($infobox,$info)= create_text();
1471
        my $refresh = Gtk2::Button->new_from_stock('ref');
1472
 
1473
 
1474
 
1475
 
1476
 
1477 32 alirezamon
        my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
1478 25 alirezamon
        my $chart   =gen_chart  ($emulate);
1479
 
1480
 
1481
 
1482
        $main_table->set_row_spacings (4);
1483
        $main_table->set_col_spacings (1);
1484
 
1485
        #my  $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
1486
 
1487
 
1488
        my $generate = def_image_button('icons/forward.png','Run all');
1489
        my $open = def_image_button('icons/browse.png','Load');
1490
 
1491
 
1492
 
1493
 
1494
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
1495
        $entry->signal_connect( 'changed'=> sub{
1496
                my $name=$entry->get_text();
1497
                $emulate->object_add_attribute ("emulate_name",undef,$name);
1498
        });
1499
        my $save = def_image_button('icons/save.png','Save');
1500
        $entrybox->pack_end($save,   FALSE, FALSE,0);
1501
 
1502
 
1503
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1504
        my $image = get_status_gif($emulate);
1505
 
1506
 
1507
 
1508
 
1509
 
1510
        $left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
1511
        $left_table->attach_defaults ($image , 0, 6, 20, 24);
1512
        $left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
1513
        $left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
1514
        $right_table->attach_defaults ($infobox  , 0, 6, 0,12);
1515
        $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1516
        $right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
1517
        $main_table->attach_defaults ($left_table , 0, 6, 0, 25);
1518
        $main_table->attach_defaults ($right_table , 6, 12, 0, 25);
1519
 
1520
 
1521
 
1522
        #referesh the mpsoc generator 
1523
        $refresh-> signal_connect("clicked" => sub{
1524
                my $name=$emulate->object_get_attribute ("emulate_name",undef);
1525
                $entry->set_text($name) if(defined $name);
1526
 
1527
 
1528
                $conf_box->destroy();
1529 32 alirezamon
                $set_win->destroy();
1530 25 alirezamon
                $chart->destroy();
1531
                $image->destroy();
1532
                $image = get_status_gif($emulate);
1533 32 alirezamon
 
1534
                ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
1535 25 alirezamon
                $chart   =gen_chart  ($emulate);
1536
                $left_table->attach_defaults ($image , 0, 6, 20, 24);
1537
                $left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
1538
                $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1539
 
1540
                $conf_box->show_all();
1541
                $main_table->show_all();
1542
 
1543
 
1544
        });
1545
 
1546
 
1547
 
1548
        #check soc status every 0.5 second. referesh device table if there is any changes 
1549
        Glib::Timeout->add (100, sub{
1550
 
1551
                my ($state,$timeout)= get_gui_status($emulate);
1552
 
1553
                if ($timeout>0){
1554
                        $timeout--;
1555
                        set_gui_status($emulate,$state,$timeout);
1556
 
1557
                }
1558 32 alirezamon
                elsif($state eq 'ref_set_win'){
1559
                        my $s=$emulate->object_get_attribute("active_setting",undef);
1560
                        $set_win->destroy();
1561
                        $emulate->object_add_attribute("active_setting",undef,$s);
1562
                        $refresh->clicked;
1563
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
1564
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
1565
                        set_gui_status($emulate,"ideal",0);
1566
 
1567
                }
1568 25 alirezamon
                elsif( $state ne "ideal" ){
1569
                        $refresh->clicked;
1570
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
1571
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
1572
                        set_gui_status($emulate,"ideal",0);
1573
 
1574
                }
1575
                return TRUE;
1576
 
1577
        } );
1578
 
1579
 
1580
        $generate-> signal_connect("clicked" => sub{
1581
                my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
1582
                for (my $i=1; $i<=$sample_num; $i++){
1583
                        $emulate->object_add_attribute ("sample$i","status","run");
1584
                }
1585
                run_emulator($emulate,\$info);
1586
                #set_gui_status($emulate,"ideal",2);
1587
 
1588
        });
1589
 
1590
#       $wb-> signal_connect("clicked" => sub{ 
1591
#               wb_address_setting($mpsoc);
1592
#       
1593
#       });
1594
 
1595
        $open-> signal_connect("clicked" => sub{
1596
 
1597
                load_emulation($emulate,\$info);
1598
                set_gui_status($emulate,"ref",5);
1599
 
1600
        });
1601
 
1602
        $save-> signal_connect("clicked" => sub{
1603
                save_emulation($emulate);
1604
                set_gui_status($emulate,"ref",5);
1605
 
1606
 
1607
        });
1608
 
1609
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1610
                $sc_win->set_policy( "automatic", "automatic" );
1611
                $sc_win->add_with_viewport($main_table);
1612
 
1613
        return $sc_win;
1614
 
1615
 
1616
}
1617
 
1618
 
1619
 
1620 32 alirezamon
 
1621
 
1622
 
1623
 
1624
############
1625
#       run_simulator
1626
###########
1627
 
1628
sub run_simulator {
1629
        my ($simulate,$info)=@_;
1630
        #return if(!check_samples($emulate,$info));
1631
        $simulate->object_add_attribute('status',undef,'run');
1632
        set_gui_status($simulate,"ref",1);
1633
        show_info($info, "Start Simulation\n");
1634
 
1635
        my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
1636
        for (my $i=1; $i<=$sample_num; $i++){
1637
                my $status=$simulate->object_get_attribute ("sample$i","status");
1638
                next if($status ne "run");
1639
                next if(!check_sample($simulate,$i,$info));
1640
                my $r= $simulate->object_get_attribute("sample$i","ratios");
1641
                my @ratios=@{check_inserted_ratios($r)};
1642
                #$emulate->object_add_attribute ("sample$i","status","run");                    
1643
                my $bin=$simulate->object_get_attribute ("sample$i","sof_file");
1644
 
1645
                #load traffic configuration
1646
                my $patern=$simulate->object_get_attribute ("sample$i",'traffic');
1647
                my $PCK_SIZE=$simulate->object_get_attribute ("sample$i","PCK_SIZE");
1648
                my $PCK_NUM_LIMIT=$simulate->object_get_attribute ("sample$i","PCK_NUM_LIMIT");
1649
                my $SIM_CLOCK_LIMIT=$simulate->object_get_attribute ("sample$i","SIM_CLOCK_LIMIT");
1650
 
1651
 
1652
                my $HOTSPOT_PERCENTAGE=$simulate->object_get_attribute ("sample$i",'HOTSPOT_PERCENTAGE');
1653
        my $HOTSPOT_NUM=$simulate->object_get_attribute ("sample$i","HOTSPOT_NUM");
1654
                my $HOTSPOT_CORE_1=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_1");
1655
        my $HOTSPOT_CORE_2=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_2");
1656
        my $HOTSPOT_CORE_3=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_3");
1657
        my $HOTSPOT_CORE_4=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_4");
1658
        my $HOTSPOT_CORE_5=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_5");
1659
 
1660
                $HOTSPOT_PERCENTAGE = 0 if (!defined $HOTSPOT_PERCENTAGE);
1661
                $HOTSPOT_NUM=0 if (!defined $HOTSPOT_NUM);
1662
                $HOTSPOT_CORE_1=0 if (!defined $HOTSPOT_CORE_1);
1663
        $HOTSPOT_CORE_2=0 if (!defined $HOTSPOT_CORE_2);
1664
        $HOTSPOT_CORE_3=0 if (!defined $HOTSPOT_CORE_3);
1665
        $HOTSPOT_CORE_4=0 if (!defined $HOTSPOT_CORE_4);
1666
        $HOTSPOT_CORE_5=0 if (!defined $HOTSPOT_CORE_5);
1667
 
1668
 
1669
 
1670
 
1671
 
1672
 
1673
 
1674
                foreach  my $ratio_in (@ratios){
1675
 
1676
                        add_info($info, "Run $bin with  injection ratio of $ratio_in \% \n");
1677
                        my $cmd="$bin -t \"$patern\"  -s $PCK_SIZE  -n  $PCK_NUM_LIMIT  -c      $SIM_CLOCK_LIMIT   -i $ratio_in -p \"100,0,0,0,0\"  -h \"$HOTSPOT_PERCENTAGE,$HOTSPOT_NUM,$HOTSPOT_CORE_1,$HOTSPOT_CORE_2,$HOTSPOT_CORE_3,$HOTSPOT_CORE_4,$HOTSPOT_CORE_5\"";
1678
                                add_info($info, "$cmd \n");
1679
                                my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout("$cmd");
1680
                                if($exit){
1681
                                        add_info($info, "Error in running simulation: $stderr \n");
1682
                                        return;
1683
                                }
1684
                                my @q =split  (/average latency =/,$stdout);
1685
                                my $d=$q[1];
1686
                                @q =split  (/\n/,$d);
1687
                                my $avg=$q[0];
1688
                                #my $avg = sprintf("%.1f", $avg);
1689
 
1690
 
1691
 
1692
 
1693
                        next if (!defined $avg);
1694
                        my $ref=$simulate->object_get_attribute ("sample$i","result");
1695
                        my %results;
1696
                        %results= %{$ref} if(defined $ref);
1697
                        #push(@results,$avg);
1698
                        $results{$ratio_in}=$avg;
1699
                        $simulate->object_add_attribute ("sample$i","result",\%results);
1700
                        set_gui_status($simulate,"ref",2);
1701
 
1702
 
1703
 
1704
 
1705
 
1706
 
1707
                }
1708
                $simulate->object_add_attribute ("sample$i","status","done");
1709
 
1710
        }
1711
 
1712
        add_info($info, "Simulation is done!\n");
1713
        $simulate->object_add_attribute('status',undef,'ideal');
1714
        set_gui_status($simulate,"ref",1);
1715
}
1716
 
1717
 
1718
 
1719
 
1720
 

powered by: WebSVN 2.1.0

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