[m-rev.] diff: ThreadScope support improvments.
Paul Bone
pbone at csse.unimelb.edu.au
Tue Jun 19 21:03:19 AEST 2012
ThreadScope support improvements.
Provide a new event for context re-use rather than creation. This event
is true to Mercury's behaviour; the existing threadscope events were
not.
Bring Mercury's usage of the create context event into line with
ThreadScope's expectations.
mercury_threadscope.[ch]:
Add a new event for when a context is re-used (and it's id is
re-assigned). This is like the create context event except that the
storage came from a previously used context.
mercury_context.c:
Post the reuse context event when a context is re-used from the
free list.
Post reuse context when a context that an engine already has is
re-used for a stolen spark. XXX: Check locally allocated contexts.
A result of these changes is that the create context message is used
even when a context is created to evaluate sparks. This is
deliberate: Some of ThreadScope's analyses require this.
mercury_thread.c:
mercury_context.c:
Place the create context event in MR_create_context rather than
after MR_create_context returns.
mercury_par_builtin.h:
Fixed the order of some type qualifiers. volatile was incorrectly
referring to the pointer's target and not the pointer.
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.105
diff -u -r1.105 mercury_context.c
--- runtime/mercury_context.c 24 Nov 2011 12:32:31 -0000 1.105
+++ runtime/mercury_context.c 19 Jun 2012 10:47:02 -0000
@@ -1057,11 +1057,18 @@
}
MR_UNLOCK(&free_context_list_lock, "create_context i");
+ if (c != NULL) {
+#ifdef MR_THREADSCOPE
+ MR_Unsigned old_id = c->MR_ctxt_num_id;
+
+ c->MR_ctxt_num_id = allocate_context_id();
+ MR_threadscope_post_reuse_context(c, old_id);
+#endif
#ifdef MR_DEBUG_STACK_SEGMENTS
- MR_debug_log_message("Re-used an old context: %p", c);
+ MR_debug_log_message("Re-used an old context: %p", c);
#endif
-
- if (c == NULL) {
+ }
+ else {
c = MR_GC_NEW_ATTRIB(MR_Context, MR_ALLOC_SITE_RUNTIME);
#ifdef MR_DEBUG_STACK_SEGMENTS
if (c) {
@@ -1078,6 +1085,7 @@
#endif
#ifdef MR_THREADSCOPE
c->MR_ctxt_num_id = allocate_context_id();
+ MR_threadscope_post_create_context(c);
#endif
}
@@ -2065,6 +2073,15 @@
MR_debug_log_message("created new context for spark: %p",
MR_ENGINE(MR_eng_this_context));
#endif
+ } else {
+#ifdef MR_THREADSCOPE
+ MR_Unsigned old_id;
+
+ old_id = MR_ENGINE(MR_eng_this_context)->MR_ctxt_num_id;
+ MR_ENGINE(MR_eng_this_context)->MR_ctxt_num_id = allocate_context_id();
+ MR_threadscope_post_reuse_context(MR_ENGINE(MR_eng_this_context),
+ old_id);
+#endif
}
#ifdef MR_THREADSCOPE
MR_threadscope_post_run_context();
Index: runtime/mercury_par_builtin.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_par_builtin.h,v
retrieving revision 1.16
diff -u -r1.16 mercury_par_builtin.h
--- runtime/mercury_par_builtin.h 20 Oct 2011 04:37:43 -0000 1.16
+++ runtime/mercury_par_builtin.h 19 Jun 2012 10:47:06 -0000
@@ -307,7 +307,7 @@
/* This lock protects only the next field */
MR_THREADSAFE_VOLATILE MR_Us_Lock MR_lc_master_context_lock;
- MR_THREADSAFE_VOLATILE MR_Context *MR_lc_master_context;
+ MR_Context* MR_THREADSAFE_VOLATILE MR_lc_master_context;
/* Unused atm */
MR_THREADSAFE_VOLATILE MR_bool MR_lc_finished;
Index: runtime/mercury_thread.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.51
diff -u -r1.51 mercury_thread.c
--- runtime/mercury_thread.c 28 Nov 2011 05:14:26 -0000 1.51
+++ runtime/mercury_thread.c 19 Jun 2012 10:47:10 -0000
@@ -213,9 +213,6 @@
MR_ENGINE(MR_eng_this_context) =
MR_create_context("init_thread",
MR_CONTEXT_SIZE_REGULAR, NULL);
-#ifdef MR_THREADSCOPE
- MR_threadscope_post_create_context(MR_ENGINE(MR_eng_this_context));
-#endif
}
MR_load_context(MR_ENGINE(MR_eng_this_context));
#ifdef MR_THREADSCOPE
Index: runtime/mercury_threadscope.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_threadscope.c,v
retrieving revision 1.19
diff -u -r1.19 mercury_threadscope.c
--- runtime/mercury_threadscope.c 16 Jun 2012 06:30:57 -0000 1.19
+++ runtime/mercury_threadscope.c 19 Jun 2012 10:47:10 -0000
@@ -212,7 +212,8 @@
#define MR_TS_MER_EVENT_CALLING_MAIN 113 /* () */
#define MR_TS_MER_EVENT_SPARK_RUN 114 /* (spark id) */
#define MR_TS_MER_EVENT_SPARK_STEAL 115 /* (victim cap, spark id) */
-#define MR_TS_NUM_MER_EVENTS 16
+#define MR_TS_MER_EVENT_REUSE_THREAD 116 /* (context id, old context id) */
+#define MR_TS_NUM_MER_EVENTS 17
#if 0 /* DEPRECATED EVENTS: */
#define EVENT_CREATE_SPARK 13 /* (cap, thread) */
@@ -638,6 +639,16 @@
0xFFFF
},
{
+ /*
+ ** The runtime system is re-useing a previous context and
+ ** re-assigning its ID.
+ */
+ MR_TS_MER_EVENT_REUSE_THREAD,
+ "Reusing a previously allocated thread",
+ SZ_CONTEXT_ID + SZ_CONTEXT_ID,
+ MR_TS_EVENT_CREATE_THREAD
+ },
+ {
/* Mark the end of this array. */
MR_TS_NUM_EVENT_TAGS,
NULL,
@@ -1259,6 +1270,28 @@
}
void
+MR_threadscope_post_reuse_context(MR_Context *context, MR_Unsigned old_id)
+{
+ struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
+
+ MR_US_SPIN_LOCK(&(buffer->MR_tsbuffer_lock));
+
+ if (!enough_room_for_event(buffer, MR_TS_MER_EVENT_REUSE_THREAD)) {
+ flush_event_buffer(buffer);
+ open_block(buffer, MR_ENGINE(MR_eng_id));
+ } else if (!block_is_open(buffer)) {
+ open_block(buffer, MR_ENGINE(MR_eng_id));
+ }
+
+ put_event_header(buffer, MR_TS_MER_EVENT_REUSE_THREAD,
+ get_current_time_nanosecs());
+ put_context_id(buffer, context->MR_ctxt_num_id);
+ put_context_id(buffer, old_id);
+
+ MR_US_UNLOCK(&(buffer->MR_tsbuffer_lock));
+}
+
+void
MR_threadscope_post_create_context_for_spark(MR_Context *context)
{
struct MR_threadscope_event_buffer *buffer = MR_ENGINE(MR_eng_ts_buffer);
Index: runtime/mercury_threadscope.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_threadscope.h,v
retrieving revision 1.14
diff -u -r1.14 mercury_threadscope.h
--- runtime/mercury_threadscope.h 8 Sep 2011 01:53:08 -0000 1.14
+++ runtime/mercury_threadscope.h 19 Jun 2012 10:47:10 -0000
@@ -98,8 +98,9 @@
struct MR_Context_Struct *context);
/*
-** The given context was created in order to execute a spark. It's an
-** alternative to the above event.
+** The given context was created in order to execute a spark. This
+** event should be posted in addition to (and after) create_thread
+** above.
*/
extern void MR_threadscope_post_create_context_for_spark(
struct MR_Context_Struct *ctxt);
@@ -113,6 +114,13 @@
struct MR_Context_Struct *context);
/*
+** This context is being reused (after being released). This event is an
+** alternative to create_context above.
+*/
+extern void MR_threadscope_post_reuse_context(
+ struct MR_Context_Struct *context, MR_Unsigned old_id);
+
+/*
** This message says the context is now ready to run. Such as it's being
** placed on the run queue after being blocked
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20120619/ed20dc29/attachment.sig>
More information about the reviews
mailing list