intel 超线程技术脚步检测是否开启

前言

intel的超线程技术能让一个物理核上并行执行两个线程,大多数情况下能提高硬件资源的利用率,增强系统性能。对于cpu密集型的数值程序,超线程技术可能会导致整体程序性能下降。鉴于此,执行OpenMP或者MPI数值程序时建议关闭超线程技术。

以下是github上找到的动态打开、关闭超线程技术的脚本。其原理是根据/sys/devices/system/cpu/cpuX/topology/thread_siblings_list文件找到逻辑核的关系,然后编辑/sys/devices/system/cpu/cpuX/online文件实现动态开启和关闭超线程技术。

If the number of logical processors is twice the number of cores you have HT. Use to following script to decode /proc/cpuinfo:

#!/bin/sh
CPUFILE=/proc/cpuinfo
test -f $CPUFILE || exit 1
NUMPHY=`grep "physical id" $CPUFILE | sort -u | wc -l`
NUMLOG=`grep "processor" $CPUFILE | wc -l`
if [ $NUMPHY -eq 1 ]
  then
    echo This system has one physical CPU,
  else
    echo This system has $NUMPHY physical CPUs,
fi
if [ $NUMLOG -gt 1 ]
  then
    echo and $NUMLOG logical CPUs.
    NUMCORE=`grep "core id" $CPUFILE | sort -u | wc -l`
    if [ $NUMCORE -gt 1 ]
      then
        echo For every physical CPU there are $NUMCORE cores.
    fi
  else
    echo and one logical CPU.
fi
echo -n The CPU is a `grep "model name" $CPUFILE | sort -u | cut -d : -f 2-`
echo " with`grep "cache size" $CPUFILE | sort -u | cut -d : -f 2-` cache"

开启或关闭超线程技术

#!/bin/bash

HYPERTHREADING=1

function toggleHyperThreading() {
 for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
   CPUID=`basename $CPU | cut -b4-`
   echo -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.";;
  esac
done
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值