Re: [Python-Dev] newgil for python 2.5.4

2010-01-21 Thread Ross Cohen
Done:
http://bugs.python.org/issue7753

Porting to 2.7 was easier since it didn't involve putting the
changesets listed in issue 4293.

The performance numbers in the bug are more accurate than the ones I
previously posted. Turns out the system python is not a good baseline.
The improvement from this patch isn't as good, but still ~15% for the 4
thread case. I hear rumor that platforms other than linux show much
better improvement from the new GIL.

Ross

On Wed, 20 Jan 2010 20:40:38 -0600
Benjamin Peterson benja...@python.org wrote:

 2010/1/20 Ross Cohen rco...@snurgle.org:
  Comments? Suggestions? I'm going to continue fixing this up, but was
  wondering if this could possibly make it into python 2.7.
 
 Yes, it could, but please post it to the tracker instead of attaching patches.
 
 
 
 -- 
 Regards,
 Benjamin
 
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] newgil for python 2.5.4

2010-01-20 Thread Ross Cohen
I put together this patch which switches 2.5.4 over to use the newgil.
This was generated by diffing change 76193 (last in the newgil branch)
against change 76189 and applying that on top of the changes listed in
issue 4293 (http://bugs.python.org/issue4293), specifically 68460, 68461
and 68722. There were only a couple of rejects, mostly in docs and tests
plus some irrelevant bits. I had to fix up one or 2 places by hand which
were pretty straightforward.

Only 2 tests are failing. test_capi looks to be a problem with the test
because it was from the py3k branch and test_command is failing for me,
which I need to look into.

Some performance tests (taken from
http://www.mail-archive.com/python-dev@python.org/msg43407.html):
Processor: Intel(R) Core(TM)2 Quad  CPU   Q9300  @ 2.50GHz
-j0
2.5.4 : 20.380s
newgil: 16.590s

-j4
2.5.4 : 27.440s
newgil: 20.120s

Comments? Suggestions? I'm going to continue fixing this up, but was
wondering if this could possibly make it into python 2.7.

Ross
diff --git a/Include/ceval.h b/Include/ceval.h
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -69,10 +69,6 @@
 PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
 PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
 
-/* this used to be handled on a per-thread basis - now just two globals */
-PyAPI_DATA(volatile int) _Py_Ticker;
-PyAPI_DATA(int) _Py_CheckInterval;
-
 /* Interface for threads.
 
A module that plans to do a blocking system call (or something else
@@ -131,6 +127,9 @@
 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
 PyAPI_FUNC(void) PyEval_ReInitThreads(void);
 
+PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
+PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
+
 #define Py_BEGIN_ALLOW_THREADS { \
 			PyThreadState *_save; \
 			_save = PyEval_SaveThread();
@@ -149,6 +148,7 @@
 #endif /* !WITH_THREAD */
 
 PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
+PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
 
 
 #ifdef __cplusplus
diff --git a/Include/pystate.h b/Include/pystate.h
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -82,6 +82,8 @@
 
 PyObject *dict;  /* Stores per-thread state */
 
+/* XXX doesn't mean anything anymore (the comment below is obsolete)
+   = deprecate or remove? */
 /* tick_counter is incremented whenever the check_interval ticker
  * reaches zero. The purpose is to give a useful measure of the number
  * of interpreted bytecode instructions in a given thread.  This
diff --git a/Include/sysmodule.h b/Include/sysmodule.h
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -19,7 +19,6 @@
 			Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
 
 PyAPI_DATA(PyObject *) _PySys_TraceFunc, *_PySys_ProfileFunc;
-PyAPI_DATA(int) _PySys_CheckInterval;
 
 PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
 PyAPI_FUNC(void) PySys_AddWarnOption(char *);
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -1,10 +1,98 @@
 # Run the _testcapi module tests (tests for the Python/C API):  by defn,
 # these are all functions _testcapi exports whose name begins with 'test_'.
 
+from __future__ import with_statement
 import sys
+import time
+import random
+import unittest
+import threading
 from test import test_support
 import _testcapi
 
+class TestPendingCalls(unittest.TestCase):
+
+def pendingcalls_submit(self, l, n):
+def callback():
+#this function can be interrupted by thread switching so let's
+#use an atomic operation
+l.append(None)
+
+for i in range(n):
+time.sleep(random.random()*0.02) #0.01 secs on average
+#try submitting callback until successful.
+#rely on regular interrupt to flush queue if we are
+#unsuccessful.
+while True:
+if _testcapi._pending_threadfunc(callback):
+break;
+
+def pendingcalls_wait(self, l, n, context = None):
+#now, stick around until l[0] has grown to 10
+count = 0;
+while len(l) != n:
+#this busy loop is where we expect to be interrupted to
+#run our callbacks.  Note that callbacks are only run on the
+#main thread
+if False and test_support.verbose:
+print (%i)%(len(l),),
+for i in xrange(1000):
+a = i*i
+if context and not context.event.is_set():
+continue
+count += 1
+self.failUnless(count  1,
+timeout waiting for %i callbacks, got %i%(n, len(l)))
+if False and test_support.verbose:
+print (%i)%(len(l),)
+
+def test_pendingcalls_threaded(self):
+
+#do every callback on a separate thread
+n = 32 #total callbacks
+threads = []
+class foo(object):pass
+context = foo()
+context.l = []
+

Re: [Python-Dev] newgil for python 2.5.4

2010-01-20 Thread Benjamin Peterson
2010/1/20 Ross Cohen rco...@snurgle.org:
 Comments? Suggestions? I'm going to continue fixing this up, but was
 wondering if this could possibly make it into python 2.7.

Yes, it could, but please post it to the tracker instead of attaching patches.



-- 
Regards,
Benjamin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com