how to disable or enable smt (hy
2021-10-19 本文已影响0人
AppleLin_cdea
2021年10月19日15:48:19
如何关闭 cpu 超线程
说明:这个重启后就恢复原样了
show logic core
# cat show_ht.sh
#!/bin/bash
let cpu_number=$(getconf _NPROCESSORS_ONLN)
for ((i=${cpu_number}/2; i<${cpu_number}; i++));do
echo “logical HT core $i.”
done
disable logic core
# cat disable_ht.sh
#!/bin/bash
let cpu_number=$(getconf _NPROCESSORS_ONLN)
for ((i=${cpu_number}/2; i<${cpu_number}; i++));do
echo “Disabling logical HT core $i.”
echo 0 > /sys/devices/system/cpu/cpu${i}/online;
done
enable logic core
#!/bin/bash
let cpu_number=$(getconf _NPROCESSORS_ONLN)
for ((i=${cpu_number}; i<${cpu_number}*2; i++));do
echo “enable logical HT core $i.”
echo 1 > /sys/devices/system/cpu/cpu${i}/online;
done
demo
没有关超线程
lscpu|grep core:
Thread(s) per core: 2
关超线程
lscpu|grep core:
Thread(s) per core: 1
apple:~/smt$ lscpu|head -8
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
apple:~/smt$ sudo ./disable_ht.sh
“Disabling logical HT core 8.”
“Disabling logical HT core 9.”
“Disabling logical HT core 10.”
“Disabling logical HT core 11.”
“Disabling logical HT core 12.”
“Disabling logical HT core 13.”
“Disabling logical HT core 14.”
“Disabling logical HT core 15.”
apple:~/smt$ lscpu|head -8
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-7
Off-line CPU(s) list: 8-15
Thread(s) per core: 1
Core(s) per socket: 8
apple:~/smt$