[m-rev.] For review: Change the Boehm collector to report on collection time.

Quan Phan quan.phan at cs.kuleuven.be
Fri Mar 7 01:44:55 AEDT 2008


Hi,

This is mainly for being reviewed by Zoltan, but anyone can help.

Regards,
Quan.


-------------- next part --------------
Estimated hours taken: 1h.
Branch: main.

Normally by setting the GC_PRINT_STATS environment variable to a
value different from 0, the Boehm collector will print out some statistics
of its behaviour each time it is invoked. I modified it a bit so that it
reports on the total time spent on garbage collection.  

boehm_gc/alloc.c:
	Accumulate the collection time into a global variable. I took the
	calls to GET_TIME out of the if statements so that we can always
	report on collection time with report_stats predicate. I tested it
	with some programs and it seemed not affect the overall performance.

boehm_gc/include/gc.h:
	Declare the global accumulator for collection time.

library/benchmarking.m:
	Change report_stats to report on GC time.

runtime/mercury_region.h:
	An unrelated, small change: change the *default* region page size to
	2K words so that a region page can store any Mercury terms regarding
	the limitation on the number of arguments a Mercury functor can have.	
-------------- next part --------------
Index: boehm_gc/alloc.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/boehm_gc/alloc.c,v
retrieving revision 1.17
diff -u -r1.17 alloc.c
--- boehm_gc/alloc.c	6 Feb 2008 01:45:48 -0000	1.17
+++ boehm_gc/alloc.c	6 Mar 2008 13:58:18 -0000
@@ -58,6 +58,7 @@
 word GC_non_gc_bytes = 0;  /* Number of bytes not intended to be collected */
 
 word GC_gc_no = 0;
+word GC_total_gc_time = 0;
 
 #ifndef SMALL_CONFIG
   int GC_incremental = 0;  /* By default, stop the world.	*/
@@ -305,6 +306,7 @@
 GC_bool GC_try_to_collect_inner(GC_stop_func stop_func)
 {
     CLOCK_TYPE start_time, current_time;
+    word gc_time;
     if (GC_dont_gc) return FALSE;
     if (GC_incremental && GC_collection_in_progress()) {
       if (GC_print_stats) {
@@ -318,8 +320,8 @@
     	}
     }
     if (stop_func == GC_never_stop_func) GC_notify_full_gc();
+    GET_TIME(start_time);
     if (GC_print_stats) {
-        GET_TIME(start_time);
 	GC_log_printf(
 	   "Initiating full world-stop collection %lu after %ld allocd bytes\n",
 	   (unsigned long)GC_gc_no+1, (long)GC_bytes_allocd);
@@ -356,10 +358,14 @@
       return(FALSE);
     }
     GC_finish_collection();
+
+    GET_TIME(current_time);
+    gc_time = MS_TIME_DIFF(current_time,start_time);
+    GC_total_gc_time += gc_time;
     if (GC_print_stats) {
-        GET_TIME(current_time);
-        GC_log_printf("Complete collection took %lu msecs\n",
-                  MS_TIME_DIFF(current_time,start_time));
+        GC_log_printf("Complete collection took %lu msecs\n", gc_time);
+        GC_log_printf("Total collection time so far is %lu msecs\n",
+	    GC_total_gc_time);
     }
     return(TRUE);
 }
Index: boehm_gc/include/gc.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/boehm_gc/include/gc.h,v
retrieving revision 1.18
diff -u -r1.18 gc.h
--- boehm_gc/include/gc.h	6 Feb 2008 01:45:48 -0000	1.18
+++ boehm_gc/include/gc.h	6 Mar 2008 13:58:18 -0000
@@ -65,6 +65,10 @@
 GC_API GC_word GC_gc_no;/* Counter incremented per collection.  	*/
 			/* Includes empty GCs at startup.		*/
 
+GC_API GC_word GC_total_gc_time;
+			/* For accumulating the time spent on		*/
+			/* collections.  				*/
+
 GC_API int GC_parallel;	/* GC is parallelized for performance on	*/
 			/* multiprocessors.  Currently set only		*/
 			/* implicitly if collector is built with	*/
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.78
diff -u -r1.78 benchmarking.m
--- library/benchmarking.m	27 Sep 2007 07:28:57 -0000	1.78
+++ library/benchmarking.m	6 Mar 2008 13:58:26 -0000
@@ -326,9 +326,10 @@
     }
   #endif /* MR_MPS_GC */
   #ifdef MR_BOEHM_GC
-    fprintf(stderr, ""\\n#GCs: %lu, ""
+    fprintf(stderr, ""\\n#GCs: %lu, GC time: %lu, ""
         ""Heap used since last GC: %.3fk, Total used: %.3fk"",
         (unsigned long) GC_gc_no,
+        (unsigned long) GC_total_gc_time,
         GC_get_bytes_since_gc() / 1024.0,
         GC_get_heap_size() / 1024.0
     );
Index: runtime/mercury_region.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_region.h,v
retrieving revision 1.11
diff -u -r1.11 mercury_region.h
--- runtime/mercury_region.h	23 Jan 2008 11:44:48 -0000	1.11
+++ runtime/mercury_region.h	6 Mar 2008 13:58:27 -0000
@@ -37,7 +37,7 @@
 
 /* XXX This should be made configurable when compiling a program. */
 #define     MR_REGION_NUM_PAGES_TO_REQUEST                  100
-#define     MR_REGION_PAGE_SPACE_SIZE                       255
+#define     MR_REGION_PAGE_SPACE_SIZE                       2048
 
 /*
 ** NOTE: The following constants *must match* the values of the Mercury


More information about the reviews mailing list