Linux – 手動關閉 hyperthread
有些情況在 BIOS 找不到關閉 CPU hyperthreadn 選項,只好透過指令手動關閉。下列指令可以手動關閉所有 hyperthread:
# echo off | sudo tee /sys/devices/system/cpu/smt/control
可以用下列指令檢查 hyperthread 狀態
# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list
/sys/devices/system/cpu/cpu0/topology/thread_siblings_list:0
/sys/devices/system/cpu/cpu10/topology/thread_siblings_list:10
/sys/devices/system/cpu/cpu11/topology/thread_siblings_list:11
/sys/devices/system/cpu/cpu12/topology/thread_siblings_list:12
/sys/devices/system/cpu/cpu13/topology/thread_siblings_list:13
/sys/devices/system/cpu/cpu14/topology/thread_siblings_list:14
/sys/devices/system/cpu/cpu15/topology/thread_siblings_list:15
/sys/devices/system/cpu/cpu1/topology/thread_siblings_list:1
/sys/devices/system/cpu/cpu2/topology/thread_siblings_list:2
/sys/devices/system/cpu/cpu3/topology/thread_siblings_list:3
/sys/devices/system/cpu/cpu4/topology/thread_siblings_list:4
/sys/devices/system/cpu/cpu5/topology/thread_siblings_list:5
/sys/devices/system/cpu/cpu6/topology/thread_siblings_list:6
/sys/devices/system/cpu/cpu7/topology/thread_siblings_list:7
/sys/devices/system/cpu/cpu8/topology/thread_siblings_list:8
/sys/devices/system/cpu/cpu9/topology/thread_siblings_list:9
# lscpu | grep Thread
Thread(s) per core: 1
如果要恢復 hyperthread 就使用下列指令:
# echo on | sudo tee /sys/devices/system/cpu/smt/control
再檢查一次 hyperthread 狀況:
# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list
/sys/devices/system/cpu/cpu0/topology/thread_siblings_list:0,16
/sys/devices/system/cpu/cpu10/topology/thread_siblings_list:10,26
/sys/devices/system/cpu/cpu11/topology/thread_siblings_list:11,27
/sys/devices/system/cpu/cpu12/topology/thread_siblings_list:12,28
/sys/devices/system/cpu/cpu13/topology/thread_siblings_list:13,29
/sys/devices/system/cpu/cpu14/topology/thread_siblings_list:14,30
/sys/devices/system/cpu/cpu15/topology/thread_siblings_list:15,31
/sys/devices/system/cpu/cpu16/topology/thread_siblings_list:0,16
/sys/devices/system/cpu/cpu17/topology/thread_siblings_list:1,17
/sys/devices/system/cpu/cpu18/topology/thread_siblings_list:2,18
/sys/devices/system/cpu/cpu19/topology/thread_siblings_list:3,19
/sys/devices/system/cpu/cpu1/topology/thread_siblings_list:1,17
/sys/devices/system/cpu/cpu20/topology/thread_siblings_list:4,20
/sys/devices/system/cpu/cpu21/topology/thread_siblings_list:5,21
/sys/devices/system/cpu/cpu22/topology/thread_siblings_list:6,22
/sys/devices/system/cpu/cpu23/topology/thread_siblings_list:7,23
/sys/devices/system/cpu/cpu24/topology/thread_siblings_list:8,24
/sys/devices/system/cpu/cpu25/topology/thread_siblings_list:9,25
/sys/devices/system/cpu/cpu26/topology/thread_siblings_list:10,26
/sys/devices/system/cpu/cpu27/topology/thread_siblings_list:11,27
/sys/devices/system/cpu/cpu28/topology/thread_siblings_list:12,28
/sys/devices/system/cpu/cpu29/topology/thread_siblings_list:13,29
/sys/devices/system/cpu/cpu2/topology/thread_siblings_list:2,18
/sys/devices/system/cpu/cpu30/topology/thread_siblings_list:14,30
/sys/devices/system/cpu/cpu31/topology/thread_siblings_list:15,31
/sys/devices/system/cpu/cpu3/topology/thread_siblings_list:3,19
/sys/devices/system/cpu/cpu4/topology/thread_siblings_list:4,20
/sys/devices/system/cpu/cpu5/topology/thread_siblings_list:5,21
/sys/devices/system/cpu/cpu6/topology/thread_siblings_list:6,22
/sys/devices/system/cpu/cpu7/topology/thread_siblings_list:7,23
/sys/devices/system/cpu/cpu8/topology/thread_siblings_list:8,24
/sys/devices/system/cpu/cpu9/topology/thread_siblings_list:9,25
# lscpu | grep Thread
Thread(s) per core: 2
如果只是想要關閉某 cpuid 可以用下列指令:
# echo 0 | sudo tee /sys/devices/system/cpu/cpu8/online
反之:
# echo 1 | sudo tee /sys/devices/system/cpu/cpu8/online