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

Peter Wang novalazy at gmail.com
Tue Mar 18 10:47:14 AEDT 2008


On 2008-03-17, Zoltan Somogyi <zs at csse.unimelb.edu.au> wrote:
> On 12-Mar-2008, Quan Phan <Quan.Phan at cs.kuleuven.be> wrote:
> > There is no objection (at least from me). Please go ahead with the necessary
> > changes.
> 
> The new diff follows, for review by anyone. It works on my test case,
> but I am just bootchecking it now. (Peter will need to look at the rename
> of --munmap.)

That's ok.

> 
> Add a new MERCURY_OPTIONS option, --boehm-gc-calc-time. If given, we record
> the time taken by garbage collections so far, and make report_stats in
> library/benchmarking.m report this information.
> 
> boehm_gc/alloc.c:
> 	Gather this information.
> 
> boehm_gc/include/gc.h:
> 	Declare the variable that contains this information as well the
> 	variable that controls whether this information is gathered at all.
> 
> doc/user_guide.texi:
> 	Document the new option.
> 
> 	Document the renaming of another option that also applies only when
> 	using the Boehm collector.

Might as well mention --munmap explicitly.

> 
> library/benchmarking.m:
> 	Print the time taken by gc so far if we gather that information.
> 
> runtime/mercury_wrapper.c:
> 	Enable the facility in boehm_gc/alloc.c if --boehm-gc-calc-time is
> 	given. Rename the other Boehm-specific option.

> Index: boehm_gc/alloc.c
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/boehm_gc/alloc.c,v
> retrieving revision 1.17
> diff -u -b -r1.17 alloc.c
> --- boehm_gc/alloc.c	6 Feb 2008 01:45:48 -0000	1.17
> +++ boehm_gc/alloc.c	17 Mar 2008 06:57:41 -0000
> @@ -59,6 +59,12 @@
>  
>  word GC_gc_no = 0;
>  
> +GC_bool		GC_mercury_calc_gc_time = 0;
> +			   /* Accumulate total gc time  in      */
> +			   /* GC_total_gc_time if set to true.  */
> +unsigned long 	GC_total_gc_time = 0;
> +			   /* Measured in milliseconds.         */
> +
>  #ifndef SMALL_CONFIG
>    int GC_incremental = 0;  /* By default, stop the world.	*/
>  #endif
> @@ -318,8 +324,9 @@
>      	}
>      }
>      if (stop_func == GC_never_stop_func) GC_notify_full_gc();
> -    if (GC_print_stats) {
> +    if (GC_print_stats || GC_mercury_calc_gc_time) {
>          GET_TIME(start_time);
> +	if (GC_print_stats)
>  	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 +363,17 @@
>        return(FALSE);
>      }
>      GC_finish_collection();
> -    if (GC_print_stats) {
> +    if (GC_print_stats || GC_mercury_calc_gc_time) {
> +	unsigned long cur_gc_time;
>          GET_TIME(current_time);
> +        cur_gc_time = MS_TIME_DIFF(current_time,start_time);
> +        if (GC_print_stats) {
>          GC_log_printf("Complete collection took %lu msecs\n",
> -                  MS_TIME_DIFF(current_time,start_time));
> +                cur_gc_time);
> +	}
> +    	if (GC_mercury_calc_gc_time) {
> +            GC_total_gc_time += cur_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 -b -r1.18 gc.h
> --- boehm_gc/include/gc.h	6 Feb 2008 01:45:48 -0000	1.18
> +++ boehm_gc/include/gc.h	17 Mar 2008 06:47:28 -0000
> @@ -233,6 +233,16 @@
>  GC_API int GC_mercury_use_munmap;
>  				/* Whether to use munmap(). Only	 */
>  				/* effective if USE_MUNMAP is defined.   */
> +GC_API int GC_mercury_calc_gc_time;
> +				/* Whether to calculate the time taken   */
> +				/* by garbage collections. If yes, the   */
> +				/* times are accumulated in the variable */
> +				/* GC_total_gc_time.			 */
> +GC_API unsigned long GC_total_gc_time;
> +				/* If GC_mercury_calc_gc_time is true,   */
> +				/* this holds the total time used so far */
> +				/* by garbage collections. Measured in   */
> +				/* milliseconds.			 */

Mention that this is user time.

> Index: runtime/mercury_wrapper.c
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
> retrieving revision 1.187
> diff -u -b -r1.187 mercury_wrapper.c
> --- runtime/mercury_wrapper.c	6 Feb 2008 01:45:50 -0000	1.187
> +++ runtime/mercury_wrapper.c	17 Mar 2008 06:32:54 -0000
> @@ -1109,7 +1109,8 @@
>      MR_COVERAGE_TEST_IF_EXEC_OPT,
>      MR_TRACE_COUNT_FILE,
>      MR_MEM_USAGE_REPORT,
> -    MR_MUNMAP
> +    MR_BOEHM_GC_MUNMAP,
> +    MR_BOEHM_GC_CALC_TIME
>  };
>  
>  struct MR_option MR_long_opts[] = {
> @@ -1208,7 +1209,8 @@
>      { "tc-summary-max",                 1, 0, MR_TRACE_COUNT_SUMMARY_MAX_OPT },
>      { "trace-count-summary-max",        1, 0, MR_TRACE_COUNT_SUMMARY_MAX_OPT },
>      { "mem-usage-report",               1, 0, MR_MEM_USAGE_REPORT },
> -    { "munmap",                         0, 0, MR_MUNMAP },
> +    { "boehm-gc-munmap",                0, 0, MR_BOEHM_GC_MUNMAP },
> +    { "boehm-gc-calc-time",             0, 0, MR_BOEHM_GC_CALC_TIME },
>  
>      /* This needs to be kept at the end. */
>      { NULL,                             0, 0, 0 }
> @@ -1733,12 +1735,18 @@
>                  MR_mem_usage_report_prefix = MR_copy_string(MR_optarg);
>                  break;
>  
> -            case MR_MUNMAP:
> +            case MR_BOEHM_GC_MUNMAP:
>  #ifdef MR_BOEHM_GC
>                  GC_mercury_use_munmap = MR_TRUE;
>  #endif
>                  break;
>  
> +            case MR_BOEHM_GC_CALC_TIME:
> +#ifdef MR_BOEHM_GC
> +                GC_mercury_calc_gc_time = MR_TRUE;
> +#endif
> +                break;
> +
>              case 'a':
>                  benchmark_all_solns = MR_TRUE;
>                  break;

Have you checked how much slowdown the calls to GET_TIME incur?

Peter

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list