FDD-book/examples/part-04/ch20-advanced-interrupts/labs/show_vector_bindings.sh
Edson Brandi 6e6dac94fe Add book companion files under examples/
Organize companion code and materials by book part:

  part-01/      Foundations
  part-02/      Kernel & driver fundamentals
  part-03/      Character & block devices
  part-04/      Networking & storage
  part-05/      Buses & advanced topics
  part-06/      Debugging & performance
  part-07/      Real-world drivers
  appendices/   Supplementary material
  README.md     Overview and build instructions
2026-04-25 16:51:00 +00:00

42 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
#
# show_vector_bindings.sh -- show each myfirst vector's IRQ number,
# descriptor, CPU binding, and fire count.
#
# Requires the myfirst driver to be loaded.
set -eu
UNIT="${1:-0}"
if ! sysctl -n "dev.myfirst.${UNIT}.intr_mode" >/dev/null 2>&1; then
echo "myfirst${UNIT} is not loaded or not attached" >&2
exit 1
fi
mode=$(sysctl -n "dev.myfirst.${UNIT}.intr_mode")
case "$mode" in
0) mode_str="legacy INTx" ;;
1) mode_str="MSI" ;;
2) mode_str="MSI-X" ;;
esac
echo "myfirst${UNIT} interrupt mode: $mode_str"
printf '%-25s %-10s %-15s %-10s\n' \
"name" "irq" "cpu mask" "fires"
vmstat -i | awk -v unit="$UNIT" '
/myfirst/ && $0 ~ "myfirst" unit {
# vmstat -i format: "irqN: name total rate"
# Parse the irq number and the handler name.
split($0, fields, /[[:space:]]+/)
irq = fields[1]
gsub(":", "", irq)
sub(/^irq/, "", irq)
name = fields[2]
total = fields[3]
print irq "|" name "|" total
}' | while IFS='|' read irq name total; do
mask=$(cpuset -g -x "$irq" 2>/dev/null | awk '{print $NF}')
printf '%-25s %-10s %-15s %-10s\n' "$name" "$irq" "$mask" "$total"
done