net: mana: Optimize irq affinity for low vcpu configs
Subsystems (5)
PATCH 1/1 net: mana: Optimize irq affinity for low vcpu configs
In mana driver, the number of IRQs allocated are capped by the min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.
This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)
TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1: mana_q1 0
IRQ2: mana_q2 2
IRQ3: mana_q3 0
IRQ4: mana_q4 3
%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17
=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)
TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3
%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36
=======================================================
Throughput Impact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28
--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +33 -2
@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; } +static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock (); +for_each_online_cpu (cpu) { +if (len <=0 ) +break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);
@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu); + }else { +/* +* In case our IRQs are more than num_online_cpus, we try to +* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu +*/ +WARN_ON (nvec >num_online_cpus ()); + err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;
base-commit: e728258debd553c95d2e70f9cd97c9fde27c7130
Signature · 1 line
2.34.1
Quoted 85 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1679
Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; } +static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock ();
We do not need to call rcu_read_lock here, as the caller of this function has already acquired cpus_read_lock.
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1681
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0+for_each_online_cpu (cpu) { +if (len <=0 )
len is unsigned here so <= doesnot makes sense. PLease change it to int or better use if(!len)
Quoted 21 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +12
-1+break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1754
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +10
-0+ }else { +/* +* In case our IRQs are more than num_online_cpus, we try to +* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu
nit: typo: should be num_online_cpus
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-1+*/ +WARN_ON (nvec >num_online_cpus ()); + err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;
Quoted 4 lines
base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1
Regards
Dipayaan Roy
Quoted 89 lines · Dipayaan Roy
Quoted 88 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; }
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1679
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5
-0+static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock ();We do not need to call
rcu_read_lockhere, as the caller of this function has already acquiredcpus_read_lock.
Thanks for your comments Dipayaan, I think this is still needed for the irq_set_affinity_and_hint(), to protect the pointer returned by irq_to_desc(). You can also see the same in the original function irq_setup() for the same reason.
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1681
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0+for_each_online_cpu (cpu) { +if (len <=0 )len is unsigned here so <= doesnot makes sense. PLease change it to int or better use if(!len)
sure, I think I will change it to explicitly exit when len == 0 Thanks.
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +15
-1+break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu); + }else { +/* +* In case our IRQs are more than num_online_cpus, we try to
Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1754
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +7
-0+* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu nit: typo: should be
num_online_cpus
noted
Quoted 16 lines
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-1+*/ +WARN_ON (nvec >num_online_cpus ()); + err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;Quoted 4 lines
base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1Regards
Dipayaan Roy
Quoted 98 lines · Shradha Gupta
Quoted 89 lines · Dipayaan Roy
Quoted 88 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; }Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1679
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5
-0+static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock ();We do not need to call
rcu_read_lockhere, as the caller of this function has already acquiredcpus_read_lock.
Quoted 4 lines
Thanks for your comments Dipayaan, I think this is still needed for the
irq_set_affinity_and_hint(), to protect the pointer returned byirq_to_desc(). You can also see the same in the original functionirq_setup()for the same reason.
Hi Shradha,
The original irq_setup() function uses rcu_read_lock() because it relies
on for_each_numa_hop_mask(), which explicitly mandates that RCU be held. You have not used it in irq_setup_linear(), hence the requirement does not apply here.
https://elixir.bootlin.com/linux/v7.0.1/source/include/linux/topology.h#L314
/**
* for_each_numa_hop_mask - iterate over cpumasks of increasing NUMA
* distance
* from a given node.
* @mask: the iteration variable.
* @node: the NUMA node to start the search from.
*
* Requires rcu_lock to be held.
*
.....
Regarding irq_set_affinity_and_hint it also garbs rcu locks internally:irq_set_affinity_and_hint ->__irq_apply_affinity_hint() -> irq_to_desc() -> mtree_load(). Also see how irq_set_affinity_and_hint is called in mana_gd_setup_irqs.
IMO we should drop the nesting when not needed, even though it appears harmless.
Thanks and Regards
Dipayaan Roy
Quoted 60 lines
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1681
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0+for_each_online_cpu (cpu) { +if (len <=0 )len is unsigned here so <= doesnot makes sense. PLease change it to int or better use if(!len)
sure, I think I will change it to explicitly exit when len == 0 Thanks.
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +15
-1+break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu); + }else { +/* +* In case our IRQs are more than num_online_cpus, we try to Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1754
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +7
-0+* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu nit: typo: should be
num_online_cpusnoted
Quoted 16 lines
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-1+*/ +WARN_ON (nvec >num_online_cpus ()); + err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;Quoted 4 lines
base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1Regards
Dipayaan Roy
Quoted 126 lines · Dipayaan Roy
Quoted 98 lines · Shradha Gupta
Quoted 89 lines · Dipayaan Roy
Quoted 88 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; }Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1679
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5
-0+static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock ();We do not need to call
rcu_read_lockhere, as the caller of this function has already acquiredcpus_read_lock.Quoted 4 lines
Thanks for your comments Dipayaan, I think this is still needed for the
irq_set_affinity_and_hint(), to protect the pointer returned byirq_to_desc(). You can also see the same in the original functionirq_setup()for the same reason.Hi Shradha,
The original
irq_setup()function usesrcu_read_lock()because it relies
onfor_each_numa_hop_mask(), which explicitly mandates that RCU be held. You have not used it inirq_setup_linear(), hence the requirement does not apply here.
https://elixir.bootlin.com/linux/v7.0.1/source/include/linux/topology.h#L314
/**
*for_each_numa_hop_mask- iterate over cpumasks of increasing NUMA
* distance
* from a given node.
* @mask: the iteration variable.
* @node: the NUMA node to start the search from.
*
* Requiresrcu_lockto be held.
*
.....
Regardingirq_set_affinity_and_hintit also garbs rcu locks internally:irq_set_affinity_and_hint->__irq_apply_affinity_hint() ->irq_to_desc()->mtree_load(). Also see howirq_set_affinity_and_hintis called inmana_gd_setup_irqs.
IMO we should drop the nesting when not needed, even though it appears harmless.
Quoted 3 lines
Thanks and Regards
Dipayaan Roy
There was a small window after mtree_load() returns irq_desc* and raw_spin_lock() being taken, where I thought the rcu_read_lock() was needed. But on futher investigation, I agree it is not needed there as well. Let me drop this in the v2. Thanks
Quoted 60 lines
Quoted 60 lines
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int irq_setup(unsigned int *irqs, unsigned int len, int node, · line 1681
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0+for_each_online_cpu (cpu) { +if (len <=0 )len is unsigned here so <= doesnot makes sense. PLease change it to int or better use if(!len)
sure, I think I will change it to explicitly exit when len == 0 Thanks.
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +15
-1+break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu); + }else { +/* +* In case our IRQs are more than num_online_cpus, we try to Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1754
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +7
-0+* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu nit: typo: should be
num_online_cpusnoted
Quoted 16 lines
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4
-1+*/ +WARN_ON (nvec >num_online_cpus ()); + err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;Quoted 4 lines
base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1Regards
Dipayaan Roy
Quoted 109 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +17
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; } +static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock (); +for_each_online_cpu (cpu) { +if (len <=0 ) +break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1744
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-1@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ */ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);
Then you don't need the 'skip_first_cpu' variable.
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1756
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +12
-0+ }else { +/* +* In case our IRQs are more than num_online_cpus, we try to +* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu +*/ +WARN_ON (nvec >num_online_cpus ());
That sounds weird. If you don't support IRQs more than CPUs , and want to warn about it, you'd do that earlier in the function, and align the other logic accordingly. For example:
if (WARN_ON(nvec > num_online_cpus()))
nvec = num_online_cpus();
irqs = kmalloc_objs(int, nvec);
if (!irqs)
return -ENOMEM;
...So you'll decrease pressure on allocator.
What would happen with those IRQs beyond num_online_cpus()? Can you explain it in the comment? I'm not an expert in your driver, but usually if you pass a vector to function, and the function is able to handle only a part of it, it returns the number of processed elements.
Thanks,
Yury
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-1+ err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1
Quoted 111 lines · Yury Norov
Quoted 110 lines · Shradha Gupta
In mana driver, the number of IRQs allocated are capped by the
min(num_cpu + 1, queue count). In cases, where the IRQ count is greater than the vcpu count, we want to utilize all the vcpus, irrespective of their NUMA/core bindings.This is important, especially in the envs where number of vcpus are so few that the softIRQ handling overhead on two IRQs on the same vcpu is much more than their overheads if they were spread across sibling vcpus
This behaviour is more evident with dynamic IRQ allocation. Since MANA IRQs are assigned at a later stage compared to static allocation, other device IRQs may already be affinitized to the vCPUs. As a result, IRQ weights become imbalanced, causing multiple MANA IRQs to land on the same vCPU.
In such cases when many parallel TCP connections are tested, the throughput drops significantly
Test envs:
=======================================================
Case 1: without this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================
IRQ0: HWC 0
IRQ1:mana_q10
IRQ2:mana_q22
IRQ3:mana_q30
IRQ4:mana_q43%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================
pass 1: 38.85 0.03 24.89 24.65
pass 2: 39.15 0.03 24.57 25.28
pass 3: 40.36 0.03 23.20 23.17=======================================================
Case 2: with this patch
=======================================================
4 vcpu(2 cores), 5 MANA IRQs (1 HWC + 4 Queue)TYPE effective vCPU aff
=======================================================IRQ0: HWC 0 IRQ1: mana_q1 0 IRQ2: mana_q2 1 IRQ3: mana_q3 2 IRQ4: mana_q4 3%soft on each vCPU(mpstat -P ALL 1) on receiver
vCPU 0 1 2 3
=======================================================pass 1: 15.42 15.85 14.99 14.51 pass 2: 15.53 15.94 15.81 15.93 pass 3: 16.41 16.35 16.40 16.36=======================================================
ThroughputImpact(in Gbps, same env)
=======================================================
TCP conn with patch w/o patch
20480 15.65 7.73
10240 15.63 8.93
8192 15.64 9.69
6144 15.64 13.16
4096 15.69 15.75
2048 15.69 15.83
1024 15.71 15.28Fixes 755391121038 ("net: mana: Allocate MSI-X vectors dynamically")Signed-off-by Shradha Gupta <[email protected]>Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- .../net/ethernet/microsoft/mana/gdma_main.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/net/ethernet/microsoft/mana/gdma_main.c +17
-0@@ -1672,6 +1672,23 @@ static int irq_setup(unsigned int *irqs, unsigned int len, int node,return 0 ; } +static int irq_setup_linear (unsigned int *irqs,unsigned int len) +{ +int cpu; + +rcu_read_lock (); +for_each_online_cpu (cpu) { +if (len <=0 ) +break ; + +irq_set_affinity_and_hint (*irqs++,cpumask_of (cpu)); + len--; + } +rcu_read_unlock (); + +return 0 ; +} +static int mana_gd_setup_dyn_irqs (struct pci_dev *pdev,int nvec) {struct gdma_context *gc =pci_get_drvdata (pdev);@@ -1722,10 +1739,24 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec)* first CPU sibling group since they are already affinitized to HWC IRQ
Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1744
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-1*/ cpus_read_lock (); -if (gc->num_msix_usable <=num_online_cpus ()) +if (gc->num_msix_usable <=num_online_cpus ()) { skip_first_cpu = true; + err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);Then you don't need the '
skip_first_cpu' variable.
That's right, let me change that.
Quoted 29 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) · line 1756
Quoted 13 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +12
-0+ }else { +/* +* In case our IRQs are more than num_online_cpus, we try to +* make sure we are using all vcpus. In such a case NUMA or +* CPU core affinity does not matter. +* Note that in this case the total mana IRQ should always be +* num_online_cpu + 1. The first HWC IRQ is already handled +* in HWC setup calls +* So, the nvec value in this path should always be equal to +* num_online_cpu +*/ +WARN_ON (nvec >num_online_cpus ());That sounds weird. If you don't support IRQs more than CPUs , and want to warn about it, you'd do that earlier in the function, and align the other logic accordingly. For example:
if (WARN_ON(nvec > num_online_cpus())) nvec = num_online_cpus(); irqs = kmalloc_objs(int, nvec); if (!irqs) return -ENOMEM; ...So you'll decrease pressure on allocator.
Quoted 8 lines
What would happen with those IRQs beyond
num_online_cpus()? Can you explain it in the comment? I'm not an expert in your driver, but usually if you pass a vector to function, and the function is able to handle only a part of it, it returns the number of processed elements.Thanks,
Yury
so, by design the nvec should never exceed num_online_cpus(). I only added the WARN_ON as a defensive safegaurd. But I agree with your suggestion to move this earlier before the allocations.
Thanks Yury!
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-1+ err =irq_setup_linear (irqs, nvec); + } - err =irq_setup (irqs, nvec, gc->numa_node, skip_first_cpu);if (err) {cpus_read_unlock (); goto free_irq;base-commit:
e728258debd553c95d2e70f9cd97c9fde27c7130Signature · 1 line
2.34.1