Mednafen Members Members   Search Search   Help Help   Register Register   Login Login   Home Home
Home » Mednafen » Bugs » Sudden extreme lag on Linux with SDL2 v2.26.5
Show: Today's Messages  :: Show Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6959] Mon, 20 November 2023 11:41 Go to next message
saturian1  [PM]
I have an issue that appeared on Fedora 39 with mednafen v0.2.UNSTABLE.fc39, on 38 it worked fine.


After some time playing, usually no longer than a minute since mednafen was started, it will suddenly extremely lag, with very low FPS. Surprisingly, fast-forward is not affected and works fine.

The only way to fix this seems to restart mednafen, but it will still reappear each time.

I tried downgrading to version 1.31.0-0.1.UNSTABLE.fc38 from Fedora 38, but same issue.

I actually reported a bug on Fedora's issue tracker: https://bugzilla.redhat.com/show_bug.cgi?id=2250556

but they asked me to ask here too.

Can someone shed light on the issue and what can be done to fix this?

[Updated on: Mon, 20 November 2023 11:44]

Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6960 is a reply to message #6959 ] Mon, 20 November 2023 14:56 Go to previous messageGo to next message
belegdol  [PM]
I am the Fedora package maintainer. I was able to reproduce this on my laptop with AMD integrated graphics but not yet on my desktop with an nvidia graphics.
mesa versions are really close between f38 and f39, 23.1.9 and 23.2.1, respectively. gcc versions are the same, but the default compiler flags might be different. binutils version is different too, 2.39 vs 2.40.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6961 is a reply to message #6960 ] Tue, 21 November 2023 15:06 Go to previous messageGo to next message
Administrator  [PM]
Does the problem still occur when Mednafen setting "video.frameskip" is set to "0", or sound is disabled by setting "sound" to "0"?
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6962 is a reply to message #6959 ] Wed, 22 November 2023 03:43 Go to previous messageGo to next message
belegdol  [PM]
-sound 0
seems to help,
-video.frameskip 0
does not. When the issue happens, the FPS counter hovers around 13 FPS for SNES instead of the expected 60.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6964 is a reply to message #6959 ] Thu, 23 November 2023 14:39 Go to previous messageGo to next message
saturian1  [PM]
I can also confirm that disabling sound helps, no more freezes.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6965 is a reply to message #6964 ] Thu, 23 November 2023 21:41 Go to previous messageGo to next message
Administrator  [PM]
Could you provide the information about sound that's printed out on startup when sound is enabled?

Like:
 Initializing sound...
  Using "ALSA" audio driver with device "hw:0":
   Format: 16 bits(signed, 2 bytes, little-endian)
   Rate: 44100
   Channels: 2
   Buffer size: 1430 sample frames(32.426304 ms)
   Latency: 1430 sample frames(32.426304 ms)
   Period size: 55 sample frames(1.247166 ms)
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6966 is a reply to message #6965 ] Fri, 24 November 2023 08:01 Go to previous messageGo to next message
saturian1  [PM]
Initializing sound...
Using "ALSA" audio driver with device "sexyal-literal-default":
Format: 16 bits(signed, 2 bytes, little-endian)
Rate: 48000
Channels: 2
Buffer size: 1560 sample frames(32.500000 ms)
Latency: 1560 sample frames(32.500000 ms)
Period size: 60 sample frames(1.250000 ms)


I have `sound.device sexyal-literal-default` in config, otherwise sound wouldn't work.

[Updated on: Fri, 24 November 2023 08:02]

Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6970 is a reply to message #6966 ] Mon, 27 November 2023 12:57 Go to previous messageGo to next message
Administrator  [PM]
It might be due to a regression in PipeWire, a kernel sound driver, or even a GPU driver if it's somehow starving the audio DMA or interrupt processing and increasing latency and jitter, but it's hard to say for sure without hands-on testing.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6971 is a reply to message #6970 ] Wed, 29 November 2023 09:26 Go to previous messageGo to next message
saturian1  [PM]
Administrator wrote on Mon, 27 November 2023 12:57

It might be due to a regression in PipeWire, a kernel sound driver, or even a GPU driver if it's somehow starving the audio DMA or interrupt processing and increasing latency and jitter, but it's hard to say for sure without hands-on testing.

Is there something else I can provide or help with to get this resolved?
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6973 is a reply to message #6971 ] Mon, 04 December 2023 03:56 Go to previous messageGo to next message
Administrator  [PM]
Running Mednafen directly with an ALSA hardware device, and not through PipeWire or anything else, to see if the problem still occurs would help a little. Also wouldn't hurt to know what GPU and sound device/card you're using.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6975 is a reply to message #6973 ] Tue, 05 December 2023 01:11 Go to previous messageGo to next message
Administrator  [PM]
I can reproduce the problem, with Fedora 39 and PipeWire 1.0.0. If I downgrade PipeWire to 0.3.80, the problem goes away, so it looks like something broke horribly in PipeWire or PipeWire's ALSA support after 0.3.80.

The problem can also be demonstrated with "aplay -F 1250 -B 32000 -v" when it's running on a heavily-loaded system, as XRUNs start triggering constantly after a moment or two, along with extremely stuttery audio, that continues for a while even after the system load is removed.

[Updated on: Tue, 05 December 2023 02:50]

Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6976 is a reply to message #6975 ] Tue, 05 December 2023 15:19 Go to previous messageGo to next message
Administrator  [PM]
After testing more with packages from Koji, it looks like the problem started in 0.3.85.

It might be due to the two PipeWire commits on November 15: https://gitlab.freedesktop.org/pipewire/pipewire/-/commits/0.3.85/pipewire-alsa?ref_type=tags
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6978 is a reply to message #6976 ] Fri, 08 December 2023 23:30 Go to previous messageGo to next message
Administrator  [PM]
I put together a quick test program to demonstrate the PipeWire bug:

https://raw.githubusercontent.com/mednafen/nonsense/master/alsapwstress.cpp

On startup it should output:
Rate: 384000
Channels: 1
Buffer size: 16384 (42.667 ms)
Period size: 64 (0.167 ms)
Avail min: 64 (0.167 ms)


...and then it will play a tone, that will begin stuttering after a moment or two, around the same time something like the following is continuously outputted:

written(101) < towrite(128)!
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
XRUN
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN
XRUN
ALSA_Write() took 200 ms to write 0.333 ms samples!
XRUN

Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #6979 is a reply to message #6959 ] Thu, 14 December 2023 13:48 Go to previous messageGo to next message
belegdol  [PM]
Reported to pipewire: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3711
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #7012 is a reply to message #6959 ] Thu, 01 February 2024 14:06 Go to previous messageGo to next message
belegdol  [PM]
With pipewire-1.0.2, alsa driver with sexyal-literal-default does not work at all:

 Initializing sound...
  Using "ALSA" audio driver with device "sexyal-literal-default":ALSA Error: snd_pcm_open(&alsa_pcm, id ? id : "hw:0", SND_PCM_STREAM_PLAYBACK, 0) Operation not supported
Error opening a sound device.
Re: Sudden extreme lag on Linux with SDL2 v2.26.5 [message #7035 is a reply to message #6959 ] Fri, 10 May 2024 05:45 Go to previous message
belegdol  [PM]
This appears to be fixed in pipewire-1.0.6, which is available from updates-testing.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:Oddworld / PSX: Unknown CUE sheet directive and maximum allowed size
Next Topic:Known bugs in general(now with minor design flaws!).
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ ]

Current Time: Sat May 11 05:02:34 CDT 2024
.:: Contact :: Home ::.

Powered by FUDforum.
Copyright © FUDforum Bulletin Board Software