SteamOS icon indicating copy to clipboard operation
SteamOS copied to clipboard

[Feature Request] Steam Deck - Toggle to enable/disable Simultaneous Multithreading (SMT) in Quick Menu or game properties

Open Shaunathanz opened this issue 1 year ago • 43 comments

Your system information

  • Steam client version: n/a
  • SteamOS version: n/a
  • Opted into Steam client beta?: n/a
  • Opted into SteamOS beta?: n/a
  • Have you checked for updates in Settings > System?: n/a

Please describe your issue in as much detail as possible:

It would be beneficial for CPU constrained games or programs that don't make use of more than 4 threads or don't benefit from the use of more threads to be able to disable SMT. Right now this can be accomplished with Decky Loader and the PowerTools plugin but official support would likely be beneficial to tinkerers and performance junkies (and people that like to run Dolphin & PCSX2 at full speed)

Steps for reproducing this issue:

  1. Run a CPU intensive game in game mode
  2. Take note of FPS
  3. Disable SMT
  4. Run game again
  5. Notice the difference

Shaunathanz avatar Sep 29 '22 17:09 Shaunathanz

What's the advantage of disabling SMT over settings a power-cap via the existing UI? Reduce the GPU clocks, reduce the power envelope - the CPU clock to lower frequencies. Thus the FPS and temperatures stay within my range of interest.

This is what I've been using for a bunch of older games with lower hardware requirements. It works like a charm.

AFAICT it's possible to disable SMT at runtime via /sys/devices/system/cpu/smt/control although writing to it requires root access which is a big red flag, usually.

evelikov avatar Sep 30 '22 12:09 evelikov

emulation runs better when cores aren't flooded with threads and have dedicated cores. TDP doesn't do that

I've tested this with power tools decky plugin

james2432 avatar Sep 30 '22 13:09 james2432

Am I understanding this correctly, that emulators want to avoid bouncing threads across cores?

If it were me I would use pthread_setaffinity_np() or the Windows variant to achieve that. IMHO it scales much better than asking your users to disable cores or SMT.

evelikov avatar Oct 01 '22 13:10 evelikov

Am I understanding this correctly, that emulators want to avoid bouncing threads across cores?

If it were me I would use pthread_setaffinity_np() or the Windows variant to achieve that. IMHO it scales much better than asking your users to disable cores or SMT.

Not every game is a AAA blockbuster that is programmed in a way where it makes effective use of multiple threads per physical core, especially not games developed prior to the PS4/XBONE generation of consoles. Many games run better with a single thread running on a single core and no sharing processing power between threads.

Users being able to toggle SMT is hardly a risk to system stability or the end user experience.

Shaunathanz avatar Oct 03 '22 21:10 Shaunathanz

Suspect that most emulators have DB of quirks already. Extending those to cover the optimal topology sounds reasonable IMHO.

I'm not arguing against a SMT toggle, but high-lighting that pushing this decision to others scales very poorly.

evelikov avatar Oct 04 '22 12:10 evelikov

This has not only uses with Emulators, but with other Games as well. Especially older onces who dont scale well with Multicore Processors. Encountered a few of them already. Adapting this would be a good Idea. Or at least a Enviroment Variable to be passed at launch would be great for tinkering.

NightHammer1000 avatar Oct 11 '22 22:10 NightHammer1000

emulation runs better when cores aren't flooded with threads and have dedicated cores. TDP doesn't do that

I've tested this with power tools decky plugin @evelikov

Not even just emulation but could have advantages for single-threaded stuff that are more optimised to expect that situation. Didn't people used to do that kinda thing for getting the most out of 1st Gen Ryzen? 🤔 (With either OC + Undervolt or just with the automatic settings)

Daasin avatar Oct 15 '22 14:10 Daasin

Noticing poor performance in emulators such as PCSX2 led me to this post. Disabling SMT with Powertools works like a charm and all my performance issue are resolved. I just wanted to also say that I enthusiastically support a feature like this in the official OS.

esotericode avatar Oct 21 '22 21:10 esotericode

Affected Emulators I noticed so far:

Dolphin PCSX2 RPCS3 YUZU Ryujinx

