[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-rt-users
Subject: [PATCH 1/6] rteval: Detect isolcpus in systopology
From: Tomas Glozar <tglozar () redhat ! com>
Date: 2023-06-30 9:19:02
Message-ID: 20230630091951.916865-2-tglozar () redhat ! com
[Download RAW message or body]
Works similarly to online_cpus:
- add CpuList.isolated_cpulist to filter isolated CPUs
- add SysTopology.isolated_cpus to get list of isolated CPUs
- add CpuList.nonisolated_cpulist to do the opposite filter
- add SysTopology.default_cpus to get CPUs that are used for scheduling
by default, i.e. online and non-isolated CPUs
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
rteval/systopology.py | 47 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/rteval/systopology.py b/rteval/systopology.py
index c8f85c5..19443f9 100644
--- a/rteval/systopology.py
+++ b/rteval/systopology.py
@@ -127,6 +127,11 @@ class CpuList:
return True
return False
+ @staticmethod
+ def isolated_file_exists():
+ """ Check whether machine / kernel is configured with isolated file """
+ return os.path.exists(os.path.join(CpuList.cpupath, "isolated"))
+
@staticmethod
def longest_sequence(cpulist):
""" return index of last element of a sequence that steps by one """
@@ -214,6 +219,24 @@ class CpuList:
newlist.append(cpu)
return newlist
+ @staticmethod
+ def isolated_cpulist(cpulist):
+ """Given a cpulist, return a cpulist of isolated CPUs"""
+ if not CpuList.isolated_file_exists():
+ return cpulist
+ isolated_cpulist = sysread(CpuList.cpupath, "isolated")
+ isolated_cpulist = CpuList.expand_cpulist(isolated_cpulist)
+ return list(set(isolated_cpulist) & set(cpulist))
+
+ @staticmethod
+ def nonisolated_cpulist(cpulist):
+ """Given a cpulist, return a cpulist of non-isolated CPUs"""
+ if not CpuList.isolated_file_exists():
+ return cpulist
+ isolated_cpulist = sysread(CpuList.cpupath, "isolated")
+ isolated_cpulist = CpuList.expand_cpulist(isolated_cpulist)
+ return list(set(cpulist).difference(set(isolated_cpulist)))
+
#
# class to abstract access to NUMA nodes in /sys filesystem
#
@@ -362,11 +385,35 @@ class SysTopology:
cpulist.sort()
return cpulist
+ def isolated_cpus(self):
+ """ return a list of integers of all isolated cpus """
+ cpulist = []
+ for n in self.nodes:
+ cpulist += CpuList.isolated_cpulist(self.getcpus(n))
+ cpulist.sort()
+ return cpulist
+
+ def default_cpus(self):
+ """ return a list of integers of all default schedulable cpus, i.e. online non-isolated cpus """
+ cpulist = []
+ for n in self.nodes:
+ cpulist += CpuList.nonisolated_cpulist(self.getcpus(n))
+ cpulist.sort()
+ return cpulist
+
def online_cpus_str(self):
""" return a list of strings of numbers of all online cpus """
cpulist = [str(cpu) for cpu in self.online_cpus()]
return cpulist
+ def isolated_cpus_str(self):
+ cpulist = [str(cpu) for cpu in self.isolated_cpus()]
+ return cpulist
+
+ def default_cpus_str(self):
+ cpulist = [str(cpu) for cpu in self.default_cpus()]
+ return cpulist
+
def invert_cpulist(self, cpulist):
""" return a list of online cpus not in cpulist """
return [c for c in self.online_cpus() if c not in cpulist]
--
2.41.0
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic