* [PATCH 1/3] hwlatdetect: handle hwlat_detector being builtin rather than module
2016-01-13 14:59 [PATCH 0/3] hwlatdetect patches John Kacur
@ 2016-01-13 14:59 ` John Kacur
2016-01-13 14:59 ` [PATCH 2/3] hwlatdetect: modify to handle python3 prints John Kacur
2016-01-13 14:59 ` [PATCH 3/3] hwlatdetect: make reading sample date work with python2 and python3 John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2016-01-13 14:59 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
From: Clark Williams <williams@redhat.com>
Originally the hwlat_detector was built as only a module and was
controlled by module parameters. The latest version uses debugfs
control files so there is no real need to force it to be a module.
The hwlatdetector script in rt-tests assumes that the hwlat_detector
code was built as a module. This patch adds logic to detect and
handle if hwlat_detector is a builtin.
Signed-off-by: Clark Williams <williams@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/hwlatdetect/hwlatdetect.py | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index dbf3f674faba..2a1c562c2188 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -108,6 +108,14 @@ class Kmod(object):
''' class to manage loading and unloading hwlat.ko'''
names = ("hwlat_detector", "smi_detector")
+ def __check_builtin(self):
+ for l in open(os.path.join('/lib/modules', os.uname()[2], 'modules.builtin'), "r"):
+ for m in Kmod.names:
+ if m in l:
+ debug("found %s as builtin" % m)
+ return m
+ return None
+
def __find_modname(self):
debug("looking for modules")
path = os.path.join("/lib/modules",
@@ -123,6 +131,15 @@ class Kmod(object):
def __init__(self):
self.preloaded = False
+ self.builtin = False
+
+ # check for builtin
+ self.modname = self.__check_builtin()
+ if self.modname:
+ self.builtin = True
+ return
+
+ # now look for module
f = open ('/proc/modules')
for l in f:
field = l.split()
@@ -136,6 +153,9 @@ class Kmod(object):
self.modname = self.__find_modname()
def load(self):
+ if self.builtin:
+ debug("not loading %s (builtin)" % self.modname)
+ return True
if self.preloaded:
debug("not loading %s (already loaded)" % self.modname)
return True
@@ -143,7 +163,7 @@ class Kmod(object):
return (subprocess.call(cmd) == 0)
def unload(self):
- if self.preloaded:
+ if self.preloaded or self.builtin:
debug("Not unloading %s" % self.modname)
return True
cmd = ['/sbin/modprobe', '-r', self.modname]
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] hwlatdetect: modify to handle python3 prints
2016-01-13 14:59 [PATCH 0/3] hwlatdetect patches John Kacur
2016-01-13 14:59 ` [PATCH 1/3] hwlatdetect: handle hwlat_detector being builtin rather than module John Kacur
@ 2016-01-13 14:59 ` John Kacur
2016-01-13 14:59 ` [PATCH 3/3] hwlatdetect: make reading sample date work with python2 and python3 John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2016-01-13 14:59 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
From: Clark Williams <williams@redhat.com>
Use __future__ import of print_function and make sure all instances
of print are now functions rather than statements.
Signed-off-by: Clark Williams <williams@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/hwlatdetect/hwlatdetect.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 2a1c562c2188..c8c86ad189ca 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -7,6 +7,8 @@
# modify it under the terms of the GNU General Public License Version 2
# as published by the Free Software Foundation.
+from __future__ import print_function
+
import sys
import os
import time
@@ -295,7 +297,7 @@ class Hwlat(object):
while val:
val = val.strip()
self.samples.append(val)
- if watch: print val
+ if watch: print(val)
debug("got a latency sample: %s" % val)
val = self.get_sample()
time.sleep(0.1)
@@ -391,7 +393,7 @@ class Smi(object):
val = val.strip()
if int(val) >= threshold:
self.samples.append(val)
- if watch: print val
+ if watch: print(val)
debug("got a latency sample: %s (threshold: %d)" % (val, self.get("threshold")))
time.sleep(0.1)
except KeyboardInterrupt as e:
@@ -572,7 +574,7 @@ if __name__ == '__main__':
if count > detect.initsmi[i]:
smis = count - detect.initsmi[i]
total_smis += smis
- print "%d SMIs occured on cpu %d" % (smis, i)
+ print("%d SMIs occured on cpu %d" % (smis, i))
info("SMIs during run: %d" % total_smis)
if reportfile:
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] hwlatdetect: make reading sample date work with python2 and python3
2016-01-13 14:59 [PATCH 0/3] hwlatdetect patches John Kacur
2016-01-13 14:59 ` [PATCH 1/3] hwlatdetect: handle hwlat_detector being builtin rather than module John Kacur
2016-01-13 14:59 ` [PATCH 2/3] hwlatdetect: modify to handle python3 prints John Kacur
@ 2016-01-13 14:59 ` John Kacur
2 siblings, 0 replies; 4+ messages in thread
From: John Kacur @ 2016-01-13 14:59 UTC (permalink / raw)
To: rt-users; +Cc: Clark Williams, John Kacur
From: Clark Williams <williams@redhat.com>
Modify the sample reading code to return correct string data and to
catch exceptions in non-blocking mode correctly on python{2,3}
Signed-off-by: Clark Williams <williams@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/hwlatdetect/hwlatdetect.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index c8c86ad189ca..d9ef0272d738 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -79,15 +79,21 @@ class DebugFS(object):
val = f.readline()
f.close()
else:
- fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK)
+ f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r")
try:
- val = os.read(fd, 256)
+ val = f.readline()
except OSError as e:
+ print ("errno: %s" % e)
if e.errno == errno.EAGAIN:
val = None
else:
raise
- os.close(fd)
+ except IOError as e:
+ if e.errno == errno.EAGAIN:
+ val = None
+ else:
+ raise
+ f.close()
return val
def putval(self, item, value):
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread