Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to enable / disable Hyper-threading Technology dynamically by Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report