All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration
@ 2021-11-11 20:41 John Kacur
  2021-11-11 20:41 ` [PATCH 02/17] rt-tests:hwlatdetect.py: Remove multiple statements on one line John Kacur
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

There is no need to specify object in python3 when creating a class

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 56fd2af8641d..ac87036d4c08 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -31,7 +31,7 @@ def info(str):
 # discovers that debugfs is already mounted, it will leave
 # it mounted.
 #
-class DebugFS(object):
+class DebugFS:
     '''class to manage mounting/umounting the debugfs'''
     def __init__(self):
         self.premounted = False
@@ -116,7 +116,7 @@ class DetectorNotAvailable(Exception):
 # above, if the module is already loaded, this class will
 # leave it alone when cleaning up.
 #
-class Kmod(object):
+class Kmod:
     ''' class to manage loading and unloading of kernel modules'''
 
     names = ("hwlat_detector", "smi_detector")
@@ -184,7 +184,7 @@ class Kmod(object):
 #
 # base class for detection modules
 #
-class Detector(object):
+class Detector:
     '''base class for detector modules'''
     def __init__(self):
         self.type = "unknown"
@@ -293,7 +293,7 @@ class Tracer(Detector):
         'threshold' : "tracing_thresh",
     }
 
-    class Sample(object):
+    class Sample:
         'private class for tracer sample data'
         __slots__ = 'timestamp', 'inner', 'outer',
         def __init__(self, line):
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/17] rt-tests:hwlatdetect.py: Remove multiple statements on one line
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 03/17] rt-tests:hwlatdetect.py: Remove unnecessary 'not' John Kacur
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Remove multiple statements on one line

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index ac87036d4c08..66e132b8c2a5 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -19,10 +19,12 @@ quiet = False
 watch = False
 
 def debug(str):
-    if debugging: print(str)
+    if debugging:
+        print(str)
 
 def info(str):
-    if not quiet: print(str)
+    if not quiet:
+        print(str)
 
 #
 # Class used to manage mounting and umounting the debugfs
@@ -358,7 +360,8 @@ class Tracer(Detector):
                 val = self.get_sample()
                 while val:
                     self.samples.append(val)
-                    if watch: val.display()
+                    if watch:
+                        val.display()
                     val = self.get_sample()
                 time.sleep(0.1)
         except KeyboardInterrupt as e:
@@ -425,7 +428,8 @@ class Hwlat(Detector):
                 while val:
                     val = val.strip()
                     self.samples.append(val)
-                    if watch: print(val)
+                    if watch:
+                        print(val)
                     val = self.get_sample()
                 time.sleep(0.1)
         except KeyboardInterrupt as e:
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/17] rt-tests:hwlatdetect.py: Remove unnecessary 'not'
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
  2021-11-11 20:41 ` [PATCH 02/17] rt-tests:hwlatdetect.py: Remove multiple statements on one line John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 04/17] rt-tests: deadline_tests: Null check to prevent floating point exception John Kacur
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Remove unnecessary 'not'

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 66e132b8c2a5..5a66280fb01c 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -66,7 +66,7 @@ class DebugFS:
             return True
         debug("umounting debugfs")
         cmd = ['/bin/umount', self.mountpoint]
-        self.mounted = not (subprocess.call(cmd) == 0)
+        self.mounted = subprocess.call(cmd) != 0
         if self.mounted:
             raise RuntimeError("Failed to umount debugfs")
         return not self.mounted
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/17] rt-tests: deadline_tests: Null check to prevent floating point exception
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
  2021-11-11 20:41 ` [PATCH 02/17] rt-tests:hwlatdetect.py: Remove multiple statements on one line John Kacur
  2021-11-11 20:41 ` [PATCH 03/17] rt-tests:hwlatdetect.py: Remove unnecessary 'not' John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 05/17] rt-tests: cyclictest: Check user supplies an value to histogram John Kacur
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Fix a floating point exception that can occur if sd->nr_adjust is 0
by checking it before performing a division by zero.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/sched_deadline/deadline_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index 53abd4d2ca6b..b7e1e045b57c 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -2050,8 +2050,10 @@ int main(int argc, char **argv)
 		printf("missed deadlines  = %d\n", sd->missed_deadlines);
 		printf("missed periods    = %d\n", sd->missed_periods);
 		printf("Total adjustments = %lld us\n", sd->total_adjust);
-		printf("# adjustments = %lld avg: %lld us\n",
-		       sd->nr_adjust, sd->total_adjust / sd->nr_adjust);
+		if (sd->nr_adjust) {
+			printf("# adjustments = %lld avg: %lld us\n",
+			sd->nr_adjust, sd->total_adjust / sd->nr_adjust);
+		}
 		printf("deadline   : %lld us\n", sd->deadline_us);
 		printf("runtime    : %lld us\n", sd->runtime_us);
 		printf("nr_periods : %lld\n", sd->nr_periods);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/17] rt-tests: cyclictest: Check user supplies an value to histogram
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (2 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 04/17] rt-tests: deadline_tests: Null check to prevent floating point exception John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 06/17] rt-tests: get_cyclictest_snapshot: print_warning should be a classmethod John Kacur
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

histogram and histofall take a required argument.

If the user fails to supply one, display the help and exit with an error

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 2187d98de725..e4d43481de97 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1089,7 +1089,10 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			histofall = 1; /* fall through */
 		case 'h':
 		case OPT_HISTOGRAM:
-			histogram = atoi(optarg); break;
+			histogram = atoi(optarg);
+			if (!histogram)
+				display_help(1);
+			break;
 		case OPT_HISTFILE:
 			use_histfile = 1;
 			strncpy(histfile, optarg, strnlen(optarg, MAX_PATH-1));
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/17] rt-tests: get_cyclictest_snapshot: print_warning should be a classmethod
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (3 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 05/17] rt-tests: cyclictest: Check user supplies an value to histogram John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 07/17] rt-tests: hwlatdetect: Remove unnessary parens after return John Kacur
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Make print_warning a class method since it only references a class
variable and doesn't require self

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/get_cyclictest_snapshot.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cyclictest/get_cyclictest_snapshot.py b/src/cyclictest/get_cyclictest_snapshot.py
index aed9681e4cc5..aedc72001fb2 100755
--- a/src/cyclictest/get_cyclictest_snapshot.py
+++ b/src/cyclictest/get_cyclictest_snapshot.py
@@ -21,10 +21,11 @@ class Snapshot:
 
     warned = False
 
-    def print_warning():
+    @classmethod
+    def print_warning(cls):
         """ print a warning one time only even if called multiple times """
-        if not Snapshot.warned:
-            Snapshot.warned = True
+        if not cls.warned:
+            cls.warned = True
             print("No cyclictest instance found")
 
     def __init__(self):
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/17] rt-tests: hwlatdetect: Remove unnessary parens after return
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (4 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 06/17] rt-tests: get_cyclictest_snapshot: print_warning should be a classmethod John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 08/17] rt-tests: hwlatdetect: Use "with" for opening files John Kacur
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Remove unnecessary parens after return

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 5a66280fb01c..2fabbb55b242 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -174,14 +174,14 @@ class Kmod:
             debug("not loading %s (already loaded)" % self.name)
             return True
         cmd = ['/sbin/modprobe', self.name]
-        return (subprocess.call(cmd) == 0)
+        return subprocess.call(cmd) == 0
 
     def unload(self):
         if self.preloaded or self.builtin:
             debug("Not unloading %s" % self.name)
             return True
         cmd = ['/sbin/modprobe', '-r', self.name]
-        return (subprocess.call(cmd) == 0)
+        return subprocess.call(cmd) == 0
 
 #
 # base class for detection modules
@@ -494,11 +494,11 @@ def microseconds(str):
     if str.isdigit():
         return int(str)
     elif str[-2:] == 'ms':
-        return (int(str[0:-2]) * 1000)
+        return int(str[0:-2]) * 1000
     elif str[-2:] == 'us':
         return int(str[0:-2])
     elif str[-1:] == 's':
-        return (int(str[0:-1]) * 1000 * 1000)
+        return int(str[0:-1]) * 1000 * 1000
     else:
         raise RuntimeError("invalid input for microseconds: '%s'" % str)
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/17] rt-tests: hwlatdetect: Use "with" for opening files
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (5 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 07/17] rt-tests: hwlatdetect: Remove unnessary parens after return John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:41 ` [PATCH 09/17] rt-tests: hwlatdetect: Use python3 style super() John Kacur
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Use "with" for opening files

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 43 ++++++++++++++++------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 2fabbb55b242..a530867777a7 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -39,14 +39,13 @@ class DebugFS:
         self.premounted = False
         self.mounted = False
         self.mountpoint = ''
-        f = open('/proc/mounts')
-        for l in f:
-            field = l.split()
-            if field[2] == "debugfs":
-                self.premounted = True
-                self.mountpoint = field[1]
-                break
-        f.close()
+        with open('/proc/mounts') as f:
+            for l in f:
+                field = l.split()
+                if field[2] == "debugfs":
+                    self.premounted = True
+                    self.mountpoint = field[1]
+                    break
 
     def mount(self, path='/sys/kernel/debug'):
         if self.premounted or self.mounted:
@@ -74,9 +73,8 @@ class DebugFS:
     def getval(self, item, nonblocking=False):
         path = os.path.join(self.mountpoint, item)
         if nonblocking == False:
-            f = open(path)
-            val = f.readline()
-            f.close()
+            with open(path) as f:
+                val = f.readline()
         else:
             f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r")
             try:
@@ -97,10 +95,9 @@ class DebugFS:
 
     def putval(self, item, value):
         path = os.path.join(self.mountpoint, item)
-        f = open(path, "w")
-        f.write(str(value))
-        f.flush()
-        f.close()
+        with open(path, "w") as f:
+            f.write(str(value))
+            f.flush()
 
     def getpath(self, item):
         return os.path.join(self.mountpoint, item)
@@ -378,10 +375,10 @@ class Tracer(Detector):
 
     def save(self, output=None):
         if output:
-            f = open(output, "w")
-            for s in self.samples:
-                f.write("%s\n" % str(s))
-            print("report saved to %s (%d samples)" % (output, len(self.samples)))
+            with open(output, "w") as f:
+                for s in self.samples:
+                    f.write("%s\n" % str(s))
+                print("report saved to %s (%d samples)" % (output, len(self.samples)))
 
     def display(self):
         for s in self.samples:
@@ -443,10 +440,10 @@ class Hwlat(Detector):
 
     def save(self, output=None):
         if output:
-            f = open(output, "w")
-            for s in self.samples:
-                f.write("%s\n" % str(s))
-            print("report saved to %s (%d samples)" % (output, len(self.samples)))
+            with open(output, "w") as f:
+                for s in self.samples:
+                    f.write("%s\n" % str(s))
+                print("report saved to %s (%d samples)" % (output, len(self.samples)))
 
     def cleanup(self):
         if not self.kmod.unload():
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/17] rt-tests: hwlatdetect: Use python3 style super()
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (6 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 08/17] rt-tests: hwlatdetect: Use "with" for opening files John Kacur
@ 2021-11-11 20:41 ` John Kacur
  2021-11-11 20:42 ` [PATCH 10/17] rt-tests: hwlatdetect: Keep consistent name from abstract method John Kacur
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:41 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Use python3 style super(), no need to specify __class__ and self

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index a530867777a7..7cd038ba913e 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -321,7 +321,7 @@ class Tracer(Detector):
         return os.path.join(path, Tracer.__field_translation[field])
 
     def __init__(self):
-        super(Tracer, self).__init__()
+        super().__init__()
         path = self.debugfs.getpath('tracing/hwlat_detector')
         if not os.path.exists(path):
             raise DetectorNotAvailable("hwlat", "hwlat tracer not available")
@@ -397,7 +397,7 @@ class Tracer(Detector):
 class Hwlat(Detector):
     '''class to wrap access to hwlat debugfs files'''
     def __init__(self):
-        super(Hwlat, self).__init__()
+        super().__init__()
         self.kmod = Kmod("hwlat_detector")
         self.type = "kmodule"
         self.kmod.load()
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/17] rt-tests: hwlatdetect: Keep consistent name from abstract method
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (7 preceding siblings ...)
  2021-11-11 20:41 ` [PATCH 09/17] rt-tests: hwlatdetect: Use python3 style super() John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 11/17] rt-tests: hwlatdetect: Remove class Hwlat John Kacur
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

Keep the variable name consistent between the abstract method and the
method overriding it.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 7cd038ba913e..c07ddbb0e89e 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -239,7 +239,7 @@ class Detector:
         '''set a value in a debugfs field'''
         raise RuntimeError("must override base method 'set'!")
 
-    def save(self, reportfile=None):
+    def save(self, output=None):
         '''save sample data to reportfile'''
         raise RuntimeError("must override base method 'save'!")
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/17] rt-tests: hwlatdetect: Remove class Hwlat
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (8 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 10/17] rt-tests: hwlatdetect: Keep consistent name from abstract method John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 12/17] rt-tests: hwlatdetect: Use abstractmethod decorator John Kacur
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

hwlatdetect converted to using ftrace a long time ago.
Since we no longer need to load a kernel module, the class Hwlat can be
removed.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 61 +---------------------------------
 1 file changed, 1 insertion(+), 60 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index c07ddbb0e89e..ff8265ac39c5 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -380,6 +380,7 @@ class Tracer(Detector):
                     f.write("%s\n" % str(s))
                 print("report saved to %s (%d samples)" % (output, len(self.samples)))
 
+
     def display(self):
         for s in self.samples:
             s.display()
@@ -391,66 +392,6 @@ class Tracer(Detector):
             raise RuntimeError("Failed to unmount debugfs")
 
 
-#
-# Class to simplify running the hwlat kernel module
-#
-class Hwlat(Detector):
-    '''class to wrap access to hwlat debugfs files'''
-    def __init__(self):
-        super().__init__()
-        self.kmod = Kmod("hwlat_detector")
-        self.type = "kmodule"
-        self.kmod.load()
-
-    def get(self, field):
-        return int(self.debugfs.getval(os.path.join("hwlat_detector", field)))
-
-    def set(self, field, val):
-        if field == "enable" and val:
-            val = 1
-        self.debugfs.putval(os.path.join("hwlat_detector", field), str(val))
-
-    def get_sample(self):
-        return self.debugfs.getval("hwlat_detector/sample", nonblocking=True)
-
-    def detect(self):
-        self.samples = []
-        testend = time.time() + self.testduration
-        pollcnt = 0
-        self.start()
-        try:
-            while time.time() < testend:
-                pollcnt += 1
-                val = self.get_sample()
-                while val:
-                    val = val.strip()
-                    self.samples.append(val)
-                    if watch:
-                        print(val)
-                    val = self.get_sample()
-                time.sleep(0.1)
-        except KeyboardInterrupt as e:
-            print("interrupted")
-        self.stop()
-        return self.samples
-
-    def display(self):
-        for s in self.samples:
-            print(s)
-
-    def save(self, output=None):
-        if output:
-            with open(output, "w") as f:
-                for s in self.samples:
-                    f.write("%s\n" % str(s))
-                print("report saved to %s (%d samples)" % (output, len(self.samples)))
-
-    def cleanup(self):
-        if not self.kmod.unload():
-            raise RuntimeError("Failed to unload %s" % self.name)
-        if not self.debugfs.umount():
-            raise RuntimeError("Failed to unmount debugfs")
-
 def seconds(str):
     "convert input string to value in seconds"
     if str.isdigit():
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 12/17] rt-tests: hwlatdetect: Use abstractmethod decorator
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (9 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 11/17] rt-tests: hwlatdetect: Remove class Hwlat John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 13/17] rt-tests: hwlatdetect: Remove unused class Kmod John Kacur
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

- Use abstractmethod decorator instead of raising error if a method is
  not overridden.
- Remove unnecessary trailing comma
- fix import order

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 37 ++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index ff8265ac39c5..ea8f2036fe82 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -1,4 +1,5 @@
 #!/usr/bin/python3
+""" Module to detect smis """
 
 # SPDX-License-Identifier: GPL-2.0-only
 
@@ -6,12 +7,13 @@
 # (C) 2015,2016 Clark Williams <williams@redhat.com>
 # (C) 2009 Clark Williams <williams@redhat.com>
 
-import sys
-import os
-import time
-import subprocess
+import abc
 import errno
+import os
 import os.path
+import subprocess
+import sys
+import time
 
 version = "0.8"
 debugging = False
@@ -72,7 +74,7 @@ class DebugFS:
 
     def getval(self, item, nonblocking=False):
         path = os.path.join(self.mountpoint, item)
-        if nonblocking == False:
+        if nonblocking is False:
             with open(path) as f:
                 val = f.readline()
         else:
@@ -228,24 +230,25 @@ class Detector:
             os.close(self.dma_latency_handle)
             debug("c-states enabled")
 
+    @abc.abstractmethod
     def cleanup(self):
-        raise RuntimeError("must override base method 'cleanup'!")
+        ''' abstract cleanup method, must override '''
 
+    @abc.abstractmethod
     def get(self, field):
-        '''get the value of a debugfs field'''
-        raise RuntimeError("must override base method 'get'!")
+        ''' get the value of a debugfs field '''
 
+    @abc.abstractmethod
     def set(self, field, val):
-        '''set a value in a debugfs field'''
-        raise RuntimeError("must override base method 'set'!")
+        ''' set a value in a debugfs field '''
 
+    @abc.abstractmethod
     def save(self, output=None):
-        '''save sample data to reportfile'''
-        raise RuntimeError("must override base method 'save'!")
+        ''' save sample data to output '''
 
+    @abc.abstractmethod
     def display(self):
-        '''output the sample data as a string'''
-        raise RuntimeError("must override base method 'display'!")
+        ''' output the sample data as a string '''
 
     def start(self):
         count = 0
@@ -277,9 +280,9 @@ class Detector:
         self.c_states_on()
         debug("detector module disabled")
 
+    @abc.abstractmethod
     def detect(self):
-        '''get detector output'''
-        raise RuntimeError("must override base method 'detect'!")
+        ''' get detector output '''
 #
 # class to handle running the hwlat tracer module of ftrace
 #
@@ -294,7 +297,7 @@ class Tracer(Detector):
 
     class Sample:
         'private class for tracer sample data'
-        __slots__ = 'timestamp', 'inner', 'outer',
+        __slots__ = 'timestamp', 'inner', 'outer'
         def __init__(self, line):
             fields = line.split()
             i,o = fields[6].split('/')
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 13/17] rt-tests: hwlatdetect: Remove unused class Kmod
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (10 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 12/17] rt-tests: hwlatdetect: Use abstractmethod decorator John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 14/17] rt-tests: hwlatdetect: Don't use built-in name str as a variable John Kacur
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

- Remove class Kmod
  Kmod was used for loading and unloading of a kernel module, but
  hwlatdetect uses ftrace now so this class is unneeded.
- Improve the spacing in the code

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 107 ++++++---------------------------
 1 file changed, 19 insertions(+), 88 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index ea8f2036fe82..c22e5eba25f6 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -20,14 +20,17 @@ debugging = False
 quiet = False
 watch = False
 
+
 def debug(str):
     if debugging:
         print(str)
 
+
 def info(str):
     if not quiet:
         print(str)
 
+
 #
 # Class used to manage mounting and umounting the debugfs
 # filesystem. Note that if an instance of this class mounts
@@ -78,7 +81,7 @@ class DebugFS:
             with open(path) as f:
                 val = f.readline()
         else:
-            f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r")
+            f = os.fdopen(os.open(path, os.O_RDONLY | os.O_NONBLOCK), "r")
             try:
                 val = f.readline()
             except OSError as e:
@@ -104,89 +107,19 @@ class DebugFS:
     def getpath(self, item):
         return os.path.join(self.mountpoint, item)
 
-# Exception class for when tracer is not available
+
 class DetectorNotAvailable(Exception):
+    """ Exception class for when tracer is not available """
+
     def __init__(self, name, msg):
         self.args = (name, msg)
         self.name = name
         self.msg = msg
 
-#
-# Class used to manage loading and unloading of the
-# hwlat kernel module. Like the debugfs class
-# above, if the module is already loaded, this class will
-# leave it alone when cleaning up.
-#
-class Kmod:
-    ''' class to manage loading and unloading of kernel modules'''
-
-    names = ("hwlat_detector", "smi_detector")
-
-    def __check_builtin(self):
-        for l in open(os.path.join('/lib/modules', os.uname()[2], 'modules.builtin'), "r"):
-            if self.name in l:
-                debug("found %s as builtin" % self.namename)
-                return True
-        return False
-
-    def __find_module(self):
-        debug("looking for module %s" % self.name)
-        path = os.path.join("/lib/modules",
-                            os.uname()[2],
-                            "kernel/drivers/misc")
-        debug("module path: %s" % path)
-        mpath = os.path.join(path, self.name) + ".ko"
-        debug("checking %s" % mpath)
-        if os.path.exists(mpath):
-            return True
-        return False
-
-    def __init__(self, name):
-        if name not in Kmod.names:
-            raise RuntimeError("unsupported module name: %s" % name)
-        if name == "smi_detector":
-            raise RuntimeError("smi_detector module no longer supported!")
-        self.name = name
-        self.preloaded = False
-        self.builtin = False
-
-        # check for builtin
-        if self.__check_builtin():
-            self.builtin = True
-            return
-
-        # now look for already loaded module
-        for l in open('/proc/modules'):
-            field = l.split()
-            if self.name in field[0]:
-                self.preloaded = True
-                debug("using already loaded %s" % self.name)
-                return
-        if not self.__find_module():
-            raise DetectorNotAvailable(name, "module %s does not exist!" % self.name)
-
-    def load(self):
-        if self.builtin:
-            debug("not loading %s (builtin)" % self.name)
-            return True
-        if self.preloaded:
-            debug("not loading %s (already loaded)" % self.name)
-            return True
-        cmd = ['/sbin/modprobe', self.name]
-        return subprocess.call(cmd) == 0
-
-    def unload(self):
-        if self.preloaded or self.builtin:
-            debug("Not unloading %s" % self.name)
-            return True
-        cmd = ['/sbin/modprobe', '-r', self.name]
-        return subprocess.call(cmd) == 0
 
-#
-# base class for detection modules
-#
 class Detector:
-    '''base class for detector modules'''
+    """ base class for detector modules """
+
     def __init__(self):
         self.type = "unknown"
         if os.getuid() != 0:
@@ -195,7 +128,7 @@ class Detector:
         if not self.debugfs.mount():
             raise RuntimeError("failed to mount debugfs")
         self.samples = []
-        self.testduration = 30 # ten seconds
+        self.testduration = 30  # ten seconds
         self.have_msr = False
         self.initsmi = []
         if os.path.exists('/usr/sbin/rdmsr'):
@@ -283,11 +216,11 @@ class Detector:
     @abc.abstractmethod
     def detect(self):
         ''' get detector output '''
-#
-# class to handle running the hwlat tracer module of ftrace
-#
+
+
 class Tracer(Detector):
-    '''class to wrap access to ftrace hwlat tracer'''
+    """ Class to handle running the hwlat tracer module of ftrace """
+
     __field_translation = {
         'width'     : "hwlat_detector/width",
         'window'    : "hwlat_detector/window",
@@ -298,9 +231,10 @@ class Tracer(Detector):
     class Sample:
         'private class for tracer sample data'
         __slots__ = 'timestamp', 'inner', 'outer'
+
         def __init__(self, line):
             fields = line.split()
-            i,o = fields[6].split('/')
+            i, o = fields[6].split('/')
             ts = fields[7][3:]
             self.timestamp = str(ts)
             self.inner = int(i)
@@ -383,7 +317,6 @@ class Tracer(Detector):
                     f.write("%s\n" % str(s))
                 print("report saved to %s (%d samples)" % (output, len(self.samples)))
 
-
     def display(self):
         for s in self.samples:
             s.display()
@@ -414,6 +347,7 @@ def seconds(str):
     else:
         raise RuntimeError("invalid input for seconds: '%s'" % str)
 
+
 def milliseconds(str):
     "convert input string to millsecond value"
     if str.isdigit():
@@ -443,9 +377,6 @@ def microseconds(str):
     else:
         raise RuntimeError("invalid input for microseconds: '%s'" % str)
 
-#
-# main starts here
-#
 
 if __name__ == '__main__':
     from argparse import ArgumentParser
@@ -533,7 +464,7 @@ if __name__ == '__main__':
     if args.duration:
         detect.testduration = seconds(args.duration)
     else:
-        detect.testduration = 120 # 2 minutes
+        detect.testduration = 120  # 2 minutes
     debug("test duration is %ds" % detect.testduration)
 
     if args.watch:
@@ -569,7 +500,7 @@ if __name__ == '__main__':
     if detect.have_msr:
         finishsmi = detect.getsmicounts()
         total_smis = 0
-        for i,count in enumerate(finishsmi):
+        for i, count in enumerate(finishsmi):
             if count > detect.initsmi[i]:
                 smis = count - detect.initsmi[i]
                 total_smis += smis
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 14/17] rt-tests: hwlatdetect: Don't use built-in name str as a variable
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (11 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 13/17] rt-tests: hwlatdetect: Remove unused class Kmod John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 15/17] rt-tests: cyclictest: Drop unused defines John Kacur
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, John Kacur

