[pypy-commit] pypy stmgc-c7: Add _stm.time() and _stm.clock().
arigo
noreply at buildbot.pypy.org
Wed Nov 12 16:09:40 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r74482:316291d870ae
Date: 2014-11-12 15:57 +0100
http://bitbucket.org/pypy/pypy/changeset/316291d870ae/
Log: Add _stm.time() and _stm.clock().
diff --git a/pypy/module/_stm/__init__.py b/pypy/module/_stm/__init__.py
--- a/pypy/module/_stm/__init__.py
+++ b/pypy/module/_stm/__init__.py
@@ -10,4 +10,6 @@
'local': 'local.STMLocal',
'count': 'count.count',
'hashtable': 'hashtable.W_Hashtable',
+ 'time': 'time.time',
+ 'clock': 'time.clock',
}
diff --git a/pypy/module/_stm/test/test_time.py b/pypy/module/_stm/test/test_time.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_stm/test/test_time.py
@@ -0,0 +1,13 @@
+
+
+class AppTestHashtable:
+ spaceconfig = dict(usemodules=['_stm'])
+
+ def test_simple(self):
+ import _stm
+ t1 = _stm.time()
+ t2 = _stm.time()
+ assert t1 < t2 < t1 + 1
+ t1 = _stm.clock()
+ t2 = _stm.clock()
+ assert t1 < t2 < t1 + 1
diff --git a/pypy/module/_stm/time.py b/pypy/module/_stm/time.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_stm/time.py
@@ -0,0 +1,56 @@
+"""
+_stm.time(), _stm.clock()
+"""
+
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
+
+# Linux-only for now
+
+eci = ExternalCompilationInfo(
+ includes=["time.h"],
+ libraries=["rt"],
+ post_include_bits = ["""
+double pypy_clock_get_time(void);
+double pypy_clock_get_clock(void);
+"""],
+ separate_module_sources = ["""
+double pypy_clock_get_time(void) {
+ struct timespec t = {-1, 0};
+ clock_gettime(CLOCK_REALTIME, &t);
+ return t.tv_sec + 0.000000001 * t.tv_nsec;
+}
+double pypy_clock_get_clock(void) {
+ struct timespec t = {-1, 0};
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
+ return t.tv_sec + 0.000000001 * t.tv_nsec;
+}
+"""])
+
+
+pypy_clock_get_time = rffi.llexternal('pypy_clock_get_time',
+ [], lltype.Float,
+ compilation_info=eci,
+ releasegil=False, transactionsafe=True)
+pypy_clock_get_clock = rffi.llexternal('pypy_clock_get_clock',
+ [], lltype.Float,
+ compilation_info=eci,
+ releasegil=False, transactionsafe=True)
+
+
+def time(space):
+ """Similar to time.time(), but works without conflict.
+The drawback is that the returned times may appear out of order:
+this thread's transaction may commit before or after another thread's,
+while _stm.time() called by both may return results in the opposite
+order (or even exactly equal results if you are unlucky)."""
+ return space.wrap(pypy_clock_get_time())
+
+def clock(space):
+ """Similar to time.clock(), but works without conflict.
+The drawback is that the returned times may appear out of order:
+this thread's transaction may commit before or after another thread's,
+while _stm.time() called by both may return results in the opposite
+order (or even exactly equal results if you are unlucky)."""
+ return space.wrap(pypy_clock_get_clock())
diff --git a/rpython/rtyper/module/ll_time.py b/rpython/rtyper/module/ll_time.py
--- a/rpython/rtyper/module/ll_time.py
+++ b/rpython/rtyper/module/ll_time.py
@@ -85,13 +85,11 @@
if self.GETTIMEOFDAY_NO_TZ:
c_gettimeofday = self.llexternal('gettimeofday',
[self.TIMEVALP], rffi.INT,
- _nowrapper=True, releasegil=False,
- transactionsafe=True)
+ _nowrapper=True, releasegil=False)
else:
c_gettimeofday = self.llexternal('gettimeofday',
[self.TIMEVALP, rffi.VOIDP], rffi.INT,
- _nowrapper=True, releasegil=False,
- transactionsafe=True)
+ _nowrapper=True, releasegil=False)
c_ftime = None # We have gettimeofday(2), so force ftime(3) OFF.
else:
c_gettimeofday = None
@@ -101,14 +99,12 @@
self.configure(CConfigForFTime)
c_ftime = self.llexternal(FTIME, [lltype.Ptr(self.TIMEB)],
lltype.Void,
- _nowrapper=True, releasegil=False,
- transactionsafe=True)
+ _nowrapper=True, releasegil=False)
else:
c_ftime = None # to not confuse the flow space
c_time = self.llexternal('time', [rffi.VOIDP], rffi.TIME_T,
- _nowrapper=True, releasegil=False,
- transactionsafe=True)
+ _nowrapper=True, releasegil=False)
def time_time_llimpl():
void = lltype.nullptr(rffi.VOIDP.TO)
@@ -146,10 +142,10 @@
A = lltype.FixedSizeArray(lltype.SignedLongLong, 1)
QueryPerformanceCounter = self.llexternal(
'QueryPerformanceCounter', [lltype.Ptr(A)], lltype.Void,
- releasegil=False, transactionsafe=True)
+ releasegil=False)
QueryPerformanceFrequency = self.llexternal(
'QueryPerformanceFrequency', [lltype.Ptr(A)], rffi.INT,
- releasegil=False, transactionsafe=True)
+ releasegil=False)
class State(object):
pass
state = State()
@@ -172,8 +168,7 @@
c_getrusage = self.llexternal('getrusage',
[rffi.INT, lltype.Ptr(RUSAGE)],
lltype.Void,
- releasegil=False,
- transactionsafe=True)
+ releasegil=False)
def time_clock_llimpl():
a = lltype.malloc(RUSAGE, flavor='raw')
c_getrusage(RUSAGE_SELF, a)
More information about the pypy-commit
mailing list