quoted
main audio thread:
while running:
snd_pcm_read // blocks until data is delivered from ALSA
wake helper(s)
do work()
sync_with_helper(s)
snd_pcm_write // blocks until data is delivered to ALSA
alsa is basically driven by the hardware, which delivers/requests data
every ~1.3ms.
quoted
distributing the work is a little tricky: to avoid excessive scheduling
overhead, the worker threads are typically woken up (after snd_pcm_read)
and the result is collected where sync_with_helper() typically boils
down to busy waiting. in this case, the workers as rate-monotonic in a
similar manner as the main audio thread.
When you say "rate-monitonic", do you mean that the worker threads with
smaller period (high rate, so) have a higher fixed-priority? If so, what
are the other periods?
the period will be the same period: i wake up the workers once per
period of the main thread, distribute the work and collect it at the
end. so "period" is basically the same, "runtime" a little lower.
as sync_with_helper() does a busy-wait, the "main audio thread" has a
relative lower priority than the worker threads, right?
typically all threads have the same priority and there will be at most N
threads for N physical CPU cores. so each thread will have a CPU to run
on and no thread will be preempted.
So, your main wish here is to avoid having a watchdog thread to
"throttle" misbehaving workload/setup?
mainly ... and nerdy research if SCHED_DEADLINE is useful for audio
applications ... ;)
For curiosity, what are the "time-constraints" setup used on mach?
it's pretty similar to the SCHED_DEADLINE constraints:
from:
https://opensource.apple.com/source/xnu/xnu-124.7/osfmk/mach/thread_policy.h.auto.html
/*
* THREAD_TIME_CONSTRAINT_POLICY:
*
* This scheduling mode is for threads which have real time
* constraints on their execution.
*
* Parameters:
*
* period: This is the nominal amount of time between separate
* processing arrivals, specified in absolute time units. A
* value of 0 indicates that there is no inherent periodicity in
* the computation.
*
* computation: This is the nominal amount of computation
* time needed during a separate processing arrival, specified
* in absolute time units.
*
* constraint: This is the maximum amount of real time that
* may elapse from the start of a separate processing arrival
* to the end of computation for logically correct functioning,
* specified in absolute time units. Must be (>= computation).
* Note that latency = (constraint - computation).
*
* preemptible: This indicates that the computation may be
* interrupted, subject to the constraint specified above.
*/
cheers,
tim