How to enable / disable Hyper-threading Technology dynamically by Linux
This article mainly shows you "Linux how to dynamically enable / disable hyper-threading technology", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Linux how to dynamically enable / disable hyper-threading technology" this article.
Preface
Intel's hyper-threading technology allows two threads to be executed in parallel on a physical core, which in most cases can improve the utilization of hardware resources and enhance system performance. For cpu-intensive numerical programs, hyper-threading technology may lead to a decline in overall program performance. For this reason, it is recommended to turn off hyper-threading when executing OpenMP or MPI numeric programs.
Here are the scripts found on github to dynamically turn on and off hyper-threading technology. The principle is to find the relationship between the logical core according to the / sys/devices/system/cpu/cpuX/topology/thread_siblings_list file, and then edit the / sys/devices/system/cpu/cpuX/online file to dynamically open and close hyper-threading technology.
#! / bin/bashHYPERTHREADING=1function toggleHyperThreading () {for CPU in/ sys/devices/system/cpu/cpu [0-9] *; do CPUID= `basename $CPU | cut-b4-`basename $CPU | cut-b4-`basename en "CPU: $CPUID\ t" [- e $CPU/online] & & echo "1" > $CPU/online THREAD1= `cat $CPU/topology/thread_siblings_list | cut-F1-d, `if [$CPUID= $THREAD1] Then echo "- > enable" [- e $CPU/online] & & echo "1" > $CPU/online else if ["$HYPERTHREADING"-eq "0"]; then echo "- > disabled"; else echo "- > enabled" Fi echo "$HYPERTHREADING" > $CPU/online fi done} function enabled () {echo-en "Enabling HyperThreading\ n" HYPERTHREADING=1 toggleHyperThreading} function disabled () {echo-en "Disabling HyperThreading\ n" HYPERTHREADING=0 toggleHyperThreading} # ONLINE=$ (cat / sys/devices/system/cpu/online) OFFLINE=$ (cat / sys/devices/system/cpu/offline) echo "-- -"echo-en" CPU's online: $ONLINE\ t CPU's offline: $OFFLINE\ n "echo"-- "while true" Do read-p "Type in e to enable or d disable hyperThreading or q to quit [e/d/q]?" Ed case $ed in [Ee] *) enabled; break;; [Dd] *) disabled;exit;; [Qq] *) exit;; *) echo "Please answer e for enable or d for disable hyperThreading."; esacdone
Note:
Script needs root permission to execute
You can view the enabled cpu information through cat / proc/cpuinfo, which does not require root permission
The lscpu command can view the status of cpu (no root permission is required): the threads per core value is 2 in hyperthreaded state and 1. 0 when disabled.
These are all the contents of the article "how Linux dynamically enables / disables Hyper-threading Technology". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!