summaryrefslogtreecommitdiff
path: root/netifd/files/etc/hotplug.d/net/20-smp-tune
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2020-05-28 11:29:34 +0200
committerKarel Kočí <cynerd@email.cz>2020-05-28 11:29:34 +0200
commitc606e009f2639c6b0518c9ad2bdf2b77c35ca6e5 (patch)
tree23efbf3e0456a78bb4a820037789477b8ab8881d /netifd/files/etc/hotplug.d/net/20-smp-tune
parent68bf801ffbda2868703db98cfb2625232da9535c (diff)
downloadopenwrt-personal-pkgs-c606e009f2639c6b0518c9ad2bdf2b77c35ca6e5.tar.gz
openwrt-personal-pkgs-c606e009f2639c6b0518c9ad2bdf2b77c35ca6e5.tar.bz2
openwrt-personal-pkgs-c606e009f2639c6b0518c9ad2bdf2b77c35ca6e5.zip
Add netifd with patch to fix service restart
Diffstat (limited to 'netifd/files/etc/hotplug.d/net/20-smp-tune')
-rw-r--r--netifd/files/etc/hotplug.d/net/20-smp-tune67
1 files changed, 67 insertions, 0 deletions
diff --git a/netifd/files/etc/hotplug.d/net/20-smp-tune b/netifd/files/etc/hotplug.d/net/20-smp-tune
new file mode 100644
index 0000000..ab9a904
--- /dev/null
+++ b/netifd/files/etc/hotplug.d/net/20-smp-tune
@@ -0,0 +1,67 @@
+#!/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"
+}
+
+default_ps="$(uci get "network.@globals[0].default_ps")"
+[ -n "$default_ps" -a "$default_ps" != 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/rx-*; do
+ set_hex_val "$q/rps_cpus" "$(($PROC_MASK & ~$irq_cpu_mask))"
+ done
+
+ ntxq="$(ls -d ${dev}/queues/tx-* | wc -l)"
+
+ idx=$(($irq_cpu + 1))
+ for q in ${dev}/queues/tx-*; do
+ set_hex_val "$q/xps_cpus" "$((1 << $idx))"
+ let "idx = idx + 1"
+ [ "$idx" -ge "$NPROCS" ] && idx=0
+ done
+done