This is a change required by parallel iperf test. To achieve reproducible
measurements it's required to turn off irqbalance and spread the NIC IRQs
evenly on the available cpus.
The current recipe parameter dev_intr_cpu can specify only one cpu.
This patch renames the dev_intr_cpu to dev_intr_cpus and changes it to ListParam.
The value is a list of cpus that will be used for pinning the NIC IRQs.
For the original behaviour a user simply needs to change
dev_intr_cpu=0
to
dev_intr_cpus=[0]
and the recipe will run as before.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
.../ConfigMixins/DevInterruptHWConfigMixin.py | 38 ++++++++++---------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/lnst/Recipes/ENRT/ConfigMixins/DevInterruptHWConfigMixin.py
b/lnst/Recipes/ENRT/ConfigMixins/DevInterruptHWConfigMixin.py
index 1f8f5e8e..d9ba81fc 100644
--- a/lnst/Recipes/ENRT/ConfigMixins/DevInterruptHWConfigMixin.py
+++ b/lnst/Recipes/ENRT/ConfigMixins/DevInterruptHWConfigMixin.py
@@ -1,6 +1,6 @@
import re
-from lnst.Common.Parameters import IntParam
+from lnst.Common.Parameters import ListParam
from lnst.Controller.Recipe import RecipeError
from lnst.Controller.RecipeResults import ResultLevel
from lnst.Recipes.ENRT.ConfigMixins.BaseHWConfigMixin import BaseHWConfigMixin
@@ -15,11 +15,11 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
.. note::
Note that this Mixin also stops the irqbalance service.
- :param dev_intr_cpu:
+ :param dev_intr_cpus:
(optional test parameter) CPU id to which the device IRQs should be pinned
"""
- dev_intr_cpu = IntParam(mandatory=False)
+ dev_intr_cpus = ListParam(mandatory=False)
@property
def dev_interrupt_hw_config_dev_list(self):
@@ -34,8 +34,8 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
hw_config = config.hw_config
- if "dev_intr_cpu" in self.params:
- intr_cfg = hw_config["dev_intr_cpu_configuration"] = {}
+ if "dev_intr_cpus" in self.params:
+ intr_cfg = hw_config["dev_intr_cpus_configuration"] = {}
intr_cfg["irq_devs"] = {}
intr_cfg["irqbalance_hosts"] = []
@@ -49,11 +49,11 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
for dev in self.dev_interrupt_hw_config_dev_list:
# TODO better service handling through HostAPI
- self._pin_dev_interrupts(dev, self.params.dev_intr_cpu)
- intr_cfg["irq_devs"][dev] = self.params.dev_intr_cpu
+ self._pin_dev_interrupts(dev, self.params.dev_intr_cpus)
+ intr_cfg["irq_devs"][dev] = self.params.dev_intr_cpus
def hw_deconfig(self, config):
- intr_config = config.hw_config.get("dev_intr_cpu_configuration", {})
+ intr_config = config.hw_config.get("dev_intr_cpus_configuration", {})
for host in intr_config.get("irqbalance_hosts", []):
host.run("service irqbalance start")
@@ -64,7 +64,7 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
hw_config = config.hw_config
- intr_cfg = hw_config.get("dev_intr_cpu_configuration", None)
+ intr_cfg = hw_config.get("dev_intr_cpus_configuration", None)
if intr_cfg:
desc += [
"{} irqbalance stopped".format(host.hostid)
@@ -80,19 +80,20 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
desc.append("Device irq configuration skipped.")
return desc
- def _pin_dev_interrupts(self, dev, cpu):
+ def _pin_dev_interrupts(self, dev, cpus):
netns = dev.netns
cpu_info = netns.run("lscpu", job_level=ResultLevel.DEBUG).stdout
regex = "CPU\(s\): *([0-9]*)"
num_cpus = int(re.search(regex, cpu_info).groups()[0])
- if cpu < 0 or cpu > num_cpus - 1:
- raise RecipeError(
- "Invalid CPU value given: %d. Accepted value %s."
- % (
- cpu,
- "is: 0" if num_cpus == 1 else "are: 0..%d" %
(num_cpus - 1),
+ for cpu in cpus:
+ if cpu < 0 or cpu > num_cpus - 1:
+ raise RecipeError(
+ "Invalid CPU value given: %d. Accepted value %s."
+ % (
+ cpu,
+ "is: 0" if num_cpus == 1 else "are: 0..%d" %
(num_cpus - 1),
+ )
)
- )
res = netns.run(
"grep {} /proc/interrupts | cut -f1 -d: | sed 's/
//'".format(
@@ -110,9 +111,10 @@ class DevInterruptHWConfigMixin(BaseHWConfigMixin):
)
intrs = res.stdout
- for intr in intrs.split("\n"):
+ for i, intr in enumerate(intrs.split("\n")):
try:
int(intr)
+ cpu = cpus[i % len(cpus)]
netns.run(
"echo -n {} > /proc/irq/{}/smp_affinity_list".format(
cpu, intr.strip()
--
2.26.2