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 37

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 37 alirezamon
                                push(@x, sort {$a<=>$b} keys %{$ref});
100 25 alirezamon
                        }
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 37 alirezamon
                                                foreach my $x (sort {$a<=>$b} keys %{$ref}) {
411 32 alirezamon
                                                        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 36 alirezamon
 
949
        my $dir = Cwd::getcwd();
950
        my $project_dir   = abs_path("$dir/../../"); #mpsoc directory address
951
        $sof= "$project_dir/$sof"   if(!(-f $sof));
952
 
953
 
954 25 alirezamon
        # ckeck if sample have sof file
955
        if(!defined $sof){
956
                add_info($info, "Error: SoF file has not set for NoC$i!\n");
957
                $emulate->object_add_attribute ("sample$i","status","failed");
958
                $status=0;
959
        } else {
960
                # ckeck if sof file has info file 
961
                my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
962 36 alirezamon
                my $sof_info= "$path$name.inf";
963 25 alirezamon
                if(!(-f $sof_info)){
964
                        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");
965
                        $emulate->object_add_attribute ("sample$i","status","failed");
966
                        $status=0;
967
                }else { #add info
968 28 alirezamon
                        my $pp= do $sof_info ;
969
 
970
                        my $p=$pp->{'noc_param'};
971
 
972
 
973
 
974
 
975
 
976 25 alirezamon
                        $status=0 if $@;
977
                        message_dialog("Error reading: $@") if $@;
978
                        if ($status==1){
979
                                $emulate->object_add_attribute ("sample$i","noc_info",$p) ;
980
                                        #print"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n";
981
 
982
                        }
983
 
984
 
985
 
986
                }
987
        }
988
 
989
 
990
        return $status;
991
 
992
 
993
}
994
 
995
 
996
 
997
 
998
##########
999
#  run external commands
1000
##########
1001
 
1002
 
1003
 
1004
 
1005
 
1006
sub run_cmd_in_back_ground
1007
{
1008
  my $command = shift;
1009
 
1010
 
1011
 
1012
 
1013
 
1014
 
1015
  ### Start running the Background Job:
1016
    my $proc = Proc::Background->new($command);
1017
    my $PID = $proc->pid;
1018
    my $start_time = $proc->start_time;
1019
    my $alive = $proc->alive;
1020
 
1021
  ### While $alive is NOT '0', then keep checking till it is...
1022
  #  *When $alive is '0', it has finished executing.
1023
  while($alive ne 0)
1024
  {
1025
    $alive = $proc->alive;
1026
 
1027
    # This while loop will cause Gtk2 to conti processing events, if
1028
    # there are events pending... *which there are...
1029
    while (Gtk2->events_pending) {
1030
      Gtk2->main_iteration;
1031
    }
1032
    Gtk2::Gdk->flush;
1033
 
1034
    usleep(1000);
1035
  }
1036
 
1037
  my $end_time = $proc->end_time;
1038
 # print "*Command Completed at $end_time, with PID = $PID\n\n";
1039
 
1040
  # Since the while loop has exited, the BG job has finished running:
1041
  # so close the pop-up window...
1042
 # $popup_window->hide;
1043
 
1044
  # Get the RETCODE from the Background Job using the 'wait' method
1045
  my $retcode = $proc->wait;
1046
  $retcode /= 256;
1047
 
1048
  print "\t*RETCODE == $retcode\n\n";
1049
  Gtk2::Gdk->flush;
1050
  ### Check if the RETCODE returned with an Error:
1051
  if ($retcode ne 0) {
1052
    print "Error: The Background Job ($command) returned with an Error...!\n";
1053
    return 1;
1054
  } else {
1055
    #print "Success: The Background Job Completed Successfully...!\n";
1056
    return 0;
1057
  }
1058
 
1059
}
1060
 
1061
 
1062
 
1063
 
1064
sub run_cmd_in_back_ground_get_stdout
1065
{
1066
        my $cmd=shift;
1067
        my $exit;
1068
        my ($stdout, $stderr);
1069
        capture { $exit=run_cmd_in_back_ground($cmd) } \$stdout, \$stderr;
1070
        return ($stdout,$exit,$stderr);
1071
 
1072
}
1073
 
