Author: Armin Rigo <[email protected]>
Branch: counter-decay
Changeset: r50538:642e93456721
Date: 2011-12-14 17:46 +0100
http://bitbucket.org/pypy/pypy/changeset/642e93456721/

Log:    Write the parametrisation of decaying counters, and a test. Missing
        the actual implementation.

diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -1557,6 +1557,13 @@
     in_recursion = 0
 
     def __init__(self, staticdata, jitdriver_sd):
+        try:
+            jitdriver_sd.warmstate.decay_counters
+        except AttributeError:   # for tests
+            pass
+        else:
+            jitdriver_sd.warmstate.decay_counters()
+        #
         self.staticdata = staticdata
         self.cpu = staticdata.cpu
         self.jitdriver_sd = jitdriver_sd
diff --git a/pypy/jit/metainterp/test/test_ajit.py 
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -2910,6 +2910,27 @@
         res = self.meta_interp(f, [32])
         assert res == f(32)
 
+    def test_decay_counters(self):
+        myjitdriver = JitDriver(greens = ['m'], reds = ['n'])
+        def f(m, n):
+            while n > 0:
+                myjitdriver.jit_merge_point(m=m, n=n)
+                n += m
+                n -= m
+                n -= 1
+        def main():
+            f(5, 7)      # run 7x with m=5           counter[m=5] = 7
+            f(15, 10)    # compiles one loop         counter[m=5] = 3  
(automatic decay)
+            f(5, 5)      # run 5x times with m=5     counter[m=5] = 8
+        #
+        self.meta_interp(main, [], decay_halflife=1,
+                         function_threshold=0, threshold=9, trace_eagerness=99)
+        self.check_trace_count(1)
+        #
+        self.meta_interp(main, [], decay_halflife=1,
+                         function_threshold=0, threshold=8, trace_eagerness=99)
+        self.check_trace_count(2)
+
 
 class TestOOtype(BasicTests, OOJitMixin):
 
diff --git a/pypy/jit/metainterp/test/test_warmstate.py 
b/pypy/jit/metainterp/test/test_warmstate.py
--- a/pypy/jit/metainterp/test/test_warmstate.py
+++ b/pypy/jit/metainterp/test/test_warmstate.py
@@ -275,3 +275,6 @@
     state.make_jitdriver_callbacks()
     res = state.can_never_inline(5, 42.5)
     assert res is True
+
+def test_decay_counters():
+    xxx
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -64,9 +64,11 @@
 
 def jittify_and_run(interp, graph, args, repeat=1, graph_and_interp_only=False,
                     backendopt=False, trace_limit=sys.maxint,
+                    threshold=3, trace_eagerness=2,
                     inline=False, loop_longevity=0, retrace_limit=5,
-                    function_threshold=4,
-                    enable_opts=ALL_OPTS_NAMES, max_retrace_guards=15, **kwds):
+                    function_threshold=4, decay_halflife=0,
+                    enable_opts=ALL_OPTS_NAMES, max_retrace_guards=15,
+                    **kwds):
     from pypy.config.config import ConfigError
     translator = interp.typer.annotator.translator
     try:
@@ -83,15 +85,16 @@
         pass
     warmrunnerdesc = WarmRunnerDesc(translator, backendopt=backendopt, **kwds)
     for jd in warmrunnerdesc.jitdrivers_sd:
-        jd.warmstate.set_param_threshold(3)          # for tests
+        jd.warmstate.set_param_threshold(threshold)
         jd.warmstate.set_param_function_threshold(function_threshold)
-        jd.warmstate.set_param_trace_eagerness(2)    # for tests
+        jd.warmstate.set_param_trace_eagerness(trace_eagerness)
         jd.warmstate.set_param_trace_limit(trace_limit)
         jd.warmstate.set_param_inlining(inline)
         jd.warmstate.set_param_loop_longevity(loop_longevity)
         jd.warmstate.set_param_retrace_limit(retrace_limit)
         jd.warmstate.set_param_max_retrace_guards(max_retrace_guards)
         jd.warmstate.set_param_enable_opts(enable_opts)
+        jd.warmstate.set_param_decay_halflife(decay_halflife)
     warmrunnerdesc.finish()
     if graph_and_interp_only:
         return interp, graph
diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py
--- a/pypy/jit/metainterp/warmstate.py
+++ b/pypy/jit/metainterp/warmstate.py
@@ -213,6 +213,12 @@
     def set_param_inlining(self, value):
         self.inlining = value
 
+    def set_param_decay_halflife(self, value):
+        if value <= 0:    # use 0 or -1 to mean "no decay"
+            self.decay_factor = 1.0
+        else:
+            self.decay_factor = 0.5 ** (1.0 / value)
+
     def set_param_enable_opts(self, value):
         from pypy.jit.metainterp.optimizeopt import ALL_OPTS_DICT, 
ALL_OPTS_NAMES
 
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -395,6 +395,7 @@
               'retrace_limit': 5,
               'max_retrace_guards': 15,
               'enable_opts': 'all',
+              'decay_halflife': 40,
               }
 unroll_parameters = unrolling_iterable(PARAMETERS.items())
 DEFAULT = object()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to