BlitterStudio / amiberry

Optimized Amiga emulator for Linux/macOS
https://amiberry.com
GNU General Public License v3.0
650 stars 87 forks source link

JIT problems when running Amiberry on Raspberry Pi 4 (model B, 4GB) #1125

Closed Realinferno closed 7 months ago

Realinferno commented 1 year ago

I wanted to emulate an Amiga on my Raspberry Pi 4B (4GB RAM). For this I used HstWB installer for Raspberry Pi (uses Amiberry as built-in emulator). Following the instructions, I first wrote the 32-bit Raspberry Pi OS Lite to an SD card. I then put the SD card in my Pi and followed the instructions on the corresponding github (https://github.com/henrikstengaard/hstwb-installer/wiki/HstWB-Installer-for-Raspberry-Pi), also installing Amiberry (32-bit, optimized for Raspberry Pi 4, version 5.5.1, which was the latest version I managed to successfully install, 5.6 and 5.6.1 both failed). Once everything was installed, I started Amiberry and set-up the emulation using my own .hdf file (a workbench 3.1 set-up I created in a previous project), with the following options: CPU 68030 with JIT enabled, FPU 68882 with JIT enabled, speed: fastest possible, ROM kickstart 3.1, 2MB chip RAM, 128MB fast RAM, 16MB RTG). Unfortunately, the emulation crashed almost immediately (returning to the HstWB menu). I restarted Amiberry, using the exact same set-up EXCEPT I turned off the JIT (both for the CPU and the FPU). This time, the emulation was successful and everything worked as it should (workbench 3.1 booted up and I was able to run several programs and games). In Amiberry I tried several other set-ups. Only when I enabled JIT, the emulation would crash (even when I only enabled JIT for the CPU). Without JIT the emulation worked fine.

Since the Pi 4B is 64-bit, I decided to do a fresh new install of HstWB installer, using the 64-bit Raspberry Pi OS Lite and the 64-bit version of Amiberry (again version 5.5.1). Everything else was the same as above. This time the emulation with JIT enabled (both for the CPU and FPU) was successful. Workbench 3.1 booted up very quickly and when running SysInfo I got 890 Mips and 217 MFlops! Running classic amiga games was no problem (e.g. Alien Breed 3D ran butter-smooth). However when running more demanding games, I did experience several problems. Quake 2 (640x480) also ran butter-smooth at start-up. However, after some time (e.g. 10 minutes) the frame rate dropped considerably. When I went back into the Amiberry menu (pressing F12) and then directly back to Quake 2, the frame-rate was back to normal again (same happened with games like Doom 2, Duke3D). When I tried to run Day Of The Tentacle using ScummVM (v1.5.0) I directly got the following error: "Program failed (error #8000000B). Wait for disk activity to finish". Sometimes the game did start, but crashed during the intro animation (returning to the raspberry console). The same happened with Sam & Max. When I disabled JIT (both for the CPU and the FPU) the games did run properly (albeit quite slower).

So, in short: using the 32-bit versions of both Raspberry Pi OS Lite and Amiberry, the emulation does not work with JIT enabled on my Pi 4B. Using the 64-bit versions of both Raspberry Pi OS Lite and Amiberry, the emulation does work with JIT enabled (both CPU and FPU), but there are problems when running more demanding games (that use an FPU?).

Is this a known issue? In any case, I hope somebody will be able to fix it. Please let me know when I need to provide more details.

Kind regards

Yserra commented 1 year ago

I had a similar issue a few years ago. If I remember well, after long weeks of tests, I finally solved the problem on the 32 bit version of Amiberry by installing another 68030.library/68040.library file in the LIBS: folder of my Workbench image disk. Then, JIT suddenly worked.

midwan commented 1 year ago

@Realinferno The JIT implementation is different for 32-bit and 64-bit targets. So it's possible that there is a bug there somewhere, if it behaves differently between those two versions. However, I didn't write this JIT implementation, so it's very hard for me to figure out and fix such a bug, if it's there. :(

The slowdown behavior you described, sounds a lot like an overheating problem. The Pi4 needs active cooling, and if you're running Amiberry using 100% of it's CPU all the time, it will heat up and it may be throttling down due to that. That would explain why it seems to run fine for a while, but slows down afterwards.

Realinferno commented 1 year ago

I had a similar issue a few years ago. If I remember well, after long weeks of tests, I finally solved the problem on the 32 bit version of Amiberry by installing another 68030.library/68040.library file in the LIBS: folder of my Workbench image disk. Then, JIT suddenly worked.

Ok, thanks for the suggestion! I found 68030.library and 68040.library files on Aminet (by Thomas Richter). I will copy these to the LIBS: folder and see what happens.

Realinferno commented 1 year ago

@Realinferno The JIT implementation is different for 32-bit and 64-bit targets. So it's possible that there is a bug there somewhere, if it behaves differently between those two versions. However, I didn't write this JIT implementation, so it's very hard for me to figure out and fix such a bug, if it's there. :(

The slowdown behavior you described, sounds a lot like an overheating problem. The Pi4 needs active cooling, and if you're running Amiberry using 100% of it's CPU all the time, it will heat up and it may be throttling down due to that. That would explain why it seems to run fine for a while, but slows down afterwards.

Thanks for your reply! I can imagine this is a hard nut to crack. Do you know who wrote the JIT implementation? Are you able/willing to look into this issue yourself or should I try to reach out to somebody else (e.g., I could e-mail the developer of HstWB installer Henrik Nørfjand Stengaard). Of course, I can provide more details that could help you (or somebody else) to recreate the issue.

Regarding the slowdown, I do use both active (two fans) and passive cooling (heatsinks) on my Pi4. Normally, the temperature of the Pi lies somewhere between 40 and 50 degrees Celcius. However, I have not checked the temperature while running demanding games. So, this is something I will look into.

Realinferno commented 1 year ago

Hello,

I have tried/tested various things since my last post. First of all, I installed new 68030 and 68040 libraries (on Aminet, by Thomas Richter). Unfortunately, this did not make any difference (Workbench 3.1 with JIT still crashed on boot-up on my Raspberry Pi 4B, 32-bit installation). @Yserra: perhaps I need different versions of the libraries?

Second, I checked the temperature of my Pi 4B (64-bit installation) when running demanding games like Quake 2 (with JIT CPU & FPU). With both passive and active cooling (two fans), the temperature did not exceed 50 degrees Celsius. So, temperature is not a problem. Games like Quake 2 (as well as Duke3D, Doom 2) run really well (640x480), but still the framerate tends to drop after playing a while. Simply opening and closing the Amiberry menu (within a matter of seconds) solves the problem (it seems like opening the Amiberry menu “re-activates” the JIT?).

Lastly, I also installed Amiberry 32-bit and 64-bit (using Raspberry Pi OS lite 32-bit or 64-bit and HstWB installer) on a Raspberry Pi 3B I had lying around. As such, I was able to compare 4 different installations (Pi 3B/4B, 32-bit/64-bit version of Amiberry), with otherwise the same set-up (Amiberry v5.5.1 installed via HstWB installer, A1200 AGA set-up with 68030 CPU, 68882 FPU, fastest CPU speed, 2MB chip RAM, 128 MB fast RAM, 16MB RTG RAM, same .hdf file running workbench 3.1).

I compared the 4 installations with regard to JIT boot-up and running some more demanding games that would benefit from JIT: Day of the Tentacle and Sam & Max via ScummVM (v1.5.0), Death Rally (latest full version 1.1). The results are as follows:

Raspberry Pi 3B (32-bit) • Workbench 3.1 boots-up with JIT (CPU & FPU). • Day of the Tentacle and Sam & Max run well (a bit on the slow side). • Death Rally runs well.

Raspberry Pi 3B (64 -bit) • Workbench 3.1 boots-up with JIT (CPU & FPU) • Day of the Tentacle and Sam & Max crash at start-up (during intro animation), also when only JIT CPU is enabled. Without JIT the Pi is too slow to run the games properly. • Death Rally starts-up fine, but crashes when starting a race (when the screen changes to the actual race track), also when only JIT CPU is enabled. Without JIT the Pi is too slow to run the game properly.

Raspberry 4B (32-bit) • Workbench 3.1 crashes on start-up with JIT (CPU & FPU). It does boot-up with only JIT CPU enabled. • Day of the Tentacle and Sam & Max run well (with only JIT CPU). • Death Rally runs well (with only JIT CPU).

Raspberry 4B (64-bit) • Workbench 3.1 boots-up with JIT (CPU & FPU). • Day of the Tentacle and Sam & Max crash at start-up (during intro animation), also with only JIT CPU. Without JIT both games run well (a bit on the slow side). • Death Rally starts-up fine, but crashes when starting a race (when the screen changes to the actual race track), also when only JIT CPU is enabled. Without JIT the game runs well.

So, it seems like the JIT implementation in Amiberry still has a few issues. I’m not sure whether the above will help solve these issues. All classic Amiga games I tried out so far (which is quite a lot) run really well. So, all in all, I’m really happy with Amiberry! Perhaps I just need to/should be patient and wait for what the next version of Amiberry will bring. Alternatively, I could try to install Amiberry via a different OS (I heard Manjaro runs Amiberry really well?).

giantclambake commented 1 year ago

Can confirm this ~ I see similar behaviour on the RPI4/B here running the 'Pimiga' image ; JIT is pretty much unusable.

Reneg: I had another look at this wrt Pimiga ~ 32bit JIT hurls chunks in libc.6 ...but it's probably not the point here =)

Ergo, I used this image;

https://downloads.raspberrypi.com/raspios_oldstable_full_arm64/images/raspios_oldstable_full_arm64-2023-10-10/2023-05-03-raspios-bullseye-arm64-full.img.xz

Set that up (I use a pironman v2), cloned the amiberry git, compiled with PLATFORM=rpi4-64-sdl2, moved the pimiga disks directory into the fray, and it works fine .... and I have to eat my words about 64bit JIT not working because now it's working fine.

With the pimiga setup at least ~ I'll swing around in the next few days and try those Amiga titles you mention, and report back.

midwan commented 7 months ago

I guess this is related to BlitterStudio/amiberry-lite#4 , if we're talking about JIT compatibility.

midwan commented 7 months ago

Closing this as a duplicate