News for hackers. Stuff that matters.
Re:The Case of the Extra 40ms by amluto on Monday December 14, 2020 @11:44PM (#25427096)
I see no reason that interrupts are need at all. On a properly working system, the system clock will track the audio clock quite well. If the audio hardware tells you that it will need more data in x ms, it will be very close to x ms as seen by the CPU. If you use a deadline scheduler, you don’t want to wait for an interrupt — you tell the scheduler that you need to run before a specific deadline, and that that. A hardware interrupt is pure overhead, especially on platforms like x86 with silly interrupt latency.

(A good kernel can account for the time it takes to wake from idle and compensate when programming a timer (as could a good CPU, but I’ve never heard of hardware that does this) and can wake a user program a bit early if the CPU is otherwise idle and would take a short nap. A sound hardware interrupt can’t do these tricks.)

Re:The Case of the Extra 40ms by PaulDavisThe1st on Tuesday December 15, 2020 @12:12AM (#25427244)
This is both true and false at the same time.

(1) It is absolutely not true that the system clock will track the audio clock "quite well". Real world numbers would typically involve drift measurable in seconds within a low integer number of hours.

(2) It absolutely is true that on most sensible audio interface designs, you don't need interrupts except early after device open. At that point, you use them to set up a DLL (Delay Locked Loop) that will enable you to use the system clock to know where the audio hardware is reading/writing to in the buffer used to move data to/from the hardware. Once the DLL is correctly configured, you can just be woken by the system timer, determine the current audio hardware state and read/write data appropriately.

Re:The Case of the Extra 40ms by marcan_42 on Tuesday December 15, 2020 @01:05AM (#25427494)
But on (2): unless you're a low level app directly driving the hardware, you shouldn't do this. And you especially shouldn't do this without good guarantees that system timers are indeed well behaved. Effectively, using a DLL and system timers instead of straight IRQs is a low level implementation detail, but that belongs either in the driver or in a very low level piece of code anyway (like JACK or some other audio daemon), not user applications. I was sort of throwing all of this together when I said hardware "events"; locking a DLL with a different time base to the playback hardware buffer pointer stats is still effectively that, and should be done, but only at a level low enough where you know it'll work. Which definitely isn't Android's high level thread scheduling framework.
Re:The Case of the Extra 40ms by amluto on Tuesday December 15, 2020 @02:10PM (#25433797)
For (1), by “quite well” I mean well enough to avoid buffer underruns. So I think we agree.
Re:The Case of the Extra 40ms by PaulDavisThe1st on Tuesday December 15, 2020 @04:04PM (#25435249)
No, we don't agree. The drift will exceed the buffer size is less than an hour, or certainly could with many hardware configurations.
Re:The Case of the Extra 40ms by FpUser on Tuesday December 15, 2020 @01:45AM (#25427699)
>"A hardware interrupt is pure overhead, especially on platforms like x86 with silly interrupt latency."

Relatively speaking maybe. But I have a device I've designed that communicates to PC using interrupt transfer at the rate of 250 requests/s. I've watched it then over oscilloscope and it is stable like a rock. Sure if you overload PC it might get into trouble but it is a game like application so when the app is ran PC is not doing much else. I recently ported the same thing to Raspberry Pi 4.

Re:The Case of the Extra 40ms by amluto on Tuesday December 15, 2020 @02:10PM (#25433784)
Hah, you must never have tried this on an otherwise idle stock Sandy Bridge before Linux added mitigations :)

x86 interrupts are slow but at least reasonably consistent on a non-idle system. If your system is deeply enough into its various idle states, this is not at all true any more. I’ve seen latencies over 10ms on Sandy Bridge with C1E enabled.

Re:The Case of the Extra 40ms by FpUser on Tuesday December 15, 2020 @04:58PM (#25435754)
Linux was on Pi 4. On PC it was actually Windows. The first version went out some 7 years ago I think and was rock solid since the beginning. They must've done something right ;)