<var id="z5l9h"><strike id="z5l9h"><progress id="z5l9h"></progress></strike></var>
<thead id="z5l9h"></thead>
<cite id="z5l9h"><strike id="z5l9h"><listing id="z5l9h"></listing></strike></cite>
<var id="z5l9h"></var>
<ins id="z5l9h"><strike id="z5l9h"></strike></ins> <var id="z5l9h"></var>
<var id="z5l9h"><dl id="z5l9h"></dl></var>
<var id="z5l9h"><strike id="z5l9h"><progress id="z5l9h"></progress></strike></var>

CPU网卡亲和绑定

#!/bin/bash
#
# Copyright (c) 2014, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Intel Corporation nor the names of its contributors
#       may be used to endorse or promote products derived from this software
#       without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Affinitize interrupts to cores
#
# typical usage is (as root):
# set_irq_affinity -x local eth1 <eth2> <eth3>
#
# to get help:
# set_irq_affinity

usage()
{
    echo
    echo "Usage: $0 [-x] {all|local|remote|one|custom} [ethX] <[ethY]>"
    echo "    options: -x        Configure XPS as well as smp_affinity"
    echo "    options: {remote|one} can be followed by a specific node number"
    echo "    Ex: $0 local eth0"
    echo "    Ex: $0 remote 1 eth0"
    echo "    Ex: $0 custom eth0 eth1"
    echo "    Ex: $0 0-7,16-23 eth0"
    echo
    exit 1
}

if [ "$1" == "-x" ]; then
    XPS_ENA=1
    shift
fi

num=^[0-9]+$
# Vars
AFF=$1
shift

case "$AFF" in
    remote)    [[ $1 =~ $num ]] && rnode=$1 && shift ;;
    one)    [[ $1 =~ $num ]] && cnt=$1 && shift ;;
    all)    ;;
    local)    ;;
    custom)    ;;
    [0-9]*)    ;;
    -h|--help)    usage ;;
    "")        usage ;;
    *)        IFACES=$AFF && AFF=all ;;    # Backwards compat mode
esac

# append the interfaces listed to the string with spaces
while [ "$#" -ne "0" ] ; do
    IFACES+=" $1"
    shift
done

# for now the user must specify interfaces
if [ -z "$IFACES" ]; then
    usage
    exit 1
fi

# support functions

set_affinity()
{
    VEC=$core
    if [ $VEC -ge 32 ]
    then
        MASK_FILL=""
        MASK_ZERO="00000000"
        let "IDX = $VEC / 32"
        for ((i=1; i<=$IDX;i++))
        do
            MASK_FILL="${MASK_FILL},${MASK_ZERO}"
        done

        let "VEC -= 32 * $IDX"
        MASK_TMP=$((1<<$VEC))
        MASK=$(printf "%X%s" $MASK_TMP $MASK_FILL)
    else
        MASK_TMP=$((1<<$VEC))
        MASK=$(printf "%X" $MASK_TMP)
    fi

    printf "%s" $MASK > /proc/irq/$IRQ/smp_affinity
    printf "%s %d %s -> /proc/irq/$IRQ/smp_affinity\n" $IFACE $core $MASK
    if ! [ -z "$XPS_ENA" ]; then
        printf "%s %d %s -> /sys/class/net/%s/queues/tx-%d/xps_cpus\n" $IFACE $core $MASK $IFACE $((n-1))
        printf "%s" $MASK > /sys/class/net/$IFACE/queues/tx-$((n-1))/xps_cpus
    fi
}

