The VAX architects apparently didn't see the need for WAIT, [...]
Of course, as soon as you started talking about virtual machines, it
did make sense again. So I think there is something in VARM about
this,
There is. There is a WAIT instruction in EL-00032-0-0-decStd32_Jan90;
see 12.1, page 12-7 in particular. It's just an ordinary privileged
instruction as far as the hardware is concerned; the hypervisor is
supposed to recognize it as a wait request.
For my VAX emulator, I did two things in aid of such a thing: (1) I
fiddled the instruction emulation so that XORL3 SP, SP, R0 operates
normally except that it clears, rather than sets, the Z bit (that
struck me as an unlikely enough instruction, and anyone who does use it
is unlikely to depend on the condition codes from it); and (2) I
implemented XFC - my implementation eats the next four bytes of the
instruction stream and, if they are 0xec 0x22 0xe7 0xfe, and there have
been at least 16 instructions executed since the last REI, and CM is
kernel, it operates as a wait-for-interrupt idle operation; if any of
those tests fail, it's a no-op. (The "last REI" test is to avoid a
race where an interrupt happens when the idle loop is just about to do
the XFC; it could idle the machine after the wakeup interrupt has
happened.)
I then changed the kernel's idle loop:
commit 28ec3be1b6dc19865a362fa0738a66fd67aab013
Author: Mouse <mouse%Rodents-Montreal.ORG@localhost>
Date: Tue Aug 29 13:44:06 2023 -0400
Give the VAX an emulator-friendly idle loop.
diff --git a/sys/arch/vax/vax/subr.s b/sys/arch/vax/vax/subr.s
index e7ecb0a..0f16c96 100644
--- a/sys/arch/vax/vax/subr.s
+++ b/sys/arch/vax/vax/subr.s
@@ -250,8 +250,12 @@ remrq: .asciz "remrunqueue"
#
idle: mtpr $0,$PR_IPL # Enable all types of interrupts
1: tstl _whichqs # Anything ready to run?
- beql 1b # no, continue to loop
- brb Swtch # Yes, goto switch again.
+ bneq Swtch
+ xorl3 sp,sp,r0 # emulator-detect magic
+ beql 1b # no emulator, or disabled - loop
+ .byte 0xfc # emulator idle
+ .long 0xfee722ec
+ brb 1b
#
# cpu_switch, cpu_exit and the idle loop implemented in assembler
With those in place, I find the load an idle emulated VAX places on the
host machine is so low it's down in the measurement noise.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B