Bug 274047 - audio/alsa-plugins: large number of underruns and CPU usage with games/veloren-weekly
Summary: audio/alsa-plugins: large number of underruns and CPU usage with games/velore...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Jan Beich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-23 14:50 UTC by Sean Farley
Modified: 2023-09-24 14:40 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Farley freebsd_committer freebsd_triage 2023-09-23 14:50:54 UTC
I am uncertain which is at fault (or both), but I noticed that Veloren runs at a high CPU with many ALSA underruns.  It also caused visual and auditory stuttering.

The CPU can be observed by running Veloren in a single world game then suspending it by opening the menu to remove game activities.  On my system, the CPU usage hovers around 70%.

The process will output many of these messages:

    ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred

The underruns can be verified via /dev/sndstat with hw.snd.verbose=2.

To reduce the CPU usage to below 10% (on my system again) and greatly reduce the underruns, I decreased the value of ALSA_OSS_BUFSZ_MAX in audio/alsa-plugins/files/patch-oss_pcm__oss.c from 131072 to 16384.  32768 appeared to be the maximum value that could be used without underruns.

I am not sure if this is the best decision or not, but it fixed Veloren for me.
Comment 1 Jan Beich freebsd_committer freebsd_triage 2023-09-23 15:21:37 UTC
Is this with BUFSZ_P2 disabled like ports 27f51d17e156 requires?

(In reply to Sean Farley from comment #0)
> On my system, the CPU usage hovers around 70%.

For me CPU usage is around 10% in foreground (current workspace) and 5% in background (different workspace). In both cases music is still playing, and I don't see "underrun occurred" ALSA warnings. Tested under sway-devel.
Comment 2 Sean Farley freebsd_committer freebsd_triage 2023-09-23 16:37:19 UTC
(In reply to Jan Beich from comment #1)

Actually, no.  My options were:
BLKCNT_P2: on
BUFSZ_P2: on
FFMPEG: off
JACK: off
PULSEAUDIO: off
SAMPLERATE: off
SPEEX: off
VERBOSE: off

However, aplay worked for me for 16- and 32-bit WAV files but not the 8-bit file.
$ aplay /usr/local/lib/python3.9/test/audiodata/pluck-pcm16.wav
Playing WAVE '/usr/local/lib/python3.9/test/audiodata/pluck-pcm16.wav' : Signed 16 bit Little Endian, Rate 11025 Hz, Stereo
$ aplay /usr/local/lib/python3.9/test/audiodata/pluck-pcm8.wav
Playing WAVE '/usr/local/lib/python3.9/test/audiodata/pluck-pcm8.wav' : Unsigned 8 bit, Rate 11025 Hz, Stereo
Assertion failed: (err >= 0), function set_params, file aplay.c, line 1399.
Aborted by signal Abort trap...

Apparently, that option was the issue.  I disabled both *_P2 options, and it is now stable.  Thank you very much!  I probably kept them enabled when they were switched back and forth a few times.

Out of curiosity, is there any use for those two options?
Comment 3 Sean Farley freebsd_committer freebsd_triage 2023-09-23 17:00:49 UTC
I also want to mention that with these options disabled, wine-devel can now play sounds when it could not with these options enabled.

I do see a few underruns in wine-devel running https://github.com/BlueDragon28/MicrophoneLoopback, with ALSA_OSS_BUFSZ_MAX at either value.  However, it does work now, so that is a good thing.
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-09-23 17:16:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=95a0d0389f594dd16b293141bac889151303a560

commit 95a0d0389f594dd16b293141bac889151303a560
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2023-09-23 17:02:11 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2023-09-23 17:14:53 +0000

    audio/alsa-plugins: remove debug options to prevent footshooting

    - BLKCNT_P2 and VERBOSE exposed compile knobs from
      https://people.freebsd.org/~ariff/libasound/20090928_00-alsa-plugins-1.0.21.diff
    - BUFSZ_P2 worked around crashes and high CPU usage in Firefox until
      native OSS support phased out ALSA
    - hselasky@ fixed many ALSA issues over the years
    - users can still adjust compile knobs via make.conf(5) or Makefile.local

    PR:             274047

 audio/alsa-plugins/Makefile | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
Comment 5 Jan Beich freebsd_committer freebsd_triage 2023-09-23 17:29:41 UTC
Let's see if anyone complains.
Comment 6 Sean Farley freebsd_committer freebsd_triage 2023-09-24 14:40:57 UTC
(In reply to Jan Beich from comment #5)

Thank you!  No complaints from my foot either!  :D