[GH-ISSUE #28] drivers: clamp elapsed-time differences against backwards clock steps (disk/SCSI stats, DDM timing) #22

Closed
opened 2026-11-03 22:02:28 -07:00 by gitea-mirror · 0 comments
Owner

Originally created by @raynorpat on GitHub (Sep 25, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/28

Follow-up to #26. The i386 kernel fix (cd9fc5abd) stops IOGetTimestamp() stepping back one tick, and NE2K, AMDPCNet32II, SerialPointingDevice and PS2Mouse are already guarded. A tick can still be lost if IRQ0 is serviced more than one PIT period late, which happens under heavy TCG load. That makes a backward step rare but still possible, so the remaining drivers that compute now - then on the unsigned 64-bit ns_time_t should tolerate it.

A backward step makes that difference wrap to about 1.8e19 ns. None of the sites below times out early. They record nonsense statistics or debug timing.

Transfer statistics (totalTime / latentTime passed to the disk stats)

  • drivers-i386/ide/drvEIDE/.../IdeDiskInternal.m:772: delta = end_time - start_time
  • drivers-i386/ide/drvPCFloppy/.../FloppyDriveInt2.m:~507: endTime - startTime
  • drivers-i386/scsi/drvBusLogic/.../BusLogicThread.m:474
  • drivers-i386/scsi/drvAdaptec1542B/.../AHAThread.m:473
  • drivers-i386/scsi/drvAdaptec6X60/.../AIC6X60Thread.m:235
  • drivers-i386/scsi/drvDPT2000/.../EATAControllerThread.m:168
  • drivers-i386/scsi/drvAMDPCSCSIDriver/.../AMD_SCSI.m:998: latentTime += currentTime - disconnectTime

Debug-only timing (DDM builds)

  • AMD_SCSI.m:217: interrupt elapsed time
  • AMD_x86.m:701: IPL test usTime > 1000 logs a false slow interval

Checked and safe (compare absolute deadlines, so a backward step only lengthens the wait)

BusLogic, Adaptec 1542B and AMD SCSI timeout scans (now >= expire), DPT2000 EATAController.m:373, Floppy motor timer (FloppyDriveInt2.m:617), AHCI deadline seconds, IOEthernet/IOTokenRing _absTimeout, IODelay (User generalFuncs.m), EISA PnPDump IOStubs.m, SYM53c8 (stores but never subtracts), and EventInput periodic scheduling (already handles an apparent clock wrap).

Suggested fix

Clamp each difference to 0 when now < then (for example delta = (end > start) ? end - start : 0), matching the forward-gap-only guards in #26. Drivers with a reconstruction/divergences.md (Floppy, and others if they are reconstructions) should record it there as a divergence.

Still open from #26

The i386 kernel with the clock fix has been built but not yet boot-tested.

Originally created by @raynorpat on GitHub (Sep 25, 2026). Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/28 Follow-up to #26. The i386 kernel fix (cd9fc5abd) stops `IOGetTimestamp()` stepping back one tick, and NE2K, AMDPCNet32II, SerialPointingDevice and PS2Mouse are already guarded. A tick can still be lost if IRQ0 is serviced more than one PIT period late, which happens under heavy TCG load. That makes a backward step rare but still possible, so the remaining drivers that compute `now - then` on the unsigned 64-bit `ns_time_t` should tolerate it. A backward step makes that difference wrap to about 1.8e19 ns. None of the sites below times out early. They record nonsense statistics or debug timing. ### Transfer statistics (`totalTime` / `latentTime` passed to the disk stats) - `drivers-i386/ide/drvEIDE/.../IdeDiskInternal.m:772`: `delta = end_time - start_time` - `drivers-i386/ide/drvPCFloppy/.../FloppyDriveInt2.m:~507`: `endTime - startTime` - `drivers-i386/scsi/drvBusLogic/.../BusLogicThread.m:474` - `drivers-i386/scsi/drvAdaptec1542B/.../AHAThread.m:473` - `drivers-i386/scsi/drvAdaptec6X60/.../AIC6X60Thread.m:235` - `drivers-i386/scsi/drvDPT2000/.../EATAControllerThread.m:168` - `drivers-i386/scsi/drvAMDPCSCSIDriver/.../AMD_SCSI.m:998`: `latentTime += currentTime - disconnectTime` ### Debug-only timing (DDM builds) - `AMD_SCSI.m:217`: interrupt elapsed time - `AMD_x86.m:701`: IPL test `usTime > 1000` logs a false slow interval ### Checked and safe (compare absolute deadlines, so a backward step only lengthens the wait) BusLogic, Adaptec 1542B and AMD SCSI timeout scans (`now >= expire`), DPT2000 `EATAController.m:373`, Floppy motor timer (`FloppyDriveInt2.m:617`), AHCI deadline seconds, `IOEthernet`/`IOTokenRing` `_absTimeout`, `IODelay` (User `generalFuncs.m`), EISA PnPDump `IOStubs.m`, SYM53c8 (stores but never subtracts), and `EventInput` periodic scheduling (already handles an apparent clock wrap). ### Suggested fix Clamp each difference to 0 when `now < then` (for example `delta = (end > start) ? end - start : 0`), matching the forward-gap-only guards in #26. Drivers with a `reconstruction/divergences.md` (Floppy, and others if they are reconstructions) should record it there as a divergence. ### Still open from #26 The i386 kernel with the clock fix has been built but not yet boot-tested.
gitea-mirror 2026-11-03 22:02:28 -07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github-starred/RhapsodiOS#22
No description provided.