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

yarv-diff:394

From: ko1 atdot.net
Date: 8 Sep 2006 18:11:16 +0900
Subject: [yarv-diff:394] r561 - in branches/parallel: . benchmark

Author: ko1
Date: 2006-09-08 18:11:13 +0900 (Fri, 08 Sep 2006)
New Revision: 561

Added:
   branches/parallel/benchmark/bm_para_attr.rb
   branches/parallel/benchmark/bm_para_attr_conflict.rb
   branches/parallel/benchmark/bm_vm1_attr.rb
Modified:
   branches/parallel/ChangeLog
   branches/parallel/benchmark/bm_para_hetero.rb
   branches/parallel/common.mk
   branches/parallel/gc.c
   branches/parallel/thread.c
   branches/parallel/thread_pthread.h
Log:
	* benchmark/bm_para_attr.rb : added

	* benchmark/bm_para_attr_conflict.rb : ditto

	* benchmark/bm_para_hetero.rb : remove debug output

	* benchmark/bm_vm1_attr.rb : added

	* common.mk : add dependency about thread

	* gc.c : remove unused check

	* thread.c : add profile_conflict_block, profile_conflict_fglock
	and print these value at the end of execution if RUBY_SHOW_PROFILE
	environment variable is defined

	* thread.c : add threads number check

	* thread_pthread.h : fix to pass execution to another thread
	if fg spin was locked



Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/ChangeLog	2006-09-08 09:11:13 UTC (rev 561)
@@ -4,6 +4,30 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-09-08(Fri) 18:03:53 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* benchmark/bm_para_attr.rb : added
+
+	* benchmark/bm_para_attr_conflict.rb : ditto
+
+	* benchmark/bm_para_hetero.rb : remove debug output
+
+	* benchmark/bm_vm1_attr.rb : added
+
+	* common.mk : add dependency about thread
+
+	* gc.c : remove unused check
+
+	* thread.c : add profile_conflict_block, profile_conflict_fglock
+	and print these value at the end of execution if RUBY_SHOW_PROFILE
+	environment variable is defined
+
+	* thread.c : add threads number check
+
+	* thread_pthread.h : fix to pass execution to another thread
+	if fg spin was ocked
+
+
 2006-09-08(Fri) 14:39:16 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* gc.c : add GC profiler

Added: branches/parallel/benchmark/bm_para_attr.rb
===================================================================
--- branches/parallel/benchmark/bm_para_attr.rb	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/benchmark/bm_para_attr.rb	2006-09-08 09:11:13 UTC (rev 561)
@@ -0,0 +1,30 @@
+def work n=8
+  (1..n).map{|i|
+    Thread.new(i){|ti|
+      yield ti
+    }
+  }.each{|t|
+    t.join
+  }
+end
+
+class C
+  def initialize
+    @a = :foo
+  end
+  
+  def attr
+    i = 0
+    while i<3000000 # while loop 1
+      i+= 1
+      s = @a
+    end
+  end
+end
+
+obj = C.new
+work{
+  #obj.attr
+  C.new.attr
+}
+


Property changes on: branches/parallel/benchmark/bm_para_attr.rb
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/parallel/benchmark/bm_para_attr_conflict.rb
===================================================================
--- branches/parallel/benchmark/bm_para_attr_conflict.rb	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/benchmark/bm_para_attr_conflict.rb	2006-09-08 09:11:13 UTC (rev 561)
@@ -0,0 +1,29 @@
+def work n=8
+  (1..n).map{|i|
+    Thread.new(i){|ti|
+      yield ti
+    }
+  }.each{|t|
+    t.join
+  }
+end
+
+class C
+  def initialize
+    @a = :foo
+  end
+  
+  def attr
+    i = 0
+    while i<3000000 # while loop 1
+      i+= 1
+      s = @a
+    end
+  end
+end
+
+obj = C.new
+work{
+  obj.attr
+}
+


Property changes on: branches/parallel/benchmark/bm_para_attr_conflict.rb
___________________________________________________________________
Name: svn:executable
   + *

Modified: branches/parallel/benchmark/bm_para_hetero.rb
===================================================================
--- branches/parallel/benchmark/bm_para_hetero.rb	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/benchmark/bm_para_hetero.rb	2006-09-08 09:11:13 UTC (rev 561)
@@ -4,7 +4,6 @@
       yield ti
     }
   }.each{|t|
-    STDERR.puts t.to_s
     t.join
   }
 end

Added: branches/parallel/benchmark/bm_vm1_attr.rb
===================================================================
--- branches/parallel/benchmark/bm_vm1_attr.rb	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/benchmark/bm_vm1_attr.rb	2006-09-08 09:11:13 UTC (rev 561)
@@ -0,0 +1,7 @@
+i = 0
+@a = :foo
+while i<30000000 # while loop 1
+  i+= 1
+  s = @a
+end
+


Property changes on: branches/parallel/benchmark/bm_vm1_attr.rb
___________________________________________________________________
Name: svn:executable
   + *

Modified: branches/parallel/common.mk
===================================================================
--- branches/parallel/common.mk	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/common.mk	2006-09-08 09:11:13 UTC (rev 561)
@@ -287,7 +287,8 @@
 gc.$(OBJEXT): {$(VPATH)}gc.c {$(VPATH)}ruby.h config.h \
   {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
   {$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}node.h \
-  {$(VPATH)}re.h {$(VPATH)}regex.h {$(VPATH)}yarvcore.h
+  {$(VPATH)}re.h {$(VPATH)}regex.h {$(VPATH)}yarvcore.h \
+  {$(VPATH)}thread_pthread.h {$(VPATH)}thread_win32.h
 hash.$(OBJEXT): {$(VPATH)}hash.c {$(VPATH)}ruby.h config.h \
   {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
   {$(VPATH)}st.h {$(VPATH)}util.h {$(VPATH)}rubysig.h
@@ -347,7 +348,8 @@
   {$(VPATH)}oniguruma.h config.h
 sprintf.$(OBJEXT): {$(VPATH)}sprintf.c {$(VPATH)}ruby.h config.h \
   {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h {$(VPATH)}vsnprintf.c
-st.$(OBJEXT): {$(VPATH)}st.c config.h {$(VPATH)}st.h
+st.$(OBJEXT): {$(VPATH)}st.c config.h {$(VPATH)}st.h \
+  {$(VPATH)}thread_pthread.h {$(VPATH)}thread_win32.h
 string.$(OBJEXT): {$(VPATH)}string.c {$(VPATH)}ruby.h config.h \
   {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
   {$(VPATH)}re.h {$(VPATH)}regex.h

Modified: branches/parallel/gc.c
===================================================================
--- branches/parallel/gc.c	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/gc.c	2006-09-08 09:11:13 UTC (rev 561)
@@ -227,12 +227,6 @@
 Init_gc_lock(void)
 {
     native_fglock_init(&g_mem_lock);
-    if (native_fg_lock(&g_mem_lock) != 0) {
-	rb_bug("Init_gc_lock: native_fg_lock");
-    }
-    if (native_fg_unlock(&g_mem_lock) != 0) {
-	rb_bug("Init_gc_lock: native_fg_unlock");
-    }
 }
 
 void *

Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/thread.c	2006-09-08 09:11:13 UTC (rev 561)
@@ -61,6 +61,8 @@
 
 static int system_working = 1;
 static int profile_conflict = 0;
+static int profile_conflict_block = 0;
+int profile_conflict_fglock = 0;
 
 inline static void
 st_delete_wrap(st_table * table, VALUE key)
@@ -147,7 +149,12 @@
 static void __attribute__((destructor))
      pr_show(void)
 {
-    // fprintf(stderr, "profile_conflict: %d\n", profile_conflict);
+    if (getenv("RUBY_SHOW_PROFILE")) {
+	fprintf(stderr, "profile_conflict: %d, %d, %d\n",
+		profile_conflict,
+		profile_conflict_block,
+		profile_conflict_fglock);
+    }
 }
 
 static int g_spinlock_count;
@@ -184,6 +191,7 @@
 	    native_thread_yield();
 	}
 
+	profile_conflict_block++;
 	yarv_save_machine_context(th);
 
 	LOCK_RANGE(&vm->gc_lock, {
@@ -274,6 +282,7 @@
     thread_debug("rb_thread_gc_barrier_stop: start\n");
     yarv_save_machine_context(th);
 
+#if 1
     while (vm->interrupt_gc_flag) {
 	LOCK_RANGE(&vm->gc_lock, {
 	    INC_WAIT_THREAD(vm);
@@ -287,24 +296,9 @@
 	    DEC_WAIT_THREAD(vm);
 	});
     }
-    
-#if 0
+#else
     GL_LOCK_RANGE(th, {
-	if (vm->interrupt_gc_flag) {
-	    native_mutex_lock(&vm->gc_lock);
-	    {
-		INC_WAIT_THREAD(vm);
-		{
-		    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);
-	    }
-	    native_mutex_unlock(&vm->gc_lock);
-	}
+	/* block only */
     });
 #endif
     thread_debug("rb_thread_gc_barrier_stop: end\n");
@@ -347,6 +341,11 @@
     yarv_vm_t *vm = GET_VM();
     thread_debug("rb_thread_gc_barrier_end: start\n");
 
+    if (vm->living_threads->num_entries != vm->num_wait_threads + 1) {
+	rb_bug("rb_thread_gc_barrier_end: another threads are running (%d)",
+	       vm->living_threads->num_entries - vm->num_wait_threads - 1);
+    }
+
     LOCK_RANGE(&vm->gc_lock, {
 	vm->interrupt_gc_flag = 0;
 	native_cond_broadcast(&vm->gc_barrier_waits_cond);
@@ -1866,7 +1865,7 @@
     yarv_thread_t *th;
     int i;
     GetThreadPtr(thval, th);
-//   fprintf(stderr, ">> %p: %d\n", th, th->profile_conflict);
+    //fprintf(stderr, "%s>> %p: %d\n", is_clear ? "clr" : "set", th, th->profile_conflict);
 
 // #define thread_debug(x, y) fprintf(stderr, x, y)
     if (th->profile_conflict > 1000 && !is_clear) {
@@ -1930,7 +1929,8 @@
 	    cnt = 100;
 	}
 	else {
-	    if (profile_conflict - prev_confilict > 10000) {
+	    // fprintf(stderr, ">> %ld\n", profile_conflict - prev_confilict);
+	    if (profile_conflict - prev_confilict > 5000) {
 		st_foreach(vm->living_threads, set_cpu_cnt_i, (st_data_t)0);
 	    }
 	}
@@ -2417,7 +2417,7 @@
 	g_spinlock_count = atoi(env);
     }
     else {
-	g_spinlock_count = 50;
+	g_spinlock_count = 100;
     }
     
     rb_disable_interrupt(); /* only timer thread recieve signal */

Modified: branches/parallel/thread_pthread.h
===================================================================
--- branches/parallel/thread_pthread.h	2006-09-08 05:47:04 UTC (rev 560)
+++ branches/parallel/thread_pthread.h	2006-09-08 09:11:13 UTC (rev 561)
@@ -27,14 +27,44 @@
 
 #if HAVE_PTHREAD_SPINLOCK_T
 typedef pthread_spinlock_t yarv_thread_fglock_t;
+
+#if 1
+#include <errno.h>
+extern int profile_conflict_fglock;
+#define native_fg_lock(lock) do {\
+    int r = pthread_spin_trylock(lock); \
+    while (r == EBUSY) { \
+	profile_conflict_fglock++; \
+	sched_yield(); \
+	r = pthread_spin_trylock(lock); \
+    } \
+    if (r != 0) { rb_bug("native_fg_lock return non-zero"); } \
+} while (0)
+#else
 #define native_fg_lock pthread_spin_lock
+#endif
+
 #define native_fg_unlock pthread_spin_unlock
 #define native_fg_trylock pthread_spin_trylock
 #define native_fg_init__ pthread_spin_init
 #define native_fg_destroy__ pthread_spin_destroy
 #else
 typedef pthread_mutex_t yarv_thread_fglock_t;
+
+#if 1
+#include <errno.h>
+#define native_fg_lock(lock) do {\
+    int r = pthread_mutex_trylock(lock); \
+    while (r == EBUSY) { \
+	sched_yield(); \
+	r = pthread_mutex_trylock(lock); \
+    } \
+    if (r != 0) { rb_bug("native_fg_lock"); } \
+} while (0)
+#else
 #define native_fg_lock pthread_mutex_lock
+#endif
+
 #define native_fg_unlock pthread_mutex_unlock
 #define native_fg_trylock pthread_mutex_trylock
 #define native_fg_init__ pthread_mutex_init


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

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