Author: Remi Meier
Branch: c7
Changeset: r688:72d1d84af244
Date: 2014-01-29 13:51 +0100
http://bitbucket.org/pypy/stmgc/changeset/72d1d84af244/
Log: remove bogus assert; change some limits for sort.duh to work;
implement 'time' builtin in duhton
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -22,7 +22,7 @@
char *object_pages;
static int num_threads_started;
uint8_t write_locks[READMARKER_END - READMARKER_START];
-volatile uint8_t inevitable_lock;
+volatile uint8_t inevitable_lock __attribute__((aligned(64))); /* cache-line
alignment */
struct _thread_local1_s* _stm_dbg_get_tl(int thread)
{
@@ -113,7 +113,8 @@
_stm_chunk_pages((struct object_s*)REAL_ADDRESS(get_thread_base(0),
obj),
&pagenum2, &pages);
assert(pagenum == pagenum2);
- assert(pages == (stmcb_size(real_address(obj)) + 4095) / 4096);
+ /* assert(pages == (stmcb_size(real_address(obj)) + 4095) / 4096);
+ not true if obj spans two pages, but is itself smaller than 1 */
}
for (pagenum2 += pages - 1; pagenum2 >= pagenum; pagenum2--)
@@ -348,6 +349,7 @@
if (_STM_TL->active == 2)
return;
assert(_STM_TL->active == 1);
+ fprintf(stderr, "%c", 'I'+_STM_TL->thread_num*32);
uint8_t our_lock = _STM_TL->thread_num + 1;
do {
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -6,11 +6,11 @@
#include <stdbool.h>
#include <assert.h>
-#define NB_PAGES (256*256) // 256MB
+#define NB_PAGES (6*256*256) // 6*256MB
#define NB_THREADS 2
#define MAP_PAGES_FLAGS (MAP_SHARED | MAP_ANONYMOUS | MAP_NORESERVE)
#define LARGE_OBJECT_WORDS 36
-#define NB_NURSERY_PAGES 1024
+#define NB_NURSERY_PAGES 2048 // 8MB
#define LENGTH_SHADOW_STACK 163840
@@ -21,7 +21,7 @@
#define READMARKER_START ((FIRST_OBJECT_PAGE * 4096UL) >> 4)
#define FIRST_READMARKER_PAGE (READMARKER_START / 4096UL)
#define FIRST_AFTER_NURSERY_PAGE (FIRST_OBJECT_PAGE + NB_NURSERY_PAGES)
-#define HEAP_PAGES (((NB_PAGES - FIRST_AFTER_NURSERY_PAGE) * 2) / 3)
+#define HEAP_PAGES (((NB_PAGES - FIRST_AFTER_NURSERY_PAGE) * 3) / 4)
diff --git a/duhton/demo/sort.duh b/duhton/demo/sort.duh
--- a/duhton/demo/sort.duh
+++ b/duhton/demo/sort.duh
@@ -39,29 +39,39 @@
-(defun merge_lists (as bs res)
- ;; empties the two lists and merges the result to res
- (setq len_as (len as))
- (setq len_bs (len bs))
- (if (< 0 len_as)
- (if (< 0 len_bs)
- (if (> (get as 0) (get bs 0))
- (append res (pop bs 0))
- (append res (pop as 0))
- )
- (append res (pop as 0))
- )
- (if (< 0 len_bs)
- (append res (pop bs 0))
+(defun merge_lists (as bs)
+ ;; merges the two lists and returns a new one
+ (setq res (list))
+ (setq idxa 0)
+ (setq idxb 0)
+ (while (&& (< idxa (len as))
+ (< idxb (len bs)))
+ (if (> (get as idxa) (get bs idxb))
+ (progn
+ (append res (get bs idxb))
+ (setq idxb (+ idxb 1))
+ )
+ (append res (get as idxa))
+ (setq idxa (+ idxa 1))
)
)
- (if (|| (< 0 len_as) (< 0 len_bs))
- (merge_lists as bs res)
- )
+
+ (if (< idxa (len as))
+ (progn
+ (setq xs as)
+ (setq idxx idxa)
+ )
+ (setq xs bs)
+ (setq idxx idxb))
+
+ (while (< idxx (len xs))
+ (append res (get xs idxx))
+ (setq idxx (+ idxx 1)))
+
+ res
)
-
(defun split_list (xs)
;; empties xs and fills 2 new lists to be returned
(setq half_len (/ (len xs) 2))
@@ -80,18 +90,47 @@
)
+
(defun merge_sort (xs)
(if (<= (len xs) 1) ; 1 elem
xs
(progn ; many elems
(setq lists (split_list xs))
+
(setq left (merge_sort (get lists 0)))
(setq right (merge_sort (get lists 1)))
;; (print left right)
- (setq merged (list))
- (merge_lists left right merged)
- ;; (print (quote >) merged)
- merged
+ (merge_lists left right)
+ )
+ )
+ )
+
+(defun merge_sort_transaction (xs res-cont)
+ (set res-cont (merge_sort xs))
+ )
+
+(defun merge_sort_parallel (xs)
+ (if (<= (len xs) 1) ; 1 elem
+ xs
+ (progn ; many elems
+ (setq lists (split_list xs))
+ (setq left-c (container None))
+ (setq right-c (container None))
+
+ (transaction merge_sort_transaction
+ (get lists 0) left-c)
+ (transaction merge_sort_transaction
+ (get lists 1) right-c)
+ (print (quote start-transactions))
+ (run-transactions)
+ (print (quote finished-transactions))
+
+ (setq left (get left-c))
+ (setq right (get right-c))
+ (assert (<= (len left) (+ (len right) 2)))
+ (assert (<= (len right) (+ (len left) 2)))
+ ;; (print left right)
+ (merge_lists left right)
)
)
)
@@ -111,7 +150,16 @@
(print (quote len:) (len xs) (quote ->) xs)
)
-
+(defun is_sorted (xs)
+ (setq idx 0)
+ (while (< idx (- (len xs) 1))
+ (assert (<=
+ (get xs idx)
+ (get xs (+ idx 1))))
+ (setq idx (+ idx 1))
+ )
+ (quote true)
+ )
;; (setq as (random_list 20))
@@ -120,10 +168,22 @@
;; (print bs)
;; (print (split_list as))
-(setq cs (random_list 10000))
-(print_list cs)
-(print_list (merge_sort (copy_list cs)))
+(setq cs (random_list 50000))
+;; (print_list cs)
+;; (setq res (container None))
+;; (transaction merge_sort_transaction cs res)
+;; (run-transactions)
+;; (print (is_sorted (get res)))
+(setq current (time))
+(print (quote before-sorting:) current)
+(setq sorted (merge_sort_parallel cs))
+(print (quote after-sorting:) (time))
+(print (quote difference:) (- (time) current))
+(print (quote sorted:) (is_sorted sorted))
+
+
+
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -1,5 +1,6 @@
#include "duhton.h"
#include <sys/select.h>
+#include <sys/time.h>
pthread_t *all_threads;
int all_threads_count;
@@ -709,6 +710,18 @@
return Du_None;
}
+DuObject *du_time(DuObject *cons, DuObject *locals)
+{
+ struct timeval current;
+ long mtime;
+
+ gettimeofday(¤t, NULL);
+
+ mtime = ((current.tv_sec) * 1000 + current.tv_usec/1000.0) + 0.5;
+ return DuInt_FromInt(mtime & 0x7fffffff); /* make it always positive 32bit
*/
+}
+
+
DuObject *du_defined(DuObject *cons, DuObject *locals)
{
/* _du_read1(cons); IMMUTABLE */
@@ -810,6 +823,7 @@
DuFrame_SetBuiltinMacro(Du_Globals, "transaction", du_transaction);
DuFrame_SetBuiltinMacro(Du_Globals, "run-transactions",
du_run_transactions);
DuFrame_SetBuiltinMacro(Du_Globals, "sleepms", du_sleepms);
+ DuFrame_SetBuiltinMacro(Du_Globals, "time", du_time);
DuFrame_SetBuiltinMacro(Du_Globals, "defined?", du_defined);
DuFrame_SetBuiltinMacro(Du_Globals, "pair?", du_pair);
DuFrame_SetBuiltinMacro(Du_Globals, "assert", du_assert);
diff --git a/duhton/transaction.c b/duhton/transaction.c
--- a/duhton/transaction.c
+++ b/duhton/transaction.c
@@ -85,7 +85,10 @@
while (__builtin_setjmp(here) == 1) { }
restart:
- stm_start_transaction(&here);
+ // stm_start_transaction(&here);
+ /* this code is critical enough so that we want it to
+ be serialized perfectly using inevitable transactions */
+ stm_start_inevitable_transaction();
root = du_pending_transactions;
/* _du_read1(root); IMMUTABLE */
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit