Author: Armin Rigo <ar...@tunes.org>
Branch: stmgc-c7
Changeset: r70223:4eb53be43a92
Date: 2014-03-24 07:29 +0100
http://bitbucket.org/pypy/pypy/changeset/4eb53be43a92/

Log:    Add __pypy__.thread.getsegmentlimit()

diff --git a/TODO b/TODO
--- a/TODO
+++ b/TODO
@@ -34,6 +34,15 @@
 
 ------------------------------------------------------------
 
+__pypy__.thread.getsegmentlimit():
+
+XXX This limit is so far a compile time option (STM_NB_SEGMENTS in
+rpython/translator/stm/src_stm/stmgc.h), but this should instead be
+based on the machine found at run-time.  We should also be able to
+change the limit (or at least lower it) with setsegmentlimit().
+
+------------------------------------------------------------
+
 
 
 
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -41,6 +41,7 @@
         '_atomic_exit':            'interp_atomic.atomic_exit',
         'last_abort_info':         'interp_atomic.last_abort_info',
         'discard_last_abort_info': 'interp_atomic.discard_last_abort_info',
+        'getsegmentlimit':         'interp_atomic.getsegmentlimit',
     }
 
 
diff --git a/pypy/module/__pypy__/interp_atomic.py 
b/pypy/module/__pypy__/interp_atomic.py
--- a/pypy/module/__pypy__/interp_atomic.py
+++ b/pypy/module/__pypy__/interp_atomic.py
@@ -41,6 +41,24 @@
     raise wrap_thread_error(space,
         "atomic.__exit__(): more exits than enters")
 
+def getsegmentlimit(space):
+    '''Return the number of "segments" this PyPy is running with.
+
+With STM, multithreaded Python code executes on multiple segments in
+parallel.  This function gives the limit above which more threads will not
+be able to execute on more cores.  In a non-STM PyPy, this limit is 1.
+
+XXX This limit is so far a compile time option (STM_NB_SEGMENTS in
+rpython/translator/stm/src_stm/stmgc.h), but this should instead be
+based on the machine found at run-time.  We should also be able to
+change the limit (or at least lower it) with setsegmentlimit().
+'''
+    if space.config.translation.stm:
+        from rpython.rlib.rstm import stm_nb_segments
+        return space.wrap(stm_nb_segments)
+    else:
+        return space.wrap(1)
+
 def last_abort_info(space):
     from rpython.rlib.rstm import charp_inspect_abort_info
     p = charp_inspect_abort_info()
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -8,6 +8,7 @@
 
 TID = rffi.UINT
 tid_offset = CDefinedIntSymbolic('offsetof(struct rpyobj_s, tid)')
+stm_nb_segments = CDefinedIntSymbolic('STM_NB_SEGMENTS')
 adr_nursery_free = CDefinedIntSymbolic('((long)&STM_SEGMENT->nursery_current)')
 adr_nursery_top  = CDefinedIntSymbolic('((long)&STM_SEGMENT->nursery_end)')
 adr_transaction_read_version = (
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to