mirror of
https://github.com/breeze303/nss-packages.git
synced 2025-12-16 16:57:29 +00:00
1.) Rather than modify upstream `smp_affinity` script, move changes into
this init script.
Primarily: "xhci-hcd:usb1", "ppdu-end-interrupts-mac1", "ppdu-end-interrupts-mac2"
2.) Move logging into separate function, and better account for NSS core
specific output.
3.) Set the defaults for `enable_rps` and `enable_log` to true ('1').
4.) Change startup to sequence to `94` [after `smp_affinity` (93)]
Signed-off-by: Qosmio <datapronix@protonmail.com>
148 lines
4.5 KiB
Bash
148 lines
4.5 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
# vim: set syn=bash
|
|
# shellcheck disable=2155,3010,3019,3043,3057,3060
|
|
# Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
|
|
#
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# copyright notice and this permission notice appear in all copies.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
######################################################################
|
|
|
|
START=94
|
|
PROG="qca-nss-drv"
|
|
|
|
log_msg() {
|
|
|
|
local irq_name="$1" affinity="$2" occurrence="$3" irq="$4"
|
|
|
|
msg="$(printf "Pinning IRQ($irq) %-24s to CPU ${affinity}\n" "$irq_name")"
|
|
|
|
[[ $irq_name =~ "nss" ]] && msg="$msg (NSS Core $((occurrence - 1)))"
|
|
|
|
logger -t "$PROG" "$msg"
|
|
}
|
|
|
|
######################################################################
|
|
### Takes a comma, space separated, or range list of CPU numbers and
|
|
## returns a bitmask of CPUs.
|
|
## cpus_to_bitmask "0,1,2,3" -> f
|
|
## cpus_to_bitmask "0 1 2 3" -> f
|
|
## cpus_to_bitmask "0-3" -> f
|
|
## cpus_to_bitmask "3" -> 8
|
|
#######################################################################
|
|
|
|
cpus_to_bitmask() {
|
|
|
|
local bitmask=0
|
|
# shellcheck disable=2048
|
|
for range in ${*//,/ }; do
|
|
start="${range%-*}"
|
|
end="${range#*-}"
|
|
if [ -z "$end" ]; then
|
|
bitmask="$((bitmask | 1 << start))"
|
|
else
|
|
bitmask="$((bitmask | (2 ** (end - start + 1) - 1) << start))"
|
|
fi
|
|
done
|
|
printf '%x' $bitmask
|
|
}
|
|
|
|
######################################################################
|
|
### Takes a bitmask of CPUs and returns a space separated list of
|
|
## CPU numbers.
|
|
## bitmask_to_cpus f -> 0 1 2 3
|
|
######################################################################
|
|
|
|
bitmask_to_cpus() {
|
|
|
|
[ "${1:0:2}" != "0x" ] && set -- "0x$1"
|
|
local bitmask="$(printf '%d' "$1")"
|
|
|
|
local cpus=""
|
|
for i in $(seq 0 63); do
|
|
if [ $((bitmask & 1)) -ne 0 ]; then
|
|
cpus="$cpus $i"
|
|
fi
|
|
bitmask=$((bitmask >> 1))
|
|
done
|
|
echo "${cpus# }"
|
|
}
|
|
|
|
######################################################################
|
|
### Sets the affinity of the IRQs with the given name to the given CPU.
|
|
## first argument: IRQ name ("nss_queue0")
|
|
## second argument: CPU number
|
|
## third argument: occurrence of the IRQ name
|
|
## since NSS core 0/1 share the same IRQ names
|
|
## set_affinity "nss_queue0" 1 1
|
|
|
|
set_affinity() {
|
|
|
|
local irq_name="$1" affinity="$2" occurrence="${3:-1}" bitmask
|
|
|
|
awk -v irq_name="$irq_name" -v occurrence="$occurrence" '
|
|
BEGIN{count=0}
|
|
$NF==irq_name {
|
|
if(++count==occurrence){
|
|
sub(/:$/,"",$1)
|
|
print $1
|
|
}
|
|
}' /proc/interrupts | while read -r irq; do
|
|
$enable_log && {
|
|
log_msg "$irq_name" "$affinity" "$occurrence" "$irq"
|
|
}
|
|
bitmask=$(cpus_to_bitmask "$affinity") && echo "$bitmask" > /proc/irq/"$irq"/smp_affinity
|
|
done
|
|
}
|
|
|
|
enable_rps() {
|
|
|
|
# NSS Core 0 : 4 nss queues to each core
|
|
set_affinity "nss_queue0" 1 1
|
|
set_affinity "nss_queue1" 2 1
|
|
set_affinity "nss_queue2" 3 1
|
|
set_affinity "nss_queue3" 0 1
|
|
|
|
# NSS Core 1 : 1 nss queue to 3rd core
|
|
set_affinity "nss_queue0" 2 2
|
|
|
|
# NSS Core 0 : 2 nss sos/queues to last core
|
|
set_affinity "nss_empty_buf_sos" 3 1
|
|
set_affinity "nss_empty_buf_queue" 3 1
|
|
|
|
# NSS Core 1 : 1 nss sos to last core
|
|
set_affinity "nss_empty_buf_sos" 2 2
|
|
|
|
# USB 3.0 : pin to 3rd core
|
|
set_affinity "xhci-hcd:usb1" 2 1
|
|
|
|
# TCL Completion, REO Dest, ERR, Exception and h2rxdma
|
|
# are offloaded, so balance remaining IRQs accordingly.
|
|
# PPDU IRQ : pin to 2nd and 3rd core
|
|
set_affinity 'ppdu-end-interrupts-mac1' 1 1
|
|
set_affinity 'ppdu-end-interrupts-mac3' 2 1
|
|
|
|
# Enable NSS RPS
|
|
sysctl -w dev.nss.rps.enable=1 > /dev/null 2> /dev/null
|
|
}
|
|
|
|
start() {
|
|
|
|
local enable_rps
|
|
|
|
config_load nss
|
|
config_get enable_rps "general" enable_rps 1
|
|
config_get_bool enable_log "general" enable_log 1
|
|
|
|
[ "$enable_log" -eq 1 ] && enable_log=true || enable_log=false
|
|
[ "$enable_rps" -eq 1 ] && enable_rps
|
|
}
|