- Don't use built-in name "str" as a variable
- Add some more docstrings to methods

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/hwlatdetect/hwlatdetect.py | 122 +++++++++++++++++----------------
 1 file changed, 63 insertions(+), 59 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index c22e5eba25f6..27c2b8a2d138 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -21,14 +21,16 @@ quiet = False
 watch = False
 
 
-def debug(str):
+def debug(dstr):
+    """ print debugging string if debugging is on """
     if debugging:
-        print(str)
+        print(dstr)
 
 
-def info(str):
+def info(istr):
+    " print info string if quiet is not on """
     if not quiet:
-        print(str)
+        print(istr)
 
 
 #
@@ -39,7 +41,7 @@ def info(str):
 # it mounted.
 #
 class DebugFS:
-    '''class to manage mounting/umounting the debugfs'''
+    """ class to manage mounting/umounting the debugfs """
     def __init__(self):
         self.premounted = False
         self.mounted = False
@@ -53,6 +55,7 @@ class DebugFS:
                     break
 
     def mount(self, path='/sys/kernel/debug'):
+        """ mount debugfs unless already mounted """
         if self.premounted or self.mounted:
             debug("not mounting debugfs")
             return True
@@ -65,6 +68,7 @@ class DebugFS:
         return self.mounted
 
     def umount(self):
+        """ unmount debugfs if not premounted """
         if self.premounted or not self.mounted:
             debug("not umounting debugfs")
             return True
@@ -76,6 +80,7 @@ class DebugFS:
         return not self.mounted
 
     def getval(self, item, nonblocking=False):
+        """ get value of mountpoint/item """
         path = os.path.join(self.mountpoint, item)
         if nonblocking is False:
             with open(path) as f:
@@ -90,21 +95,18 @@ class DebugFS:
                     val = None
                 else:
                     raise
-            except IOError as e:
-                if e.errno == errno.EAGAIN:
-                    val = None
-                else:
-                    raise
             f.close()
         return val
 
     def putval(self, item, value):
+        """ write value to mountpoint/item """
         path = os.path.join(self.mountpoint, item)
         with open(path, "w") as f:
             f.write(str(value))
             f.flush()
 
     def getpath(self, item):
+        """ get mountpoint/item """
         return os.path.join(self.mountpoint, item)
 
 
@@ -153,12 +155,14 @@ class Detector:
     # use c_states_on() to close the file descriptor and re-enable c-states
     #
     def c_states_off(self):
+        """ disable c-state transitions """
         if os.path.exists("/dev/cpu_dma_latency"):
             self.dma_latency_handle = os.open("/dev/cpu_dma_latency", os.O_WRONLY)
             os.write(self.dma_latency_handle, b'\x00\x00\x00\x00')
             debug("c-states disabled")
 
     def c_states_on(self):
+        """ close the file descriptor and re-enable c-states """
         if self.dma_latency_handle:
             os.close(self.dma_latency_handle)
             debug("c-states enabled")
@@ -184,6 +188,7 @@ class Detector:
         ''' output the sample data as a string '''
 
     def start(self):
+        """ enable the detector """
         count = 0
         threshold = int(self.get("threshold"))
         self.c_states_off()
@@ -201,6 +206,7 @@ class Detector:
         debug("detector module enabled (threshold: %d)" % int(self.get("threshold")))
 
     def stop(self):
+        """ disable the detector """
         count = 0
         debug("disabling detector module")
         self.set("enable", 0)
@@ -244,12 +250,12 @@ class Tracer(Detector):
             return "ts: %s, inner:%d, outer:%d" % (self.timestamp, self.inner, self.outer)
 
         def display(self):
+            """ convert object to string and print """
             print(str(self))
 
         def largest(self):
-            if self.inner > self.outer:
-                return self.inner
-            return self.outer
+            """ return largest value of inner or outer """
+            return max(self.inner, self.outer)
 
     def translate(self, field):
         path = self.debugfs.getpath('tracing')
@@ -274,7 +280,7 @@ class Tracer(Detector):
     def get(self, field):
         if field == "count":
             return len(self.samples)
-        elif field == "max":
+        if field == "max":
             max = 0
             for values in self.samples:
                 s = int(values.largest())
@@ -311,6 +317,7 @@ class Tracer(Detector):
         return val
 
     def save(self, output=None):
+        """ save samples """
         if output:
             with open(output, "w") as f:
                 for s in self.samples:
@@ -328,54 +335,51 @@ class Tracer(Detector):
             raise RuntimeError("Failed to unmount debugfs")
 
 
-def seconds(str):
+def seconds(sval):
     "convert input string to value in seconds"
-    if str.isdigit():
-        return int(str)
-    elif str[-2].isalpha():
-        raise RuntimeError("illegal suffix for seconds: '%s'" % str[-2:-1])
-    elif str[-1:] == 's':
-        return int(str[0:-1])
-    elif str[-1:] == 'm':
-        return int(str[0:-1]) * 60
-    elif str[-1:] == 'h':
-        return int(str[0:-1]) * 3600
-    elif str[-1:] == 'd':
-        return int(str[0:-1]) * 86400
-    elif str[-1:] == 'w':
-        return int(str[0:-1]) * 86400 * 7
-    else:
-        raise RuntimeError("invalid input for seconds: '%s'" % str)
-
-
-def milliseconds(str):
+    if sval.isdigit():
+        return int(sval)
+    if sval[-2].isalpha():
+        raise RuntimeError("illegal suffix for seconds: '%s'" % sval[-2:-1])
+    if sval[-1:] == 's':
+        return int(sval[0:-1])
+    if sval[-1:] == 'm':
+        return int(sval[0:-1]) * 60
+    if sval[-1:] == 'h':
+        return int(sval[0:-1]) * 3600
+    if sval[-1:] == 'd':
+        return int(sval[0:-1]) * 86400
+    if sval[-1:] == 'w':
+        return int(sval[0:-1]) * 86400 * 7
+    raise RuntimeError("invalid input for seconds: '%s'" % sval)
+
+
+def milliseconds(sval):
     "convert input string to millsecond value"
-    if str.isdigit():
-        return int(str)
-    elif str[-2:] == 'ms':
-        return int(str[0:-2])
-    elif str[-1] == 's':
-        return int(str[0:-2]) * 1000
-    elif str[-1] == 'm':
-        return int(str[0:-1]) * 1000 * 60
-    elif str[-1] == 'h':
-        return int(str[0:-1]) * 1000 * 60 * 60
-    else:
-        raise RuntimeError("invalid input for milliseconds: %s" % str)
-
-
-def microseconds(str):
+    if sval.isdigit():
+        return int(sval)
+    if sval[-2:] == 'ms':
+        return int(sval[0:-2])
+    if sval[-1] == 's':
+        return int(sval[0:-2]) * 1000
+    if sval[-1] == 'm':
+        return int(sval[0:-1]) * 1000 * 60
+    if sval[-1] == 'h':
+        return int(sval[0:-1]) * 1000 * 60 * 60
+    raise RuntimeError("invalid input for milliseconds: %s" % sval)
+
+
+def microseconds(sval):
     "convert input string to microsecond value"
-    if str.isdigit():
-        return int(str)
-    elif str[-2:] == 'ms':
-        return int(str[0:-2]) * 1000
-    elif str[-2:] == 'us':
-        return int(str[0:-2])
-    elif str[-1:] == 's':
-        return int(str[0:-1]) * 1000 * 1000
-    else:
-        raise RuntimeError("invalid input for microseconds: '%s'" % str)
+    if sval.isdigit():
+        return int(sval)
+    if sval[-2:] == 'ms':
+        return int(sval[0:-2]) * 1000
+    if sval[-2:] == 'us':
+        return int(sval[0:-2])
+    if sval[-1:] == 's':
+        return int(sval[0:-1]) * 1000 * 1000
+    raise RuntimeError("invalid input for microseconds: '%s'" % sval)
 
 
 if __name__ == '__main__':
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 15/17] rt-tests: cyclictest: Drop unused defines
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (12 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 14/17] rt-tests: hwlatdetect: Don't use built-in name str as a variable John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 16/17] rt-tests: cyclictest: Simplify duplicate initialization of "stop" John Kacur
  2021-11-11 20:42 ` [PATCH 17/17] rt-tests: cyclictest: Drop unnecessary variable "bufsize" John Kacur
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, Punit Agrawal, John Kacur

From: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

KVARS, KVARNAMELEN and KVALUELEN defines are not used in
cyclictest. Drop them.

Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index e4d43481de97..5758f88a24d0 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -99,10 +99,6 @@ extern int clock_nanosleep(clockid_t __clock_id, int __flags,
 /* Must be power of 2 ! */
 #define VALBUF_SIZE		16384
 
-#define KVARS			32
-#define KVARNAMELEN		32
-#define KVALUELEN		32
-
 #if (defined(__i386__) || defined(__x86_64__))
 #define ARCH_HAS_SMI_COUNTER
 #endif
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 16/17] rt-tests: cyclictest: Simplify duplicate initialization of "stop"
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (13 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 15/17] rt-tests: cyclictest: Drop unused defines John Kacur
@ 2021-11-11 20:42 ` John Kacur
  2021-11-11 20:42 ` [PATCH 17/17] rt-tests: cyclictest: Drop unnecessary variable "bufsize" John Kacur
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, Punit Agrawal, John Kacur

From: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

The timespec structure "stop" is initialised whether it is used or not
as the compiler is not smart enough to figure out that it's use is
always guarded by the "duration" variable. As a result, "stop" needs
to be initialised whether it's used or not to avoid a compiler
warning.

Replace the duplicate memset statements by initializing "stop" using
structure initialiser.

Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 5758f88a24d0..73c5be972391 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -507,7 +507,7 @@ static void *timerthread(void *param)
 	struct sigevent sigev;
 	sigset_t sigset;
 	timer_t timer;
-	struct timespec now, next, interval, stop;
+	struct timespec now, next, interval, stop = { 0 };
 	struct itimerval itimer;
 	struct itimerspec tspec;
 	struct thread_stat *stat = par->stats;
@@ -516,8 +516,6 @@ static void *timerthread(void *param)
 	pthread_t thread;
 	unsigned long smi_now, smi_old = 0;
 
-	memset(&stop, 0, sizeof(stop));
-
 	/* if we're running in numa mode, set our memory node */
 	if (par->node != -1)
 		rt_numa_set_numa_run_on_node(par->node, par->cpu);
@@ -598,7 +596,6 @@ static void *timerthread(void *param)
 	tsnorm(&next);
 
 	if (duration) {
-		memset(&stop, 0, sizeof(stop)); /* grrr */
 		stop = now;
 		stop.tv_sec += duration;
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 17/17] rt-tests: cyclictest: Drop unnecessary variable "bufsize"
  2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
                   ` (14 preceding siblings ...)
  2021-11-11 20:42 ` [PATCH 16/17] rt-tests: cyclictest: Simplify duplicate initialization of "stop" John Kacur
@ 2021-11-11 20:42 ` John Kacur
  15 siblings, 0 replies; 17+ messages in thread
