Skip to contentSkip to conversation

rteval: cpuset placement for measurement and load overlap

PATCH New John Kacur 1 participant 9 messages Sep 22

lore
Share & tools
lore

John Kacur

author
#0 lore raw

cover rteval: cpuset placement for measurement and load overlap

This series improves how rteval places measurement and load workloads when --cpusets is used, and adds the ability to confine loads to their own cpuset.

Background: rteval --cpusets creates the rteval_measurement cpuset as a cgroup-v2 isolated partition, which removes its CPUs from the root cgroup's effective set. Loads run in the root cgroup bound only by CPU affinity (taskset). In the
default run both cpulists default to all online CPUs (100% overlap), so the isolated partition starves the taskset-bound loads, kcompile fails, and rteval exits non-zero. This is why several cpuset tests had been skipped.

The series is in two parts.

Part 1 - overlap validation + --measurement-member (patches 1-6):
Fail loudly by default, and let the user explicitly opt into co-location. A new --measurement-member flag flips rteval_measurement to a member partition so loads and measurement may legally share CPUs. When measurement is isolated and the load/measurement cpulists overlap without --measurement-member, rteval now exits early with a clear message pointing at the two ways forward (add --measurement-member, or supply disjoint cpulists). The check is gated on loads actually running (not --noload / --onlyload) to avoid firing spuriously. The previously skipped cpuset tests are re-enabled and updated for the new behavior.

Part 2 - loads in a cpuset (patches 7-8):
A new opt-in --loads-cpuset flag confines load workloads to their own rteval_loads member cpuset instead of relying only on taskset. It is purely
additive: without the flag, loads use taskset exactly as before. A cpuset is a hard ceiling the whole kcompile/hackbench descendant subtree inherits and cannot escape (taskset masks can be widened via sched_setaffinity), and it lays the groundwork for NUMA memory binding. Placement uses a shared self-placement-before-exec helper (cpuset_preexec) that the measurement modules were refactored onto as well. Patch 7 is a standalone bugfix for an unguarded m[1].lower() over the loads config section that the new boolean option would otherwise crash on.

Tested on a root machine: the full cpuset shell suite passes, including the overlapping-member case (--measurement-member together with --loads-cpuset).

John Kacur (8):
rteval: Add CpuList intersection/difference helpers
rteval: Don't create measurement cpuset with --onlyload
rteval: Add --measurement-member and guard against measurement/load
overlap
rteval: Re-enable cpuset overlap tests for the new behavior
rteval: Move --measurement-member into the measurement module option
group
rteval: Add tests for overlap-check gating and --measurement-member
help
rteval: Guard load module config iteration against non-string values
rteval: Add --loads-cpuset to confine loads to a member cpuset

 rteval-cmd                               |  51 +-
 rteval/__init__.py                       |  42 +-
 rteval/cpulist_utils.py                  |  26 +
 rteval/cpuset.py                         |  37 ++
 rteval/cpusetmanager.py                  | 125 +++--
 rteval/modules/__init__.py               |  16 +
 rteval/modules/loads/__init__.py         |   6 +-
 rteval/modules/loads/hackbench.py        |   7 +-
 rteval/modules/loads/kcompile.py         |  12 +-
 rteval/modules/loads/stressng.py         |   7 +-
 rteval/modules/measurement/cyclictest.py |  13 +-
 rteval/modules/measurement/timerlat.py   |  13 +-
 tests/cpusets/test-cpusets.sh            | 573 +++++++++++++++++++----
 tests/test_cpulist_class.py              |  60 +++
 tests/test_cpusetmanager.py              | 129 +++++
 15 files changed, 950 insertions(+), 167 deletions(-)
Signature · 1 line
2.55.0
author
#1 lore raw

PATCH 1/8 rteval: Add CpuList intersection/difference helpers

The CpuList class exposed filtering helpers (online, isolated, nonisolated) but no set operations, so callers computed CPU-list intersections and differences ad-hoc with raw list comprehensions.

Add chainable intersection() and difference() methods to CpuList, each accepting either a CpuList or a plain list and returning a new CpuList. This gives one reusable, tested place for CPU-list set logic instead of scattering the same comprehensions across the code base.

Refactor the housekeeping-vs-measurement/load conflict checks and the housekeeping filtering in rteval-cmd to use the new methods. This is
behavior-preserving: the conflict messages render the same collapsed CPU string, and the filtered lists are identical.

Add unit tests for the new methods to tests/test_cpulist_class.py.

Assisted-by Claude:claude-opus-4-8
---
 rteval-cmd                  | 13 ++++----
 rteval/cpulist_utils.py     | 26 ++++++++++++++++
 tests/test_cpulist_class.py | 60 +++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 6 deletions(-)
rteval-cmd +7 -6
index 69fad2cc80e4..438ead95f843 100755
@@ -448,30 +448,31 @@ if __name__ == '__main__':
 
         # Check for conflicts between housekeeping and measurement/load cpulists
         if housekeeping_cpus:
+            housekeeping = CpuList(housekeeping_cpus)
             msrcfg_cpus = CpuList(msrcfg.cpulist).cpus if msrcfg.cpulist else []
             ldcfg_cpus = CpuList(ldcfg.cpulist).cpus if ldcfg.cpulist else []
 
             # Check measurement conflicts
             if msrcfg_cpulist_present:
-                conflicts = [cpu for cpu in housekeeping_cpus if cpu in msrcfg_cpus]
+                conflicts = housekeeping.intersection(msrcfg_cpus)
                 if conflicts:
                     raise RuntimeError(
-                        f"Housekeeping CPUs {collapse_cpulist(conflicts)} conflict with "
+                        f"Housekeeping CPUs {conflicts} conflict with "
                         f"--measurement-cpulist {msrcfg.cpulist}"
                     )
 
             # Check load conflicts
             if ldcfg_cpulist_present:
-                conflicts = [cpu for cpu in housekeeping_cpus if cpu in ldcfg_cpus]
+                conflicts = housekeeping.intersection(ldcfg_cpus)
                 if conflicts:
                     raise RuntimeError(
-                        f"Housekeeping CPUs {collapse_cpulist(conflicts)} conflict with "
+                        f"Housekeeping CPUs {conflicts} conflict with "
                         f"--loads-cpulist {ldcfg.cpulist}"
                     )
 
             # Filter out housekeeping CPUs from measurement and load lists
-            msrcfg_cpus = [cpu for cpu in msrcfg_cpus if cpu not in housekeeping_cpus]
-            ldcfg_cpus = [cpu for cpu in ldcfg_cpus if cpu not in housekeeping_cpus]
+            msrcfg_cpus = CpuList(msrcfg_cpus).difference(housekeeping).cpus
+            ldcfg_cpus = CpuList(ldcfg_cpus).difference(housekeeping).cpus
             msrcfg.cpulist = collapse_cpulist(msrcfg_cpus) if msrcfg_cpus else ""
             ldcfg.cpulist = collapse_cpulist(ldcfg_cpus) if ldcfg_cpus else ""
 
