Author: Remi Meier
Branch: c7
Changeset: r665:1605e7b96e40
Date: 2014-01-22 14:06 +0100
http://bitbucket.org/pypy/stmgc/changeset/1605e7b96e40/

Log:    move a bit of the page management to its own file

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -15,7 +15,7 @@
 #include "pagecopy.h"
 #include "reader_writer_lock.h"
 #include "nursery.h"
-
+#include "pages.h"
 
 
 
@@ -27,19 +27,12 @@
 
 char *object_pages;
 static int num_threads_started;
-
-uint8_t flag_page_private[NB_PAGES];
 uint8_t write_locks[READMARKER_END - READMARKER_START];
 
 
 /************************************************************/
 
 
-uint8_t _stm_get_page_flag(int pagenum)
-{
-    return flag_page_private[pagenum];
-}
-
 static void spin_loop(void)
 {
     asm("pause" : : : "memory");
@@ -179,11 +172,6 @@
 
 
 
-bool _stm_is_young(object_t *o)
-{
-    assert((uintptr_t)o >= FIRST_NURSERY_PAGE * 4096);
-    return (uintptr_t)o < FIRST_AFTER_NURSERY_PAGE * 4096;
-}
 
 
 char *_stm_real_address(object_t *o)
@@ -292,12 +280,6 @@
 
 
 
-
-
-
-
-
-
 void stm_setup(void)
 {
     memset(&rw_shared_lock, 0, sizeof(rwticket));
@@ -465,11 +447,6 @@
     _STM_TL->transaction_read_version = 1;
 }
 
-void stm_major_collection(void)
-{
-    assert(_STM_TL->running_transaction);
-    abort();
-}
 
 void stm_start_transaction(jmpbufptr_t *jmpbufptr)
 {
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -37,21 +37,6 @@
     GCFLAG_MOVED = (1 << 2),
 };
 
-enum {
-    /* unprivatized page seen by all threads */
-    SHARED_PAGE=0,
-
-    /* page being in the process of privatization */
-    REMAPPING_PAGE,
-
-    /* page private for each thread */
-    PRIVATE_PAGE,
-
-    /* set for SHARED pages that only contain objects belonging
-       to the current transaction, so the whole page is not
-       visible yet for other threads */
-    UNCOMMITTED_SHARED_PAGE,
-};  /* flag_page_private */
 
 
 
@@ -128,7 +113,6 @@
 
 
 
-extern uint8_t flag_page_private[NB_PAGES];   /* xxx_PAGE constants above */
 extern char *object_pages;                    /* start of MMAP region */
 extern uint8_t write_locks[READMARKER_END - READMARKER_START];
 
@@ -198,7 +182,6 @@
 char *_stm_real_address(object_t *o);
 object_t *_stm_tl_address(char *ptr);
 
-bool _stm_is_young(object_t *o);
 object_t *_stm_allocate_old(size_t size);
 
 object_t *stm_allocate_prebuilt(size_t size);
@@ -209,7 +192,6 @@
 void stm_abort_transaction(void);
 
 void _stm_minor_collect();
-uint8_t _stm_get_page_flag(int pagenum);
 #define stm_become_inevitable(msg)   /* XXX implement me! */
 
 
diff --git a/c7/nursery.c b/c7/nursery.c
--- a/c7/nursery.c
+++ b/c7/nursery.c
@@ -13,28 +13,20 @@
 #include "core.h"
 #include "list.h"
 #include "nursery.h"
+#include "pages.h"
 
-uintptr_t index_page_never_used;
 
-uintptr_t _stm_reserve_pages(int num)
+void stm_major_collection(void)
 {
-    /* Grab a free page, initially shared between the threads. */
+    assert(_STM_TL->running_transaction);
+    abort();
+}
 
-    // XXX look in some free list first
 
-    /* Return the index'th object page, which is so far never used. */
-    uintptr_t index = __sync_fetch_and_add(&index_page_never_used, num);
-
-    int i;
-    for (i = 0; i < num; i++) {
-        assert(flag_page_private[index+i] == SHARED_PAGE);
-    }
-    assert(flag_page_private[index] == SHARED_PAGE);
-    if (index + num >= NB_PAGES) {
-        fprintf(stderr, "Out of mmap'ed memory!\n");
-        abort();
-    }
-    return index;
+bool _stm_is_young(object_t *o)
+{
+    assert((uintptr_t)o >= FIRST_NURSERY_PAGE * 4096);
+    return (uintptr_t)o < FIRST_AFTER_NURSERY_PAGE * 4096;
 }
 
 
@@ -44,12 +36,10 @@
     LIST_APPEND(_STM_TL->uncommitted_pages, (object_t*)pagenum);
 }
 
-
-
 object_t *_stm_allocate_old(size_t size)
 {
     int pages = (size + 4095) / 4096;
-    localchar_t* addr = (localchar_t*)(_stm_reserve_pages(pages) * 4096);
+    localchar_t* addr = (localchar_t*)(stm_pages_reserve(pages) * 4096);
 
     object_t* o = (object_t*)addr;
     o->stm_flags |= GCFLAG_WRITE_BARRIER;
@@ -78,7 +68,7 @@
     size_t size = size_class * 8;
 
     /* reserve a fresh new page */
-    page = _stm_reserve_pages(1);
+    page = stm_pages_reserve(1);
 
     /* mark as UNCOMMITTED_... */
     mark_page_as_uncommitted(page);
diff --git a/c7/nursery.h b/c7/nursery.h
--- a/c7/nursery.h
+++ b/c7/nursery.h
@@ -6,12 +6,14 @@
 object_t *stm_allocate(size_t size);
 
 void _stm_minor_collect();
+bool _stm_is_young(object_t *o);
 
 void nursery_on_abort();
 void nursery_on_commit();
 void nursery_on_start();
 
 
+
 extern uintptr_t index_page_never_used;
     
 
diff --git a/c7/pages.c b/c7/pages.c
new file mode 100644
--- /dev/null
+++ b/c7/pages.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <asm/prctl.h>
+#include <sys/prctl.h>
+#include <pthread.h>
+
+
+#include "core.h"
+#include "list.h"
+#include "pages.h"
+
+uint8_t flag_page_private[NB_PAGES];
+uintptr_t index_page_never_used;
+
+
+uint8_t _stm_get_page_flag(int pagenum)
+{
+    return flag_page_private[pagenum];
+}
+
+
+uintptr_t stm_pages_reserve(int num)
+{
+    /* grab free, possibly uninitialized pages */
+
+    // XXX look in some free list first
+
+    /* Return the index'th object page, which is so far never used. */
+    uintptr_t index = __sync_fetch_and_add(&index_page_never_used, num);
+
+    int i;
+    for (i = 0; i < num; i++) {
+        assert(flag_page_private[index+i] == SHARED_PAGE);
+    }
+    assert(flag_page_private[index] == SHARED_PAGE);
+    if (index + num >= NB_PAGES) {
+        fprintf(stderr, "Out of mmap'ed memory!\n");
+        abort();
+    }
+    return index;
+}
+
+
+
+
diff --git a/c7/pages.h b/c7/pages.h
new file mode 100644
--- /dev/null
+++ b/c7/pages.h
@@ -0,0 +1,23 @@
+enum {
+    /* unprivatized page seen by all threads */
+    SHARED_PAGE=0,
+
+    /* page being in the process of privatization */
+    REMAPPING_PAGE,
+
+    /* page private for each thread */
+    PRIVATE_PAGE,
+
+    /* set for SHARED pages that only contain objects belonging
+       to the current transaction, so the whole page is not
+       visible yet for other threads */
+    UNCOMMITTED_SHARED_PAGE,
+};  /* flag_page_private */
+
+
+uintptr_t stm_pages_reserve(int num);
+uint8_t _stm_get_page_flag(int pagenum);
+
+extern uint8_t flag_page_private[NB_PAGES];
+
+
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -9,11 +9,11 @@
 header_files = [os.path.join(parent_dir, _n) for _n in
                 """core.h pagecopy.h list.h
                 reader_writer_lock.h
-                nursery.h""".split()]
+                nursery.h pages.h""".split()]
 source_files = [os.path.join(parent_dir, _n) for _n in
                 """core.c pagecopy.c list.c
                 reader_writer_lock.c
-                nursery.c""".split()]
+                nursery.c pages.c""".split()]
 
 _pycache_ = os.path.join(parent_dir, 'test', '__pycache__')
 if os.path.exists(_pycache_):
@@ -101,6 +101,8 @@
 #include <assert.h>
 
 #include "core.h"
+#include "pages.h"
+#include "nursery.h"
 
 struct myobj_s {
     struct object_s hdr;
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to