Helpful scripts for smp affinities, feedback welcome

List Process Affinities:

#!/bin/sh

# Get the list of network devices
network_devices=$(ls /sys/class/net)

# Iterate over each network device
for device in $network_devices; do
  echo "Network Device: $device"
  
  # Check if the device is virtual
  if ethtool -S "$device" &> /dev/null; then
    echo "  Device Type: Physical"
    
    # Get the IRQs assigned to the physical device
    irq_list=$(cat "/proc/interrupts" | awk -v dev="$device" '$0 ~ dev {gsub(/:/,"",$1); print $1}')
    
    # Iterate over each IRQ and display its core affinity
    for irq in $irq_list; do
      affinity=$(cat "/proc/irq/$irq/smp_affinity")
      echo "    IRQ $irq: Core Affinity = $affinity"
    done
  else
    echo "  Device Type: Virtual"
  fi
  
  echo
done

Pin the affinities to cores & xps

#!/bin/sh
[ "$ACTION" = add ] || exit

# This section is setup to be easier to configure instead of hexadecimal.
for IRQ in 132 133 134 135 137 138 139 140; do
    case $IRQ in
        132) CORE=0 ;;
        133) CORE=1 ;;
        134) CORE=2 ;;
        135) CORE=3 ;;
        137) CORE=0 ;;
        138) CORE=1 ;;
        139) CORE=2 ;;
        140) CORE=3 ;;
        *) continue ;;
    esac
    
    # Converts above binary to hexadecimal and also visually keeps them separated for reference. 
    AFFINITY=$(printf "%X" $((1 << $CORE)))
    echo $AFFINITY > "/proc/irq/$IRQ/smp_affinity"
    echo "IRQ $IRQ - SMP Affinity: $AFFINITY"

   # Toggle to match or not to the above cores
    case $CORE in
        0) XPS_CPUS=1 ;;
        1) XPS_CPUS=2 ;;
        2) XPS_CPUS=4 ;;
        3) XPS_CPUS=8 ;;
    esac

    echo $XPS_CPUS > "/sys/class/net/eth0/queues/tx-$((IRQ - 132))/xps_cpus"
    echo "IRQ $IRQ - XPS CPUs (eth0): $XPS_CPUS"

    echo $XPS_CPUS > "/sys/class/net/eth1/queues/tx-$((IRQ - 132))/xps_cpus"
    echo "IRQ $IRQ - XPS CPUs (eth1): $XPS_CPUS"
done