rteval/cpulist_utils.py +26 -0
index ac91651b1d9f..859ed56381e7 100644
@@ -111,6 +111,32 @@ class CpuList:
         """
         return CpuList(nonisolated_cpulist(self._cpus))
 
+    def intersection(self, other):
+        """
+        Return a new CpuList of CPUs present in both this list and other.
+
+        Args:
+            other: A CpuList or a list of CPU numbers
+
+        Returns:
+            CpuList: New instance with the CPUs common to both
+        """
+        other_cpus = other.cpus if isinstance(other, CpuList) else [int(cpu) for cpu in other]
+        return CpuList(list(set(self._cpus) & set(other_cpus)))
+
+    def difference(self, other):
+        """
+        Return a new CpuList of CPUs in this list but not in other.
+
+        Args:
+            other: A CpuList or a list of CPU numbers
+
+        Returns:
+            CpuList: New instance with this list's CPUs minus other's
+        """
+        other_cpus = other.cpus if isinstance(other, CpuList) else [int(cpu) for cpu in other]
+        return CpuList(list(set(self._cpus) - set(other_cpus)))
+
     def __str__(self):
         """Return collapsed string representation (e.g., '0-7,9-11')"""
         return collapse_cpulist(self._cpus)
tests/test_cpulist_class.py +60 -0

72 lines not on this page · raw message

Signature · 1 line
2.55.0
author
#2 lore raw

PATCH 2/8 rteval: Don't create measurement cpuset with --onlyload

In reply to John Kacur

--onlyload runs the loads but no measurement threads, yet CpusetManager always created the rteval_measurement cpuset as an isolated partition. Nothing is ever migrated into it in this mode, so it served only to remove its CPUs from the root cgroup where the taskset-bound loads run, leaving those loads with fewer (or no) usable CPUs for no benefit.

Add a create_measurement parameter to CpusetManager (default True) and skip creating the measurement cpuset when it is False. rteval-cmd passes create_measurement=not onlyload, so --onlyload now runs loads without an empty isolated measurement partition getting in their way.

Add a unit test asserting the measurement cpuset is not created when create_measurement is False.

Assisted-by Claude:claude-opus-4-8
---
 rteval-cmd                  |  3 ++-
 rteval/cpusetmanager.py     | 22 ++++++++++++++--------
 tests/test_cpusetmanager.py | 18 ++++++++++++++++++
 3 files changed, 34 insertions(+), 9 deletions(-)
rteval-cmd +2 -1
index 438ead95f843..7a8512e1a254 100755
@@ -572,7 +572,8 @@ if __name__ == '__main__':
                 housekeeping_cpus=housekeeping_cpus,
                 measurement_cpus=msrcfg_cpus,
                 logger=logger,
-                housekeeping_isolated=rtevcfg.housekeeping_isolated
+                housekeeping_isolated=rtevcfg.housekeeping_isolated,
+                create_measurement=not rtevcfg.onlyload
             )
 
         # Pass cpuset_manager to RtEval (None if not using cpusets)
rteval/cpusetmanager.py +14 -8
index a204312eda9a..8b257731b4f1 100644
@@ -23,7 +23,8 @@ class CpusetManager:
 
     Creates 1-2 cpusets based on configuration:
     - rteval_housekeeping: Only if housekeeping_cpus specified
-    - rteval_measurement: Always created for measurement workloads
+    - rteval_measurement: Created unless create_measurement is False
+      (e.g. --onlyload, which runs no measurement workloads)
 
     Load workloads use taskset for CPU affinity (no cpuset needed).
 
@@ -71,7 +72,7 @@ class CpusetManager:
             except Exception as e:
                 logger.log(Log.WARN, f"Failed to clean up {cpuset_name}: {e}")
 
-    def __init__(self, housekeeping_cpus, measurement_cpus, logger, housekeeping_isolated=False):
+    def __init__(self, housekeeping_cpus, measurement_cpus, logger, housekeeping_isolated=False, create_measurement=True):
         """
         Initialize cpuset manager
 
@@ -80,6 +81,8 @@ class CpusetManager:
             measurement_cpus: List of CPU integers for measurement workloads
             logger: rteval Log instance for logging
             housekeeping_isolated: If True, use partition=isolated for housekeeping (default: False = partition=member)
+            create_measurement: If False, skip creating the rteval_measurement cpuset
+                (e.g. --onlyload, which runs no measurement workloads; default: True)
 
         Note: Load workloads use taskset for CPU affinity and don't need cpusets.
         """
@@ -93,6 +96,7 @@ class CpusetManager:
         self.measurement_cpus = measurement_cpus
         self.logger = logger
         self.housekeeping_isolated = housekeeping_isolated
+        self.create_measurement = create_measurement
 
         # Cpuset objects (will be created in __enter__)
         self.housekeeping_cpuset = None
@@ -123,12 +127,14 @@ class CpusetManager:
             self.housekeeping_cpuset.assign_cpus(collapse_cpulist(self.housekeeping_cpus))
             self.housekeeping_cpuset.write_cpu_exclusive(self.housekeeping_isolated)  # partition=isolated if True, member if False
 
-        # Create measurement cpuset
-        self.logger.log(Log.DEBUG, f"Creating rteval_measurement cpuset with CPUs {collapse_cpulist(self.measurement_cpus)}")
-        self.measurement_cpuset = Cpuset('rteval_measurement')
-        self.measurement_cpuset.write_memnode(self.numa_nodes)
-        self.measurement_cpuset.assign_cpus(collapse_cpulist(self.measurement_cpus))
-        self.measurement_cpuset.write_cpu_exclusive(True)  # partition=isolated
+        # Create measurement cpuset (skipped when there are no measurement
+        # workloads, e.g. --onlyload)
+        if self.create_measurement:
+            self.logger.log(Log.DEBUG, f"Creating rteval_measurement cpuset with CPUs {collapse_cpulist(self.measurement_cpus)}")
+            self.measurement_cpuset = Cpuset('rteval_measurement')
+            self.measurement_cpuset.write_memnode(self.numa_nodes)
+            self.measurement_cpuset.assign_cpus(collapse_cpulist(self.measurement_cpus))
+            self.measurement_cpuset.write_cpu_exclusive(True)  # partition=isolated
 
         self.logger.log(Log.INFO, "Cpusets created successfully")
         return self
tests/test_cpusetmanager.py +18 -0
index 984e0f900edf..8d69fed90443 100644
@@ -132,6 +132,24 @@ class TestCpusetManagerHousekeepingPartitions(unittest.TestCase):
             self.assertTrue(os.path.exists(measurement_path),
                           "Measurement cpuset should exist")
 
+    def test_no_measurement_cpuset_created_when_create_measurement_false(self):
+        """Test that measurement cpuset is not created when create_measurement=False (e.g. --onlyload)"""
+        with CpusetManager(
+            housekeeping_cpus=[0, 1],
+            measurement_cpus=[2, 3],
+            logger=self.logger,
+            create_measurement=False
+        ) as manager:
+            # Check that measurement cpuset does NOT exist
+            measurement_path = '/sys/fs/cgroup/rteval_measurement'
+            self.assertFalse(os.path.exists(measurement_path),
+                           "Measurement cpuset should not exist when create_measurement is False")
+
+            # Check that housekeeping cpuset DOES exist
+            hk_path = '/sys/fs/cgroup/rteval_housekeeping'
+            self.assertTrue(os.path.exists(hk_path),
+                          "Housekeeping cpuset should exist")
+
 
 @unittest.skipUnless(os.geteuid() == 0, "Requires root permissions")
 @unittest.skipUnless(cpuset.CpusetsInit().supported, "Requires cgroup v2 support")
Signature · 1 line
2.55.0
author
#3 lore raw

PATCH 3/8 rteval: Add --measurement-member and guard against measurement/load overlap

In reply to John Kacur

By default, --cpusets creates the rteval_measurement cpuset as a cgroup v2 isolated partition, which removes its CPUs from the root cgroup where the taskset-bound loads run. When the measurement and load CPU lists overlap (as they do by default, when both cover all online CPUs), the loads are left with no usable CPUs and the run fails in a confusing way.

Add a --measurement-member option that flips the measurement cpuset to a member partition, letting loads and measurement share CPUs (co-location). Like --housekeeping-isolated, it requires --cpusets. The partition type is threaded through to CpusetManager via a measurement_member parameter, replacing the previously hardcoded isolated partition.

When --cpusets is used with an isolated measurement partition and the measurement and load CPU lists overlap, fail loud with a message that points to the two ways forward: add --measurement-member to co-locate, or supply disjoint --measurement-cpulist and --loads-cpulist. The check is skipped when no loads run (--noload) or no measurement runs (--onlyload), since neither can produce the collision.

Add unit tests for the member partition type and the --cpusets guard.

Assisted-by Claude:claude-opus-4-8
---
 rteval-cmd                  | 30 +++++++++++++++++++++++++++++-
 rteval/cpusetmanager.py     | 10 +++++++---
 tests/test_cpusetmanager.py | 29 +++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 4 deletions(-)
rteval-cmd +29 -1
index 7a8512e1a254..46a09c9de3c6 100755
@@ -126,6 +126,9 @@ def parse_options(cfg, parser, cmdargs):
     parser.add_argument("--housekeeping-isolated", dest="rteval___housekeeping_isolated",
                       action="store_true", default=False,
                       help="make housekeeping cpuset use partition=isolated instead of member (requires --cpusets and --housekeeping)")
+    parser.add_argument("--measurement-member", dest="rteval___measurement_member",
+                      action="store_true", default=False,
+                      help="make measurement cpuset use partition=member instead of isolated, allowing loads and measurement to share CPUs (requires --cpusets)")
     parser.add_argument("--warn-non-isolated-core-sharing", dest="rteval___warn_non_isolated_core_sharing",
                       action="store_true", default=False,
                       help="warn about measurement and load CPUs sharing cores even when neither is isolated")
@@ -420,6 +423,11 @@ if __name__ == '__main__':
             if not rtevcfg.housekeeping:
                 raise RuntimeError("--housekeeping-isolated requires --housekeeping")
 
+        # Validate --measurement-member usage
+        if rtevcfg.measurement_member:
+            if not rtevcfg.cpusets:
+                raise RuntimeError("--measurement-member requires --cpusets")
+
         # Validate and process housekeeping CPUs
         housekeeping_cpus = []
         if rtevcfg.housekeeping:
@@ -517,6 +525,25 @@ if __name__ == '__main__':
         for warning in core_warnings:
             logger.log(Log.WARN, warning)
 
+        # With cpusets, the measurement cpuset is an isolated partition by
+        # default, which removes its CPUs from the root cgroup where the
+        # taskset-bound loads run. If the measurement and load CPUs overlap,
+        # the loads are left with no usable CPUs. Fail loud unless the user
+        # opts into a shared (member) measurement partition. Skipped when no
+        # loads run (--noload) or no measurement runs (--onlyload).
+        if rtevcfg.cpusets and not rtevcfg.measurement_member \
+                and not rtevcfg.noload and not rtevcfg.onlyload:
+            overlap = CpuList(msrcfg_cpus).intersection(ldcfg_cpus)
+            if overlap:
+                raise RuntimeError(
+                    f"Measurement CPUs {CpuList(msrcfg_cpus)} and load CPUs "
+                    f"{CpuList(ldcfg_cpus)} overlap on {overlap}, but the measurement "
+                    "cpuset is an isolated partition, which would remove those CPUs "
+                    "from the loads. Either add --measurement-member to co-locate "
+                    "loads and measurement on the same CPUs, or supply disjoint "
+                    "--measurement-cpulist and --loads-cpulist."
+                )
+
         # if --summarize was specified then just parse the XML, print it and exit
         if cmd_opts.rteval___summarize:
             for xmlfile in cmd_opts.rteval___summarize:
@@ -573,7 +600,8 @@ if __name__ == '__main__':
                 measurement_cpus=msrcfg_cpus,
                 logger=logger,
                 housekeeping_isolated=rtevcfg.housekeeping_isolated,
-                create_measurement=not rtevcfg.onlyload
+                create_measurement=not rtevcfg.onlyload,
+                measurement_member=rtevcfg.measurement_member
             )
 
         # Pass cpuset_manager to RtEval (None if not using cpusets)
rteval/cpusetmanager.py +7 -3
index 8b257731b4f1..0c99744b42cf 100644
@@ -72,7 +72,7 @@ class CpusetManager:
             except Exception as e:
                 logger.log(Log.WARN, f"Failed to clean up {cpuset_name}: {e}")
 
-    def __init__(self, housekeeping_cpus, measurement_cpus, logger, housekeeping_isolated=False, create_measurement=True):
+    def __init__(self, housekeeping_cpus, measurement_cpus, logger, housekeeping_isolated=False, create_measurement=True, measurement_member=False):
         """
         Initialize cpuset manager
 
