[pypy-commit] pypy stm-gc: Add the modified version of richards I use.

arigo noreply at buildbot.pypy.org
Thu Feb 16 21:57:01 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52572:bba9b03f5e70
Date: 2012-02-16 21:56 +0100
http://bitbucket.org/pypy/pypy/changeset/bba9b03f5e70/

Log:	Add the modified version of richards I use.

diff --git a/pypy/translator/goal/richards.py b/pypy/translator/stm/test/richards.py
copy from pypy/translator/goal/richards.py
copy to pypy/translator/stm/test/richards.py
--- a/pypy/translator/goal/richards.py
+++ b/pypy/translator/stm/test/richards.py
@@ -7,6 +7,9 @@
 #  Translation from C++, Mario Wolczko
 #  Outer loop added by Alex Jacoby
 
+import transaction
+
+
 # Task IDs
 I_IDLE = 1
 I_WORK = 2
@@ -151,12 +154,11 @@
         self.holdCount = 0
         self.qpktCount = 0
 
-taskWorkArea = TaskWorkArea()
-
 class Task(TaskState):
 
 
-    def __init__(self,i,p,w,initialState,r):
+    def __init__(self,i,p,w,initialState,r, taskWorkArea):
+        self.taskWorkArea = taskWorkArea
         self.link = taskWorkArea.taskList
         self.ident = i
         self.priority = p
@@ -206,7 +208,7 @@
 
 
     def hold(self):
-        taskWorkArea.holdCount += 1
+        self.taskWorkArea.holdCount += 1
         self.task_holding = True
         return self.link
 
@@ -222,14 +224,14 @@
 
     def qpkt(self,pkt):
         t = self.findtcb(pkt.ident)
-        taskWorkArea.qpktCount += 1
+        self.taskWorkArea.qpktCount += 1
         pkt.link = None
         pkt.ident = self.ident
         return t.addPacket(pkt,self)
 
 
     def findtcb(self,id):
-        t = taskWorkArea.taskTab[id]
+        t = self.taskWorkArea.taskTab[id]
         if t is None:
             raise Exception("Bad task id %d" % id)
         return t
@@ -239,8 +241,8 @@
 
 
 class DeviceTask(Task):
-    def __init__(self,i,p,w,s,r):
-        Task.__init__(self,i,p,w,s,r)
+    def __init__(self,i,p,w,s,r, taskWorkArea):
+        Task.__init__(self,i,p,w,s,r, taskWorkArea)
 
     def fn(self,pkt,r):
         d = r
@@ -260,8 +262,8 @@
 
 
 class HandlerTask(Task):
-    def __init__(self,i,p,w,s,r):
-        Task.__init__(self,i,p,w,s,r)
+    def __init__(self,i,p,w,s,r, taskWorkArea):
+        Task.__init__(self,i,p,w,s,r, taskWorkArea)
 
     def fn(self,pkt,r):
         h = r
@@ -292,8 +294,8 @@
 
 
 class IdleTask(Task):
-    def __init__(self,i,p,w,s,r):
-        Task.__init__(self,i,0,None,s,r)
+    def __init__(self,i,p,w,s,r, taskWorkArea):
+        Task.__init__(self,i,0,None,s,r, taskWorkArea)
 
     def fn(self,pkt,r):
         i = r
@@ -315,8 +317,8 @@
 A = ord('A')
 
 class WorkTask(Task):
-    def __init__(self,i,p,w,s,r):
-        Task.__init__(self,i,p,w,s,r)
+    def __init__(self,i,p,w,s,r, taskWorkArea):
+        Task.__init__(self,i,p,w,s,r, taskWorkArea)
 
     def fn(self,pkt,r):
         w = r
@@ -345,9 +347,12 @@
 
 
 
-def schedule():
+def prepare_schedule(taskWorkArea):
     t = taskWorkArea.taskList
-    while t is not None:
+    transaction.add(schedule_one, taskWorkArea, t)
+
+def schedule_one(taskWorkArea, t):
+    if t is not None:
         pkt = None
 
         if tracing:
@@ -359,41 +364,53 @@
             if tracing: trace(chr(ord("0")+t.ident))
             t = t.runTask()
 
+        transaction.add(schedule_one, taskWorkArea, t)
+
+    else:
+        if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
+            pass
+        else:
+            raise Exception, "Incorrect results!"
+
+
 class Richards(object):
 
     def run(self, iterations):
         for i in xrange(iterations):
+            self.prepare_once()
+        transaction.run()
+        return True
+
+    def prepare_once(self):
+            taskWorkArea = TaskWorkArea()
             taskWorkArea.holdCount = 0
             taskWorkArea.qpktCount = 0
 
-            IdleTask(I_IDLE, 1, 10000, TaskState().running(), IdleTaskRec())
+            IdleTask(I_IDLE, 1, 10000, TaskState().running(), IdleTaskRec(), taskWorkArea)
 
             wkq = Packet(None, 0, K_WORK)
             wkq = Packet(wkq , 0, K_WORK)
-            WorkTask(I_WORK, 1000, wkq, TaskState().waitingWithPacket(), WorkerTaskRec())
+            WorkTask(I_WORK, 1000, wkq, TaskState().waitingWithPacket(), WorkerTaskRec(),
+                     taskWorkArea)
 
             wkq = Packet(None, I_DEVA, K_DEV)
             wkq = Packet(wkq , I_DEVA, K_DEV)
             wkq = Packet(wkq , I_DEVA, K_DEV)
-            HandlerTask(I_HANDLERA, 2000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())
+            HandlerTask(I_HANDLERA, 2000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec(),
+                        taskWorkArea)
 
             wkq = Packet(None, I_DEVB, K_DEV)
             wkq = Packet(wkq , I_DEVB, K_DEV)
             wkq = Packet(wkq , I_DEVB, K_DEV)
-            HandlerTask(I_HANDLERB, 3000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())
+            HandlerTask(I_HANDLERB, 3000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec(),
+                        taskWorkArea)
 
             wkq = None;
-            DeviceTask(I_DEVA, 4000, wkq, TaskState().waiting(), DeviceTaskRec());
-            DeviceTask(I_DEVB, 5000, wkq, TaskState().waiting(), DeviceTaskRec());
+            DeviceTask(I_DEVA, 4000, wkq, TaskState().waiting(), DeviceTaskRec(), taskWorkArea);
+            DeviceTask(I_DEVB, 5000, wkq, TaskState().waiting(), DeviceTaskRec(), taskWorkArea);
             
-            schedule()
+            prepare_schedule(taskWorkArea)
 
-            if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
-                pass
-            else:
-                return False
-
-        return True
 
 def entry_point(iterations):
     r = Richards()
@@ -405,9 +422,6 @@
 def main(entry_point = entry_point, iterations = 10):
     print "Richards benchmark (Python) starting... [%r]" % entry_point
     result, startTime, endTime = entry_point(iterations)
-    if not result:
-        print "Incorrect results!"
-        return -1
     print "finished."
     total_s = endTime - startTime
     print "Total time for %d iterations: %.2f secs" %(iterations,total_s)
@@ -416,6 +430,7 @@
 
 if __name__ == '__main__':
     import sys
+    transaction.set_num_threads(4)
     if len(sys.argv) >= 2:
         main(iterations = int(sys.argv[1]))
     else:


More information about the pypy-commit mailing list