Crackling sound during high CPU load in QEMU/KVM VM solved by reducing process niceness (nice-level -10)
- PipeWire version (
pipewire --version
):
pipewire
Compiled with libpipewire 0.3.56
Linked with libpipewire 0.3.56
- Distribution and distribution version (
PRETTY_NAME
from/etc/os-release
): Arch Linux - Desktop Environment: KDE Plasma
- Kernel version (
uname -r
): 5.15.55-2-lts
Description of Problem:
I've struggled with audio issues in QEMU/KVM for a long time. When the CPU is stressed by the VM, for example by playing a game, the audio starts to crackle. Recently I noticed that the crackling also applies to sounds produced by the host OS. This made me realise that the issue probably is not with the communication between the VM and pipewire as I suspected but with something else. So I decided to try reducing pipewire's process niceness by 10. It worked. It's not ideal, there still are ocasional crackles but only once every couple of minutes and during VM startup. Problem solved, right? Yeah, sort of, but I noticed this in journalctl -b
:
Jul 26 16:48:33 vladoPCarch systemd[755]: Started PipeWire Multimedia Service.
Jul 26 16:48:33 vladoPCarch systemd[755]: Started Multimedia Service Session Manager.
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: could not set nice-level to -11: No such file or directory
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: could not set nice-level to -11: No such file or directory
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch wireplumber[1056]: could not make thread 1059 realtime using RTKit: No such file or directory
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: RTKit error: org.freedesktop.DBus.Error.ServiceUnknown
Jul 26 16:48:33 vladoPCarch pipewire[1054]: mod.rt: could not make thread 1060 realtime using RTKit: No such file or directory
It appears that pipewire tries to set it's niceness even lower than what I set it to but it fails to do so. And there's this issue: #2034 (closed). Pipewire used to run with -11 niceness until someone complained and it was changed to 0. Perhaps there was a good reason to run with -11 niceness?
At this point I'm not sure what to do. I don't really have a problem as I'm happy to run pipewire with reduced niceness and managed to configure my system to set it automatically after login (more difficult than expected). I wished to inform you that reduced niceness fixes some crackling issues and you could just undo the changes in the commit that fixes issue #2034 (closed). However, you may have your reasons to not want low process niceness. If that's the case, should I open an issue about the crackling problem?