[m-rev.] diff: Fix ThreadScope support since my recent work stealing changes.
Paul Bone
pbone at csse.unimelb.edu.au
Tue May 24 14:16:20 AEST 2011
Fix ThreadScope support since my recent work stealing changes.
runtime/mercury_threadscope.h:
runtime/mercury_threadscope.c:
Fix some compilation problems.
Rename stop conjunction and stop conjunct events to use the word "end"
rather than "stop". The meaning is clearer and the name matches that used
in the threadscope paper.
runtime/mercury_context.h:
runtime/mercury_context.c:
Re-order some operations in the idle loop: try to resume an earlier
context before working on a local spark, this may lead to leas blocking.
The RUN_CONTEXT event was posted from the load_context macro. Change
this to post the RUN_CONTEXT event explicitly.
Fix some over-long lines.
Conform to changes in mercury_threadscope.h.
runtime/mercury_thread.c:
Add an explicit call to post the RUN_CONTEXT event.
compiler/layout_out.m:
Add a missing output_layout_array_name call when writing out the
threadscope string table array.
compiler/par_conj_gen.m:
Conform to changes in runtime/mercury_threadscope.h
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.117
diff -u -p -b -r1.117 layout_out.m
--- compiler/layout_out.m 23 May 2011 05:08:04 -0000 1.117
+++ compiler/layout_out.m 24 May 2011 04:14:54 -0000
@@ -2015,7 +2015,9 @@ output_layout_array_name_storage_type_na
Name, !IO)
;
Name = threadscope_string_table_array,
- io.write_string("static MR_Threadscope_String ", !IO)
+ io.write_string("static MR_Threadscope_String ", !IO),
+ output_layout_array_name(do_not_use_layout_macro, ModuleName,
+ Name, !IO)
;
Name = alloc_site_array,
% The type field may be updated at runtime so this array is not const.
Index: compiler/par_conj_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/par_conj_gen.m,v
retrieving revision 1.44
diff -u -p -b -r1.44 par_conj_gen.m
--- compiler/par_conj_gen.m 23 May 2011 05:08:09 -0000 1.44
+++ compiler/par_conj_gen.m 24 May 2011 04:14:54 -0000
@@ -314,7 +314,7 @@ ts_finish_par_conj_instr(SyncTermBaseSlo
live_lvals_info(set([SyncTermBaseSlotLval])),
format(Code, [i(SyncTermBaseSlot)]))],
Code = "#ifdef MR_THREADSCOPE
-MR_threadscope_post_stop_par_conj(&MR_sv(%d));
+MR_threadscope_post_end_par_conj(&MR_sv(%d));
#endif
".
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.93
diff -u -p -b -r1.93 mercury_context.c
--- runtime/mercury_context.c 20 May 2011 04:16:54 -0000 1.93
+++ runtime/mercury_context.c 24 May 2011 04:14:54 -0000
@@ -1457,18 +1457,13 @@ MR_define_entry(MR_do_idle);
{
/*
** Try to get a context.
- **
- ** Always look for local work first, even though we'd need to allocate a
- ** context to execute it. This is probably less efficient (TODO) but it's
- ** safer. It makes it easier for the state of the machine to change before
- ** it goes to sleep.
*/
- MR_MAYBE_TRAMPOLINE(do_local_spark(NULL));
-
advertise_engine_state_idle();
MR_MAYBE_TRAMPOLINE_AND_ACTION(do_get_context(),
advertise_engine_state_working());
+ MR_MAYBE_TRAMPOLINE_AND_ACTION(do_local_spark(NULL),
+ advertise_engine_state_working());
MR_MAYBE_TRAMPOLINE_AND_ACTION(do_work_steal(NULL),
advertise_engine_state_working());
MR_GOTO(MR_ENTRY(MR_do_sleep));
@@ -1511,6 +1506,7 @@ MR_define_entry(MR_do_idle_clean_context
MR_MAYBE_TRAMPOLINE_AND_ACTION(do_work_steal(NULL),
advertise_engine_state_working());
+
MR_MAYBE_TRAMPOLINE_AND_ACTION(do_get_context(),
advertise_engine_state_working());
MR_GOTO(MR_ENTRY(MR_do_sleep));
@@ -1700,6 +1696,9 @@ prepare_engine_for_context(MR_Context *c
}
MR_ENGINE(MR_eng_this_context) = context;
MR_load_context(context);
+#ifdef MR_THREADSCOPE
+ MR_threadscope_post_run_context();
+#endif
}
static void
@@ -1746,6 +1745,9 @@ prepare_engine_for_spark(volatile MR_Spa
#endif
*/
MR_load_context(MR_ENGINE(MR_eng_this_context));
+#ifdef MR_THREADSCOPE
+ MR_threadscope_post_run_context();
+#endif
#ifdef MR_DEBUG_STACK_SEGMENTS
MR_debug_log_message("created new context for spark: %p",
MR_ENGINE(MR_eng_this_context));
@@ -1753,7 +1755,8 @@ prepare_engine_for_spark(volatile MR_Spa
}
/*
- ** At this point we have a context, either a dirty context that's compatbile or a clean one.
+ ** At this point we have a context, either a dirty context that's
+ ** compatbile or a clean one.
*/
MR_parent_sp = spark->MR_spark_sync_term->MR_st_parent_sp;
MR_SET_THREAD_LOCAL_MUTABLES(spark->MR_spark_thread_local_mutables);
@@ -1830,7 +1833,8 @@ save_dirty_context(MR_Code *join_label)
static void
advertise_engine_state_idle(void)
{
- engine_sleep_sync_data[MR_ENGINE(MR_eng_id)].d.es_state = ENGINE_STATE_IDLE;
+ engine_sleep_sync_data[MR_ENGINE(MR_eng_id)].d.es_state =
+ ENGINE_STATE_IDLE;
MR_CPU_SFENCE;
MR_atomic_inc_int(&MR_num_idle_engines);
}
@@ -1840,7 +1844,8 @@ advertise_engine_state_working(void)
{
MR_atomic_dec_int(&MR_num_idle_engines);
MR_CPU_SFENCE;
- engine_sleep_sync_data[MR_ENGINE(MR_eng_id)].d.es_state = ENGINE_STATE_WORKING;
+ engine_sleep_sync_data[MR_ENGINE(MR_eng_id)].d.es_state =
+ ENGINE_STATE_WORKING;
}
#endif /* MR_THREAD_SAFE */
@@ -1854,7 +1859,7 @@ MR_do_join_and_continue(MR_SyncTerm *jnc
MR_Context *this_context = MR_ENGINE(MR_eng_this_context);
#ifdef MR_THREADSCOPE
- MR_threadscope_post_stop_par_conjunct((MR_Word*)jnc_st);
+ MR_threadscope_post_end_par_conjunct((MR_Word*)jnc_st);
#endif
/*
Index: runtime/mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.67
diff -u -p -b -r1.67 mercury_context.h
--- runtime/mercury_context.h 15 Apr 2011 11:13:45 -0000 1.67
+++ runtime/mercury_context.h 24 May 2011 04:14:54 -0000
@@ -676,9 +676,6 @@ extern void MR_schedule_context(
) \
) \
MR_set_min_heap_reclamation_point(load_context_c); \
- MR_IF_THREADSCOPE( \
- MR_threadscope_post_run_context(); \
- ) \
} while (0)
#define MR_save_context(cptr) \
Index: runtime/mercury_thread.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.c,v
retrieving revision 1.48
diff -u -p -b -r1.48 mercury_thread.c
--- runtime/mercury_thread.c 20 May 2011 04:16:56 -0000 1.48
+++ runtime/mercury_thread.c 24 May 2011 04:14:54 -0000
@@ -214,6 +214,9 @@ MR_init_thread(MR_when_to_use when_to_us
#endif
}
MR_load_context(MR_ENGINE(MR_eng_this_context));
+#ifdef MR_THREADSCOPE
+ MR_threadscope_post_run_context();
+#endif
MR_save_registers();
return MR_TRUE;
Index: runtime/mercury_threadscope.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_threadscope.c,v
retrieving revision 1.12
diff -u -p -b -r1.12 mercury_threadscope.c
--- runtime/mercury_threadscope.c 2 May 2011 07:55:04 -0000 1.12
+++ runtime/mercury_threadscope.c 24 May 2011 04:14:54 -0000
@@ -159,8 +159,8 @@
#define MR_TS_MER_EVENT_START 100
#define MR_TS_MER_EVENT_START_PAR_CONJ 100 /* (int id, memo'd string id) */
-#define MR_TS_MER_EVENT_STOP_PAR_CONJ 101 /* (int id) */
-#define MR_TS_MER_EVENT_STOP_PAR_CONJUNCT 102 /* (int id) */
+#define MR_TS_MER_EVENT_END_PAR_CONJ 101 /* (int id) */
+#define MR_TS_MER_EVENT_END_PAR_CONJUNCT 102 /* (int id) */
/*
** Creating sparks is not specifically mercury, but conjunct IDs are.
@@ -448,13 +448,13 @@ static EventTypeDesc event_type_descs[]
SZ_DYN_CONJ_ID + SZ_STATIC_CONJ_ID
},
{
- MR_TS_MER_EVENT_STOP_PAR_CONJ,
- "Stop a parallel conjunction (dyn id)",
+ MR_TS_MER_EVENT_END_PAR_CONJ,
+ "End a parallel conjunction (dyn id)",
SZ_DYN_CONJ_ID
},
{
- MR_TS_MER_EVENT_STOP_PAR_CONJUNCT,
- "Stop a parallel conjunct (dyn id)",
+ MR_TS_MER_EVENT_END_PAR_CONJUNCT,
+ "End a parallel conjunct (dyn id)",
SZ_DYN_CONJ_ID
},
{
@@ -573,7 +573,7 @@ enough_room_for_event(struct MR_threadsc
buffer->MR_tsbuffer_pos +
event_type_size(event_type) +
event_type_size(MR_TS_EVENT_BLOCK_MARKER) +
- ((2 + 8) * 2)) /* (EventType, Time) * 2 */
+ ((2 + 8) * 2); /* (EventType, Time) * 2 */
return needed < MR_TS_BUFFERSIZE;
}
@@ -585,7 +585,7 @@ enough_room_for_variable_size_event(stru
buffer->MR_tsbuffer_pos +
length +
event_type_size(MR_TS_EVENT_BLOCK_MARKER) +
- (2 + 8) * 2) /* (EventType, Time) * 2 */
+ ((2 + 8) * 2); /* (EventType, Time) * 2 */
return needed < MR_TS_BUFFERSIZE;
}
@@ -1391,19 +1391,19 @@ MR_threadscope_post_start_par_conj(MR_Wo
}
void
-MR_threadscope_post_stop_par_conj(MR_Word *dynamic_id)
+MR_threadscope_post_end_par_conj(MR_Word *dynamic_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_STOP_PAR_CONJ)) {
+ if (!enough_room_for_event(buffer, MR_TS_MER_EVENT_END_PAR_CONJ)) {
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_STOP_PAR_CONJ,
+ put_event_header(buffer, MR_TS_MER_EVENT_END_PAR_CONJ,
get_current_time_nanosecs());
put_par_conj_dynamic_id(buffer, dynamic_id);
@@ -1411,19 +1411,19 @@ MR_threadscope_post_stop_par_conj(MR_Wor
}
void
-MR_threadscope_post_stop_par_conjunct(MR_Word *dynamic_id)
+MR_threadscope_post_end_par_conjunct(MR_Word *dynamic_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_STOP_PAR_CONJUNCT)) {
+ if (!enough_room_for_event(buffer, MR_TS_MER_EVENT_END_PAR_CONJUNCT)) {
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_STOP_PAR_CONJUNCT,
+ put_event_header(buffer, MR_TS_MER_EVENT_END_PAR_CONJUNCT,
get_current_time_nanosecs());
put_par_conj_dynamic_id(buffer, dynamic_id);
Index: runtime/mercury_threadscope.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_threadscope.h,v
retrieving revision 1.9
diff -u -p -b -r1.9 mercury_threadscope.h
--- runtime/mercury_threadscope.h 2 May 2011 07:55:04 -0000 1.9
+++ runtime/mercury_threadscope.h 24 May 2011 04:14:54 -0000
@@ -164,12 +164,12 @@ extern void MR_threadscope_post_start_pa
/*
** Post this message after a parallel conjunction stops.
*/
-extern void MR_threadscope_post_stop_par_conj(MR_Word* dynamic_id);
+extern void MR_threadscope_post_end_par_conj(MR_Word* dynamic_id);
/*
** Post this message when a parallel conjunct calls the bariier code.
*/
-extern void MR_threadscope_post_stop_par_conjunct(MR_Word* dynamic_id);
+extern void MR_threadscope_post_end_par_conjunct(MR_Word* dynamic_id);
/*
** Post this message when a future is created, this establishes the conjuction
-------------- 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/20110524/78d05738/attachment.sig>
More information about the reviews
mailing list