[PATCH 1/6] rteval: Detect isolcpus in systopology

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux