developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | OPTIMIZED_FOR="$1" |
| 4 | CPU_LIST=`cat /proc/interrupts | sed -n '1p'` |
| 5 | NUM_OF_CPU=0; for i in $CPU_LIST; do NUM_OF_CPU=`expr $NUM_OF_CPU + 1`; done; |
| 6 | DEFAULT_RPS=0 |
| 7 | |
| 8 | . /lib/functions.sh |
| 9 | |
| 10 | RPS_IF_LIST="" |
| 11 | NUM_WIFI_CARD=0 |
| 12 | WIFI_RADIO1=0 |
| 13 | WIFI_RADIO2=0 |
| 14 | WIFI_RADIO3=0 |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 15 | WED_ENABLE=0 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 16 | |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 17 | WIFI_MODULE_LIST='mt7915e mt7996e' |
| 18 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 19 | get_if_info() |
| 20 | { |
| 21 | # try to get all wifi and eth net interface. |
| 22 | dbg2 "try to get all wifi and eth net interface." |
| 23 | NET_IF_LIST=`ls /sys/class/net` |
| 24 | for vif in $NET_IF_LIST; |
| 25 | do |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 26 | if [[ "$vif" == "eth"* ]] || \ |
| 27 | [[ "$vif" == "lan"* ]] || [[ "$vif" == "wan"* ]] || \ |
| 28 | [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 29 | RPS_IF_LIST="$RPS_IF_LIST $vif" |
| 30 | fi |
| 31 | done; |
| 32 | dbg2 "RPS_IF_LIST = $RPS_IF_LIST" |
| 33 | |
| 34 | # try to get wifi physical card num. |
| 35 | dbg2 "try to get wifi physical card num." |
| 36 | VIRTUAL_RADIO_LIST=`ls -l /sys/class/ieee80211/ | awk -F 'devices' '{print $2}' | awk -F 'phy' '{print $1}' | uniq` |
| 37 | for v in $VIRTUAL_RADIO_LIST; |
| 38 | do |
| 39 | NUM_WIFI_CARD=`expr $NUM_WIFI_CARD + 1` |
| 40 | dbg2 "physical raido $v" |
| 41 | if [[ $v == *"wmac"* ]]; then |
| 42 | WIFI_RADIO1=1 |
| 43 | fi |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 44 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 45 | if [[ $v == *"wbsys"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 46 | WIFI_RADIO1=1 |
| 47 | fi |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 48 | |
| 49 | if [[ $v == *"pci0000"* ]]; then |
| 50 | WIFI_RADIO2=1 |
| 51 | fi |
| 52 | |
| 53 | if [[ $v == *"pci0001"* ]]; then |
| 54 | WIFI_RADIO3=1 |
| 55 | fi |
| 56 | done; |
| 57 | |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 58 | |
| 59 | for v in $WIFI_MODULE_LIST; |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 60 | do |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 61 | if [[ -f "/sys/module/$v/parameters/wed_enable" ]]; then |
| 62 | WED_ENABLE_LIST=`cat /sys/module/$v/parameters/wed_enable` |
| 63 | dbg2 "wed enable ori info $v $WED_ENABLE_LIST" |
| 64 | if [[ $WED_ENABLE_LIST == "Y" ]]; then |
| 65 | WED_ENABLE=1 |
| 66 | fi |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 67 | fi |
| 68 | done; |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 69 | dbg2 "NUM_WIFI_CARD = $NUM_WIFI_CARD" |
| 70 | dbg2 "platform wifi enable = $WIFI_RADIO1" |
| 71 | dbg2 "pcie1 wifi enable = $WIFI_RADIO2" |
| 72 | dbg2 "pcie2 wifi enable = $WIFI_RADIO3" |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 73 | dbg2 "WED enable = $WED_ENABLE" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | # $1: CPU# |
| 77 | # $2: irq list for added. |
| 78 | CPU_AFFINITY_ADD() |
| 79 | { |
| 80 | eval oval=\$CPU${1}_AFFINITY |
| 81 | eval CPU${1}_AFFINITY=\"\$CPU${1}_AFFINITY $2\" |
| 82 | } |
| 83 | |
| 84 | # $1: CPU# |
| 85 | # $2: Interface name for added. |
| 86 | CPU_RPS_ADD() |
| 87 | { |
| 88 | eval oval=\$CPU${1}_RPS |
| 89 | eval CPU${1}_RPS=\"\$CPU${1}_RPS $2\" |
| 90 | dbg2 "CPU${1}_RPS=\"\$CPU${1}_RPS $2\"" |
| 91 | } |
| 92 | |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 93 | MT7988() |
| 94 | { |
| 95 | num_of_wifi=$1 |
| 96 | DEFAULT_RPS=0 |
| 97 | |
| 98 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 99 | #Ethernet RSS feature enables 4 Rx rings |
| 100 | eth_irq_rx0=221 |
| 101 | eth_irq_rx1=222 |
| 102 | eth_irq_rx2=223 |
| 103 | eth_irq_rx3=224 |
| 104 | eth_irq_tx=229 |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 105 | wifi1_irq_pcie0=524288 |
| 106 | wifi1_irq_pcie1=134742016 |
| 107 | wifi2_irq_pcie0= |
| 108 | wifi2_irq_pcie1= |
| 109 | |
| 110 | if [[ "$WED_ENABLE" -eq "1" ]]; then |
| 111 | dbg2 "WED_ENABLE ON irq/iptable setting" |
| 112 | #TCP Binding |
| 113 | iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 114 | iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 115 | ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 116 | ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 117 | #UDP Binding |
| 118 | iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 119 | iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 120 | ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 121 | ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 122 | |
| 123 | else |
| 124 | dbg2 "WED_ENABLE OFF irq/iptable seting" |
| 125 | fi |
| 126 | |
| 127 | for vif in $NET_IF_LIST; |
| 128 | do |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 129 | if [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 130 | WIFI_IF_LIST="$WIFI_IF_LIST $vif" |
| 131 | fi |
| 132 | done; |
| 133 | dbg2 "$WIFI_IF_LIST = $WIFI_IF_LIST" |
| 134 | # Please update the CPU binding in each cases. |
| 135 | # CPU#_AFFINITY="add binding irq number here" |
| 136 | # CPU#_RPS="add binding interface name here" |
| 137 | if [ "$num_of_wifi" = "0" ]; then |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 138 | CPU0_AFFINITY="$eth_irq_rx0 $eth_irq_tx" |
| 139 | CPU1_AFFINITY="$eth_irq_rx1" |
| 140 | CPU2_AFFINITY="$eth_irq_rx2" |
| 141 | CPU3_AFFINITY="$eth_irq_rx3" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 142 | |
| 143 | CPU0_RPS="$RPS_IF_LIST" |
| 144 | CPU1_RPS="$RPS_IF_LIST" |
| 145 | CPU2_RPS="$RPS_IF_LIST" |
| 146 | CPU3_RPS="$RPS_IF_LIST" |
| 147 | else |
| 148 | #we bound all wifi card to cpu0 and bound eth to cpu |
| 149 | CPU0_AFFINITY="" |
| 150 | CPU1_AFFINITY="" |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 151 | CPU2_AFFINITY="$eth_irq_rx0 $eth_irq_rx1 $eth_irq_tx" |
| 152 | CPU3_AFFINITY="$eth_irq_rx2 $eth_irq_rx3" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 153 | |
| 154 | CPU0_RPS="$WIFI_IF_LIST" |
| 155 | CPU1_RPS="$WIFI_IF_LIST" |
developer | 6d638dd | 2023-02-21 13:46:21 +0800 | [diff] [blame] | 156 | CPU2_RPS="" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 157 | CPU3_RPS="" |
| 158 | fi |
| 159 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 160 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 161 | dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY" |
| 162 | dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY" |
| 163 | } |
| 164 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 165 | MT7986() |
| 166 | { |
| 167 | num_of_wifi=$1 |
| 168 | DEFAULT_RPS=0 |
| 169 | |
| 170 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 171 | eth_irq_rx=221 |
| 172 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 173 | wifi1_irq= |
| 174 | wifi2_irq= |
| 175 | wifi3_irq= |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 176 | |
| 177 | if [[ "$WED_ENABLE" -eq "1" ]]; then |
| 178 | dbg2 "WED_ENABLE ON irq/iptable setting" |
| 179 | #TCP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 180 | iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 181 | iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 182 | ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 183 | ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 184 | #UDP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 185 | iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 186 | iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 187 | ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 188 | ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 189 | |
| 190 | #AX6000 AX7800 - SOC |
| 191 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 192 | wifi1_irq=238 |
| 193 | fi |
| 194 | #AX7800 - PCIE0 |
| 195 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 196 | wifi2_irq=237 |
| 197 | fi |
| 198 | #AX7800 - PCIE1 |
| 199 | #if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 200 | # wifi3_irq=239 |
| 201 | #fi |
| 202 | else |
| 203 | dbg2 "WED_ENABLE OFF irq/iptable seting" |
| 204 | #AX6000 AX7800 - SOC |
| 205 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 206 | wifi1_irq=245 |
| 207 | fi |
| 208 | #AX7800 - PCIE0 |
| 209 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 210 | wifi2_irq=246 |
| 211 | fi |
| 212 | #AX7800 - PCIE1 |
| 213 | #if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 214 | # wifi3_irq=247 |
| 215 | #fi |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 216 | fi |
| 217 | # Please update the CPU binding in each cases. |
| 218 | # CPU#_AFFINITY="add binding irq number here" |
| 219 | # CPU#_RPS="add binding interface name here" |
| 220 | if [ "$num_of_wifi" = "0" ]; then |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 221 | CPU0_AFFINITY="$eth_irq_rx" |
| 222 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 223 | CPU2_AFFINITY="" |
| 224 | CPU3_AFFINITY="" |
| 225 | |
| 226 | CPU0_RPS="$RPS_IF_LIST" |
| 227 | CPU1_RPS="$RPS_IF_LIST" |
| 228 | CPU2_RPS="$RPS_IF_LIST" |
| 229 | CPU3_RPS="$RPS_IF_LIST" |
| 230 | else |
| 231 | #we bound all wifi card to cpu1 and bound eth to cpu0 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 232 | CPU0_AFFINITY="$eth_irq_rx" |
| 233 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 234 | CPU2_AFFINITY="$wifi2_irq $wifi3_irq" |
| 235 | CPU3_AFFINITY="$wifi1_irq" |
| 236 | |
| 237 | CPU0_RPS="$RPS_IF_LIST" |
| 238 | CPU1_RPS="$RPS_IF_LIST" |
| 239 | CPU2_RPS="$RPS_IF_LIST" |
| 240 | CPU3_RPS="$RPS_IF_LIST" |
| 241 | fi |
| 242 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 243 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 244 | dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY" |
| 245 | dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY" |
| 246 | } |
| 247 | |
| 248 | MT7981() |
| 249 | { |
| 250 | num_of_wifi=$1 |
| 251 | DEFAULT_RPS=0 |
| 252 | |
| 253 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 254 | eth_irq_rx=221 |
| 255 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 256 | wifi1_irq= |
| 257 | wifi2_irq= |
| 258 | wifi3_irq= |
| 259 | #AX3000 |
| 260 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 261 | wifi1_irq=245 |
| 262 | fi |
| 263 | # Please update the CPU binding in each cases. |
| 264 | # CPU#_AFFINITY="add binding irq number here" |
| 265 | # CPU#_RPS="add binding interface name here" |
| 266 | if [ "$num_of_wifi" = "0" ]; then |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 267 | CPU0_AFFINITY="$eth_irq_rx" |
| 268 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 269 | |
| 270 | CPU0_RPS="$RPS_IF_LIST" |
| 271 | CPU1_RPS="$RPS_IF_LIST" |
| 272 | else |
| 273 | #we bound all wifi card to cpu0 and bound eth to cpu1 |
| 274 | CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq" |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 275 | CPU1_AFFINITY="$eth_irq_rx $eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 276 | |
| 277 | CPU0_RPS="$RPS_IF_LIST" |
| 278 | CPU1_RPS="$RPS_IF_LIST" |
| 279 | fi |
| 280 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 281 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 282 | } |
| 283 | |
| 284 | MT7622() |
| 285 | { |
| 286 | num_of_wifi=$1 |
| 287 | DEFAULT_RPS=0 |
| 288 | |
| 289 | #Physical IRQ# setting |
| 290 | eth0_irq=224 |
| 291 | eth1_irq=225 |
| 292 | wifi1_irq= |
| 293 | wifi2_irq= |
| 294 | wifi3_irq= |
| 295 | #AX1200 AX3200 |
| 296 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 297 | wifi1_irq=211 |
| 298 | fi |
| 299 | #AX1800 AX3200 |
| 300 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 301 | wifi2_irq=214 |
| 302 | fi |
| 303 | #AX3600 |
| 304 | if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 305 | wifi3_irq=215 |
| 306 | fi |
| 307 | |
| 308 | # Please update the CPU binding in each cases. |
| 309 | # CPU#_AFFINITY="add binding irq number here" |
| 310 | # CPU#_RPS="add binding interface name here" |
| 311 | if [ "$num_of_wifi" == "0" ]; then |
| 312 | CPU0_AFFINITY="$eth0_irq" |
| 313 | CPU1_AFFINITY="$eth1_irq" |
| 314 | |
| 315 | CPU0_RPS="$RPS_IF_LIST" |
| 316 | CPU1_RPS="$RPS_IF_LIST" |
| 317 | else |
| 318 | #we bound all wifi card to cpu0 and bound eth to cpu1 |
| 319 | CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq" |
| 320 | CPU1_AFFINITY="$eth0_irq $eth1_irq" |
| 321 | |
| 322 | CPU0_RPS="$RPS_IF_LIST" |
| 323 | CPU1_RPS="$RPS_IF_LIST" |
| 324 | fi |
| 325 | |
| 326 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 327 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 328 | } |
| 329 | |
| 330 | setup_model() |
| 331 | { |
| 332 | board=$(board_name) |
| 333 | num_of_wifi=$NUM_WIFI_CARD |
| 334 | |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 335 | if [[ $board == *"7988"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 336 | dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi" |
| 337 | MT7988 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 338 | elif [[ $board == *"7986"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 339 | dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi" |
| 340 | MT7986 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 341 | elif [[ $board == *"7981"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 342 | dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi" |
| 343 | MT7981 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 344 | elif [[ $board == *"7622"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 345 | dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi" |
| 346 | MT7622 $num_of_wifi |
| 347 | fi |
| 348 | } |
| 349 | |
| 350 | get_virtual_irq() |
| 351 | { |
| 352 | PHY_POS=`expr $NUM_OF_CPU + 3` #physical irq # position in /proc/interrups may vary with the number of CPU up |
| 353 | target_phy_irq=$1 |
| 354 | cat /proc/interrupts | sed 's/:/ /g'| awk '$1 ~ /^[0-9]+$/' | while read line |
| 355 | do |
| 356 | set -- $line |
| 357 | phy_irq=$(eval "echo \$$PHY_POS") |
| 358 | if [ $phy_irq == $target_phy_irq ]; then |
| 359 | echo $1 |
| 360 | return |
| 361 | fi |
| 362 | done |
| 363 | } |
| 364 | |
| 365 | set_rps_cpu_bitmap() |
| 366 | { |
| 367 | dbg2 "# Scan binding interfaces of each cpu" |
| 368 | # suppose the value of interface_var is null or hex |
| 369 | num=0 |
| 370 | while [ "$num" -lt "$NUM_OF_CPU" ];do |
| 371 | cpu_bit=$((2 ** $num)) |
| 372 | eval rps_list=\$CPU${num}_RPS |
| 373 | dbg2 "# CPU$num: rps_list=$rps_list" |
| 374 | for i in $rps_list; do |
| 375 | var=${VAR_PREFIX}_${i//-/_} |
| 376 | eval ifval=\$$var |
| 377 | dbg2 "[var val before] \$$var=$ifval" |
| 378 | if [ -z "$ifval" ]; then |
| 379 | eval $var=$cpu_bit |
| 380 | else |
| 381 | eval $var=`expr $ifval + $cpu_bit` |
| 382 | fi |
| 383 | eval ifval=\$$var |
| 384 | dbg2 "[rps val after]$i=$ifval" |
| 385 | done |
| 386 | num=`expr $num + 1` |
| 387 | done |
| 388 | } |
| 389 | |
| 390 | # $1: The default rps value. If rps of the interface is not setup, set $1 to it |
| 391 | set_rps_cpus() |
| 392 | { |
| 393 | dbg2 "# Setup rps of the interfaces, $RPS_IF_LIST." |
| 394 | for i in $RPS_IF_LIST; do |
| 395 | var=${VAR_PREFIX}_${i//-/_} |
| 396 | eval cpu_map=\$$var |
| 397 | if [ -d /sys/class/net/$i ]; then |
| 398 | if [ ! -z $cpu_map ]; then |
| 399 | cpu_map=`printf '%x' $cpu_map` |
| 400 | dbg "echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus" |
| 401 | echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus |
| 402 | elif [ ! -z $1 ]; then |
| 403 | dbg "echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus" |
| 404 | echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus |
| 405 | fi |
| 406 | fi |
| 407 | done |
| 408 | } |
| 409 | |
| 410 | set_smp_affinity() |
| 411 | { |
| 412 | dbg2 "# Setup affinity of each physical irq." |
| 413 | num=0 |
| 414 | while [ "$num" -lt "$NUM_OF_CPU" ];do |
| 415 | eval smp_list=\$CPU${num}_AFFINITY |
| 416 | for i in $smp_list; do |
| 417 | cpu_bit=$((2 ** $num)) |
| 418 | virq=$(get_virtual_irq $i) |
| 419 | #virq=$i |
| 420 | dbg2 "irq p2v $i --> $virq" |
| 421 | if [ ! -z $virq ]; then |
| 422 | dbg "echo $cpu_bit > /proc/irq/$virq/smp_affinity" |
| 423 | echo $cpu_bit > /proc/irq/$virq/smp_affinity |
| 424 | fi |
| 425 | done |
| 426 | num=`expr $num + 1` |
| 427 | done |
| 428 | } |
| 429 | |
| 430 | if [ "$1" = "dbg" ]; then |
| 431 | DBG=1 |
| 432 | elif [ "$1" = "dbg2" ]; then |
| 433 | DBG=2 |
| 434 | else |
| 435 | DBG=0 |
| 436 | fi |
| 437 | |
| 438 | # Usage: dbg "the output string" |
| 439 | dbg() |
| 440 | { |
| 441 | if [ "$DBG" -ge "1" ]; then |
| 442 | echo -e $1 |
| 443 | fi |
| 444 | } |
| 445 | |
| 446 | # Usage: dbg2 "the output string" |
| 447 | dbg2() |
| 448 | { |
| 449 | if [ "$DBG" -ge "2" ]; then |
| 450 | echo -e $1 |
| 451 | fi |
| 452 | } |
| 453 | |
| 454 | dbg "# RPS and AFFINITY Setting" |
| 455 | dbg "# NUM_OF_CPU=$NUM_OF_CPU" |
| 456 | VAR_PREFIX="autogen" |
| 457 | get_if_info |
| 458 | setup_model |
| 459 | set_rps_cpu_bitmap |
| 460 | set_rps_cpus $DEFAULT_RPS |
| 461 | set_smp_affinity |
| 462 | #end of file |