Now that you have determined the layout of your processor and receive queues, decide which CPU and receive queue you want to use for your application. If necessary, revisit the previous topics in this section.
Set the CPU for your application, and add ethtool rules to ensure that your application uses your desired receive queue:
- As root, install an ethtool rule to direct the traffic
for your application to your desired receive
queue:
# ethtool -N <interface> flow-type tcp4|udp4|tcp6|udp6 dst-ip <ip_addr> dst-port <port> queue <n>
For example if your application is using the enp1s0f0np0 interface, and is receiving UDP v4 traffic sent to port 1234 at address 192.168.10.200, then to use receive queue 3:
# ethtool -N enp1s0f0np0 flow-type udp4 dst-ip 192.168.10.200 dst-port 1234 queue 3 Added rule with ID 0
Note: If this would exceed the maximum number of filters, an error message is output, and the filter is not inserted. For example:rmgr: Cannot find appropriate slot to insert rule Cannot insert classification rule
- Optionally list the rules for the interface and confirm that the new rule is
present:
# ethtool -n <interface>
For example:
# ethtool -n enp1s0f0np0 8 RX rings available Total 1 rules Filter: 0 Rule Type: UDP over IPv4 Src IP addr: 0.0.0.0 mask: 255.255.255.255 Dest IP addr: 192.168.10.200 mask: 0.0.0.0 TOS: 0x0 mask: 0xff Src port: 0 mask: 0xffff Dest port: 1234 mask: 0x0 Action: Direct to queue 3
- Use the taskset command to start your application on its desired
CPU:
taskset -c <cpu> <command line>
- Have your application create a filter with the same parameters as the ethtool
rule.
The pre-installed ethtool rule is recognized as identical and is re-used. The application therefore uses the receive queue that was specified for the ethtool rule.
- When your application quits, delete the ethtool
rule:
ethtool -N <interface> delete <rule number>
For example, to delete rule 0 that was installed in step 1 above:
ethtool -N enp1s0f0np0 delete 0
- List the rules for the interface and confirm that the rule is
deleted:
# ethtool -n <interface>
For example:
# ethtool -n enp1s0f0np0 8 RX rings available Total 0 rules
shed_setaffinity()
function (see Linux man pages). Use of this call and
how a particular application can be tuned is beyond the scope of this guide.