1074
 
1075
#############
1076
#  images
1077
##########
1078
sub get_status_gif{
1079
                my $emulate=shift;
1080
                my $status= $emulate->object_get_attribute('status',undef);
1081
                if($status eq 'ideal'){
1082
                        return show_gif ("icons/ProNoC.png");
1083
                } elsif ($status eq 'run') {
1084
                        my($width,$hight)=max_win_size();
1085
                        my $image=($width>=1600)? "icons/hamster_l.gif":
1086
                                  ($width>=1200)? "icons/hamster_m.gif": "icons/hamster_s.gif";
1087
 
1088
                        return show_gif ($image);
1089
                } elsif ($status eq 'programer_failed') {
1090
                        return show_gif ("icons/Error.png");
1091
                }
1092
 
1093
}
1094
 
1095
 
1096
 
1097
 
1098
sub gen_noc_status_image {
1099
        my ($emulate,$i)=@_;
1100
        my   $status= $emulate->object_get_attribute ("sample$i","status");
1101
         $status='' if(!defined  $status);
1102
        my $image;
1103
        my $vbox = Gtk2::HBox->new (TRUE,1);
1104
        $image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
1105 34 alirezamon
        $image = def_icon("icons/button_ok.png") if($status eq "done");
1106
        $image = def_icon("icons/cancel.png") if($status eq "failed");
1107 25 alirezamon
        #$image_file = "icons/load.gif" if($status eq "run");
1108
 
1109
        if (defined $image) {
1110
                my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
1111
        my $frame = Gtk2::Frame->new;
1112
                $frame->set_shadow_type ('in');
1113
                # Animation
1114
                $frame->add ($image);
1115
                $align->add ($frame);
1116
                $vbox->pack_start ($align, FALSE, FALSE, 0);
1117
        }
1118
        return $vbox;
1119
 
1120
}
1121
 
1122
 
1123
############
1124
#       run_emulator
1125
###########
1126
 
1127
sub run_emulator {
1128
        my ($emulate,$info)=@_;
1129
        #return if(!check_samples($emulate,$info));
1130
        $emulate->object_add_attribute('status',undef,'run');
1131
        set_gui_status($emulate,"ref",1);
1132
        show_info($info, "start emulation\n");
1133
 
1134
        #search for available usb blaster
1135
        my $cmd = "jtagconfig";
1136
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
1137
        my @matches= ($stdout =~ /USB-Blaster.*/g);
1138
        my $usb_blaster=$matches[0];
1139
        if (!defined $usb_blaster){
1140
                add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
1141
                $emulate->object_add_attribute('status',undef,'programer_failed');
1142
                set_gui_status($emulate,"ref",2);
1143 28 alirezamon
                #/***/
1144 25 alirezamon
                return;
1145
        }else{
1146
                add_info($info, "find $usb_blaster\n");
1147
        }
1148
        my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
1149
        for (my $i=1; $i<=$sample_num; $i++){
1150
                my $status=$emulate->object_get_attribute ("sample$i","status");
1151
                next if($status ne "run");
1152
                next if(!check_sample($emulate,$i,$info));
1153
                my $r= $emulate->object_get_attribute("sample$i","ratios");
1154
                my @ratios=@{check_inserted_ratios($r)};
1155
                #$emulate->object_add_attribute ("sample$i","status","run");                    
1156 36 alirezamon
                my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
1157
                my $dir = Cwd::getcwd();
1158
                my $project_dir   = abs_path("$dir/../../"); #mpsoc directory address
1159
                $sof= "$project_dir/$sof"   if(!(-f $sof));
1160
 
1161 25 alirezamon
                add_info($info, "Programe FPGA device using $sof\n");
1162
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
1163
 
1164
 
1165
                my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
1166 28 alirezamon
 
1167 25 alirezamon
                #my $output = `$cmd 2>&1 1>/dev/null`;           # either with backticks
1168 28 alirezamon
 
1169
 
1170
 
1171
                #/***/
1172 25 alirezamon
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
1173
                if($exit){#programming FPGA board has failed
1174
                        $emulate->object_add_attribute('status',undef,'programer_failed');
1175
                        add_info($info, "$stdout\n");
1176
                        $emulate->object_add_attribute ("sample$i","status","failed");
1177
                        set_gui_status($emulate,"ref",2);
1178
                        next;
1179 28 alirezamon
                }
1180
                #print "$stdout\n";
1181
 
1182 25 alirezamon
                # read noc configuration 
1183
 
1184
 
1185 28 alirezamon
 
1186
 
1187 25 alirezamon
 
1188 28 alirezamon
                foreach  my $ratio_in (@ratios){
1189 25 alirezamon
 
1190 28 alirezamon
                        add_info($info, "Configure packet generators for  injection ratio of $ratio_in \% \n");
1191
                        next if(!programe_pck_gens($emulate,$i,$ratio_in,$info));
1192
 
1193
                        my $avg=read_pack_gen($emulate,$i,$info);
1194
                        next if (!defined $avg);
1195
                        my $ref=$emulate->object_get_attribute ("sample$i","result");
1196
                        my %results;
1197
                        %results= %{$ref} if(defined $ref);
1198
                        #push(@results,$avg);
1199
                        $results{$ratio_in}=$avg;
1200
                        $emulate->object_add_attribute ("sample$i","result",\%results);
1201
                        set_gui_status($emulate,"ref",2);
1202 25 alirezamon
 
1203
                }
1204
                $emulate->object_add_attribute ("sample$i","status","done");
1205
 
1206
        }
1207
 
1208
        add_info($info, "End emulation!\n");
1209
        $emulate->object_add_attribute('status',undef,'ideal');
1210
        set_gui_status($emulate,"ref",1);
1211
}
1212
 
1213
 
1214
 
1215
 
1216
 
1217
 
1218
 
1219
 
1220
 
1221
 
1222
sub process_notebook_gen{
1223 32 alirezamon
                my ($emulate,$info,$mode)=@_;
1224 25 alirezamon
                my $notebook = Gtk2::Notebook->new;
1225
                $notebook->set_tab_pos ('left');
1226
                $notebook->set_scrollable(TRUE);
1227
                $notebook->can_focus(FALSE);
1228 32 alirezamon
 
1229 25 alirezamon
 
1230 32 alirezamon
                my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info);
1231
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run emulator  ")) if($mode eq "emulate");
1232
                $notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic ("  _Run simulator ")) if($mode eq "simulate");
1233 25 alirezamon
 
1234
 
1235 32 alirezamon
                my $page2=get_noc_setting_gui ($emulate,$info,$mode);
1236
                my $pp=$notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic (" _Generate NoC \n Configuration"));
1237 25 alirezamon
 
1238
 
1239
 
1240 32 alirezamon
 
1241 25 alirezamon
                my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1242
                $scrolled_win->set_policy( "automatic", "automatic" );
1243
                $scrolled_win->add_with_viewport($notebook);
1244
                $scrolled_win->show_all;
1245
                my $page_num=$emulate->object_get_attribute ("process_notebook","currentpage");
1246
                $notebook->set_current_page ($page_num) if(defined $page_num);
1247
                $notebook->signal_connect( 'switch-page'=> sub{
1248
                        $emulate->object_add_attribute ("process_notebook","currentpage",$_[2]);        #save the new pagenumber
1249
 
1250
                });
1251
 
1252 32 alirezamon
                return ($scrolled_win,$set_win);
1253 25 alirezamon
 
1254
}
1255
 
1256
 
1257
sub get_noc_setting_gui {
1258 32 alirezamon
        my ($emulate,$info_text,$mode)=@_;
1259 28 alirezamon
        my $table=def_table(20,10,FALSE);#      my ($row,$col,$homogeneous)=@_;
1260
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
1261
        $scrolled_win->set_policy( "automatic", "automatic" );
1262
        $scrolled_win->add_with_viewport($table);
1263
        my $row=noc_config ($emulate,$table);
1264 25 alirezamon
 
1265 28 alirezamon
        my($label,$param,$default,$content,$type,$info);
1266
        my @dirs = grep {-d} glob("../src_emulate/fpga/*");
1267
        my $fpgas;
1268
        foreach my $dir (@dirs) {
1269
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
1270
                $default=$name;
1271
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
1272
 
1273
        }
1274
 
1275 25 alirezamon
 
1276 32 alirezamon
my @fpgainfo;
1277 25 alirezamon
 
1278 32 alirezamon
        if($mode eq "emulate"){
1279 28 alirezamon
 
1280 32 alirezamon
        @fpgainfo = (
1281 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},
1282
        { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
1283
        { 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 },
1284
 
1285
);
1286 32 alirezamon
 
1287
}
1288
else {
1289
 
1290
@fpgainfo = (
1291
        #{ label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
1292
        { label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
1293
        { 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 },
1294
 
1295
);
1296
}
1297
 
1298
 
1299
 
1300
 
1301
foreach my $d (@fpgainfo) {
1302 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});
1303
}
1304
 
1305 32 alirezamon
 
1306
 
1307
 
1308
 
1309 25 alirezamon
 
1310
 
1311
 
1312
 
1313
                my $generate = def_image_button('icons/gen.png','Generate');
1314
 
1315
 
1316
                $table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
1317
 
1318
                $generate->signal_connect ('clicked'=> sub{
1319 32 alirezamon
                        generate_sof_file($emulate,$info_text) if($mode eq "emulate");
1320
                        generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
1321 25 alirezamon
 
1322
                });
1323
 
1324
 
1325
            return $scrolled_win;
1326
 
1327
}
1328
 
1329
 
1330
 
1331
 
1332
 
1333
 
1334
 
1335
sub generate_sof_file {
1336
        my ($emulate,$info)=@_;
1337
                print "start compilation\n";
1338
                my $fpga_board=  $emulate->object_get_attribute ('fpga_param',"FPGA_BOARD");
1339
                #create work directory
1340
                my $dir_name=$emulate->object_get_attribute ('fpga_param',"SOF_DIR");
1341 28 alirezamon
                $dir_name="$dir_name/$fpga_board";
1342 25 alirezamon
                my $save_name=$emulate->object_get_attribute ('fpga_param',"SAVE_NAME");
1343
                $save_name=$fpga_board if (!defined $save_name);
1344
                $dir_name= "$dir_name/$save_name";
1345
 
1346
                show_info($info, "generate working directory: $dir_name\n");
1347
 
1348
 
1349
                #copy all noc source codes
1350 28 alirezamon
                my @files = split(/\s*,\s*/,EMULATION_RTLS);
1351 25 alirezamon
 
1352
                my $dir = Cwd::getcwd();
1353
                my $project_dir   = abs_path("$dir/../../");
1354
                my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $dir_name/src/" );
1355 32 alirezamon
 
1356
 
1357
 
1358 28 alirezamon
                copy_file_and_folders(\@files,$project_dir,"$dir_name/src/");
1359
 
1360
                foreach my $f(@files){
1361
                        my $n="$project_dir/$f";
1362
                        if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" )     ){
1363
                                add_info ($info, " WARNING: file/folder  \"$f\" ($n)  dose not exists \n");
1364
 
1365
                         }
1366
 
1367
 
1368
                }
1369 25 alirezamon
 
1370
 
1371 28 alirezamon
 
1372 25 alirezamon
 
1373 28 alirezamon
 
1374 25 alirezamon
                #copy fpga board files
1375
 
1376
                ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -Rf \"$project_dir/mpsoc/src_emulate/fpga/$fpga_board\"/*    \"$dir_name/\"");
1377
                if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout); return;}
1378
 
1379 28 alirezamon
                #generate parameters for emulator_top.v file
1380
                my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
1381
                open(FILE,  ">$dir_name/src/noc_parameters.v") || die "Can not open: $!";
1382
                print FILE $localparam;
1383 25 alirezamon
                close(FILE) || die "Error closing file: $!";
1384 28 alirezamon
                open(FILE,  ">$dir_name/src/pass_parameters.v") || die "Can not open: $!";
1385
                print FILE $pass_param;
1386
                close(FILE) || die "Error closing file: $!";
1387 25 alirezamon
 
1388
 
1389
                #compile the code  
1390
                my $Quartus_bin=  $ENV{QUARTUS_BIN};
1391
                add_info($info, "Start Quartus compilation\n $stdout\n");
1392 28 alirezamon
                my @compilation_command =("cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_map --64bit $fpga_board --read_settings_files=on ",
1393
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_fit --64bit $fpga_board --read_settings_files=on ",
1394
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_asm --64bit $fpga_board --read_settings_files=on ",
1395
                                          "cd \"$dir_name/\" \n xterm   -e $Quartus_bin/quartus_sta --64bit $fpga_board ");
1396
 
1397
 
1398
 
1399
 
1400
 
1401
                foreach my $cmd (@compilation_command){
1402
                        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $cmd);
1403
                        if($exit != 0){
1404
                                print "Quartus compilation failed !\n";
1405
                                add_info($info, "Quartus compilation failed !\n$cmd\n $stdout\n");
1406
                                return;
1407
                        }
1408 25 alirezamon
 
1409 28 alirezamon
                }
1410
 
1411
 
1412
 
1413 25 alirezamon
                        #save sof file
1414
                        my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
1415 28 alirezamon
                        mkpath("$sofdir/$fpga_board/",1,01777);
1416
                        open(FILE,  ">$sofdir/$fpga_board/$save_name.inf") || die "Can not open: $!";
1417 25 alirezamon
                        print FILE perl_file_header("$save_name.inf");
1418 28 alirezamon
                        my %pp;
1419
                        $pp{'noc_param'}= $emulate->{'noc_param'};
1420
                        $pp{'fpga_param'}= $emulate->{'fpga_param'};
1421
                        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
1422 25 alirezamon
                        close(FILE) || die "Error closing file: $!";
1423 28 alirezamon
 
1424
 
1425
                        #find  $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof" 
1426
                        @files = File::Find::Rule->file()
1427
                            ->name( '*.sof' )
1428
                            ->in( "$dir_name" );
1429
                        copy($files[0],"$sofdir/$fpga_board/$save_name.sof") or do {
1430
                                my $err= "Error copy($files[0] , $sofdir/$fpga_board/$save_name.sof";
1431
                                print "$err\n";
1432
                                message_dialog($err);
1433
                                return;
1434
                        };
1435
                        message_dialog("sof file has been generated successfully");
1436 25 alirezamon
 
1437
 
1438
 
1439
}
1440
 
1441
##########
1442
#       save_emulation
1443
##########
1444
sub save_emulation {
1445
        my ($emulate)=@_;
1446
        # read emulation name
1447
        my $name=$emulate->object_get_attribute ("emulate_name",undef);
1448
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
1449
        if ($s == 0){
1450
                message_dialog("Please set emulation name!");
1451
                return 0;
1452
        }
1453
        # Write object file
1454
        open(FILE,  ">lib/emulate/$name.EML") || die "Can not open: $!";
1455
        print FILE perl_file_header("$name.EML");
1456
        print FILE Data::Dumper->Dump([\%$emulate],[$name]);
1457
        close(FILE) || die "Error closing file: $!";
1458
        message_dialog("Emulation saved as lib/emulate/$name.EML!");
1459
        return 1;
1460
}
1461
 
1462
#############
1463
#       load_emulation
1464
############
1465
 
