Skip to content

Commit

Permalink
netifd: update packet-steering.sh
Browse files Browse the repository at this point in the history
update the packet-steering script fixing all warnings and recommendations
detected by shellcheck

Signed-off-by: Andrew Sim <[email protected]>
  • Loading branch information
Gingernut1978 committed Oct 21, 2023
1 parent bb8fd41 commit 916ab92
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/bin/sh

NPROCS="$(grep -c "^processor.*:" /proc/cpuinfo)"
[ "$NPROCS" -gt 1 ] || exit

PROC_MASK="$(( (1 << $NPROCS) - 1 ))"
PROC_MASK="$(( (1 << NPROCS) - 1 ))"

find_irq_cpu() {
local dev="$1"
local match="$(grep -m 1 "$dev\$" /proc/interrupts)"
local cpu=0
dev="$1"
match="$(grep -m 1 "$dev\$" /proc/interrupts)"
cpu=0

[ -n "$match" ] && {
set -- $match
set -- "$match"
shift
for cur in $(seq 1 $NPROCS); do
for cur in $(seq 1 NPROCS); do
[ "$1" -gt 0 ] && {
cpu=$(($cur - 1))
cpu=$((cur - 1))
break
}
shift
Expand All @@ -25,46 +26,50 @@ find_irq_cpu() {
}

set_hex_val() {
local file="$1"
local val="$2"
file="$1"
val="$2"
val="$(printf %x "$val")"
[ -n "$DEBUG" ] && echo "$file = $val"
[ -n "$DEBUG" ] && echo "$file = $val"
echo "$val" > "$file"
}

packet_steering="$(uci get "network.@globals[0].packet_steering")"
[ "$packet_steering" != 1 ] && exit 0

exec 512>/var/lock/smp_tune.lock
flock 512 || exit 1
exec 9>/var/lock/smp_tune.lock
flock 9 || exit 1

[ -e "/usr/libexec/platform/packet-steering.sh" ] && {
/usr/libexec/platform/packet-steering.sh
[ -e "/usr/libexec/platform/packet-steering.sh" ] && {
/usr/libexec/platform/packet-steering.sh
exit 0
}

for dev in /sys/class/net/*; do
[ -d "$dev" ] || continue
for dev in /sys/class/net/*; do
[ -d "$dev" ] || continue

# ignore virtual interfaces
[ -n "$(ls "${dev}/" | grep '^lower_')" ] && continue
# ignore virtual interfaces
for file in "${dev}"/lower_*; do
if [ -e "$file" ]; then continue
fi
done

[ -d "${dev}/device" ] || continue

device="$(readlink "${dev}/device")"
device="$(basename "$device")"
irq_cpu="$(find_irq_cpu "$device")"
irq_cpu_mask="$((1 << $irq_cpu))"
irq_cpu="$((1 << irq_cpu))"

for q in ${dev}/queues/tx-*; do
for q in "${dev}"/queues/tx-*; do
set_hex_val "$q/xps_cpus" "$PROC_MASK"
done

# ignore dsa slave ports for RPS
# ignore dsa slave ports for RPS
subsys="$(readlink "${dev}/device/subsystem")"
subsys="$(basename "$subsys")"
[ "$subsys" = "mdio_bus" ] && continue
[ "$subsys" = "mdio_bus" ] && continue

for q in ${dev}/queues/rx-*; do
for q in "${dev}"/queues/rx-*; do
set_hex_val "$q/rps_cpus" "$PROC_MASK"
done
done

0 comments on commit 916ab92

Please sign in to comment.