X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Futils%2Fpintos;h=fdaa91867c3ea7b8fd643c8a76c5c7c26cc50cf1;hb=5cc8ebe060af4b1f005fbe015379cd126f1bb6b9;hp=f99396841aa65f3873a8cf11145637ae1d7ff489;hpb=a6743379d7959d012eb6db2ececc01ece70642d7;p=pintos-anon diff --git a/src/utils/pintos b/src/utils/pintos index f993968..fdaa918 100755 --- a/src/utils/pintos +++ b/src/utils/pintos @@ -7,7 +7,8 @@ use File::Temp 'tempfile'; use Getopt::Long qw(:config bundling); # Command-line options. -our ($sim); # Simulator: bochs, qemu, or gsx. +our ($start_time) = time (); +our ($sim) = $ENV{PINTOSSIM}; # Simulator: bochs, qemu, or gsx. our ($debug) = "none"; # Debugger: none, monitor, or gdb. our ($mem) = 4; # Physical RAM in MB. our ($serial_out) = 1; # Send output to serial port? @@ -84,6 +85,9 @@ sub parse_command_line { $sim = "bochs" if !defined $sim; $debug = "none" if !defined $debug; $vga = "window" if !defined $vga; + + print "warning: -T or --timeout should not be used with --$debug\n" + if defined ($timeout) && $debug ne 'none'; } # usage($exitcode). @@ -111,7 +115,8 @@ Display options: (default is both VGA and serial) Timing options: (Bochs only) -j SEED Randomize timer interrupts -r, --realtime Use realistic, not reproducible, timings - -T, --timeout=N Time out and kill Pintos after N seconds + -T, --timeout=N Kill Pintos after N seconds CPU time or N*load_avg + seconds wall-clock time (whichever comes first) Configuration options: -m, --mem=N Give Pintos N MB physical RAM (default: 4) File system commands (for `run' command): @@ -125,6 +130,8 @@ Disk options: (name an existing FILE or specify SIZE in MB for a temp disk) --swap-disk=FILE|SIZE Set swap disk file (default: swap.dsk) Other options: -h, --help Display this help message. +Environment variables: + PINTOSSIM Select default simulator. EOF exit $exitcode; } @@ -362,27 +369,22 @@ sub run_vm { # Runs Bochs. sub run_bochs { # Select Bochs binary based on the chosen debugger. - my ($bin); - if ($debug eq 'none') { - $bin = 'bochs'; - } elsif ($debug eq 'monitor') { - $bin = 'bochs-dbg'; - } elsif ($debug eq 'gdb') { - $bin = 'bochs-gdb'; - } + my ($bin) = $debug eq 'monitor' ? 'bochs-dbg' : 'bochs'; # Write bochsrc.txt configuration file. open (BOCHSRC, ">", "bochsrc.txt") or die "bochsrc.txt: create: $!\n"; print BOCHSRC <= 1.0 ? $avg : 1.0; +} + +# Calls setitimer to set a timeout, then execs what was passed to us. +sub exec_setitimer { + if (defined $timeout) { + if ($ ge 5.8.0) { + eval " + use Time::HiRes qw(setitimer ITIMER_VIRTUAL); + setitimer (ITIMER_VIRTUAL, $timeout, 0); + "; + } else { + { exec ("setitimer-helper", $timeout, @_); }; + exit 1 if !$!{ENOENT}; + print STDERR "warning: setitimer-helper is not installed, so ", + "CPU time limit will not be enforced\n"; + } + } + exec (@_); + exit (1); +} + +sub SIGVTALRM { + use Config; + my $i = 0; + foreach my $name (split(' ', $Config{sig_name})) { + return $i if $name eq 'VTALRM'; + $i++; + } + return 0; +}