From: John Kacur @ 2021-11-11 20:42 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Leah Leshchinsky, Punit Agrawal, John Kacur

From: Punit Agrawal <punit1.agrawal@toshiba.co.jp>

Two copies of "bufsize", initialised with the same value are declared
in enclosed blocks. Remove the redundant declaration.

Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 73c5be972391..490aedb54c03 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -2059,7 +2059,6 @@ int main(int argc, char **argv)
 			memset(stat->values, 0, bufsize);
 			par->bufmsk = VALBUF_SIZE - 1;
 			if (smi) {
-				int bufsize = VALBUF_SIZE * sizeof(long);
 				stat->smis = threadalloc(bufsize, node);
 				if (!stat->smis)
 					goto outall;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-11-11 20:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11 20:41 [PATCH 01/17] rt-tests:hwlatdetect: Remove useless object in class declaration John Kacur
2021-11-11 20:41 ` [PATCH 02/17] rt-tests:hwlatdetect.py: Remove multiple statements on one line John Kacur
2021-11-11 20:41 ` [PATCH 03/17] rt-tests:hwlatdetect.py: Remove unnecessary 'not' John Kacur
2021-11-11 20:41 ` [PATCH 04/17] rt-tests: deadline_tests: Null check to prevent floating point exception John Kacur
2021-11-11 20:41 ` [PATCH 05/17] rt-tests: cyclictest: Check user supplies an value to histogram John Kacur
2021-11-11 20:41 ` [PATCH 06/17] rt-tests: get_cyclictest_snapshot: print_warning should be a classmethod John Kacur
2021-11-11 20:41 ` [PATCH 07/17] rt-tests: hwlatdetect: Remove unnessary parens after return John Kacur
2021-11-11 20:41 ` [PATCH 08/17] rt-tests: hwlatdetect: Use "with" for opening files John Kacur
2021-11-11 20:41 ` [PATCH 09/17] rt-tests: hwlatdetect: Use python3 style super() John Kacur
2021-11-11 20:42 ` [PATCH 10/17] rt-tests: hwlatdetect: Keep consistent name from abstract method John Kacur
2021-11-11 20:42 ` [PATCH 11/17] rt-tests: hwlatdetect: Remove class Hwlat John Kacur
2021-11-11 20:42 ` [PATCH 12/17] rt-tests: hwlatdetect: Use abstractmethod decorator John Kacur
2021-11-11 20:42 ` [PATCH 13/17] rt-tests: hwlatdetect: Remove unused class Kmod John Kacur
2021-11-11 20:42 ` [PATCH 14/17] rt-tests: hwlatdetect: Don't use built-in name str as a variable John Kacur
2021-11-11 20:42 ` [PATCH 15/17] rt-tests: cyclictest: Drop unused defines John Kacur
2021-11-11 20:42 ` [PATCH 16/17] rt-tests: cyclictest: Simplify duplicate initialization of "stop" John Kacur
2021-11-11 20:42 ` [PATCH 17/17] rt-tests: cyclictest: Drop unnecessary variable "bufsize" John Kacur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.