smt-manager: Disable Hyper Threading (and related technologies)
damentz
Status: Assistant
Joined: 09 Sep 2008
Posts: 1135
Reply Quote
Hello everyone,

Available as of now on github is a new script I thought the rest of you would find useful. It's called smt-manager, or Simultaneous Multithreading Manager. All it does is let you turn on and off all logical cores at once:

github.com/damentz/smt-manager

For example, executing the script in this repository with --offline returns this output:

:: Code ::
$ sudo smt-manager.pl --offline
[sudo] password for damentz:
CPU topology:
cpu0: primary | online
cpu1: primary | online
cpu2: primary | online
cpu3: primary | online
cpu4: logical | online
cpu5: logical | online
cpu6: logical | online
cpu7: logical | online

Setting cpu4 to offline ... done!
Setting cpu5 to offline ... done!
Setting cpu6 to offline ... done!
Setting cpu7 to offline ... done!
[ ok ] Restarting irqbalance (via systemctl): irqbalance.service.

CPU topology:
cpu0: primary | online
cpu1: primary | online
cpu2: primary | online
cpu3: primary | online
cpu4: unknown | offline
cpu5: unknown | offline
cpu6: unknown | offline
cpu7: unknown | offline


Running smt-manager.pl with --online restores everything back to normal:

:: Code ::
$ sudo smt-manager.pl --online
[sudo] password for damentz:
CPU topology:
cpu0: primary | online
cpu1: primary | online
cpu2: primary | online
cpu3: primary | online
cpu4: unknown | offline
cpu5: unknown | offline
cpu6: unknown | offline
cpu7: unknown | offline

Setting cpu4 to online ... done!
Setting cpu5 to online ... done!
Setting cpu6 to online ... done!
Setting cpu7 to online ... done!
[ ok ] Restarting irqbalance (via systemctl): irqbalance.service.

CPU topology:
cpu0: primary | online
cpu1: primary | online
cpu2: primary | online
cpu3: primary | online
cpu4: logical | online
cpu5: logical | online
cpu6: logical | online
cpu7: logical | online


Running smt-manager.pl by itself will just show you your current topology (which you get output of before and after).

The benefits of disabling logical cores? Very workload specific - if you cannot risk two executions occurring on the same core where one task is considered high priority and the other low or idle, the only way to guarantee cpu time gets distributed accurately is to disable logical cores. With logical cores enabled, cpu time will be distributed evenly between both executions regardless of priority.

Throughput will drop but performance will be more predictable. That is the tradeoff you get when disabling hyperthreading, or the technology AMD uses on their Bulldozer cores and newer.
Back to top
ethanay
Status: Curious
Joined: 28 May 2020
Posts: 6
Reply Quote
This is fantastic. I was previously using the nosmt boot parameter. Having a quick and easy way to "hotplug" the logical cores is preferable. I always assumed that doing so would have adverse side-effects compared to disabling them at boot.
Back to top
DeepDayze
Status: Contributor
Joined: 21 May 2009
Posts: 128
Reply Quote
Is smt-manager up to date enough to work properly on AMD Ryzen, ThreadRipper, EPYC CPU's?
Back to top
damentz
Status: Assistant
Joined: 09 Sep 2008
Posts: 1135
Reply Quote
Yes, it'll work. The SMT cores are also called thread siblings in the kernel, and smt-manager uses that to find and identify the logical core.

On an Intel quad core, you'll get something like this:
:: Code ::
$ cat /sys/devices/system/cpu/cpu0/topology/thread_siblings_list
0,4


Ryzen systems might number their thread siblings differently. Intel labels all physical cores before logical (at least for now).
Back to top
DeepDayze
Status: Contributor
Joined: 21 May 2009
Posts: 128
Reply Quote
On my Ryzen 3 system which is 4 cores I get this:

:: Code ::
$ cat /sys/devices/system/cpu/cpu0/topology/thread_siblings_list
0

Back to top
damentz
Status: Assistant
Joined: 09 Sep 2008
Posts: 1135
Reply Quote
Most Ryzen 3 processors don't have SMT: en.m.wikipedia.org/wiki/Ryzen

What does the output of inxi tell you?
Back to top
Display posts from previous:   

All times are GMT - 8 Hours