Permalink
Browse files

misc: Add an example for policy script

Add a do-nothing policy script as an example, pre-implement some basic
logic that could be used for applying affinity_hinting setting strictly
for IRQs of certain drivers.
  • Loading branch information...
ryncsn committed Oct 12, 2018
1 parent 5a1c7b8 commit ac27391efcf9ff78e55db3a53563c13680796c18
Showing with 39 additions and 0 deletions.
  1. +39 −0 misc/irqbalance.policy.d/follow-affinity-hint.example
@@ -0,0 +1,39 @@
#!/bin/sh
# Do not edit this file, create your own policy script and make it
# executable for irqbalance process, you can use this file as an
# boilerplate.
SYS_DEV_PATH=$1
IRQ_NUM=$2
IRQ_PATH=/proc/irq/$IRQ_NUM
UEVENT_FILE=$SYS_DEV_PATH/uevent
# Scripts below is an example for banning certain IRQs from
# irqbalance and strictly apply their affinity_hint setting
[[ ! -e $UEVENT_FILE ]] && exit 1
# IRQs from following drivers will be handled by this script
# Driver names should be separated by space
AFFINITY_WHITELIST=""
while read line; do
if [[ $line == "DRIVER="* ]] && \
[[ " $AFFINITY_WHITELIST " == *" ${line#DRIVER=} "* ]]; then
affinity_hint=$(cat $IRQ_PATH/affinity_hint 2>/dev/null)
# Check if affinity_hint value have at least one bit set
if [[ ! "$affinity_hint" =~ ^[0,]*$ ]]; then
# Ban it from irqbalance so it won't get balanced,
# we'll follow its affinity_hint setting
echo "ban=true"
# If the affinity_hint value is valid, kernel would set
# the same value for smp_affinity. But force to set that
# again in case the IRQ was balanced before.
echo "$affinity_hint" > $IRQ_PATH/smp_affinity
# Stop further script processing
exit 0
fi
fi
done <<< "$(cat $UEVENT_FILE)"
exit 1

0 comments on commit ac27391

Please sign in to comment.