[m-rev.] For post-commit review: Create threadscope grade component
Paul Bone
pbone at csse.unimelb.edu.au
Sun Jan 10 16:01:00 AEDT 2010
For post-commit review.
I've tested this change as described in the mailing list in a number of
different grades and by installing the compiler and testing mmake and mmc
--make against it.
Create a threadscope grade component.
Threadscope grades are enabled by using the grade component 'threadscope'.
They are supported only with low-lavel C parallel grades. Support for
threadscope in high level C grades is intended in the future but does not work
now.
runtime/mercury_conf_param.h:
Create the MR_THREADSCOPE macro that is defined if the grade is a
threadscope grade.
Define MR_PROFILE_FOR_PARALLEL_EXECUTION if MR_THREADSCOPE is defined.
Emit an error if MR_LL_PARALLEL_CONJ is defined before it is implied by
MR_THREADSAFE and ! MR_HIGHLEVEL_CODE
runtime/mercury_grade.h
Update the grade symbol for the threadscope grade component.
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h:
runtime/mercury_context.c:
runtime/mercury_context.h:
runtime/mercury_engine.c:
runtime/mercury_engine.h:
runtime/mercury_thread.c:
runtime/mercury_threadscope.c:
runtime/mercury_threadscope.h:
runtime/mercury_wrapper.c:
Now that MR_PROFILE_FOR_IMPLICIT_PARALLELISM is implied by MR_THREADSAFE we
don't need to test for MR_THREADSAFE when we test for
MR_PROFILE_FOR_IMPLICIT_PARALLELISM. The same is true for
MR_LL_PARALLEL_CONJ which is implied by MR_THREADSAFE &&
!MR_HIGHLEVEL_CODE.
Replace some occurances of MR_PROFILE_FOR_IMPLICIT_PARALLELISM with
MR_THREADSCOPE where the conditionally compiled code is used to support
threadscope profiling.
scripts/init_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/mgnuc.in:
compiler/handle_options.m:
compiler/options.m:
compiler/compile_target_code.m:
configure.in:
Add support for the new grade component.
Pass -DMR_THREADSCOPE to the C compiler when using a threadscope grade.
Add assertions to ensure that the 'threadscope' grade component is used
only with the 'par' grade component.
doc/user_guide.texi:
Added commented-out documentation for the threadscope greate component.
Adjusted documentation of the --profile-parallel-execution runtime option
to describe the correct prerequisite compile time options.
Added my name to the authors list.
runtime/mercury_context.c:
Corrected grammar and prose in comments in the MR_do_join_and_continue code.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.150
diff -u -p -b -r1.150 compile_target_code.m
--- compiler/compile_target_code.m 21 Oct 2009 05:38:38 -0000 1.150
+++ compiler/compile_target_code.m 9 Jan 2010 12:59:25 -0000
@@ -496,6 +496,14 @@ gather_c_compiler_flags(Globals, PIC, Al
Parallel = no,
CFLAGS_FOR_THREADS = ""
),
+ globals.lookup_bool_option(Globals, threadscope, Threadscope),
+ (
+ Threadscope = yes,
+ ThreadscopeOpt = "-DMR_THREADSCOPE "
+ ;
+ Threadscope = no,
+ ThreadscopeOpt = ""
+ ),
globals.get_gc_method(Globals, GC_Method),
BoehmGC_Opt = "-DMR_CONSERVATIVE_GC -DMR_BOEHM_GC ",
(
@@ -861,6 +869,7 @@ gather_c_compiler_flags(Globals, PIC, Al
RegOpt, GotoOpt, AsmOpt,
CFLAGS_FOR_REGS, " ", CFLAGS_FOR_GOTOS, " ",
CFLAGS_FOR_THREADS, " ", CFLAGS_FOR_PIC, " ",
+ ThreadscopeOpt,
GC_Opt,
ProfileCallsOpt, ProfileTimeOpt,
ProfileMemoryOpt, ProfileDeepOpt,
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.344
diff -u -p -b -r1.344 handle_options.m
--- compiler/handle_options.m 8 Jan 2010 16:41:01 -0000 1.344
+++ compiler/handle_options.m 9 Jan 2010 12:59:52 -0000
@@ -555,6 +555,18 @@ convert_options_to_globals(OptionTable0,
TagsMethod = TagsMethod0
),
+ globals.lookup_bool_option(!.Globals, parallel, Parallel),
+ globals.lookup_bool_option(!.Globals, threadscope, Threadscope),
+ (
+ Parallel = no,
+ Threadscope = yes
+ ->
+ add_error("'threadscope' grade component requires a parallel grade",
+ !Errors)
+ ;
+ true
+ ),
+
% Implicit parallelism requires feedback information, however this
% error should only be shown in a parallel grade, otherwise implicit
% parallelism should be disabled.
@@ -562,7 +574,6 @@ convert_options_to_globals(OptionTable0,
ImplicitParallelism),
(
ImplicitParallelism = yes,
- globals.lookup_bool_option(!.Globals, parallel, Parallel),
(
Parallel = yes,
globals.lookup_string_option(!.Globals, feedback_file,
@@ -2476,10 +2487,8 @@ grade_string_to_comp_strings(GradeString
%-----------------------------------------------------------------------------%
- % IMPORTANT: any changes here may require similar changes to
- % runtime/mercury_grade.h
- % scripts/parse_grade_options.sh-subr
- % scripts/canonical_grade.sh-subr
+ % IMPORTANT: any changes here may require similar changes to other files,
+ % see the list of files at the top of runtime/mercury_grade.h
%
% The grade_component type should have one constructor for each
% dimension of the grade. It is used when converting the components
@@ -2493,16 +2502,19 @@ grade_string_to_comp_strings(GradeString
% The value to which a grade option should be reset should be given
% in the grade_start_values table below.
%
- % The ordering of the components here is the same as the order
- % used in scripts/ml.in, and any change here will require a
- % corresponding change there. The only place where the ordering
- % actually matters is for constructing the pathname for the
- % grade of the library, etc for linking (and installation).
+ % The ordering of the components here is the same as the order used in
+ % scripts/canonical_grand.sh-subr, and any change here will require a
+ % corresponding change there. The only place where the ordering actually
+ % matters is for constructing the pathname for the grade of the library,
+ % etc for linking (and installation).
%
:- type grade_component
---> comp_gcc_ext % gcc extensions etc. -- see
% grade_component_table
; comp_par % parallelism / multithreading
+ ; comp_par_threadscope
+ % Whether to support theadscope profiling of
+ % parallel grades.
; comp_gc % the kind of GC to use
; comp_prof % what profiling options to use
; comp_term_size % whether or not to record term sizes
@@ -2754,6 +2766,10 @@ grade_component_table("erlang", comp_gcc
% Parallelism/multithreading components.
grade_component_table("par", comp_par, [parallel - bool(yes)], no, yes).
+ % Threadscope profiling in parallel grades.
+grade_component_table("threadscope", comp_par_threadscope,
+ [threadscope - bool(yes)], no, yes).
+
% GC components.
grade_component_table("gc", comp_gc, [gc - string("boehm")], no, yes).
grade_component_table("gcd", comp_gc, [gc - string("boehm_debug")], no, yes).
@@ -2886,6 +2902,7 @@ grade_start_values(highlevel_code - bool
grade_start_values(highlevel_data - bool(no)).
grade_start_values(gcc_nested_functions - bool(no)).
grade_start_values(parallel - bool(no)).
+grade_start_values(threadscope - bool(no)).
grade_start_values(gc - string("none")).
grade_start_values(profile_deep - bool(no)).
grade_start_values(profile_time - bool(no)).
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.662
diff -u -p -b -r1.662 options.m
--- compiler/options.m 30 Nov 2009 00:31:56 -0000 1.662
+++ compiler/options.m 9 Jan 2010 12:59:26 -0000
@@ -361,6 +361,7 @@
% (c) Miscellaneous
; gc
; parallel
+ ; threadscope
; use_trail
; trail_segments
; use_minimal_model_stack_copy
@@ -1245,6 +1246,7 @@ option_defaults_2(compilation_model_opti
% (c) Miscellaneous optional features
gc - string("boehm"),
parallel - bool(no),
+ threadscope - bool(no),
use_trail - bool(no),
trail_segments - bool(no),
maybe_thread_safe_opt - string("no"),
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.600
diff -u -p -b -r1.600 user_guide.texi
--- doc/user_guide.texi 8 Jan 2010 16:41:14 -0000 1.600
+++ doc/user_guide.texi 9 Jan 2010 12:59:53 -0000
@@ -73,6 +73,7 @@ into another language, under the above c
@author Tyson Dowd
@author Mark Brown
@author Ian MacLarty
+ at author Paul Bone
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1995--2010 The University of Melbourne.
@@ -7307,6 +7308,7 @@ The set of aspects and their alternative
@cindex .decldebug (grade modifier)
@c @cindex .ssdebug (grade modifier)
@cindex .par (grade modifier)
+ at c @cindex .threadscope (grade modifier)
@cindex prof (grade modifier)
@cindex memprof (grade modifier)
@cindex profdeep (grade modifier)
@@ -7319,6 +7321,7 @@ The set of aspects and their alternative
@cindex decldebug (grade modifier)
@c @cindex ssdebug (grade modifier)
@cindex par (grade modifier)
+ at c @cindex threadscope (grade modifier)
@table @asis
@item What target language to use, what data representation to use, and (for C) what combination of GNU C extensions to use:
@samp{none}, @samp{reg}, @samp{jump}, @samp{asm_jump},
@@ -7351,6 +7354,12 @@ small segments: @samp{stseg} (the defaul
@item Whether to use a thread-safe version of the runtime environment:
@samp{par} (the default is a non-thread-safe environment).
+ at c @item Whether to include support for profile the execution of parallel
+ at c programs:
+ at c @samp{threadscope} (the default is no support for profiling parallel
+ at c execution).
+ at c See also the @samp{--profile-parallel-execution} runtime option.
+
@end table
The default grade is system-dependent; it is chosen at installation time
@@ -9730,9 +9739,8 @@ grade.
@c @findex --profile-parallel-execution
@c Tells the runtime to collect and write out parallel execution profiling
@c information to a file named @file{parallel_execution_profile.txt}.
- at c This only has an effect if the executable was built in a parallel grade
- at c and the @samp{MR_PROFILE_PARALLEL_EXECUTION_SUPPORT} C macro was
- at c defined when the runtime system was compiled.
+ at c This only has an effect if the executable was built in a low level c,
+ at c parallel, threadscope grade.
@sp 1
@item --thread-pinning
Index: runtime/mercury_atomic_ops.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_atomic_ops.c,v
retrieving revision 1.8
diff -u -p -b -r1.8 mercury_atomic_ops.c
--- runtime/mercury_atomic_ops.c 15 Dec 2009 02:29:06 -0000 1.8
+++ runtime/mercury_atomic_ops.c 9 Jan 2010 12:59:26 -0000
@@ -81,7 +81,7 @@ MR_OUTLINE_DEFN(
/*---------------------------------------------------------------------------*/
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
/*
** Profiling of the parallel runtime.
@@ -501,5 +501,5 @@ MR_rdtsc(MR_uint_least64_t *tsc) {
#endif /* __GNUC__ && (__i386__ || __x86_64__) */
-#endif /* MR_THREAD_SAFE && MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
+#endif /* MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
Index: runtime/mercury_atomic_ops.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_atomic_ops.h,v
retrieving revision 1.9
diff -u -p -b -r1.9 mercury_atomic_ops.h
--- runtime/mercury_atomic_ops.h 15 Dec 2009 02:29:06 -0000 1.9
+++ runtime/mercury_atomic_ops.h 9 Jan 2010 12:59:26 -0000
@@ -481,7 +481,7 @@ typedef MR_Unsigned MR_Us_Cond;
/*---------------------------------------------------------------------------*/
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
/*
** Declarations for profiling the parallel runtime.
@@ -544,7 +544,7 @@ MR_profiling_stop_timer(MR_Timer *timer,
extern MR_uint_least64_t
MR_read_cpu_tsc(void);
-#endif /* MR_THREAD_SAFE && MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
+#endif /* MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
/*---------------------------------------------------------------------------*/
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.109
diff -u -p -b -r1.109 mercury_conf_param.h
--- runtime/mercury_conf_param.h 14 Jul 2009 04:57:07 -0000 1.109
+++ runtime/mercury_conf_param.h 9 Jan 2010 12:59:26 -0000
@@ -113,10 +113,15 @@
** MR_THREAD_SAFE
** Enable support for parallelism.
**
+** MR_THREADSCOPE
+** Enable support for parallelism profiling, aka 'threadscope'. This is a
+** grade component. This works only with the low level C parallel grades.
+**
** MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
-** Enable support for profiling parallel execution. This only has an
-** effect of MR_THREAD_SAFE is also defined. This must also be enabled
-** with the --profile-parallel-execution runtime option.
+** Enable support for profiling the parallel runtime system. This collects
+** counts and timings of certain runtime events. It is implied by
+** MR_THREADSCOPE and must be enabled at runtime with the
+** --profile-parallel-execution runtime option.
**
** MR_NO_BACKWARDS_COMPAT
** Disable backwards compatibility with C code using obsolete low-level
@@ -728,10 +733,28 @@
** Whether we are in a grade which supports the low-level parallel
** conjunction execution mechanism.
*/
+#ifdef MR_LL_PARALLEL_CONJ
+ #error "MR_LL_PARALLEL_CONJ may not be defined on the command line"
+#endif
#if !defined(MR_HIGHLEVEL_CODE) && defined(MR_THREAD_SAFE)
#define MR_LL_PARALLEL_CONJ
#endif
+/*
+** Check that MR_THREADSCOPE is used correctly.
+*/
+#if defined(MR_THREADSCOPE) && !defined(MR_THREAD_SAFE)
+ #error "The threadscope grade component may only be used with " \
+ "parallel grades"
+#endif
+
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+ #error "MR_PROFILE_PARALLEL_EXECUTION_SUPPORT may only be implied by MR_THREADSCOPE"
+#endif
+#ifdef MR_THREADSCOPE
+ #define MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#endif
+
/* XXX document MR_BYTECODE_CALLABLE */
/*
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.74
diff -u -p -b -r1.74 mercury_context.c
--- runtime/mercury_context.c 17 Dec 2009 01:29:18 -0000 1.74
+++ runtime/mercury_context.c 9 Jan 2010 12:59:26 -0000
@@ -27,7 +27,7 @@ ENDINIT
#include <unistd.h> /* for select() on OS X */
#endif
#endif
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
#include <math.h> /* for sqrt and pow */
#endif
@@ -45,7 +45,7 @@ ENDINIT
#include "mercury_threadscope.h" /* for data types and posting events */
#include "mercury_reg_workarounds.h" /* for `MR_fd*' stuff */
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
#define MR_PROFILE_PARALLEL_EXECUTION_FILENAME "parallel_execution_profile.txt"
#endif
@@ -82,9 +82,10 @@ MR_PendingContext *MR_pending_cont
MercuryLock MR_pending_contexts_lock;
#endif
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
MR_bool MR_profile_parallel_execution = MR_FALSE;
+#ifndef MR_HIGHLEVEL_CODE
static MR_Stats MR_profile_parallel_executed_global_sparks =
{ 0, 0, 0, 0 };
static MR_Stats MR_profile_parallel_executed_contexts = { 0, 0, 0, 0 };
@@ -102,13 +103,13 @@ static MR_Integer MR_profile_paral
static MR_Integer MR_profile_parallel_regular_context_reused = 0;
static MR_Integer MR_profile_parallel_small_context_kept = 0;
static MR_Integer MR_profile_parallel_regular_context_kept = 0;
-#endif
+#endif /* ! MR_HIGHLEVEL_CODE */
+#endif /* MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
/*
** Local variables for thread pinning.
*/
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY)
+#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
static MercuryLock MR_next_cpu_lock;
MR_bool MR_thread_pinning = MR_FALSE;
static MR_Unsigned MR_next_cpu = 0;
@@ -163,8 +164,7 @@ MR_init_context_maybe_generator(MR_Conte
static void
MR_write_out_profiling_parallel_execution(void);
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY)
+#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
static void
MR_do_pin_thread(int cpu);
#endif
@@ -248,8 +248,7 @@ MR_init_thread_stuff(void)
void
MR_pin_primordial_thread(void)
{
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY)
+#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
#ifdef MR_HAVE_SCHED_GETCPU
/*
** We don't need locking to pin the primordial thread as it is called
@@ -270,15 +269,14 @@ MR_pin_primordial_thread(void)
#else
MR_pin_thread();
#endif
-#endif /* defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY) */
+#endif /* defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
+ */
}
void
MR_pin_thread(void)
{
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY)
+#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
MR_LOCK(&MR_next_cpu_lock, "MR_pin_thread");
if (MR_thread_pinning) {
#if defined(MR_HAVE_SCHED_GETCPU)
@@ -290,12 +288,11 @@ MR_pin_thread(void)
MR_next_cpu++;
}
MR_UNLOCK(&MR_next_cpu_lock, "MR_pin_thread");
-#endif /* defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY) */
+#endif /* defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
+ */
}
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY)
+#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
static void
MR_do_pin_thread(int cpu)
{
@@ -318,8 +315,8 @@ MR_do_pin_thread(int cpu)
MR_thread_pinning = MR_FALSE;
}
}
-#endif /* defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_HAVE_SCHED_SETAFFINITY) */
+#endif /* defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
+ */
void
MR_finalize_thread_stuff(void)
@@ -334,14 +331,14 @@ MR_finalize_thread_stuff(void)
pthread_mutex_destroy(&spark_deques_lock);
#endif
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_write_out_profiling_parallel_execution();
}
#endif
}
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
static int
fprint_stats(FILE *stream, const char *message, MR_Stats *stats);
@@ -464,7 +461,7 @@ fprint_stats(FILE *stream, const char *m
}
};
-#endif /* defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT) */
+#endif /* MR_PROFILE_PARALLEL_EXECUTION_SUPPORT */
static void
MR_init_context_maybe_generator(MR_Context *c, const char *id,
@@ -647,7 +644,7 @@ MR_Context *
MR_create_context(const char *id, MR_ContextSize ctxt_size, MR_Generator *gen)
{
MR_Context *c;
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if MR_THREADSCOPE
MR_Unsigned context_id;
#endif
@@ -666,7 +663,7 @@ MR_create_context(const char *id, MR_Con
if (ctxt_size == MR_CONTEXT_SIZE_SMALL && free_small_context_list) {
c = free_small_context_list;
free_small_context_list = c->MR_ctxt_next;
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_profile_parallel_small_context_reused++;
}
@@ -674,7 +671,7 @@ MR_create_context(const char *id, MR_Con
} else if (free_context_list != NULL) {
c = free_context_list;
free_context_list = c->MR_ctxt_next;
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_profile_parallel_regular_context_reused++;
}
@@ -682,7 +679,7 @@ MR_create_context(const char *id, MR_Con
} else {
c = NULL;
}
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if MR_THREADSCOPE
context_id = MR_next_context_id++;
#endif
MR_UNLOCK(&free_context_list_lock, "create_context i");
@@ -701,7 +698,7 @@ MR_create_context(const char *id, MR_Con
c->MR_ctxt_trail_zone = NULL;
#endif
}
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
c->MR_ctxt_num_id = context_id;
#endif
@@ -738,7 +735,7 @@ MR_destroy_context(MR_Context *c)
case MR_CONTEXT_SIZE_REGULAR:
c->MR_ctxt_next = free_context_list;
free_context_list = c;
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_profile_parallel_regular_context_kept++;
}
@@ -747,7 +744,7 @@ MR_destroy_context(MR_Context *c)
case MR_CONTEXT_SIZE_SMALL:
c->MR_ctxt_next = free_small_context_list;
free_small_context_list = c;
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_profile_parallel_small_context_kept++;
}
@@ -1055,7 +1052,7 @@ MR_check_pending_contexts(MR_bool block)
void
MR_schedule_context(MR_Context *ctxt)
{
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
MR_threadscope_post_context_runnable(ctxt);
#endif
MR_LOCK(&MR_runqueue_lock, "schedule_context");
@@ -1223,8 +1220,10 @@ MR_define_entry(MR_do_runnext);
if (MR_ENGINE(MR_eng_this_context) == NULL) {
MR_ENGINE(MR_eng_this_context) = MR_create_context("from spark",
MR_CONTEXT_SIZE_SMALL, NULL);
-#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#ifdef MR_THREADSCOPE
MR_threadscope_post_create_context_for_spark(MR_ENGINE(MR_eng_this_context));
+#endif
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
if (MR_profile_parallel_execution) {
MR_atomic_inc_int(
&MR_profile_parallel_contexts_created_for_sparks);
@@ -1232,7 +1231,7 @@ MR_define_entry(MR_do_runnext);
#endif
MR_load_context(MR_ENGINE(MR_eng_this_context));
} else {
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_threadscope_post_run_context();
#endif
}
@@ -1299,12 +1298,12 @@ MR_do_join_and_continue(MR_SyncTerm *jnc
if (jnc_last) {
if (this_context == jnc_st->MR_st_orig_context) {
/*
- ** It has finished executing and we're the originating context. Jump
- ** to the join label.
+ ** This context originated this parallel conjunction and all the
+ ** branches have finished so jump to the join label.
*/
return join_label;
} else {
-#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#ifdef MR_THREADSCOPE
MR_threadscope_post_stop_context(MR_TS_STOP_REASON_FINISHED);
#endif
/*
@@ -1333,20 +1332,22 @@ MR_do_join_and_continue(MR_SyncTerm *jnc
* spark from our local stack. The sparks on our stack are likely to
* cause this conjunction to be complete.
*/
- popped = MR_wsdeque_pop_bottom(&this_context->MR_ctxt_spark_deque, &spark_resume);
+ popped = MR_wsdeque_pop_bottom(&this_context->MR_ctxt_spark_deque,
+ &spark_resume);
if (popped) {
MR_atomic_dec_int(&MR_num_outstanding_contexts_and_all_sparks);
return spark_resume;
} else {
/*
- ** If this context originated the parallel conjunction we've been
- ** executing, suspend this context such that it will be resumed
- ** at the join label once the parallel conjunction is completed.
+ ** If this context originated the parallel conjunction that we've
+ ** been executing, suspend this context so that it will be
+ ** resumed at the join label once the parallel conjunction is
+ ** completed.
**
** Otherwise we can reuse this context for the next piece of work.
*/
if (this_context == jnc_st->MR_st_orig_context) {
-#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#ifdef MR_THREADSCOPE
MR_threadscope_post_stop_context(MR_TS_STOP_REASON_BLOCKED);
#endif
MR_save_context(this_context);
@@ -1355,7 +1356,7 @@ MR_do_join_and_continue(MR_SyncTerm *jnc
this_context->MR_ctxt_resume = (join_label);
MR_ENGINE(MR_eng_this_context) = NULL;
} else {
-#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#ifdef MR_THREADSCOPE
MR_threadscope_post_stop_context(MR_TS_STOP_REASON_FINISHED);
#endif
}
Index: runtime/mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.58
diff -u -p -b -r1.58 mercury_context.h
--- runtime/mercury_context.h 15 Dec 2009 02:29:06 -0000 1.58
+++ runtime/mercury_context.h 9 Jan 2010 12:59:26 -0000
@@ -248,7 +248,7 @@ struct MR_SparkDeque_Struct {
struct MR_Context_Struct {
const char *MR_ctxt_id;
-#if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_Unsigned MR_ctxt_num_id;
#endif
MR_ContextSize MR_ctxt_size;
@@ -343,7 +343,7 @@ extern MR_Context *MR_runqueue_tai
extern MR_bool MR_thread_pinning;
#endif
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
extern MR_bool MR_profile_parallel_execution;
/* XXX: This is currently unused, we plan to use it in the future. -pbone */
@@ -577,11 +577,10 @@ extern void MR_schedule_context(
#define MR_IF_NOT_HIGHLEVEL_CODE(x)
#endif
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
- #define MR_IF_LL_PAR_CONJ_AND_PROF_PAR_EXEC(x) x
+#ifdef MR_THREADSCOPE
+ #define MR_IF_THREADSCOPE(x) x
#else
- #define MR_IF_LL_PAR_CONJ_AND_PROF_PAR_EXEC(x)
+ #define MR_IF_THREADSCOPE(x)
#endif
#define MR_load_context(cptr) \
@@ -648,7 +647,7 @@ extern void MR_schedule_context(
) \
) \
MR_set_min_heap_reclamation_point(load_context_c); \
- MR_IF_LL_PAR_CONJ_AND_PROF_PAR_EXEC( \
+ MR_IF_THREADSCOPE( \
MR_threadscope_post_run_context(); \
) \
} while (0)
Index: runtime/mercury_engine.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.c,v
retrieving revision 1.59
diff -u -p -b -r1.59 mercury_engine.c
--- runtime/mercury_engine.c 3 Dec 2009 05:28:00 -0000 1.59
+++ runtime/mercury_engine.c 9 Jan 2010 12:59:26 -0000
@@ -149,8 +149,7 @@ MR_init_engine(MercuryEngine *eng)
eng->MR_eng_c_depth = 0;
#endif
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_threadscope_setup_engine(eng);
#endif
@@ -172,8 +171,7 @@ void MR_finalize_engine(MercuryEngine *e
MR_destroy_context(eng->MR_eng_this_context);
}
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if MR_THREADSCOPE
if (eng->MR_eng_ts_buffer) {
MR_threadscope_finalize_engine(eng);
}
@@ -527,7 +525,7 @@ MR_define_label(engine_done);
MR_GOTO_LABEL(engine_done_2);
}
-#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+#ifdef MR_THREADSCOPE
MR_threadscope_post_stop_context(MR_TS_STOP_REASON_YIELDING);
#endif
MR_save_context(this_ctxt);
Index: runtime/mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.51
diff -u -p -b -r1.51 mercury_engine.h
--- runtime/mercury_engine.h 3 Dec 2009 05:28:00 -0000 1.51
+++ runtime/mercury_engine.h 9 Jan 2010 12:59:26 -0000
@@ -392,7 +392,7 @@ typedef struct MR_mercury_engine_struct
#ifdef MR_THREAD_SAFE
MercuryThread MR_eng_owner_thread;
MR_Unsigned MR_eng_c_depth;
- #if defined(MR_LL_PARALLEL_CONJ) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+ #ifdef MR_THREADSCOPE
/*
** For each profiling event add this offset to the time so that events on
** different engines that occur at the same time have the same time in
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.79
diff -u -p -b -r1.79 mercury_grade.h
--- runtime/mercury_grade.h 30 Oct 2009 03:33:29 -0000 1.79
+++ runtime/mercury_grade.h 9 Jan 2010 12:59:26 -0000
@@ -447,8 +447,16 @@
#define MR_GRADE_OPT_PART_17 MR_GRADE_OPT_PART_16
#endif
-#define MR_GRADE MR_GRADE_PART_17
-#define MR_GRADE_OPT MR_GRADE_OPT_PART_17
+#if defined(MR_THREADSCOPE)
+ #define MR_GRADE_PART_18 MR_PASTE2(MR_GRADE_PART_17, _threadscope)
+ #define MR_GRADE_OPT_PART_18 MR_GRADE_OPT_PART_17 ".threadscope"
+#else
+ #define MR_GRADE_PART_18 MR_GRADE_PART_17
+ #define MR_GRADE_OPT_PART_18 MR_GRADE_OPT_PART_17
+#endif
+
+#define MR_GRADE MR_GRADE_PART_18
+#define MR_GRADE_OPT MR_GRADE_OPT_PART_18
#define MR_GRADE_VAR MR_PASTE2(MR_grade_,MR_GRADE)
#define MR_GRADE_STRING MR_STRINGIFY(MR_GRADE)
Index: runtime/mercury_thread.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.39
diff -u -p -b -r1.39 mercury_thread.c
--- runtime/mercury_thread.c 17 Dec 2009 01:29:18 -0000 1.39
+++ runtime/mercury_thread.c 9 Jan 2010 12:59:26 -0000
@@ -131,8 +131,7 @@ MR_init_thread(MR_when_to_use when_to_us
#ifdef MR_THREAD_SAFE
MR_ENGINE(MR_eng_owner_thread) = pthread_self();
- #if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+ #ifdef MR_THREADSCOPE
/*
** TSC Synchronization is not used, support is commented out. See
** runtime/mercury_threadscope.h for an explanation.
@@ -166,8 +165,7 @@ MR_init_thread(MR_when_to_use when_to_us
MR_ENGINE(MR_eng_this_context) =
MR_create_context("init_thread",
MR_CONTEXT_SIZE_REGULAR, NULL);
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_threadscope_post_create_context(MR_ENGINE(MR_eng_this_context));
#endif
}
Index: runtime/mercury_threadscope.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_threadscope.c,v
retrieving revision 1.1
diff -u -p -b -r1.1 mercury_threadscope.c
--- runtime/mercury_threadscope.c 3 Dec 2009 05:28:00 -0000 1.1
+++ runtime/mercury_threadscope.c 9 Jan 2010 12:59:26 -0000
@@ -85,8 +85,7 @@ ENDINIT
#include <stdio.h>
#include <string.h>
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
/***************************************************************************/
@@ -1171,8 +1170,7 @@ get_current_time_nanosecs(void)
/***************************************************************************/
-#endif /* defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT) */
+#endif /* MR_THREADSCOPE */
/* forward decls to suppress gcc warnings */
void mercury_sys_init_threadscope_init(void);
Index: runtime/mercury_threadscope.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_threadscope.h,v
retrieving revision 1.1
diff -u -p -b -r1.1 mercury_threadscope.h
--- runtime/mercury_threadscope.h 3 Dec 2009 05:28:00 -0000 1.1
+++ runtime/mercury_threadscope.h 9 Jan 2010 12:59:26 -0000
@@ -22,8 +22,7 @@
#include "mercury_engine.h"
#include "mercury_context.h"
-#if defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
/*
** Reasons why a context has been stopped, not all of these apply to Mercury,
@@ -128,7 +127,6 @@ MR_threadscope_post_stop_context(MR_Cont
extern void
MR_threadscope_post_calling_main(void);
-#endif /* defined(MR_THREAD_SAFE) && defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT) */
+#endif /* MR_THREADSCOPE */
#endif /* not MERCURY_THREADSCOPE_H */
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.204
diff -u -p -b -r1.204 mercury_wrapper.c
--- runtime/mercury_wrapper.c 15 Dec 2009 02:29:06 -0000 1.204
+++ runtime/mercury_wrapper.c 9 Jan 2010 12:59:26 -0000
@@ -539,7 +539,7 @@ mercury_runtime_init(int argc, char **ar
}
#endif
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#if defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
/*
** Setup support for reading the CPU's TSC and detect the clock speed of the
** processor. This is currently used by profiling of the parallelism
@@ -630,7 +630,7 @@ mercury_runtime_init(int argc, char **ar
#if defined(MR_LL_PARALLEL_CONJ)
MR_pin_primordial_thread();
- #if defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+ #if defined(MR_THREADSCOPE)
/*
** We must setup threadscope before we setup the first engine.
** Pin the primordial thread, if thread pinning is configured.
@@ -656,7 +656,7 @@ mercury_runtime_init(int argc, char **ar
for (i = 1; i < MR_num_threads; i++) {
MR_create_thread(NULL);
}
- #ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
+ #ifdef MR_THREADSCOPE
/*
** TSC Synchronization is not used, support is commented out. See
** runtime/mercury_threadscope.h for an explanation.
@@ -1794,7 +1794,7 @@ MR_process_options(int argc, char **argv
break;
case MR_PROFILE_PARALLEL_EXECUTION:
-#if defined(MR_THREAD_SAFE) && defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
MR_profile_parallel_execution = MR_TRUE;
#endif
break;
@@ -2468,8 +2468,7 @@ mercury_runtime_main(void)
MR_setup_callback(MR_program_entry_point);
#endif
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_threadscope_post_calling_main();
@@ -2483,8 +2482,7 @@ mercury_runtime_main(void)
MR_debugmsg0("Returning from MR_call_engine()\n");
#endif
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
MR_threadscope_post_stop_context(MR_TS_STOP_REASON_FINISHED);
@@ -2999,8 +2997,7 @@ mercury_runtime_terminate(void)
MR_ATOMIC_PAUSE;
}
-#if defined(MR_LL_PARALLEL_CONJ) && \
- defined(MR_PROFILE_PARALLEL_EXECUTION_SUPPORT)
+#ifdef MR_THREADSCOPE
if (MR_ENGINE(MR_eng_ts_buffer)) {
MR_threadscope_finalize_engine(MR_thread_engine_base);
}
Index: scripts/canonical_grade.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/canonical_grade.sh-subr,v
retrieving revision 1.22
diff -u -p -b -r1.22 canonical_grade.sh-subr
--- scripts/canonical_grade.sh-subr 5 Sep 2008 11:19:34 -0000 1.22
+++ scripts/canonical_grade.sh-subr 9 Jan 2010 12:59:26 -0000
@@ -81,9 +81,15 @@ case $gcc_nested_functions,$highlevel_co
*) ;;
esac
-case $thread_safe in
- true) GRADE="$GRADE.par" ;;
- false) ;;
+case $thread_safe,$threadscope in
+ true,false) GRADE="$GRADE.par" ;;
+ true,true) GRADE="$GRADE.par.threadscope" ;;
+ false,false) ;;
+ *)
+ echo "$progname: error: The 'threadscope' grade component may only be" 1>&2
+ echo "$progname: error: used in parallel grades"
+ exit 1
+ ;;
esac
case $gc_method in
Index: scripts/final_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/final_grade_options.sh-subr,v
retrieving revision 1.18
diff -u -p -b -r1.18 final_grade_options.sh-subr
--- scripts/final_grade_options.sh-subr 4 Jun 2009 07:48:21 -0000 1.18
+++ scripts/final_grade_options.sh-subr 9 Jan 2010 12:59:26 -0000
@@ -97,4 +97,12 @@ case $use_regions in false)
;;
esac
+#
+# threadscope doesn't make sense in non-parallel grades.
+#
+case $thread_safe in false)
+ threadscope=false
+ ;;
+esac
+
#---------------------------------------------------------------------------#
Index: scripts/init_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/init_grade_options.sh-subr,v
retrieving revision 1.33
diff -u -p -b -r1.33 init_grade_options.sh-subr
--- scripts/init_grade_options.sh-subr 5 Sep 2008 11:19:34 -0000 1.33
+++ scripts/init_grade_options.sh-subr 9 Jan 2010 12:59:26 -0000
@@ -72,6 +72,7 @@ asm_labels=true
non_local_gotos=true
global_regs=true
thread_safe=false
+threadscope=false
gc_method=boehm
profile_time=false
profile_calls=false
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.125
diff -u -p -b -r1.125 mgnuc.in
--- scripts/mgnuc.in 5 Sep 2008 11:19:34 -0000 1.125
+++ scripts/mgnuc.in 9 Jan 2010 12:59:26 -0000
@@ -286,6 +286,11 @@ case $thread_safe in
false) THREAD_OPTS="" ;;
esac
+case $threadscope in
+ true) THREADSCOPE_OPTS="-DMR_THREADSCOPE" ;;
+ false) THREADSCOPE_OPTS="" ;;
+esac
+
# Set the correct flags if we're to use the MS Visual C runtime.
use_msvcrt=@USE_MSVCRT@
if test $use_msvcrt = "yes"; then
@@ -648,6 +653,7 @@ ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
$SINGLE_PREC_FLOAT_OPTS\
$SPLIT_OPTS\
$THREAD_OPTS\
+ $THREADSCOPE_OPTS\
$REGION_OPTS\
$PICREG_OPTS\
$ARCH_OPTS\
Index: scripts/parse_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/parse_grade_options.sh-subr,v
retrieving revision 1.40
diff -u -p -b -r1.40 parse_grade_options.sh-subr
--- scripts/parse_grade_options.sh-subr 5 Sep 2008 11:19:34 -0000 1.40
+++ scripts/parse_grade_options.sh-subr 9 Jan 2010 12:59:26 -0000
@@ -392,6 +392,10 @@
thread_safe=true
;;
+ threadscope)
+ threadscope=true
+ ;;
+
agc)
gc_method=accurate
;;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20100110/57bf32e8/attachment.sig>
More information about the reviews
mailing list