Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: Changeset: r1355:3107d8e61582 Date: 2014-09-05 11:07 +0200 http://bitbucket.org/pypy/stmgc/changeset/3107d8e61582/
Log: more progress diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -15,12 +15,14 @@ int my_segnum = STM_SEGMENT->segment_num; assert(!is_readable_log_page_in(my_segnum, pagenum)); + assert(!is_private_log_page_in(my_segnum, pagenum)); /* make readable */ assert(STM_PSEGMENT->privatization_lock); /* we hold it, nobody will privatize a page, necessary? */ pages_set_protection(my_segnum, pagenum, 1, PROT_READ|PROT_WRITE); + page_privatize(pagenum); assert(!is_shared_log_page(pagenum)); @@ -34,12 +36,30 @@ assert(is_readable_log_page_in(i, pagenum)); /* still... */ /* copy the content from there to our segment */ + dprintf(("pagecopy pagenum:%lu, src: %lu, dst:%lu\n", pagenum, i, my_segnum)); pagecopy((char*)(get_virt_page_of(my_segnum, pagenum) * 4096UL), (char*)(get_virt_page_of(i, pagenum) * 4096UL)); /* get valid state from backup copies of written objs in the range of this page: */ acquire_modified_objs_lock(i); + struct tree_s *tree = get_priv_segment(i)->modified_old_objects; + wlog_t *item; + TREE_LOOP_FORWARD(tree, item); + if (item->addr >= pagenum * 4096UL && item->addr < (pagenum + 1) * 4096UL) { + object_t *obj = (object_t*)item->addr; + struct object_s* bk_obj = (struct object_s *)item->val; + size_t obj_size; + + obj_size = stmcb_size_rounded_up(bk_obj); + assert(obj_size < 4096); /* XXX */ + + assert(obj->stm_flags & GCFLAG_WRITE_BARRIER); /* not written here */ + memcpy(REAL_ADDRESS(STM_SEGMENT->segment_base, obj), + bk_obj, obj_size); + assert(obj->stm_flags & GCFLAG_WRITE_BARRIER); /* still not written */ + } + TREE_LOOP_END; release_modified_objs_lock(i); @@ -206,14 +226,21 @@ if (i != my_segnum && i != 0) pages_set_protection(i, first_page, 1, PROT_NONE); + else /* both, seg0 and my_segnum: */ + pages_set_protection(i, first_page, 1, PROT_READ|PROT_WRITE); } /* remap pages for my_segnum and copy the contents */ - if (i != 0) { + set_page_private_in(0, first_page); + /* seg0 already up-to-date */ + if (my_segnum != 0) { page_privatize(first_page); pagecopy((char*)(get_virt_page_of(my_segnum, first_page) * 4096UL), (char*)(get_virt_page_of(0, first_page) * 4096UL)); } + + assert(is_private_log_page_in(my_segnum, first_page)); + assert(is_readable_log_page_in(my_segnum, first_page)); } void _stm_write_slowpath(object_t *obj) diff --git a/c8/stm/pages.c b/c8/stm/pages.c --- a/c8/stm/pages.c +++ b/c8/stm/pages.c @@ -77,15 +77,8 @@ volatile struct page_shared_s *ps2 = (volatile struct page_shared_s *) &pages_privatized[pagenum + amount - PAGE_FLAG_START]; - if (i == 0) { - /* readable & private */ - ps->by_segment |= bitmask; - ps2->by_segment |= bitmask; - } else { - /* not readable (ensured in setup.c), not private */ - ps->by_segment &= ~bitmask; - ps2->by_segment &= ~bitmask; - } + ps->by_segment |= bitmask; /* readable */ + ps2->by_segment = 0; /* not private */ } } } @@ -104,6 +97,8 @@ return; } + dprintf(("page_privatize(%lu) in seg:%d\n", pagenum, STM_SEGMENT->segment_num)); + /* add this thread's 'pages_privatized' bit */ ps->by_segment |= bitmask; @@ -122,23 +117,23 @@ /* we hopefully hold the privatization lock: */ assert(get_priv_segment(segnum)->privatization_lock); - char *addr = get_segment_base(segnum) + pagenum * 4096UL; + char *addr = get_virt_page_of(segnum, pagenum); mprotect(addr, count * 4096UL, prot); - long i; - for (i = 0; i < NB_SEGMENTS; i++) { - uint64_t bitmask = 1UL << i; - uintptr_t amount = count; - while (amount-->0) { - volatile struct page_shared_s *ps = (volatile struct page_shared_s *) - &pages_readable[pagenum + amount - PAGE_FLAG_START]; - if (prot == PROT_NONE) { - /* not readable */ - ps->by_segment &= ~bitmask; - } else { - assert(prot == (PROT_READ|PROT_WRITE)); - ps->by_segment |= bitmask; - } + dprintf(("pages_set_protection(%d, %lu, %lu, %d)\n", + segnum, pagenum, count, prot)); + + uint64_t bitmask = 1UL << segnum; + uintptr_t amount = count; + while (amount-->0) { + volatile struct page_shared_s *ps = (volatile struct page_shared_s *) + &pages_readable[pagenum + amount - PAGE_FLAG_START]; + if (prot == PROT_NONE) { + /* not readable */ + ps->by_segment &= ~bitmask; + } else { + assert(prot == (PROT_READ|PROT_WRITE)); + ps->by_segment |= bitmask; } } } diff --git a/c8/stm/pages.h b/c8/stm/pages.h --- a/c8/stm/pages.h +++ b/c8/stm/pages.h @@ -58,6 +58,14 @@ return pages_privatized[pagenum - PAGE_FLAG_START].by_segment == 0; } +static inline void set_page_private_in(long segnum, uintptr_t pagenum) +{ + uint64_t bitmask = 1UL << segnum; + volatile struct page_shared_s *ps = (volatile struct page_shared_s *) + &pages_privatized[pagenum - PAGE_FLAG_START]; + assert(!(ps->by_segment & bitmask)); + ps->by_segment |= bitmask; +} static inline bool is_private_log_page_in(long segnum, uintptr_t pagenum) { diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -68,16 +68,6 @@ mprotect(segment_base + 8192, (FIRST_READMARKER_PAGE - 2) * 4096UL, PROT_NONE); - - if (i != 0) { - /* let's give all pages to segment 0 at first, all others - need to trap and look for the backup copy */ - mprotect(segment_base + END_NURSERY_PAGE * 4096, - (NB_PAGES - END_NURSERY_PAGE) * 4096, - PROT_NONE); - /* pages_initialize_shared() makes sure pages_readable - is initialized correctly */ - } } } _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit