[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:393

From: ko1 atdot.net
Date: 8 Sep 2006 14:47:05 +0900
Subject: [yarv-diff:393] r560 - branches/parallel

Author: ko1
Date: 2006-09-08 14:47:04 +0900 (Fri, 08 Sep 2006)
New Revision: 560

Modified:
   branches/parallel/ChangeLog
   branches/parallel/gc.c
   branches/parallel/thread.c
Log:
	* gc.c : add GC profiler

	* thread.c : remove unused "rb_thread_global_lock_acquire_p"

	* thread.c : fix GC barrier stop routine and fix around this



Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog	2006-09-07 14:43:17 UTC (rev 559)
+++ branches/parallel/ChangeLog	2006-09-08 05:47:04 UTC (rev 560)
@@ -4,6 +4,15 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-09-08(Fri) 14:39:16 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* gc.c : add GC profiler
+
+	* thread.c : remove unused "rb_thread_global_lock_acquire_p"
+
+	* thread.c : fix GC barrier stop routine and fix around this
+
+
 2006-09-07(Thu) 22:47:20 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* thread.c : check that global lock is free when acquiring

Modified: branches/parallel/gc.c
===================================================================
--- branches/parallel/gc.c	2006-09-07 14:43:17 UTC (rev 559)
+++ branches/parallel/gc.c	2006-09-08 05:47:04 UTC (rev 560)
@@ -1368,24 +1368,51 @@
 
 static int garbage_collect_thread_unsafe(void);
 
+#define GCSTAT 0
+
 static int
 garbage_collect(void)
 {
     yarv_thread_t *th = GET_THREAD();
     int r;
+    struct timeval tvs, tve;
+    unsigned long d;
 
+    if (GCSTAT) {
+	gettimeofday(&tvs, 0);
+    }
+    
     GL_LOCK_RANGE(th, {
 	rb_thread_gc_barrier_start(th);
-	//fprintf(stderr, "gc: start\n");
+
+	if (GCSTAT) {
+	    gettimeofday(&tve, 0);
+	    d = tve.tv_sec * 1000000 + tve.tv_usec - (tvs.tv_sec * 1000000 + tvs.tv_usec);
+	    printf("gc [0]: %ld.%06ld sec\n", d/1000000, d%1000000);
+	}
+	
 	if (freelist == 0 || gc_stress) {
 	    r = garbage_collect_thread_unsafe();
 	}
 	else {
 	    r = Qtrue;
 	}
-	//fprintf(stderr, "gc: end\n");
+
+	if (GCSTAT) {
+	    gettimeofday(&tve, 0);
+	    d = tve.tv_sec * 1000000 + tve.tv_usec - (tvs.tv_sec * 1000000 + tvs.tv_usec);
+	    printf("gc [1]: %ld.%06ld sec\n", d/1000000, d%1000000);
+	}
+
 	rb_thread_gc_barrier_end(th);
+
+	if (GCSTAT) {
+	    gettimeofday(&tve, 0);
+	    d = tve.tv_sec * 1000000 + tve.tv_usec - (tvs.tv_sec * 1000000 + tvs.tv_usec);
+	    printf("gc [2]: %ld.%06ld sec\n", d/1000000, d%1000000);
+	}
     });
+
     return r;
 }
 

Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c	2006-09-07 14:43:17 UTC (rev 559)
+++ branches/parallel/thread.c	2006-09-08 05:47:04 UTC (rev 560)
@@ -137,6 +137,13 @@
 #define DEC_WAIT_THREAD(vm) ((vm)->num_wait_threads--)
 #endif
 
+#define LOCK_RANGE(lock, body) do { \
+  native_mutex_lock(lock); { \
+      body; \
+  } native_mutex_unlock(lock); \
+} while (0)
+
+
 static void __attribute__((destructor))
      pr_show(void)
 {
@@ -179,27 +186,23 @@
 
 	yarv_save_machine_context(th);
 
-	native_mutex_lock(&vm->gc_lock);
-	{
+	LOCK_RANGE(&vm->gc_lock, {
 	    INC_WAIT_THREAD(vm);
 	    if (vm->interrupt_gc_flag) {
 		native_cond_signal(&vm->gc_barrier_owner_cond);
 	    }
-	}
-	native_mutex_unlock(&vm->gc_lock);
+	});
 
 	native_mutex_lock(&vm->global_interpreter_lock);
 	thread_debug("rb_thread_global_lock_acquire: <-- done (lock)\n");
 
-	native_mutex_lock(&vm->gc_lock);
-	{
+	LOCK_RANGE(&vm->gc_lock, {
 	    DEC_WAIT_THREAD(vm);
 
 	    if (vm->interrupt_gc_flag) {
 		rb_bug("bug?");
 	    }
-	}
-	native_mutex_unlock(&vm->gc_lock);
+	});
 
       gotlock:
 	vm->lock_owner_thread = th;
@@ -224,13 +227,6 @@
 }
 
 static int
