[pypy-commit] pypy reverse-debugger: still in-progress: write the ASYNC_THREAD_SWITCH blocks just
arigo
pypy.commits at gmail.com
Tue Aug 9 13:12:20 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r86120:46485b2edf2b
Date: 2016-08-09 19:11 +0200
http://bitbucket.org/pypy/pypy/changeset/46485b2edf2b/
Log: still in-progress: write the ASYNC_THREAD_SWITCH blocks just before
we write other things to the log
diff --git a/rpython/translator/c/src/thread.h b/rpython/translator/c/src/thread.h
--- a/rpython/translator/c/src/thread.h
+++ b/rpython/translator/c/src/thread.h
@@ -26,10 +26,6 @@
#endif /* !_WIN32 */
-#ifdef RPY_REVERSE_DEBUGGER
-RPY_EXTERN void rpy_reverse_db_thread_switch(void);
-#endif
-
RPY_EXTERN void RPyGilAllocate(void);
RPY_EXTERN long RPyGilYieldThread(void);
RPY_EXTERN void RPyGilAcquireSlowPath(long);
@@ -49,9 +45,6 @@
long old_fastgil = pypy_lock_test_and_set(&rpy_fastgil, 1);
if (old_fastgil != 0)
RPyGilAcquireSlowPath(old_fastgil);
-#ifdef RPY_REVERSE_DEBUGGER
- rpy_reverse_db_thread_switch();
-#endif
}
static inline void _RPyGilRelease(void) {
assert(RPY_FASTGIL_LOCKED(rpy_fastgil));
diff --git a/rpython/translator/revdb/src-revdb/revdb.c b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -56,8 +56,8 @@
static char rpy_rev_buffer[16384]; /* max. 32768 */
int rpy_rev_fileno = -1;
static char flag_io_disabled = FID_REGULAR_MODE;
-static pthread_t current_logged_thread;
-static bool_t current_logged_thread_seen;
+__thread bool_t rpy_active_thread;
+static bool_t *rpy_active_thread_ptr;
static void setup_record_mode(int argc, char *argv[]);
@@ -254,6 +254,9 @@
rpy_revdb.buf_limit = rpy_rev_buffer + sizeof(rpy_rev_buffer) - 32;
rpy_revdb.unique_id_seen = 1;
+ rpy_active_thread = 1;
+ rpy_active_thread_ptr = &rpy_active_thread;
+
pthread_atfork(NULL, NULL, close_revdb_fileno_in_fork_child);
}
@@ -292,18 +295,6 @@
}
}
-RPY_EXTERN
-void rpy_reverse_db_lock_acquire(void)
-{
- while (1) {
- if (rpy_revdb.lock == 0) {
- if (pypy_lock_test_and_set(&rpy_revdb.lock, 1) == 0)
- break; /* done */
- }
- sched_yield();
- }
-}
-
void boehm_gc_finalizer_notifier(void)
{
/* This is called by Boehm when there are pending finalizers.
@@ -339,6 +330,24 @@
_RPY_REVDB_UNLOCK();
}
+RPY_EXTERN
+void rpy_reverse_db_lock_acquire(void)
+{
+ assert(!RPY_RDB_REPLAY);
+ while (1) {
+ if (rpy_revdb.lock == 0) {
+ if (pypy_lock_test_and_set(&rpy_revdb.lock, 1) == 0)
+ break; /* done */
+ }
+ sched_yield();
+ }
+ /* we have acquired the lock here */
+ *rpy_active_thread_ptr = 0;
+ rpy_active_thread = 1;
+ rpy_active_thread_ptr = &rpy_active_thread;
+ emit_async_block(ASYNC_THREAD_SWITCH, (uint64_t)pthread_self());
+}
+
static void record_stop_point(void)
{
/* ===== FINALIZERS =====
@@ -374,26 +383,6 @@
}
RPY_EXTERN
-void rpy_reverse_db_thread_switch(void)
-{
- /* called at the end of _RPyGilAcquire(), when there was
- potentially a thread switch. If there actually was, emit an
- ASYNC_THREAD_SWITCH block. */
- pthread_t tself;
- assert(!RPY_RDB_REPLAY);
-
- tself = pthread_self();
- if (!current_logged_thread_seen) {
- current_logged_thread = tself;
- current_logged_thread_seen = 1;
- }
- else if (!pthread_equal(tself, current_logged_thread)) {
- emit_async_block(ASYNC_THREAD_SWITCH, (uint64_t)tself);
- current_logged_thread = tself;
- }
-}
-
-RPY_EXTERN
void rpy_reverse_db_call_destructor(void *obj)
{
/* old-style finalizers. Should occur only from the
diff --git a/rpython/translator/revdb/src-revdb/revdb_include.h b/rpython/translator/revdb/src-revdb/revdb_include.h
--- a/rpython/translator/revdb/src-revdb/revdb_include.h
+++ b/rpython/translator/revdb/src-revdb/revdb_include.h
@@ -23,6 +23,7 @@
RPY_EXTERN rpy_revdb_t rpy_revdb;
RPY_EXTERN int rpy_rev_fileno;
+RPY_EXTERN __thread bool_t rpy_active_thread;
/* ------------------------------------------------------------ */
@@ -64,7 +65,8 @@
single-threaded during replaying: the lock is only useful during
recording. */
#define _RPY_REVDB_LOCK() \
- if (pypy_lock_test_and_set(&rpy_revdb.lock, 1) != 0) \
+ if (!rpy_active_thread || \
+ pypy_lock_test_and_set(&rpy_revdb.lock, 1) != 0) \
rpy_reverse_db_lock_acquire();
#define _RPY_REVDB_UNLOCK() \
More information about the pypy-commit
mailing list