All these Emulators give way more Performance with SMT off.

NightHammer1000 avatar Oct 22 '22 16:10 NightHammer1000

Having official support for this would be great, even if it was only added in the steam decks developer settings.

Daniel-Griffiths avatar Oct 30 '22 17:10 Daniel-Griffiths

A SMT toggle almost feels essential for emulators and single threaded games that require a higher and stable clockspeed.

In general though, the options included in Powertools being officially part of Steam OS as an advanced menu would be a godsend.

ds22x avatar Nov 04 '22 13:11 ds22x

Having official support for this would be great, even if it was only added in the steam decks developer settings.

Or in the UEFI menu if just having the setting out there is seen as a bad move

Daasin avatar Nov 06 '22 23:11 Daasin

Having official support for this would be great, even if it was only added in the steam decks developer settings.

Or in the UEFI menu if just having the setting out there is seen as a bad move

imo the Developer Settings/the UEFI menu is a no-go. It needs to be done per-game like TDP or Manual GPU Frequency override, and I'm certainly not going to reboot every time I switch between what I'm playing especially when it can be done at the OS level effectively as seen in PowerTools.

And again, it's not just emulators. Many older games run better with higher frequencies on fewer threads. The same TDP cap on 8 threads compared to 4 results in lower frequencies. Proton already acknowledges this with its WINE_CPU_TOPOLOGY override (in proton-cpu-topology-overrides.patch), but this obviously doesn't work for native Linux applications.

xperia64 avatar Nov 08 '22 15:11 xperia64

I wanted to note my own support for this; having control over core count exposed in SteamOS Advanced Settings/Developer Mode would be highly preferable to the current Decky/PowerTools method. Even better would be having it configurable on a per-game-launch basis, as opposed to a universal toggle, but honestly any functionality would be a massive help (and improvement over the existing solutions).

aujang avatar Dec 12 '22 15:12 aujang

Highly support adding something like this under the existing per-game options under the advanced performance overlay, as how all other performance tweaks are currently applied. Basically mirroring the existing Power Tools implementation would be really helpful to have as a native feature. It comes up across a lot of games and emulators where disabling SMT yeilds significant results.

othyn avatar Jan 05 '23 16:01 othyn

For those who waits this feature: you can kinda do that already without any third-party software. SteamOS has taskset utility, which is used to set CPU affinity of a process and doesn't need root in order to work. To use it as "SMT off button", change launch parameters to taskset -c 0,2,4,6 %command%. It will force the game to use only cores, while threads will do background tasks. From my limited testing this is actually a better option than disabling threads altogether.

bugworm avatar Jan 06 '23 18:01 bugworm

Tried the taskset suggestion as shown above, but while it does seem to make it a bit more stable due to forcing a game to stay on the assigned cores, it doesn't provide the performance boost seen when disabling SMT.

ds22x avatar Jan 08 '23 17:01 ds22x

It's happening guys, thanks to all those who chimed in to help make SteamOS better for everyone.

https://twitter.com/Plagman2/status/1626041563737645056

Shaunathanz avatar Feb 17 '23 20:02 Shaunathanz

this could probably not be required as of the 3.5 release of steamOS with the new kernel:

https://www.pcgamer.com/steamos-35-is-almost-here-includes-a-fix-for-the-steam-decks-sneakiest-performance-bug/

james2432 avatar Mar 16 '23 13:03 james2432

Interesting, so TLDR for those not wanting to read the article, Valve didn't want to add the toggle into SteamOS natively as they saw the need to disable SMT at all as a bug, SteamOS 3.5 intends to fix that.