-rb_thread_global_lock_acquire_p(yarv_thread_t *th)
-{
-    yarv_vm_t *vm = th->vm;
-    return vm->lock_owner_thread == th;
-}
-
-static int
 rb_thread_blocking_start(yarv_thread_t *th, yarv_interrupt_function_t *func)
 {
     yarv_vm_t *vm = GET_VM();
@@ -244,15 +240,13 @@
     yarv_set_interrupt_function(th, func);
     yarv_save_machine_context(th);
 
-    native_mutex_lock(&vm->gc_lock);
-    {
+    LOCK_RANGE(&vm->gc_lock, {
 	INC_WAIT_THREAD(vm);
 	
 	if (vm->interrupt_gc_flag) {
 	    native_cond_signal(&vm->gc_barrier_owner_cond);
 	}
-    }
-    native_mutex_unlock(&vm->gc_lock);
+    });
 
     rb_thread_global_lock_release(th);
     return 1;
@@ -264,12 +258,10 @@
     yarv_vm_t *vm = GET_VM();
     yarv_clear_interrupt_function(th);
 
-    native_mutex_lock(&vm->gc_lock);
-    {
+    LOCK_RANGE(&vm->gc_lock, {
 	DEC_WAIT_THREAD(vm);
-    }
-    native_mutex_unlock(&vm->gc_lock);
-    
+    });
+
     rb_thread_global_lock_acquire(th);
 }
 
@@ -282,6 +274,21 @@
     thread_debug("rb_thread_gc_barrier_stop: start\n");
     yarv_save_machine_context(th);
 
+    while (vm->interrupt_gc_flag) {
+	LOCK_RANGE(&vm->gc_lock, {
+	    INC_WAIT_THREAD(vm);
+	    while (vm->interrupt_gc_flag) {
+		thread_debug("rb_thread_gc_barrier_stop: waiting -> %d\n",
+			     vm->num_wait_threads);
+		native_cond_signal(&vm->gc_barrier_owner_cond);
+		native_cond_wait(&vm->gc_barrier_waits_cond,
+				 &vm->gc_lock);
+	    }
+	    DEC_WAIT_THREAD(vm);
+	});
+    }
+    
+#if 0
     GL_LOCK_RANGE(th, {
 	if (vm->interrupt_gc_flag) {
 	    native_mutex_lock(&vm->gc_lock);
@@ -299,7 +306,7 @@
 	    native_mutex_unlock(&vm->gc_lock);
 	}
     });
-
+#endif
     thread_debug("rb_thread_gc_barrier_stop: end\n");
 }
 
@@ -313,8 +320,7 @@
 	/* skip */
     }
     else {
-	native_mutex_lock(&vm->gc_lock);
-	{
+	LOCK_RANGE(&vm->gc_lock, {
 	    if (vm->interrupt_gc_flag) {
 		rb_bug("other thread runnning GC");
 	    }
@@ -329,8 +335,7 @@
 		thread_debug("rb_thread_gc_barrier_start: block end - ltnum: %d, wtnum: %d\n",
 			     vm->living_threads->num_entries, vm->num_wait_threads);
 	    }
-	}
-	native_mutex_unlock(&vm->gc_lock);
+	});
     }
     yarv_save_machine_context(th);
     thread_debug("rb_thread_gc_barrier_start: end\n");
@@ -342,34 +347,35 @@
     yarv_vm_t *vm = GET_VM();
     thread_debug("rb_thread_gc_barrier_end: start\n");
 
-    vm->interrupt_gc_flag = 0;
-    native_cond_broadcast(&vm->gc_barrier_waits_cond);
-    
+    LOCK_RANGE(&vm->gc_lock, {
+	vm->interrupt_gc_flag = 0;
+	native_cond_broadcast(&vm->gc_barrier_waits_cond);
+    });
+
     thread_debug("rb_thread_gc_barrier_end: end\n");
 }
 
 static void
 yarv_set_interrupt_function(yarv_thread_t *th, yarv_interrupt_function_t *func)
 {
-    native_mutex_lock(&th->interrupt_lock);
-    th->interrupt_function = func;
-    native_mutex_unlock(&th->interrupt_lock);
+    LOCK_RANGE(&th->interrupt_lock, {
+	th->interrupt_function = func;
+    });
 }
 
 static void
 yarv_clear_interrupt_function(yarv_thread_t *th)
 {
-    native_mutex_lock(&th->interrupt_lock);
-    th->interrupt_function = 0;
-    yarv_remove_repeat_interrupt_func(th);
-    native_mutex_unlock(&th->interrupt_lock);
+    LOCK_RANGE(&th->interrupt_lock, {
+	th->interrupt_function = 0;
+	yarv_remove_repeat_interrupt_func(th);
+    });
 }
 
 static void
 rb_thread_interrupt(yarv_thread_t *th)
 {
-    native_mutex_lock(&th->interrupt_lock);
-    {
+    LOCK_RANGE(&th->interrupt_lock, {
 	th->interrupt_flag = 1;
 	if (th->interrupt_function) {
 	    (th->interrupt_function)(th);
@@ -377,8 +383,7 @@
 	else {
 	    /* none */
 	}
-    }
-    native_mutex_unlock(&th->interrupt_lock);
+    });
 }
 
 static int
@@ -441,6 +446,7 @@
     if (th->vm->interrupt_gc_flag) {
 	native_cond_signal(&th->vm->gc_barrier_owner_cond);
     }
+
     rb_thread_global_lock_release(th);
     thread_debug("thread terminated: %p\n", th);
 }
@@ -1577,8 +1583,10 @@
        is true, any other threads doesn't interrupt */
 
     int num = 1;
-    if (GET_VM()->living_threads) {
-	num = GET_VM()->living_threads->num_entries;
+    yarv_vm_t *vm = GET_VM();
+    
+    if (vm->living_threads) {
+	num = vm->living_threads->num_entries;
 	thread_debug("rb_thread_alone: %d\n", num);
     }
     return num == 1;


--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]