From: tglozar@redhat.com
To: linux-rt-users@vger.kernel.org
Cc: jkacur@redhat.com, Tomas Glozar <tglozar@redhat.com>
Subject: [PATCH 2/3] rteval: Minor improvements to CpuList class
Date: Tue, 14 Nov 2023 13:18:07 +0100 [thread overview]
Message-ID: <20231114121808.154654-3-tglozar@redhat.com> (raw)
In-Reply-To: <20231114121808.154654-1-tglozar@redhat.com>
From: Tomas Glozar <tglozar@redhat.com>
- Remove unnecessary if-else from online_file_exists
- Use cpupath in online_file_exists
- Check for cpu0 instead of cpu1 in online_file_exists
- In is_online, remove check for n in cpuset and make it static
- Mark also the remaining methods static since they do not rely on
any fields of the class
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
rteval/systopology.py | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/rteval/systopology.py b/rteval/systopology.py
index ea8e242..97d3dc4 100644
--- a/rteval/systopology.py
+++ b/rteval/systopology.py
@@ -82,12 +82,14 @@ class CpuList:
def __len__(self):
return len(self.cpulist)
+ def getcpulist(self):
+ """ return the list of cpus tracked """
+ return self.cpulist
+
@staticmethod
def online_file_exists():
""" Check whether machine / kernel is configured with online file """
- if os.path.exists('/sys/devices/system/cpu/cpu1/online'):
- return True
- return False
+ return os.path.exists(os.path.join(CpuList.cpupath, "cpu0/online"))
@staticmethod
def isolated_file_exists():
@@ -147,14 +149,9 @@ class CpuList:
result.append(a)
return [int(i) for i in list(set(result))]
- def getcpulist(self):
- """ return the list of cpus tracked """
- return self.cpulist
-
- def is_online(self, n):
+ @staticmethod
+ def is_online(n):
""" check whether cpu n is online """
- if n not in self.cpulist:
- raise RuntimeError(f"invalid cpu number {n}")
path = os.path.join(CpuList.cpupath, f'cpu{n}')
# Some hardware doesn't allow cpu0 to be turned off
@@ -163,16 +160,17 @@ class CpuList:
return sysread(path, "online") == "1"
- def online_cpulist(self, cpulist):
+ @staticmethod
+ def online_cpulist(cpulist):
""" Given a cpulist, return a cpulist of online cpus """
# This only works if the sys online files exist
- if not self.online_file_exists():
+ if not CpuList.online_file_exists():
return cpulist
newlist = []
for cpu in cpulist:
- if not self.online_file_exists() and cpu == '0':
+ if not CpuList.online_file_exists() and cpu == '0':
newlist.append(cpu)
- elif self.is_online(int(cpu)):
+ elif CpuList.is_online(int(cpu)):
newlist.append(cpu)
return newlist
--
2.41.0
next prev parent reply other threads:[~2023-11-14 12:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 12:18 [PATCH 0/3] rteval: Refactor CPU list logic tglozar
2023-11-14 12:18 ` [PATCH 1/3] rteval: Refactor collapse_cpulist in systopology tglozar
2023-11-14 12:18 ` tglozar [this message]
2023-11-14 12:18 ` [PATCH 3/3] rteval: Convert CpuList class to a module tglozar
2023-11-22 9:41 ` Tomas Glozar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231114121808.154654-3-tglozar@redhat.com \
--to=tglozar@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox