Seventy becomes seventy one: a machine that can wait
HALT is terminal - stepCPU returns at once when the Halt Flag is up, so a halted machine does not execute, service devices, or take an interrupt - and that has to stay true, because every test ends with a halt and "halted" is how a program says it has finished. The consequence was that SplitBit had no way to wait at all. Every wait was a spin, and a spin is bus traffic: 11.5% of Type over a 14K file on a disk of ten thousand cycles, after read-ahead had already hidden three quarters of the latency. WAIT is 0xFE, one byte, no operands, sitting under HALT where the instruction that almost stops the machine belongs. Three decisions in it: - A line already standing means there is nothing to wait for, so WAIT does nothing. That is what makes test-then-wait race-free. - Any line ends the wait, masked or not, so a program can sleep on a device it has no handler for and read its status afterwards. Masking says who answers a request, not whether it happened. - A line that wakes the CPU without being dispatched is taken down by the WAIT. Left standing it would be found by the next WAIT, which would return at once - the program would spin exactly as before while looking as though it slept. Waiting is NOT a Status bit, and that is the trap avoided rather than a gap: Status rides into the interrupt frame and comes back out, so a machine interrupted mid-wait would return from its handler still waiting, and wait again for what it had already been given. An internal field instead. Idle cycles are counted apart from bus cycles and the halt line says so when there are any, which is what makes the difference observable at all - with the line-clearing removed the total moves by ONE cycle, 20,100 against 20,099, and only the idle half changes, halving to 9,976. A test on totals could never have seen it. Tests/terminal.sh asks that question, being the file for things a recorded output cannot see, and fails with the clear removed while "both reads finished" still passes. Three collisions, all found by building it: - 0xFE was the assembler's "not an instruction" sentinel. getOpcode now answers a negative NOT_AN_OPCODE, which is outside the range of every possible answer instead of inside the unused part of it. - 0xFE was also what faultTest and faultResumeTest executed to provoke a fault. They now use 0xFD and say why, because they did not fail when it became an instruction - they HUNG, having started sleeping instead. - Keys.asm has had a label called "wait" for a year, and mnemonics are matched uppercased. What that reported was "Branch without label" at the BRQ thirty lines away. The assembler now refuses a label that is already an instruction, at the label, by name; every instruction added takes a word out of the space of label names, so this will happen again.
This commit is contained in:
@@ -60,11 +60,21 @@ ASM
|
||||
"$ROOT/Assembler" "$BUILD/prompt.asm" -o "$BUILD/prompt.bin" >/dev/null 2>&1 || {
|
||||
echo "Could not assemble the terminal test programs."; exit 1; }
|
||||
|
||||
# And the one that waits. Assembled from the repository rather than written inline, because
|
||||
# it is a real test program that run.sh also runs - there it proves the machine wakes up at
|
||||
# all, and here it proves it was asleep.
|
||||
"$ROOT/Assembler" "$ROOT/Programs/testPrograms/waitTest.asm" -o "$BUILD/waitTest.bin" \
|
||||
>/dev/null 2>&1 || { echo "Could not assemble waitTest."; exit 1; }
|
||||
"$ROOT/SplitDisk" format "$BUILD/wait.img" 32 1 >/dev/null 2>&1 || {
|
||||
echo "Could not make the disk waitTest reads."; exit 1; }
|
||||
|
||||
python3 - "$ROOT" "$BUILD" <<'PY'
|
||||
import os
|
||||
import pty
|
||||
import select
|
||||
import signal
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
@@ -249,6 +259,37 @@ try:
|
||||
except FileNotFoundError:
|
||||
report(False, "suspending and resuming", "could not measure")
|
||||
|
||||
# ---- Waiting is not the same as spinning ----
|
||||
#
|
||||
# settle() strips cycle counts out of every recorded output, so no test in run.sh can see
|
||||
# the difference between a machine that slept through a slow disk and one that spun on it.
|
||||
# The two print the same characters and take the same elapsed time. What separates them is
|
||||
# WHICH KIND of cycle went by, and that is only visible here.
|
||||
#
|
||||
# waitTest reads two blocks from a disk given ten thousand cycles of latency, with
|
||||
# interrupts masked and no handler installed. Nearly all of the run should be idle. With
|
||||
# the line-clearing removed from WAIT the total barely moves - it was 20,100 against
|
||||
# 20,099 - and the idle count halves, because the second wait finds the first wait's line
|
||||
# still standing and returns at once.
|
||||
waitProgram = os.path.join(build, "waitTest.bin")
|
||||
waitDisk = os.path.join(build, "wait.img")
|
||||
if os.path.exists(waitProgram) and os.path.exists(waitDisk):
|
||||
run = subprocess.run([emulator, waitProgram, "--fast", "--cycles", "5000000",
|
||||
"--disk", waitDisk, "--disk-cycles", "10000"],
|
||||
capture_output=True, text=True)
|
||||
got = re.search(r"halted after (\d+) cycles, (\d+) of them waiting", run.stdout)
|
||||
if not got:
|
||||
report(False, "a slow disk is waited for", "no idle cycles were reported at all")
|
||||
else:
|
||||
total, idle = int(got.group(1)), int(got.group(2))
|
||||
report("12" in run.stdout, "both reads finished", "%d cycles" % total)
|
||||
# Two waits of ten thousand cycles each. Sleeping through both puts idle over
|
||||
# nine tenths of the run; spinning through either drops it to about half.
|
||||
report(idle > total * 0.9, "and the machine slept rather than spun",
|
||||
"%d of %d idle (%.0f%%)" % (idle, total, 100.0 * idle / total))
|
||||
else:
|
||||
report(False, "a slow disk is waited for", "waitTest.bin or the disk is missing")
|
||||
|
||||
print()
|
||||
if problems:
|
||||
print("The terminal does not survive everything it should:")
|
||||
|
||||
Reference in New Issue
Block a user