Author: Armin Rigo <[email protected]>
Branch:
Changeset: r71:27f0605ccd79
Date: 2013-06-05 18:08 +0200
http://bitbucket.org/pypy/stmgc/changeset/27f0605ccd79/
Log: Starting on the read barrier.
diff --git a/c3/et.c b/c3/et.c
--- a/c3/et.c
+++ b/c3/et.c
@@ -137,10 +137,9 @@
#endif
}
+#if 0
static inline gcptr AddInReadSet(struct tx_descriptor *d, gcptr R)
{
- abort();
-#if 0
fprintf(stderr, "AddInReadSet(%p)\n", R);
d->count_reads++;
if (!fxcache_add(&d->recent_reads_cache, R)) {
@@ -155,37 +154,22 @@
// return Localize(d, R);
// }
return R;
+}
#endif
-}
-gcptr stm_DirectReadBarrier(gcptr G)
+gcptr stm_DirectReadBarrier(gcptr P)
{
- abort();
-#if 0
- gcptr R;
struct tx_descriptor *d = thread_descriptor;
- assert(d->active >= 1);
- /* XXX optimize me based on common patterns */
- R = HeadOfRevisionChainList(d, G);
+ if (P->h_tid & GCFLAG_PUBLIC)
+ {
+ abort();
+ /*...*/
+ }
- if (R->h_tid & GCFLAG_PUBLIC_TO_PRIVATE)
- {
- if (gcptrlist_size(&d->stolen_objects) > 0)
- stmgc_normalize_stolen_objects();
-
- wlog_t *entry;
- gcptr L;
- G2L_FIND(d->public_to_private, R, entry, goto not_found);
- L = entry->val;
- assert(L->h_revision == stm_local_revision);
- return L;
-
- not_found:;
- }
- R = AddInReadSet(d, R);
- return R;
-#endif
+ gcptrlist_insert(&d->list_of_read_objects, P);
+ fxcache_add(&d->recent_reads_cache, P);
+ return P;
}
static gcptr _latest_gcptr(gcptr R)
@@ -371,6 +355,14 @@
return entry->val;
}
+gcptr stm_get_read_obj(long index)
+{
+ struct tx_descriptor *d = thread_descriptor;
+ if (index < gcptrlist_size(&d->list_of_read_objects))
+ return d->list_of_read_objects.items[index];
+ return NULL;
+}
+
/************************************************************/
static revision_t GetGlobalCurTime(struct tx_descriptor *d)
diff --git a/c3/et.h b/c3/et.h
--- a/c3/et.h
+++ b/c3/et.h
@@ -177,6 +177,7 @@
gcptr stm_WriteBarrier(gcptr);
gcptr _stm_nonrecord_barrier(gcptr, int *);
gcptr stm_get_backup_copy(gcptr);
+gcptr stm_get_read_obj(long); /* debugging */
int DescriptorInit(void);
void DescriptorDone(void);
diff --git a/c3/lists.c b/c3/lists.c
--- a/c3/lists.c
+++ b/c3/lists.c
@@ -223,6 +223,8 @@
/************************************************************/
+__thread char *stm_read_barrier_cache;
+
void _fxcache_reset(struct FXCache *fxcache)
{
fxcache->shift = 0;
diff --git a/c3/lists.h b/c3/lists.h
--- a/c3/lists.h
+++ b/c3/lists.h
@@ -178,15 +178,17 @@
more.
*/
-#define FX_ENTRIES 8192
-#define FX_TOTAL (FX_ENTRIES * 2)
+#define FX_MASK 65535
+#define FX_ENTRIES ((FX_MASK + 1) / sizeof(char *))
+#define FX_TOTAL (FX_ENTRIES * 4 / 3)
struct FXCache {
- char *cache_start;
revision_t shift;
revision_t cache[FX_TOTAL];
};
+extern __thread char *stm_read_barrier_cache;
+
void _fxcache_reset(struct FXCache *fxcache);
static inline void fxcache_clear(struct FXCache *fxcache)
@@ -194,7 +196,16 @@
fxcache->shift++;
if (fxcache->shift > FX_TOTAL - FX_ENTRIES)
_fxcache_reset(fxcache);
- fxcache->cache_start = (char *)(fxcache->cache + fxcache->shift);
+ stm_read_barrier_cache = (char *)(fxcache->cache + fxcache->shift);
+}
+
+#define FXCACHE_AT(obj) \
+ (*(gcptr *)(stm_read_barrier_cache + ((revision_t)(obj) & FX_MASK)))
+
+static inline void fxcache_add(struct FXCache *fxcache, gcptr newobj)
+{
+ assert(stm_read_barrier_cache == (char*)(fxcache->cache + fxcache->shift));
+ FXCACHE_AT(newobj) = newobj;
}
/************************************************************/
diff --git a/c3/stmsync.c b/c3/stmsync.c
--- a/c3/stmsync.c
+++ b/c3/stmsync.c
@@ -77,12 +77,10 @@
gcptr stm_read_barrier(gcptr obj)
{
- /* XXX inline in the caller */
- abort();
-#if 0
- if (UNLIKELY(obj->h_revision != stm_local_revision))
+ /* XXX inline in the caller, optimize to get the smallest code */
+ if (UNLIKELY((obj->h_revision != stm_private_rev_num) &&
+ (FXCACHE_AT(obj) != obj)))
obj = stm_DirectReadBarrier(obj);
-#endif
return obj;
}
diff --git a/c3/test/support.py b/c3/test/support.py
--- a/c3/test/support.py
+++ b/c3/test/support.py
@@ -69,6 +69,7 @@
void stm_stop_sharedlock(void);
void AbortTransaction(int);
gcptr stm_get_backup_copy(gcptr);
+ gcptr stm_get_read_obj(long index);
gcptr getptr(gcptr, long);
void setptr(gcptr, long, gcptr);
@@ -528,3 +529,14 @@
return "backup"
else:
return "protected"
+
+def list_of_read_objects():
+ result = []
+ index = 0
+ while 1:
+ p = lib.stm_get_read_obj(index)
+ if p == ffi.NULL:
+ break
+ result.append(p)
+ index += 1
+ return result
diff --git a/c3/test/test_et.py b/c3/test/test_et.py
--- a/c3/test/test_et.py
+++ b/c3/test/test_et.py
@@ -141,3 +141,18 @@
assert p.h_revision == int(ffi.cast("revision_t", p2)) + 2
assert lib.rawgetlong(p, 0) == 28971289
assert lib.rawgetlong(p2, 0) == 1289222
+
+def test_read_barrier_private():
+ p = nalloc(HDR)
+ assert lib.stm_read_barrier(p) == p # no effect
+ assert p.h_tid == gettid(p)
+ assert p.h_revision == lib.get_private_rev_num()
+ assert list_of_read_objects() == []
+
+def test_read_barrier_protected():
+ p = nalloc(HDR)
+ lib.stm_commit_transaction()
+ lib.stm_begin_inevitable_transaction()
+ assert list_of_read_objects() == []
+ assert lib.stm_read_barrier(p) == p # record as a read object
+ assert list_of_read_objects() == [p]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit