-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[image_config]: Enable Receive Packet Steering (RPS)
* This patch enables Receive Packet Steering (RPS) which helps to distribute softirq processing for CPU bound packets to all available cores. This will help prevent kernel packet drops when there are bouts of intense CPU bound packets. Ref: https://lwn.net/Articles/362339/ https://docs.kernel.org/networking/scaling.html Signed-off-by: Prabhat Aravind <paravind@microsoft.com>
- Loading branch information
1 parent
c883f16
commit 982a451
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import ast | ||
import subprocess | ||
|
||
''' | ||
Script to enable Receive Packet Steering (RPS) | ||
''' | ||
|
||
def exec_cmd(cmd): | ||
p = subprocess.Popen(cmd, shell=False, executable='/bin/bash', | ||
stdout = subprocess.PIPE) | ||
return (p.communicate()[0].strip()) | ||
|
||
|
||
def configure_rps(): | ||
num_cpus = ast.literal_eval(exec_cmd("nproc")) | ||
cpumask = hex(pow(2, num_cpus) - 1)[2:] | ||
net_dir_path = "/sys/class/net" | ||
|
||
for intf in os.listdir(net_dir_path): | ||
if "Ethernet" in intf: | ||
queues_path = os.path.join(net_dir_path, intf, "queues") | ||
queues = os.listdir(queues_path) | ||
num_rx_queues = len([q for q in queues if q.startswith("rx")]) | ||
for q in range(num_rx_queues): | ||
path = os.path.join(queues_path, "rx-{}", "rps_cpus").format(q) | ||
command = "echo {} | sudo tee {}".format(cpumask, path) | ||
print ("Setting {} to cpu mask {}".format(path, cpumask)) | ||
print (command) | ||
exec_cmd(command) | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_rps() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=Enable Receive Packet Steering (RPS) in kernel | ||
After=swss.service | ||
BindsTo=sonic.target | ||
After=sonic.target | ||
|
||
[Service] | ||
User=root | ||
Type=oneshot | ||
ExecStart=/usr/bin/rps.py | ||
RemainAfterExit=yes | ||
|
||
[Install] | ||
WantedBy=sonic.target |