1466
sub load_emulation {
1467
        my ($emulate,$info)=@_;
1468
        my $file;
1469
        my $dialog = Gtk2::FileChooserDialog->new(
1470
                'Select a File', undef,
1471
                'open',
1472
                'gtk-cancel' => 'cancel',
1473
                'gtk-ok'     => 'ok',
1474
                );
1475
 
1476
        my $filter = Gtk2::FileFilter->new();
1477
        $filter->set_name("EML");
1478
        $filter->add_pattern("*.EML");
1479
        $dialog->add_filter ($filter);
1480
        my $dir = Cwd::getcwd();
1481
        $dialog->set_current_folder ("$dir/lib/emulate");
1482
 
1483
 
1484
        if ( "ok" eq $dialog->run ) {
1485
                $file = $dialog->get_filename;
1486
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1487
                if($suffix eq '.EML'){
1488
                        my $pp= eval { do $file };
1489
                        if ($@ || !defined $pp){
1490
                                add_info($info,"**Error reading  $file file: $@\n");
1491
                                 $dialog->destroy;
1492
                                return;
1493
                        }
1494
 
1495
                        clone_obj($emulate,$pp);
1496
                        #message_dialog("done!");                               
1497
                }
1498
     }
1499
     $dialog->destroy;
1500
}
1501
 
1502
############
1503
#    main
1504
############
1505
sub emulator_main{
1506
 
1507
        add_color_to_gd();
1508
        my $emulate= emulator->emulator_new();
1509
        set_gui_status($emulate,"ideal",0);
1510
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
1511
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
1512
 
1513
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
1514
        my ($infobox,$info)= create_text();
1515
        my $refresh = Gtk2::Button->new_from_stock('ref');
1516
 
1517
 
1518
 
1519
 
1520
 
1521 32 alirezamon
        my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
1522 25 alirezamon
        my $chart   =gen_chart  ($emulate);
1523
 
1524
 
1525
 
1526
        $main_table->set_row_spacings (4);
1527
        $main_table->set_col_spacings (1);
1528
 
1529
        #my  $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
1530
 
1531
 
1532
        my $generate = def_image_button('icons/forward.png','Run all');
1533
        my $open = def_image_button('icons/browse.png','Load');
1534
 
1535
 
1536
 
1537
 
1538
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
1539
        $entry->signal_connect( 'changed'=> sub{
1540
                my $name=$entry->get_text();
1541
                $emulate->object_add_attribute ("emulate_name",undef,$name);
1542
        });
1543
        my $save = def_image_button('icons/save.png','Save');
1544
        $entrybox->pack_end($save,   FALSE, FALSE,0);
1545
 
1546
 
1547
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
1548
        my $image = get_status_gif($emulate);
1549
 
1550
 
1551
 
1552
 
1553
 
1554
        $left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
1555
        $left_table->attach_defaults ($image , 0, 6, 20, 24);
1556
        $left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
1557
        $left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
1558
        $right_table->attach_defaults ($infobox  , 0, 6, 0,12);
1559
        $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1560
        $right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
1561
        $main_table->attach_defaults ($left_table , 0, 6, 0, 25);
1562
        $main_table->attach_defaults ($right_table , 6, 12, 0, 25);
1563
 
1564
 
1565
 
1566
        #referesh the mpsoc generator 
1567
        $refresh-> signal_connect("clicked" => sub{
1568
                my $name=$emulate->object_get_attribute ("emulate_name",undef);
1569
                $entry->set_text($name) if(defined $name);
1570
 
1571
 
1572
                $conf_box->destroy();
1573 32 alirezamon
                $set_win->destroy();
1574 25 alirezamon
                $chart->destroy();
1575
                $image->destroy();
1576
                $image = get_status_gif($emulate);
1577 32 alirezamon
 
1578
                ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
1579 25 alirezamon
                $chart   =gen_chart  ($emulate);
1580
                $left_table->attach_defaults ($image , 0, 6, 20, 24);
1581
                $left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
1582
                $right_table->attach_defaults ($chart , 0, 6, 12, 24);
1583
 
1584
                $conf_box->show_all();
1585
                $main_table->show_all();
1586
 
1587
 
1588
        });
1589
 
1590
 
1591
 
1592
        #check soc status every 0.5 second. referesh device table if there is any changes 
1593
        Glib::Timeout->add (100, sub{
1594
 
1595
                my ($state,$timeout)= get_gui_status($emulate);
1596
 
1597
                if ($timeout>0){
1598
                        $timeout--;
1599
                        set_gui_status($emulate,$state,$timeout);
1600
 
1601
                }
1602 32 alirezamon
                elsif($state eq 'ref_set_win'){
1603
                        my $s=$emulate->object_get_attribute("active_setting",undef);
1604
                        $set_win->destroy();
1605
                        $emulate->object_add_attribute("active_setting",undef,$s);
1606
                        $refresh->clicked;
1607
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
1608
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
1609
                        set_gui_status($emulate,"ideal",0);
1610
 
1611
                }
1612 25 alirezamon
                elsif( $state ne "ideal" ){
1613
                        $refresh->clicked;
1614
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
1615
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
1616
                        set_gui_status($emulate,"ideal",0);
1617
 
1618
                }
1619
                return TRUE;
1620
 
1621
        } );
1622
 
1623
 
1624
        $generate-> signal_connect("clicked" => sub{
1625
                my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
1626
                for (my $i=1; $i<=$sample_num; $i++){
1627
                        $emulate->object_add_attribute ("sample$i","status","run");
1628
                }
1629
                run_emulator($emulate,\$info);
1630
                #set_gui_status($emulate,"ideal",2);
1631
 
1632
        });
1633
 
1634
#       $wb-> signal_connect("clicked" => sub{ 
1635
#               wb_address_setting($mpsoc);
1636
#       
1637
#       });
1638
 
1639
        $open-> signal_connect("clicked" => sub{
1640
 
1641
                load_emulation($emulate,\$info);
1642
                set_gui_status($emulate,"ref",5);
1643
 
1644
        });
1645
 
1646
        $save-> signal_connect("clicked" => sub{
1647
                save_emulation($emulate);
1648
                set_gui_status($emulate,"ref",5);
1649
 
1650
 
1651
        });
1652
 
1653
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
1654
                $sc_win->set_policy( "automatic", "automatic" );
1655
                $sc_win->add_with_viewport($main_table);
1656
 
1657
        return $sc_win;
1658
 
1659
 
1660
}
1661
 
