add "is_idle" capability to inorder.py so that after adding
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 18 Oct 2023 14:52:30 +0000 (15:52 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 22 Dec 2023 19:26:21 +0000 (19:26 +0000)
instructions the pipeline continues to propagate

src/openpower/cyclemodel/inorder.py

index 485b488ed74669f9429a850f199a9b453cd0c501..8d16515df7d7b324fd3e6cf4e7bb321942fee7f8 100644 (file)
@@ -170,6 +170,9 @@ class Execute:
             instruction['writes'].difference_update(writes_possible)
         return stall
 
+    def is_idle(self):
+        return len(self.stages) == 0
+
 
 class Fetch:
     """
@@ -198,6 +201,9 @@ class Fetch:
         self.stages[0] = insn_trace
         return stall
 
+    def is_idle(self):
+        return self.stages[0] is None
+
 
 class Decode:
     """
@@ -239,6 +245,10 @@ class Decode:
         self.cpu.issue.add_instruction(insn, writeregs)
         return stall
 
+    def is_idle(self):
+        return True
+
+
 class Issue:
     """
     Issue phase: if not stalled will place the instruction into execute.
@@ -266,6 +276,9 @@ class Issue:
         self.cpu.exe.add_instruction(insn, writeregs)
         return stall
 
+    def is_idle(self):
+        return True
+
 
 class CPU:
     """
@@ -319,6 +332,12 @@ class CPU:
         self.curr_clk += 1
         #print("---------------")
 
+    def is_idle(self):
+        return (self.fetch.is_idle() and
+                self.decode.is_idle() and
+                self.issue.is_idle() and
+                self.exe.is_idle())
+
     # TODO: Make formatting prettier, and conform to markdown table format
     # TODO: Adjust based on actual number of pipeline stages.
     def print_headings(self):
@@ -374,6 +393,9 @@ class TestTrace(unittest.TestCase):
         for trace in lines:
             #print(trace)
             basic_cpu.process_instructions(trace)
+        # wait for all instructions to finish
+        while not basic_cpu.is_idle():
+            basic_cpu.process_instructions(None)
 
     def test_trace1(self): # TODO, assert this is valid
         basic_cpu = CPU()
@@ -388,6 +410,10 @@ class TestTrace(unittest.TestCase):
         for trace in lines:
             #print(trace)
             basic_cpu.process_instructions(trace)
+        # wait for all instructions to finish
+        while not basic_cpu.is_idle():
+            basic_cpu.process_instructions(None)
+
 
 def help():
     print ("-t             runs unit tests")