[前][次][番号順一覧][スレッド一覧]

ruby-changes:30989

From: ko1 <ko1@a...>
Date: Fri, 27 Sep 2013 17:12:40 +0900 (JST)
Subject: [ruby-changes:30989] ko1:r43068 (trunk): * gc.c: add some fine-grained profiling codes to tuning marking phase.

ko1	2013-09-27 17:12:31 +0900 (Fri, 27 Sep 2013)

  New Revision: 43068

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43068

  Log:
    * gc.c: add some fine-grained profiling codes to tuning marking phase.
      If you enable RGENGC_PRINT_TICK to 1, then profiling results by RDTSC
      (on x86/amd64 environment) are printed at last.
      Thanks Yoshii-san.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43067)
+++ ChangeLog	(revision 43068)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 27 17:07:55 2013  Koichi Sasada  <ko1@a...>
+
+	* gc.c: add some fine-grained profiling codes to tuning marking phase.
+	  If you enable RGENGC_PRINT_TICK to 1, then profiling results by RDTSC
+	  (on x86/amd64 environment) are printed at last.
+	  Thanks Yoshii-san.
+
 Fri Sep 27 16:32:27 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c: simplify threshold of GC caused by malloc_increase.
Index: gc.c
===================================================================
--- gc.c	(revision 43067)
+++ gc.c	(revision 43068)
@@ -2397,7 +2397,6 @@ gc_before_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L2397
 	rb_sweep_method_entry(GET_VM());
     }
 
-
     gc_prof_set_malloc_info(objspace);
 
     /* reset malloc info */
@@ -3432,12 +3431,104 @@ gc_mark_stacked_objects(rb_objspace_t *o https://github.com/ruby/ruby/blob/trunk/gc.c#L3431
     shrink_stack_chunk_cache(mstack);
 }
 
+#define RGENGC_PRINT_TICK 0
+/* the following code is only for internal tuning. */
+
+/* Source code to use RDTSC is quoted and modified from
+ * http://www.mcs.anl.gov/~kazutomo/rdtsc.html
+ * written by Kazutomo Yoshii <kazutomo@m...>
+ */
+
+#if RGENGC_PRINT_TICK
+#if defined(__GNUC__) && defined(__i386__)
+typedef unsigned long long tick_t;
+
+static inline tick_t
+tick(void)
+{
+    unsigned long long int x;
+    __asm__ __volatile__ ("rdtsc" : "=A" (x));
+    return x;
+}
+
+#elif defined(__GCC__) && defined(__x86_64__)
+typedef unsigned long long tick_t;
+
+static __inline__ tick_t
+tick(void)
+{
+    unsigned long hi, lo;
+    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
+    return ((unsigned long long)lo)|( ((unsigned long long)hi)<<32);
+}
+
+#elif defined(_WIN32) && defined(_MSC_VER)
+#include <intrin.h>
+typedef unsigned __int64 tick_t;
+
+static inline tick_t
+tick(void)
+{
+    return __rdtsc();
+}
+
+#else /* use clock */
+typedef clock_t tick_t;
+static inline tick_t
+tick(void)
+{
+    return clock();
+}
+#endif
+
+#define MAX_TICKS 0x100
+static tick_t mark_ticks[MAX_TICKS];
+static int mark_ticks_start_line;
+
+static void
+show_mark_ticks(void)
+{
+    int i;
+    fprintf(stderr, "mark ticks result:\n");
+    for (i=0; i<MAX_TICKS; i++) {
+      if (mark_ticks[i] > 0) {
+	  fprintf(stderr, "@%4d\t%8lu\n", i+mark_ticks_start_line, (unsigned long)mark_ticks[i]);
+      }
+    }
+}
+
+#endif /* RGENGC_PRINT_TICK */
+
 static void
 gc_marks_body(rb_objspace_t *objspace, int minor_gc)
 {
     struct gc_list *list;
     rb_thread_t *th = GET_THREAD();
 
+#if RGENGC_PRINT_TICK
+    tick_t start_tick = tick();
+    if (mark_ticks_start_line == 0) {
+	mark_ticks_start_line = __LINE__;
+	atexit(show_mark_ticks);
+    }
+#endif
+
+#define MARK_CHECKPOINT_PRINT_TICK do { \
+    tick_t t = tick(); \
+    mark_ticks[__LINE__ - mark_ticks_start_line] = t - start_tick; \
+    start_tick = tick(); \
+} while (0)
+
+#if RGENGC_CHECK_MODE > 1
+#define MARK_CHECKPOINT do { \
+    objspace->rgengc.parent_object = INT2FIX(__LINE__); \
+} while (0)
+#elif RGENGC_PRINT_TICK
+#define MARK_CHECKPOINT MARK_CHECKPOINT_PRINT_TICK
+#else
+#define MARK_CHECKPOINT /* do nothing */
+#endif
+
     /* start marking */
     rgengc_report(1, objspace, "gc_marks_body: start (%s)\n", minor_gc ? "minor" : "major");
 
@@ -3456,12 +3547,6 @@ gc_marks_body(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L3547
     }
 #endif
 
-#if RGENGC_CHECK_MODE > 1
-#define MARK_CHECKPOINT do {objspace->rgengc.parent_object = INT2FIX(__LINE__);} while (0)
-#else
-#define MARK_CHECKPOINT
-#endif
-
     MARK_CHECKPOINT;
     SET_STACK_END;
     th->vm->self ? rb_gc_mark(th->vm->self) : rb_vm_mark(th->vm);
@@ -3504,8 +3589,10 @@ gc_marks_body(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L3589
     rb_gc_mark_unlinked_live_method_entries(th->vm);
 
     /* marking-loop */
+    MARK_CHECKPOINT;
     gc_mark_stacked_objects(objspace);
 
+    MARK_CHECKPOINT;
 #undef MARK_CHECKPOINT
 
     /* cleanup */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]