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 34

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

powered by: WebSVN 2.1.0

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