Poll Or Be Interrupted

You are writing the completion path for a storage driver. Measurements:

  • a 4 KB read usually completes in about 12 microseconds
  • roughly one read in 2,000 stalls for 2 milliseconds while the device does internal housekeeping
  • taking an interrupt, running the handler, and switching back to the blocked thread costs about 4 microseconds of CPU
  • the application runs one request at a time and has nothing else to do while it waits

Which completion strategy is the right default?

A

Enable interrupt coalescing so the device holds its interrupt until 16 completions are pending, cutting per-interrupt overhead by a factor of 16.

B

Spin on the completion queue for a bounded window of tens of microseconds, then arm the interrupt and sleep if the request has not finished.

C

Always spin until the request completes. The device is fast and the thread has no other work, so sleeping only adds the 4 microseconds of switch cost for nothing.

D

Always use interrupts. Spinning burns a core, and 12 microseconds is long enough for the scheduler to run something useful on that CPU.