bsnes icon indicating copy to clipboard operation
bsnes copied to clipboard

Unusually high CPU usage when playing seemingly any game

Open sonic2kk opened this issue 3 years ago • 6 comments

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:

  • Arch Linux with KDE Plasma 5.24.0 (Wayland session)
  • Kernel 5.16.8
  • Ryzen 3700X CPU
  • AMD 5700XT 8GB GPU

sonic2kk avatar Feb 14 '22 04:02 sonic2kk

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

sonic2kk avatar Feb 14 '22 05:02 sonic2kk

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

Screwtapello avatar Feb 14 '22 08:02 Screwtapello

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

sonic2kk avatar Feb 14 '22 21:02 sonic2kk

@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.

orbea avatar Feb 22 '22 18:02 orbea

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.

carmiker avatar Feb 22 '22 18:02 carmiker

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.

Sunspark-007 avatar Dec 07 '22 00:12 Sunspark-007