Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 May 2022 18:34:02 +0200
From:      Florian Walpen <dev@submerge.ch>
To:        freebsd-multimedia@freebsd.org
Subject:   Realtime Scheduling Priority for Users
Message-ID:  <2320930.mfXeX5GmMH@z800>

next in thread | raw e-mail | index | archive | help
Hi there,

the release of FreeBSD 13.1 brought a new MAC policy module, which allows
ordinary users to run software with realtime scheduling priority. Since that
change didn't make it into the release notes, I'd like to do a small
announcement here - I suppose it is both interesting to users of audio/jack,
and multimedia applications in general.

Taken from my notes on FreeBSD audio and Jack:
https://github.com/0EVSG/freebsd_jack_notes#realtime-priority


=== Realtime Priority

The FreeBSD scheduler is able to run processes with so-called realtime
priority, which means these processes will not be interrupted by other
processes, or even drivers. Running Jack with realtime priority can help a
great deal to avoid gaps in audio processing, in particular with modern 
desktop environments.

Traditionally, only root was allowed to run processes at realtime priority.
Starting with FreeBSD 13.1, this privilege can be granted to individual users.
We have to load the `mac_priority` kernel module, through

  # kldload mac_priority

or at system boot for a permanent setup:

./etc/rc.conf
----
kld_list="mac_priority"
----

Then we just add the audio user to the `realtime` group.

  # pw groupmod realtime -m joe

The man pages have more info on this, see `man mac_priority` and `man rtprio`.

WARNING: Misbehaving processes running at realtime priority can render a 
system unusable by starving all other processes. Only selected processes or 
threads should be run at realtime priority.

Fortunately, Jack and Jack clients take care of this and only elevate threads 
to realtime priority when needed. This can be enabled in the Jack settings.


As you may know, running the Jack server itself at realtime priority was
possible before, through the jackd RC service. But that leads to problems with
Jack clients, since they expect to run some threads at realtime too.
In comparison, granting realtime privilege to users is in line with Linux,
which is where most multimedia ports come from.

Regarding Jack, I'd recommend the DBUS interface (jack_control) for all use
cases now. Feel free to ask questions.

Have a good time!

Florian





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2320930.mfXeX5GmMH>