# Allow usage of , or -
#
parse_range () {
        RANGE=${@//,/ }
        RANGE=${RANGE//-/..}
        LIST=""
        for r in $RANGE; do
        # eval lets us use vars in {#..#} range
                [[ $r =~ .. ]] && r="$(eval echo {$r})"
        LIST+=" $r"
        done
    echo $LIST
}

# Affinitize interrupts
#
setaff()
{
    CORES=$(parse_range $CORES)
    ncores=$(echo $CORES | wc -w)
    n=1

    # this script only supports interrupt vectors in pairs,
    # modification would be required to support a single Tx or Rx queue
    # per interrupt vector

    queues="${IFACE}-.*TxRx"

    irqs=$(grep "$queues" /proc/interrupts | cut -f1 -d:)
    [ -z "$irqs" ] && irqs=$(grep $IFACE /proc/interrupts | cut -f1 -d:)
    [ -z "$irqs" ] && irqs=$(for i in `ls -Ux /sys/class/net/$IFACE/device/msi_irqs` ;                             do grep "$i:.*TxRx" /proc/interrupts | grep -v fdir | cut -f 1 -d : ;                             done)
    [ -z "$irqs" ] && echo "Error: Could not find interrupts for $IFACE"

    echo "IFACE CORE MASK -> FILE"
    echo "======================="
    for IRQ in $irqs; do
        [ "$n" -gt "$ncores" ] && n=1
        j=1
        # much faster than calling cut for each
        for i in $CORES; do
            [ $((j++)) -ge $n ] && break
        done
        core=$i
        set_affinity
        ((n++))
    done
}

# now the actual useful bits of code

# these next 2 lines would allow script to auto-determine interfaces
#[ -z "$IFACES" ] && IFACES=$(ls /sys/class/net)
#[ -z "$IFACES" ] && echo "Error: No interfaces up" && exit 1

# echo IFACES is $IFACES

CORES=$(</sys/devices/system/cpu/online)
[ "$CORES" ] || CORES=$(grep ^proc /proc/cpuinfo | cut -f2 -d:)


node_dir=/sys/devices/system/node
for i in $(ls -d $node_dir/node*); 
do i=${i/*node/} corelist[$i]=$(<$node_dir/node${i}/cpulist) done for IFACE in $IFACES; do dev_dir=/sys/class/net/$IFACE/device [ -e $dev_dir/numa_node ] && node=$(<$dev_dir/numa_node) [ "$node" ] && [ "$node" -gt 0 ] || node=0 case "$AFF" in local) CORES=${corelist[$node]} ;; remote) [ "$rnode" ] || { [ $node -eq 0 ] && rnode=1 || rnode=0; } CORES=${corelist[$rnode]} ;; one) [ -n "$cnt" ] || cnt=0 CORES=$cnt ;; all) CORES=$CORES ;; custom) echo -n "Input cores for $IFACE (ex. 0-7,15-23): " read CORES ;; [0-9]*) CORES=$AFF ;; *) usage exit 1 ;; esac # call the worker function setaff done IRQBALANCE_ON=`ps ax | grep -v grep | grep -q irqbalance; echo $?` if [ "$IRQBALANCE_ON" == "0" ] ; then echo " WARNING: irqbalance is running and will" echo " likely override this script‘s affinitization." echo " Please stop the irqbalance service and/or execute" echo " ‘killall irqbalance‘" fi
相关文章
761111香港马会查询无错九肖 当涂县| 天门市| 溆浦县| 林甸县| 萨迦县| 洛宁县| 特克斯县| 灵山县| 深州市| 望谟县| 宝应县| 石渠县| 赞皇县| 呼和浩特市| 万山特区| 繁峙县| 大田县| 米易县| 轮台县| 榕江县| 肇庆市| 得荣县| 惠东县| 仪征市| 晋城| 任丘市| 库伦旗| 保定市| 敖汉旗| 独山县| 宁津县| 界首市| 安新县| 白玉县| 利辛县| 肃宁县| 北流市| 游戏| 林芝县| 嘉荫县| 重庆市| 灌云县| 黔南| 阳春市| 合阳县| 平阴县| 皮山县| 乐安县| 蓬安县| 措美县| 高淳县| 九寨沟县| 轮台县| 高邑县| 梨树县| 平度市| 安溪县| 通河县| 济阳县| 潜山县| 江源县| 乌什县| 元谋县| 常德市| 江油市| 泰和县| 临城县| 理塘县| 合肥市| 西乌珠穆沁旗| 留坝县| 平顶山市| 横峰县| 资阳市| 紫金县| 新平| 平潭县| 雅江县| 承德县| 龙南县| 扶绥县| 岳普湖县| 潜江市| 隆昌县| 宜兰市| 浮梁县| 蒙山县| http://www.flskipo888.com http://www.hstoner888.com http://m.flsmarto888.com http://www.flskipo888.com http://wap.flshirto888.com http://www.htitler888.com http://wap.hskyr888.com http://3g.flshello888.com http://3g.hwarr888.com http://www.gwalkl888.com http://www.gwvacationl888.gold