Skip to content

Instantly share code, notes, and snippets.

@bachmanity1
Created July 23, 2026 07:34
Show Gist options
  • Select an option

  • Save bachmanity1/bda67c09653105e179f8dc92a8d7d9e8 to your computer and use it in GitHub Desktop.

Select an option

Save bachmanity1/bda67c09653105e179f8dc92a8d7d9e8 to your computer and use it in GitHub Desktop.
Read-only: print host IRQ/workqueue/RPS CPU masks compactly (changes nothing)
#!/bin/bash
# Read-only: print current host IRQ / workqueue / RPS CPU masks compactly.
# Changes NOTHING. No arguments, no root strictly required (some files may be
# unreadable without it, shown as '?').
set -uo pipefail
log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $*"; }
compact() {
# reads mask values on stdin, prints "value (xN)" groups on one line
sort | uniq -c | awk '{printf "%s%s (x%s)", (NR>1?", ":""), $2, $1} END{print ""}'
}
log "online CPUs: $(cat /sys/devices/system/cpu/online 2>/dev/null || echo '?')"
log "Current masks (read-only):"
printf ' IRQ default : %s\n' "$(cat /proc/irq/default_smp_affinity 2>/dev/null || echo '?')"
printf ' IRQ per-irq : %s\n' "$(cat /proc/irq/[0-9]*/smp_affinity 2>/dev/null | compact)"
printf ' workqueue : %s\n' "$(cat /sys/devices/virtual/workqueue/cpumask 2>/dev/null || echo 'n/a')"
printf ' wq per-wq : %s\n' "$(cat /sys/devices/virtual/workqueue/*/cpumask 2>/dev/null | compact)"
rps_now=""
for path in /sys/class/net/*; do
[ -L "$path" ] || continue
case "$(readlink "$path")" in *virtual*) continue ;; esac
rps_now+=$(cat "$path"/queues/rx-*/rps_cpus 2>/dev/null; echo)
done
printf ' RPS : %s\n' "$(printf '%s' "$rps_now" | grep -v '^$' | compact)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment