PIP_STRESS(8)
πΈ NAME πΈ
pip_stress β Priority Inheritance with processes π (yes bestie, processes, not threads, we're doing the spicy version)
β¨ SYNOPSIS β¨
pip_stress [-u|--usleep TIME]
π DESCRIPTION π
okay so this program is literally a demo, and what it's demoing is the technique of using priority inheritance (PI) mutexes with processes instead of threads. π«Ά
The way you pull this off is you grab some shared memory β in this case with mmap that backs a pthread_mutex_t, because that's the thing that will support PI. And pay particular attention to how it's initialized to support processes, because that part is the whole entire point. π
The function init_shared_pthread_mutex() is the one doing the magic: it sets the pthread_mutexattr to PTHREAD_PROCESS_SHARED and sets the mutex protocol to PTHREAD_PRIO_INHERIT. No cap. π₯
In this program we purposely try to invoke a classic priority inversion. Here's the drama:
- A low priority process grabs the mutex and does some work.
- A high priority process comes along and is blocked, because the mutex is taken. π
- A medium priority process that doesn't need the mutex at all then takes the processor.
And because the processes are restricted to one cpu, the low priority process never makes any progress, because the medium priority process is just vibing in an infinite loop. π
That right there is a priority inversion, because the medium priority process is running at the expense of the high priority process. It's giving chaos, honestly.
BUT β and this is the slay part β since we used PRIO_INHERIT and we're running on a machine that supports preemption, the high priority process will lend its priority to the low priority process, which will preempt the medium priority process. π« Then the low priority process releases the mutex, which the high priority process can obtain. And when the high priority process gets to run? It kills the medium priority process. π periodt.
The state structure keeps track of the progress, fyi.
ngl though β although this program is set up to likely trigger an inversion, there is no guarantee that scheduling will make that happen. Scheduling said "we'll see." π
After the program completes, it reports whether a priority inversion occurred or not. Either way, this program demonstrates how to use priority inheritance mutexes with processes. π
And honestly? In real life you would be better off to avoid scenarios in which a priority inversion occurs if possible β this program tries to trigger them just to show that it works. It's the "we did it for science" of scheduling. π§
If you are having difficulty triggering an inversion, merely increase the time that the low priority process sleeps while holding the lock (usleep). Easy fix bestie. β¨
Also note that you have to run as a user with permission to change scheduling priorities. π
π OPTIONS π
-u TIME,--usleep=TIMEβ specify the sleep time in usec of the low priority process. Defaults to500. πΈ
π AUTHOR π
pip_stress was written by John Kacur <jkacur at redhat.com> π«Ά
This manual page was also written by John Kacur.
SPDX-License-Identifier: GPL-2.0-or-later β yes it's licensed, yes it's the good license, iykyk. π
okay that's the whole page, ily, this is the System Manager's Manual, pip_stress section 8, dated September 17, 2018 β go forth and inherit some priorities, bestie πβ¨
π¦ where this page comes from
- arch rolling: rt-tests 2.11-1 Β· GPL-2.0-or-later
- centos-stream 10: realtime-tests 2.11-1.el10 Β· GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-only AND LGPL-2.1-or-later
- centos-stream 9: realtime-tests 2.11-1.el9 Β· GPLv2
- fedora 43: realtime-tests 2.11-1.fc43 Β· GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-only AND LGPL-2.1-or-later
- fedora 44: realtime-tests 2.11-1.fc44 Β· GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-only AND LGPL-2.1-or-later
- nixos 26.05: rt-tests 2.10
- nixpkgs unstable: rt-tests 2.11
- ubuntu resolute: rt-tests 2.9-1ubuntu1 Β· GPL-2.0-only
- ubuntu stonking: rt-tests 2.10-1ubuntu1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms