-
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 ea3735f
Showing
3 changed files
with
67 additions
and
1 deletion.
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,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
|
||
''' | ||
Script to enable Receive Packet Steering (RPS) | ||
''' | ||
def get_num_cpus(): | ||
ncpus = 0 | ||
cpu_count = os.cpu_count() | ||
if cpu_count is not None: | ||
ncpus = cpu_count | ||
|
||
return ncpus | ||
|
||
|
||
def get_cpumask(ncpus): | ||
return hex(pow(2, ncpus) - 1)[2:] | ||
|
||
|
||
def configure_rps(): | ||
rv = 0 | ||
NET_DIR_PATH = "/sys/class/net" | ||
|
||
num_cpus = get_num_cpus() | ||
if not num_cpus: | ||
rv = -1 | ||
return rv | ||
|
||
cpumask = get_cpumask(num_cpus) | ||
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): | ||
rps_cpus_path = os.path.join(queues_path, "rx-{}", "rps_cpus").format(q) | ||
with open(rps_cpus_path, 'w') as file: | ||
print ("Setting {} to cpu mask {}".format(rps_cpus_path, cpumask)) | ||
file.write(cpumask) | ||
|
||
return rv | ||
|
||
|
||
def main(): | ||
rv = 0 | ||
try: | ||
rv = configure_rps() | ||
except Exception as e: | ||
print ("configure_rps exception occurred: {}".format(str(e))) | ||
|
||
sys.exit(rv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
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 @@ | ||
ACTION=="add", SUBSYSTEM=="net", KERNEL=="Ethernet*", RUN+="/usr/bin/rps.py" |