1662
 
1663
 
1664 32 alirezamon
 
1665
 
1666
 
1667
 
1668
############
1669
#       run_simulator
1670
###########
1671
 
1672
sub run_simulator {
1673
        my ($simulate,$info)=@_;
1674
        #return if(!check_samples($emulate,$info));
1675
        $simulate->object_add_attribute('status',undef,'run');
1676
        set_gui_status($simulate,"ref",1);
1677
        show_info($info, "Start Simulation\n");
1678 34 alirezamon
        my $name=$simulate->object_get_attribute ("simulate_name",undef);
1679
        my $log= (defined $name)? "$ENV{PRONOC_WORK}/simulate/$name.log": "$ENV{PRONOC_WORK}/simulate/sim.log";
1680
        #unlink $log; # remove old log file
1681
 
1682 32 alirezamon
        my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
1683
        for (my $i=1; $i<=$sample_num; $i++){
1684
                my $status=$simulate->object_get_attribute ("sample$i","status");
1685
                next if($status ne "run");
1686
                next if(!check_sample($simulate,$i,$info));
1687
                my $r= $simulate->object_get_attribute("sample$i","ratios");
1688
                my @ratios=@{check_inserted_ratios($r)};
1689
                #$emulate->object_add_attribute ("sample$i","status","run");                    
1690
                my $bin=$simulate->object_get_attribute ("sample$i","sof_file");
1691 36 alirezamon
                my $dir = Cwd::getcwd();
1692
                my $project_dir   = abs_path("$dir/../../"); #mpsoc directory address
1693
                $bin= "$project_dir/$bin"   if(!(-f $bin));
1694 32 alirezamon
 
1695
                #load traffic configuration
1696
                my $patern=$simulate->object_get_attribute ("sample$i",'traffic');
1697
                my $PCK_SIZE=$simulate->object_get_attribute ("sample$i","PCK_SIZE");
1698
                my $PCK_NUM_LIMIT=$simulate->object_get_attribute ("sample$i","PCK_NUM_LIMIT");
1699
                my $SIM_CLOCK_LIMIT=$simulate->object_get_attribute ("sample$i","SIM_CLOCK_LIMIT");
1700
 
1701
 
1702
                my $HOTSPOT_PERCENTAGE=$simulate->object_get_attribute ("sample$i",'HOTSPOT_PERCENTAGE');
1703
        my $HOTSPOT_NUM=$simulate->object_get_attribute ("sample$i","HOTSPOT_NUM");
1704
                my $HOTSPOT_CORE_1=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_1");
1705
        my $HOTSPOT_CORE_2=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_2");
1706
        my $HOTSPOT_CORE_3=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_3");
1707
        my $HOTSPOT_CORE_4=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_4");
1708
        my $HOTSPOT_CORE_5=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_5");
1709
 
1710
                $HOTSPOT_PERCENTAGE = 0 if (!defined $HOTSPOT_PERCENTAGE);
1711
                $HOTSPOT_NUM=0 if (!defined $HOTSPOT_NUM);
1712
                $HOTSPOT_CORE_1=0 if (!defined $HOTSPOT_CORE_1);
1713
        $HOTSPOT_CORE_2=0 if (!defined $HOTSPOT_CORE_2);
1714
        $HOTSPOT_CORE_3=0 if (!defined $HOTSPOT_CORE_3);
1715
        $HOTSPOT_CORE_4=0 if (!defined $HOTSPOT_CORE_4);
1716
        $HOTSPOT_CORE_5=0 if (!defined $HOTSPOT_CORE_5);
1717
 
1718
 
1719
 
1720
 
1721
 
1722
 
1723
 
1724
                foreach  my $ratio_in (@ratios){
1725
 
1726
                        add_info($info, "Run $bin with  injection ratio of $ratio_in \% \n");
1727
                        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\"";
1728
                                add_info($info, "$cmd \n");
1729 34 alirezamon
                                my $time_strg = localtime;
1730
                                append_text_to_file($log,"started at:$time_strg\n"); #save simulation output
1731 32 alirezamon
                                my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout("$cmd");
1732
                                if($exit){
1733
                                        add_info($info, "Error in running simulation: $stderr \n");
1734 36 alirezamon
                                        $simulate->object_add_attribute ("sample$i","status","failed");
1735
                                        $simulate->object_add_attribute('status',undef,'ideal');
1736 32 alirezamon
                                        return;
1737
                                }
1738 34 alirezamon
 
1739
                                append_text_to_file($log,$stdout); #save simulation output
1740
                                $time_strg = localtime;
1741
                                append_text_to_file($log,"Ended at:$time_strg\n"); #save simulation output
1742 32 alirezamon
                                my @q =split  (/average latency =/,$stdout);
1743
                                my $d=$q[1];
1744
                                @q =split  (/\n/,$d);
1745
                                my $avg=$q[0];
1746
                                #my $avg = sprintf("%.1f", $avg);
1747
 
1748
 
1749
 
1750
 
1751
                        next if (!defined $avg);
1752
                        my $ref=$simulate->object_get_attribute ("sample$i","result");
1753
                        my %results;
1754
                        %results= %{$ref} if(defined $ref);
1755
                        #push(@results,$avg);
1756
                        $results{$ratio_in}=$avg;
1757
                        $simulate->object_add_attribute ("sample$i","result",\%results);
1758
                        set_gui_status($simulate,"ref",2);
1759
 
1760
 
1761
 
1762
 
1763
 
1764
 
1765
                }
1766
                $simulate->object_add_attribute ("sample$i","status","done");
1767
 
1768
        }
1769
 
1770
        add_info($info, "Simulation is done!\n");
1771
        $simulate->object_add_attribute('status',undef,'ideal');
1772
        set_gui_status($simulate,"ref",1);
1773
}
1774
 
1775
 
1776
 
1777
 
1778
 

powered by: WebSVN 2.1.0

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