@@ -83,6 +83,8 @@ class CpusetManager:
             housekeeping_isolated: If True, use partition=isolated for housekeeping (default: False = partition=member)
             create_measurement: If False, skip creating the rteval_measurement cpuset
                 (e.g. --onlyload, which runs no measurement workloads; default: True)
+            measurement_member: If True, use partition=member for measurement, allowing
+                loads and measurement to share CPUs (default: False = partition=isolated)
 
         Note: Load workloads use taskset for CPU affinity and don't need cpusets.
         """
@@ -97,6 +99,7 @@ class CpusetManager:
         self.logger = logger
         self.housekeeping_isolated = housekeeping_isolated
         self.create_measurement = create_measurement
+        self.measurement_member = measurement_member
 
         # Cpuset objects (will be created in __enter__)
         self.housekeeping_cpuset = None
@@ -130,11 +133,12 @@ class CpusetManager:
         # Create measurement cpuset (skipped when there are no measurement
         # workloads, e.g. --onlyload)
         if self.create_measurement:
-            self.logger.log(Log.DEBUG, f"Creating rteval_measurement cpuset with CPUs {collapse_cpulist(self.measurement_cpus)}")
+            partition_type = "member" if self.measurement_member else "isolated"
+            self.logger.log(Log.DEBUG, f"Creating rteval_measurement cpuset with CPUs {collapse_cpulist(self.measurement_cpus)} (partition={partition_type})")
             self.measurement_cpuset = Cpuset('rteval_measurement')
             self.measurement_cpuset.write_memnode(self.numa_nodes)
             self.measurement_cpuset.assign_cpus(collapse_cpulist(self.measurement_cpus))
-            self.measurement_cpuset.write_cpu_exclusive(True)  # partition=isolated
+            self.measurement_cpuset.write_cpu_exclusive(not self.measurement_member)  # partition=isolated unless member
 
         self.logger.log(Log.INFO, "Cpusets created successfully")
         return self
tests/test_cpusetmanager.py +29 -0
index 8d69fed90443..4b834a0fb218 100644
@@ -114,6 +114,20 @@ class TestCpusetManagerHousekeepingPartitions(unittest.TestCase):
             self.assertEqual(partition, 'isolated',
                            "Measurement cpuset should always be partition=isolated")
 
+    def test_measurement_member_flag(self):
+        """Test that measurement_member=True makes measurement partition=member"""
+        with CpusetManager(
+            housekeeping_cpus=[0, 1],
+            measurement_cpus=[2, 3],
+            logger=self.logger,
+            measurement_member=True
+        ) as manager:
+            measurement_partition_file = '/sys/fs/cgroup/rteval_measurement/cpuset.cpus.partition'
+            with open(measurement_partition_file) as f:
+                partition = f.read().strip()
+            self.assertEqual(partition, 'member',
+                           "Measurement cpuset should have partition=member when measurement_member is True")
+
     def test_no_housekeeping_cpuset_created_when_empty(self):
         """Test that housekeeping cpuset is not created when housekeeping_cpus is empty"""
         with CpusetManager(
@@ -185,6 +199,21 @@ class TestCpusetManagerCLIIntegration(unittest.TestCase):
         self.assertIn('requires --cpusets', result.stderr,
                      "Error message should mention --cpusets requirement")
 
+    def test_measurement_member_requires_cpusets(self):
+        """Test that --measurement-member requires --cpusets"""
+        result = subprocess.run(
+            [sys.executable, '/home/jkacur/src/rteval/rteval-cmd',
+             '--measurement-member',
+             '--duration', '1', '--onlyload'],
+            capture_output=True,
+            text=True
+        )
+
+        self.assertNotEqual(result.returncode, 0,
+                          "--measurement-member without --cpusets should fail")
+        self.assertIn('requires --cpusets', result.stderr,
+                     "Error message should mention --cpusets requirement")
+
     def test_housekeeping_isolated_requires_housekeeping(self):
         """Test that --housekeeping-isolated requires --housekeeping"""
         result = subprocess.run(
Signature · 1 line
2.55.0
author
#4 lore raw

PATCH 4/8 rteval: Re-enable cpuset overlap tests for the new behavior

In reply to John Kacur

Tests 2, 5, and 8 in the cpuset integration suite were skipped pending the measurement/load overlap design decision. Re-enable them for the new behavior:

- Test 2 (same CPUs, no housekeeping): without --measurement-member, assert rteval exits non-zero and the error points to --measurement-member; with --measurement-member, assert exit 0 and partition=member.
- Test 5 (housekeeping without isolcpus): without --measurement-member, assert early non-zero exit on the default overlap; with --measurement-member, assert exit 0 and the housekeeping cpuset is created.
- Test 8 (--measurement-run-on-isolcpus): confine loads to the non-isolated CPUs so measurement (isolcpus) and loads are disjoint, keeping the measurement cpuset an isolated partition; assert exit 0. Still skips when no isolcpus are configured.

Assisted-by Claude:claude-opus-4-8
---
 tests/cpusets/test-cpusets.sh | 212 ++++++++++++++++++++--------------
 1 file changed, 127 insertions(+), 85 deletions(-)
tests/cpusets/test-cpusets.sh +127 -85
index 5e1293532aca..39f837c177ae 100755
@@ -208,38 +208,42 @@ test_prerequisites() {
 
 test_same_cpus_no_housekeeping() {
     ((TESTS_RUN++)) || true
-    print_test "Same CPUs - No Housekeeping (Measurement Cpuset Only)"
+    print_test "Same CPUs - Overlap Handling (isolated fails, --measurement-member works)"
 
     cleanup_cpusets
 
-    # TODO: Temporarily skipped pending a design decision (see below).
-    # This runs measurement and loads on the SAME CPUs. The measurement cpuset
-    # is created as an isolated partition, which removes those CPUs from the root
-    # cgroup; the taskset-bound loads then cannot run there and kcompile fails,
-    # so rteval exits non-zero. (This test currently does not check rteval's exit
-    # code, so it silently "passes" today.) The fix - the measurement cpuset
-    # partition type / load CPU placement when measurement and loads overlap -
-    # is still under discussion. Re-enable (and add an rteval exit-code check)
-    # once that is resolved.
-    print_info "SKIPPED: pending design decision on measurement cpuset partition/overlap behavior"
-    ((TESTS_PASSED++)) || true
-    return 0
-
     local cpus=$(get_test_cpus)
     local msr_cpus=$(echo $cpus | awk '{print $2}')
 
-    print_info "Running: $RTEVAL_CMD --cpusets --measurement-cpulist $msr_cpus --loads-cpulist $msr_cpus -d $TEST_DURATION"
+    local all_good=true
 
-    # Run rteval in background
-    timeout 60s $RTEVAL_CMD --cpusets --measurement-cpulist "$msr_cpus" --loads-cpulist "$msr_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
+    # Flavor A: overlap with the default isolated measurement partition must
+    # fail early, because isolating those CPUs would leave the taskset loads
+    # with nowhere to run.
+    print_info "Running (expect early exit): $RTEVAL_CMD --cpusets --measurement-cpulist $msr_cpus --loads-cpulist $msr_cpus -d $TEST_DURATION"
+    if timeout 60s $RTEVAL_CMD --cpusets --measurement-cpulist "$msr_cpus" --loads-cpulist "$msr_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1; then
+        print_fail "rteval succeeded, but overlap with an isolated measurement partition should fail early"
+        all_good=false
+    else
+        print_info "rteval exited non-zero on overlap: OK"
+        if grep -q -- "--measurement-member" "$LOG_FILE" 2>/dev/null; then
+            print_info "Error message points to --measurement-member: OK"
+        else
+            print_fail "Overlap error message missing guidance"
+            all_good=false
+        fi
+    fi
+
+    cleanup_cpusets
+
+    # Flavor B: the same overlap with --measurement-member co-locates loads and
+    # measurement on a member partition and succeeds.
+    print_info "Running (expect success): $RTEVAL_CMD --cpusets --measurement-member --measurement-cpulist $msr_cpus --loads-cpulist $msr_cpus -d $TEST_DURATION"
+    timeout 60s $RTEVAL_CMD --cpusets --measurement-member --measurement-cpulist "$msr_cpus" --loads-cpulist "$msr_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
     local rteval_pid=$!
 
-    # Wait for cpusets to be created
     sleep 2
 
-    # Check during execution
-    local all_good=true
-
     if check_cpuset_exists "rteval_measurement"; then
         print_info "rteval_measurement cpuset created: OK"
     else
@@ -247,31 +251,22 @@ test_same_cpus_no_housekeeping() {
         all_good=false
     fi
 
-    if ! check_cpuset_exists "rteval_loads"; then
-        print_info "No rteval_loads cpuset (loads use taskset): OK"
-    else
-        print_fail "Unexpected rteval_loads cpuset found"
-        all_good=false
-    fi
-
-    if check_cpuset_cpus "rteval_measurement" "$msr_cpus"; then
-        print_info "Measurement CPU assignment correct: OK"
+    if check_cpuset_partition "rteval_measurement" "member"; then
+        print_info "Partition type is 'member': OK"
     else
-        print_fail "Measurement CPU assignment incorrect"
+        print_fail "Partition type is not 'member'"
         all_good=false
     fi
 
-    if check_cpuset_partition "rteval_measurement" "isolated"; then
-        print_info "Partition type is 'isolated': OK"
+    wait $rteval_pid
+    local rc=$?
+    if [ "$rc" -eq 0 ]; then
+        print_info "rteval exited 0 with --measurement-member: OK"
     else
-        print_fail "Partition type is not 'isolated'"
+        print_fail "rteval exited $rc with --measurement-member (expected 0)"
         all_good=false
     fi
 
-    # Wait for rteval to finish
-    wait $rteval_pid
-
-    # Check cleanup
     sleep 1
     if check_no_cpusets; then
         print_info "Cleanup successful: OK"
@@ -282,9 +277,9 @@ test_same_cpus_no_housekeeping() {
     fi
 
     if [ "$all_good" = true ]; then
-        print_pass "Measurement cpuset test"
+        print_pass "Same-CPU overlap handling test"
     else
-        print_fail "Measurement cpuset test"
+        print_fail "Same-CPU overlap handling test"
     fi
 }
 
@@ -439,18 +434,6 @@ test_housekeeping_without_isolcpus() {
 
     cleanup_cpusets
 
-    # TODO: Temporarily skipped pending a design decision.
-    # With '--cpusets --housekeeping' and no explicit --measurement-cpulist,
-    # the measurement cpuset defaults to all non-housekeeping CPUs as an
-    # isolated partition, which removes them from the root cgroup. The
-    # taskset-bound loads then have nowhere to run and kcompile fails, so
-    # rteval exits non-zero. The fix (measurement cpuset partition type /
-    # load CPU placement when measurement and loads overlap) is still under
-    # discussion. Re-enable this test once that is resolved.
-    print_info "SKIPPED: pending design decision on measurement cpuset partition/overlap behavior"
-    ((TESTS_PASSED++)) || true
-    return 0
-
     # Check if system has isolcpus
     local isolated=$(cat /sys/devices/system/cpu/isolated 2>/dev/null || echo "")
     print_info "System isolated CPUs: ${isolated:-none}"
@@ -458,22 +441,65 @@ test_housekeeping_without_isolcpus() {
     local cpus=$(get_test_cpus)
     local hk_cpus=$(echo $cpus | awk '{print $1}')
 
-    print_info "Running: $RTEVAL_CMD --cpusets --housekeeping $hk_cpus -d $TEST_DURATION"
+    local all_good=true
 
-    # This should succeed even if housekeeping CPUs are not in isolcpus
+    # Flavor A: with only --housekeeping, measurement and loads both default to
+    # the non-housekeeping CPUs, so the isolated measurement partition overlaps
+    # the loads and rteval must fail early.
+    print_info "Running (expect early exit): $RTEVAL_CMD --cpusets --housekeeping $hk_cpus -d $TEST_DURATION"
     if timeout 60s $RTEVAL_CMD --cpusets --housekeeping "$hk_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1; then
-        print_info "rteval succeeded with housekeeping without isolcpus requirement: OK"
-        sleep 1
+        print_fail "rteval succeeded, but default overlap with an isolated measurement partition should fail early"
+        all_good=false
+    else
+        print_info "rteval exited non-zero on default overlap: OK"
+    fi
 
-        if check_no_cpusets; then
-            print_info "Cleanup successful: OK"
-            print_pass "Housekeeping without isolcpus test"
-        else
-            print_fail "Cpusets not cleaned up"
-            cleanup_cpusets
-        fi
+    cleanup_cpusets
+
+    # Flavor B: adding --measurement-member co-locates loads and measurement on
+    # the non-housekeeping CPUs, so housekeeping without isolcpus succeeds.
+    print_info "Running (expect success): $RTEVAL_CMD --cpusets --housekeeping $hk_cpus --measurement-member -d $TEST_DURATION"
+    timeout 60s $RTEVAL_CMD --cpusets --housekeeping "$hk_cpus" --measurement-member -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
+    local rteval_pid=$!
+
+    sleep 2
+
+    if check_cpuset_exists "rteval_housekeeping"; then
+        print_info "rteval_housekeeping cpuset created (no isolcpus required): OK"
     else
-        print_fail "rteval failed with housekeeping (should work with cpusets)"
+        print_fail "rteval_housekeeping cpuset not created"
+        all_good=false
+    fi
+
+    if check_cpuset_cpus "rteval_housekeeping" "$hk_cpus"; then
+        print_info "Housekeeping CPU assignment correct: OK"
+    else
+        print_fail "Housekeeping CPU assignment incorrect"
+        all_good=false
+    fi
+
+    wait $rteval_pid
+    local rc=$?
+    if [ "$rc" -eq 0 ]; then
+        print_info "rteval exited 0 with housekeeping + --measurement-member: OK"
+    else
+        print_fail "rteval exited $rc (expected 0)"
+        all_good=false
+    fi
+
+    sleep 1
+    if check_no_cpusets; then
+        print_info "Cleanup successful: OK"
+    else
+        print_fail "Cpusets not cleaned up"
+        all_good=false
+        cleanup_cpusets
+    fi
+
+    if [ "$all_good" = true ]; then
+        print_pass "Housekeeping without isolcpus test"
+    else
+        print_fail "Housekeeping without isolcpus test"
     fi
 }
 
@@ -545,20 +571,10 @@ test_cleanup_on_interrupt() {
 
 test_measurement_run_on_isolcpus() {
     ((TESTS_RUN++)) || true
-    print_test "Measurement Run on isolcpus Flag"
+    print_test "Measurement Run on isolcpus Flag (disjoint loads)"
 
     cleanup_cpusets
 
-    # TODO: Temporarily skipped pending a design decision.
-    # On hosts WITH isolcpus this shares the same unresolved issue as tests 2
-    # and 5: the isolated measurement cpuset (affinity + isolcpus) removes its
-    # CPUs from the root cgroup, so taskset-bound loads on the affinity subset
-    # fail and rteval exits non-zero. Re-enable once the measurement cpuset
-    # partition type / load CPU placement (overlap) design decision is made.
-    print_info "SKIPPED: pending design decision on measurement cpuset partition/overlap behavior"
-    ((TESTS_PASSED++)) || true
-    return 0
-
     # Check if system has isolcpus
     local isolated=$(cat /sys/devices/system/cpu/isolated 2>/dev/null || echo "")
     if [ -z "$isolated" ]; then
@@ -569,34 +585,60 @@ test_measurement_run_on_isolcpus() {
 
     print_info "System isolated CPUs: $isolated"
 
-    # Run with --measurement-run-on-isolcpus and --cpusets
-    print_info "Running: $RTEVAL_CMD --cpusets --measurement-run-on-isolcpus -d $TEST_DURATION"
+    # Confine loads to the non-isolated CPUs so measurement (isolcpus) and loads
+    # are disjoint; the measurement cpuset can then stay an isolated partition
+    # without colliding with the taskset loads.
+    local repo_root=$(dirname "$RTEVAL_CMD")
+    local load_cpus=$(PYTHONPATH="$repo_root" python3 -c "from rteval.cpulist_utils import CpuList, collapse_cpulist; online=CpuList(open('/sys/devices/system/cpu/online').read().strip()); print(collapse_cpulist(online.difference(CpuList('$isolated')).cpus))")
 
-    timeout 60s $RTEVAL_CMD --cpusets --measurement-run-on-isolcpus -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
-    local rteval_pid=$!
+    if [ -z "$load_cpus" ]; then
+        print_info "SKIPPED: no non-isolated CPUs available for loads"
+        ((TESTS_PASSED++)) || true
+        return 0
+    fi
 
-    sleep 2
+    print_info "Non-isolated load CPUs: $load_cpus"
 
     local all_good=true
 
+    # Run with --measurement-run-on-isolcpus and --cpusets, loads confined to
+    # the non-isolated CPUs so they don't overlap the isolated measurement cpuset
+    print_info "Running: $RTEVAL_CMD --cpusets --measurement-run-on-isolcpus --loads-cpulist $load_cpus -d $TEST_DURATION"
+
+    timeout 60s $RTEVAL_CMD --cpusets --measurement-run-on-isolcpus --loads-cpulist "$load_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
+    local rteval_pid=$!
+
+    sleep 2
+
     # Should create measurement cpuset
     if check_cpuset_exists "rteval_measurement"; then
         print_info "rteval_measurement cpuset created: OK"
 
-        # Check that cpuset includes isolated CPUs
         local cpuset_cpus=$(cat /sys/fs/cgroup/rteval_measurement/cpuset.cpus 2>/dev/null)
         print_info "Measurement cpuset CPUs: $cpuset_cpus"
-
-        # Verify isolated CPUs are included (would need complex parsing, just verify cpuset exists)
-        print_info "Measurement cpuset includes access to isolated CPUs: OK"
     else
         print_fail "rteval_measurement cpuset not created"
         all_good=false
     fi
 
+    # Measurement stays an isolated partition (disjoint from loads)
+    if check_cpuset_partition "rteval_measurement" "isolated"; then
+        print_info "Partition type is 'isolated': OK"
+    else
+        print_fail "Partition type is not 'isolated'"
+        all_good=false
+    fi
+
     wait $rteval_pid
-    sleep 1
+    local rc=$?
+    if [ "$rc" -eq 0 ]; then
+        print_info "rteval exited 0 with disjoint isolcpus measurement/loads: OK"
+    else
+        print_fail "rteval exited $rc (expected 0)"
+        all_good=false
+    fi
 
+    sleep 1
     if check_no_cpusets; then
         print_info "Cleanup successful: OK"
     else
Signature · 1 line
2.55.0
author
#5 lore raw

PATCH 5/8 rteval: Move --measurement-member into the measurement module option group

In reply to John Kacur

--measurement-member was added to the top-level argument parser, so it rendered under the generic "options" section of --help instead of alongside its siblings (--measurement-cpulist, --measurement-run-on-isolcpus, --measurement-idle-set) in the "Group Options for measurement modules" group.

Add the flag in MeasurementModules.SetupModuleOptions instead, using dest=measurement___member (read as msrcfg.member) to match the convention already used by the other measurement placement options, and repoint the validation, overlap check, and CpusetManager construction in rteval-cmd accordingly. The flag name, guard, and behavior are unchanged.

Assisted-by Claude:claude-opus-4-8
---
 rteval-cmd                 | 9 +++------
 rteval/modules/__init__.py | 5 +++++
 2 files changed, 8 insertions(+), 6 deletions(-)
rteval-cmd +3 -6
index 46a09c9de3c6..15f6f505fed7 100755
@@ -126,9 +126,6 @@ def parse_options(cfg, parser, cmdargs):
     parser.add_argument("--housekeeping-isolated", dest="rteval___housekeeping_isolated",
                       action="store_true", default=False,
                       help="make housekeeping cpuset use partition=isolated instead of member (requires --cpusets and --housekeeping)")
-    parser.add_argument("--measurement-member", dest="rteval___measurement_member",
-                      action="store_true", default=False,
-                      help="make measurement cpuset use partition=member instead of isolated, allowing loads and measurement to share CPUs (requires --cpusets)")
     parser.add_argument("--warn-non-isolated-core-sharing", dest="rteval___warn_non_isolated_core_sharing",
                       action="store_true", default=False,
                       help="warn about measurement and load CPUs sharing cores even when neither is isolated")
@@ -424,7 +421,7 @@ if __name__ == '__main__':
                 raise RuntimeError("--housekeeping-isolated requires --housekeeping")
 
         # Validate --measurement-member usage
-        if rtevcfg.measurement_member:
+        if msrcfg.member:
             if not rtevcfg.cpusets:
                 raise RuntimeError("--measurement-member requires --cpusets")
 
@@ -531,7 +528,7 @@ if __name__ == '__main__':
         # the loads are left with no usable CPUs. Fail loud unless the user
         # opts into a shared (member) measurement partition. Skipped when no
         # loads run (--noload) or no measurement runs (--onlyload).
-        if rtevcfg.cpusets and not rtevcfg.measurement_member \
+        if rtevcfg.cpusets and not msrcfg.member \
                 and not rtevcfg.noload and not rtevcfg.onlyload:
             overlap = CpuList(msrcfg_cpus).intersection(ldcfg_cpus)
             if overlap:
@@ -601,7 +598,7 @@ if __name__ == '__main__':
                 logger=logger,
                 housekeeping_isolated=rtevcfg.housekeeping_isolated,
                 create_measurement=not rtevcfg.onlyload,
-                measurement_member=rtevcfg.measurement_member
+                measurement_member=msrcfg.member
             )
 
         # Pass cpuset_manager to RtEval (None if not using cpusets)
rteval/modules/__init__.py +5 -0
index b8c443e8e0c5..ad7891fcb3c8 100644
@@ -316,6 +316,11 @@ reference from the first import"""
                                   metavar='IDLESTATE',
                                   default=None,
                                   help='Idle state depth to set on cpus running measurement modules')
+            grparser.add_argument('--measurement-member',
+                                  dest='measurement___member',
+                                  action='store_true',
+                                  default=False,
+                                  help='make measurement cpuset use partition=member instead of isolated, allowing loads and measurement to share CPUs (requires --cpusets)')
             grparser.add_argument('--measurement-module',
                                   dest='measurement___measurement_module',
                                   type=str,
Signature · 1 line
2.55.0
author
#6 lore raw

PATCH 6/8 rteval: Add tests for overlap-check gating and --measurement-member help

In reply to John Kacur

Cover the remaining Phase 1 cpuset overlap cases:

- test_noload_skips_overlap_check: --cpusets --noload with a measurement subset (loads still default to all CPUs, so they overlap) must exit 0, guarding the 'not noload' gate that keeps the overlap check from firing spuriously when no loads run.
- test_onlyload_no_measurement_cpuset: --cpusets --onlyload must exit 0 and create no rteval_measurement cpuset (no measurement runs).
- test_measurement_member_help_text: --measurement-member and partition=member appear in --help output.

Assisted-by Claude:claude-opus-4-8
---
 tests/cpusets/test-cpusets.sh | 105 ++++++++++++++++++++++++++++++++++
 tests/test_cpusetmanager.py   |  14 +++++
 2 files changed, 119 insertions(+)
tests/cpusets/test-cpusets.sh +105 -0
index 39f837c177ae..0996d76ea1df 100755
@@ -535,6 +535,109 @@ test_backward_compatibility() {
     fi
 }
 
+test_noload_skips_overlap_check() {
+    ((TESTS_RUN++)) || true
+    print_test "Overlap Check Skipped with --noload"
+
+    cleanup_cpusets
+
+    local cpus=$(get_test_cpus)
+    local msr_cpus=$(echo $cpus | awk '{print $2}')
+
+    local all_good=true
+
+    # With --noload only the measurement runs, but the load cpulist still
+    # defaults to all online CPUs, so measurement and loads overlap. The overlap
+    # guard must be skipped (not rtevcfg.noload); regressing that gate would make
+    # this exit non-zero.
+    print_info "Running (expect success): $RTEVAL_CMD --cpusets --noload --measurement-cpulist $msr_cpus -d $TEST_DURATION"
+
+    timeout 60s $RTEVAL_CMD --cpusets --noload --measurement-cpulist "$msr_cpus" -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
+    local rteval_pid=$!
+
+    sleep 2
+
+    if check_cpuset_exists "rteval_measurement"; then
+        print_info "rteval_measurement cpuset created: OK"
+    else
+        print_fail "rteval_measurement cpuset not created"
+        all_good=false
+    fi
+
+    wait $rteval_pid
+    local rc=$?
+    if [ "$rc" -eq 0 ]; then
+        print_info "rteval exited 0 with --noload despite overlapping cpulists: OK"
+    else
+        print_fail "rteval exited $rc with --noload (expected 0; overlap check should be skipped)"
+        all_good=false
+    fi
+
+    sleep 1
+    if check_no_cpusets; then
+        print_info "Cleanup successful: OK"
+    else
+        print_fail "Cpusets not cleaned up"
+        all_good=false
+        cleanup_cpusets
+    fi
+
+    if [ "$all_good" = true ]; then
+        print_pass "--noload overlap-skip test"
+    else
+        print_fail "--noload overlap-skip test"
+    fi
+}
+
+test_onlyload_no_measurement_cpuset() {
+    ((TESTS_RUN++)) || true
+    print_test "No Measurement Cpuset with --onlyload"
+
+    cleanup_cpusets
+
+    local all_good=true
+
+    # With --onlyload no measurement runs, so the overlap check is skipped and no
+    # rteval_measurement cpuset should be created (loads use taskset).
+    print_info "Running (expect success): $RTEVAL_CMD --cpusets --onlyload -d $TEST_DURATION"
+
+    timeout 60s $RTEVAL_CMD --cpusets --onlyload -d "$TEST_DURATION" >> "$LOG_FILE" 2>&1 &
+    local rteval_pid=$!
+
+    sleep 2
+
+    if check_cpuset_exists "rteval_measurement"; then
+        print_fail "rteval_measurement cpuset created, but --onlyload runs no measurement"
+        all_good=false
+    else
+        print_info "No rteval_measurement cpuset created: OK"
+    fi
+
+    wait $rteval_pid
+    local rc=$?
+    if [ "$rc" -eq 0 ]; then
+        print_info "rteval exited 0 with --onlyload: OK"
+    else
+        print_fail "rteval exited $rc with --onlyload (expected 0)"
+        all_good=false
+    fi
+
+    sleep 1
+    if check_no_cpusets; then
+        print_info "Cleanup successful: OK"
+    else
+        print_fail "Cpusets not cleaned up"
+        all_good=false
+        cleanup_cpusets
+    fi
+
+    if [ "$all_good" = true ]; then
+        print_pass "--onlyload no-measurement-cpuset test"
+    else
+        print_fail "--onlyload no-measurement-cpuset test"
+    fi
+}
+
 test_cleanup_on_interrupt() {
     ((TESTS_RUN++)) || true
     print_test "Cleanup on Ctrl+C (Interrupt Handling)"
@@ -795,6 +898,8 @@ main() {
     test_with_housekeeping
     test_housekeeping_without_isolcpus
     test_backward_compatibility
+    test_noload_skips_overlap_check
+    test_onlyload_no_measurement_cpuset
     test_cleanup_on_interrupt
 
     # Tests that require isolcpus (will skip if not available)
tests/test_cpusetmanager.py +14 -0
index 4b834a0fb218..74466be89615 100644
@@ -214,6 +214,20 @@ class TestCpusetManagerCLIIntegration(unittest.TestCase):
         self.assertIn('requires --cpusets', result.stderr,
                      "Error message should mention --cpusets requirement")
 
+    def test_measurement_member_help_text(self):
+        """Test that --measurement-member appears in help"""
+        result = subprocess.run(
+            [sys.executable, '/home/jkacur/src/rteval/rteval-cmd', '--help'],
+            capture_output=True,
+            text=True
+        )
+
+        self.assertEqual(result.returncode, 0)
+        self.assertIn('--measurement-member', result.stdout,
+                     "--measurement-member should appear in help")
+        self.assertIn('partition=member', result.stdout,
+                     "Help should mention partition=member")
+
     def test_housekeeping_isolated_requires_housekeeping(self):
         """Test that --housekeeping-isolated requires --housekeeping"""
         result = subprocess.run(
Signature · 1 line
2.55.0
author
#7 lore raw

PATCH 7/8 rteval: Guard load module config iteration against non-string values

In reply to John Kacur

LoadModules.__LoadModules() and LoadModules.Setup() iterate over every key in the "loads" config section and call m[1].lower() to find entries whose value is the string 'module'. This assumes every option value in the section is a string. Any non-string value (for example a boolean option) makes m[1].lower() raise:

AttributeError: 'bool' object has no attribute 'lower'

which aborts the whole run during Prepare() whenever loads execute.

The measurement module already guards this with isinstance() checks; mirror that here so the loads section tolerates non-string option values.

Assisted-by Claude:claude-opus-4-8
---
 rteval/modules/loads/__init__.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rteval/modules/loads/__init__.py +4 -2
index 1ed005cc4e91..efe0fefa16e9 100644
@@ -91,7 +91,8 @@ class LoadModules(RtEvalModules):
         for m in modcfg:
             # hope to eventually have different kinds but module is only one
             # for now (jcw)
-            if m[1].lower() == 'module':
+            # Guard against non-string option values (e.g. boolean flags) in this section
+            if isinstance(m[1], str) and m[1].lower() == 'module':
                 self._LoadModule(m[0])
 
 
@@ -104,7 +105,8 @@ class LoadModules(RtEvalModules):
         for m in modcfg:
             # hope to eventually have different kinds but module is only on
             # for now (jcw)
-            if m[1].lower() == 'module':
+            # Guard against non-string option values (e.g. boolean flags) in this section
+            if isinstance(m[1], str) and m[1].lower() == 'module':
                 self._cfg.AppendConfig(m[0], modparams)
                 self._cfg.AppendConfig(m[0], {'cpulist': cpulist})
                 modobj = self._InstantiateModule(m[0], self._cfg.GetSection(m[0]))
Signature · 1 line
2.55.0
author
#8 lore raw

PATCH 8/8 rteval: Add --loads-cpuset to confine loads to a member cpuset

In reply to John Kacur

Add an opt-in --loads-cpuset flag that places load workloads in a dedicated rteval_loads cgroup v2 cpuset (partition=member) instead of relying only on taskset. This is additive: when the flag is absent, loads keep using taskset exactly as before.

A cpuset is a hard ceiling that all descendants inherit, so kcompile (make -jN -> gcc/as/ld) and hackbench fan-outs cannot escape it, unlike a taskset mask which a child can widen via sched_setaffinity(). The loads cpuset is always a member partition so its CPUs remain in the root cgroup's effective set, keeping CPUs available to the main rteval process when it is left in root (no --housekeeping).

Confinement uses self-placement before exec: a shared cpuset_preexec() helper returns a preexec_fn that writes the child's own PID into the cpuset's cgroup.procs, so the whole descendant subtree self-homes as it spawns. For loads it is strict (a failure raises RuntimeError and aborts the launch, so a load cannot silently escape its cpuset); for measurement it is lenient and falls back to post-hoc PID migration. The cyclictest and timerlat modules are refactored onto this shared helper, removing two copies of the previous inline closure; timerlat continues to work independently of cyclictest.

--loads-cpuset requires --cpusets and is skipped under --noload. Because the loads and measurement cpusets are both member partitions when --measurement-member is also given, they may share CPUs; the isolated measurement partition overlap case is still rejected by the existing overlap guard.

Tests covering the new flag are added to tests/cpusets/test-cpusets.sh (requires --cpusets, member partition, skipped with --noload, and the overlapping member-cpuset case with --measurement-member) and to tests/test_cpusetmanager.py (default no loads cpuset, member creation, CLI validation and help text).

Assisted-by Claude:claude-opus-4-8
---
 rteval-cmd                               |  12 +-
 rteval/__init__.py                       |  42 ++--
 rteval/cpuset.py                         |  37 ++++
 rteval/cpusetmanager.py                  | 111 +++++++---
 rteval/modules/__init__.py               |  11 +
 rteval/modules/loads/hackbench.py        |   7 +-
 rteval/modules/loads/kcompile.py         |  12 +-
 rteval/modules/loads/stressng.py         |   7 +-
 rteval/modules/measurement/cyclictest.py |  13 +-
 rteval/modules/measurement/timerlat.py   |  13 +-
 tests/cpusets/test-cpusets.sh            | 256 +++++++++++++++++++++++
 tests/test_cpusetmanager.py              |  68 ++++++
 12 files changed, 517 insertions(+), 72 deletions(-)
rteval-cmd +10 -2
index 15f6f505fed7..126226725697 100755
@@ -425,6 +425,11 @@ if __name__ == '__main__':
             if not rtevcfg.cpusets:
                 raise RuntimeError("--measurement-member requires --cpusets")
 
+        # Validate --loads-cpuset usage
+        if ldcfg.cpuset:
+            if not rtevcfg.cpusets:
+                raise RuntimeError("--loads-cpuset requires --cpusets")
+
         # Validate and process housekeeping CPUs
         housekeeping_cpus = []
         if rtevcfg.housekeeping:
@@ -591,14 +596,17 @@ if __name__ == '__main__':
             CpusetManager.cleanup_leftover_cpusets(logger)
 
             # Create manager (will create cpusets in __enter__)
-            # Note: Load CPUs not needed - loads use taskset for CPU affinity
+            # Loads use taskset by default; with --loads-cpuset they are also
+            # confined to the rteval_loads cpuset (member partition).
             cpuset_manager = CpusetManager(
                 housekeeping_cpus=housekeeping_cpus,
                 measurement_cpus=msrcfg_cpus,
                 logger=logger,
                 housekeeping_isolated=rtevcfg.housekeeping_isolated,
                 create_measurement=not rtevcfg.onlyload,
-                measurement_member=msrcfg.member
+                measurement_member=msrcfg.member,
+                loads_cpus=ldcfg_cpus,
+                create_loads=ldcfg.cpuset and not rtevcfg.noload
             )
 
         # Pass cpuset_manager to RtEval (None if not using cpusets)
rteval/__init__.py +29 -13

54 lines not on this page · raw message

rteval/cpuset.py +37 -0
index a0b3d8102543..3c85fce6b04d 100644
@@ -17,6 +17,43 @@ PROCESS_BLOCKLIST = {
 }
 
 
+def cpuset_preexec(cpuset_path, strict=False):
+    """Return a subprocess preexec_fn that self-homes the child into a cpuset.
+
+    The returned callable runs in the forked child just before exec and writes
+    the child's own PID into <cpuset_path>/cgroup.procs, so the child and every
+    descendant it later forks inherit the cpuset natively -- a hard ceiling that
+    taskset masks cannot widen. Returns None when cpuset_path is falsy, so
+    callers can pass the result straight to Popen(preexec_fn=...) whether or not
+    a cpuset is in use.
+
+    strict controls the failure policy:
+      - False (measurement modules): swallow errors so a failed self-placement
+        falls back to the parent's post-hoc PID migration.
+      - True (loads): let the error propagate and abort the launch, since a load
+        escaping its cpuset would defeat the confinement the caller asked for.
+    """
+    if not cpuset_path:
+        return None
+
+    procs_file = os.path.join(cpuset_path, 'cgroup.procs')
+
+    def _move_to_cpuset():
+        """Move the forked child into the cpuset before exec."""
+        try:
+            with open(procs_file, 'w') as fp:
+                fp.write(str(os.getpid()))
+        except Exception as exc:
+            if strict:
+                # Raise a RuntimeError (not the underlying OSError) so callers
+                # that catch OSError around Popen don't silently swallow it.
+                raise RuntimeError(
+                    f"failed to move process into cpuset {cpuset_path}: {exc}") from exc
+            # else: fail silently - parent will attempt migration as fallback
+
+    return _move_to_cpuset
+
+
 class Cpuset:
     """ Class for manipulating cpusets """
 
rteval/cpusetmanager.py +81 -30

171 lines not on this page · raw message

rteval/modules/__init__.py +11 -0
index ad7891fcb3c8..183efd8ef813 100644
@@ -329,6 +329,17 @@ reference from the first import"""
                                   default=None,
                                   help='Select measurement module: cyclictest or timerlat (overrides config file)')
 
+        # Set up options for load modules only
+        if self.__modtype == 'loads':
+            grparser.add_argument('--loads-cpuset',
+                                  dest='loads___cpuset',
+                                  action='store_true',
+                                  default=False,
+                                  help='confine loads to a cgroup v2 cpuset (rteval_loads, '
+                                       'partition=member) instead of only taskset; loads and '
+                                       'all their descendants are held to the load CPUs '
+                                       '(requires --cpusets)')
+
         for (modname, mod) in list(self.__modsloaded.items()):
             opts = mod.ModuleParameters()
             if len(opts) == 0:
rteval/modules/loads/hackbench.py +6 -1
index 20ebbbc4617c..6f93623535ae 100644
@@ -18,6 +18,7 @@ from rteval.modules.loads import CommandLineLoad
 from rteval.Log import Log
 from rteval.systopology import SysTopology
 from rteval.cpulist_utils import CpuList
+from rteval.cpuset import cpuset_preexec
 
 class Hackbench(CommandLineLoad):
     def __init__(self, config, logger):
@@ -123,10 +124,14 @@ class Hackbench(CommandLineLoad):
         # Only log initial startup at DEBUG level to avoid spam
         if initial:
             self._log(Log.DEBUG, f"starting on node {node}: args = {args}")
+        # When a loads cpuset is in use, self-home into it before exec so
+        # hackbench and its fan-out of tasks are confined to the load CPUs.
+        preexec_fn = cpuset_preexec(self._cfg.cpuset_path, strict=True)
         p = subprocess.Popen(args,
                              stdin=self.__nullfp,
                              stdout=self.__out,
-                             stderr=self.__err)
+                             stderr=self.__err,
+                             preexec_fn=preexec_fn)
         if not p:
             self._log(Log.DEBUG, f"hackbench failed to start on node {node}")
             raise RuntimeError(f"hackbench failed to start on node {node}")
rteval/modules/loads/kcompile.py +9 -3
index 23586b7a3c8d..99f2b3734791 100644
@@ -16,6 +16,7 @@ from rteval.modules.loads import CommandLineLoad
 from rteval.Log import Log
 from rteval.systopology import SysTopology
 from rteval.cpulist_utils import CpuList, collapse_cpulist
+from rteval.cpuset import cpuset_preexec
 
 DEFAULT_KERNEL_PREFIX = "linux-6.17.7"
 
@@ -89,12 +90,16 @@ class KBuildJob:
         subprocess.call(self.cleancmd, shell=True,
                         stdin=sin, stdout=sout, stderr=serr)
 
-    def run(self, sin=None, sout=None, serr=None):
+    def run(self, sin=None, sout=None, serr=None, cpuset_path=None):
         """ Use Popen to launch a kcompile job """
         self.log(Log.INFO, f"starting workload on node {int(self.node)}")
         self.log(Log.DEBUG, f"running on node {int(self.node)}: {self.runcmd}")
+        # When a loads cpuset is in use, self-home the build shell into it before
+        # exec so the whole make -jN subtree (gcc/as/ld) is confined to the load CPUs.
+        preexec_fn = cpuset_preexec(cpuset_path, strict=True)
         self.jobid = subprocess.Popen(self.runcmd, shell=True,
-                                      stdin=sin, stdout=sout, stderr=serr)
+                                      stdin=sin, stdout=sout, stderr=serr,
+                                      preexec_fn=preexec_fn)
 
     def isrunning(self):
         """ Query whether a job is running, returns True or False """
@@ -301,7 +306,8 @@ class Kcompile(CommandLineLoad):
                     if self.buildjobs[n].jobid.returncode not in (0, -2):
                         raise RuntimeError(f"kcompile module failed to run (returned {self.buildjobs[n].jobid.returncode}), please check logs for more detail")
                 self._log(Log.INFO, f"Starting load on node {n}")
-                self.buildjobs[n].run(self.__nullfd, self.__outfd, self.__errfd)
+                self.buildjobs[n].run(self.__nullfd, self.__outfd, self.__errfd,
+                                      cpuset_path=self._cfg.cpuset_path)
 
     def WorkloadAlive(self):
         # if any of the jobs has stopped, return False
rteval/modules/loads/stressng.py +6 -1
index df4685ee16b3..564e7988b328 100644
@@ -10,6 +10,7 @@ from rteval.modules.loads import CommandLineLoad
 from rteval.Log import Log
 from rteval.systopology import SysTopology
 from rteval.cpulist_utils import CpuList
+from rteval.cpuset import cpuset_preexec
 
 def get_valid_stressors():
     """Query stress-ng for list of valid stressor names."""
@@ -120,11 +121,15 @@ class Stressng(CommandLineLoad):
             return
 
         self._log(Log.DEBUG, f'starting with {" ".join(self.args)}')
+        # When a loads cpuset is in use, self-home into it before exec so
+        # stress-ng and its workers are confined to the load CPUs.
+        preexec_fn = cpuset_preexec(self._cfg.cpuset_path, strict=True)
         try:
             self.process = subprocess.Popen(self.args,
                                             stdout=self.__out,
                                             stderr=self.__err,
-                                            stdin=self.__in)
+                                            stdin=self.__in,
+                                            preexec_fn=preexec_fn)
             self.started = True
             self.jobs = 1
             self._log(Log.DEBUG, "running")
rteval/modules/measurement/cyclictest.py +2 -11
index b193330e27e0..029dc726f640 100644
@@ -18,6 +18,7 @@ from rteval.Log import Log
 from rteval.modules import rtevalModulePrototype
 from rteval.systopology import cpuinfo, SysTopology
 from rteval.cpulist_utils import expand_cpulist, collapse_cpulist
+from rteval.cpuset import cpuset_preexec
 
 class RunData:
     '''class to keep instance data from a cyclictest run'''
@@ -332,17 +333,7 @@ class Cyclictest(rtevalModulePrototype):
 
         # If cpuset is configured, launch process inside the cpuset
         # This is critical for cyclictest - migrating it mid-startup disrupts initialization
-        preexec_fn = None
-        if hasattr(self.__cfg, 'cpuset_path') and self.__cfg.cpuset_path:
-            def move_to_cpuset():
-                """Move child process into cpuset before exec"""
-                try:
-                    cpuset_procs = os.path.join(self.__cfg.cpuset_path, 'cgroup.procs')
-                    with open(cpuset_procs, 'w') as f:
-                        f.write(str(os.getpid()))
-                except Exception:
-                    pass  # Fail silently - parent will attempt migration as fallback
-            preexec_fn = move_to_cpuset
+        preexec_fn = cpuset_preexec(self.__cfg.cpuset_path)
 
         self.__cyclicprocess = subprocess.Popen(self.__cmd,
                                                 stdout=self.__cyclicoutput,
rteval/modules/measurement/timerlat.py +2 -11
index 735141e6796d..40465ca315b8 100644
@@ -15,6 +15,7 @@ from rteval.Log import Log
 from rteval.modules import rtevalModulePrototype
 from rteval.systopology import cpuinfo, SysTopology
 from rteval.cpulist_utils import expand_cpulist, collapse_cpulist
+from rteval.cpuset import cpuset_preexec
 
 
 class TLRunData:
@@ -363,17 +364,7 @@ class Timerlat(rtevalModulePrototype):
 
         # If cpuset is configured, launch process inside the cpuset
         # This is critical for timerlat - migrating it mid-startup disrupts initialization
-        preexec_fn = None
-        if hasattr(self.__cfg, 'cpuset_path') and self.__cfg.cpuset_path:
-            def move_to_cpuset():
-                """Move child process into cpuset before exec"""
-                try:
-                    cpuset_procs = os.path.join(self.__cfg.cpuset_path, 'cgroup.procs')
-                    with open(cpuset_procs, 'w') as f:
-                        f.write(str(os.getpid()))
-                except Exception:
-                    pass  # Fail silently - parent will attempt migration as fallback
-            preexec_fn = move_to_cpuset
+        preexec_fn = cpuset_preexec(self.__cfg.cpuset_path)
 
         self.__timerlat_process = subprocess.Popen(self.__cmd,
                                                    stdout=self.__timerlat_out,
tests/cpusets/test-cpusets.sh +256 -0

268 lines not on this page · raw message

tests/test_cpusetmanager.py +68 -0

80 lines not on this page · raw message

Signature · 1 line
2.55.0