pop-os / system76-scheduler

Auto-configure CFS and process priorities for improved desktop responsiveness
Mozilla Public License 2.0
545 stars 33 forks source link

Audio underrun issues related to pipewire priority #114

Closed fruitchewy closed 2 months ago

fruitchewy commented 7 months ago

I've been seeing a lot of underrun/skipping/crackling issues in pipewire since switching to the system76 scheduler. After playing with quantums and buffer sizes for many hours, I noticed the pipewire process was claiming a niceness value of 49. I assume that's an artifact of something system76 is doing with the bespoke priority values for pipewire, but it sent me down the right troubleshooting path.

I've ultimately managed to resolve all of my issues while still using default low latency quantums by changing sound-server nice=-15 sched=(fifo)49 io=(realtime)0 { to sound-server nice=-15 io=(realtime)0 { in my config.kdl

I'm not sure if this isn't working as intended, or if fifo realtime just isn't playing nice with pipewire, but everything seems to be working great with just the niceness and realtime io set. Wanted to share in case this isn't working as intended or could be relevant to #99 or #102 .

System info: ASUS B550-I motherboard audio (Starship/Matisse HD Audio) System76 Scheduler as default in Bazzite

liammcdermott commented 7 months ago

@fruitchewy I've been experiencing the same thing for months, and figured out it was system76-scheduler one day after you! Thank you for making this issue, it's good to know I'm not alone.


Below are the niceness values on my machine. Before making the change in OP:

$ ps -elf | grep pipewire
4 S root        3713    2218  0  92  12 - 42747 -      21:52 ?        00:00:00 /usr/bin/system76-scheduler pipewire
0 S liam        6618    6603  1  69 -11 - 44977 ep_pol 21:58 ?        00:02:15 /usr/bin/pipewire
0 S liam        6634    6603  0  80   0 -  6583 ep_pol 21:58 ?        00:00:00 /usr/bin/pipewire -c filter-chain.conf
0 S liam        6635    6603  0  69 -11 - 46585 ep_pol 21:58 ?        00:01:12 /usr/bin/pipewire-pulse

Then after:

$ ps -elf | grep pipewire
0 S liam        6618    6603  1  65 -15 - 44977 ep_pol Mar24 ?        00:09:44 /usr/bin/pipewire
0 S liam        6634    6603  0  65 -15 -  6583 ep_pol Mar24 ?        00:00:00 /usr/bin/pipewire -c filter-chain.conf
0 S liam        6635    6603  0  65 -15 - 46585 ep_pol Mar24 ?        00:03:40 /usr/bin/pipewire-pulse
4 S root      100086  100077  0  92  12 - 23798 -      10:18 ?        00:00:00 /usr/bin/system76-scheduler pipewire

The before values don't seem right, niceness should be -15, not a mix of -12 and 0. The after values look correct and lead to less Rice Krispies effect in my recorded audio.

Could it be, system76-scheduler isn't able to set sched=(fifo)49 for some reason, and therefore doesn't set the other priorities (niceness, io)?

journalctl -u com.system76.Scheduler.service turns up no errors (or anything else relevant), just the service stopping and starting successfully on reboot.

System info: Audient iD4 audio interface, this issue happens when recording audio (and when listening, but to a lesser extent). Ubuntu 23.10 My system76-scheduler configuration is default, besides the change described in OP.

liammcdermott commented 7 months ago

Just in case it's useful information, adding sched=(fifo)49 back into the sound-server profile -- and restarting the system76-scheduler service -- yields these results:

$ ps -elf | grep pipewire
0 S liam        6618    6603  1  10   - - 45014 ep_pol Mar24 ?        00:10:54 /usr/bin/pipewire
0 S liam        6634    6603  0  10   - -  6583 ep_pol Mar24 ?        00:00:00 /usr/bin/pipewire -c filter-chain.conf
0 S liam        6635    6603  0  10   - - 43519 ep_pol Mar24 ?        00:04:07 /usr/bin/pipewire-pulse
4 S root      109511  109502  0  92  12 - 23798 -      11:56 ?        00:00:00 /usr/bin/system76-scheduler pipewire

Edit: This looks better than my other results, since niceness values aren't applicable to processes with realtime priorities set (AFAICT, YMMV).

ps also showing realtime priorities:

$ sudo ps -e -o pid,uid,pri,nice,rtprio,vsz,rss,tty,stat,start,time,comm | grep -E 'PID|pipewire'
    PID   UID PRI  NI RTPRIO    VSZ   RSS TT       STAT  STARTED     TIME COMMAND
   7939  1000  89   -     49 141344 20924 ?        S<sl 13:16:20 00:07:21 pipewire
   7955  1000  89   -     49  26332  5888 ?        S<sl 13:16:20 00:00:00 pipewire
   7957  1000  89   -     49 167412 34064 ?        S<Lsl 13:16:20 00:05:08 pipewire-pulse
liammcdermott commented 7 months ago

I've been testing playing and recording audio over the past couple of days, and mine is now good. Here's what I did:

I'm not sure the realtime priorities will stick after a reboot, I'll have to wait and see.

mmstick commented 7 months ago

Feel free to submit a PR with the priority adjustments

gcentauri commented 2 months ago

Original Post helped me out today. Haven't had a single pipewire error since changing the config and restarting the system76 scheduler. previously I would get ~5 per song I'd try to play. I made the PR for the small change, but I don't have any deeper knowledge of what it changes :)