From ee317e0cb4e8681f9e0fc32189603e876d86b345 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 21 Mar 2020 21:30:58 -0700 Subject: [PATCH] SCP: Adjust RUNLIMIT time values on slow host systems As reported and discussed in #819 --- PDP8/tests/pdp8_test.ini | 3 +++ VAX/tests/vax-diag_test.ini | 4 ++++ scp.c | 19 +++++++++++++++++-- sim_timer.c | 8 ++++++++ sim_timer.h | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/PDP8/tests/pdp8_test.ini b/PDP8/tests/pdp8_test.ini index 7263febb..02b37ed5 100644 --- a/PDP8/tests/pdp8_test.ini +++ b/PDP8/tests/pdp8_test.ini @@ -8,6 +8,9 @@ cd %~p0 :: Limit maximum diagnostic execution time runlimit 2 minutes +set on +on error ignore +on runtime echof "\r\n*** Test Runtime Limit %SIM_RUNLIMIT% %SIM_RUNLIMIT_UNITS% Exceeded ***\n"; exit 1 :: Maximum memory, extended address element: set cpu 32k diff --git a/VAX/tests/vax-diag_test.ini b/VAX/tests/vax-diag_test.ini index da461031..215d82dd 100644 --- a/VAX/tests/vax-diag_test.ini +++ b/VAX/tests/vax-diag_test.ini @@ -19,6 +19,10 @@ #break A3B4 SHOW HIST=40 cd %~p0 set runlimit 2 minutes +set on +on error ignore +on runtime echof "\r\n*** Test Runtime Limit %SIM_RUNLIMIT% %SIM_RUNLIMIT_UNITS% Exceeded ***\n"; exit 1 + set env DIAG_QUIET_MODE=0 if ("%1" == "-v") set console notelnet else set -qu console telnet=localhost:65432,telnet=buffered; set env -a DIAG_QUIET_MODE=1 diff --git a/scp.c b/scp.c index 21a162b8..562b9dfa 100644 --- a/scp.c +++ b/scp.c @@ -7005,6 +7005,8 @@ char gbuf[CBUFSIZE]; int32 num; t_stat r; double usec_factor = 1.0; +const char *units = ""; +char runlimit[32]; GET_SWITCHES (cptr); /* get switches */ if (0 == flag) { @@ -7014,6 +7016,8 @@ if (0 == flag) { sim_runlimit_switches = 0; sim_runlimit_enabled = FALSE; sim_cancel (&sim_runlimit_unit); + unsetenv ("SIM_RUNLIMIT"); + unsetenv ("SIM_RUNLIMIT_UNITS"); return SCPE_OK; } @@ -7023,8 +7027,10 @@ if ((r != SCPE_OK) || (num == 0)) /* error? */ return sim_messagef (SCPE_ARG, "Invalid argument: %s\n", gbuf); cptr = get_glyph (cptr, gbuf, 0); /* get next glyph */ if ((gbuf[0] == '\0') || - (MATCH_CMD (gbuf, sim_vm_interval_units) == 0)) + (MATCH_CMD (gbuf, sim_vm_interval_units) == 0)) { sim_switches &= ~SWMASK ('T'); + units = sim_vm_interval_units; + } else { int i; struct { @@ -7042,6 +7048,7 @@ else { if (MATCH_CMD (gbuf, time_units[i].name) == 0) { sim_switches |= SWMASK ('T'); usec_factor = time_units[i].usec_factor; + units = time_units[i].name; break; } } @@ -7054,11 +7061,19 @@ sim_runlimit_enabled = TRUE; sim_cancel (&sim_runlimit_unit); sim_runlimit_switches = sim_switches; if (sim_runlimit_switches & SWMASK ('T')) { - sim_runlimit_d_initial = sim_runlimit_d = num * usec_factor; + sim_runlimit_d_initial = sim_runlimit_d = num * usec_factor * sim_host_speed_factor (); + if (sim_host_speed_factor () > 1.0) + sim_messagef (SCPE_OK, "Slow host - adjusting RUNLIMIT from %d %s to %.1f %s\n", num, units, num * sim_host_speed_factor (), units); + snprintf (runlimit, sizeof (runlimit), "%.f", num * sim_host_speed_factor ()); + setenv ("SIM_RUNLIMIT", runlimit, 1); + setenv ("SIM_RUNLIMIT_UNITS", units, 1); return sim_activate_after_d (&sim_runlimit_unit, sim_runlimit_d); } else { sim_runlimit_initial = sim_runlimit = num; + snprintf (runlimit, sizeof (runlimit), "%d", num); + setenv ("SIM_RUNLIMIT", runlimit, 1); + setenv ("SIM_RUNLIMIT_UNITS", units, 1); return sim_activate (&sim_runlimit_unit, sim_runlimit); } } diff --git a/sim_timer.c b/sim_timer.c index 6ff31910..8dd4cf07 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -3467,3 +3467,11 @@ for (tmr=0; tmr<=SIM_NTIMERS; tmr++) { sim_inst_per_sec_last = sim_precalibrate_ips; sim_idle_stable = 0; } + +double +sim_host_speed_factor (void) +{ +if (sim_precalibrate_ips > SIM_INITIAL_IPS) + return 1.0; +return (double)SIM_INITIAL_IPS / (double)sim_precalibrate_ips; +} diff --git a/sim_timer.h b/sim_timer.h index 5ea2591e..cf537718 100644 --- a/sim_timer.h +++ b/sim_timer.h @@ -158,6 +158,7 @@ t_stat sim_os_set_thread_priority (int below_normal_above); uint32 sim_get_rom_delay_factor (void); void sim_set_rom_delay_factor (uint32 delay); int32 sim_rom_read_with_delay (int32 val); +double sim_host_speed_factor (void); extern t_bool sim_idle_enab; /* idle enabled flag */ extern volatile t_bool sim_idle_wait; /* idle waiting flag */