netifd: refactor packet steering init
authorRafał Miłecki <rafal@milecki.pl>
Mon, 13 Feb 2023 08:23:39 +0000 (09:23 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Wed, 15 Feb 2023 13:25:38 +0000 (14:25 +0100)
1. Move setup code to independent script file
2. Add init.d script to allow automatic updates
3. Support platform specific /usr/libexec/platform/packet-steering.sh

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
package/network/config/netifd/Makefile
package/network/config/netifd/files/etc/hotplug.d/net/20-smp-packet-steering [deleted file]
package/network/config/netifd/files/etc/init.d/packet_steering [new file with mode: 0755]
package/network/config/netifd/files/usr/libexec/network/packet-steering.sh [new file with mode: 0755]

index 500daaa152262f1f979ef3910f316eb46355ba89..f40a990b42d5d798b9647fa6a0b8bd59f73b964a 100644 (file)
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=netifd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git
diff --git a/package/network/config/netifd/files/etc/hotplug.d/net/20-smp-packet-steering b/package/network/config/netifd/files/etc/hotplug.d/net/20-smp-packet-steering
deleted file mode 100644 (file)
index 8a86bf7..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-[ "$ACTION" = add ] || exit
-
-NPROCS="$(grep -c "^processor.*:" /proc/cpuinfo)"
-[ "$NPROCS" -gt 1 ] || exit
-
-PROC_MASK="$(( (1 << $NPROCS) - 1 ))"
-
-find_irq_cpu() {
-       local dev="$1"
-       local match="$(grep -m 1 "$dev\$" /proc/interrupts)"
-       local cpu=0
-
-       [ -n "$match" ] && {
-               set -- $match
-               shift
-               for cur in $(seq 1 $NPROCS); do
-                       [ "$1" -gt 0 ] && {
-                               cpu=$(($cur - 1))
-                               break
-                       }
-                       shift
-               done
-       }
-
-       echo "$cpu"
-}
-
-set_hex_val() {
-       local file="$1"
-       local val="$2"
-       val="$(printf %x "$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
-
-for dev in /sys/class/net/*; do
-       [ -d "$dev" ] || continue
-
-       # ignore virtual interfaces
-       [ -n "$(ls "${dev}/" | grep '^lower_')" ] && continue
-       [ -d "${dev}/device" ] || continue
-
-       device="$(readlink "${dev}/device")"
-       device="$(basename "$device")"
-       irq_cpu="$(find_irq_cpu "$device")"
-       irq_cpu_mask="$((1 << $irq_cpu))"
-
-       for q in ${dev}/queues/tx-*; do
-               set_hex_val "$q/xps_cpus" "$PROC_MASK"
-       done
-
-       # ignore dsa slave ports for RPS
-       subsys="$(readlink "${dev}/device/subsystem")"
-       subsys="$(basename "$subsys")"
-       [ "$subsys" = "mdio_bus" ] && continue
-
-       for q in ${dev}/queues/rx-*; do
-               set_hex_val "$q/rps_cpus" "$PROC_MASK"
-       done
-done
diff --git a/package/network/config/netifd/files/etc/init.d/packet_steering b/package/network/config/netifd/files/etc/init.d/packet_steering
new file mode 100755 (executable)
index 0000000..9d8f791
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh /etc/rc.common
+
+START=25
+USE_PROCD=1
+
+start_service() {
+       reload_service
+}
+
+service_triggers() {
+       procd_add_reload_trigger "network"
+       procd_add_reload_trigger "firewall"
+       procd_add_raw_trigger "interface.*" 1000 /etc/init.d/packet_steering reload
+}
+
+reload_service() {
+       /usr/libexec/network/packet-steering.sh
+}
diff --git a/package/network/config/netifd/files/usr/libexec/network/packet-steering.sh b/package/network/config/netifd/files/usr/libexec/network/packet-steering.sh
new file mode 100755 (executable)
index 0000000..799c080
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+NPROCS="$(grep -c "^processor.*:" /proc/cpuinfo)"
+[ "$NPROCS" -gt 1 ] || exit
+
+PROC_MASK="$(( (1 << $NPROCS) - 1 ))"
+
+find_irq_cpu() {
+       local dev="$1"
+       local match="$(grep -m 1 "$dev\$" /proc/interrupts)"
+       local cpu=0
+
+       [ -n "$match" ] && {
+               set -- $match
+               shift
+               for cur in $(seq 1 $NPROCS); do
+                       [ "$1" -gt 0 ] && {
+                               cpu=$(($cur - 1))
+                               break
+                       }
+                       shift
+               done
+       }
+
+       echo "$cpu"
+}
+
+set_hex_val() {
+       local file="$1"
+       local val="$2"
+       val="$(printf %x "$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
+
+[ -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
+
+       # ignore virtual interfaces
+       [ -n "$(ls "${dev}/" | grep '^lower_')" ] && continue
+       [ -d "${dev}/device" ] || continue
+
+       device="$(readlink "${dev}/device")"
+       device="$(basename "$device")"
+       irq_cpu="$(find_irq_cpu "$device")"
+       irq_cpu_mask="$((1 << $irq_cpu))"
+
+       for q in ${dev}/queues/tx-*; do
+               set_hex_val "$q/xps_cpus" "$PROC_MASK"
+       done
+
+       # ignore dsa slave ports for RPS
+       subsys="$(readlink "${dev}/device/subsystem")"
+       subsys="$(basename "$subsys")"
+       [ "$subsys" = "mdio_bus" ] && continue
+
+       for q in ${dev}/queues/rx-*; do
+               set_hex_val "$q/rps_cpus" "$PROC_MASK"
+       done
+done