sjkuo,
I neglected to mention that our system is used for real-time process control where a random delay anywhere in the system can be critical. This is why I've spent 2 weeks drilling down to find and confirm this problem before I posted
Your point about COM ports is valid but I assumed that most people wouldn't see a problem as it would be masked by the UARTs FIFO. Admittedly our legacy code doesn't open the FIFO but at 83 microseconds per byte it shouldn't need to
For your second point remember that the MBR runs after the BIOS has completed its initialisations and since I set the BIOS to optimised defaults that includes opening the processor cache
Here's the loop code from my MBR
; TEST CODE
; $$$$$$$$$$$$$$$$$$
CLI ; DISABLE INT'S
MOV EAX,0
DEC EAX
PUSH EAX ; LOOP COUNTER
; LOOP
; ----
L001:
; CHECK IF TIME TO OUTPUT A '-'
; -----------------------------
POP EAX
INC EAX
PUSH EAX
AND EAX,0FFFFFFH
JNZ L002
MOV AL,'-'
MOV AH,0EH
MOV BX,00007H
INT 10H
L002:
; EXECUTE 'CPUID' INSTRUCTION TO ENSURE PREVIOUS
; INSTRUCTIONS ARE ALL COMPLETE
; ----------------------------------------------
MOV EAX,0
; CPUID
DB 00FH,0A2H
; GET THE CPU CLOCK COUNTER VALUE IN EDX:EAX
; ------------------------------------------
; RDTSC
DB 00FH,031H
; SAVE ON STACK
; -------------
PUSH EAX
PUSH EDX
; GET COM2 STATUS (TEST INSTRUCTION)
; ----------------------------------
MOV EDX,2FDH
IN AL,DX
; EXECUTE 'CPUID' INSTRUCTION TO ENSURE PREVIOUS
; INSTRUCTIONS ARE ALL COMPLETE
; ----------------------------------------------
MOV EAX,0
; CPUID
DB 00FH,0A2H
; GET THE CPU CLOCK COUNTER VALUE IN EDX:EAX
; ------------------------------------------
; RDTSC
DB 00FH,031H
; RESTORE START CPU CLOCK COUNTER VALUE IN ECX:EBX
; ------------------------------------------------
POP ECX
POP EBX
; CALCULATE NETT CPU CLOCK COUNT
; ------------------------------
SUB EAX,EBX
SBB EDX,ECX
; CHECK IF COUNT IS EXCESSIVE OR FIRST TIME
; 20000 = 7 MICROSECONDS FOR 3.0 GHZ PROCESSOR
; OR 13 MICROSECONDS FOR 1.5 GHZ PROCESSOR
; OR 20 MICROSECONDS FOR 1.0 GHZ PROCESSOR
; ---------------------------------------------
POP ECX
OR ECX,ECX
PUSH ECX
JZ L010
CMP EAX,20000
JB L001
L010:
; OUTPUT EAX AS DECIMAL
; ---------------------
.....
This code was written to prove a point it is not meant to be real code. This was only writtten after the problem had manifested itself in other areas
Finally. Your comment about subtle timing assumption may result in surprises. A delay of a couple of microseconds on a 2.8 GHz processor is a surprise. An apparent random delay of 100s of microseconds in a realtime environment is not a surprise, its a shock