bsnes-emu / bsnes

bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.
Other
1.68k stars 156 forks source link

Unusually high CPU usage when playing seemingly any game #239

Open sonic2kk opened 2 years ago

sonic2kk commented 2 years ago

I am running on a Ryzen 3700X CPU using the Flatpak release of bsnes v115, and my CPU usage is around 44% when any game is running. When no game is running, virtually no CPU usage is reported. When a game is running, pausing the game (by unfocusing the window) brings CPU levels back down to normal. Here is a screenshot to illustrate:

Screenshot_20220214_044759

It doesn't seem to impact performance, and the usage doesn't fluctuate (KSysGuard reports 44% in the Process Table tab consistently). Regardless of this though, I don't think using 44% of this CPU is normal.

I have tested with EarthBound, Super Mario All-Stars, Super Metroid and Donkey Kong Country. I have tested with the games on various different drives with compressed and uncompressed ROMs. I have also tried the OpenGL 3.2 and OpenGL 2.0 drivers and there is no difference. The "Size" option and shaders don't have any impact either.

System Information:

sonic2kk commented 2 years ago

I tested with an installation from the AUR and the emulator did not function correctly at all, and CPU usage was at 100%.

Screwtapello commented 2 years ago

In Settings → Enhancements, what is the HD Mode 7 "Scale" option set to?

sonic2kk commented 2 years ago

It is set to 240p. Here is a screenshot of the entire "Enhancements" screen. These were the default settings with the Flatpak installation, to my knowledge I haven't changed these.

Screenshot_20220214_213622

orbea commented 2 years ago

@sonic2kk You may want to try the jgemu bsnes fork.

https://gitlab.com/jgemu/bsnes

There was a significant decrease in CPU usage when converting the code base to standard C++ along with some other changes.

carmiker commented 2 years ago

Just as a note, much of the CPU performance issues came down to letting the compiler choose what functions to inline vs not inline. In some cases you do need to tell clang to inline certain PPU functions, but generally speaking it's a good idea to let the compiler do what it wants. In this codebase the relevant directives are called "alwaysinline" and "noinline". There may have been a point in time when these things were warranted, but that time has passed.

Sunspark-007 commented 1 year ago

https://github.com/bsnes-emu/bsnes/issues/254

In that ticket, it is theorized it is due to OpenMP creating too many threads. This issue affects the Steam Deck, bsnes will use 60% CPU on that system which will drain the battery faster.