mirror of
https://github.com/breeze303/openwrt-ipq.git
synced 2025-12-17 10:41:06 +00:00
ath11k_nss: optimize qca-nss-pbuf init script
New:
* Add UCI option to /etc/config/pbuf
1. `stats_disable` - Allows disabling extended stats
collection. (Default: '1')
2. `scaling_governor` - Allow specifying CPU governor.
(Default: disabled )
Choices depend on what your system is compiled with. Can be found
using:
```sh
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
ondemand performance schedutil
```
Changes:
* Rather than hardcode every device model's memory profile. Simply read the
memory available from `/proc/meminfo`.
* Scaling governor is no longer forced as `performance`. It is now user
configurable.
* Hash bitmap is now calculated from number of CPUs rather than hardcoded to `15`
* Limit `n2h_queue_limit_core` to `256`. This was set to `2048` which is
too high when NSS wifi is also enabled.
Signed-off-by: Sean Khan <datapronix@protonmail.com>
This commit is contained in:
parent
6ec201e486
commit
6ec6ed6699
@ -5,3 +5,4 @@ config general opt
|
|||||||
# option memory_profile '1gb'
|
# option memory_profile '1gb'
|
||||||
# option memory_profile '512mb'
|
# option memory_profile '512mb'
|
||||||
# option memory_profile '256mb'
|
# option memory_profile '256mb'
|
||||||
|
option scaling_governor 'performance'
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# shellcheck disable=3043
|
# shellcheck disable=3043,3010
|
||||||
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||||
# Permission to use, copy, modify, and/or distribute this software for any
|
# Permission to use, copy, modify, and/or distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
@ -15,6 +15,12 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
START=71
|
START=71
|
||||||
|
NAME=qca-nss-pbuf
|
||||||
|
|
||||||
|
get_num_cpus() {
|
||||||
|
local num_cpus=$(awk -F': ' '/^processor/ {count++} END {print count}' /proc/cpuinfo)
|
||||||
|
echo ${num_cpus:-1}
|
||||||
|
}
|
||||||
|
|
||||||
apply_sysctl() {
|
apply_sysctl() {
|
||||||
[ "$(sysctl -n -e dev.nss.general.redirect)" -eq 0 ] && /etc/init.d/qca-nss-ecm start
|
[ "$(sysctl -n -e dev.nss.general.redirect)" -eq 0 ] && /etc/init.d/qca-nss-ecm start
|
||||||
@ -22,71 +28,74 @@ apply_sysctl() {
|
|||||||
# Running this script multiple times is useless, as extra_pbuf_core0
|
# Running this script multiple times is useless, as extra_pbuf_core0
|
||||||
# can't be changed if it is allocated, assume it's already been run.
|
# can't be changed if it is allocated, assume it's already been run.
|
||||||
if [ "$(sysctl -n -e dev.nss.n2hcfg.extra_pbuf_core0)" -eq 0 ]; then
|
if [ "$(sysctl -n -e dev.nss.n2hcfg.extra_pbuf_core0)" -eq 0 ]; then
|
||||||
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.extra_pbuf_core0=$extra_pbuf_core0"
|
logger -t $NAME "$board - setting dev.nss.n2hcfg.extra_pbuf_core0=$extra_pbuf_core0"
|
||||||
sysctl -w dev.nss.n2hcfg.extra_pbuf_core0="$extra_pbuf_core0" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.extra_pbuf_core0="$extra_pbuf_core0" > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
logger -t ath11k_nss "Sysctl key 'extra_pbuf_core0' already set to '""$extra_pbuf_core0""'. Skipping applying wifi nss configs"
|
logger -t $NAME "Sysctl key 'extra_pbuf_core0' already set to '""$extra_pbuf_core0""'. Skipping applying wifi nss configs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0" > /dev/null 2>&1
|
||||||
|
|
||||||
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.n2h_wifi_pool_buf=$n2h_wifi_pool_buf"
|
logger -t $NAME "$board - setting dev.nss.n2hcfg.n2h_wifi_pool_buf=$n2h_wifi_pool_buf"
|
||||||
sysctl -w dev.nss.n2hcfg.n2h_wifi_pool_buf="$n2h_wifi_pool_buf" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.n2h_wifi_pool_buf="$n2h_wifi_pool_buf" > /dev/null 2>&1
|
||||||
|
|
||||||
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.n2h_high_water_core0=$n2h_high_water_core0"
|
logger -t $NAME "$board - setting dev.nss.n2hcfg.n2h_high_water_core0=$n2h_high_water_core0"
|
||||||
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0" > /dev/null 2>&1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_nss_config() {
|
apply_nss_config() {
|
||||||
local auto_scale n2h_queue_limit_core0 n2h_queue_limit_core1
|
local auto_scale n2h_queue_limit_core0 n2h_queue_limit_core1 num_cpus
|
||||||
|
local hash_bitmap
|
||||||
|
|
||||||
if [ ! -r /sys/module/ath11k/parameters/nss_offload ]; then
|
if [ ! -r /sys/module/ath11k/parameters/nss_offload ]; then
|
||||||
logger -t ath11k_nss "Module parameter '/sys/module/ath11k/parameters/nss_offload' does NOT exist. Skipping applying wifi nss configs"
|
logger -t $NAME "Module parameter '/sys/module/ath11k/parameters/nss_offload' does NOT exist. Skipping applying wifi nss configs"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
enable_nss_offload=$(cat /sys/module/ath11k/parameters/nss_offload)
|
enable_nss_offload=$(cat /sys/module/ath11k/parameters/nss_offload)
|
||||||
|
|
||||||
if [ "$enable_nss_offload" -ne "1" ]; then
|
if [ "$enable_nss_offload" -ne "1" ]; then
|
||||||
logger -t ath11k_nss -s user.warn "Module parameter 'nss_offload=0'. Skipping applying wifi nss configs"
|
logger -t $NAME -s user.warn "Module parameter 'nss_offload=0'. Skipping applying wifi nss configs"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ ! -d "/proc/sys/dev/nss/rps" ] && {
|
[ ! -d "/proc/sys/dev/nss/rps" ] && {
|
||||||
logger -s -t ath11k_nss -p user.error "NSS driver not loaded or disabled! Exiting... "
|
logger -s -t $NAME -p user.error "NSS driver not loaded or disabled! Exiting... "
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
config_load pbuf
|
config_load pbuf
|
||||||
config_get_bool auto_scale opt auto_scale 0
|
config_get_bool auto_scale opt auto_scale 0
|
||||||
config_get n2h_queue_limit_core0 opt n2h_queue_limit_core0 2048
|
config_get n2h_queue_limit_core0 opt n2h_queue_limit_core0 256
|
||||||
config_get n2h_queue_limit_core1 opt n2h_queue_limit_core1 2048
|
config_get n2h_queue_limit_core1 opt n2h_queue_limit_core1 256
|
||||||
|
|
||||||
sysctl -w dev.nss.clock.auto_scale="$auto_scale" > /dev/null 2>&1
|
sysctl -w dev.nss.clock.auto_scale="$auto_scale" > /dev/null 2>&1
|
||||||
|
|
||||||
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core0="$n2h_queue_limit_core0" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core0="$n2h_queue_limit_core0" > /dev/null 2>&1
|
||||||
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core1="$n2h_queue_limit_core1" > /dev/null 2>&1
|
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core1="$n2h_queue_limit_core1" > /dev/null 2>&1
|
||||||
|
|
||||||
sysctl -w dev.nss.rps.hash_bitmap=15 > /dev/null 2>&1
|
local memory_profile memtotal board
|
||||||
|
board=$(board_name)
|
||||||
|
|
||||||
local memory_profile
|
|
||||||
if memory_profile=$(uci_get pbuf.opt.memory_profile); then
|
if memory_profile=$(uci_get pbuf.opt.memory_profile); then
|
||||||
case "$memory_profile" in
|
case "$memory_profile" in
|
||||||
1g*|512m*|256m*)
|
1024 | 1g* | 512 | 512m* | 256 | 256m*)
|
||||||
board=$memory_profile
|
logger -t $NAME "Using custom memory profile - $board"
|
||||||
logger -t ath11k_nss "Using custom memory profile - $board"
|
|
||||||
;;
|
;;
|
||||||
off*|false*|disable*|0)
|
off* | false* | disable* | 0)
|
||||||
logger -s -t ath11k_nss -p user.warn "NSS pbuf option 'memory_profile=off'. Not running. Enable if you have issues connecting more than 65 clients"
|
logger -s -t $NAME -p user.warn "NSS pbuf option 'memory_profile=off'. Not running. Enable if you have issues connecting more than 65 clients"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
auto)
|
auto)
|
||||||
board=$(board_name)
|
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
|
||||||
logger -t ath11k_nss "Setting n2hcfg values for board: $board"
|
[ "$memtotal" -gt 512000 ] && memory_profile=1024
|
||||||
|
[ "$memtotal" -le 512000 ] && memory_profile=512
|
||||||
|
[ "$memtotal" -le 256000 ] && memory_profile=256
|
||||||
|
logger -t $NAME "Setting n2hcfg values for board: $board"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
logger -s -t ath11k_nss -p user.error "Unknown profile $memory_profile. Choose auto, 1gb, 512mb, or 256mb"
|
logger -s -t $NAME -p user.error "Unknown profile $memory_profile. Choose auto, 1gb, 512mb, or 256mb"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -94,62 +103,71 @@ apply_nss_config() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$board" in
|
case "$memory_profile" in
|
||||||
# 1GB+ profile
|
# 1GB+ profile
|
||||||
arcadyan,aw1000 | \
|
1024 | 1g*)
|
||||||
buffalo,wxr-5950ax12 | \
|
|
||||||
dynalink,dl-wrx36 | \
|
|
||||||
edgecore,eap102 | \
|
|
||||||
linksys,mx4200v2 | \
|
|
||||||
linksys,mx5300 | \
|
|
||||||
netgear,rax120v2 | \
|
|
||||||
netgear,wax620 | \
|
|
||||||
netgear,wax630 | \
|
|
||||||
prpl,haze | \
|
|
||||||
qnap,301w | \
|
|
||||||
xiaomi,ax9000 | \
|
|
||||||
yuncore,ax880 | \
|
|
||||||
zyxel,nbg7815 | \
|
|
||||||
1g*)
|
|
||||||
extra_pbuf_core0=10000000 n2h_high_water_core0=72512 n2h_wifi_pool_buf=36864 apply_sysctl
|
extra_pbuf_core0=10000000 n2h_high_water_core0=72512 n2h_wifi_pool_buf=36864 apply_sysctl
|
||||||
;;
|
;;
|
||||||
# 512MB profile
|
# 512MB profile
|
||||||
edimax,cax1800 | \
|
512 | 512m*)
|
||||||
compex,wpq873 | \
|
|
||||||
linksys,mx4200v1 | \
|
|
||||||
redmi,ax6 | \
|
|
||||||
xiaomi,ax3600 | \
|
|
||||||
zte,mf269 | \
|
|
||||||
512m*)
|
|
||||||
extra_pbuf_core0=3100000 n2h_high_water_core0=30624 n2h_wifi_pool_buf=8192 apply_sysctl
|
extra_pbuf_core0=3100000 n2h_high_water_core0=30624 n2h_wifi_pool_buf=8192 apply_sysctl
|
||||||
;;
|
;;
|
||||||
# 256MB profile
|
# 256MB profile
|
||||||
netgear,wax218 | \
|
256 | 256m*)
|
||||||
256m*)
|
|
||||||
extra_pbuf_core0=3100000 n2h_high_water_core0=30258 n2h_wifi_pool_buf=4096 apply_sysctl
|
extra_pbuf_core0=3100000 n2h_high_water_core0=30258 n2h_wifi_pool_buf=4096 apply_sysctl
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
boost_performance() {
|
set_stats_disable() {
|
||||||
|
|
||||||
find /sys/kernel/debug/ath11k -name stats_disable| while read -r stats_disable; do
|
local stats_disable
|
||||||
echo 1 > "$stats_disable"
|
config_load pbuf
|
||||||
|
config_get stats_disable opt stats_disable 1
|
||||||
|
|
||||||
|
find /sys/kernel/debug/ath11k -name stats_disable | while read -r stats_file; do
|
||||||
|
stats_msg_prefix="Disabling"
|
||||||
|
[ "$stats_disable" -eq 0 ] && stats_msg_prefix="Enabling"
|
||||||
|
logger -t $NAME -p user.notice "$stats_msg_prefix ath11k stats"
|
||||||
|
echo "$stats_disable" > "$stats_file"
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
ubus call iwinfo devices | jsonfilter -e "@.devices[*]"| while read -r device; do
|
set_scaling_governor() {
|
||||||
tc qdisc replace dev "${device}" root noqueue
|
|
||||||
|
local scaling_governor num_cpus
|
||||||
|
config_load pbuf
|
||||||
|
config_get scaling_governor opt scaling_governor
|
||||||
|
|
||||||
|
scaling_available_governors=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
|
||||||
|
|
||||||
|
if [ -r "$scaling_available_governors" ]; then
|
||||||
|
scaling_available_governors=$(cat $scaling_available_governors)
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$scaling_available_governors" ] && [ -n "$scaling_governor" ]; then
|
||||||
|
if [[ "$scaling_available_governors" =~ $scaling_governor ]]; then
|
||||||
|
logger -t $NAME -p user.notice "Setting CPU scaling governor to '$scaling_governor'"
|
||||||
|
num_cpus=$(get_num_cpus)
|
||||||
|
for num in $(seq 0 $((num_cpus - 1))); do
|
||||||
|
echo "$scaling_governor" > "/sys/devices/system/cpu/cpu${num}/cpufreq/scaling_governor"
|
||||||
done
|
done
|
||||||
|
else
|
||||||
for num in 0 1 2 3; do
|
logger -t $NAME -p user.error "'$scaling_governor' not available in CPU governors [ $scaling_available_governors ]"
|
||||||
echo "performance" > /sys/devices/system/cpu/cpu${num}/cpufreq/scaling_governor
|
fi
|
||||||
done
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|
||||||
boost_performance
|
set_scaling_governor
|
||||||
|
set_stats_disable
|
||||||
apply_nss_config
|
apply_nss_config
|
||||||
|
|
||||||
|
num_cpus=$(get_num_cpus)
|
||||||
|
hash_bitmap="$(((1 << num_cpus) - 1))"
|
||||||
|
sysctl -w dev.nss.rps.hash_bitmap=$hash_bitmap > /dev/null 2>&1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user