Although this is for my Flint2, it can be a good starting point.
logread -e smp_setup
#!/bin/sh
# OpenWrt SMP and AQL optimization script
# Logging function
log() {
# Default to user.notice if no priority specified
[ -z "$1" ] && priority="user.notice" || priority="$1"
[ -z "$2" ] && message="No message provided" || message="$2"
# Use standard OpenWrt logging
logger -p "$priority" -t "smp_setup" "$message"
}
# Test logging system
test_logging() {
if ! pidof logd >/dev/null; then
echo "Error: logd not running"
exit 1
fi
log "daemon.info" "SMP setup logging initialized"
return 0
}
# Configure AQL parameters
configure_aql() {
log "daemon.notice" "Starting AQL configuration"
find /sys/kernel/debug/ieee80211 -name 'phy[0-9]*' | while read -r phypath; do
log "daemon.info" "Configuring wireless device: $phypath"
for queue in 0 1 2 3; do
if ! echo "$queue 1500 5000" > "$phypath/aql_txq_limit"; then
log "daemon.err" "AQL: Failed setting queue $queue limits on $phypath"
continue 2
fi
done
if ! echo "12000" > "$phypath/aql_threshold"; then
log "daemon.err" "AQL: Failed setting threshold on $phypath"
continue
fi
log "daemon.info" "AQL: Successfully configured $phypath"
done
log "daemon.notice" "AQL configuration completed"
}
# Get number of CPUs
get_cpu_count() {
grep -c ^processor /proc/cpuinfo
}
# Optimize SMP settings
optimize_smp() {
cpu_count=$(get_cpu_count)
log "daemon.notice" "Starting SMP optimization for $cpu_count cores"
# Calculate CPU masks for 4-core system
eth_mask="3" # Cores 0,1
wifi_mask="c" # Cores 2,3
# Configure network interfaces
for iface in /sys/class/net/*; do
case "$iface" in
*virtual*) continue ;;
esac
if [ -e "$iface/queues/rx-0/rps_cpus" ]; then
iface_name="${iface##*/}"
case "$iface_name" in
eth*|lan*)
if ! echo "$eth_mask" > "$iface/queues/rx-0/rps_cpus"; then
log "daemon.err" "SMP: RPS configuration failed for $iface_name"
else
log "daemon.info" "SMP: Set RPS affinity $eth_mask for $iface_name"
fi
;;
phy*)
if ! echo "$wifi_mask" > "$iface/queues/rx-0/rps_cpus"; then
log "daemon.err" "SMP: RPS configuration failed for $iface_name"
else
log "daemon.info" "SMP: Set RPS affinity $wifi_mask for $iface_name"
fi
;;
esac
fi
done
# Configure IRQ affinity
irq_map="130:$eth_mask 131:$eth_mask 133:$wifi_mask"
for irq_set in $irq_map; do
irq="${irq_set%:*}"
aff="${irq_set#*:}"
if [ -d "/proc/irq/$irq" ]; then
if ! echo "$aff" > "/proc/irq/$irq/smp_affinity"; then
log "daemon.err" "SMP: Failed setting IRQ affinity for irq $irq"
else
log "daemon.info" "SMP: Set IRQ $irq affinity to $aff"
fi
fi
done
# Configure NAPI thread affinity
for pid in $(pgrep -f 'napi/mtk_eth'); do
if ! taskset -p "$eth_mask" "$pid" >/dev/null 2>&1; then
log "daemon.err" "SMP: Failed setting Ethernet NAPI affinity for pid $pid"
else
log "daemon.info" "SMP: Set Ethernet NAPI affinity $eth_mask for pid $pid"
fi
done
for pid in $(pgrep -f 'napi/phy0-'); do
if ! taskset -p "$wifi_mask" "$pid" >/dev/null 2>&1; then
log "daemon.err" "SMP: Failed setting WiFi NAPI affinity for pid $pid"
else
log "daemon.info" "SMP: Set WiFi NAPI affinity $wifi_mask for pid $pid"
fi
done
log "daemon.notice" "SMP optimization completed"
}
# Main function
main() {
# Verify logging is working
test_logging || exit 1
log "daemon.notice" "Starting system optimization"
# Allow system to settle
sleep 10
# Run configurations
configure_aql
optimize_smp
log "daemon.notice" "System optimization completed"
}
# Entry point
main
exit 0