[seastar-dev] [PATCH v1] scripts/perftune.py: introduce --compute-cpu-mask argument

2 views
Skip to first unread message

Vlad Zolotarov

<vladz@scylladb.com>
unread,
Oct 3, 2022, 9:45:39 PMOct 3
to seastar-dev@googlegroups.com, Vlad Zolotarov
Introduce the ability to provide the second component of the left side
of the invariant:

compute_cpu_mask | irq_cpu_mask == cpu_mask

We want to allow providing only one of the two among 'compute_cpu_mask'
and 'irq_cpu_mask' so that the missing one can be deducted out of the given
one and the value of 'cpu_mask'.
---
scripts/perftune.py | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/scripts/perftune.py b/scripts/perftune.py
index 39e6fe203..f25c2fd8e 100755
--- a/scripts/perftune.py
+++ b/scripts/perftune.py
@@ -342,6 +342,8 @@ class PerfTunerBase(metaclass=abc.ABCMeta):
self.mode = PerfTunerBase.SupportedModes[self.args.mode]
elif args.irq_cpu_mask:
self.irqs_cpu_mask = args.irq_cpu_mask
+ elif args.compute_cpu_mask:
+ self.compute_cpu_mask = args.compute_cpu_mask
else:
self.irqs_cpu_mask = auto_detect_irq_mask(self.cpu_mask, self.cores_per_irq_core)

@@ -486,6 +488,27 @@ class PerfTunerBase(metaclass=abc.ABCMeta):
"""
return self.__compute_cpu_mask

+ @compute_cpu_mask.setter
+ def compute_cpu_mask(self, new_compute_cpu_mask):
+ self.__compute_cpu_mask = new_compute_cpu_mask
+
+ # Sanity check
+ if PerfTunerBase.cpu_mask_is_zero(self.__compute_cpu_mask):
+ raise PerfTunerBase.CPUMaskIsZeroException("Bad configuration: zero Compute CPU mask is given")
+
+ if run_hwloc_calc([self.__compute_cpu_mask]) == run_hwloc_calc([self.cpu_mask]):
+ # Special case: if Compute CPU mask is the same as total CPU mask - set an IRQ CPU mask to cpu_mask
+ self.__irq_cpu_mask = self.cpu_mask
+ else:
+ # Otherwise, a Compute CPU mask is a CPU mask without IRQ CPU mask bits
+ self.__irq_cpu_mask = run_hwloc_calc([self.cpu_mask, f"~{self.__compute_cpu_mask}"])
+
+ # Sanity check
+ if PerfTunerBase.cpu_mask_is_zero(self.__irq_cpu_mask):
+ raise PerfTunerBase.CPUMaskIsZeroException(
+ f"Bad configuration: cpu_mask:{self.cpu_mask}, compute_cpu_mask:{self.__compute_cpu_mask}: "
+ f"results in a zero-mask for IRQ")
+
@property
def irqs_cpu_mask(self):
"""
@@ -1549,6 +1572,7 @@ argp.add_argument('--verbose', action='store_true', help="be more verbose about
argp.add_argument('--tune', choices=TuneModes.names(), help="components to configure (may be given more than once)", action='append', default=[])
argp.add_argument('--cpu-mask', help="mask of cores to use, by default use all available cores", metavar='MASK')
argp.add_argument('--irq-cpu-mask', help="mask of cores to use for IRQs binding", metavar='MASK')
+argp.add_argument('--compute-cpu-mask', help="mask of cores to use for Compute", metavar='MASK')
argp.add_argument('--dir', help="directory to optimize (may appear more than once)", action='append', dest='dirs', default=[])
argp.add_argument('--dev', help="device to optimize (may appear more than once), e.g. sda1", action='append', dest='devs', default=[])
argp.add_argument('--options-file', help="configuration YAML file")
@@ -1628,6 +1652,9 @@ def parse_options_file(prog_args):
if 'irq_cpu_mask' in y and not prog_args.irq_cpu_mask:
prog_args.irq_cpu_mask = parse_cpu_mask_from_yaml(y, 'irq_cpu_mask', prog_args.options_file)

+ if 'compute_cpu_mask' in y and not prog_args.compute_cpu_mask:
+ prog_args.compute_cpu_mask = parse_cpu_mask_from_yaml(y, 'compute_cpu_mask', prog_args.options_file)
+
if 'dir' in y:
prog_args.dirs = extend_and_unique(prog_args.dirs, y['dir'])

@@ -1670,6 +1697,9 @@ def dump_config(prog_args):
if prog_args.irq_cpu_mask:
prog_options['irq_cpu_mask'] = prog_args.irq_cpu_mask

+ if prog_args.compute_cpu_mask:
+ prog_options['compute_cpu_mask'] = prog_args.compute_cpu_mask
+
if prog_args.dirs:
prog_options['dir'] = list(set(prog_args.dirs))

@@ -1720,10 +1750,19 @@ if not args.cpu_mask:
args.cpu_mask = run_hwloc_calc(['all'])
##########################################

+# Sanity: at most one of irq_cpu_mask or a compute_cpu_mask should be given - not both!
+# The one that is not given is going to be calculated as 'cpu_mask' ^ <given value>
+if args.irq_cpu_mask and args.compute_cpu_mask:
+ sys.exit("ERROR: Only one of IRQ CPU mask and compute CPU mask may be given - not both")
+
# Sanity: irq_cpu_mask should be a subset of cpu_mask
if args.irq_cpu_mask and run_hwloc_calc([args.cpu_mask]) != run_hwloc_calc([args.cpu_mask, args.irq_cpu_mask]):
sys.exit("ERROR: IRQ CPU mask({}) must be a subset of CPU mask({})".format(args.irq_cpu_mask, args.cpu_mask))

+# Sanity: compute_cpu_mask should be a subset of cpu_mask
+if args.compute_cpu_mask and run_hwloc_calc([args.cpu_mask]) != run_hwloc_calc([args.cpu_mask, args.compute_cpu_mask]):
+ sys.exit("ERROR: IRQ CPU mask({}) must be a subset of CPU mask({})".format(args.irq_cpu_mask, args.cpu_mask))
+
if args.dump_options_file:
dump_config(args)
sys.exit(0)
--
2.34.1

Reply all
Reply to author
Forward
0 new messages