devmiyax / yabause

Yabause is a Sega Saturn emulator and took over as Yaba Sanshiro
http://www.uoyabause.org
GNU General Public License v2.0
207 stars 35 forks source link

Cotton 2 hung waiting in a futex Emuelec odroid n2+ #849

Closed Kelvfimer closed 2 years ago

Kelvfimer commented 2 years ago

Hello

When executing Cotton 2 on Yabasanshiro stand alone for Emuelec on Odroid n2+ seems to be locked in a FUTEX and the emulator gets hung.

it seems to be a problem with Vdp2VBlankIN() (yabause/src/yabause.c:791) when waiting for an event on YabWaitEventQueue (yabause/src/vdp2.cpp:836). I set a breakpoint and I see that is called a lot of times until the moment it gets hung waiting in the futex at line value = queue->buffer[queue->out] (yabause/src/thr-linux.cpp:235) on and the emulator gets unresponsive and the music keeps playing.

Please, can you help on find the root cause of the issue and potential fix?

thx so much

GDB Call Stack and Info Threads

(gdb) bt

0 futex_wait_cancelable (private=0, expected=0, futex_word=0x2f4ccaf4)

at ../sysdeps/nptl/futex-internal.h:183

1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x2f4cca68,

cond=0x2f4ccac8) at pthread_cond_wait.c:508

2 __pthread_cond_wait (cond=cond@entry=0x2f4ccac8,

mutex=mutex@entry=0x2f4cca68) at pthread_cond_wait.c:638

3 0x000000000067b8c8 in YabWaitEventQueue (queue_t=0x2f4cca50)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/thr-linux.cpp:235

4 0x000000000060243c in YabauseEmulate ()

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/yabause.c:791

5 0x0000000000601f00 in YabauseExec ()

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/yabause.c:588

6 0x000000000053fde8 in main (argc=, argv=)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/retro_arena/main.cpp:652

(gdb) info threads Id Target Id Frame

Kelvfimer commented 2 years ago

As the one that I told in Fighting Vipers https://github.com/devmiyax/yabause/issues/795 I think there is a deadlock because of the futex in this case in Coton2 could be because of thread 69 or 71

THREAD 69 (gdb) thread 69 [Switching to thread 69 (Thread 0x7f8d7de130 (LWP 5710))]

0 futex_wait_cancelable (private=0, expected=0, futex_word=0x381cf8f0)

at ../sysdeps/nptl/futex-internal.h:183

183 ../sysdeps/nptl/futex-internal.h: No such file or directory. (gdb) bt

0 futex_wait_cancelable (private=0, expected=0, futex_word=0x381cf8f0)

at ../sysdeps/nptl/futex-internal.h:183

1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x381cf898,

cond=0x381cf8c8) at pthread_cond_wait.c:508

2 __pthread_cond_wait (cond=cond@entry=0x381cf8c8,

mutex=mutex@entry=0x381cf898) at pthread_cond_wait.c:638

3 0x000000000067b7ec in YabAddEventQueue (queue_t=0x381cf880,

evcode=evcode@entry=0)
at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/thr-linux.cpp:208

4 0x00000000005b1044 in vdp2VBlankOUT ()

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/vdp2.cpp:1311

5 VdpProc (arg=)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/vdp2.cpp:524

6 VdpProc (arg=)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/vdp2.cpp:500

7 0x0000007fb459add4 in start_thread (arg=0x7fe5a86570)

at pthread_create.c:463

8 0x0000007fb1ced79c in thread_start ()

at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

THREAD 71 (gdb) thread 71 [Switching to thread 71 (Thread 0x7f8cfdd130 (LWP 5712))]

0 __lll_lock_wait (futex=futex@entry=0x7f84163a50, private=0)

at lowlevellock.c:52

52 lowlevellock.c: No such file or directory. (gdb) bt

0 __lll_lock_wait (futex=futex@entry=0x7f84163a50, private=0)

at lowlevellock.c:52

1 0x0000007fb459cc70 in __GI___pthread_mutex_lock (mutex=0x7f84163a50)

at pthread_mutex_lock.c:80

2 0x00000000005cc75c in Vdp2DrawRotationThread (p=0x0)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/vidogl.c:3536

3 0x0000007fb459add4 in start_thread (arg=0x7f8d7dd620)

at pthread_create.c:463

4 0x0000007fb1ced79c in thread_start ()

at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

(gdb)

Kelvfimer commented 2 years ago

As spoken in Fighter vipers one https://github.com/devmiyax/yabause/issues/795

Reading further it seems that the lock is done in thread 71 on /yabause/src/vidogl.c:3536 YabThreadLock(g_rotate_mtx);

use thread [New Thread 0x7f7fd9b130 (LWP 6369)] [Thread 0x7f7fd9b130 (LWP 6369) exited] [New Thread 0x7f7fd9b130 (LWP 6370)] Vdp2DrawRotationThread ^C Thread 1 "yabasanshiro" received signal SIGINT, Interrupt. futex_wait_cancelable (private=0, expected=0, futex_word=0xc0c4894) at ../sysdeps/nptl/futex-internal.h:183 183 ../sysdeps/nptl/futex-internal.h: No such file or directory. (gdb) info threads Id Target Id Frame

(gdb) thread 71 [Switching to thread 71 (Thread 0x7f7fd9b130 (LWP 6370))]

0 __lll_lock_wait (futex=futex@entry=0x7f78163a50, private=0) at lowlevellock.c:52

52 lowlevellock.c: No such file or directory. (gdb) bt

0 __lll_lock_wait (futex=futex@entry=0x7f78163a50, private=0) at lowlevellock.c:52

1 0x0000007fab076c70 in __GI___pthread_mutex_lock (mutex=0x7f78163a50) at pthread_mutex_lock.c:80

2 0x00000000005cc75c in Vdp2DrawRotationThread (p=0x0)

at /home/kelv/EmuELEC/build.EmuELEC-Amlogic-ng.aarch64-4/build/yabasanshiroSA-f6f41dd6485c638ab661f3acd2951c9522f34450/yabause/src/vidogl.c:3536

3 0x0000007fab074dd4 in start_thread (arg=0x7f807cd620) at pthread_create.c:463

4 0x0000007fa87c779c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

(gdb) x /3d 0x7f78163a50 0x7f78163a50: 2 0 6368 (gdb)

Kelvfimer commented 2 years ago

Hello

New news, if compiled as relwithdebinfo the game starts and I can get into the first stage but it gets hung again because of the FUTEX issue :(

I hope it helps

thx

Kelvfimer commented 2 years ago

Solved in the latest pi 1.9.0 banch. thx @devmiyax for your work!!!