The summary is that AMD discovered a Linux kernel bug that invalidates a cores cache once a thread sleeps, meaning the other thread using the core (as that's what SMT is) would loose access to anything in the cache and have to go refetch it from memory, which is comparitively slow, causing performance issues in older (or emulated) games.

Newer software and games can apply patches to work around that, where as older games and (even in emulators) will not. Instead of Valve taking the approach of placing this on the user, and applauds the efforts of things like PowerTools for providing the SMT toggle as a work around, their goal was always to try and patch the bug so that SMT never has to be disabled in the first place and correct performance is always attained.

With SteamOS 3.5 containing this patch, they're hoping the need to disable SMT at all will go away, but are listening to user feedback post-update to see how that works in reality.

othyn avatar Mar 16 '23 14:03 othyn

Steam OS 3.5 with Kernel 6.1.12-valve2-1-neptune-61 is out on steam deck preview branch, but unfortunately I am not seeing the benefit of the SMT fix that is supposed to be in the new kernel.

Test case: Dolphin, playing Metroid Prime 2, open the scan visor in the first room. With SMT on, the game slows to 35FPS or so. With SMT off, it stays around 60FPS. This is still the case in the new Kernel 6.1 in steam deck preview.

Perhaps the SMT changes aren't in the kernel yet?

bangstk avatar Mar 17 '23 05:03 bangstk

Shouldn't the changes already be in the kernel if they are rebasing to 6.1? Unless there's something else bottlenecking it or we have to wait until steamos 3.5 shows up on the beta branch to see it merged in properly?

Unless it's actually in the main update branch on deck, I'm unsure

waspennator avatar Mar 28 '23 17:03 waspennator

@bangstk I saw the same thing on both the main channel and a Ubuntu live USB running the 6.2 kernel -- SMT off still made a huge difference to Yuzu performance.

There's definitely still something weird going on apart from SMT. With SMT on, all 8 cores run at 2000 MHz and only show around 40% utilization, but I wasn't getting full speed. But then locking the GPU anywhere 1200MHz or higher, all 8 cores would boost up until Yuzu ran at full speed, which is the opposite of what I'd expect. Combined with https://github.com/ValveSoftware/SteamOS/issues/957, and being able to resolve that one by toggling the GPU frequency lock (no matter what it's set to!) it seems like the power management can get flaky.

EDIT: I'm pretty sure it's this bug. The symptoms are really similar and the workarounds have an effect: https://gitlab.freedesktop.org/drm/amd/-/issues/1500 (the workarounds don't entirely fix the problem, though)

justinweiss avatar Apr 21 '23 01:04 justinweiss

Honestly kinda curious if Sonic Generations runs better on the main branch or not out of the box now. Cause either the fixes aren't there yet, or they are in and certain programs like emulators are being bottlenecked by smt in some other way.

Or maybe it'll be easier to test out when steamos 3.5 lands in Preview or beta, cause I've seen someone on the deck reddit say smt performance is better and some still saying it's bad.

waspennator avatar Apr 21 '23 01:04 waspennator

I switched to the preview branch but there's no new kernel for me like @bangstk mentioned. I wonder if anyone else has access to it or did Valve pull the update or something like that?

esotericode avatar Apr 21 '23 03:04 esotericode

It's on the main channel, which only appears if you turn on "Show Advanced Update Channels" in the developer settings. I wouldn't recommend it right now, especially if you use an SD card or made any BIOS tweaks, since it changes the SD card path and updates the BIOS.

justinweiss avatar Apr 22 '23 00:04 justinweiss

PowerTools is likely messing with the CPU clock somehow when SMT is toggled off. This hurts battery life, but does push emulators and old games up to a more acceptable level of performance. I really think the whole idea of turning SMT off was a red herring.

Nope. I did not even have powertools installed for the test. I did nothing but write 'off' to /sys/devices/system/cpu/smt/control Any changes to cpu clock is solely as a consequence of SMT being turned off, not something powertools is doing.

bangstk avatar May 02 '23 19:05 bangstk

So is this something that can be fixed or will steam deck need an option to turn off smt?

Cause I'm guessing the specific smt fixes should be in main by now.

waspennator avatar May 02 '23 19:05 waspennator

@waspennator

I'm also really curious to know if the changes in the main branch actually resolve the performance issues with emulators or not. I've seen conflicting reports between "totally fixed" and "not at all" so I dunno what to believe.

esotericode avatar May 02 '23 20:05 esotericode

I am still seeing significantly better performance in stress testing scenarios with SMT disabled on the latest stable branch. I was able to boost the FPS in Metroid Prime 2 Echoes by 10%

Shaunathanz avatar Jun 25 '23 15:06 Shaunathanz