Ant27
Posts: 4
Joined: Sat Jun 16, 2018 12:29 am

Setting taskset/cpu affinity of whole audio stack (ALSA kernel module, lib, USB/gpio IRQ's)

Fri Aug 24, 2018 11:34 pm

So I know you can use taskset to set the cpu affinity of user-space processes. For real time audio in my case (using isolcapus and taskset), that would be Jack audio server and Pure data.

The problem is, Jack runs on top of ALSA, and I need the ALSA kernel module and Alsa-lib to be on the same isolated cores as Jack. Also anything else for handling the USB sound card with ALSA (At least a few years ago, setting IRQ affinity or priority was convoluted or unsupported in Raspbian, but that may have changed).

Would taskset consider the audio chain under Jack to be child processes (therefore moving ALSA and the audio chain to Jack's core)? If not, how should I go about that (a way to set ALSA/kernel module affinity as a whole, or how to find individual PID's and sched_setaffinity them)?

I really appreciate any help. I am a beginner, but this topic seems more appropriate for the advanced section.

Ant27
Posts: 4
Joined: Sat Jun 16, 2018 12:29 am

Re: Setting taskset/cpu affinity of whole audio stack (ALSA kernel module, lib, USB/gpio IRQ's)

Sat Aug 25, 2018 8:28 pm

I’ll just update this, in case someone else has the same goal. Hardware interrupts are defaulted to core 0 with arm cpu’s. You can’t really move them around (maybe with the RT patch).

For me, it worked best to isolcpus=2,3 and taskset jack and Pure data to those. Jack2 can use multiple cores(taskset -c 2,3), and with the sched_fifo permissions the scheduler handles multiprocessing there (jack2 will use parallel threads if two separate clients go to the outputs individually, like if you individually taskset multiple instances of Pure data). I'm not sure if it was fixed, but there use to be a bug where sched_other would schedule all threads to the first available core in taskset, instead of scheduling them in parallel. So you still need to make sure realtime permissions are set up to get parallel processing on isolated cores.

There's also some affinity flags on boot for various other things that seem to override isolscpus and add stuff to core 0 and 1 (1st and 2nd depending on syntax), but the last two cores appear to be entirely free. The interrupts for my USB sound card are already at an ideal priority, and core 0 sends them out fast enough to the other cores. So this worked best for me.

AspectCarl
Posts: 1
Joined: Sun Nov 04, 2018 8:59 am

Re: Setting taskset/cpu affinity of whole audio stack (ALSA kernel module, lib, USB/gpio IRQ's)

Sun Nov 04, 2018 9:20 am

There is a bug on isolcpu on Linux, for whatever reason the scheduler will not move onto the next listed core and instead stays on the first listed core.

You should try to ensure that Jack and your Audio interrupts are on the same core.

Then lastly adjust your RTPrio.

In place of isolcpu you can set the affinity of each service using CPUAffinity= (cpu core#) in the service files.

Return to “Advanced users”